📄 inspectorcontroller.cpp
字号:
void InspectorController::willSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest& request, const ResourceResponse& redirectResponse){ if (!enabled()) return; InspectorResource* resource = m_resources.get(identifier).get(); if (!resource) return; resource->startTime = currentTime(); if (!redirectResponse.isNull()) { updateResourceRequest(resource, request); updateResourceResponse(resource, redirectResponse); } if (resource != m_mainResource && windowVisible()) { if (!resource->scriptObject) addScriptResource(resource); else updateScriptResourceRequest(resource); updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); if (!redirectResponse.isNull()) updateScriptResourceResponse(resource); }}void InspectorController::didReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse& response){ if (!enabled()) return; InspectorResource* resource = m_resources.get(identifier).get(); if (!resource) return; updateResourceResponse(resource, response); resource->responseReceivedTime = currentTime(); if (windowVisible() && resource->scriptObject) { updateScriptResourceResponse(resource); updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime); }}void InspectorController::didReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived){ if (!enabled()) return; InspectorResource* resource = m_resources.get(identifier).get(); if (!resource) return; resource->length += lengthReceived; if (windowVisible() && resource->scriptObject) updateScriptResource(resource, resource->length);}void InspectorController::didFinishLoading(DocumentLoader*, unsigned long identifier){ if (!enabled()) return; RefPtr<InspectorResource> resource = m_resources.get(identifier); if (!resource) return; removeResource(resource.get()); resource->finished = true; resource->endTime = currentTime(); addResource(resource.get()); if (windowVisible() && resource->scriptObject) { updateScriptResource(resource.get(), resource->startTime, resource->responseReceivedTime, resource->endTime); updateScriptResource(resource.get(), resource->finished); }}void InspectorController::didFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError& /*error*/){ if (!enabled()) return; RefPtr<InspectorResource> resource = m_resources.get(identifier); if (!resource) return; removeResource(resource.get()); resource->finished = true; resource->failed = true; resource->endTime = currentTime(); addResource(resource.get()); if (windowVisible() && resource->scriptObject) { updateScriptResource(resource.get(), resource->startTime, resource->responseReceivedTime, resource->endTime); updateScriptResource(resource.get(), resource->finished, resource->failed); }}void InspectorController::resourceRetrievedByXMLHttpRequest(unsigned long identifier, const JSC::UString& sourceString){ if (!enabled()) return; InspectorResource* resource = m_resources.get(identifier).get(); if (!resource) return; resource->setXMLHttpRequestProperties(sourceString); if (windowVisible() && resource->scriptObject) updateScriptResourceType(resource);}#if ENABLE(DATABASE)void InspectorController::didOpenDatabase(Database* database, const String& domain, const String& name, const String& version){ if (!enabled()) return; RefPtr<InspectorDatabaseResource> resource = InspectorDatabaseResource::create(database, domain, name, version); m_databaseResources.add(resource); if (windowVisible()) addDatabaseScriptResource(resource.get());}#endif#if ENABLE(DOM_STORAGE)void InspectorController::didUseDOMStorage(StorageArea* storageArea, bool isLocalStorage, Frame* frame){ if (!enabled()) return; DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end(); for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it) { InspectorDOMStorageResource* resource = it->get(); if (equalIgnoringCase(resource->frame->document()->securityOrigin()->host(), frame->document()->securityOrigin()->host()) && resource->isLocalStorage == isLocalStorage) return; } RefPtr<Storage> domStorage = Storage::create(frame, storageArea); RefPtr<InspectorDOMStorageResource> resource = InspectorDOMStorageResource::create(domStorage.get(), isLocalStorage, frame); m_domStorageResources.add(resource); if (windowVisible()) addDOMStorageScriptResource(resource.get());}#endifvoid InspectorController::moveWindowBy(float x, float y) const{ if (!m_page || !enabled()) return; FloatRect frameRect = m_page->chrome()->windowRect(); frameRect.move(x, y); m_page->chrome()->setWindowRect(frameRect);}#if ENABLE(JAVASCRIPT_DEBUGGER)void InspectorController::enableDebugger(){ if (!enabled()) return; if (!m_scriptContext || !m_scriptObject) { m_attachDebuggerWhenShown = true; return; } ASSERT(m_inspectedPage); JavaScriptDebugServer::shared().addListener(this, m_inspectedPage); JavaScriptDebugServer::shared().clearBreakpoints(); m_debuggerEnabled = true; m_attachDebuggerWhenShown = false; callSimpleFunction(m_scriptContext, m_scriptObject, "debuggerWasEnabled");}void InspectorController::disableDebugger(){ if (!enabled()) return; ASSERT(m_inspectedPage); JavaScriptDebugServer::shared().removeListener(this, m_inspectedPage); m_debuggerEnabled = false; m_attachDebuggerWhenShown = false; if (m_scriptContext && m_scriptObject) callSimpleFunction(m_scriptContext, m_scriptObject, "debuggerWasDisabled");}JavaScriptCallFrame* InspectorController::currentCallFrame() const{ return JavaScriptDebugServer::shared().currentCallFrame();}bool InspectorController::pauseOnExceptions(){ return JavaScriptDebugServer::shared().pauseOnExceptions();}void InspectorController::setPauseOnExceptions(bool pause){ JavaScriptDebugServer::shared().setPauseOnExceptions(pause);}void InspectorController::pauseInDebugger(){ if (!m_debuggerEnabled) return; JavaScriptDebugServer::shared().pauseProgram();}void InspectorController::resumeDebugger(){ if (!m_debuggerEnabled) return; JavaScriptDebugServer::shared().continueProgram();}void InspectorController::stepOverStatementInDebugger(){ if (!m_debuggerEnabled) return; JavaScriptDebugServer::shared().stepOverStatement();}void InspectorController::stepIntoStatementInDebugger(){ if (!m_debuggerEnabled) return; JavaScriptDebugServer::shared().stepIntoStatement();}void InspectorController::stepOutOfFunctionInDebugger(){ if (!m_debuggerEnabled) return; JavaScriptDebugServer::shared().stepOutOfFunction();}void InspectorController::addBreakpoint(intptr_t sourceID, unsigned lineNumber){ JavaScriptDebugServer::shared().addBreakpoint(sourceID, lineNumber);}void InspectorController::removeBreakpoint(intptr_t sourceID, unsigned lineNumber){ JavaScriptDebugServer::shared().removeBreakpoint(sourceID, lineNumber);}#endifstatic Path quadToPath(const FloatQuad& quad){ Path quadPath; quadPath.moveTo(quad.p1()); quadPath.addLineTo(quad.p2()); quadPath.addLineTo(quad.p3()); quadPath.addLineTo(quad.p4()); quadPath.closeSubpath(); return quadPath;}static void drawOutlinedQuad(GraphicsContext& context, const FloatQuad& quad, const Color& fillColor){ static const int outlineThickness = 2; static const Color outlineColor(62, 86, 180, 228); Path quadPath = quadToPath(quad); // Clip out the quad, then draw with a 2px stroke to get a pixel // of outline (because inflating a quad is hard) { context.save(); context.addPath(quadPath); context.clipOut(quadPath); context.addPath(quadPath); context.setStrokeThickness(outlineThickness); context.setStrokeColor(outlineColor); context.strokePath(); context.restore(); } // Now do the fill context.addPath(quadPath); context.setFillColor(fillColor); context.fillPath();}static void drawOutlinedQuadWithClip(GraphicsContext& context, const FloatQuad& quad, const FloatQuad& clipQuad, const Color& fillColor){ context.save(); Path clipQuadPath = quadToPath(clipQuad); context.clipOut(clipQuadPath); drawOutlinedQuad(context, quad, fillColor); context.restore();}static void drawHighlightForBox(GraphicsContext& context, const FloatQuad& contentQuad, const FloatQuad& paddingQuad, const FloatQuad& borderQuad, const FloatQuad& marginQuad){ static const Color contentBoxColor(125, 173, 217, 128); static const Color paddingBoxColor(125, 173, 217, 160); static const Color borderBoxColor(125, 173, 217, 192); static const Color marginBoxColor(125, 173, 217, 228); if (marginQuad != borderQuad) drawOutlinedQuadWithClip(context, marginQuad, borderQuad, marginBoxColor); if (borderQuad != paddingQuad) drawOutlinedQuadWithClip(context, borderQuad, paddingQuad, borderBoxColor); if (paddingQuad != contentQuad) drawOutlinedQuadWithClip(context, paddingQuad, contentQuad, paddingBoxColor); drawOutlinedQuad(context, contentQuad, contentBoxColor);}static void drawHighlightForLineBoxes(GraphicsContext& context, const Vector<FloatQuad>& lineBoxQuads){ static const Color lineBoxColor(125, 173, 217, 128); for (size_t i = 0; i < lineBoxQuads.size(); ++i) drawOutlinedQuad(context, lineBoxQuads[i], lineBoxColor);}static inline void convertFromFrameToMainFrame(Frame* frame, IntRect& rect){ rect = frame->page()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(rect));}static inline IntSize frameToMainFrameOffset(Frame* frame){ IntPoint mainFramePoint = frame->page()->mainFrame()->view()->windowToContents(frame->view()->contentsToWindow(IntPoint())); return mainFramePoint - IntPoint();}void InspectorController::drawNodeHighlight(GraphicsContext& context) const{ if (!m_highlightedNode) return; RenderObject* renderer = m_highlightedNode->renderer(); Frame* containingFrame = m_highlightedNode->document()->frame(); if (!renderer || !containingFrame) return; IntSize mainFrameOffset = frameToMainFrameOffset(containingFrame); IntRect boundingBox = renderer->absoluteBoundingBoxRect(true); boundingBox.move(mainFrameOffset); ASSERT(m_inspectedPage); FrameView* view = m_inspectedPage->mainFrame()->view(); FloatRect overlayRect = view->visibleContentRect(); if (!overlayRect.contains(boundingBox) && !boundingBox.contains(enclosingIntRect(overlayRect))) overlayRect = view->visibleContentRect(); context.translate(-overlayRect.x(), -overlayRect.y()); if (renderer->isBox()) { RenderBox* renderBox = toRenderBox(renderer); IntRect contentBox = renderBox->contentBoxRect(); IntRect paddingBox(contentBox.x() - renderBox->paddingLeft(), contentBox.y() - renderBox->paddingTop(), contentBox.width() + renderBox->paddingLeft() + renderBox->paddingRight(), contentBox.height() + renderBox->paddingTop() + renderBox->paddingBottom()); IntRect borderBox(paddingBox.x() - renderBox->borderLeft(), paddingBox.y() - renderBox->borderTop(), paddingBox.width() + renderBox->borderLeft() + renderBox->borderRight(), paddingBox.height() + renderBox->borderTop() + renderBox->borderBottom()); IntRect marginBox(borderBox.x() - renderBox->marginLeft(), borderBox.y() - renderBox->marginTop(), borderBox.width() + renderBox->marginLeft() + renderBox->marginRight(), borderBox.height() + renderBox->marginTop() + renderBox->marginBottom()); FloatQuad absContentQuad = renderBox->localToAbsoluteQuad(FloatRect(contentBox)); FloatQuad absPaddingQuad = renderBox->localToAbsoluteQuad(FloatRect(paddingBox)); FloatQuad absBorderQuad = renderBox->localToAbsoluteQuad(FloatRect(borderBox)); FloatQuad absMarginQuad = renderBox->localToAbsoluteQuad(FloatRect(marginBox)); absContentQuad.move(mainFrameOffset); absPaddingQuad.move(mainFrameOffset); absBorderQuad.move(mainFrameOffset); absMarginQuad.move(mainFrameOffset); drawHighlightForBox(context, absContentQuad, absP
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -