forked from mirrors/gecko-dev
		
	 a7b308c3a2
			
		
	
	
		a7b308c3a2
		
	
	
	
	
		
			
			These issues were previously ignored due to the nature of our global import rules. They need to be fixed before that rule can be updated. MozReview-Commit-ID: DCChktTc5TW --HG-- extra : rebase_source : cffb1c9762191c579d1397c8169e6e7635d229da extra : histedit_source : dea59ddd2daaae52069c5faceae9149a4f08dd73
		
			
				
	
	
		
			179 lines
		
	
	
	
		
			5.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			179 lines
		
	
	
	
		
			5.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* This Source Code Form is subject to the terms of the Mozilla Public
 | |
|  * License, v. 2.0. If a copy of the MPL was not distributed with this
 | |
|  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 | |
| 
 | |
| "use strict";
 | |
| 
 | |
| var EXPORTED_SYMBOLS = [ "AboutHomeUtils", "AboutHome" ];
 | |
| 
 | |
| ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
 | |
| ChromeUtils.import("resource://gre/modules/Services.jsm");
 | |
| 
 | |
| ChromeUtils.defineModuleGetter(this, "AppConstants",
 | |
|   "resource://gre/modules/AppConstants.jsm");
 | |
| ChromeUtils.defineModuleGetter(this, "AutoMigrate",
 | |
|   "resource:///modules/AutoMigrate.jsm");
 | |
| ChromeUtils.defineModuleGetter(this, "SessionStore",
 | |
|   "resource:///modules/sessionstore/SessionStore.jsm");
 | |
| 
 | |
| // Url to fetch snippets, in the urlFormatter service format.
 | |
| const SNIPPETS_URL_PREF = "browser.aboutHomeSnippets.updateUrl";
 | |
| 
 | |
| // Should be bumped up if the snippets content format changes.
 | |
| const STARTPAGE_VERSION = 4;
 | |
| 
 | |
| var AboutHomeUtils = {
 | |
|   get snippetsVersion() {
 | |
|     return STARTPAGE_VERSION;
 | |
|   },
 | |
| 
 | |
|   /*
 | |
|    * showKnowYourRights - Determines if the user should be shown the
 | |
|    * about:rights notification. The notification should *not* be shown if
 | |
|    * we've already shown the current version, or if the override pref says to
 | |
|    * never show it. The notification *should* be shown if it's never been seen
 | |
|    * before, if a newer version is available, or if the override pref says to
 | |
|    * always show it.
 | |
|    */
 | |
|   get showKnowYourRights() {
 | |
|     // Look for an unconditional override pref. If set, do what it says.
 | |
|     // (true --> never show, false --> always show)
 | |
|     try {
 | |
|       return !Services.prefs.getBoolPref("browser.rights.override");
 | |
|     } catch (e) { }
 | |
|     // Ditto, for the legacy EULA pref.
 | |
|     try {
 | |
|       return !Services.prefs.getBoolPref("browser.EULA.override");
 | |
|     } catch (e) { }
 | |
| 
 | |
|     if (!AppConstants.MOZILLA_OFFICIAL) {
 | |
|       // Non-official builds shouldn't show the notification.
 | |
|       return false;
 | |
|     }
 | |
| 
 | |
|     // Look to see if the user has seen the current version or not.
 | |
|     var currentVersion = Services.prefs.getIntPref("browser.rights.version");
 | |
|     try {
 | |
|       return !Services.prefs.getBoolPref("browser.rights." + currentVersion + ".shown");
 | |
|     } catch (e) { }
 | |
| 
 | |
|     // Legacy: If the user accepted a EULA, we won't annoy them with the
 | |
|     // equivalent about:rights page until the version changes.
 | |
|     try {
 | |
|       return !Services.prefs.getBoolPref("browser.EULA." + currentVersion + ".accepted");
 | |
|     } catch (e) { }
 | |
| 
 | |
|     // We haven't shown the notification before, so do so now.
 | |
|     return true;
 | |
|   }
 | |
| };
 | |
| 
 | |
| /**
 | |
|  * Returns the URL to fetch snippets from, in the urlFormatter service format.
 | |
|  */
 | |
| XPCOMUtils.defineLazyGetter(AboutHomeUtils, "snippetsURL", function() {
 | |
|   let updateURL = Services.prefs
 | |
|                           .getCharPref(SNIPPETS_URL_PREF)
 | |
|                           .replace("%STARTPAGE_VERSION%", STARTPAGE_VERSION);
 | |
|   return Services.urlFormatter.formatURL(updateURL);
 | |
| });
 | |
| 
 | |
| /**
 | |
|  * This code provides services to the about:home page. Whenever
 | |
|  * about:home needs to do something chrome-privileged, it sends a
 | |
|  * message that's handled here.
 | |
|  */
 | |
| var AboutHome = {
 | |
|   MESSAGES: [
 | |
|     "AboutHome:RestorePreviousSession",
 | |
|     "AboutHome:Downloads",
 | |
|     "AboutHome:Bookmarks",
 | |
|     "AboutHome:History",
 | |
|     "AboutHome:Addons",
 | |
|     "AboutHome:Sync",
 | |
|     "AboutHome:Settings",
 | |
|   ],
 | |
| 
 | |
|   init() {
 | |
|     for (let msg of this.MESSAGES) {
 | |
|       Services.mm.addMessageListener(msg, this);
 | |
|     }
 | |
|   },
 | |
| 
 | |
|   // Additional listeners are registered in nsBrowserGlue.js
 | |
|   receiveMessage(aMessage) {
 | |
|     let window = aMessage.target.ownerGlobal;
 | |
| 
 | |
|     switch (aMessage.name) {
 | |
|       case "AboutHome:RestorePreviousSession":
 | |
|         if (SessionStore.canRestoreLastSession) {
 | |
|           SessionStore.restoreLastSession();
 | |
|         }
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:Downloads":
 | |
|         window.BrowserDownloadsUI();
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:Bookmarks":
 | |
|         window.PlacesCommandHook.showPlacesOrganizer("UnfiledBookmarks");
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:History":
 | |
|         window.PlacesCommandHook.showPlacesOrganizer("History");
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:Addons":
 | |
|         window.BrowserOpenAddonsMgr();
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:Sync":
 | |
|         window.openPreferences("paneSync", { urlParams: { entrypoint: "abouthome" }, origin: "aboutHome"  });
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:Settings":
 | |
|         window.openPreferences(undefined, {origin: "aboutHome"} );
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:RequestUpdate":
 | |
|         this.sendAboutHomeData(aMessage.target);
 | |
|         break;
 | |
| 
 | |
|       case "AboutHome:MaybeShowMigrateMessage":
 | |
|         AutoMigrate.shouldShowMigratePrompt(aMessage.target).then((prompt) => {
 | |
|           if (prompt) {
 | |
|             AutoMigrate.showUndoNotificationBar(aMessage.target);
 | |
|           }
 | |
|         });
 | |
|         break;
 | |
|     }
 | |
|   },
 | |
| 
 | |
|   // Send all the chrome-privileged data needed by about:home. This
 | |
|   // gets re-sent when the search engine changes.
 | |
|   sendAboutHomeData(target) {
 | |
|     SessionStore.promiseInitialized.then(function() {
 | |
|       let data = {
 | |
|         showRestoreLastSession: SessionStore.canRestoreLastSession,
 | |
|         snippetsURL: AboutHomeUtils.snippetsURL,
 | |
|         showKnowYourRights: AboutHomeUtils.showKnowYourRights,
 | |
|         snippetsVersion: AboutHomeUtils.snippetsVersion,
 | |
|       };
 | |
| 
 | |
|       if (AboutHomeUtils.showKnowYourRights) {
 | |
|         // Set pref to indicate we've shown the notification.
 | |
|         let currentVersion = Services.prefs.getIntPref("browser.rights.version");
 | |
|         Services.prefs.setBoolPref("browser.rights." + currentVersion + ".shown", true);
 | |
|       }
 | |
| 
 | |
|       if (target && target.messageManager) {
 | |
|         target.messageManager.sendAsyncMessage("AboutHome:Update", data);
 | |
|       } else {
 | |
|         Services.mm.broadcastAsyncMessage("AboutHome:Update", data);
 | |
|       }
 | |
|     }).catch(function onError(x) {
 | |
|       Cu.reportError("Error in AboutHome.sendAboutHomeData: " + x);
 | |
|     });
 | |
|   },
 | |
| 
 | |
| };
 |