| 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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 { | 78 { |
| 79 if (m_enabled) | 79 if (m_enabled) |
| 80 return; | 80 return; |
| 81 | 81 |
| 82 InspectorRuntimeAgent::enable(errorString); | 82 InspectorRuntimeAgent::enable(errorString); |
| 83 | 83 |
| 84 // Only report existing contexts if the page did commit load, otherwise we m
ay | 84 // Only report existing contexts if the page did commit load, otherwise we m
ay |
| 85 // unintentionally initialize contexts in the frames which may trigger some
listeners | 85 // unintentionally initialize contexts in the frames which may trigger some
listeners |
| 86 // that are expected to be triggered only after the load is committed, see h
ttp://crbug.com/131623 | 86 // that are expected to be triggered only after the load is committed, see h
ttp://crbug.com/131623 |
| 87 if (m_mainWorldContextCreated) | 87 if (m_mainWorldContextCreated) |
| 88 reportExecutionContextCreation(); | 88 reportExecutionContextsToFrontend(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 void PageRuntimeAgent::run(ErrorString* errorString) | 91 void PageRuntimeAgent::run(ErrorString* errorString) |
| 92 { | 92 { |
| 93 m_client->resumeStartup(); | 93 m_client->resumeStartup(); |
| 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 |
| 101 void PageRuntimeAgent::registerMainWorldContext(LocalFrame* frame) |
| 102 { |
| 103 if (!frame->script().isMainWorldInitialized()) |
| 104 return; |
| 105 |
| 106 String frameId = m_pageAgent->frameId(frame); |
| 107 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr
ameId); |
| 108 } |
| 109 |
| 110 void PageRuntimeAgent::didCreateMainWorldContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) |
| 111 { |
| 100 if (!m_enabled) | 112 if (!m_enabled) |
| 101 return; | 113 return; |
| 102 ASSERT(m_frontend); | 114 ASSERT(m_frontend); |
| 103 | 115 |
| 104 if (frame == m_inspectedPage->mainFrame()) { | |
| 105 m_scriptStateToId.clear(); | |
| 106 m_frontend->executionContextsCleared(); | |
| 107 } | |
| 108 String frameId = m_pageAgent->frameId(frame); | 116 String frameId = m_pageAgent->frameId(frame); |
| 109 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr
ameId); | 117 addExecutionContextToFrontend(scriptState, true, origin->toRawString(), fram
eId); |
| 110 } | 118 } |
| 111 | 119 |
| 112 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) | 120 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) |
| 113 { | 121 { |
| 114 if (!m_enabled) | 122 if (!m_enabled) |
| 115 return; | 123 return; |
| 116 ASSERT(m_frontend); | 124 ASSERT(m_frontend); |
| 117 String frameId = m_pageAgent->frameId(frame); | 125 String frameId = m_pageAgent->frameId(frame); |
| 118 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra
meId); | 126 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra
meId); |
| 119 } | 127 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 136 void PageRuntimeAgent::muteConsole() | 144 void PageRuntimeAgent::muteConsole() |
| 137 { | 145 { |
| 138 FrameConsole::mute(); | 146 FrameConsole::mute(); |
| 139 } | 147 } |
| 140 | 148 |
| 141 void PageRuntimeAgent::unmuteConsole() | 149 void PageRuntimeAgent::unmuteConsole() |
| 142 { | 150 { |
| 143 FrameConsole::unmute(); | 151 FrameConsole::unmute(); |
| 144 } | 152 } |
| 145 | 153 |
| 146 void PageRuntimeAgent::reportExecutionContextCreation() | 154 void PageRuntimeAgent::reportExecutionContextsToFrontend() |
| 147 { | 155 { |
| 148 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; | 156 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; |
| 149 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { | 157 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { |
| 150 if (!frame->isLocalFrame()) | 158 if (!frame->isLocalFrame()) |
| 151 continue; | 159 continue; |
| 152 LocalFrame* localFrame = toLocalFrame(frame); | 160 LocalFrame* localFrame = toLocalFrame(frame); |
| 153 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) | 161 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) |
| 154 continue; | 162 continue; |
| 155 String frameId = m_pageAgent->frameId(localFrame); | 163 String frameId = m_pageAgent->frameId(localFrame); |
| 156 | 164 |
| 157 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); | 165 registerMainWorldContext(localFrame); |
| 158 addExecutionContextToFrontend(scriptState, true, "", frameId); | |
| 159 localFrame->script().collectIsolatedContexts(isolatedContexts); | 166 localFrame->script().collectIsolatedContexts(isolatedContexts); |
| 160 if (isolatedContexts.isEmpty()) | 167 if (isolatedContexts.isEmpty()) |
| 161 continue; | 168 continue; |
| 162 for (size_t i = 0; i< isolatedContexts.size(); i++) | 169 for (size_t i = 0; i< isolatedContexts.size(); i++) |
| 163 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol
atedContexts[i].second->toRawString(), frameId); | 170 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol
atedContexts[i].second->toRawString(), frameId); |
| 164 isolatedContexts.clear(); | 171 isolatedContexts.clear(); |
| 165 } | 172 } |
| 166 } | 173 } |
| 167 | 174 |
| 168 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) | 175 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) |
| 169 { | 176 { |
| 170 Vector<RefPtr<ScriptState> > scriptStatesToRemove; | 177 Vector<RefPtr<ScriptState> > scriptStatesToRemove; |
| 171 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip
tStateToId.end(); ++it) { | 178 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip
tStateToId.end(); ++it) { |
| 172 RefPtr<ScriptState> scriptState = it->key; | 179 RefPtr<ScriptState> scriptState = it->key; |
| 173 if (!scriptState->contextIsValid() || window == scriptState->domWindow()
) { | 180 if (!scriptState->contextIsValid() || window == scriptState->domWindow()
) { |
| 174 scriptStatesToRemove.append(scriptState); | 181 scriptStatesToRemove.append(scriptState); |
| 175 m_frontend->executionContextDestroyed(it->value); | 182 m_frontend->executionContextDestroyed(it->value); |
| 176 } | 183 } |
| 177 } | 184 } |
| 178 m_scriptStateToId.removeAll(scriptStatesToRemove); | 185 m_scriptStateToId.removeAll(scriptStatesToRemove); |
| 179 injectedScriptManager()->discardInjectedScriptsFor(window); | 186 injectedScriptManager()->discardInjectedScriptsFor(window); |
| 180 } | 187 } |
| 181 | 188 |
| 182 } // namespace blink | 189 } // namespace blink |
| 183 | 190 |
| OLD | NEW |