📄 inspectorcontroller.cpp
字号:
}void InspectorController::focusNode(){ if (!enabled()) return; ASSERT(m_scriptContext); ASSERT(m_scriptObject); ASSERT(m_nodeToFocus); Frame* frame = m_nodeToFocus->document()->frame(); if (!frame) return; ExecState* exec = toJSDOMWindow(frame)->globalExec(); JSValueRef arg0; { JSC::JSLock lock(false); arg0 = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, m_nodeToFocus.get()))); } m_nodeToFocus = 0; JSValueRef exception = 0; callFunction(m_scriptContext, m_scriptObject, "updateFocusedNode", 1, &arg0, exception);}void InspectorController::highlight(Node* node){ if (!enabled()) return; ASSERT_ARG(node, node); m_highlightedNode = node; m_client->highlight(node);}void InspectorController::hideHighlight(){ if (!enabled()) return; m_highlightedNode = 0; m_client->hideHighlight();}bool InspectorController::windowVisible(){ return m_windowVisible;}void InspectorController::setWindowVisible(bool visible, bool attached){ if (visible == m_windowVisible) return; m_windowVisible = visible; if (!m_scriptContext || !m_scriptObject) return; if (m_windowVisible) { setAttachedWindow(attached); populateScriptObjects(); if (m_nodeToFocus) focusNode();#if ENABLE(JAVASCRIPT_DEBUGGER) if (m_attachDebuggerWhenShown) enableDebugger();#endif if (m_showAfterVisible != CurrentPanel) showPanel(m_showAfterVisible); } else {#if ENABLE(JAVASCRIPT_DEBUGGER) disableDebugger();#endif resetScriptObjects(); } m_showAfterVisible = CurrentPanel;}void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, ScriptCallStack* callStack){ if (!enabled()) return; addConsoleMessage(callStack->state(), new ConsoleMessage(source, level, callStack, m_groupLevel, level == TraceMessageLevel));}void InspectorController::addMessageToConsole(MessageSource source, MessageLevel level, const String& message, unsigned lineNumber, const String& sourceID){ if (!enabled()) return; addConsoleMessage(0, new ConsoleMessage(source, level, message, lineNumber, sourceID, m_groupLevel));}void InspectorController::addConsoleMessage(ExecState* exec, ConsoleMessage* consoleMessage){ ASSERT(enabled()); ASSERT_ARG(consoleMessage, consoleMessage); if (m_previousMessage && m_previousMessage->isEqual(exec, consoleMessage)) { ++m_previousMessage->repeatCount; delete consoleMessage; } else { m_previousMessage = consoleMessage; m_consoleMessages.append(consoleMessage); } if (windowVisible()) addScriptConsoleMessage(m_previousMessage);}void InspectorController::clearConsoleMessages(){ deleteAllValues(m_consoleMessages); m_consoleMessages.clear(); m_previousMessage = 0; m_groupLevel = 0;}void InspectorController::toggleRecordButton(bool isProfiling){ if (!m_scriptContext) return; JSValueRef exception = 0; JSValueRef isProvingValue = JSValueMakeBoolean(m_scriptContext, isProfiling); callFunction(m_scriptContext, m_scriptObject, "setRecordingProfile", 1, &isProvingValue, exception);}void InspectorController::startGroup(MessageSource source, ScriptCallStack* callStack){ ++m_groupLevel; addConsoleMessage(callStack->state(), new ConsoleMessage(source, StartGroupMessageLevel, callStack, m_groupLevel));}void InspectorController::endGroup(MessageSource source, unsigned lineNumber, const String& sourceURL){ if (m_groupLevel == 0) return; --m_groupLevel; addConsoleMessage(0, new ConsoleMessage(source, EndGroupMessageLevel, String(), lineNumber, sourceURL, m_groupLevel));}void InspectorController::addProfile(PassRefPtr<Profile> prpProfile, unsigned lineNumber, const UString& sourceURL){ if (!enabled()) return; RefPtr<Profile> profile = prpProfile; m_profiles.append(profile); if (windowVisible()) addScriptProfile(profile.get()); addProfileMessageToConsole(profile, lineNumber, sourceURL);}void InspectorController::addProfileMessageToConsole(PassRefPtr<Profile> prpProfile, unsigned lineNumber, const UString& sourceURL){ RefPtr<Profile> profile = prpProfile; UString message = "Profile \"webkit-profile://"; message += encodeWithURLEscapeSequences(profile->title()); message += "/"; message += UString::from(profile->uid()); message += "\" finished."; addMessageToConsole(JSMessageSource, LogMessageLevel, message, lineNumber, sourceURL);}void InspectorController::attachWindow(){ if (!enabled()) return; m_client->attachWindow();}void InspectorController::detachWindow(){ if (!enabled()) return; m_client->detachWindow();}void InspectorController::setAttachedWindow(bool attached){ if (!enabled() || !m_scriptContext || !m_scriptObject) return; JSValueRef attachedValue = JSValueMakeBoolean(m_scriptContext, attached); JSValueRef exception = 0; callFunction(m_scriptContext, m_scriptObject, "setAttachedWindow", 1, &attachedValue, exception);}void InspectorController::setAttachedWindowHeight(unsigned height){ if (!enabled()) return; m_client->setAttachedWindowHeight(height);}void InspectorController::toggleSearchForNodeInPage(){ if (!enabled()) return; m_searchingForNode = !m_searchingForNode; if (!m_searchingForNode) hideHighlight();}void InspectorController::mouseDidMoveOverElement(const HitTestResult& result, unsigned){ if (!enabled() || !m_searchingForNode) return; Node* node = result.innerNode(); if (node) highlight(node);}void InspectorController::handleMousePressOnNode(Node* node){ if (!enabled()) return; ASSERT(m_searchingForNode); ASSERT(node); if (!node) return; // inspect() will implicitly call ElementsPanel's focusedNodeChanged() and the hover feedback will be stopped there. inspect(node);}void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame){ if (!enabled() || !m_scriptContext || !m_scriptObject) return; JSDOMWindow* win = toJSDOMWindow(frame); ExecState* exec = win->globalExec(); JSValueRef arg0; { JSC::JSLock lock(false); arg0 = toRef(JSInspectedObjectWrapper::wrap(exec, win)); } JSValueRef exception = 0; callFunction(m_scriptContext, m_scriptObject, "inspectedWindowCleared", 1, &arg0, exception);}void InspectorController::windowScriptObjectAvailable(){ if (!m_page || !enabled()) return; // FIXME: This should be cleaned up. API Mix-up. JSGlobalObject* globalObject = m_page->mainFrame()->script()->globalObject(); ExecState* exec = globalObject->globalExec(); m_scriptContext = toRef(exec); JSValuePtr jsInspector = toJS(exec, this); m_controllerScriptObject = toRef(asObject(jsInspector)); globalObject->putDirect(Identifier(exec, "InspectorController"), jsInspector);}void InspectorController::scriptObjectReady(){ ASSERT(m_scriptContext); if (!m_scriptContext) return; JSObjectRef global = JSContextGetGlobalObject(m_scriptContext); ASSERT(global); JSValueRef exception = 0; JSValueRef inspectorValue = JSObjectGetProperty(m_scriptContext, global, jsStringRef("WebInspector").get(), &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return; ASSERT(inspectorValue); if (!inspectorValue) return; m_scriptObject = JSValueToObject(m_scriptContext, inspectorValue, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return; ASSERT(m_scriptObject); JSValueProtect(m_scriptContext, m_scriptObject); // Make sure our window is visible now that the page loaded showWindow();}void InspectorController::show(){ if (!enabled()) return; if (!m_page) { m_page = m_client->createPage(); if (!m_page) return; m_page->setParentInspectorController(this); // showWindow() will be called after the page loads in scriptObjectReady() return; } showWindow();}void InspectorController::showPanel(SpecialPanels panel){ if (!enabled()) return; show(); if (!m_scriptObject) { m_showAfterVisible = panel; return; } if (panel == CurrentPanel) return; const char* showFunctionName; switch (panel) { case ConsolePanel: showFunctionName = "showConsole"; break; case DatabasesPanel: showFunctionName = "showDatabasesPanel"; break; case ElementsPanel: showFunctionName = "showElementsPanel"; break; case ProfilesPanel: showFunctionName = "showProfilesPanel"; break; case ResourcesPanel: showFunctionName = "showResourcesPanel"; break; case ScriptsPanel: showFunctionName = "showScriptsPanel"; break; default: ASSERT_NOT_REACHED(); showFunctionName = 0; } if (showFunctionName) callSimpleFunction(m_scriptContext, m_scriptObject, showFunctionName);}void InspectorController::close(){ if (!enabled()) return; stopUserInitiatedProfiling();#if ENABLE(JAVASCRIPT_DEBUGGER) disableDebugger();#endif closeWindow(); if (m_scriptContext && m_scriptObject) JSValueUnprotect(m_scriptContext, m_scriptObject); m_scriptObject = 0; m_scriptContext = 0;}void InspectorController::showWindow(){ ASSERT(enabled()); m_client->showWindow();}void InspectorController::closeWindow(){ m_client->closeWindow();}void InspectorController::startUserInitiatedProfilingSoon()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -