Bug 1526891 - Part 1: Change handling of indexeddb:// from simple URI to standard URL; r=asuth
authorJan Varga <jan.varga@gmail.com>
Sat, 23 Feb 2019 04:20:29 +0100
changeset 520814 910b832dbbf6f2cf54461817eb5d9165b78caa6c
parent 520813 29f06968e80af7188d89768f48fe02daec45f5b4
child 520815 875bba6627b329803cb02bf0c40d028d0520121b
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1526891
milestone67.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 1526891 - Part 1: Change handling of indexeddb:// from simple URI to standard URL; r=asuth Differential Revision: https://phabricator.services.mozilla.com/D20905
caps/ContentPrincipal.cpp
dom/quota/components.conf
dom/quota/moz.build
dom/quota/nsIndexedDBProtocolHandler.cpp
dom/quota/nsIndexedDBProtocolHandler.h
--- a/caps/ContentPrincipal.cpp
+++ b/caps/ContentPrincipal.cpp
@@ -147,18 +147,17 @@ nsresult ContentPrincipal::GenerateOrigi
   bool isBehaved;
   if ((NS_SUCCEEDED(origin->SchemeIs("about", &isBehaved)) && isBehaved) ||
       (NS_SUCCEEDED(origin->SchemeIs("moz-safe-about", &isBehaved)) &&
        isBehaved &&
        // We generally consider two about:foo origins to be same-origin, but
        // about:blank is special since it can be generated from different
        // sources. We check for moz-safe-about:blank since origin is an
        // innermost URI.
-       !origin->GetSpecOrDefault().EqualsLiteral("moz-safe-about:blank")) ||
-      (NS_SUCCEEDED(origin->SchemeIs("indexeddb", &isBehaved)) && isBehaved)) {
+       !origin->GetSpecOrDefault().EqualsLiteral("moz-safe-about:blank"))) {
     rv = origin->GetAsciiSpec(aOriginNoSuffix);
     NS_ENSURE_SUCCESS(rv, rv);
 
     int32_t pos = aOriginNoSuffix.FindChar('?');
     int32_t hashPos = aOriginNoSuffix.FindChar('#');
 
     if (hashPos != kNotFound && (pos == kNotFound || hashPos < pos)) {
       pos = hashPos;
@@ -405,16 +404,23 @@ static nsresult GetSpecialBaseDomain(con
     return rv;
   }
 
   if (hasNoRelativeFlag) {
     *aHandled = true;
     return aCodebase->GetSpec(aBaseDomain);
   }
 
+  bool isBehaved;
+  if (NS_SUCCEEDED(aCodebase->SchemeIs("indexeddb", &isBehaved)) &&
+      isBehaved) {
+    *aHandled = true;
+    return aCodebase->GetSpec(aBaseDomain);
+  }
+
   return NS_OK;
 }
 
 NS_IMETHODIMP
 ContentPrincipal::GetBaseDomain(nsACString& aBaseDomain) {
   // Handle some special URIs first.
   bool handled;
   nsresult rv = GetSpecialBaseDomain(mCodebase, &handled, aBaseDomain);
new file mode 100644
--- /dev/null
+++ b/dom/quota/components.conf
@@ -0,0 +1,14 @@
+# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
+# vim: set filetype=python:
+# 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/.
+
+Classes = [
+    {
+        'cid': '{b6f2f870-b0bc-4a1a-9c40-02cc171adb5b}',
+        'contract_ids': ['@mozilla.org/network/protocol;1?name=indexeddb'],
+        'type': 'nsIndexedDBProtocolHandler',
+        'headers': ['/dom/quota/nsIndexedDBProtocolHandler.h'],
+    },
+]
--- a/dom/quota/moz.build
+++ b/dom/quota/moz.build
@@ -44,21 +44,26 @@ EXPORTS.mozilla.dom.quota += [
     'QuotaCommon.h',
     'QuotaManager.h',
     'QuotaManagerService.h',
     'QuotaObject.h',
     'SerializationHelpers.h',
     'UsageInfo.h',
 ]
 
+XPCOM_MANIFESTS += [
+    'components.conf',
+]
+
 UNIFIED_SOURCES += [
     'ActorsChild.cpp',
     'ActorsParent.cpp',
     'FileStreams.cpp',
     'MemoryOutputStream.cpp',
+    'nsIndexedDBProtocolHandler.cpp',
     'QuotaCommon.cpp',
     'QuotaManagerService.cpp',
     'QuotaRequests.cpp',
     'QuotaResults.cpp',
     'StorageManager.cpp',
 ]
 
 IPDL_SOURCES += [
new file mode 100644
--- /dev/null
+++ b/dom/quota/nsIndexedDBProtocolHandler.cpp
@@ -0,0 +1,63 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim:set ts=2 sts=2 sw=2 et cin:
+ *
+ * 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/. */
+
+#include "nsIndexedDBProtocolHandler.h"
+
+#include "nsIURIMutator.h"
+#include "nsStandardURL.h"
+
+using namespace mozilla::net;
+
+nsIndexedDBProtocolHandler::nsIndexedDBProtocolHandler() {}
+
+nsIndexedDBProtocolHandler::~nsIndexedDBProtocolHandler() {}
+
+NS_IMPL_ISUPPORTS(nsIndexedDBProtocolHandler, nsIProtocolHandler,
+                  nsISupportsWeakReference)
+
+NS_IMETHODIMP nsIndexedDBProtocolHandler::GetScheme(nsACString& aScheme) {
+  aScheme.AssignLiteral("indexeddb");
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsIndexedDBProtocolHandler::GetDefaultPort(
+    int32_t* aDefaultPort) {
+  *aDefaultPort = -1;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsIndexedDBProtocolHandler::GetProtocolFlags(
+    uint32_t* aProtocolFlags) {
+  *aProtocolFlags = URI_STD | URI_DANGEROUS_TO_LOAD | URI_DOES_NOT_RETURN_DATA |
+                    URI_NON_PERSISTABLE;
+  return NS_OK;
+}
+
+NS_IMETHODIMP nsIndexedDBProtocolHandler::NewURI(
+    const nsACString& aSpec, const char* aOriginCharset, nsIURI* aBaseURI,
+    nsIURI** _retval) {
+  nsCOMPtr<nsIURI> baseURI(aBaseURI);
+  return NS_MutateURI(new nsStandardURL::Mutator())
+      .Apply(NS_MutatorMethod(&nsIStandardURLMutator::Init,
+                              nsIStandardURL::URLTYPE_AUTHORITY, 0,
+                              nsCString(aSpec), aOriginCharset, baseURI,
+                              nullptr))
+      .Finalize(_retval);
+}
+
+NS_IMETHODIMP
+nsIndexedDBProtocolHandler::NewChannel(nsIURI* aURI, nsILoadInfo* aLoadInfo,
+                                       nsIChannel** _retval) {
+  return NS_ERROR_NOT_IMPLEMENTED;
+}
+
+NS_IMETHODIMP
+nsIndexedDBProtocolHandler::AllowPort(int32_t aPort, const char* aScheme,
+                                      bool* _retval) {
+  *_retval = false;
+  return NS_OK;
+}
new file mode 100644
--- /dev/null
+++ b/dom/quota/nsIndexedDBProtocolHandler.h
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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/. */
+
+#ifndef nsIndexedDBProtocolHandler_h
+#define nsIndexedDBProtocolHandler_h
+
+#include "nsIProtocolHandler.h"
+#include "nsWeakReference.h"
+
+class nsIndexedDBProtocolHandler final : public nsIProtocolHandler,
+                                         public nsSupportsWeakReference {
+ public:
+  nsIndexedDBProtocolHandler();
+
+ private:
+  ~nsIndexedDBProtocolHandler();
+
+  NS_DECL_THREADSAFE_ISUPPORTS
+  NS_DECL_NSIPROTOCOLHANDLER
+};
+
+#endif  // nsIndexedDBProtocolHandler_h