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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 } | 107 } |
108 | |
109 registerMainWorldContext(frame); | |
yurys
2014/10/30 10:23:43
In this case we should not force initialization, i
eustas
2014/10/31 06:59:53
Done.
| |
110 } | |
111 | |
112 void PageRuntimeAgent::registerMainWorldContext(LocalFrame* frame) | |
113 { | |
114 // Force creation on main world contect. | |
aandrey
2014/10/30 10:27:16
maybe add a comment that creation otherwise will h
eustas
2014/10/31 06:59:53
Done.
| |
115 // Positive result means that contect was just initialized, | |
aandrey
2014/10/30 10:27:16
typo: contect
eustas
2014/10/31 06:59:53
Done.
| |
116 // so it was registered in didCreateMainWorldContext. | |
117 if (frame->script().initializeMainWorld()) | |
118 return; | |
119 | |
120 // Negative result means that context already exists, and we need to registe r it. | |
108 String frameId = m_pageAgent->frameId(frame); | 121 String frameId = m_pageAgent->frameId(frame); |
109 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr ameId); | 122 addExecutionContextToFrontend(ScriptState::forMainWorld(frame), true, "", fr ameId); |
110 } | 123 } |
111 | 124 |
125 void PageRuntimeAgent::didCreateMainWorldContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin) | |
126 { | |
127 if (!m_enabled) | |
128 return; | |
129 ASSERT(m_frontend); | |
130 String frameId = m_pageAgent->frameId(frame); | |
131 addExecutionContextToFrontend(scriptState, true, origin->toRawString(), fram eId); | |
132 } | |
133 | |
112 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin) | 134 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin) |
113 { | 135 { |
114 if (!m_enabled) | 136 if (!m_enabled) |
115 return; | 137 return; |
116 ASSERT(m_frontend); | 138 ASSERT(m_frontend); |
117 String frameId = m_pageAgent->frameId(frame); | 139 String frameId = m_pageAgent->frameId(frame); |
118 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra meId); | 140 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra meId); |
119 } | 141 } |
120 | 142 |
121 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) | 143 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) |
(...skipping 14 matching lines...) Expand all Loading... | |
136 void PageRuntimeAgent::muteConsole() | 158 void PageRuntimeAgent::muteConsole() |
137 { | 159 { |
138 FrameConsole::mute(); | 160 FrameConsole::mute(); |
139 } | 161 } |
140 | 162 |
141 void PageRuntimeAgent::unmuteConsole() | 163 void PageRuntimeAgent::unmuteConsole() |
142 { | 164 { |
143 FrameConsole::unmute(); | 165 FrameConsole::unmute(); |
144 } | 166 } |
145 | 167 |
146 void PageRuntimeAgent::reportExecutionContextCreation() | 168 void PageRuntimeAgent::reportExecutionContextCreation() |
aandrey
2014/10/30 10:27:16
nit: reportExecutionContextsToFrontend
eustas
2014/10/31 06:59:53
Done.
| |
147 { | 169 { |
148 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; | 170 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; |
149 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) { | 171 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) { |
150 if (!frame->isLocalFrame()) | 172 if (!frame->isLocalFrame()) |
151 continue; | 173 continue; |
152 LocalFrame* localFrame = toLocalFrame(frame); | 174 LocalFrame* localFrame = toLocalFrame(frame); |
153 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) | 175 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) |
154 continue; | 176 continue; |
155 String frameId = m_pageAgent->frameId(localFrame); | 177 String frameId = m_pageAgent->frameId(localFrame); |
156 | 178 |
157 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); | 179 registerMainWorldContext(localFrame); |
158 addExecutionContextToFrontend(scriptState, true, "", frameId); | |
159 localFrame->script().collectIsolatedContexts(isolatedContexts); | 180 localFrame->script().collectIsolatedContexts(isolatedContexts); |
160 if (isolatedContexts.isEmpty()) | 181 if (isolatedContexts.isEmpty()) |
161 continue; | 182 continue; |
162 for (size_t i = 0; i< isolatedContexts.size(); i++) | 183 for (size_t i = 0; i< isolatedContexts.size(); i++) |
163 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId); | 184 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId); |
164 isolatedContexts.clear(); | 185 isolatedContexts.clear(); |
165 } | 186 } |
166 } | 187 } |
167 | 188 |
168 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) | 189 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) |
169 { | 190 { |
170 Vector<RefPtr<ScriptState> > scriptStatesToRemove; | 191 Vector<RefPtr<ScriptState> > scriptStatesToRemove; |
171 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) { | 192 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) { |
172 RefPtr<ScriptState> scriptState = it->key; | 193 RefPtr<ScriptState> scriptState = it->key; |
173 if (!scriptState->contextIsValid() || window == scriptState->domWindow() ) { | 194 if (!scriptState->contextIsValid() || window == scriptState->domWindow() ) { |
174 scriptStatesToRemove.append(scriptState); | 195 scriptStatesToRemove.append(scriptState); |
175 m_frontend->executionContextDestroyed(it->value); | 196 m_frontend->executionContextDestroyed(it->value); |
176 } | 197 } |
177 } | 198 } |
178 m_scriptStateToId.removeAll(scriptStatesToRemove); | 199 m_scriptStateToId.removeAll(scriptStatesToRemove); |
179 injectedScriptManager()->discardInjectedScriptsFor(window); | 200 injectedScriptManager()->discardInjectedScriptsFor(window); |
180 } | 201 } |
181 | 202 |
182 } // namespace blink | 203 } // namespace blink |
183 | 204 |
OLD | NEW |