Changeset 116744 in webkit
- Timestamp:
- May 11, 2012 2:55:19 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r116743 r116744 1 2012-05-04 Yury Semikhatsky <yurys@chromium.org> 2 3 Web Inspector: console should allow JS execution in the context of an isolated world 4 https://bugs.webkit.org/show_bug.cgi?id=85612 5 6 Reviewed by Pavel Feldman. 7 8 Added an option to select not only a frame but also isolated world in which 9 to perform evaluation of the code typed into the console. 10 11 Each execution context can be identified using it injected script id. We call it 12 execution context id in the protocol. Runtime agent is extended with an event that 13 is sent when new ExecutionContext is created. The event tracking can be enabled/disabled 14 using setReportExecutionContextCreation command. 15 16 * bindings/js/ScriptController.cpp: 17 (WebCore): 18 (WebCore::isolatedWorldToSecurityOriginMap): 19 * bindings/js/ScriptController.h: 20 (ScriptController): 21 * bindings/js/ScriptState.cpp: 22 (WebCore::isolatedWorldScriptState): 23 (WebCore): 24 * bindings/js/ScriptState.h: 25 (WebCore): 26 * bindings/v8/ScriptController.cpp: 27 (WebCore): 28 (WebCore::ScriptController::isolatedWorldToSecurityOriginMap): 29 * bindings/v8/ScriptController.h: 30 (ScriptController): 31 * bindings/v8/ScriptState.cpp: 32 (WebCore::isolatedWorldScriptState): 33 (WebCore): 34 * bindings/v8/ScriptState.h: 35 (WebCore): 36 * bindings/v8/V8IsolatedContext.cpp: 37 (WebCore::V8IsolatedContext::setSecurityOrigin): 38 * bindings/v8/V8Proxy.cpp: 39 (WebCore::V8Proxy::setIsolatedWorldSecurityOrigin): 40 (WebCore::V8Proxy::isolatedWorldContext): 41 (WebCore): 42 (WebCore::V8Proxy::isolatedWorldToSecurityOriginMap): 43 * bindings/v8/V8Proxy.h: 44 (V8Proxy): 45 * inspector/CodeGeneratorInspector.py: 46 (DomainNameFixes): 47 * inspector/Inspector.json: 48 * inspector/InspectorInstrumentation.cpp: 49 (WebCore::InspectorInstrumentation::didCreateIsolatedContextImpl): 50 (WebCore): 51 * inspector/InspectorInstrumentation.h: 52 (WebCore): 53 (InspectorInstrumentation): 54 (WebCore::InspectorInstrumentation::didCreateIsolatedContext): 55 * inspector/InspectorRuntimeAgent.cpp: 56 (WebCore::InspectorRuntimeAgent::evaluate): 57 * inspector/InspectorRuntimeAgent.h: 58 (InspectorRuntimeAgent): 59 * inspector/InstrumentingAgents.h: 60 (WebCore): 61 (WebCore::InstrumentingAgents::InstrumentingAgents): 62 (WebCore::InstrumentingAgents::pageRuntimeAgent): 63 (WebCore::InstrumentingAgents::setPageRuntimeAgent): 64 (InstrumentingAgents): 65 * inspector/PageRuntimeAgent.cpp: 66 (PageRuntimeAgentState): 67 (WebCore): 68 (WebCore::PageRuntimeAgent::PageRuntimeAgent): 69 (WebCore::PageRuntimeAgent::setFrontend): 70 (WebCore::PageRuntimeAgent::clearFrontend): 71 (WebCore::PageRuntimeAgent::restore): 72 (WebCore::PageRuntimeAgent::setReportExecutionContextCreation): 73 (WebCore::PageRuntimeAgent::didCreateExecutionContext): 74 (WebCore::PageRuntimeAgent::getScriptStateForEval): 75 * inspector/PageRuntimeAgent.h: 76 (WebCore): 77 (PageRuntimeAgent): 78 * inspector/WorkerRuntimeAgent.cpp: 79 (WebCore::WorkerRuntimeAgent::setReportExecutionContextCreation): 80 (WebCore::WorkerRuntimeAgent::getScriptStateForEval): 81 * inspector/WorkerRuntimeAgent.h: 82 (WorkerRuntimeAgent): 83 * inspector/front-end/ConsoleView.js: 84 (WebInspector.ConsoleView.prototype.get statusBarItems): 85 (WebInspector.ConsoleView.prototype.addContext): 86 (WebInspector.ConsoleView.prototype.removeContext): 87 (WebInspector.ConsoleView.prototype._updateIsolatedWorldSelector): 88 (WebInspector.ConsoleView.prototype._contextUpdated): 89 (WebInspector.ConsoleView.prototype._addedExecutionContext): 90 (WebInspector.ConsoleView.prototype._currentEvaluationContextId): 91 (WebInspector.ConsoleView.prototype._currentEvaluationContext): 92 (WebInspector.ConsoleView.prototype._currentIsolatedWorldId): 93 (WebInspector.ConsoleView.prototype.evalInInspectedWindow): 94 * inspector/front-end/ExtensionPanel.js: 95 (WebInspector.ExtensionSidebarPane.prototype.setExpression): 96 * inspector/front-end/ExtensionServer.js: 97 (WebInspector.ExtensionServer.prototype._onEvaluateOnInspectedPage): 98 * inspector/front-end/JavaScriptContextManager.js: 99 (WebInspector.JavaScriptContextManager): 100 (WebInspector.JavaScriptContextManager.prototype._didLoadCachedResources): 101 (WebInspector.JavaScriptContextManager.prototype.isolatedContextCreated): 102 (WebInspector.RuntimeDispatcher): 103 (WebInspector.RuntimeDispatcher.prototype.isolatedContextCreated): 104 (WebInspector.ExecutionContext): 105 (WebInspector.ExecutionContext.comparator): 106 (WebInspector.FrameEvaluationContext): 107 (WebInspector.FrameEvaluationContext.prototype._frameNavigated): 108 (WebInspector.FrameEvaluationContext.prototype._addExecutionContext): 109 (WebInspector.FrameEvaluationContext.prototype._ensureMainWorldContextAdded): 110 (WebInspector.FrameEvaluationContext.prototype.isolatedContexts): 111 1 112 2012-05-11 Andrey Kosyakov <caseq@chromium.org> 2 113 -
trunk/Source/WebCore/bindings/js/ScriptController.cpp
r115498 r116744 327 327 { 328 328 } 329 330 void ScriptController::collectIsolatedContexts(Vector<std::pair<JSC::ExecState*, SecurityOrigin*> >&) 331 { 332 // FIXME(85709): support isolated contexts inspection for JSC. 333 } 329 334 #endif 330 335 -
trunk/Source/WebCore/bindings/js/ScriptController.h
r115498 r116744 41 41 namespace JSC { 42 42 class JSGlobalObject; 43 class ExecState; 43 44 44 45 namespace Bindings { … … 53 54 class ScriptSourceCode; 54 55 class ScriptValue; 56 class SecurityOrigin; 55 57 class Widget; 56 58 … … 144 146 #if ENABLE(INSPECTOR) 145 147 static void setCaptureCallStackForUncaughtExceptions(bool); 148 void collectIsolatedContexts(Vector<std::pair<JSC::ExecState*, SecurityOrigin*> >&); 146 149 #endif 147 150 -
trunk/Source/WebCore/bindings/v8/ScriptController.cpp
r115670 r116744 468 468 v8::V8::SetCaptureStackTraceForUncaughtExceptions(value, ScriptCallStack::maxCallStackSizeToCapture, stackTraceOptions); 469 469 } 470 471 void ScriptController::collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >& result) 472 { 473 m_proxy->collectIsolatedContexts(result); 474 } 470 475 #endif 471 476 -
trunk/Source/WebCore/bindings/v8/ScriptController.h
r115498 r116744 62 62 class PagePopupClient; 63 63 class ScriptSourceCode; 64 class ScriptState; 64 65 class Widget; 65 66 … … 135 136 #if ENABLE(INSPECTOR) 136 137 static void setCaptureCallStackForUncaughtExceptions(bool); 138 void collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >&); 137 139 #endif 138 140 -
trunk/Source/WebCore/bindings/v8/V8IsolatedContext.cpp
r116580 r116744 35 35 #include "Frame.h" 36 36 #include "FrameLoaderClient.h" 37 #include "InspectorInstrumentation.h" 37 38 #include "SecurityOrigin.h" 38 39 #include "V8BindingPerContextData.h" … … 119 120 void V8IsolatedContext::setSecurityOrigin(PassRefPtr<SecurityOrigin> securityOrigin) 120 121 { 122 if (!m_securityOrigin && InspectorInstrumentation::hasFrontends() && !context().IsEmpty()) { 123 v8::HandleScope handleScope; 124 ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(context())); 125 InspectorInstrumentation::didCreateIsolatedContext(m_frame, scriptState, securityOrigin.get()); 126 } 121 127 m_securityOrigin = securityOrigin; 122 128 } -
trunk/Source/WebCore/bindings/v8/V8Proxy.cpp
r116171 r116744 632 632 } 633 633 634 v8::Local<v8::Context> V8Proxy::isolatedWorldContext(int worldId) 635 { 636 IsolatedWorldMap::iterator iter = m_isolatedWorlds.find(worldId); 637 if (iter == m_isolatedWorlds.end()) 638 return v8::Local<v8::Context>(); 639 return v8::Local<v8::Context>::New(iter->second->context()); 640 } 641 634 642 bool V8Proxy::matchesCurrentContext() 635 643 { … … 728 736 } 729 737 738 void V8Proxy::collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >& result) 739 { 740 v8::HandleScope handleScope; 741 for (IsolatedWorldMap::iterator it = m_isolatedWorlds.begin(); it != m_isolatedWorlds.end(); ++it) { 742 V8IsolatedContext* isolatedContext = it->second; 743 if (!isolatedContext->securityOrigin()) 744 continue; 745 v8::Handle<v8::Context> v8Context = isolatedContext->context(); 746 if (v8Context.IsEmpty()) 747 continue; 748 ScriptState* scriptState = ScriptState::forContext(v8::Local<v8::Context>::New(v8Context)); 749 result.append(std::pair<ScriptState*, SecurityOrigin*>(scriptState, isolatedContext->securityOrigin())); 750 } 751 } 752 730 753 v8::Local<v8::Context> toV8Context(ScriptExecutionContext* context, const WorldContextHandle& worldContext) 731 754 { -
trunk/Source/WebCore/bindings/v8/V8Proxy.h
r115522 r116744 245 245 v8::Local<v8::Context> context(); 246 246 v8::Local<v8::Context> mainWorldContext(); 247 v8::Local<v8::Context> isolatedWorldContext(int worldId); 247 248 bool matchesCurrentContext(); 248 249 … … 252 253 bool setContextDebugId(int id); 253 254 static int contextDebugId(v8::Handle<v8::Context>); 255 void collectIsolatedContexts(Vector<std::pair<ScriptState*, SecurityOrigin*> >&); 254 256 255 257 // Registers a v8 extension to be available on webpages. Will only -
trunk/Source/WebCore/inspector/CodeGeneratorInspector.py
r116641 r116744 186 186 return Res 187 187 188 skip_js_bind_domains = set([" Runtime", "DOMDebugger"])188 skip_js_bind_domains = set(["DOMDebugger"]) 189 189 190 190 -
trunk/Source/WebCore/inspector/InjectedScriptManager.cpp
r110854 r116744 80 80 InjectedScript InjectedScriptManager::injectedScriptForId(long id) 81 81 { 82 return m_idToInjectedScript.get(id); 82 IdToInjectedScriptMap::iterator it = m_idToInjectedScript.find(id); 83 if (it != m_idToInjectedScript.end()) 84 return it->second; 85 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) { 86 if (it->second == id) 87 return injectedScriptFor(it->first); 88 } 89 return InjectedScript(); 90 } 91 92 long InjectedScriptManager::injectedScriptIdFor(ScriptState* scriptState) 93 { 94 ScriptStateToId::iterator it = m_scriptStateToId.find(scriptState); 95 if (it != m_scriptStateToId.end()) 96 return it->second; 97 long id = m_nextInjectedScriptId++; 98 m_scriptStateToId.set(scriptState, id); 99 return id; 83 100 } 84 101 … … 90 107 bool success = parsedObjectId->asObject()->getNumber("injectedScriptId", &injectedScriptId); 91 108 if (success) 92 return injectedScriptForId(injectedScriptId);109 return m_idToInjectedScript.get(injectedScriptId); 93 110 } 94 111 return InjectedScript(); … … 101 118 discardInjectedScript(it->second.scriptState()); 102 119 m_idToInjectedScript.clear(); 120 m_scriptStateToId.clear(); 103 121 } 104 122 105 123 void InjectedScriptManager::discardInjectedScriptsFor(DOMWindow* window) 106 124 { 125 if (m_scriptStateToId.isEmpty()) 126 return; 127 107 128 Vector<long> idsToRemove; 108 129 IdToInjectedScriptMap::iterator end = m_idToInjectedScript.end(); … … 112 133 continue; 113 134 discardInjectedScript(scriptState); 135 m_scriptStateToId.remove(scriptState); 114 136 idsToRemove.append(it->first); 115 137 } … … 117 139 for (size_t i = 0; i < idsToRemove.size(); i++) 118 140 m_idToInjectedScript.remove(idsToRemove[i]); 141 142 // Now remove script states that have id but no injected script. 143 Vector<ScriptState*> scriptStatesToRemove; 144 for (ScriptStateToId::iterator it = m_scriptStateToId.begin(); it != m_scriptStateToId.end(); ++it) { 145 ScriptState* scriptState = it->first; 146 if (window == domWindowFromScriptState(scriptState)) 147 scriptStatesToRemove.append(scriptState); 148 } 149 for (size_t i = 0; i < scriptStatesToRemove.size(); i++) 150 m_scriptStateToId.remove(scriptStatesToRemove[i]); 119 151 } 120 152 … … 137 169 pair<long, ScriptObject> InjectedScriptManager::injectScript(const String& source, ScriptState* scriptState) 138 170 { 139 long id = m_nextInjectedScriptId++;171 long id = injectedScriptIdFor(scriptState); 140 172 return std::make_pair(id, createInjectedScript(source, scriptState, id)); 141 173 } -
trunk/Source/WebCore/inspector/InjectedScriptManager.h
r95901 r116744 59 59 InjectedScript injectedScriptFor(ScriptState*); 60 60 InjectedScript injectedScriptForId(long); 61 long injectedScriptIdFor(ScriptState*); 61 62 InjectedScript injectedScriptForObjectId(const String& objectId); 62 63 void discardInjectedScripts(); … … 81 82 RefPtr<InjectedScriptHost> m_injectedScriptHost; 82 83 InspectedStateAccessCheck m_inspectedStateAccessCheck; 84 typedef HashMap<ScriptState*, long> ScriptStateToId; 85 ScriptStateToId m_scriptStateToId; 83 86 }; 84 87 -
trunk/Source/WebCore/inspector/Inspector.json
r116237 r116744 428 428 { "name": "objectId", "$ref": "RemoteObjectId", "optional": true, "description": "Remote object handle." } 429 429 ] 430 } 430 }, 431 { 432 "id": "ExecutionContextId", 433 "type": "integer", 434 "description": "Id of an execution context.", 435 "hidden": true 436 }, 437 { 438 "id": "ExecutionContextDescription", 439 "type": "object", 440 "description": "Description of an isolated world.", 441 "properties": [ 442 { "name": "id", "$ref": "ExecutionContextId", "description": "Unique id of the execution context. It can be used to specify in which execution context script evaluation should be performed." }, 443 { "name": "isPageContext", "type": "boolean", "description": "True if this is a context where inpspected web page scripts run. False if it is a content script isolated context." }, 444 { "name": "name", "type": "string", "description": "Human readable name describing given context." }, 445 { "name": "frameId", "$ref": "Network.FrameId", "description": "Id of the owning frame." } 446 ], 447 "hidden": true 448 } 449 431 450 ], 432 451 "commands": [ … … 438 457 { "name": "includeCommandLineAPI", "type": "boolean", "optional": true, "description": "Determines whether Command Line API should be available during the evaluation.", "hidden": true }, 439 458 { "name": "doNotPauseOnExceptionsAndMuteConsole", "type": "boolean", "optional": true, "description": "Specifies whether evaluation should stop on exceptions and mute console. Overrides setPauseOnException state.", "hidden": true }, 440 { "name": " frameId", "$ref": "Network.FrameId", "optional": true, "description": "Specifies in which frame to perform evaluation.", "hidden": true },459 { "name": "contextId", "type": "integer", "optional": true, "description": "Specifies in which isolated context to perform evaluation. Each content script lives in an isolated context and this parameter may be used to specify on of those contexts. If the parameter is omitted or 0 the evaluation will be performed in the context of the inspected page.", "hidden": true }, 441 460 { "name": "returnByValue", "type": "boolean", "optional": true, "description": "Whether the result is expected to be a JSON object that should be sent by value." } 442 461 ], … … 491 510 "hidden": true, 492 511 "description": "Tells inspected instance(worker or page) that it can run in case it was started paused." 512 }, 513 { 514 "name": "setReportExecutionContextCreation", 515 "parameters": [ 516 { "name": "enabled", "type": "boolean", "description": "Reporting enabled state." } 517 ], 518 "hidden": true, 519 "description": "Enables reporting about creation of isolated contexts by means of <code>isolatedContextCreated</code> event. When the reporting gets enabled the event will be sent immediately for each existing isolated context." 520 } 521 522 ], 523 "events": [ 524 { 525 "name": "isolatedContextCreated", 526 "parameters": [ 527 { "name": "context", "$ref": "ExecutionContextDescription", "description": "A newly created isolated contex." } 528 ], 529 "description": "Issued when new isolated context is created." 493 530 } 494 531 ] -
trunk/Source/WebCore/inspector/InspectorInstrumentation.cpp
r115427 r116744 62 62 #include "InspectorWorkerAgent.h" 63 63 #include "InstrumentingAgents.h" 64 #include "PageRuntimeAgent.h" 64 65 #include "ScriptArguments.h" 65 66 #include "ScriptCallStack.h" … … 113 114 } 114 115 #endif 116 if (PageRuntimeAgent* pageRuntimeAgent = instrumentingAgents->pageRuntimeAgent()) { 117 if (world == mainThreadNormalWorld()) 118 pageRuntimeAgent->didClearWindowObject(frame); 119 } 115 120 } 116 121 … … 362 367 if (InspectorTimelineAgent* timelineAgent = retrieveTimelineAgent(cookie)) 363 368 timelineAgent->didEvaluateScript(); 369 } 370 371 void InspectorInstrumentation::didCreateIsolatedContextImpl(InstrumentingAgents* instrumentingAgents, Frame* frame, ScriptState* scriptState, SecurityOrigin* origin) 372 { 373 if (PageRuntimeAgent* runtimeAgent = instrumentingAgents->pageRuntimeAgent()) 374 runtimeAgent->didCreateIsolatedContext(frame, scriptState, origin); 364 375 } 365 376 -
trunk/Source/WebCore/inspector/InspectorInstrumentation.h
r115427 r116744 40 40 #include "ScriptExecutionContext.h" 41 41 42 #if USE(JSC) 43 namespace JSC { 44 class ExecState; 45 } 46 #endif 47 42 48 namespace WebCore { 43 49 … … 64 70 class ScriptExecutionContext; 65 71 class ScriptProfile; 72 class SecurityOrigin; 66 73 class ShadowRoot; 67 74 class StorageArea; … … 70 77 class WorkerContextProxy; 71 78 class XMLHttpRequest; 79 80 #if USE(JSC) 81 typedef JSC::ExecState ScriptState; 82 #else 83 class ScriptState; 84 #endif 72 85 73 86 #if ENABLE(WEB_SOCKETS) … … 120 133 static InspectorInstrumentationCookie willEvaluateScript(Frame*, const String& url, int lineNumber); 121 134 static void didEvaluateScript(const InspectorInstrumentationCookie&); 135 static void didCreateIsolatedContext(Frame*, ScriptState*, SecurityOrigin*); 122 136 static InspectorInstrumentationCookie willFireTimer(ScriptExecutionContext*, int timerId); 123 137 static void didFireTimer(const InspectorInstrumentationCookie&); … … 279 293 static InspectorInstrumentationCookie willEvaluateScriptImpl(InstrumentingAgents*, const String& url, int lineNumber); 280 294 static void didEvaluateScriptImpl(const InspectorInstrumentationCookie&); 295 static void didCreateIsolatedContextImpl(InstrumentingAgents*, Frame*, ScriptState*, SecurityOrigin*); 281 296 static InspectorInstrumentationCookie willFireTimerImpl(InstrumentingAgents*, int timerId); 282 297 static void didFireTimerImpl(const InspectorInstrumentationCookie&); … … 707 722 } 708 723 724 inline void InspectorInstrumentation::didCreateIsolatedContext(Frame* frame, ScriptState* scriptState, SecurityOrigin* origin) 725 { 726 #if ENABLE(INSPECTOR) 727 FAST_RETURN_IF_NO_FRONTENDS(void()); 728 if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForFrame(frame)) 729 return didCreateIsolatedContextImpl(instrumentingAgents, frame, scriptState, origin); 730 #endif 731 } 732 709 733 inline InspectorInstrumentationCookie InspectorInstrumentation::willFireTimer(ScriptExecutionContext* context, int timerId) 710 734 { -
trunk/Source/WebCore/inspector/InspectorRuntimeAgent.cpp
r116099 r116744 84 84 #endif 85 85 86 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptionsAndMuteConsole, const String* const frameId, const bool* const returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown)86 void InspectorRuntimeAgent::evaluate(ErrorString* errorString, const String& expression, const String* const objectGroup, const bool* const includeCommandLineAPI, const bool* const doNotPauseOnExceptionsAndMuteConsole, const int* executionContextId, const bool* const returnByValue, RefPtr<TypeBuilder::Runtime::RemoteObject>& result, TypeBuilder::OptOutput<bool>* wasThrown) 87 87 { 88 ScriptState* scriptState = scriptStateForEval(errorString, frameId);89 if ( !scriptState)88 InjectedScript injectedScript = injectedScriptForEval(errorString, executionContextId); 89 if (injectedScript.hasNoValue()) 90 90 return; 91 InjectedScript injectedScript = m_injectedScriptManager->injectedScriptFor(scriptState);92 if (injectedScript.hasNoValue()) {93 *errorString = "Inspected frame has gone";94 return;95 }96 91 #if ENABLE(JAVASCRIPT_DEBUGGER) 97 92 ScriptDebugServer::PauseOnExceptionsState previousPauseOnExceptionsState = ScriptDebugServer::DontPauseOnExceptions; -
trunk/Source/WebCore/inspector/InspectorRuntimeAgent.h
r116099 r116744 41 41 namespace WebCore { 42 42 43 class InjectedScript; 43 44 class InjectedScriptManager; 44 45 class InspectorArray; … … 63 64 const bool* includeCommandLineAPI, 64 65 const bool* doNotPauseOnExceptionsAndMuteConsole, 65 const String* frameId,66 const int* executionContextId, 66 67 const bool* returnByValue, 67 68 RefPtr<TypeBuilder::Runtime::RemoteObject>& result, … … 89 90 protected: 90 91 InspectorRuntimeAgent(InstrumentingAgents*, InspectorState*, InjectedScriptManager*); 91 virtual ScriptState* scriptStateForEval(ErrorString*, const String* frameId) = 0;92 virtual InjectedScript injectedScriptForEval(ErrorString*, const int* executionContextId) = 0; 92 93 93 94 virtual void muteConsole() = 0; 94 95 virtual void unmuteConsole() = 0; 96 97 InjectedScriptManager* injectedScriptManager() { return m_injectedScriptManager; } 95 98 96 99 private: -
trunk/Source/WebCore/inspector/InstrumentingAgents.h
r101236 r116744 54 54 class InspectorWorkerAgent; 55 55 class Page; 56 class PageRuntimeAgent; 56 57 class WorkerContext; 57 58 … … 68 69 , m_inspectorResourceAgent(0) 69 70 , m_inspectorRuntimeAgent(0) 71 , m_pageRuntimeAgent(0) 70 72 , m_inspectorTimelineAgent(0) 71 73 , m_inspectorDOMStorageAgent(0) … … 108 110 InspectorRuntimeAgent* inspectorRuntimeAgent() const { return m_inspectorRuntimeAgent; } 109 111 void setInspectorRuntimeAgent(InspectorRuntimeAgent* agent) { m_inspectorRuntimeAgent = agent; } 112 113 PageRuntimeAgent* pageRuntimeAgent() const { return m_pageRuntimeAgent; } 114 void setPageRuntimeAgent(PageRuntimeAgent* agent) { m_pageRuntimeAgent = agent; } 110 115 111 116 InspectorTimelineAgent* inspectorTimelineAgent() const { return m_inspectorTimelineAgent; } … … 151 156 InspectorResourceAgent* m_inspectorResourceAgent; 152 157 InspectorRuntimeAgent* m_inspectorRuntimeAgent; 158 PageRuntimeAgent* m_pageRuntimeAgent; 153 159 InspectorTimelineAgent* m_inspectorTimelineAgent; 154 160 InspectorDOMStorageAgent* m_inspectorDOMStorageAgent; -
trunk/Source/WebCore/inspector/PageRuntimeAgent.cpp
r116099 r116744 36 36 37 37 #include "Console.h" 38 #include "Document.h" 39 #include "InjectedScript.h" 40 #include "InjectedScriptManager.h" 38 41 #include "InspectorPageAgent.h" 42 #include "InspectorState.h" 43 #include "InstrumentingAgents.h" 39 44 #include "Page.h" 40 #include "ScriptState.h" 45 #include "SecurityOrigin.h" 46 47 using WebCore::TypeBuilder::Runtime::ExecutionContextDescription; 41 48 42 49 namespace WebCore { 50 51 namespace PageRuntimeAgentState { 52 static const char reportExecutionContextCreation[] = "reportExecutionContextCreation"; 53 }; 43 54 44 55 PageRuntimeAgent::PageRuntimeAgent(InstrumentingAgents* instrumentingAgents, InspectorState* state, InjectedScriptManager* injectedScriptManager, Page* page, InspectorPageAgent* pageAgent) … … 46 57 , m_inspectedPage(page) 47 58 , m_pageAgent(pageAgent) 59 , m_frontend(0) 48 60 { 49 61 } … … 53 65 } 54 66 55 ScriptState* PageRuntimeAgent::scriptStateForEval(ErrorString* errorString, const String* frameId)67 void PageRuntimeAgent::setFrontend(InspectorFrontend* frontend) 56 68 { 57 if (!frameId) 58 return mainWorldScriptState(m_inspectedPage->mainFrame()); 69 m_frontend = frontend->runtime(); 70 m_instrumentingAgents->setPageRuntimeAgent(this); 71 } 59 72 60 Frame* frame = m_pageAgent->frameForId(*frameId); 61 if (!frame) { 62 *errorString = "Frame with given id not found."; 63 return 0; 73 void PageRuntimeAgent::clearFrontend() 74 { 75 m_instrumentingAgents->setPageRuntimeAgent(0); 76 m_frontend = 0; 77 m_state->setBoolean(PageRuntimeAgentState::reportExecutionContextCreation, false); 78 } 79 80 void PageRuntimeAgent::restore() 81 { 82 if (!m_state->getBoolean(PageRuntimeAgentState::reportExecutionContextCreation)) 83 return; 84 String error; 85 setReportExecutionContextCreation(&error, true); 86 } 87 88 void PageRuntimeAgent::setReportExecutionContextCreation(ErrorString*, bool enable) 89 { 90 m_state->setBoolean(PageRuntimeAgentState::reportExecutionContextCreation, enable); 91 if (!enable) 92 return; 93 Vector<std::pair<ScriptState*, SecurityOrigin*> > isolatedContexts; 94 for (Frame* frame = m_inspectedPage->mainFrame(); frame; frame = frame->tree()->traverseNext()) { 95 if (!frame->script()->canExecuteScripts(NotAboutToExecuteScript)) 96 continue; 97 String frameId = m_pageAgent->frameId(frame); 98 99 ScriptState* scriptState = mainWorldScriptState(frame); 100 notifyContextCreated(frameId, scriptState, 0, true); 101 frame->script()->collectIsolatedContexts(isolatedContexts); 102 if (isolatedContexts.isEmpty()) 103 continue; 104 for (size_t i = 0; i< isolatedContexts.size(); i++) 105 notifyContextCreated(frameId, isolatedContexts[i].first, isolatedContexts[i].second, false); 106 isolatedContexts.clear(); 64 107 } 65 return mainWorldScriptState(frame); 108 } 109 110 void PageRuntimeAgent::didClearWindowObject(Frame* frame) 111 { 112 if (!m_state->getBoolean(PageRuntimeAgentState::reportExecutionContextCreation)) 113 return; 114 ASSERT(m_frontend); 115 String frameId = m_pageAgent->frameId(frame); 116 ScriptState* scriptState = mainWorldScriptState(frame); 117 notifyContextCreated(frameId, scriptState, 0, true); 118 } 119 120 void PageRuntimeAgent::didCreateIsolatedContext(Frame* frame, ScriptState* scriptState, SecurityOrigin* origin) 121 { 122 if (!m_state->getBoolean(PageRuntimeAgentState::reportExecutionContextCreation)) 123 return; 124 ASSERT(m_frontend); 125 String frameId = m_pageAgent->frameId(frame); 126 notifyContextCreated(frameId, scriptState, origin, false); 127 } 128 129 InjectedScript PageRuntimeAgent::injectedScriptForEval(ErrorString* errorString, const int* executionContextId) 130 { 131 if (!executionContextId) { 132 ScriptState* scriptState = mainWorldScriptState(m_inspectedPage->mainFrame()); 133 return injectedScriptManager()->injectedScriptFor(scriptState); 134 } 135 InjectedScript injectedScript = injectedScriptManager()->injectedScriptForId(*executionContextId); 136 if (injectedScript.hasNoValue()) 137 *errorString = "Execution context with given id not found."; 138 return injectedScript; 66 139 } 67 140 … … 76 149 } 77 150 151 void PageRuntimeAgent::notifyContextCreated(const String& frameId, ScriptState* scriptState, SecurityOrigin* securityOrigin, bool isPageContext) 152 { 153 ASSERT(securityOrigin || isPageContext); 154 long executionContextId = injectedScriptManager()->injectedScriptIdFor(scriptState); 155 String name = securityOrigin ? securityOrigin->toString() : ""; 156 m_frontend->isolatedContextCreated(ExecutionContextDescription::create() 157 .setId(executionContextId) 158 .setIsPageContext(isPageContext) 159 .setName(name) 160 .setFrameId(frameId) 161 .release()); 162 } 163 78 164 } // namespace WebCore 79 165 -
trunk/Source/WebCore/inspector/PageRuntimeAgent.h
r116099 r116744 34 34 #if ENABLE(INSPECTOR) 35 35 36 #include "InspectorFrontend.h" 36 37 #include "InspectorRuntimeAgent.h" 38 #include "ScriptState.h" 37 39 #include <wtf/PassOwnPtr.h> 38 40 … … 41 43 class InspectorPageAgent; 42 44 class Page; 45 class SecurityOrigin; 43 46 44 47 class PageRuntimeAgent : public InspectorRuntimeAgent { … … 49 52 } 50 53 virtual ~PageRuntimeAgent(); 54 virtual void setFrontend(InspectorFrontend*); 55 virtual void clearFrontend(); 56 virtual void restore(); 57 virtual void setReportExecutionContextCreation(ErrorString*, bool); 58 59 void didClearWindowObject(Frame*); 60 void didCreateIsolatedContext(Frame*, ScriptState*, SecurityOrigin*); 51 61 52 62 private: 53 63 PageRuntimeAgent(InstrumentingAgents*, InspectorState*, InjectedScriptManager*, Page*, InspectorPageAgent*); 54 64 55 virtual ScriptState* scriptStateForEval(ErrorString*, const String* frameId);65 virtual InjectedScript injectedScriptForEval(ErrorString*, const int* executionContextId); 56 66 virtual void muteConsole(); 57 67 virtual void unmuteConsole(); 68 void notifyContextCreated(const String& frameId, ScriptState*, SecurityOrigin*, bool isPageContext); 69 58 70 Page* m_inspectedPage; 59 71 InspectorPageAgent* m_pageAgent; 72 InspectorFrontend::Runtime* m_frontend; 60 73 }; 61 74 -
trunk/Source/WebCore/inspector/WorkerRuntimeAgent.cpp
r116099 r116744 35 35 #include "WorkerRuntimeAgent.h" 36 36 37 #include "InjectedScript.h" 37 38 #include "ScriptState.h" 38 39 … … 49 50 } 50 51 51 ScriptState* WorkerRuntimeAgent::scriptStateForEval(ErrorString* error, const String* frameId)52 void WorkerRuntimeAgent::setReportExecutionContextCreation(ErrorString* error, bool) 52 53 { 53 if (frameId) { 54 *error = "Frame id is not supported for workers."; 55 return 0; 54 *error = "Isolated contexts are not supported for workers."; 55 } 56 57 InjectedScript WorkerRuntimeAgent::injectedScriptForEval(ErrorString* error, const int* executionContextId) 58 { 59 if (executionContextId) { 60 *error = "Execution context id is not supported for workers as there is only one execution context."; 61 return InjectedScript(); 56 62 } 57 return scriptStateFromWorkerContext(m_workerContext); 63 ScriptState* scriptState = scriptStateFromWorkerContext(m_workerContext); 64 return injectedScriptManager()->injectedScriptFor(scriptState); 58 65 } 59 66 -
trunk/Source/WebCore/inspector/WorkerRuntimeAgent.h
r116099 r116744 48 48 } 49 49 virtual ~WorkerRuntimeAgent(); 50 virtual void setReportExecutionContextCreation(ErrorString*, bool); 50 51 51 52 private: 52 53 WorkerRuntimeAgent(InstrumentingAgents*, InspectorState*, InjectedScriptManager*, WorkerContext*); 53 virtual ScriptState* scriptStateForEval(ErrorString*, const String* frameId);54 virtual InjectedScript injectedScriptForEval(ErrorString*, const int* executionContextId); 54 55 virtual void muteConsole(); 55 56 virtual void unmuteConsole(); -
trunk/Source/WebCore/inspector/front-end/ConsoleView.js
r115194 r116744 48 48 this._contextSelectElement.id = "console-context"; 49 49 this._contextSelectElement.className = "status-bar-item"; 50 51 if (hideContextSelector) 50 this._contextSelectElement.addEventListener("change", this._updateIsolatedWorldSelector.bind(this), false); 51 52 this._isolatedWorldSelectElement = document.createElement("select"); 53 this._isolatedWorldSelectElement.id = "console-context"; 54 this._isolatedWorldSelectElement.className = "status-bar-item"; 55 56 if (hideContextSelector) { 52 57 this._contextSelectElement.addStyleClass("hidden"); 58 this._isolatedWorldSelectElement.addStyleClass("hidden"); 59 } 53 60 54 61 this.messagesElement = document.createElement("div"); … … 128 135 get statusBarItems() 129 136 { 130 return [this._clearConsoleButton.element, this._contextSelectElement, this._ filterBarElement];137 return [this._clearConsoleButton.element, this._contextSelectElement, this._isolatedWorldSelectElement, this._filterBarElement]; 131 138 }, 132 139 … … 140 147 this._contextSelectElement.appendChild(option); 141 148 context.addEventListener(WebInspector.FrameEvaluationContext.EventTypes.Updated, this._contextUpdated, this); 149 context.addEventListener(WebInspector.FrameEvaluationContext.EventTypes.AddedExecutionContext, this._addedExecutionContext, this); 150 this._updateIsolatedWorldSelector(); 142 151 }, 143 152 … … 145 154 { 146 155 this._contextSelectElement.removeChild(context._consoleOption); 156 this._updateIsolatedWorldSelector(); 157 }, 158 159 _updateIsolatedWorldSelector: function() 160 { 161 var context = this._currentEvaluationContext(); 162 if (!context) { 163 this._isolatedWorldSelectElement.addStyleClass("hidden"); 164 return; 165 } 166 167 var isolatedContexts = context.isolatedContexts(); 168 if (!isolatedContexts.length) { 169 this._isolatedWorldSelectElement.addStyleClass("hidden"); 170 return; 171 } 172 this._isolatedWorldSelectElement.removeStyleClass("hidden"); 173 this._isolatedWorldSelectElement.removeChildren(); 174 this._appendIsolatedContextOption(context.mainWorldContext()); 175 for (var i = 0; i < isolatedContexts.length; i++) 176 this._appendIsolatedContextOption(isolatedContexts[i]); 177 }, 178 179 _appendIsolatedContextOption: function(isolatedContext) 180 { 181 if (!isolatedContext) 182 return; 183 var option = document.createElement("option"); 184 option.text = isolatedContext.name; 185 option.title = isolatedContext.id; 186 option._executionContextId = isolatedContext.id; 187 this._isolatedWorldSelectElement.appendChild(option); 147 188 }, 148 189 … … 150 191 { 151 192 var context = event.data; 152 var option = context._consoleOption;193 var option = context._consoleOption; 153 194 option.text = context.displayName; 154 195 option.title = context.url; 155 196 }, 156 197 198 _addedExecutionContext: function(event) 199 { 200 var context = event.data; 201 if (context === this._currentEvaluationContext()) 202 this._updateIsolatedWorldSelector(); 203 }, 204 157 205 _currentEvaluationContextId: function() 206 { 207 var result = this._currentIsolatedContextId(); 208 if (result !== undefined) 209 return result; 210 var context = this._currentEvaluationContext(); 211 if (context && context.mainWorldContext()) 212 return context.mainWorldContext().id; 213 return undefined; 214 }, 215 216 _currentEvaluationContext: function() 158 217 { 159 218 if (this._contextSelectElement.selectedIndex === -1) 160 219 return undefined; 161 return this._contextSelectElement[this._contextSelectElement.selectedIndex]._context.frameId; 220 return this._contextSelectElement[this._contextSelectElement.selectedIndex]._context; 221 }, 222 223 _currentIsolatedContextId: function() 224 { 225 if (this._isolatedWorldSelectElement.hasStyleClass("hidden")) 226 return undefined; 227 if (this._isolatedWorldSelectElement.selectedIndex === -1) 228 return undefined; 229 return this._isolatedWorldSelectElement[this._isolatedWorldSelectElement.selectedIndex]._executionContextId; 162 230 }, 163 231 … … 621 689 callback(WebInspector.RemoteObject.fromPayload(result), !!wasThrown); 622 690 } 623 RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, this._currentEvaluationContextId(), returnByValue, evalCallback); 691 var contextId = this._currentEvaluationContextId(); 692 RuntimeAgent.evaluate(expression, objectGroup, includeCommandLineAPI, doNotPauseOnExceptionsAndMuteConsole, contextId, returnByValue, evalCallback); 624 693 }, 625 694 -
trunk/Source/WebCore/inspector/front-end/JavaScriptContextManager.js
r114117 r116744 38 38 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameNavigated, this._frameNavigated, this); 39 39 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.FrameDetached, this._frameDetached, this); 40 resourceTreeModel.addEventListener(WebInspector.ResourceTreeModel.EventTypes.CachedResourcesLoaded, this._didLoadCachedResources, this); 40 41 this._consoleView = consoleView; 41 42 this._frameIdToContext = {}; … … 68 69 delete this._frameIdToContext[frame.id]; 69 70 }, 71 72 _didLoadCachedResources: function() 73 { 74 InspectorBackend.registerRuntimeDispatcher(new WebInspector.RuntimeDispatcher(this)); 75 RuntimeAgent.setReportExecutionContextCreation(true); 76 }, 77 78 isolatedContextCreated: function(context) 79 { 80 var frameEvaluationContext = this._frameIdToContext[context.frameId]; 81 // FIXME(85708): this should never happen 82 if (!frameEvaluationContext) 83 return; 84 frameEvaluationContext._addExecutionContext(new WebInspector.ExecutionContext(context.id, context.name, context.isPageContext)); 85 } 70 86 } 71 87 72 88 WebInspector.JavaScriptContextManager.prototype.__proto__ = WebInspector.Object.prototype; 73 89 90 91 /** 92 * @constructor 93 * @implements {RuntimeAgent.Dispatcher} 94 * @param {WebInspector.JavaScriptContextManager} contextManager 95 */ 96 WebInspector.RuntimeDispatcher = function(contextManager) 97 { 98 this._contextManager = contextManager; 99 } 100 101 WebInspector.RuntimeDispatcher.prototype = { 102 isolatedContextCreated: function(context) 103 { 104 this._contextManager.isolatedContextCreated(context); 105 } 106 } 107 74 108 /** 75 109 * @constructor 76 110 * @extends {WebInspector.Object} 77 111 */ 112 WebInspector.ExecutionContext = function(id, name, isPageContext) 113 { 114 this.id = id; 115 this.name = (isPageContext && !name) ? "<page context>" : name; 116 this.isMainWorldContext = isPageContext; 117 } 118 119 /** 120 * @param {WebInspector.ExecutionContext} a 121 * @param {WebInspector.ExecutionContext} b 122 */ 123 WebInspector.ExecutionContext.comparator = function(a, b) 124 { 125 // Main world context should always go first. 126 if (a.isMainWorldContext) 127 return -1; 128 if (b.isMainWorldContext) 129 return +1; 130 return a.name.localeCompare(b.name); 131 } 132 133 /** 134 * @constructor 135 * @extends {WebInspector.Object} 136 */ 78 137 WebInspector.FrameEvaluationContext = function(frame) 79 138 { 80 139 this._frame = frame; 140 this._mainWorldContext = null; 141 this._isolatedContexts = []; 81 142 } 82 143 83 144 WebInspector.FrameEvaluationContext.EventTypes = { 84 Updated: "updated" 145 Updated: "Updated", 146 AddedExecutionContext: "AddedExecutionContext" 85 147 } 86 148 … … 90 152 { 91 153 this._frame = frame; 154 this._mainWorldContext = null; 155 this._isolatedContexts = []; 92 156 this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.Updated, this); 157 }, 158 159 /** 160 * @param {WebInspector.ExecutionContext} context 161 */ 162 _addExecutionContext: function(context) 163 { 164 if (context.isMainWorldContext) 165 this._mainWorldContext = context; 166 else 167 this._isolatedContexts.push(context); 168 this.dispatchEventToListeners(WebInspector.FrameEvaluationContext.EventTypes.AddedExecutionContext, this); 169 }, 170 171 mainWorldContext: function() 172 { 173 return this._mainWorldContext; 174 }, 175 176 isolatedContexts: function() 177 { 178 if (this._isolatedContexts.length) 179 this._isolatedContexts.sort(WebInspector.ExecutionContext.comparator); 180 return this._isolatedContexts; 93 181 }, 94 182
Note: See TracChangeset
for help on using the changeset viewer.