| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 } | 94 } |
| 95 | 95 |
| 96 void PageRuntimeAgent::didClearDocumentOfWindowObject(LocalFrame* frame) | 96 void PageRuntimeAgent::didClearDocumentOfWindowObject(LocalFrame* frame) |
| 97 { | 97 { |
| 98 m_mainWorldContextCreated = true; | 98 m_mainWorldContextCreated = true; |
| 99 | 99 |
| 100 if (!m_enabled) | 100 if (!m_enabled) |
| 101 return; | 101 return; |
| 102 ASSERT(m_frontend); | 102 ASSERT(m_frontend); |
| 103 | 103 |
| 104 if (frame == m_inspectedPage->mainFrame()) { | 104 frame->script().initializeMainWorld(); |
| 105 m_scriptStateToId.clear(); | |
| 106 m_frontend->executionContextsCleared(); | |
| 107 } | |
| 108 String frameId = m_pageAgent->frameId(frame); | |
| 109 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr
ameId); | |
| 110 } | 105 } |
| 111 | 106 |
| 112 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) | 107 void PageRuntimeAgent::didCreateScriptContext(LocalFrame* frame, ScriptState* sc
riptState, SecurityOrigin* origin, bool isMainWorldContext) |
| 113 { | 108 { |
| 114 if (!m_enabled) | 109 if (!m_enabled) |
| 115 return; | 110 return; |
| 116 ASSERT(m_frontend); | 111 ASSERT(m_frontend); |
| 117 String originString = origin ? origin->toRawString() : ""; | 112 String originString = origin ? origin->toRawString() : ""; |
| 118 String frameId = m_pageAgent->frameId(frame); | 113 String frameId = m_pageAgent->frameId(frame); |
| 119 addExecutionContextToFrontend(scriptState, false, originString, frameId); | 114 addExecutionContextToFrontend(scriptState, isMainWorldContext, originString,
frameId); |
| 115 } |
| 116 |
| 117 void PageRuntimeAgent::willReleaseScriptContext(LocalFrame* frame, ScriptState*
scriptState) |
| 118 { |
| 119 injectedScriptManager()->discardInjectedScriptFor(scriptState); |
| 120 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); |
| 121 if (it == m_scriptStateToId.end()) |
| 122 return; |
| 123 int id = it->value; |
| 124 m_scriptStateToId.remove(scriptState); |
| 125 m_frontend->executionContextDestroyed(id); |
| 120 } | 126 } |
| 121 | 127 |
| 122 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString,
const int* executionContextId) | 128 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString,
const int* executionContextId) |
| 123 { | 129 { |
| 124 if (!executionContextId) { | 130 if (!executionContextId) { |
| 125 ScriptState* scriptState = ScriptState::forMainWorld(m_inspectedPage->de
precatedLocalMainFrame()); | 131 ScriptState* scriptState = ScriptState::forMainWorld(m_inspectedPage->de
precatedLocalMainFrame()); |
| 126 InjectedScript result = injectedScriptManager()->injectedScriptFor(scrip
tState); | 132 InjectedScript result = injectedScriptManager()->injectedScriptFor(scrip
tState); |
| 127 if (result.isEmpty()) | 133 if (result.isEmpty()) |
| 128 *errorString = "Internal error: main world execution context not fou
nd."; | 134 *errorString = "Internal error: main world execution context not fou
nd."; |
| 129 return result; | 135 return result; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 148 { | 154 { |
| 149 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; | 155 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; |
| 150 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { | 156 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { |
| 151 if (!frame->isLocalFrame()) | 157 if (!frame->isLocalFrame()) |
| 152 continue; | 158 continue; |
| 153 LocalFrame* localFrame = toLocalFrame(frame); | 159 LocalFrame* localFrame = toLocalFrame(frame); |
| 154 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) | 160 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) |
| 155 continue; | 161 continue; |
| 156 String frameId = m_pageAgent->frameId(localFrame); | 162 String frameId = m_pageAgent->frameId(localFrame); |
| 157 | 163 |
| 158 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); | 164 // Ensure execution context is created. |
| 159 addExecutionContextToFrontend(scriptState, true, "", frameId); | 165 // If initializeMainWorld returns true, then is registered by didCreateS
criptContext |
| 166 if (!localFrame->script().initializeMainWorld()) |
| 167 addExecutionContextToFrontend(ScriptState::forMainWorld(localFrame),
true, "", frameId); |
| 160 localFrame->script().collectIsolatedContexts(isolatedContexts); | 168 localFrame->script().collectIsolatedContexts(isolatedContexts); |
| 161 if (isolatedContexts.isEmpty()) | 169 if (isolatedContexts.isEmpty()) |
| 162 continue; | 170 continue; |
| 163 for (const auto& pair : isolatedContexts) { | 171 for (const auto& pair : isolatedContexts) { |
| 164 String originString = pair.second ? pair.second->toRawString() : ""; | 172 String originString = pair.second ? pair.second->toRawString() : ""; |
| 165 addExecutionContextToFrontend(pair.first, false, originString, frame
Id); | 173 addExecutionContextToFrontend(pair.first, false, originString, frame
Id); |
| 166 } | 174 } |
| 167 isolatedContexts.clear(); | 175 isolatedContexts.clear(); |
| 168 } | 176 } |
| 169 } | 177 } |
| 170 | 178 |
| 171 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) | |
| 172 { | |
| 173 Vector<RefPtr<ScriptState> > scriptStatesToRemove; | |
| 174 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip
tStateToId.end(); ++it) { | |
| 175 RefPtr<ScriptState> scriptState = it->key; | |
| 176 if (!scriptState->contextIsValid() || window == scriptState->domWindow()
) { | |
| 177 scriptStatesToRemove.append(scriptState); | |
| 178 m_frontend->executionContextDestroyed(it->value); | |
| 179 } | |
| 180 } | |
| 181 m_scriptStateToId.removeAll(scriptStatesToRemove); | |
| 182 injectedScriptManager()->discardInjectedScriptsFor(window); | |
| 183 } | |
| 184 | |
| 185 } // namespace blink | 179 } // namespace blink |
| 186 | 180 |
| OLD | NEW |