Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: Source/core/inspector/PageRuntimeAgent.cpp

Issue 686763002: Fix Runtime.executionContextCreated for crafted iframes. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Do not force context initialization Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 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 registerMainWorldContext(frame);
109 }
110
111 void PageRuntimeAgent::registerMainWorldContext(LocalFrame* frame)
112 {
113 if (!frame->script().isMainWorldInitialized())
114 return;
115
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::forMainWorld(frame), true, "", fr ameId);
110 } 118 }
111 119
120 void PageRuntimeAgent::didCreateMainWorldContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin)
121 {
122 if (!m_enabled)
123 return;
124 ASSERT(m_frontend);
125 base::debug::StackTrace().Print();
vsevik 2014/10/31 14:58:07 remove
eustas 2014/11/03 20:14:16 Done.
126 String frameId = m_pageAgent->frameId(frame);
127 addExecutionContextToFrontend(scriptState, true, origin->toRawString(), fram eId);
128 }
129
112 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin) 130 void PageRuntimeAgent::didCreateIsolatedContext(LocalFrame* frame, ScriptState* scriptState, SecurityOrigin* origin)
113 { 131 {
114 if (!m_enabled) 132 if (!m_enabled)
115 return; 133 return;
116 ASSERT(m_frontend); 134 ASSERT(m_frontend);
117 String frameId = m_pageAgent->frameId(frame); 135 String frameId = m_pageAgent->frameId(frame);
118 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra meId); 136 addExecutionContextToFrontend(scriptState, false, origin->toRawString(), fra meId);
119 } 137 }
120 138
121 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) 139 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId)
(...skipping 14 matching lines...) Expand all
136 void PageRuntimeAgent::muteConsole() 154 void PageRuntimeAgent::muteConsole()
137 { 155 {
138 FrameConsole::mute(); 156 FrameConsole::mute();
139 } 157 }
140 158
141 void PageRuntimeAgent::unmuteConsole() 159 void PageRuntimeAgent::unmuteConsole()
142 { 160 {
143 FrameConsole::unmute(); 161 FrameConsole::unmute();
144 } 162 }
145 163
146 void PageRuntimeAgent::reportExecutionContextCreation() 164 void PageRuntimeAgent::reportExecutionContextsToFrontend()
147 { 165 {
148 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; 166 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts;
149 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) { 167 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree ().traverseNext()) {
150 if (!frame->isLocalFrame()) 168 if (!frame->isLocalFrame())
151 continue; 169 continue;
152 LocalFrame* localFrame = toLocalFrame(frame); 170 LocalFrame* localFrame = toLocalFrame(frame);
153 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript)) 171 if (!localFrame->script().canExecuteScripts(NotAboutToExecuteScript))
154 continue; 172 continue;
155 String frameId = m_pageAgent->frameId(localFrame); 173 String frameId = m_pageAgent->frameId(localFrame);
156 174
157 ScriptState* scriptState = ScriptState::forMainWorld(localFrame); 175 registerMainWorldContext(localFrame);
yurys 2014/10/31 15:08:03 Am I right that now we may end up with 0 contexts
eustas 2014/11/03 20:14:16 Yes and no. Theoretically - yes. But I've examined
158 addExecutionContextToFrontend(scriptState, true, "", frameId);
159 localFrame->script().collectIsolatedContexts(isolatedContexts); 176 localFrame->script().collectIsolatedContexts(isolatedContexts);
160 if (isolatedContexts.isEmpty()) 177 if (isolatedContexts.isEmpty())
161 continue; 178 continue;
162 for (size_t i = 0; i< isolatedContexts.size(); i++) 179 for (size_t i = 0; i< isolatedContexts.size(); i++)
163 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId); 180 addExecutionContextToFrontend(isolatedContexts[i].first, false, isol atedContexts[i].second->toRawString(), frameId);
164 isolatedContexts.clear(); 181 isolatedContexts.clear();
165 } 182 }
166 } 183 }
167 184
168 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window) 185 void PageRuntimeAgent::frameWindowDiscarded(LocalDOMWindow* window)
169 { 186 {
170 Vector<RefPtr<ScriptState> > scriptStatesToRemove; 187 Vector<RefPtr<ScriptState> > scriptStatesToRemove;
171 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) { 188 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scrip tStateToId.end(); ++it) {
172 RefPtr<ScriptState> scriptState = it->key; 189 RefPtr<ScriptState> scriptState = it->key;
173 if (!scriptState->contextIsValid() || window == scriptState->domWindow() ) { 190 if (!scriptState->contextIsValid() || window == scriptState->domWindow() ) {
174 scriptStatesToRemove.append(scriptState); 191 scriptStatesToRemove.append(scriptState);
175 m_frontend->executionContextDestroyed(it->value); 192 m_frontend->executionContextDestroyed(it->value);
176 } 193 }
177 } 194 }
178 m_scriptStateToId.removeAll(scriptStatesToRemove); 195 m_scriptStateToId.removeAll(scriptStatesToRemove);
179 injectedScriptManager()->discardInjectedScriptsFor(window); 196 injectedScriptManager()->discardInjectedScriptsFor(window);
180 } 197 }
181 198
182 } // namespace blink 199 } // namespace blink
183 200
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698