mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-23 23:47:43 +01:00
chrome: Add support for reparenting of popups with Views (see issue #2969)
This commit is contained in:
parent
4960970dbd
commit
25701cfa6f
@ -51,8 +51,13 @@ struct CefBrowserCreateParams {
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
// The BrowserView that will own a Views-hosted browser. Will be nullptr for
|
||||
// popup browsers (the BrowserView will be created later in that case).
|
||||
// popup browsers.
|
||||
CefRefPtr<CefBrowserView> browser_view;
|
||||
|
||||
// True if this browser is a popup and has a Views-hosted opener, in which
|
||||
// case the BrowserView for this browser will be created later (from
|
||||
// PopupWebContentsCreated).
|
||||
bool popup_with_views_hosted_opener = false;
|
||||
#endif
|
||||
|
||||
// Client implementation. May be nullptr.
|
||||
|
@ -181,8 +181,11 @@ bool CefBrowserInfoManager::CanCreateWindow(
|
||||
if (allow) {
|
||||
CefBrowserCreateParams create_params;
|
||||
|
||||
if (!browser->HasView())
|
||||
if (browser->HasView()) {
|
||||
create_params.popup_with_views_hosted_opener = true;
|
||||
} else {
|
||||
create_params.window_info = std::move(window_info);
|
||||
}
|
||||
|
||||
create_params.settings = pending_popup->settings;
|
||||
create_params.client = pending_popup->client;
|
||||
|
@ -84,7 +84,8 @@ std::unique_ptr<CefBrowserPlatformDelegate> CefBrowserPlatformDelegate::Create(
|
||||
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate =
|
||||
CreateNativeDelegate(CefWindowInfo(), background_color);
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
if (create_params.browser_view) {
|
||||
if (create_params.browser_view ||
|
||||
create_params.popup_with_views_hosted_opener) {
|
||||
return std::make_unique<CefBrowserPlatformDelegateChromeViews>(
|
||||
std::move(native_delegate),
|
||||
static_cast<CefBrowserViewImpl*>(create_params.browser_view.get()));
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include "chrome/browser/profiles/profile.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_tabstrip.h"
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
|
||||
@ -65,7 +66,7 @@ void ChromeBrowserDelegate::SetAsDelegate(content::WebContents* web_contents,
|
||||
create_params_.request_context);
|
||||
|
||||
CreateBrowser(web_contents, create_params_.settings, create_params_.client,
|
||||
std::move(platform_delegate), browser_info,
|
||||
std::move(platform_delegate), browser_info, /*opener=*/nullptr,
|
||||
request_context_impl);
|
||||
}
|
||||
|
||||
@ -103,7 +104,28 @@ void ChromeBrowserDelegate::WebContentsCreated(
|
||||
// We don't officially own |new_contents| until AddNewContents() is called.
|
||||
// However, we need to install observers/delegates here.
|
||||
CreateBrowser(new_contents, settings, client, std::move(platform_delegate),
|
||||
browser_info, request_context_impl);
|
||||
browser_info, opener, request_context_impl);
|
||||
}
|
||||
|
||||
void ChromeBrowserDelegate::AddNewContents(
|
||||
content::WebContents* source_contents,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
const GURL& target_url,
|
||||
WindowOpenDisposition disposition,
|
||||
const gfx::Rect& initial_rect,
|
||||
bool user_gesture,
|
||||
bool* was_blocked) {
|
||||
auto new_browser =
|
||||
ChromeBrowserHostImpl::GetBrowserForContents(new_contents.get());
|
||||
if (new_browser) {
|
||||
// Create a new Browser and give it ownership of the WebContents.
|
||||
new_browser->AddNewContents(std::move(new_contents));
|
||||
return;
|
||||
}
|
||||
|
||||
// Fall back to default behavior from Browser::AddNewContents.
|
||||
chrome::AddWebContents(browser_, source_contents, std::move(new_contents),
|
||||
target_url, disposition, initial_rect);
|
||||
}
|
||||
|
||||
content::WebContents* ChromeBrowserDelegate::OpenURLFromTab(
|
||||
@ -195,6 +217,7 @@ void ChromeBrowserDelegate::CreateBrowser(
|
||||
CefRefPtr<CefClient> client,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
CefRefPtr<ChromeBrowserHostImpl> opener,
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl) {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(web_contents);
|
||||
@ -202,6 +225,9 @@ void ChromeBrowserDelegate::CreateBrowser(
|
||||
DCHECK(browser_info);
|
||||
DCHECK(request_context_impl);
|
||||
|
||||
// If |opener| is non-nullptr it must be a popup window.
|
||||
DCHECK(!opener.get() || browser_info->is_popup());
|
||||
|
||||
if (!client) {
|
||||
if (auto app = CefAppManager::Get()->GetApplication()) {
|
||||
if (auto bph = app->GetBrowserProcessHandler()) {
|
||||
@ -226,7 +252,12 @@ void ChromeBrowserDelegate::CreateBrowser(
|
||||
CefRefPtr<ChromeBrowserHostImpl> browser_host =
|
||||
new ChromeBrowserHostImpl(settings, client, std::move(platform_delegate),
|
||||
browser_info, request_context_impl);
|
||||
browser_host->Attach(browser_, web_contents);
|
||||
browser_host->Attach(web_contents, opener);
|
||||
|
||||
// The Chrome browser for a popup won't be created until AddNewContents().
|
||||
if (!opener) {
|
||||
browser_host->SetBrowser(browser_);
|
||||
}
|
||||
}
|
||||
|
||||
CefBrowserContentsDelegate* ChromeBrowserDelegate::GetDelegateForWebContents(
|
||||
|
@ -55,6 +55,13 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
|
||||
const std::string& frame_name,
|
||||
const GURL& target_url,
|
||||
content::WebContents* new_contents) override;
|
||||
void AddNewContents(content::WebContents* source_contents,
|
||||
std::unique_ptr<content::WebContents> new_contents,
|
||||
const GURL& target_url,
|
||||
WindowOpenDisposition disposition,
|
||||
const gfx::Rect& initial_rect,
|
||||
bool user_gesture,
|
||||
bool* was_blocked) override;
|
||||
content::WebContents* OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) override;
|
||||
@ -88,6 +95,7 @@ class ChromeBrowserDelegate : public cef::BrowserDelegate {
|
||||
CefRefPtr<CefClient> client,
|
||||
std::unique_ptr<CefBrowserPlatformDelegate> platform_delegate,
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
CefRefPtr<ChromeBrowserHostImpl> opener,
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl);
|
||||
|
||||
CefBrowserContentsDelegate* GetDelegateForWebContents(
|
||||
|
@ -32,60 +32,7 @@
|
||||
// static
|
||||
CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::Create(
|
||||
const CefBrowserCreateParams& params) {
|
||||
// Get or create the request context and profile.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
||||
CefRequestContextImpl::GetOrCreateForRequestContext(
|
||||
params.request_context);
|
||||
CHECK(request_context_impl);
|
||||
auto cef_browser_context = request_context_impl->GetBrowserContext();
|
||||
CHECK(cef_browser_context);
|
||||
auto profile = cef_browser_context->AsProfile();
|
||||
|
||||
Browser::CreateParams chrome_params =
|
||||
Browser::CreateParams(profile, /*user_gesture=*/false);
|
||||
|
||||
// Pass |params| to cef::BrowserDelegate::Create from the Browser constructor.
|
||||
chrome_params.cef_params = base::MakeRefCounted<DelegateCreateParams>(params);
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
// Configure Browser creation to use the existing Views-based
|
||||
// Widget/BrowserFrame (ChromeBrowserFrame) and BrowserView/BrowserWindow
|
||||
// (ChromeBrowserView). See views/chrome_browser_frame.h for related
|
||||
// documentation.
|
||||
ChromeBrowserView* chrome_browser_view = nullptr;
|
||||
if (params.browser_view) {
|
||||
// Don't show most controls.
|
||||
chrome_params.type = Browser::TYPE_POPUP;
|
||||
// Don't show title bar or address.
|
||||
chrome_params.trusted_source = true;
|
||||
|
||||
auto view_impl =
|
||||
static_cast<CefBrowserViewImpl*>(params.browser_view.get());
|
||||
|
||||
chrome_browser_view =
|
||||
static_cast<ChromeBrowserView*>(view_impl->root_view());
|
||||
chrome_params.window = chrome_browser_view;
|
||||
|
||||
auto chrome_widget =
|
||||
static_cast<ChromeBrowserFrame*>(chrome_browser_view->GetWidget());
|
||||
chrome_browser_view->set_frame(chrome_widget);
|
||||
}
|
||||
#endif // defined(TOOLKIT_VIEWS)
|
||||
|
||||
// Create the Browser. This will indirectly create the ChomeBrowserDelegate.
|
||||
// The same params will be used to create a new Browser if the tab is dragged
|
||||
// out of the existing Browser. The returned Browser is owned by the
|
||||
// associated BrowserView.
|
||||
auto browser = Browser::Create(chrome_params);
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
if (chrome_browser_view) {
|
||||
// Initialize the BrowserFrame and BrowserView and create the controls that
|
||||
// require access to the Browser.
|
||||
chrome_browser_view->InitBrowser(base::WrapUnique(browser),
|
||||
params.browser_view);
|
||||
}
|
||||
#endif
|
||||
auto browser = CreateBrowser(params);
|
||||
|
||||
GURL url = params.url;
|
||||
if (url.is_empty()) {
|
||||
@ -98,7 +45,8 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::Create(
|
||||
// Add a new tab. This will indirectly create a new tab WebContents and
|
||||
// call ChromeBrowserDelegate::OnWebContentsCreated to create the associated
|
||||
// ChromeBrowserHostImpl.
|
||||
chrome::AddTabAt(browser, url, /*idx=*/-1, /*foreground=*/true);
|
||||
chrome::AddTabAt(browser, url, /*index=*/TabStripModel::kNoTab,
|
||||
/*foreground=*/true);
|
||||
|
||||
// The new tab WebContents.
|
||||
auto web_contents = browser->tab_strip_model()->GetActiveWebContents();
|
||||
@ -159,6 +107,34 @@ CefRefPtr<ChromeBrowserHostImpl> ChromeBrowserHostImpl::GetBrowserForFrameRoute(
|
||||
|
||||
ChromeBrowserHostImpl::~ChromeBrowserHostImpl() = default;
|
||||
|
||||
void ChromeBrowserHostImpl::AddNewContents(
|
||||
std::unique_ptr<content::WebContents> contents) {
|
||||
DCHECK(contents);
|
||||
DCHECK(!browser_);
|
||||
|
||||
// We should already be associated with the WebContents.
|
||||
DCHECK_EQ(GetWebContents(), contents.get());
|
||||
|
||||
CefBrowserCreateParams params;
|
||||
params.request_context = request_context();
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
params.browser_view = GetBrowserView();
|
||||
#endif
|
||||
|
||||
// Create the new Browser representation.
|
||||
auto browser = CreateBrowser(params);
|
||||
|
||||
// Add the WebContents to the Browser.
|
||||
browser->tab_strip_model()->AddWebContents(
|
||||
std::move(contents), /*index=*/TabStripModel::kNoTab,
|
||||
ui::PageTransition::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
||||
TabStripModel::ADD_ACTIVE);
|
||||
|
||||
SetBrowser(browser);
|
||||
|
||||
browser->window()->Show();
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::OnWebContentsDestroyed(
|
||||
content::WebContents* web_contents) {
|
||||
platform_delegate_->WebContentsDestroyed(web_contents);
|
||||
@ -461,17 +437,112 @@ ChromeBrowserHostImpl::ChromeBrowserHostImpl(
|
||||
browser_info,
|
||||
request_context) {}
|
||||
|
||||
void ChromeBrowserHostImpl::Attach(Browser* browser,
|
||||
content::WebContents* web_contents) {
|
||||
DCHECK(browser);
|
||||
// static
|
||||
Browser* ChromeBrowserHostImpl::CreateBrowser(
|
||||
const CefBrowserCreateParams& params) {
|
||||
// Get or create the request context and profile.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
||||
CefRequestContextImpl::GetOrCreateForRequestContext(
|
||||
params.request_context);
|
||||
CHECK(request_context_impl);
|
||||
auto cef_browser_context = request_context_impl->GetBrowserContext();
|
||||
CHECK(cef_browser_context);
|
||||
auto profile = cef_browser_context->AsProfile();
|
||||
|
||||
Browser::CreateParams chrome_params =
|
||||
Browser::CreateParams(profile, /*user_gesture=*/false);
|
||||
|
||||
// Pass |params| to cef::BrowserDelegate::Create from the Browser constructor.
|
||||
chrome_params.cef_params = base::MakeRefCounted<DelegateCreateParams>(params);
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
// Configure Browser creation to use the existing Views-based
|
||||
// Widget/BrowserFrame (ChromeBrowserFrame) and BrowserView/BrowserWindow
|
||||
// (ChromeBrowserView). See views/chrome_browser_frame.h for related
|
||||
// documentation.
|
||||
ChromeBrowserView* chrome_browser_view = nullptr;
|
||||
if (params.browser_view) {
|
||||
// Don't show most controls.
|
||||
chrome_params.type = Browser::TYPE_POPUP;
|
||||
// Don't show title bar or address.
|
||||
chrome_params.trusted_source = true;
|
||||
|
||||
auto view_impl =
|
||||
static_cast<CefBrowserViewImpl*>(params.browser_view.get());
|
||||
|
||||
chrome_browser_view =
|
||||
static_cast<ChromeBrowserView*>(view_impl->root_view());
|
||||
chrome_params.window = chrome_browser_view;
|
||||
|
||||
auto chrome_widget =
|
||||
static_cast<ChromeBrowserFrame*>(chrome_browser_view->GetWidget());
|
||||
chrome_browser_view->set_frame(chrome_widget);
|
||||
}
|
||||
#endif // defined(TOOLKIT_VIEWS)
|
||||
|
||||
// Create the Browser. This will indirectly create the ChomeBrowserDelegate.
|
||||
// The same params will be used to create a new Browser if the tab is dragged
|
||||
// out of the existing Browser. The returned Browser is owned by the
|
||||
// associated BrowserView.
|
||||
auto browser = Browser::Create(chrome_params);
|
||||
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
if (chrome_browser_view) {
|
||||
// Initialize the BrowserFrame and BrowserView and create the controls that
|
||||
// require access to the Browser.
|
||||
chrome_browser_view->InitBrowser(base::WrapUnique(browser),
|
||||
params.browser_view);
|
||||
}
|
||||
#endif
|
||||
|
||||
return browser;
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::Attach(content::WebContents* web_contents,
|
||||
CefRefPtr<ChromeBrowserHostImpl> opener) {
|
||||
DCHECK(web_contents);
|
||||
|
||||
SetBrowser(browser);
|
||||
if (opener) {
|
||||
// Give the opener browser's platform delegate an opportunity to modify the
|
||||
// new browser's platform delegate.
|
||||
opener->platform_delegate_->PopupWebContentsCreated(
|
||||
settings_, client_, web_contents, platform_delegate_.get(),
|
||||
/*is_devtools_popup=*/false);
|
||||
}
|
||||
|
||||
platform_delegate_->WebContentsCreated(web_contents,
|
||||
/*own_web_contents=*/false);
|
||||
contents_delegate_->ObserveWebContents(web_contents);
|
||||
|
||||
// Associate the platform delegate with this browser.
|
||||
platform_delegate_->BrowserCreated(this);
|
||||
|
||||
// Associate the base class with the WebContents.
|
||||
InitializeBrowser();
|
||||
|
||||
// Notify that the browser has been created. These must be delivered in the
|
||||
// expected order.
|
||||
|
||||
// 1. Notify the browser's LifeSpanHandler. This must always be the first
|
||||
// notification for the browser.
|
||||
{
|
||||
// The WebContents won't be added to the Browser's TabStripModel until later
|
||||
// in the current call stack. Block navigation until that time.
|
||||
auto navigation_lock = browser_info_->CreateNavigationLock();
|
||||
OnAfterCreated();
|
||||
}
|
||||
|
||||
// 2. Notify the platform delegate. With Views this will result in a call to
|
||||
// CefBrowserViewDelegate::OnBrowserCreated().
|
||||
platform_delegate_->NotifyBrowserCreated();
|
||||
|
||||
if (opener && opener->platform_delegate_) {
|
||||
// 3. Notify the opener browser's platform delegate. With Views this will
|
||||
// result in a call to CefBrowserViewDelegate::OnPopupBrowserViewCreated().
|
||||
opener->platform_delegate_->PopupBrowserCreated(
|
||||
this,
|
||||
/*is_devtools_popup=*/false);
|
||||
}
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
|
||||
@ -481,21 +552,6 @@ void ChromeBrowserHostImpl::SetBrowser(Browser* browser) {
|
||||
->set_chrome_browser(browser);
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::InitializeBrowser() {
|
||||
CEF_REQUIRE_UIT();
|
||||
DCHECK(browser_);
|
||||
|
||||
// Associate the platform delegate with this browser.
|
||||
platform_delegate_->BrowserCreated(this);
|
||||
|
||||
CefBrowserHostBase::InitializeBrowser();
|
||||
|
||||
// The WebContents won't be added to the Browser's TabStripModel until later
|
||||
// in the current call stack. Block navigation until that time.
|
||||
auto navigation_lock = browser_info_->CreateNavigationLock();
|
||||
OnAfterCreated();
|
||||
}
|
||||
|
||||
void ChromeBrowserHostImpl::WindowDestroyed() {
|
||||
CEF_REQUIRE_UIT();
|
||||
#if defined(TOOLKIT_VIEWS)
|
||||
|
@ -142,17 +142,24 @@ class ChromeBrowserHostImpl : public CefBrowserHostBase {
|
||||
scoped_refptr<CefBrowserInfo> browser_info,
|
||||
CefRefPtr<CefRequestContextImpl> request_context);
|
||||
|
||||
// Called from ChromeBrowserDelegate::SetAsDelegate when this object is first
|
||||
// created. Must be called on the UI thread.
|
||||
void Attach(Browser* browser, content::WebContents* web_contents);
|
||||
// Create a new Browser without initializing the WebContents.
|
||||
static Browser* CreateBrowser(const CefBrowserCreateParams& params);
|
||||
|
||||
// Called from ChromeBrowserDelegate::SetAsDelegate when this object changes
|
||||
// Browser ownership (e.g. dragging between windows). The old Browser will be
|
||||
// cleared before the new Browser is added. Must be called on the UI thread.
|
||||
// Called from ChromeBrowserDelegate::CreateBrowser when this object is first
|
||||
// created. Must be called on the UI thread.
|
||||
void Attach(content::WebContents* web_contents,
|
||||
CefRefPtr<ChromeBrowserHostImpl> opener);
|
||||
|
||||
// Called from ChromeBrowserDelegate::AddNewContents to take ownership of a
|
||||
// popup WebContents.
|
||||
void AddNewContents(std::unique_ptr<content::WebContents> contents);
|
||||
|
||||
// Called when this object changes Browser ownership (e.g. initially created,
|
||||
// dragging between windows, etc). The old Browser, if any, will be cleared
|
||||
// before the new Browser is added. Must be called on the UI thread.
|
||||
void SetBrowser(Browser* browser);
|
||||
|
||||
// CefBrowserHostBase methods:
|
||||
void InitializeBrowser() override;
|
||||
void WindowDestroyed() override;
|
||||
void DestroyBrowser() override;
|
||||
|
||||
|
@ -4,14 +4,59 @@
|
||||
|
||||
#include "libcef/browser/chrome/views/browser_platform_delegate_chrome_views.h"
|
||||
|
||||
#include "include/views/cef_window.h"
|
||||
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
namespace {
|
||||
|
||||
// Default popup window delegate implementation.
|
||||
class PopupWindowDelegate : public CefWindowDelegate {
|
||||
public:
|
||||
explicit PopupWindowDelegate(CefRefPtr<CefBrowserView> browser_view)
|
||||
: browser_view_(browser_view) {}
|
||||
|
||||
void OnWindowCreated(CefRefPtr<CefWindow> window) override {
|
||||
window->AddChildView(browser_view_);
|
||||
window->Show();
|
||||
browser_view_->RequestFocus();
|
||||
}
|
||||
|
||||
void OnWindowDestroyed(CefRefPtr<CefWindow> window) override {
|
||||
browser_view_ = nullptr;
|
||||
}
|
||||
|
||||
bool CanClose(CefRefPtr<CefWindow> window) override {
|
||||
CefRefPtr<CefBrowser> browser = browser_view_->GetBrowser();
|
||||
if (browser)
|
||||
return browser->GetHost()->TryCloseBrowser();
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
CefRefPtr<CefBrowserView> browser_view_;
|
||||
|
||||
IMPLEMENT_REFCOUNTING(PopupWindowDelegate);
|
||||
DISALLOW_COPY_AND_ASSIGN(PopupWindowDelegate);
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
CefBrowserPlatformDelegateChromeViews::CefBrowserPlatformDelegateChromeViews(
|
||||
std::unique_ptr<CefBrowserPlatformDelegateNative> native_delegate,
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view)
|
||||
: CefBrowserPlatformDelegateChrome(std::move(native_delegate)),
|
||||
browser_view_(browser_view) {}
|
||||
: CefBrowserPlatformDelegateChrome(std::move(native_delegate)) {
|
||||
if (browser_view)
|
||||
SetBrowserView(browser_view);
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChromeViews::SetBrowserView(
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view) {
|
||||
DCHECK(!browser_view_);
|
||||
DCHECK(browser_view);
|
||||
browser_view_ = browser_view;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChromeViews::WebContentsCreated(
|
||||
content::WebContents* web_contents,
|
||||
@ -59,6 +104,50 @@ CefBrowserPlatformDelegateChromeViews::GetBrowserView() const {
|
||||
return browser_view_.get();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChromeViews::PopupWebContentsCreated(
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* new_web_contents,
|
||||
CefBrowserPlatformDelegate* new_platform_delegate,
|
||||
bool is_devtools) {
|
||||
DCHECK(new_platform_delegate->IsViewsHosted());
|
||||
auto* new_platform_delegate_impl =
|
||||
static_cast<CefBrowserPlatformDelegateChromeViews*>(
|
||||
new_platform_delegate);
|
||||
|
||||
CefRefPtr<CefBrowserViewDelegate> new_delegate;
|
||||
if (browser_view_->delegate()) {
|
||||
new_delegate = browser_view_->delegate()->GetDelegateForPopupBrowserView(
|
||||
browser_view_.get(), settings, client, is_devtools);
|
||||
}
|
||||
|
||||
// Create a new BrowserView for the popup.
|
||||
CefRefPtr<CefBrowserViewImpl> new_browser_view =
|
||||
CefBrowserViewImpl::CreateForPopup(settings, new_delegate);
|
||||
|
||||
// Associate the PlatformDelegate with the new BrowserView.
|
||||
new_platform_delegate_impl->SetBrowserView(new_browser_view);
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChromeViews::PopupBrowserCreated(
|
||||
CefBrowserHostBase* new_browser,
|
||||
bool is_devtools) {
|
||||
CefRefPtr<CefBrowserView> new_browser_view =
|
||||
CefBrowserView::GetForBrowser(new_browser);
|
||||
DCHECK(new_browser_view);
|
||||
|
||||
bool popup_handled = false;
|
||||
if (browser_view_->delegate()) {
|
||||
popup_handled = browser_view_->delegate()->OnPopupBrowserViewCreated(
|
||||
browser_view_.get(), new_browser_view.get(), is_devtools);
|
||||
}
|
||||
|
||||
if (!popup_handled) {
|
||||
CefWindow::CreateTopLevelWindow(
|
||||
new PopupWindowDelegate(new_browser_view.get()));
|
||||
}
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateChromeViews::IsViewsHosted() const {
|
||||
return true;
|
||||
}
|
||||
|
@ -26,9 +26,19 @@ class CefBrowserPlatformDelegateChromeViews
|
||||
void CloseHostWindow() override;
|
||||
views::Widget* GetWindowWidget() const override;
|
||||
CefRefPtr<CefBrowserView> GetBrowserView() const override;
|
||||
void PopupWebContentsCreated(
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefClient> client,
|
||||
content::WebContents* new_web_contents,
|
||||
CefBrowserPlatformDelegate* new_platform_delegate,
|
||||
bool is_devtools) override;
|
||||
void PopupBrowserCreated(CefBrowserHostBase* new_browser,
|
||||
bool is_devtools) override;
|
||||
bool IsViewsHosted() const override;
|
||||
|
||||
private:
|
||||
void SetBrowserView(CefRefPtr<CefBrowserViewImpl> browser_view);
|
||||
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view_;
|
||||
};
|
||||
|
||||
|
@ -10,8 +10,6 @@
|
||||
#include "libcef/browser/context.h"
|
||||
#include "libcef/browser/thread_util.h"
|
||||
#include "libcef/browser/views/window_impl.h"
|
||||
#include "libcef/features/runtime.h"
|
||||
#include "libcef/features/runtime_checks.h"
|
||||
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "ui/content_accelerators/accelerator_util.h"
|
||||
@ -62,7 +60,6 @@ CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::Create(
|
||||
CefRefPtr<CefBrowserViewImpl> CefBrowserViewImpl::CreateForPopup(
|
||||
const CefBrowserSettings& settings,
|
||||
CefRefPtr<CefBrowserViewDelegate> delegate) {
|
||||
REQUIRE_ALLOY_RUNTIME();
|
||||
CEF_REQUIRE_UIT_RETURN(nullptr);
|
||||
|
||||
CefRefPtr<CefBrowserViewImpl> browser_view = new CefBrowserViewImpl(delegate);
|
||||
|
@ -13,7 +13,7 @@ index ba0c5c3fc044..b4df9af95ecd 100644
|
||||
return false;
|
||||
}
|
||||
diff --git chrome/browser/ui/browser.cc chrome/browser/ui/browser.cc
|
||||
index f225525e74eb..ee5932936215 100644
|
||||
index f225525e74eb..2f3d13b087b0 100644
|
||||
--- chrome/browser/ui/browser.cc
|
||||
+++ chrome/browser/ui/browser.cc
|
||||
@@ -256,6 +256,20 @@
|
||||
@ -102,7 +102,23 @@ index f225525e74eb..ee5932936215 100644
|
||||
NavigateParams nav_params(this, params.url, params.transition);
|
||||
nav_params.FillNavigateParamsFromOpenURLParams(params);
|
||||
nav_params.source_contents = source;
|
||||
@@ -1651,6 +1698,8 @@ void Browser::LoadingStateChanged(WebContents* source,
|
||||
@@ -1633,6 +1680,15 @@ void Browser::AddNewContents(WebContents* source,
|
||||
source, disposition);
|
||||
}
|
||||
|
||||
+#if BUILDFLAG(ENABLE_CEF)
|
||||
+ if (cef_browser_delegate_) {
|
||||
+ cef_browser_delegate_->AddNewContents(
|
||||
+ source, std::move(new_contents), target_url, disposition, initial_rect,
|
||||
+ user_gesture, was_blocked);
|
||||
+ return;
|
||||
+ }
|
||||
+#endif
|
||||
+
|
||||
chrome::AddWebContents(this, source, std::move(new_contents), target_url,
|
||||
disposition, initial_rect);
|
||||
}
|
||||
@@ -1651,6 +1707,8 @@ void Browser::LoadingStateChanged(WebContents* source,
|
||||
bool to_different_document) {
|
||||
ScheduleUIUpdate(source, content::INVALIDATE_TYPE_LOAD);
|
||||
UpdateWindowForLoadingStateChanged(source, to_different_document);
|
||||
@ -111,7 +127,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
}
|
||||
|
||||
void Browser::CloseContents(WebContents* source) {
|
||||
@@ -1678,6 +1727,8 @@ void Browser::SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
|
||||
@@ -1678,6 +1736,8 @@ void Browser::SetContentsBounds(WebContents* source, const gfx::Rect& bounds) {
|
||||
}
|
||||
|
||||
void Browser::UpdateTargetURL(WebContents* source, const GURL& url) {
|
||||
@ -120,7 +136,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
if (!GetStatusBubble())
|
||||
return;
|
||||
|
||||
@@ -1685,6 +1736,17 @@ void Browser::UpdateTargetURL(WebContents* source, const GURL& url) {
|
||||
@@ -1685,6 +1745,17 @@ void Browser::UpdateTargetURL(WebContents* source, const GURL& url) {
|
||||
GetStatusBubble()->SetURL(url);
|
||||
}
|
||||
|
||||
@ -138,7 +154,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
void Browser::ContentsMouseEvent(WebContents* source,
|
||||
bool motion,
|
||||
bool exited) {
|
||||
@@ -1801,6 +1863,10 @@ void Browser::WebContentsCreated(WebContents* source_contents,
|
||||
@@ -1801,6 +1872,10 @@ void Browser::WebContentsCreated(WebContents* source_contents,
|
||||
|
||||
// Make the tab show up in the task manager.
|
||||
task_manager::WebContentsTags::CreateForTabContents(new_contents);
|
||||
@ -149,7 +165,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
}
|
||||
|
||||
void Browser::PortalWebContentsCreated(WebContents* portal_web_contents) {
|
||||
@@ -1837,6 +1903,8 @@ void Browser::RendererResponsive(
|
||||
@@ -1837,6 +1912,8 @@ void Browser::RendererResponsive(
|
||||
void Browser::DidNavigateMainFramePostCommit(WebContents* web_contents) {
|
||||
if (web_contents == tab_strip_model_->GetActiveWebContents())
|
||||
UpdateBookmarkBarState(BOOKMARK_BAR_STATE_CHANGE_TAB_STATE);
|
||||
@ -158,7 +174,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
}
|
||||
|
||||
content::JavaScriptDialogManager* Browser::GetJavaScriptDialogManager(
|
||||
@@ -1883,11 +1951,15 @@ void Browser::EnterFullscreenModeForTab(
|
||||
@@ -1883,11 +1960,15 @@ void Browser::EnterFullscreenModeForTab(
|
||||
const blink::mojom::FullscreenOptions& options) {
|
||||
exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
|
||||
requesting_frame, options.display_id);
|
||||
@ -174,7 +190,7 @@ index f225525e74eb..ee5932936215 100644
|
||||
}
|
||||
|
||||
bool Browser::IsFullscreenForTabOrPending(const WebContents* web_contents) {
|
||||
@@ -2730,6 +2802,8 @@ void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) {
|
||||
@@ -2730,6 +2811,8 @@ void Browser::SetAsDelegate(WebContents* web_contents, bool set_delegate) {
|
||||
content_translate_driver->RemoveTranslationObserver(this);
|
||||
BookmarkTabHelper::FromWebContents(web_contents)->RemoveObserver(this);
|
||||
}
|
||||
|
@ -13,11 +13,6 @@ void CreateBrowserDelegates(ClientAppBrowser::DelegateSet& delegates) {
|
||||
extern void CreateAudioOutputTests(ClientAppBrowser::DelegateSet & delegates);
|
||||
CreateAudioOutputTests(delegates);
|
||||
|
||||
// Bring in navigation tests.
|
||||
extern void CreateNavigationBrowserTests(ClientAppBrowser::DelegateSet &
|
||||
delegates);
|
||||
CreateNavigationBrowserTests(delegates);
|
||||
|
||||
// Bring in the plugin tests.
|
||||
extern void CreatePluginBrowserTests(ClientAppBrowser::DelegateSet &
|
||||
delegates);
|
||||
|
@ -20,22 +20,6 @@ using client::ClientAppRenderer;
|
||||
|
||||
namespace {
|
||||
|
||||
// Browser-side app delegate.
|
||||
class NavigationBrowserTest : public client::ClientAppBrowser::Delegate {
|
||||
public:
|
||||
NavigationBrowserTest() {}
|
||||
|
||||
void OnBeforeCommandLineProcessing(
|
||||
CefRefPtr<client::ClientAppBrowser> app,
|
||||
CefRefPtr<CefCommandLine> command_line) override {
|
||||
// Disable popup blocking for the chrome runtime.
|
||||
command_line->AppendSwitch("disable-popup-blocking");
|
||||
}
|
||||
|
||||
private:
|
||||
IMPLEMENT_REFCOUNTING(NavigationBrowserTest);
|
||||
};
|
||||
|
||||
const char kHNav1[] = "http://tests-hnav.com/nav1.html";
|
||||
const char kHNav2[] = "http://tests-hnav.com/nav2.html";
|
||||
const char kHNav3[] = "http://tests-hnav.com/nav3.html";
|
||||
@ -3548,10 +3532,3 @@ void CreateNavigationRendererTests(ClientAppRenderer::DelegateSet& delegates) {
|
||||
delegates.insert(new LoadNavRendererTest);
|
||||
delegates.insert(new ExtraInfoNavRendererTest);
|
||||
}
|
||||
|
||||
// Entry point for creating plugin browser test objects.
|
||||
// Called from client_app_delegates.cc.
|
||||
void CreateNavigationBrowserTests(
|
||||
client::ClientAppBrowser::DelegateSet& delegates) {
|
||||
delegates.insert(new NavigationBrowserTest);
|
||||
}
|
||||
|
@ -47,6 +47,9 @@ void ClientAppBrowser::OnBeforeCommandLineProcessing(
|
||||
command_line->AppendSwitch("disable-gpu-shader-disk-cache");
|
||||
}
|
||||
|
||||
// Disable popup blocking for the chrome runtime.
|
||||
command_line->AppendSwitch("disable-popup-blocking");
|
||||
|
||||
#if defined(OS_MAC)
|
||||
// Disable the toolchain prompt on macOS.
|
||||
command_line->AppendSwitch("use-mock-keychain");
|
||||
|
Loading…
x
Reference in New Issue
Block a user