2017-08-04 00:55:19 +02:00
|
|
|
// Copyright 2017 the Chromium Embedded Framework Authors. Portions copyright
|
|
|
|
// 2013 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 "libcef/browser/extensions/extension_view_host.h"
|
|
|
|
|
|
|
|
#include "libcef/browser/browser_platform_delegate.h"
|
|
|
|
#include "libcef/browser/extensions/extension_host_delegate.h"
|
|
|
|
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2021-10-19 00:17:16 +02:00
|
|
|
#include "extensions/browser/process_util.h"
|
2020-03-04 01:29:39 +01:00
|
|
|
#include "third_party/blink/public/common/input/web_gesture_event.h"
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
using content::NativeWebKeyboardEvent;
|
|
|
|
using content::OpenURLParams;
|
|
|
|
using content::WebContents;
|
|
|
|
using content::WebContentsObserver;
|
|
|
|
|
|
|
|
namespace extensions {
|
|
|
|
|
2020-09-22 21:54:02 +02:00
|
|
|
CefExtensionViewHost::CefExtensionViewHost(AlloyBrowserHostImpl* browser,
|
2020-07-03 22:13:27 +02:00
|
|
|
const Extension* extension,
|
|
|
|
content::WebContents* host_contents,
|
|
|
|
const GURL& url,
|
2021-04-21 00:52:34 +02:00
|
|
|
mojom::ViewType host_type)
|
2017-08-04 00:55:19 +02:00
|
|
|
: ExtensionHost(new CefExtensionHostDelegate(browser),
|
|
|
|
extension,
|
2020-07-03 22:13:27 +02:00
|
|
|
host_contents->GetBrowserContext(),
|
2017-08-04 00:55:19 +02:00
|
|
|
host_contents,
|
|
|
|
url,
|
|
|
|
host_type) {
|
2023-11-21 20:17:55 +01:00
|
|
|
// Only used for popups.
|
|
|
|
DCHECK(host_type == mojom::ViewType::kExtensionPopup);
|
2017-08-04 00:55:19 +02:00
|
|
|
}
|
|
|
|
|
2024-01-20 23:48:57 +01:00
|
|
|
CefExtensionViewHost::~CefExtensionViewHost() = default;
|
2017-08-04 00:55:19 +02:00
|
|
|
|
|
|
|
void CefExtensionViewHost::OnDidStopFirstLoad() {
|
|
|
|
// Nothing to do here, but don't call the base class method.
|
|
|
|
}
|
|
|
|
|
|
|
|
void CefExtensionViewHost::LoadInitialURL() {
|
2021-10-19 00:17:16 +02:00
|
|
|
if (process_util::GetPersistentBackgroundPageState(*extension(),
|
|
|
|
browser_context()) ==
|
|
|
|
process_util::PersistentBackgroundPageState::kNotReady) {
|
2017-08-04 00:55:19 +02:00
|
|
|
// Make sure the background page loads before any others.
|
2021-12-16 23:35:54 +01:00
|
|
|
host_registry_observation_.Observe(
|
|
|
|
ExtensionHostRegistry::Get(browser_context()));
|
2017-08-04 00:55:19 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ExtensionHost::LoadInitialURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionViewHost::IsBackgroundPage() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-23 18:40:13 +02:00
|
|
|
bool CefExtensionViewHost::ShouldAllowRendererInitiatedCrossProcessNavigation(
|
2017-08-04 00:55:19 +02:00
|
|
|
bool is_main_frame_navigation) {
|
|
|
|
// Block navigations that cause the main frame to navigate to non-extension
|
|
|
|
// content (i.e. to web content).
|
|
|
|
return !is_main_frame_navigation;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CefExtensionViewHost::PreHandleGestureEvent(
|
|
|
|
content::WebContents* source,
|
|
|
|
const blink::WebGestureEvent& event) {
|
|
|
|
// Disable pinch zooming.
|
|
|
|
return blink::WebInputEvent::IsPinchGestureEventType(event.GetType());
|
|
|
|
}
|
|
|
|
|
|
|
|
WebContents* CefExtensionViewHost::GetVisibleWebContents() const {
|
2023-01-02 23:59:03 +01:00
|
|
|
if (extension_host_type() == mojom::ViewType::kExtensionPopup) {
|
2017-08-04 00:55:19 +02:00
|
|
|
return host_contents();
|
2023-01-02 23:59:03 +01:00
|
|
|
}
|
2017-08-04 00:55:19 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2021-12-16 23:35:54 +01:00
|
|
|
void CefExtensionViewHost::OnExtensionHostDocumentElementAvailable(
|
|
|
|
content::BrowserContext* host_browser_context,
|
|
|
|
ExtensionHost* extension_host) {
|
|
|
|
DCHECK(extension_host->extension());
|
|
|
|
if (host_browser_context != browser_context() ||
|
|
|
|
extension_host->extension() != extension() ||
|
|
|
|
extension_host->extension_host_type() !=
|
|
|
|
mojom::ViewType::kExtensionBackgroundPage) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-10-19 00:17:16 +02:00
|
|
|
DCHECK_EQ(process_util::PersistentBackgroundPageState::kReady,
|
|
|
|
process_util::GetPersistentBackgroundPageState(*extension(),
|
|
|
|
browser_context()));
|
2021-12-16 23:35:54 +01:00
|
|
|
// We only needed to wait for the background page to load, so stop observing.
|
|
|
|
host_registry_observation_.Reset();
|
2017-08-04 00:55:19 +02:00
|
|
|
LoadInitialURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace extensions
|