| /* |
| * Copyright (C) 2011 Google Inc. All rights reserved. |
| * |
| * Redistribution and use in source and binary forms, with or without |
| * modification, are permitted provided that the following conditions are |
| * met: |
| * |
| * * Redistributions of source code must retain the above copyright |
| * notice, this list of conditions and the following disclaimer. |
| * * Redistributions in binary form must reproduce the above |
| * copyright notice, this list of conditions and the following disclaimer |
| * in the documentation and/or other materials provided with the |
| * distribution. |
| * * Neither the name of Google Inc. nor the names of its |
| * contributors may be used to endorse or promote products derived from |
| * this software without specific prior written permission. |
| * |
| * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| |
| #include "config.h" |
| #include "core/inspector/InspectorInstrumentation.h" |
| |
| #include "core/inspector/InspectorAgent.h" |
| #include "core/inspector/InspectorCSSAgent.h" |
| #include "core/inspector/InspectorConsoleAgent.h" |
| #include "core/inspector/InspectorDebuggerAgent.h" |
| #include "core/inspector/InspectorPageAgent.h" |
| #include "core/inspector/InspectorProfilerAgent.h" |
| #include "core/inspector/InspectorResourceAgent.h" |
| #include "core/inspector/InspectorTimelineAgent.h" |
| #include "core/inspector/InspectorWorkerAgent.h" |
| #include "core/inspector/InstrumentingAgents.h" |
| #include "core/loader/cache/CachedResourceInitiatorInfo.h" |
| #include "core/workers/WorkerContext.h" |
| |
| namespace WebCore { |
| |
| namespace { |
| static HashSet<InstrumentingAgents*>* instrumentingAgentsSet = 0; |
| } |
| |
| namespace InspectorInstrumentation { |
| int FrontendCounter::s_frontendCounter = 0; |
| } |
| |
| InspectorInstrumentationCookie::InspectorInstrumentationCookie() |
| : m_instrumentingAgents(0) |
| , m_timelineAgentId(0) |
| { |
| } |
| |
| InspectorInstrumentationCookie::InspectorInstrumentationCookie(InstrumentingAgents* agents, int timelineAgentId) |
| : m_instrumentingAgents(agents) |
| , m_timelineAgentId(timelineAgentId) |
| { |
| } |
| |
| InspectorInstrumentationCookie::InspectorInstrumentationCookie(const InspectorInstrumentationCookie& other) |
| : m_instrumentingAgents(other.m_instrumentingAgents) |
| , m_timelineAgentId(other.m_timelineAgentId) |
| { |
| } |
| |
| InspectorInstrumentationCookie& InspectorInstrumentationCookie::operator=(const InspectorInstrumentationCookie& other) |
| { |
| if (this != &other) { |
| m_instrumentingAgents = other.m_instrumentingAgents; |
| m_timelineAgentId = other.m_timelineAgentId; |
| } |
| return *this; |
| } |
| |
| InspectorInstrumentationCookie::~InspectorInstrumentationCookie() |
| { |
| } |
| |
| namespace InspectorInstrumentation { |
| |
| bool isDebuggerPausedImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorDebuggerAgent* debuggerAgent = instrumentingAgents->inspectorDebuggerAgent()) |
| return debuggerAgent->isPaused(); |
| return false; |
| } |
| |
| bool forcePseudoStateImpl(InstrumentingAgents* instrumentingAgents, Element* element, CSSSelector::PseudoType pseudoState) |
| { |
| if (InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent()) |
| return cssAgent->forcePseudoState(element, pseudoState); |
| return false; |
| } |
| |
| bool shouldApplyScreenWidthOverrideImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) { |
| long width = 0; |
| pageAgent->applyScreenWidthOverride(&width); |
| return !!width; |
| } |
| return false; |
| } |
| |
| bool shouldApplyScreenHeightOverrideImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) { |
| long height = 0; |
| pageAgent->applyScreenHeightOverride(&height); |
| return !!height; |
| } |
| return false; |
| } |
| |
| void continueAfterPingLoaderImpl(InstrumentingAgents* instrumentingAgents, unsigned long identifier, DocumentLoader* loader, ResourceRequest& request, const ResourceResponse& response) |
| { |
| willSendRequestImpl(instrumentingAgents, identifier, loader, request, response, CachedResourceInitiatorInfo()); |
| } |
| |
| void didReceiveResourceResponseButCanceledImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r) |
| { |
| InspectorInstrumentationCookie cookie = willReceiveResourceResponse(frame, identifier, r); |
| didReceiveResourceResponse(cookie, identifier, loader, r, 0); |
| } |
| |
| void continueAfterXFrameOptionsDeniedImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r) |
| { |
| didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r); |
| } |
| |
| void continueWithPolicyDownloadImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r) |
| { |
| didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r); |
| } |
| |
| void continueWithPolicyIgnoreImpl(Frame* frame, DocumentLoader* loader, unsigned long identifier, const ResourceResponse& r) |
| { |
| didReceiveResourceResponseButCanceledImpl(frame, loader, identifier, r); |
| } |
| |
| void willDestroyCachedResourceImpl(CachedResource* cachedResource) |
| { |
| if (!instrumentingAgentsSet) |
| return; |
| HashSet<InstrumentingAgents*>::iterator end = instrumentingAgentsSet->end(); |
| for (HashSet<InstrumentingAgents*>::iterator it = instrumentingAgentsSet->begin(); it != end; ++it) { |
| InstrumentingAgents* instrumentingAgents = *it; |
| if (InspectorResourceAgent* inspectorResourceAgent = instrumentingAgents->inspectorResourceAgent()) |
| inspectorResourceAgent->willDestroyCachedResource(cachedResource); |
| } |
| } |
| |
| String getCurrentUserInitiatedProfileNameImpl(InstrumentingAgents* instrumentingAgents, bool incrementProfileNumber) |
| { |
| if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent()) |
| return profilerAgent->getCurrentUserInitiatedProfileName(incrementProfileNumber); |
| return ""; |
| } |
| |
| bool profilerEnabledImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorProfilerAgent* profilerAgent = instrumentingAgents->inspectorProfilerAgent()) |
| return profilerAgent->enabled(); |
| return false; |
| } |
| |
| bool shouldPauseDedicatedWorkerOnStartImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorWorkerAgent* workerAgent = instrumentingAgents->inspectorWorkerAgent()) |
| return workerAgent->shouldPauseDedicatedWorkerOnStart(); |
| return false; |
| } |
| |
| |
| bool collectingHTMLParseErrorsImpl(InstrumentingAgents* instrumentingAgents) |
| { |
| if (InspectorAgent* inspectorAgent = instrumentingAgents->inspectorAgent()) |
| return inspectorAgent->hasFrontend(); |
| return false; |
| } |
| |
| bool canvasAgentEnabled(ScriptExecutionContext* scriptExecutionContext) |
| { |
| InstrumentingAgents* instrumentingAgents = instrumentingAgentsForScriptExecutionContext(scriptExecutionContext); |
| return instrumentingAgents && instrumentingAgents->inspectorCanvasAgent(); |
| } |
| |
| bool consoleAgentEnabled(ScriptExecutionContext* scriptExecutionContext) |
| { |
| InstrumentingAgents* instrumentingAgents = instrumentingAgentsForScriptExecutionContext(scriptExecutionContext); |
| InspectorConsoleAgent* consoleAgent = instrumentingAgents ? instrumentingAgents->inspectorConsoleAgent() : 0; |
| return consoleAgent && consoleAgent->enabled(); |
| } |
| |
| bool timelineAgentEnabled(ScriptExecutionContext* scriptExecutionContext) |
| { |
| InstrumentingAgents* instrumentingAgents = instrumentingAgentsForScriptExecutionContext(scriptExecutionContext); |
| return instrumentingAgents && instrumentingAgents->inspectorTimelineAgent(); |
| } |
| |
| void registerInstrumentingAgents(InstrumentingAgents* instrumentingAgents) |
| { |
| if (!instrumentingAgentsSet) |
| instrumentingAgentsSet = new HashSet<InstrumentingAgents*>(); |
| instrumentingAgentsSet->add(instrumentingAgents); |
| } |
| |
| void unregisterInstrumentingAgents(InstrumentingAgents* instrumentingAgents) |
| { |
| if (!instrumentingAgentsSet) |
| return; |
| instrumentingAgentsSet->remove(instrumentingAgents); |
| if (instrumentingAgentsSet->isEmpty()) { |
| delete instrumentingAgentsSet; |
| instrumentingAgentsSet = 0; |
| } |
| } |
| |
| InspectorTimelineAgent* retrieveTimelineAgent(const InspectorInstrumentationCookie& cookie) |
| { |
| if (!cookie.instrumentingAgents()) |
| return 0; |
| InspectorTimelineAgent* timelineAgent = cookie.instrumentingAgents()->inspectorTimelineAgent(); |
| if (timelineAgent && cookie.hasMatchingTimelineAgentId(timelineAgent->id())) |
| return timelineAgent; |
| return 0; |
| } |
| |
| InstrumentingAgents* instrumentingAgentsForPage(Page* page) |
| { |
| if (!page) |
| return 0; |
| return instrumentationForPage(page); |
| } |
| |
| InstrumentingAgents* instrumentingAgentsForRenderObject(RenderObject* renderer) |
| { |
| return instrumentingAgentsForFrame(renderer->frame()); |
| } |
| |
| InstrumentingAgents* instrumentingAgentsForWorkerContext(WorkerContext* workerContext) |
| { |
| if (!workerContext) |
| return 0; |
| return instrumentationForWorkerContext(workerContext); |
| } |
| |
| InstrumentingAgents* instrumentingAgentsForNonDocumentContext(ScriptExecutionContext* context) |
| { |
| if (context->isWorkerContext()) |
| return instrumentationForWorkerContext(static_cast<WorkerContext*>(context)); |
| return 0; |
| } |
| |
| GeolocationPosition* overrideGeolocationPositionImpl(InstrumentingAgents* instrumentingAgents, GeolocationPosition* position) |
| { |
| if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) |
| position = pageAgent->overrideGeolocationPosition(position); |
| return position; |
| } |
| |
| DeviceOrientationData* overrideDeviceOrientationImpl(InstrumentingAgents* instrumentingAgents, DeviceOrientationData* deviceOrientation) |
| { |
| if (InspectorPageAgent* pageAgent = instrumentingAgents->inspectorPageAgent()) |
| deviceOrientation = pageAgent->overrideDeviceOrientation(deviceOrientation); |
| return deviceOrientation; |
| } |
| |
| |
| bool cssErrorFilter(const CSSParserString& content, int propertyId, int errorType) |
| { |
| return InspectorCSSAgent::cssErrorFilter(content, propertyId, errorType); |
| } |
| |
| } // namespace InspectorInstrumentation |
| |
| namespace InstrumentationEvents { |
| const char PaintSetup[] = "PaintSetup"; |
| const char PaintLayer[] = "PaintLayer"; |
| const char RasterTask[] = "RasterTask"; |
| const char ImageDecodeTask[] = "ImageDecodeTask"; |
| const char Paint[] = "Paint"; |
| const char Layer[] = "Layer"; |
| const char BeginFrame[] = "BeginFrame"; |
| }; |
| |
| namespace InstrumentationEventArguments { |
| const char LayerId[] = "layerId"; |
| const char PageId[] = "pageId"; |
| const char NodeId[] = "nodeId"; |
| }; |
| |
| } // namespace WebCore |
| |