diff options
Diffstat (limited to 'Source/WebCore/inspector/InspectorPageAgent.cpp')
-rw-r--r-- | Source/WebCore/inspector/InspectorPageAgent.cpp | 669 |
1 files changed, 276 insertions, 393 deletions
diff --git a/Source/WebCore/inspector/InspectorPageAgent.cpp b/Source/WebCore/inspector/InspectorPageAgent.cpp index e3d0cc0be..de057b5ac 100644 --- a/Source/WebCore/inspector/InspectorPageAgent.cpp +++ b/Source/WebCore/inspector/InspectorPageAgent.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2011 Google Inc. All rights reserved. + * Copyright (C) 2015 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -29,9 +30,6 @@ */ #include "config.h" - -#if ENABLE(INSPECTOR) - #include "InspectorPageAgent.h" #include "CachedCSSStyleSheet.h" @@ -42,41 +40,39 @@ #include "CachedScript.h" #include "Cookie.h" #include "CookieJar.h" -#include "DOMImplementation.h" -#include "DOMPatchSupport.h" #include "DOMWrapperWorld.h" #include "Document.h" #include "DocumentLoader.h" #include "Frame.h" +#include "FrameLoadRequest.h" #include "FrameLoader.h" #include "FrameSnapshotting.h" #include "FrameView.h" #include "HTMLFrameOwnerElement.h" #include "HTMLNames.h" -#include "IdentifiersFactory.h" #include "ImageBuffer.h" #include "InspectorClient.h" #include "InspectorDOMAgent.h" -#include "InspectorInstrumentation.h" +#include "InspectorNetworkAgent.h" #include "InspectorOverlay.h" -#include "InspectorWebFrontendDispatchers.h" #include "InstrumentingAgents.h" +#include "MIMETypeRegistry.h" #include "MainFrame.h" #include "MemoryCache.h" #include "Page.h" -#include "ResourceBuffer.h" +#include "RenderObject.h" #include "ScriptController.h" #include "SecurityOrigin.h" #include "Settings.h" +#include "StyleScope.h" #include "TextEncoding.h" #include "TextResourceDecoder.h" #include "UserGestureIndicator.h" -#include <bindings/ScriptValue.h> #include <inspector/ContentSearchUtilities.h> +#include <inspector/IdentifiersFactory.h> #include <inspector/InspectorValues.h> -#include <wtf/CurrentTime.h> #include <wtf/ListHashSet.h> -#include <wtf/Vector.h> +#include <wtf/Stopwatch.h> #include <wtf/text/Base64.h> #include <wtf/text/StringBuilder.h> #include <yarr/RegularExpression.h> @@ -113,43 +109,25 @@ static bool prepareCachedResourceBuffer(CachedResource* cachedResource, bool* ha return true; } - if (cachedResource->isPurgeable()) { - // If the resource is purgeable then make it unpurgeable to get - // get its data. This might fail, in which case we return an - // empty String. - // FIXME: should we do something else in the case of a purged - // resource that informs the user why there is no data in the - // inspector? - if (!cachedResource->makePurgeable(false)) - return false; - } - return true; } static bool hasTextContent(CachedResource* cachedResource) { - InspectorPageAgent::ResourceType type = InspectorPageAgent::cachedResourceType(*cachedResource); - return type == InspectorPageAgent::DocumentResource || type == InspectorPageAgent::StylesheetResource || type == InspectorPageAgent::ScriptResource || type == InspectorPageAgent::XHRResource; -} + // FIXME: <https://webkit.org/b/165495> Web Inspector: XHR / Fetch for non-text content should not show garbled text + // We should not assume XHR / Fetch have text content. -static PassRefPtr<TextResourceDecoder> createXHRTextDecoder(const String& mimeType, const String& textEncodingName) -{ - RefPtr<TextResourceDecoder> decoder; - if (!textEncodingName.isEmpty()) - decoder = TextResourceDecoder::create("text/plain", textEncodingName); - else if (DOMImplementation::isXMLMIMEType(mimeType.lower())) { - decoder = TextResourceDecoder::create("application/xml"); - decoder->useLenientXMLDecoding(); - } else if (equalIgnoringCase(mimeType, "text/html")) - decoder = TextResourceDecoder::create("text/html", "UTF-8"); - else - decoder = TextResourceDecoder::create("text/plain", "UTF-8"); - return decoder; + InspectorPageAgent::ResourceType type = InspectorPageAgent::cachedResourceType(*cachedResource); + return type == InspectorPageAgent::DocumentResource + || type == InspectorPageAgent::StylesheetResource + || type == InspectorPageAgent::ScriptResource + || type == InspectorPageAgent::XHRResource + || type == InspectorPageAgent::FetchResource; } bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, String* result, bool* base64Encoded) { + // FIXME: result should be a String& and base64Encoded should be a bool&. bool hasZeroSize; bool prepared = prepareCachedResourceBuffer(cachedResource, &hasZeroSize); if (!prepared) @@ -157,42 +135,45 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S *base64Encoded = !hasTextContent(cachedResource); if (*base64Encoded) { - RefPtr<SharedBuffer> buffer = hasZeroSize ? SharedBuffer::create() : cachedResource->resourceBuffer()->sharedBuffer(); - - if (!buffer) - return false; - - *result = base64Encode(buffer->data(), buffer->size()); - return true; + if (hasZeroSize) { + *result = { }; + return true; + } + if (auto* buffer = cachedResource->resourceBuffer()) { + *result = base64Encode(buffer->data(), buffer->size()); + return true; + } + return false; } if (hasZeroSize) { - *result = ""; + *result = emptyString(); return true; } if (cachedResource) { switch (cachedResource->type()) { case CachedResource::CSSStyleSheet: - *result = static_cast<CachedCSSStyleSheet*>(cachedResource)->sheetText(false); - return true; + // This can return a null String if the MIME type is invalid. + *result = downcast<CachedCSSStyleSheet>(*cachedResource).sheetText(); + return !result->isNull(); case CachedResource::Script: - *result = static_cast<CachedScript*>(cachedResource)->script(); + *result = downcast<CachedScript>(*cachedResource).script().toString(); return true; + case CachedResource::MediaResource: case CachedResource::RawResource: { - ResourceBuffer* buffer = cachedResource->resourceBuffer(); + auto* buffer = cachedResource->resourceBuffer(); if (!buffer) return false; - RefPtr<TextResourceDecoder> decoder = createXHRTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName()); + RefPtr<TextResourceDecoder> decoder = InspectorPageAgent::createTextDecoder(cachedResource->response().mimeType(), cachedResource->response().textEncodingName()); // We show content for raw resources only for certain mime types (text, html and xml). Otherwise decoder will be null. if (!decoder) return false; - String content = decoder->decode(buffer->data(), buffer->size()); - *result = content + decoder->flush(); + *result = decoder->decodeAndFlush(buffer->data(), buffer->size()); return true; } default: - ResourceBuffer* buffer = cachedResource->resourceBuffer(); + auto* buffer = cachedResource->resourceBuffer(); return decodeBuffer(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, cachedResource->encoding(), result); } } @@ -201,16 +182,13 @@ bool InspectorPageAgent::cachedResourceContent(CachedResource* cachedResource, S bool InspectorPageAgent::mainResourceContent(Frame* frame, bool withBase64Encode, String* result) { - RefPtr<ResourceBuffer> buffer = frame->loader().documentLoader()->mainResourceData(); + RefPtr<SharedBuffer> buffer = frame->loader().documentLoader()->mainResourceData(); if (!buffer) return false; - String textEncodingName = frame->document()->inputEncoding(); - - return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), textEncodingName, withBase64Encode, result); + return InspectorPageAgent::dataContent(buffer->data(), buffer->size(), frame->document()->encoding(), withBase64Encode, result); } -// static -bool InspectorPageAgent::sharedBufferContent(PassRefPtr<SharedBuffer> buffer, const String& textEncodingName, bool withBase64Encode, String* result) +bool InspectorPageAgent::sharedBufferContent(RefPtr<SharedBuffer>&& buffer, const String& textEncodingName, bool withBase64Encode, String* result) { return dataContent(buffer ? buffer->data() : nullptr, buffer ? buffer->size() : 0, textEncodingName, withBase64Encode, result); } @@ -225,8 +203,7 @@ bool InspectorPageAgent::dataContent(const char* data, unsigned size, const Stri return decodeBuffer(data, size, textEncodingName, result); } -// static -void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, const URL& url, String* result, bool* base64Encoded) +void InspectorPageAgent::resourceContent(ErrorString& errorString, Frame* frame, const URL& url, String* result, bool* base64Encoded) { DocumentLoader* loader = assertDocumentLoader(errorString, frame); if (!loader) @@ -243,14 +220,14 @@ void InspectorPageAgent::resourceContent(ErrorString* errorString, Frame* frame, success = cachedResourceContent(cachedResource(frame, url), result, base64Encoded); if (!success) - *errorString = "No resource with given URL found"; + errorString = ASCIILiteral("No resource with given URL found"); } //static String InspectorPageAgent::sourceMapURLForResource(CachedResource* cachedResource) { - DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeader, (ASCIILiteral("SourceMap"))); - DEFINE_STATIC_LOCAL(String, sourceMapHTTPHeaderDeprecated, (ASCIILiteral("X-SourceMap"))); + static NeverDestroyed<String> sourceMapHTTPHeader(ASCIILiteral("SourceMap")); + static NeverDestroyed<String> sourceMapHTTPHeaderDeprecated(ASCIILiteral("X-SourceMap")); if (!cachedResource) return String(); @@ -277,39 +254,42 @@ String InspectorPageAgent::sourceMapURLForResource(CachedResource* cachedResourc CachedResource* InspectorPageAgent::cachedResource(Frame* frame, const URL& url) { - CachedResource* cachedResource = frame->document()->cachedResourceLoader()->cachedResource(url); + if (url.isNull()) + return nullptr; + + CachedResource* cachedResource = frame->document()->cachedResourceLoader().cachedResource(MemoryCache::removeFragmentIdentifierIfNeeded(url)); if (!cachedResource) { ResourceRequest request(url); -#if ENABLE(CACHE_PARTITIONING) - request.setCachePartition(frame->document()->topOrigin()->cachePartition()); -#endif - cachedResource = memoryCache()->resourceForRequest(request); + request.setDomainForCachePartition(frame->document()->topOrigin().domainForCachePartition()); + cachedResource = MemoryCache::singleton().resourceForRequest(request, frame->page()->sessionID()); } return cachedResource; } -Inspector::TypeBuilder::Page::ResourceType::Enum InspectorPageAgent::resourceTypeJson(InspectorPageAgent::ResourceType resourceType) +Inspector::Protocol::Page::ResourceType InspectorPageAgent::resourceTypeJson(InspectorPageAgent::ResourceType resourceType) { switch (resourceType) { case DocumentResource: - return Inspector::TypeBuilder::Page::ResourceType::Document; + return Inspector::Protocol::Page::ResourceType::Document; case ImageResource: - return Inspector::TypeBuilder::Page::ResourceType::Image; + return Inspector::Protocol::Page::ResourceType::Image; case FontResource: - return Inspector::TypeBuilder::Page::ResourceType::Font; + return Inspector::Protocol::Page::ResourceType::Font; case StylesheetResource: - return Inspector::TypeBuilder::Page::ResourceType::Stylesheet; + return Inspector::Protocol::Page::ResourceType::Stylesheet; case ScriptResource: - return Inspector::TypeBuilder::Page::ResourceType::Script; + return Inspector::Protocol::Page::ResourceType::Script; case XHRResource: - return Inspector::TypeBuilder::Page::ResourceType::XHR; + return Inspector::Protocol::Page::ResourceType::XHR; + case FetchResource: + return Inspector::Protocol::Page::ResourceType::Fetch; case WebSocketResource: - return Inspector::TypeBuilder::Page::ResourceType::WebSocket; + return Inspector::Protocol::Page::ResourceType::WebSocket; case OtherResource: - return Inspector::TypeBuilder::Page::ResourceType::Other; + return Inspector::Protocol::Page::ResourceType::Other; } - return Inspector::TypeBuilder::Page::ResourceType::Other; + return Inspector::Protocol::Page::ResourceType::Other; } InspectorPageAgent::ResourceType InspectorPageAgent::cachedResourceType(const CachedResource& cachedResource) @@ -317,87 +297,106 @@ InspectorPageAgent::ResourceType InspectorPageAgent::cachedResourceType(const Ca switch (cachedResource.type()) { case CachedResource::ImageResource: return InspectorPageAgent::ImageResource; +#if ENABLE(SVG_FONTS) + case CachedResource::SVGFontResource: +#endif case CachedResource::FontResource: return InspectorPageAgent::FontResource; - case CachedResource::CSSStyleSheet: - // Fall through. #if ENABLE(XSLT) case CachedResource::XSLStyleSheet: #endif + case CachedResource::CSSStyleSheet: return InspectorPageAgent::StylesheetResource; case CachedResource::Script: return InspectorPageAgent::ScriptResource; - case CachedResource::RawResource: - return InspectorPageAgent::XHRResource; case CachedResource::MainResource: return InspectorPageAgent::DocumentResource; + case CachedResource::MediaResource: + case CachedResource::RawResource: { + switch (cachedResource.resourceRequest().requester()) { + case ResourceRequest::Requester::Fetch: + return InspectorPageAgent::FetchResource; + case ResourceRequest::Requester::Main: + return InspectorPageAgent::DocumentResource; + default: + return InspectorPageAgent::XHRResource; + } + } default: break; } return InspectorPageAgent::OtherResource; } -Inspector::TypeBuilder::Page::ResourceType::Enum InspectorPageAgent::cachedResourceTypeJson(const CachedResource& cachedResource) +Inspector::Protocol::Page::ResourceType InspectorPageAgent::cachedResourceTypeJson(const CachedResource& cachedResource) { return resourceTypeJson(cachedResourceType(cachedResource)); } -InspectorPageAgent::InspectorPageAgent(InstrumentingAgents* instrumentingAgents, Page* page, InspectorClient* client, InspectorOverlay* overlay) - : InspectorAgentBase(ASCIILiteral("Page"), instrumentingAgents) - , m_page(page) +RefPtr<TextResourceDecoder> InspectorPageAgent::createTextDecoder(const String& mimeType, const String& textEncodingName) +{ + if (!textEncodingName.isEmpty()) + return TextResourceDecoder::create(ASCIILiteral("text/plain"), textEncodingName); + + if (MIMETypeRegistry::isTextMIMEType(mimeType)) + return TextResourceDecoder::create(mimeType, "UTF-8"); + + if (MIMETypeRegistry::isXMLMIMEType(mimeType)) { + RefPtr<TextResourceDecoder> decoder = TextResourceDecoder::create(ASCIILiteral("application/xml")); + decoder->useLenientXMLDecoding(); + return decoder; + } + + return TextResourceDecoder::create(ASCIILiteral("text/plain"), "UTF-8"); +} + +InspectorPageAgent::InspectorPageAgent(PageAgentContext& context, InspectorClient* client, InspectorOverlay* overlay) + : InspectorAgentBase(ASCIILiteral("Page"), context) + , m_frontendDispatcher(std::make_unique<Inspector::PageFrontendDispatcher>(context.frontendRouter)) + , m_backendDispatcher(Inspector::PageBackendDispatcher::create(context.backendDispatcher, this)) + , m_page(context.inspectedPage) , m_client(client) , m_overlay(overlay) - , m_lastScriptIdentifier(0) - , m_enabled(false) - , m_isFirstLayoutAfterOnLoad(false) - , m_originalScriptExecutionDisabled(false) - , m_ignoreScriptsEnabledNotification(false) - , m_showPaintRects(false) { } -void InspectorPageAgent::didCreateFrontendAndBackend(Inspector::InspectorFrontendChannel* frontendChannel, InspectorBackendDispatcher* backendDispatcher) +void InspectorPageAgent::didCreateFrontendAndBackend(Inspector::FrontendRouter*, Inspector::BackendDispatcher*) { - m_frontendDispatcher = std::make_unique<InspectorPageFrontendDispatcher>(frontendChannel); - m_backendDispatcher = InspectorPageBackendDispatcher::create(backendDispatcher, this); } -void InspectorPageAgent::willDestroyFrontendAndBackend(InspectorDisconnectReason) +void InspectorPageAgent::willDestroyFrontendAndBackend(Inspector::DisconnectReason) { - m_frontendDispatcher = nullptr; - m_backendDispatcher.clear(); + ErrorString unused; + disable(unused); +} - ErrorString error; - disable(&error); -#if ENABLE(TOUCH_EVENTS) - updateTouchEventEmulationInPage(false); -#endif +double InspectorPageAgent::timestamp() +{ + return m_environment.executionStopwatch()->elapsedTime(); } -void InspectorPageAgent::enable(ErrorString*) +void InspectorPageAgent::enable(ErrorString&) { m_enabled = true; - m_instrumentingAgents->setInspectorPageAgent(this); + m_instrumentingAgents.setInspectorPageAgent(this); - if (Frame* frame = mainFrame()) - m_originalScriptExecutionDisabled = !frame->settings().isScriptEnabled(); + auto stopwatch = m_environment.executionStopwatch(); + stopwatch->reset(); + stopwatch->start(); } -void InspectorPageAgent::disable(ErrorString*) +void InspectorPageAgent::disable(ErrorString&) { m_enabled = false; - m_scriptsToEvaluateOnLoad.clear(); - m_instrumentingAgents->setInspectorPageAgent(nullptr); + m_scriptsToEvaluateOnLoad = nullptr; + m_instrumentingAgents.setInspectorPageAgent(nullptr); - setScriptExecutionDisabled(nullptr, m_originalScriptExecutionDisabled); - setShowPaintRects(nullptr, false); - setShowDebugBorders(nullptr, false); - setShowFPSCounter(nullptr, false); - setEmulatedMedia(nullptr, ""); - setContinuousPaintingEnabled(nullptr, false); + ErrorString unused; + setShowPaintRects(unused, false); + setEmulatedMedia(unused, emptyString()); } -void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& source, String* identifier) +void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString&, const String& source, String* identifier) { if (!m_scriptsToEvaluateOnLoad) m_scriptsToEvaluateOnLoad = InspectorObject::create(); @@ -411,32 +410,35 @@ void InspectorPageAgent::addScriptToEvaluateOnLoad(ErrorString*, const String& s m_scriptsToEvaluateOnLoad->setString(*identifier, source); } -void InspectorPageAgent::removeScriptToEvaluateOnLoad(ErrorString* error, const String& identifier) +void InspectorPageAgent::removeScriptToEvaluateOnLoad(ErrorString& error, const String& identifier) { if (!m_scriptsToEvaluateOnLoad || m_scriptsToEvaluateOnLoad->find(identifier) == m_scriptsToEvaluateOnLoad->end()) { - *error = "Script not found"; + error = ASCIILiteral("Script not found"); return; } m_scriptsToEvaluateOnLoad->remove(identifier); } -void InspectorPageAgent::reload(ErrorString*, const bool* const optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad) +void InspectorPageAgent::reload(ErrorString&, const bool* const optionalIgnoreCache, const String* optionalScriptToEvaluateOnLoad) { - m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *optionalScriptToEvaluateOnLoad : ""; - m_page->mainFrame().loader().reload(optionalIgnoreCache ? *optionalIgnoreCache : false); + m_pendingScriptToEvaluateOnLoadOnce = optionalScriptToEvaluateOnLoad ? *optionalScriptToEvaluateOnLoad : emptyString(); + m_page.mainFrame().loader().reload(optionalIgnoreCache ? *optionalIgnoreCache : false); } -void InspectorPageAgent::navigate(ErrorString*, const String& url) +void InspectorPageAgent::navigate(ErrorString&, const String& url) { - UserGestureIndicator indicator(DefinitelyProcessingUserGesture); - Frame& frame = m_page->mainFrame(); - frame.loader().changeLocation(frame.document()->securityOrigin(), frame.document()->completeURL(url), "", false, false); + UserGestureIndicator indicator(ProcessingUserGesture); + Frame& frame = m_page.mainFrame(); + + ResourceRequest resourceRequest(frame.document()->completeURL(url)); + FrameLoadRequest frameRequest(frame.document()->securityOrigin(), resourceRequest, "_self", LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, AllowNavigationToInvalidURL::No, NewFrameOpenerPolicy::Allow, ShouldReplaceDocumentIfJavaScriptURL::ReplaceDocumentIfJavaScriptURL, ShouldOpenExternalURLsPolicy::ShouldNotAllow); + frame.loader().changeLocation(frameRequest); } -static PassRefPtr<Inspector::TypeBuilder::Page::Cookie> buildObjectForCookie(const Cookie& cookie) +static Ref<Inspector::Protocol::Page::Cookie> buildObjectForCookie(const Cookie& cookie) { - return Inspector::TypeBuilder::Page::Cookie::create() + return Inspector::Protocol::Page::Cookie::create() .setName(cookie.name) .setValue(cookie.value) .setDomain(cookie.domain) @@ -449,14 +451,12 @@ static PassRefPtr<Inspector::TypeBuilder::Page::Cookie> buildObjectForCookie(con .release(); } -static PassRefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::Cookie>> buildArrayForCookies(ListHashSet<Cookie>& cookiesList) +static Ref<Inspector::Protocol::Array<Inspector::Protocol::Page::Cookie>> buildArrayForCookies(ListHashSet<Cookie>& cookiesList) { - RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::Cookie>> cookies = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::Cookie>::create(); + auto cookies = Inspector::Protocol::Array<Inspector::Protocol::Page::Cookie>::create(); - ListHashSet<Cookie>::iterator end = cookiesList.end(); - ListHashSet<Cookie>::iterator it = cookiesList.begin(); - for (int i = 0; it != end; ++it, i++) - cookies->addItem(buildObjectForCookie(*it)); + for (const auto& cookie : cookiesList) + cookies->addItem(buildObjectForCookie(cookie)); return cookies; } @@ -465,14 +465,17 @@ static Vector<CachedResource*> cachedResourcesForFrame(Frame* frame) { Vector<CachedResource*> result; - const CachedResourceLoader::DocumentResourceMap& allResources = frame->document()->cachedResourceLoader()->allCachedResources(); - CachedResourceLoader::DocumentResourceMap::const_iterator end = allResources.end(); - for (CachedResourceLoader::DocumentResourceMap::const_iterator it = allResources.begin(); it != end; ++it) { - CachedResource* cachedResource = it->value.get(); + for (auto& cachedResourceHandle : frame->document()->cachedResourceLoader().allCachedResources().values()) { + auto* cachedResource = cachedResourceHandle.get(); + if (cachedResource->resourceRequest().hiddenFromInspector()) + continue; switch (cachedResource->type()) { case CachedResource::ImageResource: // Skip images that were not auto loaded (images disabled in the user agent). +#if ENABLE(SVG_FONTS) + case CachedResource::SVGFontResource: +#endif case CachedResource::FontResource: // Skip fonts that were referenced in CSS but never used/downloaded. if (cachedResource->stillNeedsLoad()) @@ -495,14 +498,13 @@ static Vector<URL> allResourcesURLsForFrame(Frame* frame) result.append(frame->loader().documentLoader()->url()); - Vector<CachedResource*> allResources = cachedResourcesForFrame(frame); - for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) - result.append((*it)->url()); + for (auto* cachedResource : cachedResourcesForFrame(frame)) + result.append(cachedResource->url()); return result; } -void InspectorPageAgent::getCookies(ErrorString*, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::Cookie>>& cookies) +void InspectorPageAgent::getCookies(ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Page::Cookie>>& cookies) { // If we can get raw cookies. ListHashSet<Cookie> rawCookiesList; @@ -515,23 +517,24 @@ void InspectorPageAgent::getCookies(ErrorString*, RefPtr<Inspector::TypeBuilder: // always return the same true/false value. bool rawCookiesImplemented = false; - for (Frame* frame = mainFrame(); frame; frame = frame->tree().traverseNext(mainFrame())) { + for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) { Document* document = frame->document(); - Vector<URL> allURLs = allResourcesURLsForFrame(frame); - for (Vector<URL>::const_iterator it = allURLs.begin(); it != allURLs.end(); ++it) { + if (!document) + continue; + + for (auto& url : allResourcesURLsForFrame(frame)) { Vector<Cookie> docCookiesList; - rawCookiesImplemented = getRawCookies(document, URL(ParsedURLString, *it), docCookiesList); + rawCookiesImplemented = getRawCookies(*document, URL(ParsedURLString, url), docCookiesList); + if (!rawCookiesImplemented) { // FIXME: We need duplication checking for the String representation of cookies. - // // Exceptions are thrown by cookie() in sandboxed frames. That won't happen here // because "document" is the document of the main frame of the page. - stringCookiesList.append(document->cookie(ASSERT_NO_EXCEPTION)); + stringCookiesList.append(document->cookie().releaseReturnValue()); } else { - int cookiesSize = docCookiesList.size(); - for (int i = 0; i < cookiesSize; i++) { - if (!rawCookiesList.contains(docCookiesList[i])) - rawCookiesList.add(docCookiesList[i]); + for (auto& cookie : docCookiesList) { + if (!rawCookiesList.contains(cookie)) + rawCookiesList.add(cookie); } } } @@ -541,22 +544,24 @@ void InspectorPageAgent::getCookies(ErrorString*, RefPtr<Inspector::TypeBuilder: if (rawCookiesImplemented) cookies = buildArrayForCookies(rawCookiesList); else - cookies = Inspector::TypeBuilder::Array<TypeBuilder::Page::Cookie>::create(); + cookies = Inspector::Protocol::Array<Inspector::Protocol::Page::Cookie>::create(); } -void InspectorPageAgent::deleteCookie(ErrorString*, const String& cookieName, const String& url) +void InspectorPageAgent::deleteCookie(ErrorString&, const String& cookieName, const String& url) { URL parsedURL(ParsedURLString, url); - for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext(&m_page->mainFrame())) - WebCore::deleteCookie(frame->document(), parsedURL, cookieName); + for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) { + if (auto* document = frame->document()) + WebCore::deleteCookie(*document, parsedURL, cookieName); + } } -void InspectorPageAgent::getResourceTree(ErrorString*, RefPtr<Inspector::TypeBuilder::Page::FrameResourceTree>& object) +void InspectorPageAgent::getResourceTree(ErrorString&, RefPtr<Inspector::Protocol::Page::FrameResourceTree>& object) { - object = buildObjectForFrameTree(&m_page->mainFrame()); + object = buildObjectForFrameTree(&m_page.mainFrame()); } -void InspectorPageAgent::getResourceContent(ErrorString* errorString, const String& frameId, const String& url, String* content, bool* base64Encoded) +void InspectorPageAgent::getResourceContent(ErrorString& errorString, const String& frameId, const String& url, String* content, bool* base64Encoded) { Frame* frame = assertFrame(errorString, frameId); if (!frame) @@ -568,7 +573,6 @@ void InspectorPageAgent::getResourceContent(ErrorString* errorString, const Stri static bool textContentForCachedResource(CachedResource* cachedResource, String* result) { if (hasTextContent(cachedResource)) { - String content; bool base64Encoded; if (InspectorPageAgent::cachedResourceContent(cachedResource, result, &base64Encoded)) { ASSERT(!base64Encoded); @@ -578,18 +582,25 @@ static bool textContentForCachedResource(CachedResource* cachedResource, String* return false; } -void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, const String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::GenericTypes::SearchMatch>>& results) +void InspectorPageAgent::searchInResource(ErrorString& errorString, const String& frameId, const String& url, const String& query, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, const String* optionalRequestId, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::GenericTypes::SearchMatch>>& results) { - results = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::GenericTypes::SearchMatch>::create(); + results = Inspector::Protocol::Array<Inspector::Protocol::GenericTypes::SearchMatch>::create(); bool isRegex = optionalIsRegex ? *optionalIsRegex : false; bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false; - Frame* frame = frameForId(frameId); + if (optionalRequestId) { + if (InspectorNetworkAgent* networkAgent = m_instrumentingAgents.inspectorNetworkAgent()) { + networkAgent->searchInRequest(errorString, *optionalRequestId, query, caseSensitive, isRegex, results); + return; + } + } + + Frame* frame = assertFrame(errorString, frameId); if (!frame) return; - DocumentLoader* loader = frame->loader().documentLoader(); + DocumentLoader* loader = assertDocumentLoader(errorString, frame); if (!loader) return; @@ -612,134 +623,54 @@ void InspectorPageAgent::searchInResource(ErrorString*, const String& frameId, c results = ContentSearchUtilities::searchInTextByLines(content, query, caseSensitive, isRegex); } -static PassRefPtr<Inspector::TypeBuilder::Page::SearchResult> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount) +static Ref<Inspector::Protocol::Page::SearchResult> buildObjectForSearchResult(const String& frameId, const String& url, int matchesCount) { - return Inspector::TypeBuilder::Page::SearchResult::create() + return Inspector::Protocol::Page::SearchResult::create() .setUrl(url) .setFrameId(frameId) .setMatchesCount(matchesCount) .release(); } -void InspectorPageAgent::searchInResources(ErrorString*, const String& text, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::SearchResult>>& results) +void InspectorPageAgent::searchInResources(ErrorString&, const String& text, const bool* const optionalCaseSensitive, const bool* const optionalIsRegex, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Page::SearchResult>>& result) { - RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::SearchResult>> searchResults = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::SearchResult>::create(); + result = Inspector::Protocol::Array<Inspector::Protocol::Page::SearchResult>::create(); bool isRegex = optionalIsRegex ? *optionalIsRegex : false; bool caseSensitive = optionalCaseSensitive ? *optionalCaseSensitive : false; JSC::Yarr::RegularExpression regex = ContentSearchUtilities::createSearchRegex(text, caseSensitive, isRegex); - for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext(&m_page->mainFrame())) { + for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) { String content; - Vector<CachedResource*> allResources = cachedResourcesForFrame(frame); - for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) { - CachedResource* cachedResource = *it; + + for (auto* cachedResource : cachedResourcesForFrame(frame)) { if (textContentForCachedResource(cachedResource, &content)) { int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, content); if (matchesCount) - searchResults->addItem(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount)); + result->addItem(buildObjectForSearchResult(frameId(frame), cachedResource->url(), matchesCount)); } } + if (mainResourceContent(frame, false, &content)) { int matchesCount = ContentSearchUtilities::countRegularExpressionMatches(regex, content); if (matchesCount) - searchResults->addItem(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount)); + result->addItem(buildObjectForSearchResult(frameId(frame), frame->document()->url(), matchesCount)); } } - results = searchResults; -} - -void InspectorPageAgent::setDocumentContent(ErrorString* errorString, const String& frameId, const String& html) -{ - Frame* frame = assertFrame(errorString, frameId); - if (!frame) - return; - - Document* document = frame->document(); - if (!document) { - *errorString = "No Document instance to set HTML for"; - return; - } - DOMPatchSupport::patchDocument(document, html); + if (InspectorNetworkAgent* networkAgent = m_instrumentingAgents.inspectorNetworkAgent()) + networkAgent->searchOtherRequests(regex, result); } -void InspectorPageAgent::setShowPaintRects(ErrorString*, bool show) +void InspectorPageAgent::setShowPaintRects(ErrorString&, bool show) { m_showPaintRects = show; m_client->setShowPaintRects(show); - if (!show && mainFrame() && mainFrame()->view()) - mainFrame()->view()->invalidate(); -} - -void InspectorPageAgent::canShowDebugBorders(ErrorString*, bool* outParam) -{ - *outParam = m_client->canShowDebugBorders(); -} - -void InspectorPageAgent::setShowDebugBorders(ErrorString*, bool show) -{ - m_client->setShowDebugBorders(show); - if (mainFrame() && mainFrame()->view()) - mainFrame()->view()->invalidate(); -} - -void InspectorPageAgent::canShowFPSCounter(ErrorString*, bool* outParam) -{ - *outParam = m_client->canShowFPSCounter(); -} - -void InspectorPageAgent::setShowFPSCounter(ErrorString*, bool show) -{ - m_client->setShowFPSCounter(show); - - if (mainFrame() && mainFrame()->view()) - mainFrame()->view()->invalidate(); -} - -void InspectorPageAgent::canContinuouslyPaint(ErrorString*, bool* outParam) -{ - *outParam = m_client->canContinuouslyPaint(); -} - -void InspectorPageAgent::setContinuousPaintingEnabled(ErrorString*, bool enabled) -{ - m_client->setContinuousPaintingEnabled(enabled); - - if (!enabled && mainFrame() && mainFrame()->view()) - mainFrame()->view()->invalidate(); -} - -void InspectorPageAgent::getScriptExecutionStatus(ErrorString*, InspectorPageBackendDispatcherHandler::Result::Enum* status) -{ - bool disabledByScriptController = false; - bool disabledInSettings = false; - Frame* frame = mainFrame(); - if (frame) { - disabledByScriptController = !frame->script().canExecuteScripts(NotAboutToExecuteScript); - disabledInSettings = !frame->settings().isScriptEnabled(); - } - - if (!disabledByScriptController) { - *status = InspectorPageBackendDispatcherHandler::Result::Allowed; + if (m_client->overridesShowPaintRects()) return; - } - - if (disabledInSettings) - *status = InspectorPageBackendDispatcherHandler::Result::Disabled; - else - *status = InspectorPageBackendDispatcherHandler::Result::Forbidden; -} -void InspectorPageAgent::setScriptExecutionDisabled(ErrorString*, bool value) -{ - if (!mainFrame()) - return; - - m_ignoreScriptsEnabledNotification = true; - mainFrame()->settings().setScriptEnabled(!value); - m_ignoreScriptsEnabledNotification = false; + m_overlay->setShowingPaintRects(show); } void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWorld& world) @@ -747,14 +678,10 @@ void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWor if (&world != &mainThreadNormalWorld()) return; - if (!m_frontendDispatcher) - return; - if (m_scriptsToEvaluateOnLoad) { - InspectorObject::const_iterator end = m_scriptsToEvaluateOnLoad->end(); - for (InspectorObject::const_iterator it = m_scriptsToEvaluateOnLoad->begin(); it != end; ++it) { + for (auto& keyValuePair : *m_scriptsToEvaluateOnLoad) { String scriptText; - if (it->value->asString(&scriptText)) + if (keyValuePair.value->asString(scriptText)) frame->script().executeScript(scriptText); } } @@ -766,26 +693,26 @@ void InspectorPageAgent::didClearWindowObjectInWorld(Frame* frame, DOMWrapperWor void InspectorPageAgent::domContentEventFired() { m_isFirstLayoutAfterOnLoad = true; - m_frontendDispatcher->domContentEventFired(currentTime()); + m_frontendDispatcher->domContentEventFired(timestamp()); } void InspectorPageAgent::loadEventFired() { - m_frontendDispatcher->loadEventFired(currentTime()); + m_frontendDispatcher->loadEventFired(timestamp()); } -void InspectorPageAgent::frameNavigated(DocumentLoader* loader) +void InspectorPageAgent::frameNavigated(Frame& frame) { - if (loader->frame()->isMainFrame()) { + if (frame.isMainFrame()) { m_scriptToEvaluateOnLoadOnce = m_pendingScriptToEvaluateOnLoadOnce; m_pendingScriptToEvaluateOnLoadOnce = String(); } - m_frontendDispatcher->frameNavigated(buildObjectForFrame(loader->frame())); + m_frontendDispatcher->frameNavigated(buildObjectForFrame(&frame)); } -void InspectorPageAgent::frameDetached(Frame* frame) +void InspectorPageAgent::frameDetached(Frame& frame) { - HashMap<Frame*, String>::iterator iterator = m_frameToIdentifier.find(frame); + HashMap<Frame*, String>::iterator iterator = m_frameToIdentifier.find(&frame); if (iterator != m_frameToIdentifier.end()) { m_frontendDispatcher->frameDetached(iterator->value); m_identifierToFrame.remove(iterator->value); @@ -793,10 +720,9 @@ void InspectorPageAgent::frameDetached(Frame* frame) } } -Frame* InspectorPageAgent::mainFrame() +MainFrame& InspectorPageAgent::mainFrame() { - // FIXME: This should return a Frame& - return &m_page->mainFrame(); + return m_page.mainFrame(); } Frame* InspectorPageAgent::frameForId(const String& frameId) @@ -807,7 +733,7 @@ Frame* InspectorPageAgent::frameForId(const String& frameId) String InspectorPageAgent::frameId(Frame* frame) { if (!frame) - return ""; + return emptyString(); String identifier = m_frameToIdentifier.get(frame); if (identifier.isNull()) { identifier = IdentifiersFactory::createIdentifier(); @@ -825,7 +751,7 @@ bool InspectorPageAgent::hasIdForFrame(Frame* frame) const String InspectorPageAgent::loaderId(DocumentLoader* loader) { if (!loader) - return ""; + return emptyString(); String identifier = m_loaderToIdentifier.get(loader); if (identifier.isNull()) { identifier = IdentifiersFactory::createIdentifier(); @@ -836,37 +762,34 @@ String InspectorPageAgent::loaderId(DocumentLoader* loader) Frame* InspectorPageAgent::findFrameWithSecurityOrigin(const String& originRawString) { - for (Frame* frame = &m_page->mainFrame(); frame; frame = frame->tree().traverseNext()) { - RefPtr<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); + for (Frame* frame = &m_page.mainFrame(); frame; frame = frame->tree().traverseNext()) { + Ref<SecurityOrigin> documentOrigin = frame->document()->securityOrigin(); if (documentOrigin->toRawString() == originRawString) return frame; } return nullptr; } -Frame* InspectorPageAgent::assertFrame(ErrorString* errorString, const String& frameId) +Frame* InspectorPageAgent::assertFrame(ErrorString& errorString, const String& frameId) { Frame* frame = frameForId(frameId); if (!frame) - *errorString = "No frame for given id found"; + errorString = ASCIILiteral("No frame for given id found"); return frame; } -// static -DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString* errorString, Frame* frame) +DocumentLoader* InspectorPageAgent::assertDocumentLoader(ErrorString& errorString, Frame* frame) { FrameLoader& frameLoader = frame->loader(); DocumentLoader* documentLoader = frameLoader.documentLoader(); if (!documentLoader) - *errorString = "No documentLoader for given frame found"; + errorString = ASCIILiteral("No documentLoader for given frame found"); return documentLoader; } -void InspectorPageAgent::loaderDetachedFromFrame(DocumentLoader* loader) +void InspectorPageAgent::loaderDetachedFromFrame(DocumentLoader& loader) { - HashMap<DocumentLoader*, String>::iterator iterator = m_loaderToIdentifier.find(loader); - if (iterator != m_loaderToIdentifier.end()) - m_loaderToIdentifier.remove(iterator); + m_loaderToIdentifier.remove(&loader); } void InspectorPageAgent::frameStartedLoading(Frame& frame) @@ -889,31 +812,26 @@ void InspectorPageAgent::frameClearedScheduledNavigation(Frame& frame) m_frontendDispatcher->frameClearedScheduledNavigation(frameId(&frame)); } -void InspectorPageAgent::willRunJavaScriptDialog(const String& message) +void InspectorPageAgent::didPaint(RenderObject& renderer, const LayoutRect& rect) { - m_frontendDispatcher->javascriptDialogOpening(message); -} + if (!m_enabled || !m_showPaintRects) + return; -void InspectorPageAgent::didRunJavaScriptDialog() -{ - m_frontendDispatcher->javascriptDialogClosed(); -} + LayoutRect absoluteRect = LayoutRect(renderer.localToAbsoluteQuad(FloatRect(rect)).boundingBox()); + FrameView* view = renderer.document().view(); -void InspectorPageAgent::didPaint(GraphicsContext* context, const LayoutRect& rect) -{ - if (!m_enabled || m_client->overridesShowPaintRects() || !m_showPaintRects) - return; + LayoutRect rootRect = absoluteRect; + if (!view->frame().isMainFrame()) { + IntRect rootViewRect = view->contentsToRootView(snappedIntRect(absoluteRect)); + rootRect = view->frame().mainFrame().view()->rootViewToContents(rootViewRect); + } - static int colorSelector = 0; - const Color colors[] = { - Color(0xFF, 0, 0, 0x3F), - Color(0xFF, 0, 0xFF, 0x3F), - Color(0, 0, 0xFF, 0x3F), - }; + if (m_client->overridesShowPaintRects()) { + m_client->showPaintRect(rootRect); + return; + } - LayoutRect inflatedRect(rect); - inflatedRect.inflate(-1); - m_overlay->drawOutline(context, inflatedRect, colors[colorSelector++ % WTF_ARRAY_LENGTH(colors)]); + m_overlay->showPaintRect(rootRect); } void InspectorPageAgent::didLayout() @@ -940,50 +858,46 @@ void InspectorPageAgent::didRecalculateStyle() m_overlay->update(); } -void InspectorPageAgent::scriptsEnabled(bool isEnabled) +Ref<Inspector::Protocol::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame) { - if (m_ignoreScriptsEnabledNotification) - return; - - m_frontendDispatcher->scriptsEnabled(isEnabled); -} + ASSERT_ARG(frame, frame); -PassRefPtr<Inspector::TypeBuilder::Page::Frame> InspectorPageAgent::buildObjectForFrame(Frame* frame) -{ - RefPtr<Inspector::TypeBuilder::Page::Frame> frameObject = Inspector::TypeBuilder::Page::Frame::create() + auto frameObject = Inspector::Protocol::Page::Frame::create() .setId(frameId(frame)) .setLoaderId(loaderId(frame->loader().documentLoader())) .setUrl(frame->document()->url().string()) .setMimeType(frame->loader().documentLoader()->responseMIMEType()) - .setSecurityOrigin(frame->document()->securityOrigin()->toRawString()); + .setSecurityOrigin(frame->document()->securityOrigin().toRawString()) + .release(); if (frame->tree().parent()) frameObject->setParentId(frameId(frame->tree().parent())); if (frame->ownerElement()) { String name = frame->ownerElement()->getNameAttribute(); if (name.isEmpty()) - name = frame->ownerElement()->getAttribute(HTMLNames::idAttr); + name = frame->ownerElement()->attributeWithoutSynchronization(HTMLNames::idAttr); frameObject->setName(name); } return frameObject; } -PassRefPtr<Inspector::TypeBuilder::Page::FrameResourceTree> InspectorPageAgent::buildObjectForFrameTree(Frame* frame) +Ref<Inspector::Protocol::Page::FrameResourceTree> InspectorPageAgent::buildObjectForFrameTree(Frame* frame) { - RefPtr<Inspector::TypeBuilder::Page::Frame> frameObject = buildObjectForFrame(frame); - RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::FrameResourceTree::Resources>> subresources = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::FrameResourceTree::Resources>::create(); - RefPtr<Inspector::TypeBuilder::Page::FrameResourceTree> result = Inspector::TypeBuilder::Page::FrameResourceTree::create() - .setFrame(frameObject) - .setResources(subresources); + ASSERT_ARG(frame, frame); - Vector<CachedResource*> allResources = cachedResourcesForFrame(frame); - for (Vector<CachedResource*>::const_iterator it = allResources.begin(); it != allResources.end(); ++it) { - CachedResource* cachedResource = *it; + Ref<Inspector::Protocol::Page::Frame> frameObject = buildObjectForFrame(frame); + auto subresources = Inspector::Protocol::Array<Inspector::Protocol::Page::FrameResource>::create(); + auto result = Inspector::Protocol::Page::FrameResourceTree::create() + .setFrame(WTFMove(frameObject)) + .setResources(subresources.copyRef()) + .release(); - RefPtr<Inspector::TypeBuilder::Page::FrameResourceTree::Resources> resourceObject = Inspector::TypeBuilder::Page::FrameResourceTree::Resources::create() + for (auto* cachedResource : cachedResourcesForFrame(frame)) { + auto resourceObject = Inspector::Protocol::Page::FrameResource::create() .setUrl(cachedResource->url()) .setType(cachedResourceTypeJson(*cachedResource)) - .setMimeType(cachedResource->response().mimeType()); + .setMimeType(cachedResource->response().mimeType()) + .release(); if (cachedResource->wasCanceled()) resourceObject->setCanceled(true); else if (cachedResource->status() == CachedResource::LoadError) @@ -991,13 +905,16 @@ PassRefPtr<Inspector::TypeBuilder::Page::FrameResourceTree> InspectorPageAgent:: String sourceMappingURL = InspectorPageAgent::sourceMapURLForResource(cachedResource); if (!sourceMappingURL.isEmpty()) resourceObject->setSourceMapURL(sourceMappingURL); - subresources->addItem(resourceObject); + String targetId = cachedResource->resourceRequest().initiatorIdentifier(); + if (!targetId.isEmpty()) + resourceObject->setTargetId(targetId); + subresources->addItem(WTFMove(resourceObject)); } - RefPtr<Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::FrameResourceTree>> childrenArray; + RefPtr<Inspector::Protocol::Array<Inspector::Protocol::Page::FrameResourceTree>> childrenArray; for (Frame* child = frame->tree().firstChild(); child; child = child->tree().nextSibling()) { if (!childrenArray) { - childrenArray = Inspector::TypeBuilder::Array<Inspector::TypeBuilder::Page::FrameResourceTree>::create(); + childrenArray = Inspector::Protocol::Array<Inspector::Protocol::Page::FrameResourceTree>::create(); result->setChildFrames(childrenArray); } childrenArray->addItem(buildObjectForFrameTree(child)); @@ -1005,113 +922,81 @@ PassRefPtr<Inspector::TypeBuilder::Page::FrameResourceTree> InspectorPageAgent:: return result; } -#if ENABLE(TOUCH_EVENTS) -void InspectorPageAgent::updateTouchEventEmulationInPage(bool enabled) -{ - if (mainFrame()) - mainFrame()->settings().setTouchEventEmulationEnabled(enabled); -} -#endif - -void InspectorPageAgent::setTouchEmulationEnabled(ErrorString* error, bool enabled) -{ -#if ENABLE(TOUCH_EVENTS) - UNUSED_PARAM(error); - updateTouchEventEmulationInPage(enabled); -#else - *error = "Touch events emulation not supported"; - UNUSED_PARAM(enabled); -#endif -} - -void InspectorPageAgent::setEmulatedMedia(ErrorString*, const String& media) +void InspectorPageAgent::setEmulatedMedia(ErrorString&, const String& media) { if (media == m_emulatedMedia) return; m_emulatedMedia = media; - Document* document = m_page->mainFrame().document(); + Document* document = m_page.mainFrame().document(); if (document) { - document->styleResolverChanged(RecalcStyleImmediately); + document->styleScope().didChangeStyleSheetEnvironment(); document->updateLayout(); } } -void InspectorPageAgent::applyEmulatedMedia(String* media) +void InspectorPageAgent::applyEmulatedMedia(String& media) { if (!m_emulatedMedia.isEmpty()) - *media = m_emulatedMedia; + media = m_emulatedMedia; } -void InspectorPageAgent::getCompositingBordersVisible(ErrorString*, bool* outParam) +void InspectorPageAgent::getCompositingBordersVisible(ErrorString&, bool* outParam) { - *outParam = m_page->settings().showDebugBorders() || m_page->settings().showRepaintCounter(); + *outParam = m_page.settings().showDebugBorders() || m_page.settings().showRepaintCounter(); } -void InspectorPageAgent::setCompositingBordersVisible(ErrorString*, bool visible) +void InspectorPageAgent::setCompositingBordersVisible(ErrorString&, bool visible) { - m_page->settings().setShowDebugBorders(visible); - m_page->settings().setShowRepaintCounter(visible); + m_page.settings().setShowDebugBorders(visible); + m_page.settings().setShowRepaintCounter(visible); } -void InspectorPageAgent::snapshotNode(ErrorString* errorString, int nodeId, String* outDataURL) +void InspectorPageAgent::snapshotNode(ErrorString& errorString, int nodeId, String* outDataURL) { - Frame* frame = mainFrame(); - ASSERT(frame); + Frame& frame = mainFrame(); - InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent(); + InspectorDOMAgent* domAgent = m_instrumentingAgents.inspectorDOMAgent(); ASSERT(domAgent); Node* node = domAgent->assertNode(errorString, nodeId); if (!node) return; - std::unique_ptr<ImageBuffer> snapshot = WebCore::snapshotNode(*frame, *node); + std::unique_ptr<ImageBuffer> snapshot = WebCore::snapshotNode(frame, *node); if (!snapshot) { - *errorString = ASCIILiteral("Could not capture snapshot"); + errorString = ASCIILiteral("Could not capture snapshot"); return; } *outDataURL = snapshot->toDataURL(ASCIILiteral("image/png")); } -void InspectorPageAgent::snapshotRect(ErrorString* errorString, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL) +void InspectorPageAgent::snapshotRect(ErrorString& errorString, int x, int y, int width, int height, const String& coordinateSystem, String* outDataURL) { - Frame* frame = mainFrame(); - ASSERT(frame); + Frame& frame = mainFrame(); SnapshotOptions options = SnapshotOptionsNone; if (coordinateSystem == "Viewport") options |= SnapshotOptionsInViewCoordinates; IntRect rectangle(x, y, width, height); - std::unique_ptr<ImageBuffer> snapshot = snapshotFrameRect(*frame, rectangle, options); + std::unique_ptr<ImageBuffer> snapshot = snapshotFrameRect(frame, rectangle, options); if (!snapshot) { - *errorString = ASCIILiteral("Could not capture snapshot"); + errorString = ASCIILiteral("Could not capture snapshot"); return; } *outDataURL = snapshot->toDataURL(ASCIILiteral("image/png")); } -void InspectorPageAgent::handleJavaScriptDialog(ErrorString* errorString, bool accept, const String* promptText) -{ - if (!m_client->handleJavaScriptDialog(accept, promptText)) - *errorString = "Could not handle JavaScript dialog"; -} - -void InspectorPageAgent::archive(ErrorString* errorString, String* data) +void InspectorPageAgent::archive(ErrorString& errorString, String* data) { - Frame* frame = mainFrame(); - if (!frame) { - *errorString = "No main frame"; - return; - } - #if ENABLE(WEB_ARCHIVE) && USE(CF) + Frame& frame = mainFrame(); RefPtr<LegacyWebArchive> archive = LegacyWebArchive::create(frame); if (!archive) { - *errorString = "Could not create web archive for main frame"; + errorString = ASCIILiteral("Could not create web archive for main frame"); return; } @@ -1119,10 +1004,8 @@ void InspectorPageAgent::archive(ErrorString* errorString, String* data) *data = base64Encode(CFDataGetBytePtr(buffer.get()), CFDataGetLength(buffer.get())); #else UNUSED_PARAM(data); - *errorString = "No support for creating archives"; + errorString = ASCIILiteral("No support for creating archives"); #endif } } // namespace WebCore - -#endif // ENABLE(INSPECTOR) |