From 30a0d1ff9d3f4f864b13a97073b4efa418e3da32 Mon Sep 17 00:00:00 2001 From: Doug Turner Date: Thu, 9 Sep 2010 22:00:08 -0700 Subject: [PATCH] Bug 594261 - IPC part - Factor out geolocation prompt into something that can be reused. r=chris jones, a=stuart --HG-- rename : dom/src/geolocation/PGeolocationRequest.ipdl => dom/ipc/PContentPermissionRequest.ipdl extra : rebase_source : 73f75b6f4c4deae71337dd2a9925d15aefcaacb8 --- dom/ipc/Makefile.in | 4 +- dom/ipc/PBrowser.ipdl | 6 +-- dom/ipc/PCOMContentPermissionRequestChild.h | 54 +++++++++++++++++++ .../PContentPermissionRequest.ipdl} | 2 +- dom/ipc/TabChild.cpp | 15 +++--- dom/ipc/TabChild.h | 4 +- dom/ipc/TabParent.cpp | 12 +++-- dom/ipc/TabParent.h | 4 +- dom/ipc/ipdl.mk | 1 + dom/src/geolocation/ipdl.mk | 40 -------------- dom/src/geolocation/nsGeolocation.cpp | 9 ++-- dom/src/geolocation/nsGeolocation.h | 9 +++- dom/src/geolocation/nsGeolocationOOP.h | 4 +- ipc/ipdl/Makefile.in | 1 - 14 files changed, 93 insertions(+), 72 deletions(-) create mode 100644 dom/ipc/PCOMContentPermissionRequestChild.h rename dom/{src/geolocation/PGeolocationRequest.ipdl => ipc/PContentPermissionRequest.ipdl} (98%) delete mode 100644 dom/src/geolocation/ipdl.mk diff --git a/dom/ipc/Makefile.in b/dom/ipc/Makefile.in index a582adbbbceb..659d69711a50 100644 --- a/dom/ipc/Makefile.in +++ b/dom/ipc/Makefile.in @@ -47,7 +47,7 @@ LIBXUL_LIBRARY = 1 FORCE_STATIC_LIB = 1 EXPORT_LIBRARY = 1 -EXPORTS = TabMessageUtils.h +EXPORTS = TabMessageUtils.h PCOMContentPermissionRequestChild.h EXPORTS_NAMESPACES = mozilla mozilla/dom @@ -80,10 +80,10 @@ LOCAL_INCLUDES += \ -I$(srcdir)/../../content/base/src \ -I$(srcdir)/../../content/events/src \ -I$(srcdir)/../../toolkit/components/places/src \ - -I$(srcdir)/../src/geolocation \ -I$(topsrcdir)/chrome/src \ -I$(topsrcdir)/uriloader/exthandler \ -I$(srcdir)/../../netwerk/base/src \ + -I$(srcdir)/../src/geolocation \ $(NULL) CXXFLAGS += $(TK_CFLAGS) diff --git a/dom/ipc/PBrowser.ipdl b/dom/ipc/PBrowser.ipdl index 7e372129e053..5b026a916e6f 100644 --- a/dom/ipc/PBrowser.ipdl +++ b/dom/ipc/PBrowser.ipdl @@ -42,7 +42,7 @@ include protocol PContentDialog; include protocol PDocumentRenderer; include protocol PDocumentRendererShmem; include protocol PDocumentRendererNativeID; -include protocol PGeolocationRequest; +include protocol PContentPermissionRequest; include protocol PExternalHelperApp; include "mozilla/TabTypes.h"; @@ -71,7 +71,7 @@ rpc protocol PBrowser manages PDocumentRenderer; manages PDocumentRendererShmem; manages PDocumentRendererNativeID; - manages PGeolocationRequest; + manages PContentPermissionRequest; manages PExternalHelperApp; both: @@ -114,7 +114,7 @@ parent: QueryContentResult(nsQueryContentEvent event); - PGeolocationRequest(URI uri); + PContentPermissionRequest(nsCString aType, URI uri); PContentDialog(PRUint32 aType, nsCString aName, nsCString aFeatures, PRInt32[] aIntParams, nsString[] aStringParams); diff --git a/dom/ipc/PCOMContentPermissionRequestChild.h b/dom/ipc/PCOMContentPermissionRequestChild.h new file mode 100644 index 000000000000..d0f98e3a8b2e --- /dev/null +++ b/dom/ipc/PCOMContentPermissionRequestChild.h @@ -0,0 +1,54 @@ +/* ***** BEGIN LICENSE BLOCK ***** + * Version: MPL 1.1/GPL 2.0/LGPL 2.1 + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * The Original Code is mozilla.org code. + * + * The Initial Developer of the Original Code is + * The Mozilla Foundation + * Portions created by the Initial Developer are Copyright (C) 2010 + * the Initial Developer. All Rights Reserved. + * + * Contributor(s): + * Doug Turner (Original Author) + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPL"), or + * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), + * in which case the provisions of the GPL or the LGPL are applicable instead + * of those above. If you wish to allow use of your version of this file only + * under the terms of either the GPL or the LGPL, and not to allow others to + * use your version of this file under the terms of the MPL, indicate your + * decision by deleting the provisions above and replace them with the notice + * and other provisions required by the GPL or the LGPL. If you do not delete + * the provisions above, a recipient may use your version of this file under + * the terms of any one of the MPL, the GPL or the LGPL. + * + * ***** END LICENSE BLOCK ***** */ + +#include "mozilla/dom/PContentPermissionRequestChild.h" +// Microsoft's API Name hackery sucks +#undef CreateEvent + +/* + 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; +}; diff --git a/dom/src/geolocation/PGeolocationRequest.ipdl b/dom/ipc/PContentPermissionRequest.ipdl similarity index 98% rename from dom/src/geolocation/PGeolocationRequest.ipdl rename to dom/ipc/PContentPermissionRequest.ipdl index ed797cc9e5e7..f6b3645f65b7 100644 --- a/dom/src/geolocation/PGeolocationRequest.ipdl +++ b/dom/ipc/PContentPermissionRequest.ipdl @@ -43,7 +43,7 @@ using IPC::URI; namespace mozilla { namespace dom { -protocol PGeolocationRequest +protocol PContentPermissionRequest { manager PBrowser; diff --git a/dom/ipc/TabChild.cpp b/dom/ipc/TabChild.cpp index bfd4ce3e6e76..6d01bd5e90f1 100644 --- a/dom/ipc/TabChild.cpp +++ b/dom/ipc/TabChild.cpp @@ -87,7 +87,7 @@ #include "nsIFrame.h" #include "nsIView.h" #include "nsIEventListenerManager.h" -#include "nsGeolocation.h" +#include "PCOMContentPermissionRequestChild.h" #ifdef MOZ_WIDGET_QT #include @@ -968,21 +968,18 @@ TabChild::DeallocPContentDialog(PContentDialogChild* aDialog) return true; } -/* The PGeolocationRequestChild actor is implemented by a refcounted - nsGeolocationRequest, and has an identical lifetime. */ - -PGeolocationRequestChild* -TabChild::AllocPGeolocationRequest(const IPC::URI&) +PContentPermissionRequestChild* +TabChild::AllocPContentPermissionRequest(const nsCString& aType, const IPC::URI&) { NS_RUNTIMEABORT("unused"); return nsnull; } bool -TabChild::DeallocPGeolocationRequest(PGeolocationRequestChild* actor) +TabChild::DeallocPContentPermissionRequest(PContentPermissionRequestChild* actor) { - static_cast(actor)->Release(); - return true; + static_cast(actor)->IPDLRelease(); + return true; } bool diff --git a/dom/ipc/TabChild.h b/dom/ipc/TabChild.h index 370a4085f111..489aee78910f 100644 --- a/dom/ipc/TabChild.h +++ b/dom/ipc/TabChild.h @@ -283,8 +283,8 @@ public: const gfxMatrix& aMatrix, const PRUint32& aNativeID); - virtual PGeolocationRequestChild* AllocPGeolocationRequest(const IPC::URI& uri); - virtual bool DeallocPGeolocationRequest(PGeolocationRequestChild* actor); + virtual PContentPermissionRequestChild* AllocPContentPermissionRequest(const nsCString& aType, const IPC::URI& uri); + virtual bool DeallocPContentPermissionRequest(PContentPermissionRequestChild* actor); nsIWebNavigation* WebNavigation() { return mWebNav; } diff --git a/dom/ipc/TabParent.cpp b/dom/ipc/TabParent.cpp index c8ca19162ab2..d1da4f166876 100644 --- a/dom/ipc/TabParent.cpp +++ b/dom/ipc/TabParent.cpp @@ -524,14 +524,18 @@ TabParent::DeallocPDocumentRendererNativeID(PDocumentRendererNativeIDParent* act return true; } -PGeolocationRequestParent* -TabParent::AllocPGeolocationRequest(const IPC::URI& uri) +PContentPermissionRequestParent* +TabParent::AllocPContentPermissionRequest(const nsCString& type, const IPC::URI& uri) { - return new GeolocationRequestParent(mFrameElement, uri); + if (type.Equals(NS_LITERAL_CSTRING("geolocation"))) { + return new GeolocationRequestParent(mFrameElement, uri); + } + + return nsnull; } bool -TabParent::DeallocPGeolocationRequest(PGeolocationRequestParent* actor) +TabParent::DeallocPContentPermissionRequest(PContentPermissionRequestParent* actor) { delete actor; return true; diff --git a/dom/ipc/TabParent.h b/dom/ipc/TabParent.h index 67bf4bcaf2e3..877197f85a8f 100644 --- a/dom/ipc/TabParent.h +++ b/dom/ipc/TabParent.h @@ -199,8 +199,8 @@ public: virtual bool DeallocPDocumentRendererNativeID(PDocumentRendererNativeIDParent* actor); - virtual PGeolocationRequestParent* AllocPGeolocationRequest(const IPC::URI& uri); - virtual bool DeallocPGeolocationRequest(PGeolocationRequestParent* actor); + virtual PContentPermissionRequestParent* AllocPContentPermissionRequest(const nsCString& aType, const IPC::URI& uri); + virtual bool DeallocPContentPermissionRequest(PContentPermissionRequestParent* actor); JSBool GetGlobalJSObject(JSContext* cx, JSObject** globalp); diff --git a/dom/ipc/ipdl.mk b/dom/ipc/ipdl.mk index 7643436fa452..c93d162fd913 100644 --- a/dom/ipc/ipdl.mk +++ b/dom/ipc/ipdl.mk @@ -41,4 +41,5 @@ IPDLSRCS = \ PDocumentRenderer.ipdl \ PDocumentRendererNativeID.ipdl \ PDocumentRendererShmem.ipdl \ + PContentPermissionRequest.ipdl \ $(NULL) diff --git a/dom/src/geolocation/ipdl.mk b/dom/src/geolocation/ipdl.mk deleted file mode 100644 index 0f7a70909e31..000000000000 --- a/dom/src/geolocation/ipdl.mk +++ /dev/null @@ -1,40 +0,0 @@ -# ***** BEGIN LICENSE BLOCK ***** -# Version: MPL 1.1/GPL 2.0/LGPL 2.1 -# -# The contents of this file are subject to the Mozilla Public License Version -# 1.1 (the "License"); you may not use this file except in compliance with -# the License. You may obtain a copy of the License at -# http://www.mozilla.org/MPL/ -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License -# for the specific language governing rights and limitations under the -# License. -# -# The Original Code is Geolocation code. -# -# The Initial Developer of the Original Code is -# the Mozilla Foundation. -# Portions created by the Initial Developer are Copyright (C) 2010 -# the Initial Developer. All Rights Reserved. -# -# Contributor(s): -# Josh Matthews (Initial Developer) -# -# Alternatively, the contents of this file may be used under the terms of -# either the GNU General Public License Version 2 or later (the "GPL"), or -# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), -# in which case the provisions of the GPL or the LGPL are applicable instead -# of those above. If you wish to allow use of your version of this file only -# under the terms of either the GPL or the LGPL, and not to allow others to -# use your version of this file under the terms of the MPL, indicate your -# decision by deleting the provisions above and replace them with the notice -# and other provisions required by the GPL or the LGPL. If you do not delete -# the provisions above, a recipient may use your version of this file under -# the terms of any one of the MPL, the GPL or the LGPL. -# -# ***** END LICENSE BLOCK ***** - -IPDLSRCS = \ - PGeolocationRequest.ipdl \ - $(NULL) diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index fccd0036b605..68dc2dc64cc1 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -1115,13 +1115,14 @@ nsGeolocation::RegisterRequestWithPrompt(nsGeolocationRequest* request) // the one and only TabChild. TabChild* child = GetTabChildFrom(window->GetDocShell()); - child->SendPGeolocationRequestConstructor(request, IPC::URI(mURI)); - // Retain a reference so the object isn't deleted without IPDL's knowledge. - // Corresponding release occurs in DeallocPGeolocationRequest. + // Corresponding release occurs in DeallocPContentPermissionRequest. request->AddRef(); - unused << request->Sendprompt(); + nsCString type = NS_LITERAL_CSTRING("geolocation"); + child->SendPContentPermissionRequestConstructor(request, type, IPC::URI(mURI)); + + request->Sendprompt(); return; } #endif diff --git a/dom/src/geolocation/nsGeolocation.h b/dom/src/geolocation/nsGeolocation.h index 4561dec8a3a1..c4157c568d5f 100644 --- a/dom/src/geolocation/nsGeolocation.h +++ b/dom/src/geolocation/nsGeolocation.h @@ -38,7 +38,7 @@ #define nsGeoLocation_h #ifdef MOZ_IPC -#include "mozilla/dom/PGeolocationRequestChild.h" +#include "mozilla/dom/PContentPermissionRequestChild.h" // Microsoft's API Name hackery sucks #undef CreateEvent #endif @@ -67,6 +67,10 @@ #include "nsIGeolocationProvider.h" #include "nsIContentPermissionPrompt.h" +#ifdef MOZ_IPC +#include "PCOMContentPermissionRequestChild.h" +#endif + class nsGeolocationService; class nsGeolocation; @@ -74,7 +78,7 @@ class nsGeolocationRequest : public nsIContentPermissionRequest , public nsITimerCallback #ifdef MOZ_IPC - , public mozilla::dom::PGeolocationRequestChild + , public PCOMContentPermissionRequestChild #endif { public: @@ -100,6 +104,7 @@ class nsGeolocationRequest #ifdef MOZ_IPC bool Recv__delete__(const bool& allow); + void IPDLRelease() { Release(); } #endif private: diff --git a/dom/src/geolocation/nsGeolocationOOP.h b/dom/src/geolocation/nsGeolocationOOP.h index 4e9be6f57639..08226977810c 100644 --- a/dom/src/geolocation/nsGeolocationOOP.h +++ b/dom/src/geolocation/nsGeolocationOOP.h @@ -45,14 +45,14 @@ #include "nsString.h" #include "nsIDOMElement.h" -#include "mozilla/dom/PGeolocationRequestParent.h" +#include "mozilla/dom/PContentPermissionRequestParent.h" class nsGeolocationRequestProxy; namespace mozilla { namespace dom { -class GeolocationRequestParent : public PGeolocationRequestParent +class GeolocationRequestParent : public PContentPermissionRequestParent { public: GeolocationRequestParent(nsIDOMElement *element, const IPC::URI& principal); diff --git a/ipc/ipdl/Makefile.in b/ipc/ipdl/Makefile.in index bc4c35cc5b8c..a62c7f969daf 100644 --- a/ipc/ipdl/Makefile.in +++ b/ipc/ipdl/Makefile.in @@ -55,7 +55,6 @@ EXPORT_LIBRARY = 1 ## IPDLDIRS = \ uriloader/exthandler \ - dom/src/geolocation \ dom/plugins \ dom/ipc \ gfx/layers/ipc \