Chromium Code Reviews| 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(); |
|
yurys
2014/11/13 13:58:30
How can we be sure that this is a scriptless docum
eustas
2014/12/05 10:01:37
No guarantees. But this worked for ages...
| |
| 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 frameId = m_pageAgent->frameId(frame); | 112 String frameId = m_pageAgent->frameId(frame); |
| 118 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra meId); | 113 addExecutionContextToFrontend(scriptState, isMainWorldContext, origin->toRaw String(), frameId); |
| 114 } | |
| 115 | |
| 116 void PageRuntimeAgent::willReleaseScriptContext(LocalFrame* frame, ScriptState* scriptState) | |
| 117 { | |
| 118 injectedScriptManager()->discardInjectedScriptFor(scriptState); | |
| 119 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); | |
| 120 if (it == m_scriptStateToId.end()) | |
| 121 return; | |
| 122 int id = it->value; | |
| 123 m_scriptStateToId.remove(scriptState); | |
| 124 m_frontend->executionContextDestroyed(id); | |
| 119 } | 125 } |
| 120 | 126 |
| 121 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) | 127 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) |
| 122 { | 128 { |
| 123 if (!executionContextId) { | 129 if (!executionContextId) { |
| 124 ScriptState* scriptState = ScriptState::forMainWorld(m_inspectedPage->de precatedLocalMainFrame()); | 130 ScriptState* scriptState = ScriptState::forMainWorld(m_inspectedPage->de precatedLocalMainFrame()); |
| 125 InjectedScript result = injectedScriptManager()->injectedScriptFor(scrip tState); | 131 InjectedScript result = injectedScriptManager()->injectedScriptFor(scrip tState); |
| 126 if (result.isEmpty()) | 132 if (result.isEmpty()) |
| 127 *errorString = "Internal error: main world execution context not fou nd."; | 133 *errorString = "Internal error: main world execution context not fou nd."; |
| 128 return result; | 134 return result; |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 147 { | 153 { |
| 148 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; | 154 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; |
| 149 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) { | 155 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) { |
| 150 if (!frame->isLocalFrame()) | 156 if (!frame->isLocalFrame()) |
| 151 continue; | 157 continue; |
| 152 LocalFrame* localFrame = toLocalFrame(frame); | 158 LocalFrame* localFrame = toLocalFrame(frame); |
| 153 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) | 159 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) |
| 154 continue; | 160 continue; |
| 155 String frameId = m_pageAgent->frameId(localFrame); | 161 String frameId = m_pageAgent->frameId(localFrame); |
| 156 | 162 |
| 157 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); | 163 if (!localFrame->script().initializeMainWorld()) |
|
yurys
2014/11/13 13:58:30
Mind adding a comment?
eustas
2014/12/05 10:01:37
Done.
| |
| 158 addExecutionContextToFrontend(scriptState, true, "", frameId); | 164 addExecutionContextToFrontend(ScriptState::forMainWorld(localFrame), true, "", frameId); |
| 159 localFrame->script().collectIsolatedContexts(isolatedContexts); | 165 localFrame->script().collectIsolatedContexts(isolatedContexts); |
| 160 if (isolatedContexts.isEmpty()) | 166 if (isolatedContexts.isEmpty()) |
| 161 continue; | 167 continue; |
| 162 for (size_t i = 0; i< isolatedContexts.size(); i++) | 168 for (size_t i = 0; i< isolatedContexts.size(); i++) |
| 163 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId); | 169 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId); |
| 164 isolatedContexts.clear(); | 170 isolatedContexts.clear(); |
| 165 } | 171 } |
| 166 } | 172 } |
| 167 | 173 |
| 168 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) | |
| 169 { | |
| 170 Vector<RefPtr<ScriptState> > scriptStatesToRemove; | |
| 171 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) { | |
| 172 RefPtr<ScriptState> scriptState = it->key; | |
| 173 if (!scriptState->contextIsValid() || window == scriptState->domWindow() ) { | |
| 174 scriptStatesToRemove.append(scriptState); | |
| 175 m_frontend->executionContextDestroyed(it->value); | |
| 176 } | |
| 177 } | |
| 178 m_scriptStateToId.removeAll(scriptStatesToRemove); | |
| 179 injectedScriptManager()->discardInjectedScriptsFor(window); | |
| 180 } | |
| 181 | |
| 182 } // namespace blink | 174 } // namespace blink |
| 183 | 175 |
| OLD | NEW |