Bug 1439443 - Policies: Remove Default Bookmarks and Smart Bookmarks. r=mak draft
authorFelipe Gomes <felipc@gmail.com>
Thu, 15 Mar 2018 18:52:28 -0300
changeset 768292 85a13da2d25658e05fc015bd9ae8ebe99ffb6dbc
parent 762811 6f0e4220aa2f3ce7176f1f29967dabf8bd4c1624
push id102833
push userfelipc@gmail.com
push dateThu, 15 Mar 2018 21:53:09 +0000
reviewersmak
bugs1439443
milestone60.0a1
Bug 1439443 - Policies: Remove Default Bookmarks and Smart Bookmarks. r=mak MozReview-Commit-ID: ES3faCFUfXG
browser/components/enterprisepolicies/Policies.jsm
browser/components/enterprisepolicies/schemas/policies-schema.json
browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/bookmarks_policies.json
browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/browser.ini
browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/browser_policies_smart_and_default_bookmarks.js
browser/components/enterprisepolicies/tests/moz.build
browser/components/migration/MigrationUtils.jsm
browser/components/nsBrowserGlue.js
--- a/browser/components/enterprisepolicies/Policies.jsm
+++ b/browser/components/enterprisepolicies/Policies.jsm
@@ -246,16 +246,32 @@ var Policies = {
   },
 
   "InstallAddons": {
     onBeforeUIStartup(manager, param) {
       addAllowDenyPermissions("install", param.Allow, null);
     }
   },
 
+  "NoDefaultBookmarks": {
+    onProfileAfterChange(manager, param) {
+      if (param) {
+        manager.disallowFeature("defaultBookmarks");
+      }
+    }
+  },
+
+  "NoSmartBookmarks": {
+    onProfileAfterChange(manager, param) {
+      if (param) {
+        manager.disallowFeature("smartBookmarks");
+      }
+    }
+  },
+
   "Popups": {
     onBeforeUIStartup(manager, param) {
       addAllowDenyPermissions("popup", param.Allow, null);
     }
   },
 
   "RememberPasswords": {
     onBeforeUIStartup(manager, param) {
--- a/browser/components/enterprisepolicies/schemas/policies-schema.json
+++ b/browser/components/enterprisepolicies/schemas/policies-schema.json
@@ -227,16 +227,32 @@
           "type": "array",
           "items": {
             "type": "origin"
           }
         }
       }
     },
 
+    "NoDefaultBookmarks": {
+      "description": "Don't create the default bookmarks. Note: this policy is only effective if used before the first run of the profile.",
+      "first_available": "60.0",
+
+      "type": "boolean",
+      "enum": [true]
+    },
+
+    "NoSmartBookmarks": {
+      "description": "Remove the Smart Bookmarks (Most Visited, Recent Tags).",
+      "first_available": "60.0",
+
+      "type": "boolean",
+      "enum": [true]
+    },
+
     "Popups": {
       "description": "Allow or deny popup usage.",
       "first_available": "60.0",
 
       "type": "object",
       "properties": {
         "Allow": {
           "type": "array",
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/bookmarks_policies.json
@@ -0,0 +1,6 @@
+{
+  "policies": {
+    "NoSmartBookmarks": true,
+    "NoDefaultBookmarks": true
+  }
+}
copy from browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini
copy to browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/browser.ini
--- a/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/browser.ini
+++ b/browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/browser.ini
@@ -1,8 +1,8 @@
 [DEFAULT]
 prefs =
   browser.policies.enabled=true
-  browser.policies.alternatePath='<test-root>/browser/components/enterprisepolicies/tests/browser/disable_developer_tools/config_disable_developer_tools.json'
+  browser.policies.alternatePath='<test-root>/browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/bookmarks_policies.json'
 support-files =
-  config_disable_developer_tools.json
+  bookmarks_policies.json
 
-[browser_policy_disable_developer_tools.js]
+[browser_policies_smart_and_default_bookmarks.js]
new file mode 100644
--- /dev/null
+++ b/browser/components/enterprisepolicies/tests/browser/smart_and_default_bookmarks/browser_policies_smart_and_default_bookmarks.js
@@ -0,0 +1,22 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+// This test must run in a separate folder because the
+// No Default Bookmarks policy needs to be present on
+// the first run of the profile, and not dinamically loaded
+// like most of the policies tested in the main test folder.
+
+add_task(async function test_smart_and_default_bookmarks() {
+  is(Services.prefs.getIntPref("browser.places.smartBookmarksVersion"), 0, "Smart Bookmarks are disabled");
+
+  let firstBookmarkOnToolbar =
+    await PlacesUtils.bookmarks.fetch({parentGuid: PlacesUtils.bookmarks.toolbarGuid, index: 0});
+
+  let firstBookmarkOnMenu =
+    await PlacesUtils.bookmarks.fetch({parentGuid: PlacesUtils.bookmarks.menuGuid, index: 0});
+
+  is(firstBookmarkOnToolbar, null, "No bookmarks on toolbar");
+  is(firstBookmarkOnMenu, null, "No bookmarks on menu");
+});
--- a/browser/components/enterprisepolicies/tests/moz.build
+++ b/browser/components/enterprisepolicies/tests/moz.build
@@ -6,9 +6,10 @@
 
 with Files("**"):
     BUG_COMPONENT = ("Firefox", "General")
 
 BROWSER_CHROME_MANIFESTS += [
     'browser/browser.ini',
     'browser/disable_app_update/browser.ini',
     'browser/disable_developer_tools/browser.ini',
+    'browser/smart_and_default_bookmarks/browser.ini',
 ]
--- a/browser/components/migration/MigrationUtils.jsm
+++ b/browser/components/migration/MigrationUtils.jsm
@@ -355,17 +355,18 @@ var MigratorPrototype = {
           }
 
           await completeDeferred.promise;
           await unblockMainThread();
         }
       }
     };
 
-    if (MigrationUtils.isStartupMigration && !this.startupOnlyMigrator) {
+    if (MigrationUtils.isStartupMigration && !this.startupOnlyMigrator &&
+        Services.policies.isAllowed("defaultBookmarks")) {
       MigrationUtils.profileStartup.doStartup();
       // First import the default bookmarks.
       // Note: We do not need to do so for the Firefox migrator
       // (=startupOnlyMigrator), as it just copies over the places database
       // from another profile.
       (async function() {
         // Tell nsBrowserGlue we're importing default bookmarks.
         let browserGlue = Cc["@mozilla.org/browser/browserglue;1"].
--- a/browser/components/nsBrowserGlue.js
+++ b/browser/components/nsBrowserGlue.js
@@ -1643,17 +1643,19 @@ BrowserGlue.prototype = {
           bookmarksUrl = "chrome://browser/locale/bookmarks.html";
         } else if (await OS.File.exists(BookmarkHTMLUtils.defaultPath)) {
           bookmarksUrl = OS.Path.toFileURI(BookmarkHTMLUtils.defaultPath);
         }
 
         if (bookmarksUrl) {
           // Import from bookmarks.html file.
           try {
-            await BookmarkHTMLUtils.importFromURL(bookmarksUrl, true);
+            if (Services.policies.isAllowed("defaultBookmarks")) {
+              await BookmarkHTMLUtils.importFromURL(bookmarksUrl, true);
+            }
           } catch (e) {
             Cu.reportError("Bookmarks.html file could be corrupt. " + e);
           }
           try {
             // Now apply distribution customized bookmarks.
             // This should always run after Places initialization.
             await this._distributionCustomizer.applyBookmarks();
             // Ensure that smart bookmarks are created once the operation is
@@ -2453,16 +2455,17 @@ BrowserGlue.prototype = {
     // TODO bug 399268: should this be a pref?
     const MAX_RESULTS = 10;
 
     // Get current smart bookmarks version.  If not set, create them.
     let smartBookmarksCurrentVersion = Services.prefs.getIntPref(SMART_BOOKMARKS_PREF, 0);
 
     // If version is current, or smart bookmarks are disabled, bail out.
     if (smartBookmarksCurrentVersion == -1 ||
+        !Services.policies.isAllowed("smartBookmarks") ||
         smartBookmarksCurrentVersion >= SMART_BOOKMARKS_VERSION) {
       return;
     }
 
     try {
       let menuIndex = 0;
       let toolbarIndex = 0;
       let bundle = Services.strings.createBundle("chrome://browser/locale/places/places.properties");