зеркало из https://github.com/mozilla/gecko-dev.git
Bug 705651, simplify message manager, and remove certainly useless comment about OMIT_COMPONENTS_OBJECT, r=mrbkap
This commit is contained in:
Родитель
6ff56ee903
Коммит
2f4aac4f4b
|
@ -51,6 +51,9 @@
|
|||
#include "nsIScriptError.h"
|
||||
#include "nsIConsoleService.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsIJSRuntimeService.h"
|
||||
#include "xpcpublic.h"
|
||||
|
||||
#ifdef ANDROID
|
||||
#include <android/log.h>
|
||||
|
@ -808,6 +811,58 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
|
||||
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
||||
NS_ENSURE_TRUE(runtimeSvc, false);
|
||||
|
||||
JSRuntime* rt = nsnull;
|
||||
runtimeSvc->GetRuntime(&rt);
|
||||
NS_ENSURE_TRUE(rt, false);
|
||||
|
||||
JSContext* cx = JS_NewContext(rt, 8192);
|
||||
NS_ENSURE_TRUE(cx, false);
|
||||
|
||||
mCx = cx;
|
||||
|
||||
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
|
||||
|
||||
JS_SetNativeStackQuota(cx, 128 * sizeof(size_t) * 1024);
|
||||
|
||||
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
|
||||
JS_SetVersion(cx, JSVERSION_LATEST);
|
||||
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
|
||||
|
||||
xpc_LocalizeContext(cx);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
||||
const PRUint32 flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES |
|
||||
nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT;
|
||||
|
||||
|
||||
JS_SetContextPrivate(cx, aScope);
|
||||
|
||||
nsresult rv =
|
||||
xpc->InitClassesWithNewWrappedGlobal(cx, aScope,
|
||||
NS_GET_IID(nsISupports),
|
||||
mPrincipal, nsnull,
|
||||
flags, getter_AddRefs(mGlobal));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
|
||||
JSObject* global = nsnull;
|
||||
rv = mGlobal->GetJSObject(&global);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
JS_SetGlobalObject(cx, global);
|
||||
DidCreateCx();
|
||||
return true;
|
||||
}
|
||||
|
||||
// static
|
||||
void
|
||||
nsFrameScriptExecutor::Traverse(nsFrameScriptExecutor *tmp,
|
||||
|
|
|
@ -231,6 +231,7 @@ protected:
|
|||
// Call this when you want to destroy mCx.
|
||||
void DestroyCx();
|
||||
void LoadFrameScriptInternal(const nsAString& aURL);
|
||||
bool InitTabChildGlobalInternal(nsISupports* aScope);
|
||||
static void Traverse(nsFrameScriptExecutor *tmp,
|
||||
nsCycleCollectionTraversalCallback &cb);
|
||||
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
|
||||
|
|
|
@ -293,53 +293,10 @@ nsInProcessTabChildGlobal::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
|
|||
nsresult
|
||||
nsInProcessTabChildGlobal::InitTabChildGlobal()
|
||||
{
|
||||
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
|
||||
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
||||
NS_ENSURE_STATE(runtimeSvc);
|
||||
|
||||
JSRuntime* rt = nsnull;
|
||||
runtimeSvc->GetRuntime(&rt);
|
||||
NS_ENSURE_STATE(rt);
|
||||
|
||||
JSContext* cx = JS_NewContext(rt, 8192);
|
||||
NS_ENSURE_STATE(cx);
|
||||
|
||||
mCx = cx;
|
||||
|
||||
nsContentUtils::XPConnect()->SetSecurityManagerForJSContext(cx, nsContentUtils::GetSecurityManager(), 0);
|
||||
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
|
||||
|
||||
JS_SetNativeStackQuota(cx, 128 * sizeof(size_t) * 1024);
|
||||
|
||||
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
|
||||
JS_SetVersion(cx, JSVERSION_LATEST);
|
||||
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
|
||||
|
||||
xpc_LocalizeContext(cx);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
||||
const PRUint32 flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES |
|
||||
/*nsIXPConnect::OMIT_COMPONENTS_OBJECT ? |*/
|
||||
nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT;
|
||||
|
||||
nsISupports* scopeSupports =
|
||||
NS_ISUPPORTS_CAST(nsIDOMEventTarget*, this);
|
||||
JS_SetContextPrivate(cx, scopeSupports);
|
||||
|
||||
nsresult rv =
|
||||
xpc->InitClassesWithNewWrappedGlobal(cx, scopeSupports,
|
||||
NS_GET_IID(nsISupports),
|
||||
GetPrincipal(), nsnull,
|
||||
flags, getter_AddRefs(mGlobal));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
JSObject* global = nsnull;
|
||||
rv = mGlobal->GetJSObject(&global);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
JS_SetGlobalObject(cx, global);
|
||||
DidCreateCx();
|
||||
NS_ENSURE_STATE(InitTabChildGlobalInternal(scopeSupports));
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -897,36 +897,6 @@ TabChild::InitTabChildGlobal()
|
|||
do_QueryInterface(window->GetChromeEventHandler());
|
||||
NS_ENSURE_TRUE(chromeHandler, false);
|
||||
|
||||
nsCOMPtr<nsIJSRuntimeService> runtimeSvc =
|
||||
do_GetService("@mozilla.org/js/xpc/RuntimeService;1");
|
||||
NS_ENSURE_TRUE(runtimeSvc, false);
|
||||
|
||||
JSRuntime* rt = nsnull;
|
||||
runtimeSvc->GetRuntime(&rt);
|
||||
NS_ENSURE_TRUE(rt, false);
|
||||
|
||||
JSContext* cx = JS_NewContext(rt, 8192);
|
||||
NS_ENSURE_TRUE(cx, false);
|
||||
|
||||
mCx = cx;
|
||||
|
||||
nsContentUtils::XPConnect()->SetSecurityManagerForJSContext(cx, nsContentUtils::GetSecurityManager(), 0);
|
||||
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
|
||||
|
||||
JS_SetNativeStackQuota(cx, 128 * sizeof(size_t) * 1024);
|
||||
|
||||
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
|
||||
JS_SetVersion(cx, JSVERSION_LATEST);
|
||||
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
|
||||
|
||||
xpc_LocalizeContext(cx);
|
||||
|
||||
JSAutoRequest ar(cx);
|
||||
nsIXPConnect* xpc = nsContentUtils::XPConnect();
|
||||
const PRUint32 flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES |
|
||||
/*nsIXPConnect::OMIT_COMPONENTS_OBJECT ? |*/
|
||||
nsIXPConnect::FLAG_SYSTEM_GLOBAL_OBJECT;
|
||||
|
||||
nsRefPtr<TabChildGlobal> scope = new TabChildGlobal(this);
|
||||
NS_ENSURE_TRUE(scope, false);
|
||||
|
||||
|
@ -934,25 +904,12 @@ TabChild::InitTabChildGlobal()
|
|||
|
||||
nsISupports* scopeSupports =
|
||||
NS_ISUPPORTS_CAST(nsIDOMEventTarget*, scope);
|
||||
JS_SetContextPrivate(cx, scopeSupports);
|
||||
|
||||
nsresult rv =
|
||||
xpc->InitClassesWithNewWrappedGlobal(cx, scopeSupports,
|
||||
NS_GET_IID(nsISupports),
|
||||
scope->GetPrincipal(), nsnull,
|
||||
flags, getter_AddRefs(mGlobal));
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
NS_ENSURE_TRUE(InitTabChildGlobalInternal(scopeSupports), false);
|
||||
|
||||
nsCOMPtr<nsPIWindowRoot> root = do_QueryInterface(chromeHandler);
|
||||
NS_ENSURE_TRUE(root, false);
|
||||
root->SetParentTarget(scope);
|
||||
|
||||
JSObject* global = nsnull;
|
||||
rv = mGlobal->GetJSObject(&global);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
JS_SetGlobalObject(cx, global);
|
||||
DidCreateCx();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче