Bug 1451486 - Part 1 - Ignore the storage attribute on indexedDB.open() by default. r=asuth,baku
☠☠ backed out by 5067d8ae88c3 ☠ ☠
authorJohann Hofmann <jhofmann@mozilla.com>
Tue, 10 Apr 2018 23:00:30 +0200
changeset 466891 2e635314b75f06c5652cd1a60e46bd116bc5c270
parent 466890 37b8862d354e0014a72715462dd2102dd5b599cc
child 466892 eea1bfe5404db3705ef7d32c7a6f19a533531be7
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth, baku
bugs1451486
milestone61.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1451486 - Part 1 - Ignore the storage attribute on indexedDB.open() by default. r=asuth,baku MozReview-Commit-ID: 844FRkx3rKZ
devtools/client/storage/test/browser_storage_indexeddb_duplicate_names.js
dom/base/DOMPrefsInternal.h
dom/indexedDB/IDBFactory.cpp
dom/indexedDB/test/browser.ini
dom/indexedDB/test/mochitest.ini
dom/indexedDB/test/unit/test_defaultStorageUpgrade.js
dom/indexedDB/test/unit/test_metadata2Restore.js
dom/indexedDB/test/unit/test_metadataRestore.js
modules/libpref/init/all.js
--- a/devtools/client/storage/test/browser_storage_indexeddb_duplicate_names.js
+++ b/devtools/client/storage/test/browser_storage_indexeddb_duplicate_names.js
@@ -3,16 +3,20 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 // Test to verify that indexedDBs with duplicate names (different types / paths)
 // work as expected.
 
 "use strict";
 
 add_task(async function() {
+  await SpecialPowers.pushPrefEnv({
+    set: [["dom.indexedDB.storageOption.enabled", true]]
+  });
+
   const TESTPAGE = MAIN_DOMAIN + "storage-indexeddb-duplicate-names.html";
 
   setPermission(TESTPAGE, "indexedDB");
 
   await openTabAndSetupStorage(TESTPAGE);
 
   await checkState([
     [
--- a/dom/base/DOMPrefsInternal.h
+++ b/dom/base/DOMPrefsInternal.h
@@ -36,16 +36,17 @@ DOM_PREF(StreamsEnabled, "dom.streams.en
 DOM_PREF(OffscreenCanvasEnabled, "gfx.offscreencanvas.enabled")
 DOM_PREF(WebkitBlinkDirectoryPickerEnabled, "dom.webkitBlink.dirPicker.enabled")
 DOM_PREF(NetworkInformationEnabled, "dom.netinfo.enabled")
 DOM_PREF(FetchObserverEnabled, "dom.fetchObserver.enabled")
 DOM_PREF(ResistFingerprintingEnabled, "privacy.resistFingerprinting")
 DOM_PREF(EnableAutoDeclineCanvasPrompts, "privacy.resistFingerprinting.autoDeclineNoUserInputCanvasPrompts")
 DOM_PREF(DevToolsEnabled, "devtools.enabled")
 DOM_PREF(PerformanceObserverEnabled, "dom.enable_performance_observer")
+DOM_PREF(IndexedDBStorageOptionsEnabled, "dom.indexedDB.storageOption.enabled")
 
 DOM_WEBIDL_PREF(ImageBitmapExtensionsEnabled)
 DOM_WEBIDL_PREF(DOMCachesEnabled)
 DOM_WEBIDL_PREF(NotificationEnabledInServiceWorkers)
 DOM_WEBIDL_PREF(NotificationRIEnabled)
 DOM_WEBIDL_PREF(ServiceWorkersEnabled)
 DOM_WEBIDL_PREF(StorageManagerEnabled)
 DOM_WEBIDL_PREF(PromiseRejectionEventsEnabled)
--- a/dom/indexedDB/IDBFactory.cpp
+++ b/dom/indexedDB/IDBFactory.cpp
@@ -688,21 +688,37 @@ IDBFactory::OpenInternal(JSContext* aCx,
   PersistenceType persistenceType;
 
   bool isInternal = principalInfo.type() == PrincipalInfo::TSystemPrincipalInfo;
   if (!isInternal && principalInfo.type() == PrincipalInfo::TContentPrincipalInfo) {
     nsCString origin = principalInfo.get_ContentPrincipalInfo().originNoSuffix();
     isInternal = QuotaManager::IsOriginInternal(origin);
   }
 
+  // Allow storage attributes for add-ons independent of the pref.
+  // This works in the main thread only, workers don't have the principal.
+  bool isAddon = false;
+  if (NS_IsMainThread()) {
+    // aPrincipal is passed inconsistently, so even when we are already on
+    // the main thread, we may have been passed a null aPrincipal.
+    nsCOMPtr<nsIPrincipal> principal = PrincipalInfoToPrincipal(principalInfo);
+    if (principal) {
+      nsAutoString addonId;
+      Unused << NS_WARN_IF(NS_FAILED(principal->GetAddonId(addonId)));
+      isAddon = !addonId.IsEmpty();
+    }
+  }
+
   if (isInternal) {
     // Chrome privilege and internal origins always get persistent storage.
     persistenceType = PERSISTENCE_TYPE_PERSISTENT;
+  } else if (isAddon || DOMPrefs::IndexedDBStorageOptionsEnabled()) {
+    persistenceType = PersistenceTypeFromStorage(aStorageType);
   } else {
-    persistenceType = PersistenceTypeFromStorage(aStorageType);
+    persistenceType = PERSISTENCE_TYPE_DEFAULT;
   }
 
   DatabaseMetadata& metadata = commonParams.metadata();
   metadata.name() = aName;
   metadata.persistenceType() = persistenceType;
 
   FactoryRequestParams params;
   if (aDeleting) {
--- a/dom/indexedDB/test/browser.ini
+++ b/dom/indexedDB/test/browser.ini
@@ -1,9 +1,11 @@
 [DEFAULT]
+prefs =
+  dom.indexedDB.storageOption.enabled=true
 skip-if = (buildapp != "browser")
 support-files =
   head.js
   browser_forgetThisSiteAdd.html
   browser_forgetThisSiteGet.html
   browserHelpers.js
   browser_permissionsPrompt.html
   browser_permissionsSharedWorker.html
--- a/dom/indexedDB/test/mochitest.ini
+++ b/dom/indexedDB/test/mochitest.ini
@@ -1,13 +1,15 @@
 # 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/.
 
 [DEFAULT]
+prefs =
+  dom.indexedDB.storageOption.enabled=true
 support-files =
   bfcache_page1.html
   bfcache_page2.html
   blob_worker_crash_iframe.html
   error_events_abort_transactions_iframe.html
   event_propagation_iframe.html
   exceptions_in_events_iframe.html
   file.js
--- a/dom/indexedDB/test/unit/test_defaultStorageUpgrade.js
+++ b/dom/indexedDB/test/unit/test_defaultStorageUpgrade.js
@@ -2,16 +2,21 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
+  Services.prefs.setBoolPref("dom.indexedDB.storageOption.enabled", true);
+  registerCleanupFunction(() => {
+    Services.prefs.clearUserPref("dom.indexedDB.storageOption.enabled");
+  });
+
   const openParams = [
     // This one lives in storage/default/http+++localhost
     { url: "http://localhost", dbName: "dbA", dbVersion: 1 },
 
     // This one lives in storage/default/http+++www.mozilla.org
     { url: "http://www.mozilla.org", dbName: "dbB", dbVersion: 1 },
 
     // This one lives in storage/default/http+++www.mozilla.org+8080
--- a/dom/indexedDB/test/unit/test_metadata2Restore.js
+++ b/dom/indexedDB/test/unit/test_metadata2Restore.js
@@ -2,16 +2,21 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
+  Services.prefs.setBoolPref("dom.indexedDB.storageOption.enabled", true);
+  registerCleanupFunction(() => {
+    Services.prefs.clearUserPref("dom.indexedDB.storageOption.enabled");
+  });
+
   const openParams = [
     // This one lives in storage/permanent/chrome
     // The .metadata-v2 file was intentionally removed for this origin directory
     // to test restoring.
     { dbName: "dbA",
       dbOptions: { version: 1, storage: "persistent" } },
 
     // This one lives in storage/temporary/http+++localhost
--- a/dom/indexedDB/test/unit/test_metadataRestore.js
+++ b/dom/indexedDB/test/unit/test_metadataRestore.js
@@ -2,16 +2,21 @@
  * Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/
  */
 
 var testGenerator = testSteps();
 
 function* testSteps()
 {
+  Services.prefs.setBoolPref("dom.indexedDB.storageOption.enabled", true);
+  registerCleanupFunction(() => {
+    Services.prefs.clearUserPref("dom.indexedDB.storageOption.enabled");
+  });
+
   const openParams = [
     // This one lives in storage/permanent/chrome
     { dbName: "dbA",
       dbOptions: { version: 1, storage: "persistent" } },
 
     // This one lives in storage/temporary/http+++localhost
     { url: "http://localhost", dbName: "dbB",
       dbOptions: { version: 1, storage: "temporary" } },
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -133,16 +133,18 @@ pref("dom.indexedDB.enabled", true);
 // Whether or not indexedDB experimental features are enabled.
 pref("dom.indexedDB.experimental", false);
 // Enable indexedDB logging.
 pref("dom.indexedDB.logging.enabled", true);
 // Detailed output in log messages.
 pref("dom.indexedDB.logging.details", true);
 // Enable profiler marks for indexedDB events.
 pref("dom.indexedDB.logging.profiler-marks", false);
+// Enable passing the "storage" option to indexedDB.open.
+pref("dom.indexedDB.storageOption.enabled", false);
 
 // Whether or not File Handle is enabled.
 pref("dom.fileHandle.enabled", true);
 
 // Whether window.onappinstalled from "W3C Web Manifest" is enabled
 pref("dom.manifest.onappinstalled", false);
 
 // Whether or not selection events are enabled