aa23198ad8
* chore: in shell/renderer/renderer_client_base.h, remove include media/base/key_systems_support_registration.h
last use removed in c670e38b
(##41610)
* chore: iwyu electron/fuses.h
* chore: iwyu media/base/video_frame.h
* chore: iwyu base/functional/callback.h
* chore: iwyu base/task/cancelable_task_tracker.h
* chore: iwyu shell/browser/draggable_region_provider.h
* chore: iwyu shell/browser/ui/inspectable_web_contents_view.h
* chore: iwyu ui/aura/window.h
* chore: iwyu ui/base/win/shell.h
* chore: iwyu ui/display/win/screen_win.h
* chore: iwyu ui/gfx/geometry/insets.h
* chore: iwyu ui/display/display.h
* chore: iwyu ui/gfx/geometry/skia_conversions.h
* chore: iwyu ui/gfx/geometry/rect_conversions.h
* chore: iwyu ui/gfx/geometry/point.h
* chore: iwyu ui/gfx/scoped_canvas.h
* chore: iwyu ui/gfx/image/image.h
* chore: iwyu ui/accessibility/ax_node_data.h
* chore: iwyu ui/views/animation/ink_drop_highlight.h
* chore: iwyu ui/gfx/font_list.h
* chore: iwyu ui/linux/nav_button_provider.h
* chore: iwyu shell/browser/ui/views/frameless_view.h
* chore: iwyu services/metrics/public/cpp/ukm_source_id.h
* chore: iwyu net/http/http_util.h
* chore: iwyu net/base/mime_util.h
* chore: iwyu content/public/common/content_client.h
* chore: iwyu <list>
* chore: iwyu <optional>
* chore: iwyu <memory>
* chore: iwyu base/files/file_path.h
* chore: iwyu ui/base/cursor/cursor.h
* chore: iwyu build/build_config.h
* chore: iwyu content/public/browser/web_contents.h
* chore: iwyu shell/browser/hid/hid_chooser_context.h
* chore: iwyu shell/common/platform_util.h
* chore: iwyu base/task/single_thread_task_runner.h
* chore: iwyu content/browser/renderer_host/render_widget_host_impl.h
* chore: iwyu content/public/browser/render_widget_host.h
* chore: iwyu shell/browser/electron_browser_context.h
* chore: iwyu content/public/browser/web_contents_observer.h
* chore: iwyu content/public/browser/render_frame_host.h
* chore: iwyu content/public/browser/media_stream_request.h
* chore: iwyu chrome/common/chrome_paths.h
* chore: iwyu chrome/browser/icon_manager.h
* chore: iwyu printing/print_settings.h
* chore: iwyu renderer/pepper_helper.h
* chore: iwyu shell/browser/api/process_metric.h
* chore: iwyu shell/browser/electron_browser_client.h
* chore: iwyu shell/browser/electron_browser_context.h
* chore: iwyu shell/browser/api/electron_api_session.h
* chore: iwyu shell/browser/api/electron_api_app.h
* chore: iwyu shell/browser/ui/views/client_frame_view_linux.h
* chore: iwyu shell/browser/native_window_views.h
* chore: iwyu base/win/windows_version.h
* chore: iwyu shell/common/electron_paths.h
* chore: iwyu content/public/common/content_switches.h
* chore: iwyu third_party/skia/include/core/SkRRect.h
* chore: iwyu third_party/skia/include/core/SkBitmap.h
* chore: iwyu third_party/skia
* chore: iwyu shell/browser/osr/osr_host_display_client.h
* chore: iwyu shell/browser/login_handler.h
* chore: iwyu shell/browser/javascript_environment.h
* chore: iwyu shell/browser/event_emitter_mixin.h
* fix: mac
* fix: mac
* chore: iwyu base/nix/xdg_util.h
* fix: win
* fix: win
* fix: win
* fix: win
138 lines
4.8 KiB
C++
138 lines
4.8 KiB
C++
// Copyright 2017 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include "shell/browser/extensions/electron_messaging_delegate.h"
|
|
|
|
#include <memory>
|
|
#include <utility>
|
|
|
|
#include "base/functional/callback.h"
|
|
#include "base/values.h"
|
|
#include "components/prefs/pref_service.h"
|
|
#include "content/public/browser/browser_context.h"
|
|
#include "content/public/browser/browser_thread.h"
|
|
#include "content/public/browser/render_frame_host.h"
|
|
#include "content/public/browser/web_contents.h"
|
|
#include "electron/shell/common/extensions/api/tabs.h"
|
|
#include "extensions/browser/api/messaging/extension_message_port.h"
|
|
#include "extensions/browser/api/messaging/native_message_host.h"
|
|
#include "extensions/browser/extension_api_frame_id_map.h"
|
|
#include "extensions/browser/pref_names.h"
|
|
#include "extensions/common/api/messaging/port_id.h"
|
|
#include "extensions/common/extension.h"
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
|
#include "ui/gfx/native_widget_types.h"
|
|
#include "url/gurl.h"
|
|
|
|
namespace extensions {
|
|
|
|
ElectronMessagingDelegate::ElectronMessagingDelegate() = default;
|
|
ElectronMessagingDelegate::~ElectronMessagingDelegate() = default;
|
|
|
|
MessagingDelegate::PolicyPermission
|
|
ElectronMessagingDelegate::IsNativeMessagingHostAllowed(
|
|
content::BrowserContext* browser_context,
|
|
const std::string& native_host_name) {
|
|
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
|
return PolicyPermission::DISALLOW;
|
|
}
|
|
|
|
std::optional<base::Value::Dict> ElectronMessagingDelegate::MaybeGetTabInfo(
|
|
content::WebContents* web_contents) {
|
|
if (web_contents) {
|
|
auto* api_contents = electron::api::WebContents::From(web_contents);
|
|
if (api_contents) {
|
|
api::tabs::Tab tab;
|
|
tab.id = api_contents->ID();
|
|
tab.url = api_contents->GetURL().spec();
|
|
tab.title = base::UTF16ToUTF8(api_contents->GetTitle());
|
|
tab.audible = api_contents->IsCurrentlyAudible();
|
|
return tab.ToValue();
|
|
}
|
|
}
|
|
return std::nullopt;
|
|
}
|
|
|
|
content::WebContents* ElectronMessagingDelegate::GetWebContentsByTabId(
|
|
content::BrowserContext* browser_context,
|
|
int tab_id) {
|
|
auto* contents = electron::api::WebContents::FromID(tab_id);
|
|
if (!contents) {
|
|
return nullptr;
|
|
}
|
|
return contents->web_contents();
|
|
}
|
|
|
|
std::unique_ptr<MessagePort> ElectronMessagingDelegate::CreateReceiverForTab(
|
|
base::WeakPtr<MessagePort::ChannelDelegate> channel_delegate,
|
|
const std::string& extension_id,
|
|
const PortId& receiver_port_id,
|
|
content::WebContents* receiver_contents,
|
|
int receiver_frame_id,
|
|
const std::string& receiver_document_id) {
|
|
// Frame ID -1 is every frame in the tab.
|
|
bool include_child_frames =
|
|
receiver_frame_id == -1 && receiver_document_id.empty();
|
|
|
|
content::RenderFrameHost* receiver_rfh = nullptr;
|
|
if (include_child_frames) {
|
|
// The target is the active outermost main frame of the WebContents.
|
|
receiver_rfh = receiver_contents->GetPrimaryMainFrame();
|
|
} else if (!receiver_document_id.empty()) {
|
|
ExtensionApiFrameIdMap::DocumentId document_id =
|
|
ExtensionApiFrameIdMap::DocumentIdFromString(receiver_document_id);
|
|
|
|
// Return early for invalid documentIds.
|
|
if (!document_id)
|
|
return nullptr;
|
|
|
|
receiver_rfh =
|
|
ExtensionApiFrameIdMap::Get()->GetRenderFrameHostByDocumentId(
|
|
document_id);
|
|
|
|
// If both |document_id| and |receiver_frame_id| are provided they
|
|
// should find the same RenderFrameHost, if not return early.
|
|
if (receiver_frame_id != -1 &&
|
|
ExtensionApiFrameIdMap::GetRenderFrameHostById(
|
|
receiver_contents, receiver_frame_id) != receiver_rfh) {
|
|
return nullptr;
|
|
}
|
|
} else {
|
|
DCHECK_GT(receiver_frame_id, -1);
|
|
receiver_rfh = ExtensionApiFrameIdMap::GetRenderFrameHostById(
|
|
receiver_contents, receiver_frame_id);
|
|
}
|
|
if (!receiver_rfh)
|
|
return nullptr;
|
|
|
|
return std::make_unique<ExtensionMessagePort>(
|
|
channel_delegate, receiver_port_id, extension_id, receiver_rfh,
|
|
include_child_frames);
|
|
}
|
|
|
|
std::unique_ptr<MessagePort>
|
|
ElectronMessagingDelegate::CreateReceiverForNativeApp(
|
|
content::BrowserContext* browser_context,
|
|
base::WeakPtr<MessagePort::ChannelDelegate> channel_delegate,
|
|
content::RenderFrameHost* source,
|
|
const std::string& extension_id,
|
|
const PortId& receiver_port_id,
|
|
const std::string& native_app_name,
|
|
bool allow_user_level,
|
|
std::string* error_out) {
|
|
return nullptr;
|
|
}
|
|
|
|
void ElectronMessagingDelegate::QueryIncognitoConnectability(
|
|
content::BrowserContext* context,
|
|
const Extension* target_extension,
|
|
content::WebContents* source_contents,
|
|
const GURL& source_url,
|
|
base::OnceCallback<void(bool)> callback) {
|
|
DCHECK(context->IsOffTheRecord());
|
|
std::move(callback).Run(false);
|
|
}
|
|
|
|
} // namespace extensions
|