electron/shell/browser/extensions/electron_extensions_api_client.cc
Charles Kerr e70ce89235
chore: more iwyu (#43063)
* chore: iwyu shell/browser/electron_pdf_document_helper_client.h

* chore: iwyu shell/browser/hid/electron_hid_delegate.h

* chore: iwyu content/public/browser/web_contents.h

* chore: iwyu shell/browser/usb/electron_usb_delegate.h

* chore: iwyu shell/browser/browser_observer.h

* chore: iwyu shell/browser/bluetooth/electron_bluetooth_delegate.h

* chore: iwyu shell/browser/serial/electron_serial_delegate.h

* chore: iwyu shell/browser/api/frame_subscriber.h

* chore: iwyu mojo/public/cpp/bindings/

* chore: iwyu components/

* chore: iwyu extensions/

* chore: iwyu shell/common/gin_helper/

* chore: iwyu v8/

* chore: iwyu base/containers/linked_list.h

* chore: iwyu shell/browser/native_window.h

* chore: iwyu shell/browser/api/electron_api_base_window.h

* chore: iwyu shell/common/node_includes.h

* chore: iwyu gin/handle.h

* chore: iwyu base/functional/callback.h

* chore: iwyu ui/gfx/

* chore: iwyu content/public/browser/render_frame_host.h

* fix: mac

* fix: mac

* fix: win

* chore: iwyu base/files/file_path.h

* chore: iwyu base/unguessable_token.h

* chore: iwyu ui/display/screen.h

* chore: iwyu chrome/browser/predictors/preconnect_manager.h

* chore: iwyu base/observer_list_types.h

* chore: iwyu content/public/browser/web_contents.h

* chore: iwyu chrome/browser/devtools/devtools_eye_dropper.h

* chore: iwyu shell/browser/ui/inspectable_web_contents.h

* chore: iwyu content/public/browser/keyboard_event_processing_result.h

* chore: iwyu net/cookies/canonical_cookie.h

* chore: iwyu net/base/address_list.h

* chore: iwyu net/cert/x509_certificate.h

* chore: iwyu net/cookies/cookie_change_dispatcher.h

* chore: iwyu net/dns/public/host_resolver_results.h

* fix: mac

* Revert "chore: iwyu net/cert/x509_certificate.h"

This reverts commit 002896f71146e90f1e29e090a1d6eede48cee11e.
2024-07-29 12:42:57 -05:00

119 lines
4.2 KiB
C++

// Copyright (c) 2019 Slack Technologies, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/extensions/electron_extensions_api_client.h"
#include <memory>
#include <string>
#include "electron/buildflags/buildflags.h"
#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h"
#include "printing/buildflags/buildflags.h"
#include "shell/browser/api/electron_api_web_contents.h"
#include "shell/browser/extensions/api/management/electron_management_api_delegate.h"
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
#include "shell/browser/extensions/electron_messaging_delegate.h"
#include "v8/include/v8.h"
#if BUILDFLAG(ENABLE_PRINTING)
#include "components/printing/browser/print_manager_utils.h"
#include "shell/browser/printing/print_view_manager_electron.h"
#endif
#if BUILDFLAG(ENABLE_PDF_VIEWER)
#include "components/pdf/browser/pdf_document_helper.h" // nogncheck
#endif
namespace extensions {
class ElectronGuestViewManagerDelegate
: public ExtensionsGuestViewManagerDelegate {
public:
ElectronGuestViewManagerDelegate() : ExtensionsGuestViewManagerDelegate() {}
~ElectronGuestViewManagerDelegate() override = default;
// disable copy
ElectronGuestViewManagerDelegate(const ElectronGuestViewManagerDelegate&) =
delete;
ElectronGuestViewManagerDelegate& operator=(
const ElectronGuestViewManagerDelegate&) = delete;
// GuestViewManagerDelegate:
void OnGuestAdded(content::WebContents* guest_web_contents) const override {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
v8::HandleScope scope(isolate);
electron::api::WebContents::FromOrCreate(isolate, guest_web_contents);
}
};
class ElectronMimeHandlerViewGuestDelegate
: public MimeHandlerViewGuestDelegate {
public:
ElectronMimeHandlerViewGuestDelegate() = default;
~ElectronMimeHandlerViewGuestDelegate() override = default;
// disable copy
ElectronMimeHandlerViewGuestDelegate(
const ElectronMimeHandlerViewGuestDelegate&) = delete;
ElectronMimeHandlerViewGuestDelegate& operator=(
const ElectronMimeHandlerViewGuestDelegate&) = delete;
// MimeHandlerViewGuestDelegate.
bool HandleContextMenu(content::RenderFrameHost& render_frame_host,
const content::ContextMenuParams& params) override {
auto* web_contents =
content::WebContents::FromRenderFrameHost(&render_frame_host);
if (!web_contents)
return true;
electron::api::WebContents* api_web_contents =
electron::api::WebContents::From(
web_contents->GetOutermostWebContents());
if (api_web_contents)
api_web_contents->HandleContextMenu(render_frame_host, params);
return true;
}
void RecordLoadMetric(bool in_main_frame,
const std::string& mime_type,
content::BrowserContext* browser_context) override {}
};
ElectronExtensionsAPIClient::ElectronExtensionsAPIClient() = default;
ElectronExtensionsAPIClient::~ElectronExtensionsAPIClient() = default;
MessagingDelegate* ElectronExtensionsAPIClient::GetMessagingDelegate() {
if (!messaging_delegate_)
messaging_delegate_ = std::make_unique<ElectronMessagingDelegate>();
return messaging_delegate_.get();
}
void ElectronExtensionsAPIClient::AttachWebContentsHelpers(
content::WebContents* web_contents) const {
#if BUILDFLAG(ENABLE_PRINTING)
electron::PrintViewManagerElectron::CreateForWebContents(web_contents);
#endif
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
web_contents);
}
ManagementAPIDelegate*
ElectronExtensionsAPIClient::CreateManagementAPIDelegate() const {
return new ElectronManagementAPIDelegate;
}
std::unique_ptr<MimeHandlerViewGuestDelegate>
ElectronExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
MimeHandlerViewGuest* guest) const {
return std::make_unique<ElectronMimeHandlerViewGuestDelegate>();
}
std::unique_ptr<guest_view::GuestViewManagerDelegate>
ElectronExtensionsAPIClient::CreateGuestViewManagerDelegate() const {
return std::make_unique<ElectronGuestViewManagerDelegate>();
}
} // namespace extensions