Bug 1197461 - e10s support for Permissions.revoke. r=poiru
authorMarco Castelluccio <mcastelluccio@mozilla.com>
Wed, 02 Mar 2016 21:09:48 +0000
changeset 322854 59b8d765123ce48d13db01a00a3d3fc628ad67e8
parent 322853 e978b825517d6d06d1071d179d5f0d89a069733c
child 322855 990eeaa39c299b43c06b5b9b04951c8cf8b8b421
push id5913
push userjlund@mozilla.com
push dateMon, 25 Apr 2016 16:57:49 +0000
treeherdermozilla-beta@dcaf0a6fa115 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspoiru
bugs1197461
milestone47.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 1197461 - e10s support for Permissions.revoke. r=poiru
dom/ipc/ContentParent.cpp
dom/ipc/ContentParent.h
dom/ipc/PContent.ipdl
dom/permission/Permissions.cpp
dom/permission/Permissions.h
dom/permission/moz.build
--- a/dom/ipc/ContentParent.cpp
+++ b/dom/ipc/ContentParent.cpp
@@ -62,16 +62,17 @@
 #include "mozilla/dom/ServiceWorkerRegistrar.h"
 #include "mozilla/dom/bluetooth/PBluetoothParent.h"
 #include "mozilla/dom/cellbroadcast/CellBroadcastParent.h"
 #include "mozilla/dom/devicestorage/DeviceStorageRequestParent.h"
 #include "mozilla/dom/icc/IccParent.h"
 #include "mozilla/dom/mobileconnection/MobileConnectionParent.h"
 #include "mozilla/dom/mobilemessage/SmsParent.h"
 #include "mozilla/dom/power/PowerManagerService.h"
+#include "mozilla/dom/Permissions.h"
 #include "mozilla/dom/PresentationParent.h"
 #include "mozilla/dom/PPresentationParent.h"
 #include "mozilla/dom/quota/QuotaManagerService.h"
 #include "mozilla/dom/telephony/TelephonyParent.h"
 #include "mozilla/dom/time/DateCacheCleaner.h"
 #include "mozilla/dom/voicemail/VoicemailParent.h"
 #include "mozilla/embedding/printingui/PrintingParent.h"
 #include "mozilla/hal_sandbox/PHalParent.h"
@@ -1049,16 +1050,24 @@ ContentParent::RecvUngrabPointer(const u
   return false;
 #else
   gdk_pointer_ungrab(aTime);
   return true;
 #endif
 }
 
 bool
+ContentParent::RecvRemovePermission(const IPC::Principal& aPrincipal,
+                                    const nsCString& aPermissionType,
+                                    nsresult* aRv) {
+  *aRv = Permissions::RemovePermission(aPrincipal, aPermissionType.get());
+  return true;
+}
+
+bool
 ContentParent::RecvConnectPluginBridge(const uint32_t& aPluginId, nsresult* aRv)
 {
   *aRv = NS_OK;
   // We don't need to get the run ID for the plugin, since we already got it
   // in the first call to SetupBridge in RecvLoadPlugin, so we pass in a dummy
   // pointer and just throw it away.
   uint32_t dummy = 0;
   return mozilla::plugins::SetupBridge(aPluginId, this, true, aRv, &dummy);
--- a/dom/ipc/ContentParent.h
+++ b/dom/ipc/ContentParent.h
@@ -208,16 +208,20 @@ public:
 
   virtual bool RecvFindPlugins(const uint32_t& aPluginEpoch,
                                nsresult* aRv,
                                nsTArray<PluginTag>* aPlugins,
                                uint32_t* aNewPluginEpoch) override;
 
   virtual bool RecvUngrabPointer(const uint32_t& aTime) override;
 
+  virtual bool RecvRemovePermission(const IPC::Principal& aPrincipal,
+                                    const nsCString& aPermissionType,
+                                    nsresult* aRv) override;
+
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(ContentParent, nsIObserver)
 
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSIOBSERVER
   NS_DECL_NSIDOMGEOPOSITIONCALLBACK
   NS_DECL_NSIDOMGEOPOSITIONERRORCALLBACK
 
   /**
--- a/dom/ipc/PContent.ipdl
+++ b/dom/ipc/PContent.ipdl
@@ -1185,15 +1185,17 @@ parent:
 
     /**
      * Tells the parent to ungrab the pointer on the default display.
      *
      * This is for GTK platforms where we have to ensure the pointer ungrab happens in the
      * chrome process as that's the process that receives the pointer event.
      */
     sync UngrabPointer(uint32_t time);
+
+    sync RemovePermission(Principal principal, nsCString permissionType) returns (nsresult rv);
 both:
      async AsyncMessage(nsString aMessage, ClonedMessageData aData,
                         CpowEntry[] aCpows, Principal aPrincipal);
 };
 
 }
 }
--- a/dom/permission/Permissions.cpp
+++ b/dom/permission/Permissions.cpp
@@ -1,16 +1,17 @@
 /* -*- 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/. */
 
 #include "mozilla/dom/Permissions.h"
 
+#include "mozilla/dom/ContentChild.h"
 #include "mozilla/dom/PermissionsBinding.h"
 #include "mozilla/dom/Promise.h"
 #include "mozilla/Services.h"
 #include "nsIPermissionManager.h"
 #include "PermissionUtils.h"
 
 namespace mozilla {
 namespace dom {
@@ -116,16 +117,29 @@ Permissions::Query(JSContext* aCx,
     promise->MaybeReject(aRv);
   } else {
     MOZ_ASSERT(status);
     promise->MaybeResolve(status);
   }
   return promise.forget();
 }
 
+/* static */ nsresult
+Permissions::RemovePermission(nsIPrincipal* aPrincipal, const char* aPermissionType)
+{
+  MOZ_ASSERT(XRE_IsParentProcess());
+
+  nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
+  if (NS_WARN_IF(!permMgr)) {
+    return NS_ERROR_FAILURE;
+  }
+
+  return permMgr->RemoveFromPrincipal(aPrincipal, aPermissionType);
+}
+
 already_AddRefed<Promise>
 Permissions::Revoke(JSContext* aCx,
                     JS::Handle<JSObject*> aPermission,
                     ErrorResult& aRv)
 {
   nsCOMPtr<nsIGlobalObject> global = do_QueryInterface(mWindow);
   if (!global) {
     aRv.Throw(NS_ERROR_UNEXPECTED);
@@ -151,17 +165,29 @@ Permissions::Revoke(JSContext* aCx,
   }
 
   nsCOMPtr<nsIPermissionManager> permMgr = services::GetPermissionManager();
   if (NS_WARN_IF(!permMgr)) {
     promise->MaybeReject(NS_ERROR_FAILURE);
     return promise.forget();
   }
 
-  nsresult rv = permMgr->RemoveFromPrincipal(document->NodePrincipal(), PermissionNameToType(permission.mName));
+  const char* permissionType = PermissionNameToType(permission.mName);
+
+  nsresult rv;
+  if (XRE_IsParentProcess()) {
+    rv = RemovePermission(document->NodePrincipal(), permissionType);
+  } else {
+    // Permissions can't be removed from the content process. Send a message
+    // to the parent; `ContentParent::RecvRemovePermission` will call
+    // `RemovePermission`.
+    ContentChild::GetSingleton()->SendRemovePermission(
+      IPC::Principal(document->NodePrincipal()), nsDependentCString(permissionType), &rv);
+  }
+
   if (NS_WARN_IF(NS_FAILED(rv))) {
     promise->MaybeReject(rv);
     return promise.forget();
   }
 
   RefPtr<PermissionStatus> status =
     CreatePermissionStatus(aCx, aPermission, mWindow, aRv);
   if (NS_WARN_IF(aRv.Failed())) {
--- a/dom/permission/Permissions.h
+++ b/dom/permission/Permissions.h
@@ -33,16 +33,18 @@ public:
 
   JSObject* WrapObject(JSContext* aCx,
                        JS::Handle<JSObject*> aGivenProto) override;
 
   already_AddRefed<Promise> Query(JSContext* aCx,
                                   JS::Handle<JSObject*> aPermission,
                                   ErrorResult& aRv);
 
+  static nsresult RemovePermission(nsIPrincipal* aPrincipal, const char* aPermissionType);
+
   already_AddRefed<Promise> Revoke(JSContext* aCx,
                                    JS::Handle<JSObject*> aPermission,
                                    ErrorResult& aRv);
 
 private:
   ~Permissions();
 
   nsCOMPtr<nsPIDOMWindowInner> mWindow;
--- a/dom/permission/moz.build
+++ b/dom/permission/moz.build
@@ -45,8 +45,10 @@ if CONFIG['MOZ_WEBSMS_BACKEND']:
 
 if CONFIG['MOZ_TIME_MANAGER']:
     MOCHITEST_MANIFESTS += ['tests/mochitest-time.ini']
 
 FINAL_LIBRARY = 'xul'
 
 if CONFIG['GNU_CXX']:
     CXXFLAGS += ['-Wshadow']
+
+include('/ipc/chromium/chromium-config.mozbuild')