15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
25c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* Copyright (C) 2011 Google Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* modification, are permitted provided that the following conditions are
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*     * Redistributions of source code must retain the above copyright
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* notice, this list of conditions and the following disclaimer.
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*     * Redistributions in binary form must reproduce the above
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* copyright notice, this list of conditions and the following disclaimer
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* in the documentation and/or other materials provided with the
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* distribution.
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*     * Neither the name of Google Inc. nor the names of its
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* contributors may be used to endorse or promote products derived from
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* this software without specific prior written permission.
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)*/
305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)#include "config.h"
3253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorInstrumentation.h"
3353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
3409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/events/EventTarget.h"
35e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)#include "core/fetch/FetchInitiatorInfo.h"
3653e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorCSSAgent.h"
3753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorConsoleAgent.h"
38521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "core/inspector/InspectorController.h"
3953e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorDebuggerAgent.h"
4009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)#include "core/inspector/InspectorInspectorAgent.h"
4153e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorProfilerAgent.h"
4253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorResourceAgent.h"
4353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InspectorTimelineAgent.h"
4453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)#include "core/inspector/InstrumentingAgents.h"
45197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/inspector/ScriptAsyncCallStack.h"
46197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/inspector/ScriptCallStack.h"
47521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)#include "core/inspector/WorkerInspectorController.h"
48197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch#include "core/page/Page.h"
49591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch#include "core/workers/WorkerGlobalScope.h"
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
51c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
525c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
535c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)namespace {
545c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0;
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
565c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
5753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)namespace InspectorInstrumentation {
5853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)int FrontendCounter::s_frontendCounter = 0;
595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
605c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
61926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)InspectorInstrumentationCookie::InspectorInstrumentationCookie()
62d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)    : m_instrumentingAgents(nullptr)
63926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_timelineAgentId(0)
64926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
65926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
66926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
67926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId)
68926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    : m_instrumentingAgents(agents)
69926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_timelineAgentId(timelineAgentId)
70926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
71926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
72926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
73926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other)
74926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    : m_instrumentingAgents(other.m_instrumentingAgents)
75926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    , m_timelineAgentId(other.m_timelineAgentId)
76926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
77926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
78926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
79926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other)
80926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
81926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (this != &other) {
82926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        m_instrumentingAgents = other.m_instrumentingAgents;
83926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)        m_timelineAgentId = other.m_timelineAgentId;
84926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    }
85926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    return *this;
86926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
87926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
88926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)InspectorInstrumentationCookie::~InspectorInstrumentationCookie()
89926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles){
90926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)}
91926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
9253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)namespace InspectorInstrumentation {
9353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
9453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)bool isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents)
955c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
975c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return debuggerAgent->isPaused();
985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
995c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1005c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
101d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void didReceiveResourceResponseButCanceledImpl(LocalFrame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
1025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
103a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)    didReceiveResourceResponse(frame, identifier, loader, r, 0);
1045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1055c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
106d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void continueAfterXFrameOptionsDeniedImpl(LocalFrame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
1075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
1095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
111d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)void continueWithPolicyIgnoreImpl(LocalFrame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r)
1125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r);
1145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
116fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdochvoid willDestroyResourceImpl(Resource* cachedResource)
1175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!instrumentingAgentsSet)
1195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
1205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end();
1215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) {
1225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        InstrumentingAgents* instrumentingAgents = *it;
1235c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent())
124fff8884795cb540f87cf6e6d67b629519b00eb8bBen Murdoch            inspectorResourceAgent->willDestroyResource(cachedResource);
1255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1265c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
12853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)bool collectingHTMLParseErrorsImpl(InstrumentingAgents* instrumentingAgents)
1295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
13009380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (InspectorInspectorAgent* inspectorAgent = instrumentingAgents->inspectorInspectorAgent())
1315c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return inspectorAgent->hasFrontend();
1325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return false;
1335c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
135d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)PassOwnPtr<ScriptSourceCode> preprocessImpl(InstrumentingAgents* instrumentingAgents, LocalFrame* frame, const ScriptSourceCode& sourceCode)
136e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
137e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
138e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return debuggerAgent->preprocess(frame, sourceCode);
139e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    return PassOwnPtr<ScriptSourceCode>();
140e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
141e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
142d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)String preprocessEventListenerImpl(InstrumentingAgents* instrumentingAgents, LocalFrame* frame, const String& source, const String& url, const String& functionName)
143e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles){
144e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
145e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)        return debuggerAgent->preprocessEventListener(frame, source, url, functionName);
146e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    return source;
147e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)}
148e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)
149197021e6b966cfb06891637935ef33fff06433d1Ben Murdochvoid appendAsyncCallStack(ExecutionContext* executionContext, ScriptCallStack* callStack)
150197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch{
151197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
152197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (!instrumentingAgents)
153197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        return;
154197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent())
155197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch        callStack->setAsyncCallStack(debuggerAgent->currentAsyncStackTraceForConsole());
156197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch}
157197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch
1581e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool canvasAgentEnabled(ExecutionContext* executionContext)
1595c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1601e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
1615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return instrumentingAgents && instrumentingAgents->inspectorCanvasAgent();
1625c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1635c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1641e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool consoleAgentEnabled(ExecutionContext* executionContext)
1655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1661e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
1675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->inspectorConsoleAgent() : 0;
1685c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return consoleAgent && consoleAgent->enabled();
1695c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1705c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
1711e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)bool timelineAgentEnabled(ExecutionContext* executionContext)
1725c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1731e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)    InstrumentingAgents* instrumentingAgents = instrumentingAgentsFor(executionContext);
1745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent();
1755c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1765c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
17753e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)void registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1785c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1795c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!instrumentingAgentsSet)
1805c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        instrumentingAgentsSet = new HashSet<InstrumentingAgents*>();
1815c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    instrumentingAgentsSet->add(instrumentingAgents);
1825c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1835c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
18453e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)void unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents)
1855c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
1865c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!instrumentingAgentsSet)
1875c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return;
1885c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    instrumentingAgentsSet->remove(instrumentingAgents);
1895c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (instrumentingAgentsSet->isEmpty()) {
1905c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        delete instrumentingAgentsSet;
1915c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        instrumentingAgentsSet = 0;
1925c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    }
1935c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
1945c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
19553e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie)
1965c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
197926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (!cookie.instrumentingAgents())
1985c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
199926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent();
200926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)    if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id()))
2015c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return timelineAgent;
2025c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
2035c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2045c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2058abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)InstrumentingAgents* instrumentingAgentsFor(Page* page)
2065c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
2075c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    if (!page)
2085c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
2095c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return instrumentationForPage(page);
2105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
21209380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)InstrumentingAgents* instrumentingAgentsFor(EventTarget* eventTarget)
21309380295ba73501a205346becac22c6978e4671dTorne (Richard Coles){
21409380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    if (!eventTarget)
21509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)        return 0;
21609380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)    return instrumentingAgentsFor(eventTarget->executionContext());
21709380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)}
21809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)
2198abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)InstrumentingAgents* instrumentingAgentsFor(RenderObject* renderer)
22053e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles){
2218abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)    return instrumentingAgentsFor(renderer->frame());
22253e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)}
22353e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)
2248abfc5808a4e34d6e03867af8bc440dee641886fTorne (Richard Coles)InstrumentingAgents* instrumentingAgentsFor(WorkerGlobalScope* workerGlobalScope)
2255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
226591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    if (!workerGlobalScope)
2275c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)        return 0;
228591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    return instrumentationForWorkerGlobalScope(workerGlobalScope);
2295c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2305c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
2311e202183a5dc46166763171984b285173f8585e5Torne (Richard Coles)InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ExecutionContext* context)
2325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles){
233591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    if (context->isWorkerGlobalScope())
234591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch        return instrumentationForWorkerGlobalScope(toWorkerGlobalScope(context));
2355c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)    return 0;
2365c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)}
2375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
23853e740f4a82e17f3ae59772501622dc354e42336Torne (Richard Coles)} // namespace InspectorInstrumentation
239926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
240926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)namespace InstrumentationEvents {
24193ac45cfc74041c8ae536ce58a9534d46db2024eTorne (Richard Coles)const char PaintSetup[] = "PaintSetup";
242926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char RasterTask[] = "RasterTask";
243926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char Paint[] = "Paint";
244926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char Layer[] = "Layer";
24509380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)const char RequestMainThreadFrame[] = "RequestMainThreadFrame";
246926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char BeginFrame[] = "BeginFrame";
247a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)const char ActivateLayerTree[] = "ActivateLayerTree";
24809380295ba73501a205346becac22c6978e4671dTorne (Richard Coles)const char DrawFrame[] = "DrawFrame";
249d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)const char EmbedderCallback[] = "EmbedderCallback";
250926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)};
251926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
252926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)namespace InstrumentationEventArguments {
253a854de003a23bf3c7f95ec0f8154ada64092ff5cTorne (Richard Coles)const char FrameId[] = "frameId";
254926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)const char LayerId[] = "layerId";
255e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochconst char LayerTreeId[] = "layerTreeId";
256e69819bd8e388ea4ad1636a19aa6b2eed4952191Ben Murdochconst char PageId[] = "pageId";
257d5428f32f5d1719f774f62e19147104ca245a3abTorne (Richard Coles)const char CallbackName[] = "callbackName";
258926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)};
259926b001d589ce2f10facb93dd4b87578ea35a855Torne (Richard Coles)
260521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)InstrumentingAgents* instrumentationForPage(Page* page)
261521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles){
262521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    ASSERT(isMainThread());
263e1f1df5f01594c0e62e751e4b46e779b85c2faa5Torne (Richard Coles)    return page->inspectorController().m_instrumentingAgents.get();
264521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)}
265521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)
266591b958dee2cf159d33a0b931e6231072eaf38d5Ben MurdochInstrumentingAgents* instrumentationForWorkerGlobalScope(WorkerGlobalScope* workerGlobalScope)
267521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles){
268591b958dee2cf159d33a0b931e6231072eaf38d5Ben Murdoch    if (WorkerInspectorController* controller = workerGlobalScope->workerInspectorController())
269521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)        return controller->m_instrumentingAgents.get();
270521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)    return 0;
271521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)}
272521d96ec04ace82590870fb04353ec4f82bb150fTorne (Richard Coles)
273c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
2745c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
275