Bug 797206 - Remove GetPrincipalAndFrame. r=bz
authorBobby Holley <bobbyholley@gmail.com>
Mon, 29 Oct 2012 15:55:35 +0100
changeset 111804 8d042bf5002d3de4abfde5ccd0c3fb8aa71ab285
parent 111803 fe7466681e36a949b1cb053b74d41ccbbc3cc84d
child 111805 acfb2d79235b74f959fafbef0513881365dc1d1b
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersbz
bugs797206
milestone19.0a1
Bug 797206 - Remove GetPrincipalAndFrame. r=bz
caps/include/nsScriptSecurityManager.h
caps/src/nsScriptSecurityManager.cpp
--- a/caps/include/nsScriptSecurityManager.h
+++ b/caps/include/nsScriptSecurityManager.h
@@ -426,45 +426,31 @@ private:
 
     // Returns null if a principal cannot be found.  Note that rv can be NS_OK
     // when this happens -- this means that there was no script for the
     // context.  Callers MUST pass in a non-null rv here.
     nsIPrincipal*
     GetSubjectPrincipal(JSContext* cx, nsresult* rv);
 
     // Returns null if a principal cannot be found.  Note that rv can be NS_OK
-    // when this happens -- this means that there was no script for the frame.
-    // Callers MUST pass in a non-null rv here.
-    nsIPrincipal*
-    GetFramePrincipal(JSContext* cx, JSStackFrame* fp, nsresult* rv);
-
-    // Returns null if a principal cannot be found.  Note that rv can be NS_OK
     // when this happens -- this means that there was no script.  Callers MUST
     // pass in a non-null rv here.
     static nsIPrincipal*
     GetScriptPrincipal(JSScript* script, nsresult* rv);
 
     // Returns null if a principal cannot be found.  Note that rv can be NS_OK
     // when this happens -- this means that there was no script associated
     // with the function object, and no global object associated with the scope
     // of obj (the last object on its parent chain).  If the caller is walking
     // the JS stack, fp must point to the current frame in the stack iteration.
     // Callers MUST pass in a non-null rv here.
     static nsIPrincipal*
     GetFunctionObjectPrincipal(JSContext* cx, JSObject* obj, JSStackFrame *fp,
                                nsresult* rv);
 
-    // Returns null if a principal cannot be found.  Note that rv can be NS_OK
-    // when this happens -- this means that there was no script
-    // running.  Callers MUST pass in a non-null rv here.
-    nsIPrincipal*
-    GetPrincipalAndFrame(JSContext *cx,
-                         JSStackFrame** frameResult,
-                         nsresult* rv);
-
     /**
      * Check capability levels for an |aObj| that implements
      * nsISecurityCheckedComponent.
      *
      * NB: This function also checks to see if aObj is a plugin and the user
      * has set the "security.xpconnect.plugin.unrestricted" pref to allow
      * anybody to script plugin objects from anywhere.
      *
--- a/caps/src/nsScriptSecurityManager.cpp
+++ b/caps/src/nsScriptSecurityManager.cpp
@@ -2032,96 +2032,16 @@ nsScriptSecurityManager::GetFunctionObje
             *rv = NS_ERROR_FAILURE;
         return result;
     }
 
     return GetScriptPrincipal(script, rv);
 }
 
 nsIPrincipal*
-nsScriptSecurityManager::GetFramePrincipal(JSContext *cx,
-                                           JSStackFrame *fp,
-                                           nsresult *rv)
-{
-    NS_PRECONDITION(rv, "Null out param");
-    JSObject *obj = JS_GetFrameFunctionObject(cx, fp);
-    if (!obj)
-    {
-        // Must be in a top-level script. Get principal from the script.
-        JSScript *script = JS_GetFrameScript(cx, fp);
-        return GetScriptPrincipal(script, rv);
-    }
-
-    nsIPrincipal* result = GetFunctionObjectPrincipal(cx, obj, fp, rv);
-
-#ifdef DEBUG
-    if (NS_SUCCEEDED(*rv) && !result)
-    {
-        JSFunction *fun = JS_GetObjectFunction(obj);
-        JSScript *script = JS_GetFunctionScript(cx, fun);
-
-        NS_ASSERTION(!script, "Null principal for non-native function!");
-    }
-#endif
-
-    return result;
-}
-
-nsIPrincipal*
-nsScriptSecurityManager::GetPrincipalAndFrame(JSContext *cx,
-                                              JSStackFrame **frameResult,
-                                              nsresult* rv)
-{
-    NS_PRECONDITION(rv, "Null out param");
-    //-- If there's no principal on the stack, look at the global object
-    //   and return the innermost frame for annotations.
-    *rv = NS_OK;
-
-    if (cx)
-    {
-        // Get principals from innermost JavaScript frame.
-        JSStackFrame *fp = nullptr; // tell JS_BrokenFrameIterator to start at innermost
-        for (fp = JS_BrokenFrameIterator(cx, &fp); fp; fp = JS_BrokenFrameIterator(cx, &fp))
-        {
-            nsIPrincipal* result = GetFramePrincipal(cx, fp, rv);
-            if (result)
-            {
-                NS_ASSERTION(NS_SUCCEEDED(*rv), "Weird return");
-                *frameResult = fp;
-                return result;
-            }
-        }
-
-        nsIScriptContextPrincipal* scp =
-            GetScriptContextPrincipalFromJSContext(cx);
-        if (scp)
-        {
-            nsIScriptObjectPrincipal* globalData = scp->GetObjectPrincipal();
-            if (!globalData)
-            {
-                *rv = NS_ERROR_FAILURE;
-                return nullptr;
-            }
-
-            // Note that we're not in a loop or anything, and nothing comes
-            // after this point in the function, so we can just return here.
-            nsIPrincipal* result = globalData->GetPrincipal();
-            if (result)
-            {
-                JSStackFrame *inner = nullptr;
-                *frameResult = JS_BrokenFrameIterator(cx, &inner);
-                return result;
-            }
-        }
-    }
-
-    return nullptr;
-}
-
-nsIPrincipal*
 nsScriptSecurityManager::GetSubjectPrincipal(JSContext *cx,
                                              nsresult* rv)
 {
     *rv = NS_OK;
     JSCompartment *compartment = js::GetContextCompartment(cx);
 
     // The context should always be in a compartment, either one it has entered
     // or the one associated with its global.