📄 inspectorcontroller.cpp
字号:
#if ENABLE(DATABASE)JSObjectRef InspectorController::addDatabaseScriptResource(InspectorDatabaseResource* resource){ ASSERT_ARG(resource, resource); if (resource->scriptObject) return resource->scriptObject; ASSERT(m_scriptContext); ASSERT(m_scriptObject); if (!m_scriptContext || !m_scriptObject) return 0; Frame* frame = resource->database->document()->frame(); if (!frame) return 0; JSValueRef exception = 0; JSValueRef databaseProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("Database").get(), &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; JSObjectRef databaseConstructor = JSValueToObject(m_scriptContext, databaseProperty, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; ExecState* exec = toJSDOMWindow(frame)->globalExec(); JSValueRef database; { JSC::JSLock lock(false); database = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, resource->database.get()))); } JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->domain).get()); JSValueRef nameValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->name).get()); JSValueRef versionValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->version).get()); JSValueRef arguments[] = { database, domainValue, nameValue, versionValue }; JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, databaseConstructor, 4, arguments, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; ASSERT(result); callFunction(m_scriptContext, m_scriptObject, "addDatabase", 1, &result, exception); if (exception) return 0; resource->setScriptObject(m_scriptContext, result); return result;}void InspectorController::removeDatabaseScriptResource(InspectorDatabaseResource* 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, "removeDatabase", 1, &scriptObject, exception);}#endif#if ENABLE(DOM_STORAGE)JSObjectRef InspectorController::addDOMStorageScriptResource(InspectorDOMStorageResource* resource){ ASSERT_ARG(resource, resource); if (resource->scriptObject) return resource->scriptObject; ASSERT(m_scriptContext); ASSERT(m_scriptObject); if (!m_scriptContext || !m_scriptObject) return 0; JSValueRef exception = 0; JSValueRef domStorageProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("DOMStorage").get(), &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; JSObjectRef domStorageConstructor = JSValueToObject(m_scriptContext, domStorageProperty, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; ExecState* exec = toJSDOMWindow(resource->frame.get())->globalExec(); JSValueRef domStorage; { JSC::JSLock lock(false); domStorage = toRef(JSInspectedObjectWrapper::wrap(exec, toJS(exec, resource->domStorage.get()))); } JSValueRef domainValue = JSValueMakeString(m_scriptContext, jsStringRef(resource->frame->document()->securityOrigin()->host()).get()); JSValueRef isLocalStorageValue = JSValueMakeBoolean(m_scriptContext, resource->isLocalStorage); JSValueRef arguments[] = { domStorage, domainValue, isLocalStorageValue }; JSObjectRef result = JSObjectCallAsConstructor(m_scriptContext, domStorageConstructor, 3, arguments, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return 0; ASSERT(result); callFunction(m_scriptContext, m_scriptObject, "addDOMStorage", 1, &result, exception); if (exception) return 0; resource->setScriptObject(m_scriptContext, result); return result;}void InspectorController::removeDOMStorageScriptResource(InspectorDOMStorageResource* 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, "removeDOMStorage", 1, &scriptObject, exception);}#endifvoid InspectorController::addScriptConsoleMessage(const ConsoleMessage* message){ ASSERT_ARG(message, message); JSValueRef exception = 0; JSValueRef messageConstructorProperty = JSObjectGetProperty(m_scriptContext, m_scriptObject, jsStringRef("ConsoleMessage").get(), &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return; JSObjectRef messageConstructor = JSValueToObject(m_scriptContext, messageConstructorProperty, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return; JSValueRef sourceValue = JSValueMakeNumber(m_scriptContext, message->source); JSValueRef levelValue = JSValueMakeNumber(m_scriptContext, message->level); JSValueRef lineValue = JSValueMakeNumber(m_scriptContext, message->line); JSValueRef urlValue = JSValueMakeString(m_scriptContext, jsStringRef(message->url).get()); JSValueRef groupLevelValue = JSValueMakeNumber(m_scriptContext, message->groupLevel); JSValueRef repeatCountValue = JSValueMakeNumber(m_scriptContext, message->repeatCount); static const unsigned maximumMessageArguments = 256; JSValueRef arguments[maximumMessageArguments]; unsigned argumentCount = 0; arguments[argumentCount++] = sourceValue; arguments[argumentCount++] = levelValue; arguments[argumentCount++] = lineValue; arguments[argumentCount++] = urlValue; arguments[argumentCount++] = groupLevelValue; arguments[argumentCount++] = repeatCountValue; if (!message->frames.isEmpty()) { unsigned remainingSpaceInArguments = maximumMessageArguments - argumentCount; unsigned argumentsToAdd = min(remainingSpaceInArguments, static_cast<unsigned>(message->frames.size())); for (unsigned i = 0; i < argumentsToAdd; ++i) arguments[argumentCount++] = JSValueMakeString(m_scriptContext, jsStringRef(message->frames[i]).get()); } else if (!message->wrappedArguments.isEmpty()) { unsigned remainingSpaceInArguments = maximumMessageArguments - argumentCount; unsigned argumentsToAdd = min(remainingSpaceInArguments, static_cast<unsigned>(message->wrappedArguments.size())); for (unsigned i = 0; i < argumentsToAdd; ++i) arguments[argumentCount++] = toRef(message->wrappedArguments[i]); } else { JSValueRef messageValue = JSValueMakeString(m_scriptContext, jsStringRef(message->message).get()); arguments[argumentCount++] = messageValue; } JSObjectRef messageObject = JSObjectCallAsConstructor(m_scriptContext, messageConstructor, argumentCount, arguments, &exception); if (HANDLE_EXCEPTION(m_scriptContext, exception)) return; callFunction(m_scriptContext, m_scriptObject, "addMessageToConsole", 1, &messageObject, exception);}void InspectorController::addScriptProfile(Profile* profile){ JSLock lock(false); JSValueRef exception = 0; JSValueRef profileObject = toRef(toJS(toJS(m_scriptContext), profile)); callFunction(m_scriptContext, m_scriptObject, "addProfile", 1, &profileObject, exception);}void InspectorController::resetScriptObjects(){ if (!m_scriptContext || !m_scriptObject) return; ResourcesMap::iterator resourcesEnd = m_resources.end(); for (ResourcesMap::iterator it = m_resources.begin(); it != resourcesEnd; ++it) { InspectorResource* resource = it->second.get(); resource->setScriptObject(0, 0); }#if ENABLE(DATABASE) DatabaseResourcesSet::iterator databasesEnd = m_databaseResources.end(); for (DatabaseResourcesSet::iterator it = m_databaseResources.begin(); it != databasesEnd; ++it) { InspectorDatabaseResource* resource = (*it).get(); resource->setScriptObject(0, 0); }#endif#if ENABLE(DOM_STORAGE) DOMStorageResourcesSet::iterator domStorageEnd = m_domStorageResources.end(); for (DOMStorageResourcesSet::iterator it = m_domStorageResources.begin(); it != domStorageEnd; ++it) { InspectorDOMStorageResource* resource = it->get(); resource->setScriptObject(0, 0); }#endif callSimpleFunction(m_scriptContext, m_scriptObject, "reset");}void InspectorController::pruneResources(ResourcesMap* resourceMap, DocumentLoader* loaderToKeep){ ASSERT_ARG(resourceMap, resourceMap); ResourcesMap mapCopy(*resourceMap); ResourcesMap::iterator end = mapCopy.end(); for (ResourcesMap::iterator it = mapCopy.begin(); it != end; ++it) { InspectorResource* resource = (*it).second.get(); if (resource == m_mainResource) continue; if (!loaderToKeep || resource->loader != loaderToKeep) { removeResource(resource); if (windowVisible() && resource->scriptObject) removeScriptResource(resource); } }}void InspectorController::didCommitLoad(DocumentLoader* loader){ if (!enabled()) return; ASSERT(m_inspectedPage); if (loader->frame() == m_inspectedPage->mainFrame()) { m_client->inspectedURLChanged(loader->url().string()); clearConsoleMessages(); m_times.clear(); m_counts.clear(); m_profiles.clear();#if ENABLE(DATABASE) m_databaseResources.clear();#endif#if ENABLE(DOM_STORAGE) m_domStorageResources.clear();#endif if (windowVisible()) { resetScriptObjects(); if (!loader->isLoadingFromCachedPage()) { ASSERT(m_mainResource && m_mainResource->loader == loader); // We don't add the main resource until its load is committed. This is // needed to keep the load for a user-entered URL from showing up in the // list of resources for the page they are navigating away from. addAndUpdateScriptResource(m_mainResource.get()); } else { // Pages loaded from the page cache are committed before // m_mainResource is the right resource for this load, so we // clear it here. It will be re-assigned in // identifierForInitialRequest. m_mainResource = 0; } } } for (Frame* frame = loader->frame(); frame; frame = frame->tree()->traverseNext(loader->frame())) if (ResourcesMap* resourceMap = m_frameResources.get(frame)) pruneResources(resourceMap, loader);}void InspectorController::frameDetachedFromParent(Frame* frame){ if (!enabled()) return; if (ResourcesMap* resourceMap = m_frameResources.get(frame)) removeAllResources(resourceMap);}void InspectorController::addResource(InspectorResource* resource){ m_resources.set(resource->identifier, resource); m_knownResources.add(resource->requestURL.string()); Frame* frame = resource->frame.get(); ResourcesMap* resourceMap = m_frameResources.get(frame); if (resourceMap) resourceMap->set(resource->identifier, resource); else { resourceMap = new ResourcesMap; resourceMap->set(resource->identifier, resource); m_frameResources.set(frame, resourceMap); }}void InspectorController::removeResource(InspectorResource* resource){ m_resources.remove(resource->identifier); m_knownResources.remove(resource->requestURL.string()); Frame* frame = resource->frame.get(); ResourcesMap* resourceMap = m_frameResources.get(frame); if (!resourceMap) { ASSERT_NOT_REACHED(); return; } resourceMap->remove(resource->identifier); if (resourceMap->isEmpty()) { m_frameResources.remove(frame); delete resourceMap; }}void InspectorController::didLoadResourceFromMemoryCache(DocumentLoader* loader, const CachedResource* cachedResource){ if (!enabled()) return; // If the resource URL is already known, we don't need to add it again since this is just a cached load. if (m_knownResources.contains(cachedResource->url())) return; RefPtr<InspectorResource> resource = InspectorResource::create(m_nextIdentifier--, loader, loader->frame()); resource->finished = true; resource->requestURL = KURL(cachedResource->url()); updateResourceResponse(resource.get(), cachedResource->response()); resource->length = cachedResource->encodedSize(); resource->cached = true; resource->startTime = currentTime(); resource->responseReceivedTime = resource->startTime; resource->endTime = resource->startTime; ASSERT(m_inspectedPage); if (loader->frame() == m_inspectedPage->mainFrame() && cachedResource->url() == loader->requestURL()) m_mainResource = resource; addResource(resource.get()); if (windowVisible()) addAndUpdateScriptResource(resource.get());}void InspectorController::identifierForInitialRequest(unsigned long identifier, DocumentLoader* loader, const ResourceRequest& request){ if (!enabled()) return; RefPtr<InspectorResource> resource = InspectorResource::create(identifier, loader, loader->frame()); updateResourceRequest(resource.get(), request); ASSERT(m_inspectedPage); if (loader->frame() == m_inspectedPage->mainFrame() && request.url() == loader->requestURL()) m_mainResource = resource; addResource(resource.get()); if (windowVisible() && loader->isLoadingFromCachedPage() && resource == m_mainResource) addAndUpdateScriptResource(resource.get());}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -