diff --git a/docshell/base/LoadContext.cpp b/docshell/base/LoadContext.cpp index f08e049a0aa4..3a2ea33e0abe 100644 --- a/docshell/base/LoadContext.cpp +++ b/docshell/base/LoadContext.cpp @@ -7,7 +7,34 @@ #include "mozilla/Assertions.h" #include "mozilla/BasePrincipal.h" #include "mozilla/LoadContext.h" +#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI +#include "nsContentUtils.h" +#include "xpcpublic.h" +bool +nsILoadContext::GetOriginAttributes(mozilla::DocShellOriginAttributes& aAttrs) +{ + mozilla::dom::AutoJSAPI jsapi; + bool ok = jsapi.Init(xpc::PrivilegedJunkScope()); + NS_ENSURE_TRUE(ok, false); + JS::Rooted v(jsapi.cx()); + nsresult rv = GetOriginAttributes(&v); + NS_ENSURE_SUCCESS(rv, false); + NS_ENSURE_TRUE(v.isObject(), false); + JS::Rooted obj(jsapi.cx(), &v.toObject()); + + // If we're JS-implemented, the object will be left in a different (System-Principaled) + // scope, so we may need to enter its compartment. + MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj))); + JSAutoCompartment ac(jsapi.cx(), obj); + + mozilla::DocShellOriginAttributes attrs; + ok = attrs.Init(jsapi.cx(), v); + NS_ENSURE_TRUE(ok, false); + aAttrs = attrs; + return true; +} + namespace mozilla { NS_IMPL_ISUPPORTS(LoadContext, nsILoadContext, nsIInterfaceRequestor) diff --git a/docshell/base/nsILoadContext.idl b/docshell/base/nsILoadContext.idl index bbdea31dd791..b4badd627b07 100644 --- a/docshell/base/nsILoadContext.idl +++ b/docshell/base/nsILoadContext.idl @@ -12,9 +12,6 @@ interface nsIDOMElement; %{C++ #ifdef MOZILLA_INTERNAL_API #include "mozilla/BasePrincipal.h" // for DocShellOriginAttributes -#include "mozilla/dom/ScriptSettings.h" // for AutoJSAPI -#include "xpcpublic.h" // for PrivilegedJunkScope -#include "nsContentUtils.h" // for IsSystemPrincipal #endif %} @@ -23,7 +20,7 @@ interface nsIDOMElement; * can be queried for various information about where the load is * happening. */ -[scriptable, uuid(96014778-d30b-4fee-8902-a3481788907b)] +[scriptable, uuid(c71ef717-8fb9-425e-98ef-aef5894890f8)] interface nsILoadContext : nsISupports { /** @@ -139,30 +136,10 @@ interface nsILoadContext : nsISupports #ifdef MOZILLA_INTERNAL_API /** * The C++ getter for origin attributes. + * + * Defined in LoadContext.cpp */ - bool GetOriginAttributes(mozilla::DocShellOriginAttributes& aAttrs) - { - mozilla::dom::AutoJSAPI jsapi; - bool ok = jsapi.Init(xpc::PrivilegedJunkScope()); - NS_ENSURE_TRUE(ok, false); - JS::Rooted v(jsapi.cx()); - nsresult rv = GetOriginAttributes(&v); - NS_ENSURE_SUCCESS(rv, false); - NS_ENSURE_TRUE(v.isObject(), false); - JS::Rooted obj(jsapi.cx(), &v.toObject()); - - // If we're JS-implemented, the object will be left in a different (System-Principaled) - // scope, so we may need to enter its compartment. - MOZ_ASSERT(nsContentUtils::IsSystemPrincipal(nsContentUtils::ObjectPrincipal(obj))); - JSAutoCompartment ac(jsapi.cx(), obj); - - mozilla::DocShellOriginAttributes attrs; - ok = attrs.Init(jsapi.cx(), v); - NS_ENSURE_TRUE(ok, false); - aAttrs = attrs; - return true; - } - + bool GetOriginAttributes(mozilla::DocShellOriginAttributes& aAttrs); #endif %} };