chromium/third_party/blink/renderer/core/inspector/inspector_page_agent.cc

/*
 * Copyright (C) 2011 Google 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:
 *
 *     * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *     * 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.
 *     * Neither the name of Google Inc. nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 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 THE COPYRIGHT
 * OWNER OR 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.
 */

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/351564777): Remove this and convert code to safer constructs.
#pragma allow_unsafe_buffers
#endif

#include "third_party/blink/renderer/core/inspector/inspector_page_agent.h"

#include <memory>
#include <optional>
#include <utility>

#include "base/containers/span.h"
#include "base/numerics/safe_conversions.h"
#include "build/build_config.h"
#include "third_party/blink/public/common/frame/frame_ad_evidence.h"
#include "third_party/blink/public/common/origin_trials/trial_token.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/mojom/ad_tagging/ad_evidence.mojom-blink.h"
#include "third_party/blink/public/mojom/loader/same_document_navigation_type.mojom-blink.h"
#include "third_party/blink/renderer/bindings/core/v8/local_window_proxy.h"
#include "third_party/blink/renderer/bindings/core/v8/script_controller.h"
#include "third_party/blink/renderer/bindings/core/v8/script_evaluation_result.h"
#include "third_party/blink/renderer/core/dom/document.h"
#include "third_party/blink/renderer/core/dom/document_timing.h"
#include "third_party/blink/renderer/core/dom/dom_node_ids.h"
#include "third_party/blink/renderer/core/execution_context/agent.h"
#include "third_party/blink/renderer/core/frame/ad_tracker.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/frame/local_frame_view.h"
#include "third_party/blink/renderer/core/frame/report.h"
#include "third_party/blink/renderer/core/frame/reporting_context.h"
#include "third_party/blink/renderer/core/frame/settings.h"
#include "third_party/blink/renderer/core/frame/test_report_body.h"
#include "third_party/blink/renderer/core/frame/visual_viewport.h"
#include "third_party/blink/renderer/core/html/forms/html_input_element.h"
#include "third_party/blink/renderer/core/html/html_frame_owner_element.h"
#include "third_party/blink/renderer/core/html/parser/text_resource_decoder.h"
#include "third_party/blink/renderer/core/html_names.h"
#include "third_party/blink/renderer/core/inspector/identifiers_factory.h"
#include "third_party/blink/renderer/core/inspector/inspected_frames.h"
#include "third_party/blink/renderer/core/inspector/inspector_css_agent.h"
#include "third_party/blink/renderer/core/inspector/inspector_resource_content_loader.h"
#include "third_party/blink/renderer/core/inspector/v8_inspector_string.h"
#include "third_party/blink/renderer/core/layout/adjust_for_absolute_zoom.h"
#include "third_party/blink/renderer/core/loader/document_loader.h"
#include "third_party/blink/renderer/core/loader/frame_loader.h"
#include "third_party/blink/renderer/core/loader/idleness_detector.h"
#include "third_party/blink/renderer/core/loader/resource/css_style_sheet_resource.h"
#include "third_party/blink/renderer/core/loader/resource/script_resource.h"
#include "third_party/blink/renderer/core/origin_trials/origin_trial_context.h"
#include "third_party/blink/renderer/core/page/page.h"
#include "third_party/blink/renderer/core/paint/paint_layer_scrollable_area.h"
#include "third_party/blink/renderer/core/permissions_policy/permissions_policy_devtools_support.h"
#include "third_party/blink/renderer/core/probe/core_probes.h"
#include "third_party/blink/renderer/core/script/classic_script.h"
#include "third_party/blink/renderer/core/style/computed_style.h"
#include "third_party/blink/renderer/platform/bindings/dom_wrapper_world.h"
#include "third_party/blink/renderer/platform/bindings/script_regexp.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/loader/fetch/memory_cache.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
#include "third_party/blink/renderer/platform/loader/fetch/text_resource_decoder_options.h"
#include "third_party/blink/renderer/platform/network/mime/mime_type_registry.h"
#include "third_party/blink/renderer/platform/network/network_utils.h"
#include "third_party/blink/renderer/platform/text/locale_to_script_mapping.h"
#include "third_party/blink/renderer/platform/weborigin/security_origin.h"
#include "third_party/blink/renderer/platform/wtf/text/base64.h"
#include "third_party/blink/renderer/platform/wtf/text/string_utf8_adaptor.h"
#include "third_party/blink/renderer/platform/wtf/text/text_encoding.h"
#include "third_party/blink/renderer/platform/wtf/vector.h"
#include "third_party/inspector_protocol/crdtp/protocol_core.h"
#include "ui/display/screen_info.h"
#include "v8/include/v8-inspector.h"

namespace blink {

namespace {

String ClientNavigationReasonToProtocol(ClientNavigationReason reason) {}

String NavigationPolicyToProtocol(NavigationPolicy policy) {}

String FrameDetachTypeToProtocol(FrameDetachType type) {}

Resource* CachedResource(LocalFrame* frame,
                         const KURL& url,
                         InspectorResourceContentLoader* loader) {}

std::unique_ptr<protocol::Array<String>> GetEnabledWindowFeatures(
    const WebWindowFeatures& window_features) {}

}  // namespace

static bool PrepareResourceBuffer(const Resource* cached_resource,
                                  bool* has_zero_size) {}

static bool HasTextContent(const Resource* cached_resource) {}

static std::unique_ptr<TextResourceDecoder> CreateResourceTextDecoder(
    const String& mime_type,
    const String& text_encoding_name) {}

static void MaybeEncodeTextContent(const String& text_content,
                                   const char* buffer_data,
                                   wtf_size_t buffer_size,
                                   String* result,
                                   bool* base64_encoded) {}

static void MaybeEncodeTextContent(const String& text_content,
                                   scoped_refptr<const SharedBuffer> buffer,
                                   String* result,
                                   bool* base64_encoded) {}

// static
KURL InspectorPageAgent::UrlWithoutFragment(const KURL& url) {}

// static
bool InspectorPageAgent::SegmentedBufferContent(
    const SegmentedBuffer* buffer,
    const String& mime_type,
    const String& text_encoding_name,
    String* result,
    bool* base64_encoded) {}

// static
bool InspectorPageAgent::CachedResourceContent(const Resource* cached_resource,
                                               String* result,
                                               bool* base64_encoded) {}

String InspectorPageAgent::ResourceTypeJson(
    InspectorPageAgent::ResourceType resource_type) {}

InspectorPageAgent::ResourceType InspectorPageAgent::ToResourceType(
    const blink::ResourceType resource_type) {}

String InspectorPageAgent::CachedResourceTypeJson(
    const Resource& cached_resource) {}

InspectorPageAgent::PageReloadScriptInjection::PageReloadScriptInjection(
    InspectorAgentState& agent_state)
    :{}

void InspectorPageAgent::PageReloadScriptInjection::clear() {}

void InspectorPageAgent::PageReloadScriptInjection::SetPending(
    String script,
    const KURL& target_url) {}

void InspectorPageAgent::PageReloadScriptInjection::PromoteToLoadOnce() {}

String InspectorPageAgent::PageReloadScriptInjection::GetScriptForInjection(
    const KURL& target_url) {}

InspectorPageAgent::InspectorPageAgent(
    InspectedFrames* inspected_frames,
    Client* client,
    InspectorResourceContentLoader* resource_content_loader,
    v8_inspector::V8InspectorSession* v8_session)
    :{}

void InspectorPageAgent::Restore() {}

protocol::Response InspectorPageAgent::enable() {}

protocol::Response InspectorPageAgent::disable() {}

protocol::Response InspectorPageAgent::addScriptToEvaluateOnNewDocument(
    const String& source,
    Maybe<String> world_name,
    Maybe<bool> include_command_line_api,
    Maybe<bool> runImmediately,
    String* identifier) {}

protocol::Response InspectorPageAgent::removeScriptToEvaluateOnNewDocument(
    const String& identifier) {}

protocol::Response InspectorPageAgent::addScriptToEvaluateOnLoad(
    const String& source,
    String* identifier) {}

protocol::Response InspectorPageAgent::removeScriptToEvaluateOnLoad(
    const String& identifier) {}

protocol::Response InspectorPageAgent::setLifecycleEventsEnabled(bool enabled) {}

protocol::Response InspectorPageAgent::setAdBlockingEnabled(bool enable) {}

protocol::Response InspectorPageAgent::reload(
    Maybe<bool> optional_bypass_cache,
    Maybe<String> optional_script_to_evaluate_on_load,
    Maybe<String> loader_id) {}

protocol::Response InspectorPageAgent::stopLoading() {}

static void CachedResourcesForDocument(Document* document,
                                       HeapVector<Member<Resource>>& result,
                                       bool skip_xhrs) {}

// static
static HeapVector<Member<Resource>> CachedResourcesForFrame(LocalFrame* frame,
                                                            bool skip_xhrs) {}

protocol::Response InspectorPageAgent::getResourceTree(
    std::unique_ptr<protocol::Page::FrameResourceTree>* object) {}

protocol::Response InspectorPageAgent::getFrameTree(
    std::unique_ptr<protocol::Page::FrameTree>* object) {}

void InspectorPageAgent::GetResourceContentAfterResourcesContentLoaded(
    const String& frame_id,
    const String& url,
    std::unique_ptr<GetResourceContentCallback> callback) {}

void InspectorPageAgent::getResourceContent(
    const String& frame_id,
    const String& url,
    std::unique_ptr<GetResourceContentCallback> callback) {}

protocol::Response InspectorPageAgent::getAdScriptId(
    const String& frame_id,
    Maybe<protocol::Page::AdScriptId>* ad_script_id) {}

void InspectorPageAgent::SearchContentAfterResourcesContentLoaded(
    const String& frame_id,
    const String& url,
    const String& query,
    bool case_sensitive,
    bool is_regex,
    std::unique_ptr<SearchInResourceCallback> callback) {}

void InspectorPageAgent::searchInResource(
    const String& frame_id,
    const String& url,
    const String& query,
    Maybe<bool> optional_case_sensitive,
    Maybe<bool> optional_is_regex,
    std::unique_ptr<SearchInResourceCallback> callback) {}

protocol::Response InspectorPageAgent::setBypassCSP(bool enabled) {}

namespace {

std::unique_ptr<protocol::Page::PermissionsPolicyBlockLocator>
CreatePermissionsPolicyBlockLocator(
    const blink::PermissionsPolicyBlockLocator& locator) {}
}  // namespace

protocol::Response InspectorPageAgent::getPermissionsPolicyState(
    const String& frame_id,
    std::unique_ptr<
        protocol::Array<protocol::Page::PermissionsPolicyFeatureState>>*
        states) {}

protocol::Response InspectorPageAgent::setDocumentContent(
    const String& frame_id,
    const String& html) {}

namespace {
const char* NavigationTypeToProtocolString(
    mojom::blink::SameDocumentNavigationType navigation_type) {}
}  // namespace

void InspectorPageAgent::DidNavigateWithinDocument(
    LocalFrame* frame,
    mojom::blink::SameDocumentNavigationType navigation_type) {}

DOMWrapperWorld* InspectorPageAgent::EnsureDOMWrapperWorld(
    LocalFrame* frame,
    const String& world_name,
    bool grant_universal_access) {}

void InspectorPageAgent::DidCreateMainWorldContext(LocalFrame* frame) {}

void InspectorPageAgent::EvaluateScriptOnNewDocument(
    LocalFrame& frame,
    const String& script_identifier) {}

void InspectorPageAgent::DomContentLoadedEventFired(LocalFrame* frame) {}

void InspectorPageAgent::LoadEventFired(LocalFrame* frame) {}

void InspectorPageAgent::WillCommitLoad(LocalFrame*, DocumentLoader* loader) {}

void InspectorPageAgent::DidRestoreFromBackForwardCache(LocalFrame* frame) {}

void InspectorPageAgent::DidOpenDocument(LocalFrame* frame,
                                         DocumentLoader* loader) {}

void InspectorPageAgent::FrameAttachedToParent(
    LocalFrame* frame,
    const std::optional<AdScriptIdentifier>& ad_script_on_stack) {}

void InspectorPageAgent::FrameDetachedFromParent(LocalFrame* frame,
                                                 FrameDetachType type) {}

void InspectorPageAgent::FrameSubtreeWillBeDetached(Frame* frame) {}

bool InspectorPageAgent::ScreencastEnabled() {}

void InspectorPageAgent::FrameStoppedLoading(LocalFrame* frame) {}

void InspectorPageAgent::FrameRequestedNavigation(Frame* target_frame,
                                                  const KURL& url,
                                                  ClientNavigationReason reason,
                                                  NavigationPolicy policy) {}

void InspectorPageAgent::FrameScheduledNavigation(
    LocalFrame* frame,
    const KURL& url,
    base::TimeDelta delay,
    ClientNavigationReason reason) {}

void InspectorPageAgent::FrameClearedScheduledNavigation(LocalFrame* frame) {}

void InspectorPageAgent::WillRunJavaScriptDialog() {}

void InspectorPageAgent::DidRunJavaScriptDialog() {}

void InspectorPageAgent::DidResizeMainFrame() {}

void InspectorPageAgent::DidChangeViewport() {}

void InspectorPageAgent::LifecycleEvent(LocalFrame* frame,
                                        DocumentLoader* loader,
                                        const char* name,
                                        double timestamp) {}

void InspectorPageAgent::PaintTiming(Document* document,
                                     const char* name,
                                     double timestamp) {}

void InspectorPageAgent::Will(const probe::UpdateLayout&) {}

void InspectorPageAgent::Did(const probe::UpdateLayout&) {}

void InspectorPageAgent::Will(const probe::RecalculateStyle&) {}

void InspectorPageAgent::Did(const probe::RecalculateStyle&) {}

void InspectorPageAgent::PageLayoutInvalidated(bool resized) {}

void InspectorPageAgent::WindowOpen(const KURL& url,
                                    const AtomicString& window_name,
                                    const WebWindowFeatures& window_features,
                                    bool user_gesture) {}

namespace {
protocol::Page::SecureContextType CreateProtocolSecureContextType(
    SecureContextModeExplanation explanation) {}
protocol::Page::CrossOriginIsolatedContextType
CreateProtocolCrossOriginIsolatedContextType(ExecutionContext* context) {}
std::unique_ptr<std::vector<protocol::Page::GatedAPIFeatures>>
CreateGatedAPIFeaturesArray(LocalDOMWindow* window) {}

protocol::Page::OriginTrialTokenStatus CreateOriginTrialTokenStatus(
    blink::OriginTrialTokenStatus status) {}

protocol::Page::OriginTrialStatus CreateOriginTrialStatus(
    blink::OriginTrialStatus status) {}

protocol::Page::OriginTrialUsageRestriction CreateOriginTrialUsageRestriction(
    blink::TrialToken::UsageRestriction blink_restriction) {}

std::unique_ptr<protocol::Page::OriginTrialToken> CreateOriginTrialToken(
    const blink::TrialToken& blink_trial_token) {}

std::unique_ptr<protocol::Page::OriginTrialTokenWithStatus>
CreateOriginTrialTokenWithStatus(
    const blink::OriginTrialTokenResult& blink_token_result) {}

std::unique_ptr<protocol::Page::OriginTrial> CreateOriginTrial(
    const blink::OriginTrialResult& blink_trial_result) {}

std::unique_ptr<protocol::Array<protocol::Page::OriginTrial>>
CreateOriginTrials(LocalDOMWindow* window) {}

protocol::Page::AdFrameType BuildAdFrameType(LocalFrame* frame) {}

std::unique_ptr<protocol::Page::AdFrameStatus> BuildAdFrameStatus(
    LocalFrame* frame) {}

}  // namespace

std::unique_ptr<protocol::Page::Frame> InspectorPageAgent::BuildObjectForFrame(
    LocalFrame* frame) {}

std::unique_ptr<protocol::Page::FrameTree>
InspectorPageAgent::BuildObjectForFrameTree(LocalFrame* frame) {}

std::unique_ptr<protocol::Page::FrameResourceTree>
InspectorPageAgent::BuildObjectForResourceTree(LocalFrame* frame) {}

protocol::Response InspectorPageAgent::startScreencast(
    Maybe<String> format,
    Maybe<int> quality,
    Maybe<int> max_width,
    Maybe<int> max_height,
    Maybe<int> every_nth_frame) {}

protocol::Response InspectorPageAgent::stopScreencast() {}

protocol::Response InspectorPageAgent::getLayoutMetrics(
    std::unique_ptr<protocol::Page::LayoutViewport>* out_layout_viewport,
    std::unique_ptr<protocol::Page::VisualViewport>* out_visual_viewport,
    std::unique_ptr<protocol::DOM::Rect>* out_content_size,
    std::unique_ptr<protocol::Page::LayoutViewport>* out_css_layout_viewport,
    std::unique_ptr<protocol::Page::VisualViewport>* out_css_visual_viewport,
    std::unique_ptr<protocol::DOM::Rect>* out_css_content_size) {}

void InspectorPageAgent::createIsolatedWorld(
    const String& frame_id,
    Maybe<String> world_name,
    Maybe<bool> grant_universal_access,
    std::unique_ptr<CreateIsolatedWorldCallback> callback) {}

void InspectorPageAgent::CreateIsolatedWorldImpl(
    LocalFrame& frame,
    String world_name,
    bool grant_universal_access,
    std::unique_ptr<CreateIsolatedWorldCallback> callback) {}

protocol::Response InspectorPageAgent::setFontFamilies(
    GenericFontFamilySettings& family_settings,
    const protocol::Array<protocol::Page::ScriptFontFamilies>&
        script_font_families) {}

protocol::Response InspectorPageAgent::setFontFamilies(
    std::unique_ptr<protocol::Page::FontFamilies> font_families,
    Maybe<protocol::Array<protocol::Page::ScriptFontFamilies>> for_scripts) {}

protocol::Response InspectorPageAgent::setFontSizes(
    std::unique_ptr<protocol::Page::FontSizes> font_sizes) {}

void InspectorPageAgent::ApplyCompilationModeOverride(
    const ClassicScript& classic_script,
    v8::ScriptCompiler::CachedData** cached_data,
    v8::ScriptCompiler::CompileOptions* compile_options) {}

void InspectorPageAgent::DidProduceCompilationCache(
    const ClassicScript& classic_script,
    v8::Local<v8::Script> script) {}

void InspectorPageAgent::FileChooserOpened(LocalFrame* frame,
                                           HTMLInputElement* element,
                                           bool multiple,
                                           bool* intercepted) {}

protocol::Response InspectorPageAgent::produceCompilationCache(
    std::unique_ptr<protocol::Array<protocol::Page::CompilationCacheParams>>
        scripts) {}

protocol::Response InspectorPageAgent::addCompilationCache(
    const String& url,
    const protocol::Binary& data) {}

protocol::Response InspectorPageAgent::clearCompilationCache() {}

protocol::Response InspectorPageAgent::waitForDebugger() {}

protocol::Response InspectorPageAgent::setInterceptFileChooserDialog(
    bool enabled) {}

protocol::Response InspectorPageAgent::generateTestReport(const String& message,
                                                          Maybe<String> group) {}

void InspectorPageAgent::Trace(Visitor* visitor) const {}

protocol::Response InspectorPageAgent::getOriginTrials(
    const String& frame_id,
    std::unique_ptr<protocol::Array<protocol::Page::OriginTrial>>*
        originTrials) {}

}  // namespace blink