This commit is contained in:
Phil Ringnalda 2013-06-30 16:46:20 -07:00
Родитель 1790cc89d5 8d980e0018
Коммит 14cacaa652
11 изменённых файлов: 57 добавлений и 238 удалений

Просмотреть файл

@ -370,8 +370,11 @@ SessionStore.prototype = {
if (aWindow.Browser.tabs.length > 0) {
// Bundle this browser's data and extra data and save in the closedTabs
// window property
//
// NB: The access to aBrowser.__SS_extdata throws during automation (in
// browser_msgmgr_01). See bug 888736.
let data = aBrowser.__SS_data;
data.extData = aBrowser.__SS_extdata;
try { data.extData = aBrowser.__SS_extdata; } catch (e) { }
this._windows[aWindow.__SSID].closedTabs.unshift(data);
let length = this._windows[aWindow.__SSID].closedTabs.length;

Просмотреть файл

@ -1264,19 +1264,13 @@ nsFrameLoader::SwapWithOtherLoader(nsFrameLoader* aOther,
mMessageManager->GetParentManager() : nullptr;
nsFrameMessageManager* otherParentManager = aOther->mMessageManager ?
aOther->mMessageManager->GetParentManager() : nullptr;
JSContext* thisCx =
mMessageManager ? mMessageManager->GetJSContext() : nullptr;
JSContext* otherCx =
aOther->mMessageManager ? aOther->mMessageManager->GetJSContext() : nullptr;
if (mMessageManager) {
mMessageManager->RemoveFromParent();
mMessageManager->SetJSContext(otherCx);
mMessageManager->SetParentManager(otherParentManager);
mMessageManager->SetCallback(aOther, false);
}
if (aOther->mMessageManager) {
aOther->mMessageManager->RemoveFromParent();
aOther->mMessageManager->SetJSContext(thisCx);
aOther->mMessageManager->SetParentManager(ourParentManager);
aOther->mMessageManager->SetCallback(this, false);
}
@ -2224,8 +2218,7 @@ public:
nsInProcessTabChildGlobal* tabChild =
static_cast<nsInProcessTabChildGlobal*>(mFrameLoader->mChildMessageManager.get());
if (tabChild && tabChild->GetInnerManager()) {
nsFrameScriptCx cx(static_cast<EventTarget*>(tabChild), tabChild);
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(tabChild->GetGlobal());
StructuredCloneData data;
data.mData = mData.data();
data.mDataLength = mData.nbytes();
@ -2233,7 +2226,7 @@ public:
nsRefPtr<nsFrameMessageManager> mm = tabChild->GetInnerManager();
mm->ReceiveMessage(static_cast<EventTarget*>(tabChild), mMessage,
false, &data, JS::NullPtr(), nullptr, nullptr);
false, &data, JS::NullPtr(), nullptr);
}
return NS_OK;
}
@ -2389,12 +2382,10 @@ nsFrameLoader::EnsureMessageManager()
if (ShouldUseRemoteProcess()) {
mMessageManager = new nsFrameMessageManager(mRemoteBrowserShown ? this : nullptr,
static_cast<nsFrameMessageManager*>(parentManager.get()),
cx,
MM_CHROME);
} else {
mMessageManager = new nsFrameMessageManager(nullptr,
static_cast<nsFrameMessageManager*>(parentManager.get()),
cx,
MM_CHROME);
mChildMessageManager =

Просмотреть файл

@ -632,14 +632,10 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
bool aSync,
const StructuredCloneData* aCloneData,
JS::Handle<JSObject*> aObjectsArray,
InfallibleTArray<nsString>* aJSONRetVal,
JSContext* aContext)
InfallibleTArray<nsString>* aJSONRetVal)
{
JSContext *cxToUse = mContext ? mContext
: (aContext ? aContext
: nsContentUtils::GetSafeJSContext());
AutoPushJSContext ctx(cxToUse);
JS::Rooted<JSObject*> objectsArray(cxToUse, aObjectsArray);
AutoSafeJSContext ctx;
JS::Rooted<JSObject*> objectsArray(ctx, aObjectsArray);
if (mListeners.Length()) {
nsCOMPtr<nsIAtom> name = do_GetAtom(aMessage);
MMListenerRemover lr(this);
@ -655,9 +651,6 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
if (!object) {
continue;
}
nsCxPusher pusher;
pusher.Push(ctx);
JSAutoCompartment ac(ctx, object);
// The parameter for the listener function.
@ -762,7 +755,7 @@ nsFrameMessageManager::ReceiveMessage(nsISupports* aTarget,
return mParentManager ? mParentManager->ReceiveMessage(aTarget, aMessage,
aSync, aCloneData,
objectsArray,
aJSONRetVal, mContext) : NS_OK;
aJSONRetVal) : NS_OK;
}
void
@ -819,7 +812,6 @@ nsFrameMessageManager::RemoveFromParent()
mParentManager = nullptr;
mCallback = nullptr;
mOwnedCallback = nullptr;
mContext = nullptr;
}
void
@ -832,7 +824,6 @@ nsFrameMessageManager::Disconnect(bool aRemoveFromParent)
mParentManager = nullptr;
mCallback = nullptr;
mOwnedCallback = nullptr;
mContext = nullptr;
if (!mHandlingMessage) {
mListeners.Clear();
}
@ -844,95 +835,19 @@ NS_NewGlobalMessageManager(nsIMessageBroadcaster** aResult)
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default,
NS_ERROR_NOT_AVAILABLE);
nsFrameMessageManager* mm = new nsFrameMessageManager(nullptr,
nullptr,
nullptr,
MM_CHROME | MM_GLOBAL | MM_BROADCASTER);
return CallQueryInterface(mm, aResult);
}
void
ContentScriptErrorReporter(JSContext* aCx,
const char* aMessage,
JSErrorReport* aReport)
{
nsresult rv;
nsCOMPtr<nsIScriptError> scriptError =
do_CreateInstance(NS_SCRIPTERROR_CONTRACTID, &rv);
if (NS_FAILED(rv)) {
return;
}
nsAutoString message, filename, line;
uint32_t lineNumber, columnNumber, flags, errorNumber;
if (aReport) {
if (aReport->ucmessage) {
message.Assign(static_cast<const PRUnichar*>(aReport->ucmessage));
}
filename.AssignWithConversion(aReport->filename);
line.Assign(static_cast<const PRUnichar*>(aReport->uclinebuf));
lineNumber = aReport->lineno;
columnNumber = aReport->uctokenptr - aReport->uclinebuf;
flags = aReport->flags;
errorNumber = aReport->errorNumber;
} else {
lineNumber = columnNumber = errorNumber = 0;
flags = nsIScriptError::errorFlag | nsIScriptError::exceptionFlag;
}
if (message.IsEmpty()) {
message.AssignWithConversion(aMessage);
}
rv = scriptError->Init(message, filename, line,
lineNumber, columnNumber, flags,
"Message manager content script");
if (NS_FAILED(rv)) {
return;
}
nsCOMPtr<nsIConsoleService> consoleService =
do_GetService(NS_CONSOLESERVICE_CONTRACTID);
if (consoleService) {
(void) consoleService->LogMessage(scriptError);
}
#ifdef DEBUG
// Print it to stderr as well, for the benefit of those invoking
// mozilla with -console.
nsAutoCString error;
error.Assign("JavaScript ");
if (JSREPORT_IS_STRICT(flags)) {
error.Append("strict ");
}
if (JSREPORT_IS_WARNING(flags)) {
error.Append("warning: ");
} else {
error.Append("error: ");
}
error.Append(aReport->filename);
error.Append(", line ");
error.AppendInt(lineNumber, 10);
error.Append(": ");
if (aReport->ucmessage) {
AppendUTF16toUTF8(static_cast<const PRUnichar*>(aReport->ucmessage),
error);
} else {
error.Append(aMessage);
}
fprintf(stderr, "%s\n", error.get());
fflush(stderr);
#endif
}
nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>*
nsFrameScriptExecutor::sCachedScripts = nullptr;
nsScriptCacheCleaner* nsFrameScriptExecutor::sScriptCacheCleaner = nullptr;
void
nsFrameScriptExecutor::DidCreateCx()
nsFrameScriptExecutor::DidCreateGlobal()
{
NS_ASSERTION(mCx, "Should have mCx!");
NS_ASSERTION(mGlobal, "Should have mGlobal!");
if (!sCachedScripts) {
sCachedScripts =
new nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>;
@ -944,26 +859,6 @@ nsFrameScriptExecutor::DidCreateCx()
}
}
void
nsFrameScriptExecutor::DestroyCx()
{
if (mCxStackRefCnt) {
mDelayedCxDestroy = true;
return;
}
mDelayedCxDestroy = false;
if (mCx) {
nsIXPConnect* xpc = nsContentUtils::XPConnect();
if (xpc) {
xpc->ReleaseJSContext(mCx, true);
} else {
JS_DestroyContext(mCx);
}
}
mCx = nullptr;
mGlobal = nullptr;
}
static PLDHashOperator
CachedScriptUnrooter(const nsAString& aKey,
nsFrameJSScriptExecutorHolder*& aData,
@ -995,7 +890,7 @@ nsFrameScriptExecutor::Shutdown()
void
nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
{
if (!mGlobal || !mCx || !sCachedScripts) {
if (!mGlobal || !sCachedScripts) {
return;
}
@ -1006,11 +901,11 @@ nsFrameScriptExecutor::LoadFrameScriptInternal(const nsAString& aURL)
}
if (holder) {
nsCxPusher pusher;
pusher.Push(mCx);
JS::Rooted<JSObject*> global(mCx, mGlobal->GetJSObject());
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
if (global) {
(void) JS_ExecuteScript(mCx, global, holder->mScript, nullptr);
JSAutoCompartment ac(cx, global);
(void) JS_ExecuteScript(cx, global, holder->mScript, nullptr);
}
}
}
@ -1059,18 +954,17 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
}
if (!dataString.IsEmpty()) {
nsCxPusher pusher;
pusher.Push(mCx);
JS::Rooted<JSObject*> global(mCx, mGlobal->GetJSObject());
AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
if (global) {
JSAutoCompartment ac(mCx, global);
JS::CompileOptions options(mCx);
JSAutoCompartment ac(cx, global);
JS::CompileOptions options(cx);
options.setNoScriptRval(true)
.setFileAndLine(url.get(), 1)
.setPrincipals(nsJSPrincipals::get(mPrincipal));
JS::RootedObject empty(mCx, nullptr);
JS::Rooted<JSScript*> script(mCx,
JS::Compile(mCx, empty, options, dataString.get(),
JS::RootedObject empty(cx, nullptr);
JS::Rooted<JSScript*> script(cx,
JS::Compile(cx, empty, options, dataString.get(),
dataString.Length()));
if (script) {
@ -1081,11 +975,11 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
nsFrameJSScriptExecutorHolder* holder =
new nsFrameJSScriptExecutorHolder(script);
// Root the object also for caching.
JS_AddNamedScriptRoot(mCx, &(holder->mScript),
JS_AddNamedScriptRoot(cx, &(holder->mScript),
"Cached message manager script");
sCachedScripts->Put(aURL, holder);
} else if (aBehavior == EXECUTE_IF_CANT_CACHE) {
(void) JS_ExecuteScript(mCx, global, script, nullptr);
(void) JS_ExecuteScript(cx, global, script, nullptr);
}
}
}
@ -1105,26 +999,16 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
runtimeSvc->GetRuntime(&rt);
NS_ENSURE_TRUE(rt, false);
JSContext* cx_ = JS_NewContext(rt, 8192);
NS_ENSURE_TRUE(cx_, false);
AutoPushJSContext cx(cx_);
mCx = cx;
AutoSafeJSContext cx;
nsContentUtils::GetSecurityManager()->GetSystemPrincipal(getter_AddRefs(mPrincipal));
JS_SetOptions(cx, JS_GetOptions(cx) | JSOPTION_PRIVATE_IS_NSISUPPORTS);
JS_SetErrorReporter(cx, ContentScriptErrorReporter);
nsIXPConnect* xpc = nsContentUtils::XPConnect();
const uint32_t flags = nsIXPConnect::INIT_JS_STANDARD_CLASSES;
JS_SetContextPrivate(cx, aScope);
JS::CompartmentOptions options;
options.setZone(JS::SystemZone)
.setVersion(JSVERSION_LATEST);
nsresult rv =
xpc->InitClassesWithNewWrappedGlobal(cx, aScope, mPrincipal,
flags, options, getter_AddRefs(mGlobal));
@ -1134,13 +1018,11 @@ nsFrameScriptExecutor::InitTabChildGlobalInternal(nsISupports* aScope,
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
NS_ENSURE_TRUE(global, false);
JS_SetGlobalObject(cx, global);
// Set the location information for the new global, so that tools like
// about:memory may use that information.
xpc::SetLocationForGlobal(global, aID);
DidCreateCx();
DidCreateGlobal();
return true;
}
@ -1150,21 +1032,13 @@ nsFrameScriptExecutor::Traverse(nsFrameScriptExecutor *tmp,
nsCycleCollectionTraversalCallback &cb)
{
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mGlobal)
nsIXPConnect* xpc = nsContentUtils::XPConnect();
if (xpc) {
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mCx");
xpc->NoteJSContext(tmp->mCx, cb);
}
}
// static
void
nsFrameScriptExecutor::Unlink(nsFrameScriptExecutor* aTmp)
{
if (aTmp->mCx) {
JSAutoRequest ar(aTmp->mCx);
JS_SetGlobalObject(aTmp->mCx, nullptr);
}
aTmp->mGlobal = nullptr;
}
NS_IMPL_ISUPPORTS1(nsScriptCacheCleaner, nsIObserver)
@ -1198,7 +1072,7 @@ public:
nsRefPtr<nsFrameMessageManager> ppm = nsFrameMessageManager::sChildProcessManager;
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()), mMessage,
false, &data, JS::NullPtr(), nullptr, nullptr);
false, &data, JS::NullPtr(), nullptr);
}
return NS_OK;
}
@ -1328,7 +1202,7 @@ public:
nsRefPtr<nsFrameMessageManager> ppm =
nsFrameMessageManager::sSameProcessParentManager;
ppm->ReceiveMessage(static_cast<nsIContentFrameMessageManager*>(ppm.get()),
mMessage, false, &data, JS::NullPtr(), nullptr, nullptr);
mMessage, false, &data, JS::NullPtr(), nullptr);
}
return NS_OK;
}
@ -1398,7 +1272,6 @@ NS_NewParentProcessMessageManager(nsIMessageBroadcaster** aResult)
NS_ENSURE_TRUE(XRE_GetProcessType() == GeckoProcessType_Default,
NS_ERROR_NOT_AVAILABLE);
nsRefPtr<nsFrameMessageManager> mm = new nsFrameMessageManager(nullptr,
nullptr,
nullptr,
MM_CHROME | MM_PROCESSMANAGER | MM_BROADCASTER);
nsFrameMessageManager::sParentProcessManager = mm;
@ -1421,12 +1294,10 @@ nsFrameMessageManager::NewProcessMessageManager(mozilla::dom::ContentParent* aPr
if (aProcess) {
mm = new nsFrameMessageManager(aProcess,
nsFrameMessageManager::sParentProcessManager,
nullptr,
MM_CHROME | MM_PROCESSMANAGER);
} else {
mm = new nsFrameMessageManager(new SameParentProcessMessageManagerCallback(),
nsFrameMessageManager::sParentProcessManager,
nullptr,
MM_CHROME | MM_PROCESSMANAGER | MM_OWNSCALLBACK);
sSameProcessParentManager = mm;
}
@ -1446,7 +1317,6 @@ NS_NewChildProcessMessageManager(nsISyncMessageSender** aResult)
cb = new ChildProcessMessageManagerCallback();
}
nsFrameMessageManager* mm = new nsFrameMessageManager(cb,
nullptr,
nullptr,
MM_PROCESSMANAGER | MM_OWNSCALLBACK);
nsFrameMessageManager::sChildProcessManager = mm;

Просмотреть файл

@ -120,7 +120,6 @@ class nsFrameMessageManager MOZ_FINAL : public nsIContentFrameMessageManager,
public:
nsFrameMessageManager(mozilla::dom::ipc::MessageManagerCallback* aCallback,
nsFrameMessageManager* aParentManager,
JSContext* aContext,
/* mozilla::dom::ipc::MessageManagerFlags */ uint32_t aFlags)
: mChrome(!!(aFlags & mozilla::dom::ipc::MM_CHROME)),
mGlobal(!!(aFlags & mozilla::dom::ipc::MM_GLOBAL)),
@ -130,11 +129,8 @@ public:
mHandlingMessage(false),
mDisconnected(false),
mCallback(aCallback),
mParentManager(aParentManager),
mContext(aContext)
mParentManager(aParentManager)
{
NS_ASSERTION(mContext || (mChrome && !mParentManager) || mIsProcessManager,
"Should have mContext in non-global/non-process manager!");
NS_ASSERTION(mChrome || !aParentManager, "Should not set parent manager!");
NS_ASSERTION(!mIsBroadcaster || !mCallback,
"Broadcasters cannot have callbacks!");
@ -188,8 +184,7 @@ public:
nsresult ReceiveMessage(nsISupports* aTarget, const nsAString& aMessage,
bool aSync, const StructuredCloneData* aCloneData,
JS::Handle<JSObject*> aObjectsArray,
InfallibleTArray<nsString>* aJSONRetVal,
JSContext* aContext = nullptr);
InfallibleTArray<nsString>* aJSONRetVal);
void AddChildManager(nsFrameMessageManager* aManager,
bool aLoadScripts = true);
@ -212,8 +207,6 @@ public:
uint8_t aArgc);
nsresult DispatchAsyncMessageInternal(const nsAString& aMessage,
const StructuredCloneData& aData);
JSContext* GetJSContext() { return mContext; }
void SetJSContext(JSContext* aCx) { mContext = aCx; }
void RemoveFromParent();
nsFrameMessageManager* GetParentManager() { return mParentManager; }
void SetParentManager(nsFrameMessageManager* aParent)
@ -247,7 +240,6 @@ protected:
mozilla::dom::ipc::MessageManagerCallback* mCallback;
nsAutoPtr<mozilla::dom::ipc::MessageManagerCallback> mOwnedCallback;
nsFrameMessageManager* mParentManager;
JSContext* mContext;
nsTArray<nsString> mPendingScripts;
public:
static nsFrameMessageManager* sParentProcessManager;
@ -265,11 +257,6 @@ private:
bool* aValid);
};
void
ContentScriptErrorReporter(JSContext* aCx,
const char* aMessage,
JSErrorReport* aReport);
class nsScriptCacheCleaner;
struct nsFrameJSScriptExecutorHolder
@ -285,16 +272,18 @@ class nsFrameScriptExecutor
{
public:
static void Shutdown();
already_AddRefed<nsIXPConnectJSObjectHolder> GetGlobal()
{
nsCOMPtr<nsIXPConnectJSObjectHolder> ref = mGlobal;
return ref.forget();
}
protected:
friend class nsFrameScriptCx;
nsFrameScriptExecutor() : mCx(nullptr), mCxStackRefCnt(0),
mDelayedCxDestroy(false)
nsFrameScriptExecutor()
{ MOZ_COUNT_CTOR(nsFrameScriptExecutor); }
~nsFrameScriptExecutor()
{ MOZ_COUNT_DTOR(nsFrameScriptExecutor); }
void DidCreateCx();
// Call this when you want to destroy mCx.
void DestroyCx();
void DidCreateGlobal();
void LoadFrameScriptInternal(const nsAString& aURL);
enum CacheFailedBehavior { EXECUTE_IF_CANT_CACHE, DONT_EXECUTE };
void TryCacheLoadAndCompileScript(const nsAString& aURL,
@ -304,33 +293,11 @@ protected:
nsCycleCollectionTraversalCallback &cb);
static void Unlink(nsFrameScriptExecutor* aTmp);
nsCOMPtr<nsIXPConnectJSObjectHolder> mGlobal;
JSContext* mCx;
uint32_t mCxStackRefCnt;
bool mDelayedCxDestroy;
nsCOMPtr<nsIPrincipal> mPrincipal;
static nsDataHashtable<nsStringHashKey, nsFrameJSScriptExecutorHolder*>* sCachedScripts;
static nsScriptCacheCleaner* sScriptCacheCleaner;
};
class nsFrameScriptCx
{
public:
nsFrameScriptCx(nsISupports* aOwner, nsFrameScriptExecutor* aExec)
: mOwner(aOwner), mExec(aExec)
{
++(mExec->mCxStackRefCnt);
}
~nsFrameScriptCx()
{
if (--(mExec->mCxStackRefCnt) == 0 &&
mExec->mDelayedCxDestroy) {
mExec->DestroyCx();
}
}
nsCOMPtr<nsISupports> mOwner;
nsFrameScriptExecutor* mExec;
};
class nsScriptCacheCleaner MOZ_FINAL : public nsIObserver
{
NS_DECL_ISUPPORTS

Просмотреть файл

@ -74,7 +74,7 @@ public:
nsRefPtr<nsFrameMessageManager> mm = mTabChild->mChromeMessageManager;
mm->ReceiveMessage(mTabChild->mOwner, mMessage, false, &data,
JS::NullPtr(), nullptr, nullptr);
JS::NullPtr(), nullptr);
}
return NS_OK;
}
@ -118,7 +118,6 @@ nsInProcessTabChildGlobal::nsInProcessTabChildGlobal(nsIDocShell* aShell,
nsInProcessTabChildGlobal::~nsInProcessTabChildGlobal()
{
NS_ASSERTION(!mCx, "Couldn't release JSContext?!?");
}
/* [notxpcom] boolean markForCC (); */
@ -141,7 +140,6 @@ nsInProcessTabChildGlobal::Init()
"Couldn't initialize nsInProcessTabChildGlobal");
mMessageManager = new nsFrameMessageManager(this,
nullptr,
mCx,
mozilla::dom::ipc::MM_CHILD);
return NS_OK;
}
@ -248,9 +246,7 @@ nsInProcessTabChildGlobal::DelayedDisconnect()
if (!mLoadingScript) {
nsContentUtils::ReleaseWrapper(static_cast<EventTarget*>(this), this);
if (mCx) {
DestroyCx();
}
mGlobal = nullptr;
} else {
mDelayedDisconnect = true;
}

Просмотреть файл

@ -93,7 +93,7 @@ public:
}
using nsDOMEventTargetHelper::AddEventListener;
virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return mCx; }
virtual JSContext* GetJSContextForEventHandlers() MOZ_OVERRIDE { return nsContentUtils::GetSafeJSContext(); }
virtual nsIPrincipal* GetPrincipal() MOZ_OVERRIDE { return mPrincipal; }
void LoadFrameScript(const nsAString& aURL);
void Disconnect();

Просмотреть файл

@ -11625,7 +11625,6 @@ nsGlobalChromeWindow::GetMessageManager(nsIMessageBroadcaster** aManager)
mMessageManager =
new nsFrameMessageManager(nullptr,
static_cast<nsFrameMessageManager*>(globalMM.get()),
cx,
MM_CHROME | MM_BROADCASTER);
NS_ENSURE_TRUE(mMessageManager, NS_ERROR_OUT_OF_MEMORY);
}

Просмотреть файл

@ -141,7 +141,7 @@ CollectWindowReports(nsGlobalWindow *aWindow,
location = GetWindowURI(aWindow);
}
if (location) {
if (addonManager && location) {
bool ok;
nsAutoCString id;
if (NS_SUCCEEDED(addonManager->MapURIToAddonID(location, id, &ok)) && ok) {

Просмотреть файл

@ -1145,10 +1145,8 @@ TabChild::~TabChild()
if (webBrowser) {
webBrowser->SetContainerWindow(nullptr);
}
if (mCx) {
DestroyCx();
}
mGlobal = nullptr;
if (mTabChildGlobal) {
nsEventListenerManager* elm = mTabChildGlobal->GetListenerManager(false);
if (elm) {
@ -1445,7 +1443,7 @@ TabChild::DispatchMessageManagerMessage(const nsAString& aMessageName,
cloneData.mDataLength = buffer.nbytes();
}
nsFrameScriptCx frameScriptCx(static_cast<nsIWebBrowserChrome*>(this), this);
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
// Let the BrowserElementScrolling helper (if it exists) for this
// content manipulate the frame state.
nsRefPtr<nsFrameMessageManager> mm =
@ -1485,7 +1483,7 @@ TabChild::RecvUpdateFrame(const FrameMetrics& aFrameMetrics)
bool
TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
{
if (!mCx || !mTabChildGlobal) {
if (!mGlobal || !mTabChildGlobal) {
return true;
}
@ -1555,7 +1553,7 @@ TabChild::ProcessUpdateFrame(const FrameMetrics& aFrameMetrics)
bool
TabChild::RecvHandleDoubleTap(const CSSIntPoint& aPoint)
{
if (!mCx || !mTabChildGlobal) {
if (!mGlobal || !mTabChildGlobal) {
return true;
}
@ -1572,7 +1570,7 @@ TabChild::RecvHandleDoubleTap(const CSSIntPoint& aPoint)
bool
TabChild::RecvHandleSingleTap(const CSSIntPoint& aPoint)
{
if (!mCx || !mTabChildGlobal) {
if (!mGlobal || !mTabChildGlobal) {
return true;
}
@ -1586,7 +1584,7 @@ TabChild::RecvHandleSingleTap(const CSSIntPoint& aPoint)
bool
TabChild::RecvHandleLongTap(const CSSIntPoint& aPoint)
{
if (!mCx || !mTabChildGlobal) {
if (!mGlobal || !mTabChildGlobal) {
return true;
}
@ -1995,7 +1993,7 @@ TabChild::DeallocPOfflineCacheUpdate(POfflineCacheUpdateChild* actor)
bool
TabChild::RecvLoadRemoteScript(const nsString& aURL)
{
if (!mCx && !InitTabChildGlobal())
if (!mGlobal && !InitTabChildGlobal())
// This can happen if we're half-destroyed. It's not a fatal
// error.
return true;
@ -2009,7 +2007,7 @@ TabChild::RecvAsyncMessage(const nsString& aMessage,
const ClonedMessageData& aData)
{
if (mTabChildGlobal) {
nsFrameScriptCx cx(static_cast<nsIWebBrowserChrome*>(this), this);
nsCOMPtr<nsIXPConnectJSObjectHolder> kungFuDeathGrip(GetGlobal());
StructuredCloneData cloneData = UnpackClonedMessageDataForChild(aData);
nsRefPtr<nsFrameMessageManager> mm =
static_cast<nsFrameMessageManager*>(mTabChildGlobal->mMessageManager.get());
@ -2093,7 +2091,7 @@ TabChild::DeallocPRenderFrame(PRenderFrameChild* aFrame)
bool
TabChild::InitTabChildGlobal(FrameScriptLoading aScriptLoading)
{
if (!mCx && !mTabChildGlobal) {
if (!mGlobal && !mTabChildGlobal) {
nsCOMPtr<nsPIDOMWindow> window = do_GetInterface(mWebNav);
NS_ENSURE_TRUE(window, false);
nsCOMPtr<EventTarget> chromeHandler =
@ -2344,7 +2342,6 @@ TabChildGlobal::Init()
NS_ASSERTION(!mMessageManager, "Re-initializing?!?");
mMessageManager = new nsFrameMessageManager(mTabChild,
nullptr,
mTabChild->GetJSContext(),
MM_CHILD);
}
@ -2418,9 +2415,7 @@ TabChildGlobal::Atob(const nsAString& aAsciiString,
JSContext*
TabChildGlobal::GetJSContextForEventHandlers()
{
if (!mTabChild)
return nullptr;
return mTabChild->GetJSContext();
return nsContentUtils::GetSafeJSContext();
}
nsIPrincipal*

Просмотреть файл

@ -282,8 +282,6 @@ public:
nsIWebNavigation* WebNavigation() { return mWebNav; }
JSContext* GetJSContext() { return mCx; }
nsIPrincipal* GetPrincipal() { return mPrincipal; }
/** Return the DPI of the widget this TabChild draws to. */

Просмотреть файл

@ -1091,7 +1091,7 @@ TabParent::ReceiveMessage(const nsString& aMessage,
if (frameLoader && frameLoader->GetFrameMessageManager()) {
nsRefPtr<nsFrameMessageManager> manager =
frameLoader->GetFrameMessageManager();
AutoPushJSContext ctx(manager->GetJSContext());
AutoSafeJSContext ctx;
uint32_t len = 0; //TODO: obtain a real value in bug 572685
// Because we want JS messages to have always the same properties,
// create array even if len == 0.