Bug 594261 - IPC part - Factor out geolocation prompt into something that can be reused. r=chris jones, a=stuart
authorDoug Turner <dougt@dougt.org>
Thu, 09 Sep 2010 22:00:08 -0700
changeset 52354 caa83e7f002016bd02fb7d7adac0c62a0ea2881f
parent 52353 91808d29bce3dfe5005a78103f49437fe2cb1450
child 52355 da8eae9cbf24b434524e5b4e562e5f2b7ded1de0
push id15607
push userdougt@mozilla.com
push dateFri, 10 Sep 2010 05:03:28 +0000
treeherdermozilla-central@5a9dc4ef0736 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschris, stuart
bugs594261
milestone2.0b6pre
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 594261 - IPC part - Factor out geolocation prompt into something that can be reused. r=chris jones, a=stuart
dom/ipc/Makefile.in
dom/ipc/PBrowser.ipdl
dom/ipc/PCOMContentPermissionRequestChild.h
dom/ipc/PContentPermissionRequest.ipdl
dom/ipc/TabChild.cpp
dom/ipc/TabChild.h
dom/ipc/TabParent.cpp
dom/ipc/TabParent.h
dom/ipc/ipdl.mk
dom/src/geolocation/PGeolocationRequest.ipdl
dom/src/geolocation/ipdl.mk
dom/src/geolocation/nsGeolocation.cpp
dom/src/geolocation/nsGeolocation.h
dom/src/geolocation/nsGeolocationOOP.h
ipc/ipdl/Makefile.in
--- a/dom/ipc/Makefile.in
+++ b/dom/ipc/Makefile.in
@@ -42,17 +42,17 @@ VPATH = @srcdir@
 include $(DEPTH)/config/autoconf.mk
 
 MODULE = dom
 LIBRARY_NAME = domipc_s
 LIBXUL_LIBRARY = 1
 FORCE_STATIC_LIB = 1
 EXPORT_LIBRARY = 1
 
-EXPORTS = TabMessageUtils.h
+EXPORTS = TabMessageUtils.h PCOMContentPermissionRequestChild.h
 
 EXPORTS_NAMESPACES = mozilla mozilla/dom
 
 EXPORTS_mozilla = \
   TabTypes.h \
   $(NULL)
 
 EXPORTS_mozilla/dom = \
@@ -75,17 +75,17 @@ CPPSRCS = \
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/ipc/chromium/chromium-config.mk
 include $(topsrcdir)/config/rules.mk
 
 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)
 
 DEFINES += -DBIN_SUFFIX='"$(BIN_SUFFIX)"'
--- a/dom/ipc/PBrowser.ipdl
+++ b/dom/ipc/PBrowser.ipdl
@@ -37,17 +37,17 @@
  *
  * ***** END LICENSE BLOCK ***** */
 
 include protocol PContent;
 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";
 include "TabMessageUtils.h";
 include "gfxMatrix.h";
 include "mozilla/net/NeckoMessageUtils.h";
 include "IPC/nsGUIEventIPC.h";
 
@@ -66,17 +66,17 @@ namespace dom {
 rpc protocol PBrowser
 {
     manager PContent;
 
     manages PContentDialog;
     manages PDocumentRenderer;
     manages PDocumentRendererShmem;
     manages PDocumentRendererNativeID;
-    manages PGeolocationRequest;
+    manages PContentPermissionRequest;
     manages PExternalHelperApp;
 
 both:
     AsyncMessage(nsString aMessage, nsString aJSON);
 
 parent:
     /**
      * When child sends this message, parent should move focus to
@@ -109,17 +109,17 @@ parent:
 
     rpc CreateWindow() returns (PBrowser window);
 
     sync SyncMessage(nsString aMessage, nsString aJSON)
       returns (nsString[] retval);
 
     QueryContentResult(nsQueryContentEvent event);
 
-    PGeolocationRequest(URI uri);
+    PContentPermissionRequest(nsCString aType, URI uri);
 
     PContentDialog(PRUint32 aType, nsCString aName, nsCString aFeatures,
                    PRInt32[] aIntParams, nsString[] aStringParams);
 
     __delete__();
 
     PExternalHelperApp(URI uri, nsCString aMimeContentType, bool aForceSave, PRInt64 aContentLength);
 
new file mode 100644
--- /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 <dougt@mozilla.com>  (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;
+};
rename from dom/src/geolocation/PGeolocationRequest.ipdl
rename to dom/ipc/PContentPermissionRequest.ipdl
--- a/dom/src/geolocation/PGeolocationRequest.ipdl
+++ b/dom/ipc/PContentPermissionRequest.ipdl
@@ -38,17 +38,17 @@
 include protocol PBrowser;
 include "mozilla/net/NeckoMessageUtils.h";
 
 using IPC::URI;
 
 namespace mozilla {
 namespace dom {
 
-protocol PGeolocationRequest
+protocol PContentPermissionRequest
 {
   manager PBrowser;
 
 parent:
   prompt();
 
 child:
   __delete__(bool allow);
--- a/dom/ipc/TabChild.cpp
+++ b/dom/ipc/TabChild.cpp
@@ -82,17 +82,17 @@
 #include "nsIScriptGlobalObject.h"
 #include "nsWeakReference.h"
 #include "nsISecureBrowserUI.h"
 #include "nsISSLStatusProvider.h"
 #include "nsSerializationHelper.h"
 #include "nsIFrame.h"
 #include "nsIView.h"
 #include "nsIEventListenerManager.h"
-#include "nsGeolocation.h"
+#include "PCOMContentPermissionRequestChild.h"
 
 #ifdef MOZ_WIDGET_QT
 #include <QGraphicsView>
 #include <QGraphicsWidget>
 #endif
 
 #ifdef MOZ_WIDGET_GTK2
 #include <gdk/gdkx.h>
@@ -963,31 +963,28 @@ TabChild::AllocPContentDialog(const PRUi
 
 bool
 TabChild::DeallocPContentDialog(PContentDialogChild* aDialog)
 {
   delete 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<nsGeolocationRequest*>(actor)->Release();
-  return true;
+    static_cast<PCOMContentPermissionRequestChild*>(actor)->IPDLRelease();
+    return true;
 }
 
 bool
 TabChild::RecvActivateFrameEvent(const nsString& aType, const bool& capture)
 {
   nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
   NS_ENSURE_TRUE(window, true);
   nsCOMPtr<nsIDOMEventTarget> chromeHandler =
--- a/dom/ipc/TabChild.h
+++ b/dom/ipc/TabChild.h
@@ -278,18 +278,18 @@ public:
             const PRInt32& aW,
             const PRInt32& aH,
             const nsString& bgcolor,
             const PRUint32& flags,
             const bool& flush,
             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; }
 
     JSContext* GetJSContext() { return mCx; }
 
     nsIPrincipal* GetPrincipal() { return mPrincipal; }
 
 protected:
--- a/dom/ipc/TabParent.cpp
+++ b/dom/ipc/TabParent.cpp
@@ -519,24 +519,28 @@ TabParent::AllocPDocumentRendererNativeI
 
 bool
 TabParent::DeallocPDocumentRendererNativeID(PDocumentRendererNativeIDParent* actor)
 {
     delete actor;
     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;
 }
 
 void
 TabParent::SendMouseEvent(const nsAString& aType, float aX, float aY,
                           PRInt32 aButton, PRInt32 aClickCount,
--- a/dom/ipc/TabParent.h
+++ b/dom/ipc/TabParent.h
@@ -194,18 +194,18 @@ public:
             const nsString& bgcolor,
             const PRUint32& flags,
             const bool& flush,
             const gfxMatrix& aMatrix,
             const PRUint32& nativeID);
     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);
 
     NS_DECL_ISUPPORTS
     NS_DECL_NSIWEBPROGRESS
     NS_DECL_NSIAUTHPROMPTPROVIDER
     NS_DECL_NSISECUREBROWSERUI
     NS_DECL_NSISSLSTATUSPROVIDER
--- a/dom/ipc/ipdl.mk
+++ b/dom/ipc/ipdl.mk
@@ -36,9 +36,10 @@
 
 IPDLSRCS = \
   PBrowser.ipdl \
   PContent.ipdl \
   PContentDialog.ipdl \
   PDocumentRenderer.ipdl \
   PDocumentRendererNativeID.ipdl \
   PDocumentRendererShmem.ipdl \
+  PContentPermissionRequest.ipdl \
   $(NULL)
deleted file mode 100644
--- 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 <josh@joshmatthews.net> (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)
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -1110,23 +1110,24 @@ nsGeolocation::RegisterRequestWithPrompt
     nsCOMPtr<nsPIDOMWindow> window = do_QueryReferent(mOwner);
     if (!window)
       return;
 
     // because owner implements nsITabChild, we can assume that it is
     // 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
 
   if (nsContentUtils::GetBoolPref("geo.prompt.testing", PR_FALSE))
   {
     nsCOMPtr<nsIRunnable> ev  = new RequestAllowEvent(nsContentUtils::GetBoolPref("geo.prompt.testing.allow", PR_FALSE), request);
     NS_DispatchToMainThread(ev);
--- a/dom/src/geolocation/nsGeolocation.h
+++ b/dom/src/geolocation/nsGeolocation.h
@@ -33,17 +33,17 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef nsGeoLocation_h
 #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
 
 #include "nsCOMPtr.h"
 #include "nsAutoPtr.h"
 #include "nsCOMArray.h"
 #include "nsTArray.h"
@@ -62,24 +62,28 @@
 #include "nsIDOMGeoPositionOptions.h"
 #include "nsIDOMNavigatorGeolocation.h"
 
 #include "nsPIDOMWindow.h"
 
 #include "nsIGeolocationProvider.h"
 #include "nsIContentPermissionPrompt.h"
 
+#ifdef MOZ_IPC
+#include "PCOMContentPermissionRequestChild.h"
+#endif
+
 class nsGeolocationService;
 class nsGeolocation;
 
 class nsGeolocationRequest
  : public nsIContentPermissionRequest
  , public nsITimerCallback
 #ifdef MOZ_IPC
- , public mozilla::dom::PGeolocationRequestChild
+ , public PCOMContentPermissionRequestChild
 #endif
 {
  public:
   NS_DECL_CYCLE_COLLECTING_ISUPPORTS
   NS_DECL_NSICONTENTPERMISSIONREQUEST
   NS_DECL_NSITIMERCALLBACK
 
   NS_DECL_CYCLE_COLLECTION_CLASS_AMBIGUOUS(nsGeolocationRequest, nsIContentPermissionRequest)
@@ -95,16 +99,17 @@ class nsGeolocationRequest
   void MarkCleared();
   PRBool Allowed() {return mAllowed;}
   void SetTimeoutTimer();
 
   ~nsGeolocationRequest();
 
 #ifdef MOZ_IPC
   bool Recv__delete__(const bool& allow);
+  void IPDLRelease() { Release(); }
 #endif
 
  private:
 
   void NotifyError(PRInt16 errorCode);
   PRPackedBool mAllowed;
   PRPackedBool mCleared;
 
--- a/dom/src/geolocation/nsGeolocationOOP.h
+++ b/dom/src/geolocation/nsGeolocationOOP.h
@@ -40,24 +40,24 @@
 
 #include "base/basictypes.h"
 
 #include "nsIGeolocationProvider.h"
 #include "nsIContentPermissionPrompt.h"
 #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);
   virtual ~GeolocationRequestParent();
   
   nsCOMPtr<nsIURI>           mURI;
   nsCOMPtr<nsIDOMElement>    mElement;
   nsCOMPtr<nsGeolocationRequestProxy> mProxy;
--- a/ipc/ipdl/Makefile.in
+++ b/ipc/ipdl/Makefile.in
@@ -50,17 +50,16 @@ FORCE_STATIC_LIB = 1
 LIBXUL_LIBRARY = 1
 EXPORT_LIBRARY = 1
 
 ##-----------------------------------------------------------------------------
 ## When you add IPDL files to a source directory, list the directory here.
 ##
 IPDLDIRS =  \
   uriloader/exthandler \
-  dom/src/geolocation \
   dom/plugins  \
   dom/ipc  \
   gfx/layers/ipc \
   ipc/ipdl/test/cxx  \
   ipc/testshell  \
   js/ipc  \
   js/jetpack \
   netwerk/ipc  \