Bug 327244 (1/2) - Remove nsIScriptSecurityManager::CheckLoadURIStr(). r=sicking
authorMounir Lamouri <mounir.lamouri@gmail.com>
Wed, 18 Jul 2012 13:35:15 -0700
changeset 102883 be7df3c9d50fe7cef0e4c980db17aa659938fe91
parent 102872 614017b8bd95732c891db13501044908fe07e19a
child 102884 489d944a6fe6f80f4f167d98d7314d78169b2d56
push idunknown
push userunknown
push dateunknown
reviewerssicking
bugs327244
milestone17.0a1
Bug 327244 (1/2) - Remove nsIScriptSecurityManager::CheckLoadURIStr(). r=sicking
caps/idl/nsIScriptSecurityManager.idl
caps/src/nsScriptSecurityManager.cpp
content/base/src/contentAreaDropListener.js
ipc/testshell/XPCShellEnvironment.cpp
js/xpconnect/shell/xpcshell.cpp
toolkit/content/nsDragAndDrop.js
--- a/caps/idl/nsIScriptSecurityManager.idl
+++ b/caps/idl/nsIScriptSecurityManager.idl
@@ -108,25 +108,16 @@ interface nsIScriptSecurityManager : nsI
      * load as well); if any of the versions of this URI is not allowed, this
      * function will return error code NS_ERROR_DOM_BAD_URI.
      */
     void checkLoadURIStrWithPrincipal(in nsIPrincipal aPrincipal,
                                       in AUTF8String uri,
                                       in unsigned long flags);
 
     /**
-     * Same as CheckLoadURI but takes string arguments for ease of use
-     * by scripts
-     *
-     * @deprecated Use checkLoadURIStrWithPrincipal instead of this function.
-     */
-    [deprecated] void checkLoadURIStr(in AUTF8String from, in AUTF8String uri,
-                                      in unsigned long flags);
-
-    /**
      * Check that the function 'funObj' is allowed to run on 'targetObj'
      *
      * Will return error code NS_ERROR_DOM_SECURITY_ERR if the function
      * should not run
      *
      * @param cx The current active JavaScript context.
      * @param funObj The function trying to run..
      * @param targetObj The object the function will run on.
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -1583,40 +1583,16 @@ nsScriptSecurityManager::ReportError(JSC
 #ifdef DEBUG
         fprintf(stderr, "%s\n", NS_LossyConvertUTF16toASCII(message).get());
 #endif
     }
     return NS_OK;
 }
 
 NS_IMETHODIMP
-nsScriptSecurityManager::CheckLoadURIStr(const nsACString& aSourceURIStr,
-                                         const nsACString& aTargetURIStr,
-                                         PRUint32 aFlags)
-{
-    // FIXME: bug 327244 -- this function should really die...  Really truly.
-    nsCOMPtr<nsIURI> source;
-    nsresult rv = NS_NewURI(getter_AddRefs(source), aSourceURIStr,
-                            nsnull, nsnull, sIOService);
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    // Note: this is not _quite_ right if aSourceURI has
-    // NS_NULLPRINCIPAL_SCHEME, but we'll just extract the scheme in
-    // CheckLoadURIWithPrincipal anyway, so this is good enough.  This method
-    // really needs to go away....
-    nsCOMPtr<nsIPrincipal> sourcePrincipal;
-    rv = CreateCodebasePrincipal(source,
-                                 getter_AddRefs(sourcePrincipal));
-    NS_ENSURE_SUCCESS(rv, rv);
-
-    return CheckLoadURIStrWithPrincipal(sourcePrincipal, aTargetURIStr,
-                                        aFlags);
-}
-
-NS_IMETHODIMP
 nsScriptSecurityManager::CheckLoadURIStrWithPrincipal(nsIPrincipal* aPrincipal,
                                                       const nsACString& aTargetURIStr,
                                                       PRUint32 aFlags)
 {
     nsresult rv;
     nsCOMPtr<nsIURI> target;
     rv = NS_NewURI(getter_AddRefs(target), aTargetURIStr,
                    nsnull, nsnull, sIOService);
--- a/content/base/src/contentAreaDropListener.js
+++ b/content/base/src/contentAreaDropListener.js
@@ -61,39 +61,39 @@ ContentAreaDropListener.prototype =
 
     // Strip leading and trailing whitespace, then try to create a
     // URI from the dropped string. If that succeeds, we're
     // dropping a URI and we need to do a security check to make
     // sure the source document can load the dropped URI.
     uriString = uriString.replace(/^\s*|\s*$/g, '');
 
     let uri;
+    let ioService = Cc["@mozilla.org/network/io-service;1"]
+                      .getService(Components.interfaces.nsIIOService);
     try {
       // Check that the uri is valid first and return an empty string if not.
       // It may just be plain text and should be ignored here
-      uri = Cc["@mozilla.org/network/io-service;1"].
-              getService(Components.interfaces.nsIIOService).
-              newURI(uriString, null, null);
+      uri = ioService.newURI(uriString, null, null);
     } catch (ex) { }
     if (!uri)
       return uriString;
 
     // uriString is a valid URI, so do the security check.
     let secMan = Cc["@mozilla.org/scriptsecuritymanager;1"].
                    getService(Ci.nsIScriptSecurityManager);
     let sourceNode = dataTransfer.mozSourceNode;
     let flags = secMan.STANDARD;
     if (disallowInherit)
       flags |= secMan.DISALLOW_INHERIT_PRINCIPAL;
 
     // Use file:/// as the default uri so that drops of file URIs are always allowed
-    if (sourceNode)
-      secMan.checkLoadURIStrWithPrincipal(sourceNode.nodePrincipal, uriString, flags);
-    else
-      secMan.checkLoadURIStr("file:///", uriString, flags);
+    let principal = sourceNode ? sourceNode.principal
+                               : secMan.getCodebasePrincipal(ioService.newURI("file:///", null, null));
+
+    secMan.checkLoadURIStrWithPrincipal(principal, uriString, flags);
 
     return uriString;
   },
 
   canDropLink: function(aEvent, aAllowSameDocument)
   {
     let dataTransfer = aEvent.dataTransfer;
     let types = dataTransfer.types;
--- a/ipc/testshell/XPCShellEnvironment.cpp
+++ b/ipc/testshell/XPCShellEnvironment.cpp
@@ -725,24 +725,16 @@ NS_IMETHODIMP
 FullTrustSecMan::CheckLoadURIStrWithPrincipal(nsIPrincipal *aPrincipal,
                                               const nsACString & uri,
                                               PRUint32 flags)
 {
     return NS_OK;
 }
 
 NS_IMETHODIMP
-FullTrustSecMan::CheckLoadURIStr(const nsACString & from,
-                                 const nsACString & uri,
-                                 PRUint32 flags)
-{
-    return NS_OK;
-}
-
-NS_IMETHODIMP
 FullTrustSecMan::CheckFunctionAccess(JSContext * cx,
                                      void * funObj,
                                      void * targetObj)
 {
     return NS_OK;
 }
 
 NS_IMETHODIMP
--- a/js/xpconnect/shell/xpcshell.cpp
+++ b/js/xpconnect/shell/xpcshell.cpp
@@ -1343,24 +1343,16 @@ FullTrustSecMan::CheckLoadURI(nsIURI *fr
 NS_IMETHODIMP
 FullTrustSecMan::CheckLoadURIStrWithPrincipal(nsIPrincipal *aPrincipal,
                                               const nsACString & uri,
                                               PRUint32 flags)
 {
     return NS_OK;
 }
 
-/* void checkLoadURIStr (in AUTF8String from, in AUTF8String uri, in unsigned long flags); */
-NS_IMETHODIMP
-FullTrustSecMan::CheckLoadURIStr(const nsACString & from,
-                                 const nsACString & uri, PRUint32 flags)
-{
-    return NS_OK;
-}
-
 /* [noscript] void checkFunctionAccess (in JSContextPtr cx, in voidPtr funObj, in voidPtr targetObj); */
 NS_IMETHODIMP
 FullTrustSecMan::CheckFunctionAccess(JSContext * cx, void * funObj,
                                      void * targetObj)
 {
     return NS_OK;
 }
 
--- a/toolkit/content/nsDragAndDrop.js
+++ b/toolkit/content/nsDragAndDrop.js
@@ -560,21 +560,20 @@ var nsDragAndDrop = {
       // sure the source document can load the dropped URI. We don't
       // so much care about creating the real URI here
       // (i.e. encoding differences etc don't matter), we just want
       // to know if aDraggedText really is a URI.
 
       aDraggedText = aDraggedText.replace(/^\s*|\s*$/g, '');
 
       var uri;
-
+      var ioService = Components.classes["@mozilla.org/network/io-service;1"]
+                                .getService(Components.interfaces.nsIIOService);
       try {
-        uri = Components.classes["@mozilla.org/network/io-service;1"]
-                        .getService(Components.interfaces.nsIIOService)
-                        .newURI(aDraggedText, null, null);
+        uri = ioService.newURI(aDraggedText, null, null);
       } catch (e) {
       }
 
       if (!uri)
         return;
 
       // aDraggedText is a URI, do the security check.
       const nsIScriptSecurityManager = Components.interfaces
@@ -583,21 +582,22 @@ var nsDragAndDrop = {
                              .getService(nsIScriptSecurityManager);
 
       if (!aDragSession)
         aDragSession = this.mDragService.getCurrentSession();
 
       var sourceDoc = aDragSession.sourceDocument;
       // Use "file:///" as the default sourceURI so that drops of file:// URIs
       // are always allowed.
-      var sourceURI = sourceDoc ? sourceDoc.documentURI : "file:///";
+      var principal = sourceDoc ? sourceDoc.nodePrincipal
+                                : secMan.getCodebasePrincipal(ioService.newURI("file:///", null, null));
 
       try {
-        secMan.checkLoadURIStr(sourceURI, aDraggedText,
-                               nsIScriptSecurityManager.STANDARD);
+        secMan.checkLoadURIStrWithPrincipal(principal, aDraggedText,
+                                            nsIScriptSecurityManager.STANDARD);
       } catch (e) {
         // Stop event propagation right here.
         aEvent.stopPropagation();
 
         throw "Drop of " + aDraggedText + " denied.";
       }
     }
 };