⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inspectorcontroller.cpp

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 CPP
📖 第 1 页 / 共 5 页
字号:
{    m_startProfiling.startOneShot(0);}void InspectorController::startUserInitiatedProfiling(Timer<InspectorController>*){    if (!enabled())        return;    if (!profilerEnabled()) {        enableProfiler(true);        JavaScriptDebugServer::shared().recompileAllJSFunctions();    }    m_recordingUserInitiatedProfile = true;    m_currentUserInitiatedProfileNumber = m_nextUserInitiatedProfileNumber++;    UString title = UserInitiatedProfileName;    title += ".";    title += UString::from(m_currentUserInitiatedProfileNumber);    ExecState* exec = toJSDOMWindow(m_inspectedPage->mainFrame())->globalExec();    Profiler::profiler()->startProfiling(exec, title);    toggleRecordButton(true);}void InspectorController::stopUserInitiatedProfiling(){    if (!enabled())        return;    m_recordingUserInitiatedProfile = false;    UString title =  UserInitiatedProfileName;    title += ".";    title += UString::from(m_currentUserInitiatedProfileNumber);    if (m_inspectedPage) {        ExecState* exec = toJSDOMWindow(m_inspectedPage->mainFrame())->globalExec();        RefPtr<Profile> profile = Profiler::profiler()->stopProfiling(exec, title);        if (profile)            addProfile(profile, 0, UString());    }    toggleRecordButton(false);}void InspectorController::enableProfiler(bool skipRecompile){    if (m_profilerEnabled)        return;    m_profilerEnabled = true;    if (!skipRecompile)        JavaScriptDebugServer::shared().recompileAllJSFunctionsSoon();    if (m_scriptContext && m_scriptObject)        callSimpleFunction(m_scriptContext, m_scriptObject, "profilerWasEnabled");}void InspectorController::disableProfiler(){    if (!m_profilerEnabled)        return;    m_profilerEnabled = false;    JavaScriptDebugServer::shared().recompileAllJSFunctionsSoon();    if (m_scriptContext && m_scriptObject)        callSimpleFunction(m_scriptContext, m_scriptObject, "profilerWasDisabled");}static void addHeaders(JSContextRef context, JSObjectRef object, const HTTPHeaderMap& headers, JSValueRef* exception){    ASSERT_ARG(context, context);    ASSERT_ARG(object, object);    HTTPHeaderMap::const_iterator end = headers.end();    for (HTTPHeaderMap::const_iterator it = headers.begin(); it != end; ++it) {        JSValueRef value = JSValueMakeString(context, jsStringRef(it->second).get());        JSObjectSetProperty(context, object, jsStringRef((it->first).string()).get(), value, kJSPropertyAttributeNone, exception);        if (exception && *exception)            return;    }}static JSObjectRef scriptObjectForRequest(JSContextRef context, const InspectorResource* resource, JSValueRef* exception){    ASSERT_ARG(context, context);    JSObjectRef object = JSObjectMake(context, 0, 0);    addHeaders(context, object, resource->requestHeaderFields, exception);    return object;}static JSObjectRef scriptObjectForResponse(JSContextRef context, const InspectorResource* resource, JSValueRef* exception){    ASSERT_ARG(context, context);    JSObjectRef object = JSObjectMake(context, 0, 0);    addHeaders(context, object, resource->responseHeaderFields, exception);    return object;}JSObjectRef InspectorController::addScriptResource(InspectorResource* resource){    ASSERT_ARG(resource, resource);    ASSERT(m_scriptContext);    ASSERT(m_scriptObject);    if (!m_scriptContext || !m_scriptObject)        return 0;    if (!resource->scriptObject) {        JSValueRef exception = 0;        JSValueRef resourceProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("Resource").get(), &exception);        if (HANDLE_EXCEPTION(m_scriptContext, exception))            return 0;        JSObjectRef resourceConstructor = JSValueToObject(m_scriptContext, resourceProperty, &exception);        if (HANDLE_EXCEPTION(m_scriptContext, exception))            return 0;        JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.string()).get());        JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.host()).get());        JSValueRef pathValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.path()).get());        JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.lastPathComponent()).get());        JSValueRef identifier = JSValueMakeNumber(m_scriptContext, resource->identifier);        JSValueRef mainResource = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource);        JSValueRef cached = JSValueMakeBoolean(m_scriptContext, resource->cached);        JSObjectRef scriptObject = scriptObjectForRequest(m_scriptContext, resource, &exception);        if (HANDLE_EXCEPTION(m_scriptContext, exception))            return 0;        JSValueRef arguments[] = { scriptObject, urlValue, domainValue, pathValue, lastPathComponentValue, identifier, mainResource, cached };        JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, resourceConstructor, 8, arguments, &exception);        if (HANDLE_EXCEPTION(m_scriptContext, exception))            return 0;        ASSERT(result);        resource->setScriptObject(m_scriptContext, result);    }    JSValueRef exception = 0;    callFunction(m_scriptContext, m_scriptObject, "addResource", 1, &resource->scriptObject, exception);    if (exception)        return 0;    return resource->scriptObject;}JSObjectRef InspectorController::addAndUpdateScriptResource(InspectorResource* resource){    ASSERT_ARG(resource, resource);    JSObjectRef scriptResource = addScriptResource(resource);    if (!scriptResource)        return 0;    updateScriptResourceResponse(resource);    updateScriptResource(resource, resource->length);    updateScriptResource(resource, resource->startTime, resource->responseReceivedTime, resource->endTime);    updateScriptResource(resource, resource->finished, resource->failed);    return scriptResource;}void InspectorController::removeScriptResource(InspectorResource* resource){    ASSERT(m_scriptContext);    ASSERT(m_scriptObject);    if (!m_scriptContext || !m_scriptObject)        return;    ASSERT(resource);    ASSERT(resource->scriptObject);    if (!resource || !resource->scriptObject)        return;    JSObjectRef scriptObject = resource->scriptObject;    resource->setScriptObject(0, 0);    JSValueRef exception = 0;    callFunction(m_scriptContext, m_scriptObject, "removeResource", 1, &scriptObject, exception);}static void updateResourceRequest(InspectorResource* resource, const ResourceRequest& request){    resource->requestHeaderFields = request.httpHeaderFields();    resource->requestURL = request.url();}static void updateResourceResponse(InspectorResource* resource, const ResourceResponse& response){    resource->expectedContentLength = response.expectedContentLength();    resource->mimeType = response.mimeType();    resource->responseHeaderFields = response.httpHeaderFields();    resource->responseStatusCode = response.httpStatusCode();    resource->suggestedFilename = response.suggestedFilename();}void InspectorController::updateScriptResourceRequest(InspectorResource* resource){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.string()).get());    JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.host()).get());    JSValueRef pathValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.path()).get());    JSValueRef lastPathComponentValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->requestURL.lastPathComponent()).get());    JSValueRef mainResourceValue = JSValueMakeBoolean(m_scriptContext, m_mainResource == resource);    JSValueRef exception = 0;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("url").get(), urlValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("domain").get(), domainValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("path").get(), pathValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("lastPathComponent").get(), lastPathComponentValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectRef scriptObject = scriptObjectForRequest(m_scriptContext, resource, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("requestHeaders").get(), scriptObject, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("mainResource").get(), mainResourceValue, kJSPropertyAttributeNone, &exception);    HANDLE_EXCEPTION(m_scriptContext, exception);}void InspectorController::updateScriptResourceResponse(InspectorResource* resource){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef mimeTypeValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->mimeType).get());    JSValueRef suggestedFilenameValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->suggestedFilename).get());    JSValueRef expectedContentLengthValue = JSValueMakeNumber(m_scriptContext, static_cast<double>(resource->expectedContentLength));    JSValueRef statusCodeValue = JSValueMakeNumber(m_scriptContext, resource->responseStatusCode);    JSValueRef exception = 0;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("mimeType").get(), mimeTypeValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("suggestedFilename").get(), suggestedFilenameValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("expectedContentLength").get(), expectedContentLengthValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("statusCode").get(), statusCodeValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectRef scriptObject = scriptObjectForResponse(m_scriptContext, resource, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("responseHeaders").get(), scriptObject, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    updateScriptResourceType(resource);}void InspectorController::updateScriptResourceType(InspectorResource* resource){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef exception = 0;    JSValueRef typeValue = JSValueMakeNumber(m_scriptContext, resource->type());    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("type").get(), typeValue, kJSPropertyAttributeNone, &exception);    HANDLE_EXCEPTION(m_scriptContext, exception);}void InspectorController::updateScriptResource(InspectorResource* resource, int length){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef lengthValue = JSValueMakeNumber(m_scriptContext, length);    JSValueRef exception = 0;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("contentLength").get(), lengthValue, kJSPropertyAttributeNone, &exception);    HANDLE_EXCEPTION(m_scriptContext, exception);}void InspectorController::updateScriptResource(InspectorResource* resource, bool finished, bool failed){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef failedValue = JSValueMakeBoolean(m_scriptContext, failed);    JSValueRef finishedValue = JSValueMakeBoolean(m_scriptContext, finished);    JSValueRef exception = 0;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("failed").get(), failedValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("finished").get(), finishedValue, kJSPropertyAttributeNone, &exception);    HANDLE_EXCEPTION(m_scriptContext, exception);}void InspectorController::updateScriptResource(InspectorResource* resource, double startTime, double responseReceivedTime, double endTime){    ASSERT(resource->scriptObject);    ASSERT(m_scriptContext);    if (!resource->scriptObject || !m_scriptContext)        return;    JSValueRef startTimeValue = JSValueMakeNumber(m_scriptContext, startTime);    JSValueRef responseReceivedTimeValue = JSValueMakeNumber(m_scriptContext, responseReceivedTime);    JSValueRef endTimeValue = JSValueMakeNumber(m_scriptContext, endTime);    JSValueRef exception = 0;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("startTime").get(), startTimeValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("responseReceivedTime").get(), responseReceivedTimeValue, kJSPropertyAttributeNone, &exception);    if (HANDLE_EXCEPTION(m_scriptContext, exception))        return;    JSObjectSetProperty(m_scriptContext, resource->scriptObject, jsStringRef("endTime").get(), endTimeValue, kJSPropertyAttributeNone, &exception);    HANDLE_EXCEPTION(m_scriptContext, exception);}void InspectorController::populateScriptObjects(){    ASSERT(m_scriptContext);    if (!m_scriptContext)        return;    ResourcesMap::iterator resourcesEnd = m_resources.end();    for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it)        addAndUpdateScriptResource(it->second.get());    unsigned messageCount = m_consoleMessages.size();    for (unsigned i = 0; i < messageCount; ++i)        addScriptConsoleMessage(m_consoleMessages[i]);#if ENABLE(DATABASE)    DatabaseResourcesSet::iterator databasesEnd = m_databaseResources.end();    for (DatabaseResourcesSet::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it)        addDatabaseScriptResource((*it).get());#endif#if ENABLE(DOM_STORAGE)    DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end();    for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it)        addDOMStorageScriptResource(it->get());#endif    callSimpleFunction(m_scriptContext, m_scriptObject, "populateInterface");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -