Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(819)

Unified Diff: Source/core/inspector/PageRuntimeAgent.cpp

Issue 686763002: Fix Runtime.executionContextCreated for crafted iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: rebase Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/inspector/PageRuntimeAgent.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/inspector/PageRuntimeAgent.cpp
diff --git a/Source/core/inspector/PageRuntimeAgent.cpp b/Source/core/inspector/PageRuntimeAgent.cpp
index 5fd8887f0c172caef14d5709be7e6fc0d07a1f8e..f23ef3c7e22dd9906cfd9ae23b0f34198bb50909 100644
--- a/Source/core/inspector/PageRuntimeAgent.cpp
+++ b/Source/core/inspector/PageRuntimeAgent.cpp
@@ -101,22 +101,28 @@ void PageRuntimeAgent::didClearDocumentOfWindowObject(LocalFrame* frame)
return;
ASSERT(m_frontend);
- if (frame == m_inspectedPage->mainFrame()) {
- m_scriptStateToId.clear();
- m_frontend->executionContextsCleared();
- }
- String frameId = m_pageAgent->frameId(frame);
- addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", frameId);
+ frame->script().initializeMainWorld();
}
-void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin)
+void PageRuntimeAgent::didCreateScriptContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin, bool isMainWorldContext)
{
if (!m_enabled)
return;
ASSERT(m_frontend);
String originString = origin ? origin->toRawString() : "";
String frameId = m_pageAgent->frameId(frame);
- addExecutionContextToFrontend(scriptState, false, originString, frameId);
+ addExecutionContextToFrontend(scriptState, isMainWorldContext, originString, frameId);
+}
+
+void PageRuntimeAgent::willReleaseScriptContext(LocalFrame* frame, ScriptState* scriptState)
+{
+ injectedScriptManager()->discardInjectedScriptFor(scriptState);
+ ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState);
+ if (it == m_scriptStateToId.end())
+ return;
+ int id = it->value;
+ m_scriptStateToId.remove(scriptState);
+ m_frontend->executionContextDestroyed(id);
}
InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
@@ -155,8 +161,10 @@ void PageRuntimeAgent::reportExecutionContextCreation()
continue;
String frameId = m_pageAgent->frameId(localFrame);
- ScriptState* scriptState = ScriptState::forMainWorld(localFrame);
- addExecutionContextToFrontend(scriptState, true, "", frameId);
+ // Ensure execution context is created.
+ // If initializeMainWorld returns true, then is registered by didCreateScriptContext
+ if (!localFrame->script().initializeMainWorld())
+ addExecutionContextToFrontend(ScriptState::forMainWorld(localFrame), true, "", frameId);
localFrame->script().collectIsolatedContexts(isolatedContexts);
if (isolatedContexts.isEmpty())
continue;
@@ -168,19 +176,5 @@ void PageRuntimeAgent::reportExecutionContextCreation()
}
}
-void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window)
-{
- Vector<RefPtr<ScriptState> > scriptStatesToRemove;
- for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) {
- RefPtr<ScriptState> scriptState = it->key;
- if (!scriptState->contextIsValid() || window == scriptState->domWindow()) {
- scriptStatesToRemove.append(scriptState);
- m_frontend->executionContextDestroyed(it->value);
- }
- }
- m_scriptStateToId.removeAll(scriptStatesToRemove);
- injectedScriptManager()->discardInjectedScriptsFor(window);
-}
-
} // namespace blink
« no previous file with comments | « Source/core/inspector/PageRuntimeAgent.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698