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 reportExecutionContextsToFrontend(); | 88 reportExecutionContextCreation(); |
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 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 if (frame == m_inspectedPage->mainFrame()) { |
105 m_scriptStateToId.clear(); | 105 m_scriptStateToId.clear(); |
106 m_frontend->executionContextsCleared(); | 106 m_frontend->executionContextsCleared(); |
107 registerMainWorldContext(frame); | |
108 } | 107 } |
109 } | |
110 | |
111 void PageRuntimeAgent::registerMainWorldContext(LocalFrame* frame) | |
112 { | |
113 if (!frame->script().isMainWorldInitialized()) | |
114 return; | |
115 | |
116 String frameId = m_pageAgent->frameId(frame); | 108 String frameId = m_pageAgent->frameId(frame); |
117 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr
ameId); | 109 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr
ameId); |
118 } | 110 } |
119 | 111 |
120 void PageRuntimeAgent::didCreateMainWorldContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) | |
121 { | |
122 if (!m_enabled) | |
123 return; | |
124 ASSERT(m_frontend); | |
125 | |
126 String frameId = m_pageAgent->frameId(frame); | |
127 addExecutionContextToFrontend(scriptState, true, origin->toRawString(), fram
eId); | |
128 } | |
129 | |
130 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) | 112 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState*
scriptState, SecurityOrigin* origin) |
131 { | 113 { |
132 if (!m_enabled) | 114 if (!m_enabled) |
133 return; | 115 return; |
134 ASSERT(m_frontend); | 116 ASSERT(m_frontend); |
135 String frameId = m_pageAgent->frameId(frame); | 117 String frameId = m_pageAgent->frameId(frame); |
136 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra
meId); | 118 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra
meId); |
137 } | 119 } |
138 | 120 |
139 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString,
const int* executionContextId) | 121 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString,
const int* executionContextId) |
(...skipping 14 matching lines...) Expand all Loading... |
154 void PageRuntimeAgent::muteConsole() | 136 void PageRuntimeAgent::muteConsole() |
155 { | 137 { |
156 FrameConsole::mute(); | 138 FrameConsole::mute(); |
157 } | 139 } |
158 | 140 |
159 void PageRuntimeAgent::unmuteConsole() | 141 void PageRuntimeAgent::unmuteConsole() |
160 { | 142 { |
161 FrameConsole::unmute(); | 143 FrameConsole::unmute(); |
162 } | 144 } |
163 | 145 |
164 void PageRuntimeAgent::reportExecutionContextsToFrontend() | 146 void PageRuntimeAgent::reportExecutionContextCreation() |
165 { | 147 { |
166 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; | 148 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; |
167 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { | 149 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree
().traverseNext()) { |
168 if (!frame->isLocalFrame()) | 150 if (!frame->isLocalFrame()) |
169 continue; | 151 continue; |
170 LocalFrame* localFrame = toLocalFrame(frame); | 152 LocalFrame* localFrame = toLocalFrame(frame); |
171 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) | 153 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) |
172 continue; | 154 continue; |
173 String frameId = m_pageAgent->frameId(localFrame); | 155 String frameId = m_pageAgent->frameId(localFrame); |
174 | 156 |
175 registerMainWorldContext(localFrame); | 157 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); |
| 158 addExecutionContextToFrontend(scriptState, true, "", frameId); |
176 localFrame->script().collectIsolatedContexts(isolatedContexts); | 159 localFrame->script().collectIsolatedContexts(isolatedContexts); |
177 if (isolatedContexts.isEmpty()) | 160 if (isolatedContexts.isEmpty()) |
178 continue; | 161 continue; |
179 for (size_t i = 0; i< isolatedContexts.size(); i++) | 162 for (size_t i = 0; i< isolatedContexts.size(); i++) |
180 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol
atedContexts[i].second->toRawString(), frameId); | 163 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol
atedContexts[i].second->toRawString(), frameId); |
181 isolatedContexts.clear(); | 164 isolatedContexts.clear(); |
182 } | 165 } |
183 } | 166 } |
184 | 167 |
185 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) | 168 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) |
186 { | 169 { |
187 Vector<RefPtr<ScriptState> > scriptStatesToRemove; | 170 Vector<RefPtr<ScriptState> > scriptStatesToRemove; |
188 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip
tStateToId.end(); ++it) { | 171 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip
tStateToId.end(); ++it) { |
189 RefPtr<ScriptState> scriptState = it->key; | 172 RefPtr<ScriptState> scriptState = it->key; |
190 if (!scriptState->contextIsValid() || window == scriptState->domWindow()
) { | 173 if (!scriptState->contextIsValid() || window == scriptState->domWindow()
) { |
191 scriptStatesToRemove.append(scriptState); | 174 scriptStatesToRemove.append(scriptState); |
192 m_frontend->executionContextDestroyed(it->value); | 175 m_frontend->executionContextDestroyed(it->value); |
193 } | 176 } |
194 } | 177 } |
195 m_scriptStateToId.removeAll(scriptStatesToRemove); | 178 m_scriptStateToId.removeAll(scriptStatesToRemove); |
196 injectedScriptManager()->discardInjectedScriptsFor(window); | 179 injectedScriptManager()->discardInjectedScriptsFor(window); |
197 } | 180 } |
198 | 181 |
199 } // namespace blink | 182 } // namespace blink |
200 | 183 |
OLD | NEW |