2020-01-13 22:55:58 +00:00
|
|
|
// 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>
|
2020-02-13 00:39:12 +00:00
|
|
|
#include <string>
|
2020-01-13 22:55:58 +00:00
|
|
|
|
2020-09-16 22:15:01 +00:00
|
|
|
#include "electron/buildflags/buildflags.h"
|
2021-04-23 20:51:37 +00:00
|
|
|
#include "extensions/browser/guest_view/extensions_guest_view_manager_delegate.h"
|
2020-02-13 00:39:12 +00:00
|
|
|
#include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_guest_delegate.h"
|
2020-08-17 15:25:20 +00:00
|
|
|
#include "printing/buildflags/buildflags.h"
|
2021-04-23 20:51:37 +00:00
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2020-09-02 00:59:56 +00:00
|
|
|
#include "shell/browser/extensions/api/management/electron_management_api_delegate.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
#include "shell/browser/extensions/electron_messaging_delegate.h"
|
2021-04-23 20:51:37 +00:00
|
|
|
#include "v8/include/v8.h"
|
2020-01-13 22:55:58 +00:00
|
|
|
|
2020-10-17 01:30:46 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
|
|
|
#include "components/printing/browser/print_manager_utils.h"
|
|
|
|
#include "shell/browser/printing/print_preview_message_handler.h"
|
2021-05-19 23:15:47 +00:00
|
|
|
#include "shell/browser/printing/print_view_manager_electron.h"
|
2020-10-17 01:30:46 +00:00
|
|
|
#endif
|
|
|
|
|
2020-09-16 22:15:01 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2020-09-21 02:08:15 +00:00
|
|
|
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
|
2020-08-17 15:25:20 +00:00
|
|
|
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
|
|
|
|
#endif
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
namespace extensions {
|
|
|
|
|
2021-04-23 20:51:37 +00:00
|
|
|
class ElectronGuestViewManagerDelegate
|
|
|
|
: public ExtensionsGuestViewManagerDelegate {
|
|
|
|
public:
|
|
|
|
explicit ElectronGuestViewManagerDelegate(content::BrowserContext* context)
|
|
|
|
: ExtensionsGuestViewManagerDelegate(context) {}
|
|
|
|
~ElectronGuestViewManagerDelegate() override = default;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElectronGuestViewManagerDelegate);
|
|
|
|
};
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
class ElectronMimeHandlerViewGuestDelegate
|
|
|
|
: public MimeHandlerViewGuestDelegate {
|
|
|
|
public:
|
2021-06-04 04:16:13 +00:00
|
|
|
ElectronMimeHandlerViewGuestDelegate() = default;
|
|
|
|
~ElectronMimeHandlerViewGuestDelegate() override = default;
|
2020-02-13 00:39:12 +00:00
|
|
|
|
|
|
|
// MimeHandlerViewGuestDelegate.
|
|
|
|
bool HandleContextMenu(content::WebContents* web_contents,
|
|
|
|
const content::ContextMenuParams& params) override {
|
|
|
|
// TODO(nornagon): surface this event to JS
|
|
|
|
LOG(INFO) << "HCM";
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
void RecordLoadMetric(bool in_main_frame,
|
|
|
|
const std::string& mime_type) override {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(ElectronMimeHandlerViewGuestDelegate);
|
|
|
|
};
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
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 {
|
2020-10-17 01:30:46 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
|
|
|
electron::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
|
2021-05-19 23:15:47 +00:00
|
|
|
electron::PrintViewManagerElectron::CreateForWebContents(web_contents);
|
2020-10-17 01:30:46 +00:00
|
|
|
#endif
|
2020-08-17 15:25:20 +00:00
|
|
|
|
2020-09-16 22:15:01 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
2020-08-17 15:25:20 +00:00
|
|
|
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
|
|
|
web_contents, std::make_unique<ElectronPDFWebContentsHelperClient>());
|
|
|
|
#endif
|
2020-10-17 01:30:46 +00:00
|
|
|
|
|
|
|
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
|
|
|
web_contents);
|
2020-01-13 22:55:58 +00:00
|
|
|
}
|
|
|
|
|
2020-09-02 00:59:56 +00:00
|
|
|
ManagementAPIDelegate*
|
|
|
|
ElectronExtensionsAPIClient::CreateManagementAPIDelegate() const {
|
|
|
|
return new ElectronManagementAPIDelegate;
|
|
|
|
}
|
|
|
|
|
2020-02-13 00:39:12 +00:00
|
|
|
std::unique_ptr<MimeHandlerViewGuestDelegate>
|
|
|
|
ElectronExtensionsAPIClient::CreateMimeHandlerViewGuestDelegate(
|
|
|
|
MimeHandlerViewGuest* guest) const {
|
|
|
|
return std::make_unique<ElectronMimeHandlerViewGuestDelegate>();
|
|
|
|
}
|
|
|
|
|
2021-04-23 20:51:37 +00:00
|
|
|
std::unique_ptr<guest_view::GuestViewManagerDelegate>
|
|
|
|
ElectronExtensionsAPIClient::CreateGuestViewManagerDelegate(
|
|
|
|
content::BrowserContext* context) const {
|
|
|
|
return std::make_unique<ElectronGuestViewManagerDelegate>(context);
|
|
|
|
}
|
|
|
|
|
2020-01-13 22:55:58 +00:00
|
|
|
} // namespace extensions
|