chromium/extensions/renderer/extension_frame_helper.cc

// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "extensions/renderer/extension_frame_helper.h"

#include <set>

#include "base/feature_list.h"
#include "base/containers/map_util.h"
#include "base/metrics/histogram_macros.h"
#include "base/ranges/algorithm.h"
#include "base/strings/string_util.h"
#include "base/timer/elapsed_timer.h"
#include "content/public/renderer/render_frame.h"
#include "extensions/common/api/messaging/message.h"
#include "extensions/common/api/messaging/port_id.h"
#include "extensions/common/constants.h"
#include "extensions/common/extension_features.h"
#include "extensions/common/extension_id.h"
#include "extensions/common/manifest_handlers/background_info.h"
#include "extensions/renderer/api/messaging/native_renderer_messaging_service.h"
#include "extensions/renderer/console.h"
#include "extensions/renderer/dispatcher.h"
#include "extensions/renderer/ipc_message_sender.h"
#include "extensions/renderer/native_extension_bindings_system.h"
#include "extensions/renderer/script_context.h"
#include "extensions/renderer/script_context_set.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_registry.h"
#include "third_party/blink/public/platform/scheduler/web_agent_group_scheduler.h"
#include "third_party/blink/public/platform/web_isolated_world_info.h"
#include "third_party/blink/public/platform/web_security_origin.h"
#include "third_party/blink/public/web/web_console_message.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_document_loader.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/public/web/web_settings.h"
#include "third_party/blink/public/web/web_view.h"
#include "v8/include/v8-container.h"
#include "v8/include/v8-context.h"
#include "v8/include/v8-isolate.h"
#include "v8/include/v8-object.h"
#include "v8/include/v8-primitive.h"

namespace extensions {

namespace {

base::LazyInstance<std::set<const ExtensionFrameHelper*>>::DestructorAtExit
    g_frame_helpers =;

// Returns true if the render frame corresponding with |frame_helper| matches
// the given criteria.
//
// We deliberately do not access any methods that require a v8::Context or
// ScriptContext.  See also comment below.
bool RenderFrameMatches(const ExtensionFrameHelper* frame_helper,
                        mojom::ViewType match_view_type,
                        int match_window_id,
                        int match_tab_id,
                        const ExtensionId& match_extension_id) {}

// Runs every callback in |callbacks_to_be_run_and_cleared| while |frame_helper|
// is valid, and clears |callbacks_to_be_run_and_cleared|.
void RunCallbacksWhileFrameIsValid(
    base::WeakPtr<ExtensionFrameHelper> frame_helper,
    std::vector<base::OnceClosure>* callbacks_to_be_run_and_cleared) {}

enum class PortType {};

// Returns an extension hosted in the |render_frame| (or nullptr if the frame
// doesn't host an extension).
const Extension* GetExtensionFromFrame(content::RenderFrame* render_frame) {}

}  // namespace

ExtensionFrameHelper::ExtensionFrameHelper(content::RenderFrame* render_frame,
                                           Dispatcher* extension_dispatcher)
    :{}

ExtensionFrameHelper::~ExtensionFrameHelper() {}

// static
std::vector<content::RenderFrame*> ExtensionFrameHelper::GetExtensionFrames(
    const ExtensionId& extension_id,
    int browser_window_id,
    int tab_id,
    mojom::ViewType view_type) {}

// static
v8::Local<v8::Array> ExtensionFrameHelper::GetV8MainFrames(
    v8::Local<v8::Context> context,
    const ExtensionId& extension_id,
    int browser_window_id,
    int tab_id,
    mojom::ViewType view_type) {}

// static
content::RenderFrame* ExtensionFrameHelper::GetBackgroundPageFrame(
    const ExtensionId& extension_id) {}

v8::Local<v8::Value> ExtensionFrameHelper::GetV8BackgroundPageMainFrame(
    v8::Isolate* isolate,
    const ExtensionId& extension_id) {}

// static
content::RenderFrame* ExtensionFrameHelper::FindFrame(
    content::RenderFrame* relative_to_frame,
    const std::string& name) {}

// static
bool ExtensionFrameHelper::IsContextForEventPage(const ScriptContext* context) {}

void ExtensionFrameHelper::BindLocalFrame(
    mojo::PendingAssociatedReceiver<mojom::LocalFrame> pending_receiver) {}

void ExtensionFrameHelper::DidCreateDocumentElement() {}

void ExtensionFrameHelper::DidCreateNewDocument() {}

void ExtensionFrameHelper::RunScriptsAtDocumentStart() {}

void ExtensionFrameHelper::RunScriptsAtDocumentEnd() {}

void ExtensionFrameHelper::RunScriptsAtDocumentIdle() {}

void ExtensionFrameHelper::ScheduleAtDocumentStart(base::OnceClosure callback) {}

void ExtensionFrameHelper::ScheduleAtDocumentEnd(base::OnceClosure callback) {}

void ExtensionFrameHelper::ScheduleAtDocumentIdle(base::OnceClosure callback) {}

const std::set<std::optional<std::string>>*
ExtensionFrameHelper::GetActiveUserScriptWorlds(
      const ExtensionId& extension_id) {}

void ExtensionFrameHelper::AddActiveUserScriptWorld(
    const ExtensionId& extension_id,
    const std::optional<std::string>& world_id) {}

mojom::LocalFrameHost* ExtensionFrameHelper::GetLocalFrameHost() {}

mojom::RendererHost* ExtensionFrameHelper::GetRendererHost() {}

mojom::EventRouter* ExtensionFrameHelper::GetEventRouter() {}

mojom::RendererAutomationRegistry*
ExtensionFrameHelper::GetRendererAutomationRegistry() {}

void ExtensionFrameHelper::ReadyToCommitNavigation(
    blink::WebDocumentLoader* document_loader) {}

void ExtensionFrameHelper::DidCommitProvisionalLoad(
    ui::PageTransition transition) {}

void ExtensionFrameHelper::DidCreateScriptContext(
    v8::Local<v8::Context> context,
    int32_t world_id) {}

void ExtensionFrameHelper::WillReleaseScriptContext(
    v8::Local<v8::Context> context,
    int32_t world_id) {}

void ExtensionFrameHelper::SetTabId(int32_t tab_id) {}

void ExtensionFrameHelper::NotifyRenderViewType(mojom::ViewType type) {}

void ExtensionFrameHelper::MessageInvoke(const ExtensionId& extension_id,
                                         const std::string& module_name,
                                         const std::string& function_name,
                                         base::Value::List args) {}

void ExtensionFrameHelper::ExecuteCode(mojom::ExecuteCodeParamsPtr param,
                                       ExecuteCodeCallback callback) {}

void ExtensionFrameHelper::SetFrameName(const std::string& name) {}

void ExtensionFrameHelper::AppWindowClosed(bool send_onclosed) {}

void ExtensionFrameHelper::SetSpatialNavigationEnabled(bool enabled) {}

void ExtensionFrameHelper::ExecuteDeclarativeScript(
    int32_t tab_id,
    const ExtensionId& extension_id,
    const std::string& script_id,
    const GURL& url) {}

void ExtensionFrameHelper::UpdateBrowserWindowId(int32_t window_id) {}

void ExtensionFrameHelper::DispatchOnConnect(
    const PortId& port_id,
    extensions::mojom::ChannelType channel_type,
    const std::string& channel_name,
    extensions::mojom::TabConnectionInfoPtr tab_info,
    extensions::mojom::ExternalConnectionInfoPtr external_connection_info,
    mojo::PendingAssociatedReceiver<extensions::mojom::MessagePort> port,
    mojo::PendingAssociatedRemote<extensions::mojom::MessagePortHost> port_host,
    DispatchOnConnectCallback callback) {}

void ExtensionFrameHelper::NotifyDidCreateScriptContext(int32_t world_id) {}

void ExtensionFrameHelper::OnDestruct() {}

void ExtensionFrameHelper::DidClearWindowObject() {}

content::RenderFrame* ExtensionFrameHelper::FindFrameFromFrameTokenString(
    v8::Isolate* isolate,
    v8::Local<v8::Value> v8_string) {}

}  // namespace extensions