From 6bb8d86e9f83768a07342b2795980aaf4863ae2f Mon Sep 17 00:00:00 2001 From: Shih-Chiang Chien Date: Fri, 1 Aug 2014 15:22:20 +0800 Subject: [PATCH] Bug 1045975 - Use nsIDOMWindowUtils.askPermission in all types of permission request. r=smaug --- content/base/src/nsDocument.cpp | 16 +- dom/base/nsContentPermissionHelper.cpp | 209 ++++++++++-------- dom/base/nsContentPermissionHelper.h | 70 ++++-- dom/base/nsDOMWindowUtils.cpp | 38 +--- dom/camera/DOMCameraManager.cpp | 64 +----- dom/devicestorage/nsDeviceStorage.cpp | 155 +------------ dom/devicestorage/nsDeviceStorage.h | 6 - .../FileSystemPermissionRequest.cpp | 63 +----- dom/filesystem/FileSystemPermissionRequest.h | 15 +- dom/ipc/PCOMContentPermissionRequestChild.h | 38 ---- dom/ipc/TabChild.cpp | 29 +-- dom/ipc/TabChild.h | 7 - dom/ipc/TabParent.cpp | 2 +- dom/ipc/moz.build | 1 - dom/media/MediaPermissionGonk.cpp | 72 +----- dom/src/geolocation/nsGeolocation.cpp | 76 ++----- dom/src/notification/DesktopNotification.cpp | 72 +----- dom/src/notification/Notification.cpp | 64 +----- 18 files changed, 236 insertions(+), 761 deletions(-) delete mode 100644 dom/ipc/PCOMContentPermissionRequestChild.h diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index cfb884cc4dd..0cef447be04 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -11428,12 +11428,8 @@ public: // Handling a request from user input in non-fullscreen mode. // Do a normal permission check. - nsCOMPtr prompt = - do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(this); - } - + nsCOMPtr window = doc->GetInnerWindow(); + nsContentPermissionUtils::AskPermission(this, window); return NS_OK; } @@ -11462,10 +11458,10 @@ NS_IMETHODIMP nsPointerLockPermissionRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(NS_LITERAL_CSTRING("pointerLock"), - NS_LITERAL_CSTRING("unused"), - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("pointerLock"), + NS_LITERAL_CSTRING("unused"), + emptyOptions, + aTypes); } NS_IMETHODIMP diff --git a/dom/base/nsContentPermissionHelper.cpp b/dom/base/nsContentPermissionHelper.cpp index 98c35f49743..98e6ee2fba5 100644 --- a/dom/base/nsContentPermissionHelper.cpp +++ b/dom/base/nsContentPermissionHelper.cpp @@ -14,6 +14,7 @@ #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/PContentPermissionRequestParent.h" #include "mozilla/dom/ScriptSettings.h" +#include "mozilla/dom/TabChild.h" #include "mozilla/dom/TabParent.h" #include "mozilla/unused.h" #include "nsComponentManagerUtils.h" @@ -23,6 +24,7 @@ #include "nsCxPusher.h" #include "nsJSUtils.h" #include "nsISupportsPrimitives.h" +#include "nsServiceManagerUtils.h" using mozilla::unused; // using namespace mozilla::dom; @@ -153,9 +155,11 @@ ContentPermissionType::GetOptions(nsIArray** aOptions) return NS_OK; } -uint32_t -ConvertPermissionRequestToArray(nsTArray& aSrcArray, - nsIMutableArray* aDesArray) +// nsContentPermissionUtils + +/* static */ uint32_t +nsContentPermissionUtils::ConvertPermissionRequestToArray(nsTArray& aSrcArray, + nsIMutableArray* aDesArray) { uint32_t len = aSrcArray.Length(); for (uint32_t i = 0; i < len; i++) { @@ -168,11 +172,46 @@ ConvertPermissionRequestToArray(nsTArray& aSrcArray, return len; } -nsresult -CreatePermissionArray(const nsACString& aType, - const nsACString& aAccess, - const nsTArray& aOptions, - nsIArray** aTypesArray) +/* static */ uint32_t +nsContentPermissionUtils::ConvertArrayToPermissionRequest(nsIArray* aSrcArray, + nsTArray& aDesArray) +{ + uint32_t len = 0; + aSrcArray->GetLength(&len); + for (uint32_t i = 0; i < len; i++) { + nsCOMPtr cpt = do_QueryElementAt(aSrcArray, i); + nsAutoCString type; + nsAutoCString access; + cpt->GetType(type); + cpt->GetAccess(access); + + nsCOMPtr optionArray; + cpt->GetOptions(getter_AddRefs(optionArray)); + uint32_t optionsLength = 0; + if (optionArray) { + optionArray->GetLength(&optionsLength); + } + nsTArray options; + for (uint32_t j = 0; j < optionsLength; ++j) { + nsCOMPtr isupportsString = do_QueryElementAt(optionArray, j); + if (isupportsString) { + nsString option; + isupportsString->GetData(option); + options.AppendElement(option); + } + } + + aDesArray.AppendElement(PermissionRequest(type, access, options)); + } + return len; +} + + +/* static */ nsresult +nsContentPermissionUtils::CreatePermissionArray(const nsACString& aType, + const nsACString& aAccess, + const nsTArray& aOptions, + nsIArray** aTypesArray) { nsCOMPtr types = do_CreateInstance(NS_ARRAY_CONTRACTID); nsRefPtr permType = new ContentPermissionType(aType, @@ -184,14 +223,60 @@ CreatePermissionArray(const nsACString& aType, return NS_OK; } -PContentPermissionRequestParent* -CreateContentPermissionRequestParent(const nsTArray& aRequests, - Element* element, - const IPC::Principal& principal) +/* static */ PContentPermissionRequestParent* +nsContentPermissionUtils::CreateContentPermissionRequestParent(const nsTArray& aRequests, + Element* element, + const IPC::Principal& principal) { return new ContentPermissionRequestParent(aRequests, element, principal); } +/* static */ nsresult +nsContentPermissionUtils::AskPermission(nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow) +{ + MOZ_ASSERT(!aWindow || aWindow->IsInnerWindow()); + NS_ENSURE_STATE(aWindow && aWindow->IsCurrentInnerWindow()); + + // for content process + if (XRE_GetProcessType() == GeckoProcessType_Content) { + + nsRefPtr req = + new RemotePermissionRequest(aRequest, aWindow); + + MOZ_ASSERT(NS_IsMainThread()); // IPC can only be execute on main thread. + + TabChild* child = TabChild::GetFrom(aWindow->GetDocShell()); + NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); + + nsCOMPtr typeArray; + nsresult rv = aRequest->GetTypes(getter_AddRefs(typeArray)); + NS_ENSURE_SUCCESS(rv, rv); + + nsTArray permArray; + ConvertArrayToPermissionRequest(typeArray, permArray); + + nsCOMPtr principal; + rv = aRequest->GetPrincipal(getter_AddRefs(principal)); + NS_ENSURE_SUCCESS(rv, rv); + + req->IPDLAddRef(); + child->SendPContentPermissionRequestConstructor(req, + permArray, + IPC::Principal(principal)); + + req->Sendprompt(); + return NS_OK; + } + + // for chrome process + nsCOMPtr prompt = + do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); + if (prompt) { + prompt->Prompt(aRequest); + } + return NS_OK; +} + } // namespace dom } // namespace mozilla @@ -213,7 +298,7 @@ nsContentPermissionRequestProxy::Init(const nsTArray& request mParent = parent; mPermissionRequests = requests; - nsCOMPtr prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); + nsCOMPtr prompt = do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); if (!prompt) { return NS_ERROR_FAILURE; } @@ -234,7 +319,7 @@ NS_IMETHODIMP nsContentPermissionRequestProxy::GetTypes(nsIArray** aTypes) { nsCOMPtr types = do_CreateInstance(NS_ARRAY_CONTRACTID); - if (ConvertPermissionRequestToArray(mPermissionRequests, types)) { + if (mozilla::dom::nsContentPermissionUtils::ConvertPermissionRequestToArray(mPermissionRequests, types)) { types.forget(aTypes); return NS_OK; } @@ -362,110 +447,50 @@ nsContentPermissionRequestProxy::Allow(JS::HandleValue aChoices) // RemotePermissionRequest -// static -uint32_t -RemotePermissionRequest::ConvertArrayToPermissionRequest( - nsIArray* aSrcArray, - nsTArray& aDesArray) -{ - uint32_t len = 0; - aSrcArray->GetLength(&len); - for (uint32_t i = 0; i < len; i++) { - nsCOMPtr cpt = do_QueryElementAt(aSrcArray, i); - nsAutoCString type; - nsAutoCString access; - cpt->GetType(type); - cpt->GetAccess(access); - - nsCOMPtr optionArray; - cpt->GetOptions(getter_AddRefs(optionArray)); - uint32_t optionsLength = 0; - if (optionArray) { - optionArray->GetLength(&optionsLength); - } - nsTArray options; - for (uint32_t j = 0; j < optionsLength; ++j) { - nsCOMPtr isupportsString = do_QueryElementAt(optionArray, j); - if (isupportsString) { - nsString option; - isupportsString->GetData(option); - options.AppendElement(option); - } - } - - aDesArray.AppendElement(PermissionRequest(type, access, options)); - } - return len; -} - -NS_IMPL_ISUPPORTS(RemotePermissionRequest, nsIContentPermissionRequest) +NS_IMPL_ISUPPORTS0(RemotePermissionRequest) RemotePermissionRequest::RemotePermissionRequest( nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow) : mRequest(aRequest) , mWindow(aWindow) + , mIPCOpen(false) { } -// nsIContentPermissionRequest methods -NS_IMETHODIMP -RemotePermissionRequest::GetTypes(nsIArray** aTypes) +void +RemotePermissionRequest::DoCancel() { NS_ASSERTION(mRequest, "We need a request"); - return mRequest->GetTypes(aTypes); + mRequest->Cancel(); } -NS_IMETHODIMP -RemotePermissionRequest::GetPrincipal(nsIPrincipal **aRequestingPrincipal) -{ - NS_ENSURE_ARG_POINTER(aRequestingPrincipal); - - return mRequest->GetPrincipal(aRequestingPrincipal); -} - -NS_IMETHODIMP -RemotePermissionRequest::GetWindow(nsIDOMWindow** aRequestingWindow) -{ - NS_ENSURE_ARG_POINTER(aRequestingWindow); - - return mRequest->GetWindow(aRequestingWindow); -} - -NS_IMETHODIMP -RemotePermissionRequest::GetElement(nsIDOMElement** aRequestingElement) -{ - NS_ENSURE_ARG_POINTER(aRequestingElement); - *aRequestingElement = nullptr; - return NS_OK; -} - -NS_IMETHODIMP -RemotePermissionRequest::Cancel() +void +RemotePermissionRequest::DoAllow(JS::HandleValue aChoices) { NS_ASSERTION(mRequest, "We need a request"); - return mRequest->Cancel(); + mRequest->Allow(aChoices); } -NS_IMETHODIMP -RemotePermissionRequest::Allow(JS::HandleValue aChoices) -{ - NS_ASSERTION(mRequest, "We need a request"); - return mRequest->Allow(aChoices); -} - -// PCOMContentPermissionRequestChild +// PContentPermissionRequestChild bool RemotePermissionRequest::Recv__delete__(const bool& aAllow, const nsTArray& aChoices) { if (aAllow && mWindow->IsCurrentInnerWindow()) { + // Use 'undefined' if no choice is provided. + if (aChoices.IsEmpty()) { + DoAllow(JS::UndefinedHandleValue); + return true; + } + // Convert choices to a JS val if any. // {"type1": "choice1", "type2": "choiceA"} AutoJSAPI jsapi; if (NS_WARN_IF(!jsapi.Init(mWindow))) { return true; // This is not an IPC error. } + JSContext* cx = jsapi.cx(); JS::Rooted obj(cx); obj = JS_NewObject(cx, nullptr, JS::NullPtr(), JS::NullPtr()); @@ -479,9 +504,9 @@ RemotePermissionRequest::Recv__delete__(const bool& aAllow, } } JS::RootedValue val(cx, JS::ObjectValue(*obj)); - (void) Allow(val); + DoAllow(val); } else { - (void) Cancel(); + DoCancel(); } return true; } diff --git a/dom/base/nsContentPermissionHelper.h b/dom/base/nsContentPermissionHelper.h index cdf8d42cb5b..02c779c7d83 100644 --- a/dom/base/nsContentPermissionHelper.h +++ b/dom/base/nsContentPermissionHelper.h @@ -8,7 +8,11 @@ #include "nsIContentPermissionPrompt.h" #include "nsTArray.h" #include "nsIMutableArray.h" -#include "PCOMContentPermissionRequestChild.h" +#include "mozilla/dom/PContentPermissionRequestChild.h" +// Microsoft's API Name hackery sucks +// XXXbz Doing this in a header is a gigantic footgun. See +// https://bugzilla.mozilla.org/show_bug.cgi?id=932421#c3 for why. +#undef LoadImage class nsPIDOMWindow; class nsContentPermissionRequestProxy; @@ -49,18 +53,31 @@ protected: nsTArray mOptions; }; -uint32_t ConvertPermissionRequestToArray(nsTArray& aSrcArray, - nsIMutableArray* aDesArray); +class nsContentPermissionUtils +{ +public: + static uint32_t + ConvertPermissionRequestToArray(nsTArray& aSrcArray, + nsIMutableArray* aDesArray); -nsresult CreatePermissionArray(const nsACString& aType, - const nsACString& aAccess, - const nsTArray& aOptions, - nsIArray** aTypesArray); + static uint32_t + ConvertArrayToPermissionRequest(nsIArray* aSrcArray, + nsTArray& aDesArray); -PContentPermissionRequestParent* -CreateContentPermissionRequestParent(const nsTArray& aRequests, - Element* element, - const IPC::Principal& principal); + static nsresult + CreatePermissionArray(const nsACString& aType, + const nsACString& aAccess, + const nsTArray& aOptions, + nsIArray** aTypesArray); + + static PContentPermissionRequestParent* + CreateContentPermissionRequestParent(const nsTArray& aRequests, + Element* element, + const IPC::Principal& principal); + + static nsresult + AskPermission(nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow); +}; } // namespace dom } // namespace mozilla @@ -75,6 +92,7 @@ class nsContentPermissionRequestProxy : public nsIContentPermissionRequest nsresult Init(const nsTArray& requests, mozilla::dom::ContentPermissionRequestParent* parent); + void OnParentDestroyed(); private: @@ -88,12 +106,11 @@ class nsContentPermissionRequestProxy : public nsIContentPermissionRequest /** * RemotePermissionRequest will send a prompt ipdl request to b2g process. */ -class RemotePermissionRequest : public nsIContentPermissionRequest - , public PCOMContentPermissionRequestChild +class RemotePermissionRequest MOZ_FINAL : public nsISupports + , public mozilla::dom::PContentPermissionRequestChild { public: NS_DECL_ISUPPORTS - NS_DECL_NSICONTENTPERMISSIONREQUEST RemotePermissionRequest(nsIContentPermissionRequest* aRequest, nsPIDOMWindow* aWindow); @@ -101,16 +118,31 @@ public: // It will be called when prompt dismissed. virtual bool Recv__delete__(const bool &aAllow, const nsTArray& aChoices) MOZ_OVERRIDE; - virtual void IPDLRelease() MOZ_OVERRIDE { Release(); } - static uint32_t ConvertArrayToPermissionRequest( - nsIArray* aSrcArray, - nsTArray& aDesArray); + void IPDLAddRef() + { + mIPCOpen = true; + AddRef(); + } + + void IPDLRelease() + { + mIPCOpen = false; + Release(); + } + private: - virtual ~RemotePermissionRequest() {} + virtual ~RemotePermissionRequest() + { + MOZ_ASSERT(!mIPCOpen, "Protocol must not be open when RemotePermissionRequest is destroyed."); + } + + void DoAllow(JS::HandleValue aChoices); + void DoCancel(); nsCOMPtr mRequest; nsCOMPtr mWindow; + bool mIPCOpen; }; #endif // nsContentPermissionHelper_h diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 9e68f7e48bb..ae068f04002 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -3856,43 +3856,7 @@ NS_IMETHODIMP nsDOMWindowUtils::AskPermission(nsIContentPermissionRequest* aRequest) { nsCOMPtr window = do_QueryReferent(mWindow); - nsRefPtr req = - new RemotePermissionRequest(aRequest, window->GetCurrentInnerWindow()); - - // for content process - if (XRE_GetProcessType() == GeckoProcessType_Content) { - MOZ_ASSERT(NS_IsMainThread()); // IPC can only be execute on main thread. - - dom::TabChild* child = dom::TabChild::GetFrom(window->GetDocShell()); - NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); - - nsCOMPtr typeArray; - nsresult rv = req->GetTypes(getter_AddRefs(typeArray)); - NS_ENSURE_SUCCESS(rv, rv); - - nsTArray permArray; - RemotePermissionRequest::ConvertArrayToPermissionRequest(typeArray, permArray); - - nsCOMPtr principal; - rv = req->GetPrincipal(getter_AddRefs(principal)); - NS_ENSURE_SUCCESS(rv, rv); - - req->AddRef(); - child->SendPContentPermissionRequestConstructor(req, - permArray, - IPC::Principal(principal)); - - req->Sendprompt(); - return NS_OK; - } - - // for chrome process - nsCOMPtr prompt = - do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(req); - } - return NS_OK; + return nsContentPermissionUtils::AskPermission(aRequest, window->GetCurrentInnerWindow()); } NS_INTERFACE_MAP_BEGIN(nsTranslationNodeList) diff --git a/dom/camera/DOMCameraManager.cpp b/dom/camera/DOMCameraManager.cpp index 47ea95e0661..6a9667cb252 100644 --- a/dom/camera/DOMCameraManager.cpp +++ b/dom/camera/DOMCameraManager.cpp @@ -9,16 +9,16 @@ #include "nsPIDOMWindow.h" #include "mozilla/Services.h" #include "nsContentPermissionHelper.h" +#include "nsIContentPermissionPrompt.h" #include "nsIObserverService.h" #include "nsIPermissionManager.h" +#include "nsIScriptObjectPrincipal.h" #include "DOMCameraControl.h" #include "nsDOMClassInfo.h" #include "CameraCommon.h" #include "mozilla/dom/BindingUtils.h" #include "mozilla/dom/CameraManagerBinding.h" #include "mozilla/dom/PermissionMessageUtils.h" -#include "mozilla/dom/TabChild.h" -#include "PCOMContentPermissionRequestChild.h" using namespace mozilla; using namespace mozilla::dom; @@ -122,7 +122,6 @@ nsDOMCameraManager::CreateInstance(nsPIDOMWindow* aWindow) } class CameraPermissionRequest : public nsIContentPermissionRequest - , public PCOMContentPermissionRequestChild , public nsIRunnable { public: @@ -149,14 +148,6 @@ public: { } - bool Recv__delete__(const bool& aAllow, - const InfallibleTArray& choices); - - void IPDLRelease() - { - Release(); - } - protected: virtual ~CameraPermissionRequest() { @@ -188,48 +179,7 @@ NS_IMPL_CYCLE_COLLECTING_RELEASE(CameraPermissionRequest) NS_IMETHODIMP CameraPermissionRequest::Run() { - if (XRE_GetProcessType() == GeckoProcessType_Content) { - TabChild* child = TabChild::GetFrom(mWindow->GetDocShell()); - if (!child) { - return NS_ERROR_NOT_AVAILABLE; - } - - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. - AddRef(); - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest( - NS_LITERAL_CSTRING("camera"), - NS_LITERAL_CSTRING("unused"), - emptyOptions)); - child->SendPContentPermissionRequestConstructor(this, permArray, - IPC::Principal(mPrincipal)); - - Sendprompt(); - return NS_OK; - } - - nsCOMPtr prompt = - do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(this); - } - - return NS_OK; -} - -bool -CameraPermissionRequest::Recv__delete__(const bool& aAllow, - const InfallibleTArray& choices) -{ - if (aAllow) { - Allow(JS::UndefinedHandleValue); - } else { - Cancel(); - } - return true; + return nsContentPermissionUtils::AskPermission(this, mWindow); } NS_IMETHODIMP @@ -294,10 +244,10 @@ NS_IMETHODIMP CameraPermissionRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(NS_LITERAL_CSTRING("camera"), - NS_LITERAL_CSTRING("unused"), - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("camera"), + NS_LITERAL_CSTRING("unused"), + emptyOptions, + aTypes); } void diff --git a/dom/devicestorage/nsDeviceStorage.cpp b/dom/devicestorage/nsDeviceStorage.cpp index ec79a38e51c..51474687d10 100644 --- a/dom/devicestorage/nsDeviceStorage.cpp +++ b/dom/devicestorage/nsDeviceStorage.cpp @@ -18,7 +18,6 @@ #include "mozilla/dom/FileSystemUtils.h" #include "mozilla/dom/ipc/Blob.h" #include "mozilla/dom/PBrowserChild.h" -#include "mozilla/dom/PContentPermissionRequestChild.h" #include "mozilla/dom/PermissionMessageUtils.h" #include "mozilla/dom/Promise.h" #include "mozilla/dom/ScriptSettings.h" @@ -46,7 +45,6 @@ #include "nsContentUtils.h" #include "nsCxPusher.h" #include "nsXULAppAPI.h" -#include "TabChild.h" #include "DeviceStorageFileDescriptor.h" #include "DeviceStorageRequestChild.h" #include "nsCRT.h" @@ -1785,7 +1783,6 @@ StringToJsval(nsPIDOMWindow* aWindow, nsAString& aString, class DeviceStorageCursorRequest MOZ_FINAL : public nsIContentPermissionRequest - , public PCOMContentPermissionRequestChild { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -1797,24 +1794,6 @@ public: DeviceStorageCursorRequest(nsDOMDeviceStorageCursor* aCursor) : mCursor(aCursor) { } - bool Recv__delete__(const bool& allow, - const InfallibleTArray& choices) - { - MOZ_ASSERT(choices.IsEmpty(), "DeviceStorageCursor doesn't support permission choice"); - if (allow) { - Allow(JS::UndefinedHandleValue); - } - else { - Cancel(); - } - return true; - } - - void IPDLRelease() - { - Release(); - } - private: ~DeviceStorageCursorRequest() {} @@ -2049,10 +2028,10 @@ nsDOMDeviceStorageCursor::GetTypes(nsIArray** aTypes) NS_ENSURE_SUCCESS(rv, rv); nsTArray emptyOptions; - return CreatePermissionArray(type, - NS_LITERAL_CSTRING("read"), - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(type, + NS_LITERAL_CSTRING("read"), + emptyOptions, + aTypes); } NS_IMETHODIMP @@ -2137,27 +2116,6 @@ nsDOMDeviceStorageCursor::Continue(ErrorResult& aRv) mOkToCallContinue = false; } -bool -nsDOMDeviceStorageCursor::Recv__delete__(const bool& allow, - const InfallibleTArray& choices) -{ - MOZ_ASSERT(choices.IsEmpty(), "DeviceStorageCursor doesn't support permission choice"); - - if (allow) { - Allow(JS::UndefinedHandleValue); - } - else { - Cancel(); - } - return true; -} - -void -nsDOMDeviceStorageCursor::IPDLRelease() -{ - Release(); -} - void nsDOMDeviceStorageCursor::RequestComplete() { @@ -2706,7 +2664,6 @@ private: class DeviceStorageRequest MOZ_FINAL : public nsIContentPermissionRequest , public nsIRunnable - , public PCOMContentPermissionRequestChild { public: @@ -2774,7 +2731,8 @@ public: NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(DeviceStorageRequest, nsIContentPermissionRequest) - NS_IMETHOD Run() { + NS_IMETHOD Run() + { MOZ_ASSERT(NS_IsMainThread()); if (mozilla::Preferences::GetBool("device.storage.prompt.testing", false)) { @@ -2782,48 +2740,7 @@ public: return NS_OK; } - if (XRE_GetProcessType() == GeckoProcessType_Content) { - - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(mWindow->GetDocShell()); - if (!child) { - return NS_OK; - } - - // Retain a reference so the object isn't deleted without IPDL's - // knowledge. Corresponding release occurs in - // DeallocPContentPermissionRequest. - AddRef(); - - nsCString type; - nsresult rv = DeviceStorageTypeChecker::GetPermissionForType( - mFile->mStorageType, type); - if (NS_FAILED(rv)) { - return rv; - } - nsCString access; - rv = DeviceStorageTypeChecker::GetAccessForRequest( - DeviceStorageRequestType(mRequestType), access); - if (NS_FAILED(rv)) { - return rv; - } - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest(type, access, emptyOptions)); - child->SendPContentPermissionRequestConstructor( - this, permArray, IPC::Principal(mPrincipal)); - - Sendprompt(); - return NS_OK; - } - - nsCOMPtr prompt - = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(this); - } - return NS_OK; + return nsContentPermissionUtils::AskPermission(this, mWindow); } NS_IMETHODIMP GetTypes(nsIArray** aTypes) @@ -2843,7 +2760,7 @@ public: } nsTArray emptyOptions; - return CreatePermissionArray(type, access, emptyOptions, aTypes); + return nsContentPermissionUtils::CreatePermissionArray(type, access, emptyOptions, aTypes); } NS_IMETHOD GetPrincipal(nsIPrincipal * *aRequestingPrincipal) @@ -3208,25 +3125,6 @@ public: return NS_OK; } - bool Recv__delete__(const bool& allow, - const InfallibleTArray& choices) - { - MOZ_ASSERT(choices.IsEmpty(), "DeviceStorage doesn't support permission choice"); - - if (allow) { - Allow(JS::UndefinedHandleValue); - } - else { - Cancel(); - } - return true; - } - - void IPDLRelease() - { - Release(); - } - private: ~DeviceStorageRequest() {} @@ -4232,42 +4130,7 @@ nsDOMDeviceStorage::EnumerateInternal(const nsAString& aPath, return cursor.forget(); } - if (XRE_GetProcessType() == GeckoProcessType_Content) { - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(win->GetDocShell()); - if (!child) { - return cursor.forget(); - } - - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. - r->AddRef(); - - nsCString type; - aRv = DeviceStorageTypeChecker::GetPermissionForType(mStorageType, type); - if (aRv.Failed()) { - return nullptr; - } - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest(type, - NS_LITERAL_CSTRING("read"), - emptyOptions)); - child->SendPContentPermissionRequestConstructor(r, - permArray, - IPC::Principal(mPrincipal)); - - r->Sendprompt(); - - return cursor.forget(); - } - - nsCOMPtr prompt - = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(r); - } + nsContentPermissionUtils::AskPermission(r, win); return cursor.forget(); } diff --git a/dom/devicestorage/nsDeviceStorage.h b/dom/devicestorage/nsDeviceStorage.h index 18d0aab5fec..fd27ff65e2d 100644 --- a/dom/devicestorage/nsDeviceStorage.h +++ b/dom/devicestorage/nsDeviceStorage.h @@ -7,7 +7,6 @@ class nsPIDOMWindow; #include "mozilla/Attributes.h" -#include "PCOMContentPermissionRequestChild.h" #include "DOMRequest.h" #include "DOMCursor.h" @@ -191,7 +190,6 @@ private: class nsDOMDeviceStorageCursor MOZ_FINAL : public mozilla::dom::DOMCursor , public nsIContentPermissionRequest - , public PCOMContentPermissionRequestChild , public mozilla::dom::devicestorage::DeviceStorageRequestChildCallback { public: @@ -212,10 +210,6 @@ public: bool mOkToCallContinue; PRTime mSince; - virtual bool Recv__delete__(const bool& allow, - const InfallibleTArray& choices) MOZ_OVERRIDE; - virtual void IPDLRelease() MOZ_OVERRIDE; - void GetStorageType(nsAString & aType); void RequestComplete() MOZ_OVERRIDE; diff --git a/dom/filesystem/FileSystemPermissionRequest.cpp b/dom/filesystem/FileSystemPermissionRequest.cpp index 6ea1966a393..e3e9001e328 100644 --- a/dom/filesystem/FileSystemPermissionRequest.cpp +++ b/dom/filesystem/FileSystemPermissionRequest.cpp @@ -8,10 +8,9 @@ #include "mozilla/dom/FileSystemBase.h" #include "mozilla/dom/FileSystemTaskBase.h" #include "mozilla/dom/FileSystemUtils.h" -#include "mozilla/dom/TabChild.h" #include "nsIDocument.h" #include "nsPIDOMWindow.h" -#include "nsString.h" +#include "nsContentPermissionHelper.h" namespace mozilla { namespace dom { @@ -62,34 +61,14 @@ FileSystemPermissionRequest::~FileSystemPermissionRequest() { } -bool -FileSystemPermissionRequest::Recv__delete__(const bool& aAllow, - const InfallibleTArray& aChoices) -{ - MOZ_ASSERT(aChoices.IsEmpty(), - "FileSystemPermissionRequest doesn't support permission choice"); - if (aAllow) { - Allow(JS::UndefinedHandleValue); - } else { - Cancel(); - } - return true; -} - -void -FileSystemPermissionRequest::IPDLRelease() -{ - Release(); -} - NS_IMETHODIMP FileSystemPermissionRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(mPermissionType, - mPermissionAccess, - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(mPermissionType, + mPermissionAccess, + emptyOptions, + aTypes); } NS_IMETHODIMP @@ -147,42 +126,12 @@ FileSystemPermissionRequest::Run() return NS_OK; } - if (FileSystemUtils::IsParentProcess()) { - nsCOMPtr prompt - = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (!prompt || NS_FAILED(prompt->Prompt(this))) { - Cancel(); - } - return NS_OK; - } - if (!mWindow) { Cancel(); return NS_OK; } - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(mWindow->GetDocShell()); - if (!child) { - Cancel(); - return NS_OK; - } - - // Retain a reference so the object isn't deleted without IPDL's - // knowledge. Corresponding release occurs in - // DeallocPContentPermissionRequest. - AddRef(); - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest(mPermissionType, - mPermissionAccess, - emptyOptions)); - child->SendPContentPermissionRequestConstructor( - this, permArray, IPC::Principal(mPrincipal)); - - Sendprompt(); + nsContentPermissionUtils::AskPermission(this, mWindow); return NS_OK; } diff --git a/dom/filesystem/FileSystemPermissionRequest.h b/dom/filesystem/FileSystemPermissionRequest.h index 6513e9b7d58..e349c792c37 100644 --- a/dom/filesystem/FileSystemPermissionRequest.h +++ b/dom/filesystem/FileSystemPermissionRequest.h @@ -7,12 +7,11 @@ #ifndef mozilla_dom_FileSystemPermissionRequest_h #define mozilla_dom_FileSystemPermissionRequest_h -#include "PCOMContentPermissionRequestChild.h" #include "nsAutoPtr.h" -#include "nsContentPermissionHelper.h" #include "nsIRunnable.h" +#include "nsIContentPermissionPrompt.h" +#include "nsString.h" -class nsCString; class nsPIDOMWindow; namespace mozilla { @@ -23,22 +22,12 @@ class FileSystemTaskBase; class FileSystemPermissionRequest MOZ_FINAL : public nsIContentPermissionRequest , public nsIRunnable - , public PCOMContentPermissionRequestChild { public: // Request permission for the given task. static void RequestForTask(FileSystemTaskBase* aTask); - // Overrides PCOMContentPermissionRequestChild - - virtual void - IPDLRelease() MOZ_OVERRIDE; - - bool - Recv__delete__(const bool& aAllow, - const InfallibleTArray& aChoices) MOZ_OVERRIDE; - NS_DECL_THREADSAFE_ISUPPORTS NS_DECL_NSICONTENTPERMISSIONREQUEST NS_DECL_NSIRUNNABLE diff --git a/dom/ipc/PCOMContentPermissionRequestChild.h b/dom/ipc/PCOMContentPermissionRequestChild.h deleted file mode 100644 index 22f92bad68e..00000000000 --- a/dom/ipc/PCOMContentPermissionRequestChild.h +++ /dev/null @@ -1,38 +0,0 @@ -/* 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 PCOMContentPermissionRequestChild_h -#define PCOMContentPermissionRequestChild_h - -#include "mozilla/dom/PContentPermissionRequestChild.h" -// Microsoft's API Name hackery sucks -// XXXbz Doing this in a header is a gigantic footgun. See -// https://bugzilla.mozilla.org/show_bug.cgi?id=932421#c3 for why. -#undef CreateEvent -#undef LoadImage - -/* - PContentPermissionRequestChild implementations also are - XPCOM objects. Addref() is called on their implementation - before SendPContentPermissionRequestConstructor is called. - When Dealloc is called, IPDLRelease() is called. - Implementations of this method are expected to call - Release() on themselves. See Bug 594261 for more - information. - */ -class PCOMContentPermissionRequestChild : public mozilla::dom::PContentPermissionRequestChild { -public: - virtual void IPDLRelease() = 0; -#ifdef DEBUG - PCOMContentPermissionRequestChild() : mIPCOpen(false) {} - virtual ~PCOMContentPermissionRequestChild() { - // mIPCOpen is set to true in TabChild::SendPContentPermissionRequestConstructor - // and set to false in TabChild::DeallocPContentPermissionRequest - MOZ_ASSERT(!mIPCOpen, "Protocol must not be open when PCOMContentPermissionRequestChild is destroyed."); - } - bool mIPCOpen; -#endif /* DEBUG */ -}; - -#endif diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index f7e51bf67b9..9437454efff 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -68,7 +68,7 @@ #include "nsWeakReference.h" #include "nsWindowWatcher.h" #include "PermissionMessageUtils.h" -#include "PCOMContentPermissionRequestChild.h" +#include "nsContentPermissionHelper.h" #include "PuppetWidget.h" #include "StructuredCloneUtils.h" #include "nsViewportInfo.h" @@ -82,10 +82,6 @@ #include "nsColorPickerProxy.h" -#ifdef DEBUG -#include "PCOMContentPermissionRequestChild.h" -#endif /* DEBUG */ - #define BROWSER_ELEMENT_CHILD_SCRIPT \ NS_LITERAL_STRING("chrome://global/content/BrowserElementChild.js") @@ -1407,19 +1403,6 @@ TabChild::SendPendingTouchPreventedResponse(bool aPreventDefault, } } -#ifdef DEBUG -PContentPermissionRequestChild* -TabChild:: SendPContentPermissionRequestConstructor(PContentPermissionRequestChild* aActor, - const InfallibleTArray& aRequests, - const IPC::Principal& aPrincipal) -{ - PCOMContentPermissionRequestChild* child = static_cast(aActor); - PContentPermissionRequestChild* request = PBrowserChild::SendPContentPermissionRequestConstructor(aActor, aRequests, aPrincipal); - child->mIPCOpen = true; - return request; -} -#endif /* DEBUG */ - void TabChild::DestroyWindow() { @@ -2360,13 +2343,9 @@ TabChild::AllocPContentPermissionRequestChild(const InfallibleTArray(actor); -#ifdef DEBUG - child->mIPCOpen = false; -#endif /* DEBUG */ - child->IPDLRelease(); - return true; + RemotePermissionRequest* child = static_cast(actor); + child->IPDLRelease(); + return true; } PFilePickerChild* diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 35447c3a197..cfbd400987a 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -386,13 +386,6 @@ public: AllocPColorPickerChild(const nsString& title, const nsString& initialColor) MOZ_OVERRIDE; virtual bool DeallocPColorPickerChild(PColorPickerChild* actor) MOZ_OVERRIDE; -#ifdef DEBUG - virtual PContentPermissionRequestChild* - SendPContentPermissionRequestConstructor(PContentPermissionRequestChild* aActor, - const InfallibleTArray& aRequests, - const IPC::Principal& aPrincipal); -#endif /* DEBUG */ - virtual PContentPermissionRequestChild* AllocPContentPermissionRequestChild(const InfallibleTArray& aRequests, const IPC::Principal& aPrincipal) MOZ_OVERRIDE; diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index a5e166ea787..d25f2a52185 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -714,7 +714,7 @@ PContentPermissionRequestParent* TabParent::AllocPContentPermissionRequestParent(const InfallibleTArray& aRequests, const IPC::Principal& aPrincipal) { - return CreateContentPermissionRequestParent(aRequests, mFrameElement, aPrincipal); + return nsContentPermissionUtils::CreateContentPermissionRequestParent(aRequests, mFrameElement, aPrincipal); } bool diff --git a/dom/ipc/moz.build b/dom/ipc/moz.build index 76edcbe6ed8..006e5e1d3cf 100644 --- a/dom/ipc/moz.build +++ b/dom/ipc/moz.build @@ -6,7 +6,6 @@ EXPORTS += [ 'nsICachedFileDescriptorListener.h', - 'PCOMContentPermissionRequestChild.h', ] EXPORTS.mozilla.dom.ipc += [ diff --git a/dom/media/MediaPermissionGonk.cpp b/dom/media/MediaPermissionGonk.cpp index 8cab5e67e5c..2f4a78ff1de 100644 --- a/dom/media/MediaPermissionGonk.cpp +++ b/dom/media/MediaPermissionGonk.cpp @@ -16,9 +16,7 @@ #include "nsPIDOMWindow.h" #include "nsTArray.h" #include "GetUserMediaRequest.h" -#include "PCOMContentPermissionRequestChild.h" #include "mozilla/dom/PBrowserChild.h" -#include "mozilla/dom/TabChild.h" #include "mozilla/dom/MediaStreamTrackBinding.h" #include "nsISupportsPrimitives.h" #include "nsServiceManagerUtils.h" @@ -110,7 +108,6 @@ namespace { * to its owned type. */ class MediaPermissionRequest : public nsIContentPermissionRequest - , public PCOMContentPermissionRequestChild { public: NS_DECL_ISUPPORTS @@ -119,11 +116,6 @@ public: MediaPermissionRequest(nsRefPtr &aRequest, nsTArray > &aDevices); - // It will be called when prompt dismissed. - virtual bool Recv__delete__(const bool &allow, - const InfallibleTArray& choices) MOZ_OVERRIDE; - virtual void IPDLRelease() MOZ_OVERRIDE { Release(); } - already_AddRefed GetOwner(); protected: @@ -316,29 +308,6 @@ MediaPermissionRequest::GetOwner() return window.forget(); } -//PCOMContentPermissionRequestChild -bool -MediaPermissionRequest::Recv__delete__(const bool& allow, - const InfallibleTArray& choices) -{ - if (allow) { - // get selected device name for audio and video - nsString audioDevice, videoDevice; - for (uint32_t i = 0; i < choices.Length(); ++i) { - const nsString &choice = choices[i].choice(); - if (choices[i].type().EqualsLiteral(AUDIO_PERMISSION_NAME)) { - audioDevice = choice; - } else if (choices[i].type().EqualsLiteral(VIDEO_PERMISSION_NAME)) { - videoDevice = choice; - } - } - (void) DoAllow(audioDevice, videoDevice); - } else { - (void) Cancel(); - } - return true; -} - // Success callback for MediaManager::GetUserMediaDevices(). class MediaDeviceSuccessCallback: public nsIGetUserMediaDevicesSuccessCallback { @@ -400,45 +369,8 @@ MediaDeviceSuccessCallback::OnSuccess(nsIVariant* aDevices) nsresult MediaDeviceSuccessCallback::DoPrompt(nsRefPtr &req) { - // for content process - if (XRE_GetProcessType() == GeckoProcessType_Content) { - MOZ_ASSERT(NS_IsMainThread()); // IPC can only be execute on main thread. - - nsresult rv; - - nsCOMPtr window(req->GetOwner()); - NS_ENSURE_TRUE(window, NS_ERROR_FAILURE); - - dom::TabChild* child = dom::TabChild::GetFrom(window->GetDocShell()); - NS_ENSURE_TRUE(child, NS_ERROR_FAILURE); - - nsCOMPtr typeArray; - rv = req->GetTypes(getter_AddRefs(typeArray)); - NS_ENSURE_SUCCESS(rv, rv); - - nsTArray permArray; - RemotePermissionRequest::ConvertArrayToPermissionRequest(typeArray, permArray); - - nsCOMPtr principal; - rv = req->GetPrincipal(getter_AddRefs(principal)); - NS_ENSURE_SUCCESS(rv, rv); - - req->AddRef(); - child->SendPContentPermissionRequestConstructor(req, - permArray, - IPC::Principal(principal)); - - req->Sendprompt(); - return NS_OK; - } - - // for chrome process - nsCOMPtr prompt = - do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(req); - } - return NS_OK; + nsCOMPtr window(req->GetOwner()); + return dom::nsContentPermissionUtils::AskPermission(req, window); } // Error callback for MediaManager::GetUserMediaDevices() diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 02323d65304..e8353f17295 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -5,7 +5,6 @@ #include "nsXULAppAPI.h" #include "mozilla/dom/ContentChild.h" -#include "mozilla/dom/TabChild.h" #include "mozilla/Telemetry.h" #include "nsISettingsService.h" @@ -24,7 +23,6 @@ #include "mozilla/unused.h" #include "mozilla/Preferences.h" #include "mozilla/ClearOnShutdown.h" -#include "PCOMContentPermissionRequestChild.h" #include "mozilla/dom/PermissionMessageUtils.h" class nsIPrincipal; @@ -60,7 +58,6 @@ class nsGeolocationRequest : public nsIContentPermissionRequest , public nsITimerCallback , public nsIGeolocationUpdate - , public PCOMContentPermissionRequestChild { public: NS_DECL_CYCLE_COLLECTING_ISUPPORTS @@ -85,14 +82,10 @@ class nsGeolocationRequest void NotifyErrorAndShutdown(uint16_t); nsIPrincipal* GetPrincipal(); - virtual bool Recv__delete__(const bool& allow, - const InfallibleTArray& choices) MOZ_OVERRIDE; - virtual void IPDLRelease() MOZ_OVERRIDE { Release(); } - bool IsWatch() { return mIsWatchPositionRequest; } int32_t WatchId() { return mWatchId; } private: - ~nsGeolocationRequest(); + virtual ~nsGeolocationRequest(); bool mIsWatchPositionRequest; @@ -169,21 +162,22 @@ NS_IMPL_ISUPPORTS(GeolocationSettingsCallback, nsISettingsServiceCallback) class RequestPromptEvent : public nsRunnable { public: - RequestPromptEvent(nsGeolocationRequest* request) - : mRequest(request) + RequestPromptEvent(nsGeolocationRequest* aRequest, nsWeakPtr aWindow) + : mRequest(aRequest) + , mWindow(aWindow) { } - NS_IMETHOD Run() { - nsCOMPtr prompt = do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(mRequest); - } + NS_IMETHOD Run() + { + nsCOMPtr window = do_QueryReferent(mWindow); + nsContentPermissionUtils::AskPermission(mRequest, window); return NS_OK; } private: nsRefPtr mRequest; + nsWeakPtr mWindow; }; class RequestAllowEvent : public nsRunnable @@ -384,10 +378,10 @@ NS_IMETHODIMP nsGeolocationRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(NS_LITERAL_CSTRING("geolocation"), - NS_LITERAL_CSTRING("unused"), - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("geolocation"), + NS_LITERAL_CSTRING("unused"), + emptyOptions, + aTypes); } NS_IMETHODIMP @@ -600,18 +594,6 @@ nsGeolocationRequest::Shutdown() } } -bool nsGeolocationRequest::Recv__delete__(const bool& allow, - const InfallibleTArray& choices) -{ - MOZ_ASSERT(choices.IsEmpty(), "Geolocation doesn't support permission choice"); - - if (allow) { - (void) Allow(JS::UndefinedHandleValue); - } else { - (void) Cancel(); - } - return true; -} //////////////////////////////////////////////////// // nsGeolocationService //////////////////////////////////////////////////// @@ -1469,37 +1451,7 @@ Geolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) return true; } - if (XRE_GetProcessType() == GeckoProcessType_Content) { - nsCOMPtr window = do_QueryReferent(mOwner); - if (!window) { - return true; - } - - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(window->GetDocShell()); - if (!child) { - return false; - } - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest(NS_LITERAL_CSTRING("geolocation"), - NS_LITERAL_CSTRING("unused"), - emptyOptions)); - - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. - request->AddRef(); - child->SendPContentPermissionRequestConstructor(request, - permArray, - IPC::Principal(mPrincipal)); - - request->Sendprompt(); - return true; - } - - nsCOMPtr ev = new RequestPromptEvent(request); + nsCOMPtr ev = new RequestPromptEvent(request, mOwner); NS_DispatchToMainThread(ev); return true; } diff --git a/dom/src/notification/DesktopNotification.cpp b/dom/src/notification/DesktopNotification.cpp index 43886bdf0b4..c3ba7db189b 100644 --- a/dom/src/notification/DesktopNotification.cpp +++ b/dom/src/notification/DesktopNotification.cpp @@ -9,11 +9,9 @@ #include "nsXULAppAPI.h" #include "mozilla/dom/PBrowserChild.h" #include "nsIDOMDesktopNotification.h" -#include "TabChild.h" #include "mozilla/Preferences.h" #include "nsGlobalWindow.h" #include "nsIAppsService.h" -#include "PCOMContentPermissionRequestChild.h" #include "nsIScriptSecurityManager.h" #include "nsServiceManagerUtils.h" #include "PermissionMessageUtils.h" @@ -24,12 +22,10 @@ namespace dom { /* * Simple Request */ -class DesktopNotificationRequest : public nsIContentPermissionRequest, - public nsRunnable, - public PCOMContentPermissionRequestChild - +class DesktopNotificationRequest : public nsIContentPermissionRequest + , public nsRunnable { - ~DesktopNotificationRequest() + virtual ~DesktopNotificationRequest() { } @@ -42,27 +38,11 @@ public: NS_IMETHOD Run() MOZ_OVERRIDE { - nsCOMPtr prompt = - do_CreateInstance(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(this); - } + nsCOMPtr window = mDesktopNotification->GetOwner(); + nsContentPermissionUtils::AskPermission(this, window); return NS_OK; } - virtual bool Recv__delete__(const bool& aAllow, - const InfallibleTArray& choices) MOZ_OVERRIDE - { - MOZ_ASSERT(choices.IsEmpty(), "DesktopNotification doesn't support permission choice"); - if (aAllow) { - (void) Allow(JS::UndefinedHandleValue); - } else { - (void) Cancel(); - } - return true; - } - virtual void IPDLRelease() MOZ_OVERRIDE { Release(); } - nsRefPtr mDesktopNotification; }; @@ -164,38 +144,6 @@ DesktopNotification::Init() { nsRefPtr request = new DesktopNotificationRequest(this); - // if we are in the content process, then remote it to the parent. - if (XRE_GetProcessType() == GeckoProcessType_Content) { - - // if for some reason mOwner is null, just silently - // bail. The user will not see a notification, and that - // is fine. - if (!GetOwner()) - return; - - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild for this docshell. - TabChild* child = TabChild::GetFrom(GetOwner()->GetDocShell()); - - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. - nsRefPtr copy = request; - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest( - NS_LITERAL_CSTRING("desktop-notification"), - NS_LITERAL_CSTRING("unused"), - emptyOptions)); - child->SendPContentPermissionRequestConstructor(copy.forget().take(), - permArray, - IPC::Principal(mPrincipal)); - - request->Sendprompt(); - return; - } - - // otherwise, dispatch it NS_DispatchToMainThread(request); } @@ -310,7 +258,7 @@ DesktopNotificationCenter::WrapObject(JSContext* aCx) /* ------------------------------------------------------------------------ */ NS_IMPL_ISUPPORTS_INHERITED(DesktopNotificationRequest, nsRunnable, - nsIContentPermissionRequest) + nsIContentPermissionRequest) NS_IMETHODIMP DesktopNotificationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal) @@ -363,10 +311,10 @@ NS_IMETHODIMP DesktopNotificationRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"), - NS_LITERAL_CSTRING("unused"), - emptyOptions, - aTypes); + return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"), + NS_LITERAL_CSTRING("unused"), + emptyOptions, + aTypes); } } // namespace dom diff --git a/dom/src/notification/Notification.cpp b/dom/src/notification/Notification.cpp index 548da2bd121..b96dee21413 100644 --- a/dom/src/notification/Notification.cpp +++ b/dom/src/notification/Notification.cpp @@ -2,13 +2,11 @@ * 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 "PCOMContentPermissionRequestChild.h" #include "mozilla/dom/Notification.h" #include "mozilla/dom/AppNotificationServiceOptionsBinding.h" #include "mozilla/dom/OwningNonNull.h" #include "mozilla/dom/Promise.h" #include "mozilla/Preferences.h" -#include "TabChild.h" #include "nsContentUtils.h" #include "nsIAlertsService.h" #include "nsIAppsService.h" @@ -93,7 +91,7 @@ public: } private: - ~NotificationStorageCallback() + virtual ~NotificationStorageCallback() { DropData(); } @@ -144,7 +142,6 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(NotificationStorageCallback) NS_IMPL_CYCLE_COLLECTION_UNLINK_END class NotificationPermissionRequest : public nsIContentPermissionRequest, - public PCOMContentPermissionRequestChild, public nsIRunnable { public: @@ -160,10 +157,6 @@ public: mPermission(NotificationPermission::Default), mCallback(aCallback) {} - bool Recv__delete__(const bool& aAllow, - const InfallibleTArray& choices); - void IPDLRelease() { Release(); } - protected: virtual ~NotificationPermissionRequest() {} @@ -256,38 +249,7 @@ NotificationPermissionRequest::Run() return DispatchCallback(); } - if (XRE_GetProcessType() == GeckoProcessType_Content) { - // because owner implements nsITabChild, we can assume that it is - // the one and only TabChild. - TabChild* child = TabChild::GetFrom(mWindow->GetDocShell()); - if (!child) { - return NS_ERROR_NOT_AVAILABLE; - } - - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPContentPermissionRequest. - AddRef(); - - nsTArray permArray; - nsTArray emptyOptions; - permArray.AppendElement(PermissionRequest( - NS_LITERAL_CSTRING("desktop-notification"), - NS_LITERAL_CSTRING("unused"), - emptyOptions)); - child->SendPContentPermissionRequestConstructor(this, permArray, - IPC::Principal(mPrincipal)); - - Sendprompt(); - return NS_OK; - } - - nsCOMPtr prompt = - do_GetService(NS_CONTENT_PERMISSION_PROMPT_CONTRACTID); - if (prompt) { - prompt->Prompt(this); - } - - return NS_OK; + return nsContentPermissionUtils::AskPermission(this, mWindow); } NS_IMETHODIMP @@ -352,24 +314,10 @@ NS_IMETHODIMP NotificationPermissionRequest::GetTypes(nsIArray** aTypes) { nsTArray emptyOptions; - return CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"), - NS_LITERAL_CSTRING("unused"), - emptyOptions, - aTypes); -} - -bool -NotificationPermissionRequest::Recv__delete__(const bool& aAllow, - const InfallibleTArray& choices) -{ - MOZ_ASSERT(choices.IsEmpty(), "Notification doesn't support permission choice"); - - if (aAllow) { - (void) Allow(JS::UndefinedHandleValue); - } else { - (void) Cancel(); - } - return true; + return nsContentPermissionUtils::CreatePermissionArray(NS_LITERAL_CSTRING("desktop-notification"), + NS_LITERAL_CSTRING("unused"), + emptyOptions, + aTypes); } NS_IMPL_ISUPPORTS(NotificationTask, nsIRunnable)