mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Create a ChromeBrowserHostImpl for every Chrome tab (see issue #2969)
The Browser object represents the top-level Chrome browser window. One or more tabs (WebContents) are then owned by the Browser object via TabStripModel. A new Browser object can be created programmatically using "new Browser" or Browser::Create, or as a result of user action such as dragging a tab out of an existing window. New or existing tabs can also be added to an already existing Browser object. The Browser object acts as the WebContentsDelegate for all attached tabs. CEF integration requires WebContentsDelegate callbacks and notification of tab attach/detach. To support this integration we add a cef::BrowserDelegate (ChromeBrowserDelegate) member that is created in the Browser constructor and receives delegation for the Browser callbacks. ChromeBrowserDelegate creates a new ChromeBrowserHostImpl when a tab is added to a Browser for the first time, and that ChromeBrowserHostImpl continues to exist until the tab's WebContents is destroyed. The associated WebContents object does not change, but the Browser object will change when the tab is dragged between windows. CEF callback logic is shared between the chrome and alloy runtimes where possible. This shared logic has been extracted from CefBrowserHostImpl to create new CefBrowserHostBase and CefBrowserContentsDelegate classes. The CefBrowserHostImpl class is now only used with the alloy runtime and will be renamed to AlloyBrowserHostImpl in a future commit.
This commit is contained in:
@@ -1,138 +0,0 @@
|
||||
// Copyright 2020 The Chromium Embedded Framework 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/chrome/browser_platform_delegate_chrome.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "chrome/browser/ui/browser.h"
|
||||
#include "chrome/browser/ui/browser_tabstrip.h"
|
||||
#include "chrome/browser/ui/browser_window.h"
|
||||
#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
||||
|
||||
CefBrowserPlatformDelegateChrome::CefBrowserPlatformDelegateChrome(
|
||||
SkColor background_color)
|
||||
: background_color_(background_color) {}
|
||||
|
||||
content::WebContents* CefBrowserPlatformDelegateChrome::CreateWebContents(
|
||||
CefBrowserHostImpl::CreateParams& create_params,
|
||||
bool& own_web_contents) {
|
||||
// Get or create the request context and profile.
|
||||
CefRefPtr<CefRequestContextImpl> request_context_impl =
|
||||
CefRequestContextImpl::GetOrCreateForRequestContext(
|
||||
create_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();
|
||||
|
||||
if (!create_params.request_context) {
|
||||
// Using the global request context.
|
||||
create_params.request_context = request_context_impl.get();
|
||||
}
|
||||
|
||||
// Create a Browser.
|
||||
Browser::CreateParams params =
|
||||
Browser::CreateParams(profile, /*user_gesture=*/false);
|
||||
chrome_browser_ = new Browser(params);
|
||||
|
||||
chrome::AddTabAt(chrome_browser_, create_params.url, /*idx=*/-1,
|
||||
/*foreground=*/true);
|
||||
|
||||
auto web_contents =
|
||||
chrome_browser_->tab_strip_model()->GetActiveWebContents();
|
||||
CHECK(web_contents);
|
||||
|
||||
own_web_contents = false;
|
||||
return web_contents;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::WebContentsDestroyed(
|
||||
content::WebContents* web_contents) {
|
||||
CefBrowserPlatformDelegate::WebContentsDestroyed(web_contents);
|
||||
|
||||
// TODO(chrome-runtime): Find a better way to be notified of Browser
|
||||
// destruction.
|
||||
browser_->WindowDestroyed();
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::BrowserDestroyed(
|
||||
CefBrowserHostImpl* browser) {
|
||||
CefBrowserPlatformDelegate::BrowserDestroyed(browser);
|
||||
|
||||
// Release the reference added in CreateHostWindow.
|
||||
browser->Release();
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateChrome::CreateHostWindow() {
|
||||
// Keep a reference to the CEF browser.
|
||||
browser_->AddRef();
|
||||
|
||||
chrome_browser_->window()->Show();
|
||||
return true;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::CloseHostWindow() {}
|
||||
|
||||
CefWindowHandle CefBrowserPlatformDelegateChrome::GetHostWindowHandle() const {
|
||||
return kNullWindowHandle;
|
||||
}
|
||||
|
||||
SkColor CefBrowserPlatformDelegateChrome::GetBackgroundColor() const {
|
||||
return background_color_;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::WasResized() {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendKeyEvent(const CefKeyEvent& event) {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendMouseClickEvent(
|
||||
const CefMouseEvent& event,
|
||||
CefBrowserHost::MouseButtonType type,
|
||||
bool mouseUp,
|
||||
int clickCount) {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendMouseMoveEvent(
|
||||
const CefMouseEvent& event,
|
||||
bool mouseLeave) {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendMouseWheelEvent(
|
||||
const CefMouseEvent& event,
|
||||
int deltaX,
|
||||
int deltaY) {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendTouchEvent(
|
||||
const CefTouchEvent& event) {}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::SendFocusEvent(bool setFocus) {}
|
||||
|
||||
gfx::Point CefBrowserPlatformDelegateChrome::GetScreenPoint(
|
||||
const gfx::Point& view) const {
|
||||
return view;
|
||||
}
|
||||
|
||||
void CefBrowserPlatformDelegateChrome::ViewText(const std::string& text) {}
|
||||
|
||||
bool CefBrowserPlatformDelegateChrome::HandleKeyboardEvent(
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CefEventHandle CefBrowserPlatformDelegateChrome::GetEventHandle(
|
||||
const content::NativeWebKeyboardEvent& event) const {
|
||||
return kNullEventHandle;
|
||||
}
|
||||
|
||||
std::unique_ptr<CefMenuRunner>
|
||||
CefBrowserPlatformDelegateChrome::CreateMenuRunner() {
|
||||
NOTIMPLEMENTED();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateChrome::IsWindowless() const {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CefBrowserPlatformDelegateChrome::IsViewsHosted() const {
|
||||
return false;
|
||||
}
|
Reference in New Issue
Block a user