Bug 1455676 part 18. Stop using getInterface as the primary API for the indexeddb permission notifications. r=mrbkap
authorBoris Zbarsky <bzbarsky@mit.edu>
Tue, 29 May 2018 22:58:50 -0400
changeset 474618 8210471a0b5e2eb23ea94ba2dd00a25c068e6c2b
parent 474617 bcf0bd0ee7bbdf77f7e117d20c7ad09fdc584946
child 474619 94070be7a406ba8448900617da8fa54e317daba5
push id9374
push userjlund@mozilla.com
push dateMon, 18 Jun 2018 21:43:20 +0000
treeherdermozilla-beta@160e085dfb0b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmrbkap
bugs1455676
milestone62.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 1455676 part 18. Stop using getInterface as the primary API for the indexeddb permission notifications. r=mrbkap
browser/base/content/browser.js
dom/indexedDB/PermissionRequestBase.cpp
dom/indexedDB/PermissionRequestBase.h
dom/indexedDB/moz.build
dom/indexedDB/nsIIDBPermissionsRequest.idl
mobile/android/chrome/content/browser.js
--- a/browser/base/content/browser.js
+++ b/browser/base/content/browser.js
@@ -6866,36 +6866,36 @@ var IndexedDBPromptHelper = {
   },
 
   observe:
   function IndexedDBPromptHelper_observe(subject, topic, data) {
     if (topic != this._permissionsPrompt) {
       throw new Error("Unexpected topic!");
     }
 
-    var requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor);
-
-    var browser = requestor.getInterface(Ci.nsIDOMNode);
+    var request = subject.QueryInterface(Ci.nsIIDBPermissionsRequest);
+
+    var browser = request.browserElement;
     if (browser.ownerGlobal != window) {
       // Only listen for notifications for browsers in our chrome window.
       return;
     }
 
     // Get the host name if available or the file path otherwise.
     var host = browser.currentURI.asciiHost || browser.currentURI.pathQueryRef;
 
     var message;
     var responseTopic;
     if (topic == this._permissionsPrompt) {
       message = gNavigatorBundle.getFormattedString("offlineApps.available2",
                                                     [ host ]);
       responseTopic = this._permissionsResponse;
     }
 
-    var observer = requestor.getInterface(Ci.nsIObserver);
+    var observer = request.responseObserver;
 
     var mainAction = {
       label: gNavigatorBundle.getString("offlineApps.allowStoring.label"),
       accessKey: gNavigatorBundle.getString("offlineApps.allowStoring.accesskey"),
       callback() {
         observer.observe(null, responseTopic,
                          Ci.nsIPermissionManager.ALLOW_ACTION);
       }
--- a/dom/indexedDB/PermissionRequestBase.cpp
+++ b/dom/indexedDB/PermissionRequestBase.cpp
@@ -186,34 +186,32 @@ PermissionRequestBase::SetExplicitPermis
                                           aIntPermission,
                                           nsIPermissionManager::EXPIRE_NEVER,
                                           /* aExpireTime */ 0);
   if (NS_WARN_IF(NS_FAILED(rv))) {
     return;
   }
 }
 
-NS_IMPL_ISUPPORTS(PermissionRequestBase, nsIObserver, nsIInterfaceRequestor)
+NS_IMPL_ISUPPORTS(PermissionRequestBase, nsIObserver, nsIIDBPermissionsRequest)
 
 NS_IMETHODIMP
-PermissionRequestBase::GetInterface(const nsIID& aIID,
-                                    void** aResult)
+PermissionRequestBase::GetBrowserElement(Element** aElement)
 {
   AssertSanity();
-
-  if (aIID.Equals(NS_GET_IID(nsIObserver))) {
-    return QueryInterface(aIID, aResult);
-  }
+  *aElement = do_AddRef(mOwnerElement).take();
+  return NS_OK;
+}
 
-  if (aIID.Equals(NS_GET_IID(nsIDOMNode)) && mOwnerElement) {
-    return mOwnerElement->QueryInterface(aIID, aResult);
-  }
-
-  *aResult = nullptr;
-  return NS_ERROR_NOT_AVAILABLE;
+NS_IMETHODIMP
+PermissionRequestBase::GetResponseObserver(nsIObserver** aObserver)
+{
+  AssertSanity();
+  *aObserver = do_AddRef(this).take();
+  return NS_OK;
 }
 
 NS_IMETHODIMP
 PermissionRequestBase::Observe(nsISupports* aSubject,
                                const char* aTopic,
                                const char16_t* aData)
 {
   AssertSanity();
--- a/dom/indexedDB/PermissionRequestBase.h
+++ b/dom/indexedDB/PermissionRequestBase.h
@@ -4,34 +4,34 @@
  * 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 mozilla_dom_indexeddb_permissionrequestbase_h__
 #define mozilla_dom_indexeddb_permissionrequestbase_h__
 
 #include "mozilla/Attributes.h"
 #include "nsCOMPtr.h"
-#include "nsIInterfaceRequestor.h"
+#include "nsIIDBPermissionsRequest.h"
 #include "nsIObserver.h"
 #include "nsIPermissionManager.h"
 #include "nsISupportsImpl.h"
 #include "nsString.h"
 
 class nsIPrincipal;
 
 namespace mozilla {
 namespace dom {
 
 class Element;
 
 namespace indexedDB {
 
 class PermissionRequestBase
   : public nsIObserver
-  , public nsIInterfaceRequestor
+  , public nsIIDBPermissionsRequest
 {
   nsCOMPtr<Element> mOwnerElement;
   nsCOMPtr<nsIPrincipal> mPrincipal;
 
 public:
   enum PermissionValue {
     kPermissionAllowed = nsIPermissionManager::ALLOW_ACTION,
     kPermissionDenied = nsIPermissionManager::DENY_ACTION,
@@ -66,16 +66,16 @@ protected:
   OnPromptComplete(PermissionValue aPermissionValue) = 0;
 
 private:
   void
   SetExplicitPermission(nsIPrincipal* aPrincipal,
                         uint32_t aIntPermission);
 
   NS_DECL_NSIOBSERVER
-  NS_DECL_NSIINTERFACEREQUESTOR
+  NS_DECL_NSIIDBPERMISSIONSREQUEST
 };
 
 } // namespace indexedDB
 } // namespace dom
 } // namespace mozilla
 
 #endif // mozilla_dom_indexeddb_permissionrequestbase_h__
--- a/dom/indexedDB/moz.build
+++ b/dom/indexedDB/moz.build
@@ -104,8 +104,14 @@ if CONFIG['CC_TYPE'] in ('clang', 'gcc')
 LOCAL_INCLUDES += [
     '/db/sqlite3/src',
     '/dom/base',
     '/dom/storage',
     '/ipc/glue',
     '/xpcom/build',
     '/xpcom/threads',
 ]
+
+XPIDL_SOURCES += [
+    'nsIIDBPermissionsRequest.idl',
+]
+
+XPIDL_MODULE = 'dom_indexeddb'
new file mode 100644
--- /dev/null
+++ b/dom/indexedDB/nsIIDBPermissionsRequest.idl
@@ -0,0 +1,24 @@
+/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* 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/. */
+
+/**
+ * Interface for IDB permission requests.  This is passed as the
+ * subject for the permission request observer service notifications.
+ */
+#include "nsISupports.idl"
+
+interface nsIObserver;
+
+webidl Element;
+
+[scriptable, builtinclass, uuid(c3493c65-0530-496e-995c-bcd38dbfce21)]
+interface nsIIDBPermissionsRequest : nsISupports
+{
+  // The <browser> element the permission request is coming from.
+  readonly attribute Element browserElement;
+
+  // The nsIObserver that can be used to send the reply notification.
+  readonly attribute nsIObserver responseObserver;
+};
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -5384,19 +5384,19 @@ var IndexedDB = {
     Services.obs.addObserver(this, this._permissionsPrompt);
   },
 
   observe: function IndexedDB_observe(subject, topic, data) {
     if (topic != this._permissionsPrompt) {
       throw new Error("Unexpected topic!");
     }
 
-    let requestor = subject.QueryInterface(Ci.nsIInterfaceRequestor);
-
-    let browser = requestor.getInterface(Ci.nsIDOMNode);
+    let request = subject.QueryInterface(Ci.nsIIDBPermissionsRequest);
+
+    let browser = request.browserElement;
     let tab = BrowserApp.getTabForBrowser(browser);
     if (!tab)
       return;
 
     let host = browser.currentURI.asciiHost;
 
     let strings = Strings.browser;
 
@@ -5406,17 +5406,17 @@ var IndexedDB = {
       responseTopic = this._permissionsResponse;
     }
 
     const firstTimeoutDuration = 300000; // 5 minutes
 
     let timeoutId;
 
     let notificationID = responseTopic + host;
-    let observer = requestor.getInterface(Ci.nsIObserver);
+    let observer = request.responseObserver;
 
     // This will be set to the result of PopupNotifications.show() below, or to
     // the result of PopupNotifications.getNotification() if this is a
     // quotaCancel notification.
     let notification;
 
     function timeoutNotification() {
       // Remove the notification.