Bug 769586 - Make PopupWindowManager using principal to test permissions instead of URI. r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Sun, 15 Jul 2012 18:37:31 -0700
changeset 99374 66a9604f532679a43c53dbe3444a6ffa3629fb2d
parent 99373 e72e124b791aabcf9944ed1a8a5f72c08fa504dc
child 99375 27e4b9cbed7438d797e85864ffe2c26fb9f50ec0
push id1316
push userakeybl@mozilla.com
push dateMon, 27 Aug 2012 22:37:00 +0000
treeherdermozilla-esr52@6fdf9985acfe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssicking
bugs769586
milestone16.0a1
Bug 769586 - Make PopupWindowManager using principal to test permissions instead of URI. r=sicking
content/html/content/src/nsHTMLInputElement.cpp
dom/base/nsGlobalWindow.cpp
dom/media/MediaManager.cpp
extensions/cookie/nsPopupWindowManager.cpp
extensions/cookie/nsPopupWindowManager.h
xpfe/appshell/public/nsIPopupWindowManager.idl
--- a/content/html/content/src/nsHTMLInputElement.cpp
+++ b/content/html/content/src/nsHTMLInputElement.cpp
@@ -247,17 +247,17 @@ AsyncClickHandler::Run()
     nsCOMPtr<nsIPopupWindowManager> pm =
       do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID);
 
     if (!pm) {
       return NS_OK;
     }
 
     PRUint32 permission;
-    pm->TestPermission(doc->GetDocumentURI(), &permission);
+    pm->TestPermission(doc->NodePrincipal(), &permission);
     if (permission == nsIPopupWindowManager::DENY_POPUP) {
       nsCOMPtr<nsIDOMDocument> domDoc = do_QueryInterface(doc);
       nsGlobalWindow::FirePopupBlockedEvent(domDoc, win, nsnull, EmptyString(), EmptyString());
       return NS_OK;
     }
   }
 
   // Get Loc title
--- a/dom/base/nsGlobalWindow.cpp
+++ b/dom/base/nsGlobalWindow.cpp
@@ -5657,17 +5657,17 @@ bool IsPopupBlocked(nsIDOMDocument* aDoc
     return false;
   }
 
   bool blocked = true;
   nsCOMPtr<nsIDocument> doc(do_QueryInterface(aDoc));
 
   if (doc) {
     PRUint32 permission = nsIPopupWindowManager::ALLOW_POPUP;
-    pm->TestPermission(doc->GetDocumentURI(), &permission);
+    pm->TestPermission(doc->NodePrincipal(), &permission);
     blocked = (permission == nsIPopupWindowManager::DENY_POPUP);
   }
   return blocked;
 }
 
 /* static */
 void 
 nsGlobalWindow::FirePopupBlockedEvent(nsIDOMDocument* aDoc,
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -373,17 +373,17 @@ MediaManager::GetUserMedia(nsPIDOMWindow
     nsCOMPtr<nsIPopupWindowManager> pm =
       do_GetService(NS_POPUPWINDOWMANAGER_CONTRACTID);
     if (!pm) {
       return NS_ERROR_FAILURE;
     }
 
     PRUint32 permission;
     nsCOMPtr<nsIDocument> doc = aWindow->GetExtantDoc();
-    pm->TestPermission(doc->GetDocumentURI(), &permission);
+    pm->TestPermission(doc->NodePrincipal(), &permission);
     if (aWindow && (permission == nsIPopupWindowManager::DENY_POPUP)) {
       nsCOMPtr<nsIDOMDocument> domDoc = aWindow->GetExtantDocument();
       nsGlobalWindow::FirePopupBlockedEvent(
         domDoc, aWindow, nsnull, EmptyString(), EmptyString()
       );
       return NS_ERROR_FAILURE;
     }
   }
--- a/extensions/cookie/nsPopupWindowManager.cpp
+++ b/extensions/cookie/nsPopupWindowManager.cpp
@@ -4,16 +4,18 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsPopupWindowManager.h"
 
 #include "nsCRT.h"
 #include "nsIServiceManager.h"
 #include "nsIPrefService.h"
 #include "nsIPrefBranch.h"
+#include "nsIPrincipal.h"
+#include "nsIURI.h"
 
 /**
  * The Popup Window Manager maintains popup window permissions by website.
  */
 
 static const char kPopupDisablePref[] = "dom.disable_open_during_load";
 
 //*****************************************************************************
@@ -56,30 +58,27 @@ nsPopupWindowManager::Init()
   return NS_OK;
 }
 
 //*****************************************************************************
 //*** nsPopupWindowManager::nsIPopupWindowManager
 //*****************************************************************************
 
 NS_IMETHODIMP
-nsPopupWindowManager::TestPermission(nsIURI *aURI, PRUint32 *aPermission)
+nsPopupWindowManager::TestPermission(nsIPrincipal* aPrincipal,
+                                     PRUint32 *aPermission)
 {
-  NS_ENSURE_ARG_POINTER(aURI);
+  NS_ENSURE_ARG_POINTER(aPrincipal);
   NS_ENSURE_ARG_POINTER(aPermission);
 
-  nsresult rv;
   PRUint32 permit;
-
   *aPermission = mPolicy;
 
   if (mPermissionManager) {
-    rv = mPermissionManager->TestPermission(aURI, "popup", &permit);
-
-    if (NS_SUCCEEDED(rv)) {
+    if (NS_SUCCEEDED(mPermissionManager->TestPermissionFromPrincipal(aPrincipal, "popup", &permit))) {
       // Share some constants between interfaces?
       if (permit == nsIPermissionManager::ALLOW_ACTION) {
         *aPermission = ALLOW_POPUP;
       } else if (permit == nsIPermissionManager::DENY_ACTION) {
         *aPermission = DENY_POPUP;
       }
     }
   }
--- a/extensions/cookie/nsPopupWindowManager.h
+++ b/extensions/cookie/nsPopupWindowManager.h
@@ -8,18 +8,16 @@
 
 #include "nsCOMPtr.h"
 
 #include "nsIObserver.h"
 #include "nsIPermissionManager.h"
 #include "nsIPopupWindowManager.h"
 #include "nsWeakReference.h"
 
-class nsIURI;
-
 class nsPopupWindowManager : public nsIPopupWindowManager,
                              public nsIObserver,
                              public nsSupportsWeakReference {
 
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIPOPUPWINDOWMANAGER
   NS_DECL_NSIOBSERVER
--- a/xpfe/appshell/public/nsIPopupWindowManager.idl
+++ b/xpfe/appshell/public/nsIPopupWindowManager.idl
@@ -5,31 +5,31 @@
 
 /**
  * This is the interface to the Popup Window Manager: an object which
  * maintains popup window permissions by website.
  */
 
 #include "nsISupports.idl"
 
-interface nsIURI;
+interface nsIPrincipal;
 
-[scriptable, uuid(3210a6aa-b464-4f57-9335-b22815567cf1)]
+[scriptable, uuid(66386aa9-2088-4bae-82c7-9f58bc02be64)]
 interface nsIPopupWindowManager : nsISupports {
 
   /**
    * These values are returned by the testPermission method
    */
   const PRUint32 ALLOW_POPUP = 1;
   const PRUint32 DENY_POPUP = 2;
   const PRUint32 ALLOW_POPUP_WITH_PREJUDICE = 3;
 
   /**
    * Test whether a website has permission to show a popup window.
-   * @param   uri is the URI to be tested
+   * @param   principal is the principal to be tested
    * @return  one of the enumerated permission actions defined above
    */
-  PRUint32 testPermission(in nsIURI uri);
+  PRUint32 testPermission(in nsIPrincipal principal);
 };
 
 %{ C++
 #define NS_POPUPWINDOWMANAGER_CONTRACTID "@mozilla.org/PopupWindowManager;1"
 %}