haikuwebkit/Source/WebCore/inspector/InspectorAuditResourcesObje...

97 lines
3.5 KiB
C
Raw Permalink Normal View History

Web Inspector: Audit: provide a way to get the contents of resources https://bugs.webkit.org/show_bug.cgi?id=195266 <rdar://problem/48550911> Reviewed by Joseph Pecoraro. Source/JavaScriptCore: * inspector/InjectedScriptBase.cpp: (Inspector::InjectedScriptBase::makeAsyncCall): Drive-by: fix missing `else`. Source/WebCore: Test: inspector/audit/run-resources.html * inspector/InspectorAuditResourcesObject.idl: Added. * inspector/InspectorAuditResourcesObject.h: Added. (WebCore::InspectorAuditResourcesObject::create): (WebCore::InspectorAuditResourcesObject::Resource): (WebCore::InspectorAuditResourcesObject::ResourceContent): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedResourceClient): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedFontClient): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedImageClient): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedRawResourceClient): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedStyleSheetClient): (WebCore::InspectorAuditResourcesObject::InspectorAuditCachedSVGDocumentClient): * inspector/InspectorAuditResourcesObject.cpp: Added. (WebCore::InspectorAuditResourcesObject::InspectorAuditResourcesObject): (WebCore::InspectorAuditResourcesObject::getResources): (WebCore::InspectorAuditResourcesObject::getResourceContent): (WebCore::InspectorAuditResourcesObject::clientForResource): * inspector/agents/InspectorPageAgent.h: * inspector/agents/InspectorPageAgent.cpp: (WebCore::InspectorPageAgent::cachedResourcesForFrame): Added. (WebCore::allResourcesURLsForFrame): Moved a file static function to be a class static function so it can be used elsewhere. * CMakeLists.txt: * DerivedSources-input.xcfilelist: * DerivedSources-output.xcfilelist: * DerivedSources.make: * Sources.txt: * WebCore.xcodeproj/project.pbxproj: LayoutTests: * inspector/audit/resources/sample-resource.css: Added. * inspector/audit/resources/sample-resource.js: Added. * inspector/audit/run-resources.html: Added. * inspector/audit/run-resources-expected.txt: Added. Canonical link: https://commits.webkit.org/210031@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@242941 268f45cc-cd09-0410-ab3c-d52691b4dbfc
2019-03-14 10:13:57 +00:00
/*
* Copyright (C) 2019 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 met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include "CachedFontClient.h"
#include "CachedImageClient.h"
#include "CachedRawResourceClient.h"
#include "CachedResourceClient.h"
#include "CachedSVGDocumentClient.h"
#include "CachedStyleSheetClient.h"
#include "ExceptionOr.h"
#include <JavaScriptCore/InspectorAuditAgent.h>
#include <wtf/Forward.h>
#include <wtf/Ref.h>
#include <wtf/RefCounted.h>
namespace WebCore {
class CachedResource;
class Document;
class InspectorAuditResourcesObject : public RefCounted<InspectorAuditResourcesObject> {
public:
static Ref<InspectorAuditResourcesObject> create(Inspector::InspectorAuditAgent& auditAgent)
{
return adoptRef(*new InspectorAuditResourcesObject(auditAgent));
}
~InspectorAuditResourcesObject();
struct Resource {
String id;
String url;
String mimeType;
};
struct ResourceContent {
String data;
bool base64Encoded;
};
ExceptionOr<Vector<Resource>> getResources(Document&);
ExceptionOr<ResourceContent> getResourceContent(Document&, const String& id);
private:
explicit InspectorAuditResourcesObject(Inspector::InspectorAuditAgent&);
CachedResourceClient& clientForResource(const CachedResource&);
Inspector::InspectorAuditAgent& m_auditAgent;
class InspectorAuditCachedResourceClient : public CachedResourceClient { };
InspectorAuditCachedResourceClient m_cachedResourceClient;
class InspectorAuditCachedFontClient : public CachedFontClient { };
InspectorAuditCachedFontClient m_cachedFontClient;
class InspectorAuditCachedImageClient : public CachedImageClient { };
InspectorAuditCachedImageClient m_cachedImageClient;
class InspectorAuditCachedRawResourceClient : public CachedRawResourceClient { };
InspectorAuditCachedRawResourceClient m_cachedRawResourceClient;
class InspectorAuditCachedSVGDocumentClient : public CachedSVGDocumentClient { };
InspectorAuditCachedSVGDocumentClient m_cachedSVGDocumentClient;
class InspectorAuditCachedStyleSheetClient : public CachedStyleSheetClient { };
InspectorAuditCachedStyleSheetClient m_cachedStyleSheetClient;
HashMap<String, CachedResource*> m_resources;
};
} // namespace WebCore