mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Add chrome runtime support for more callbacks and ceftests (see issue #2969)
This change adds support for: - Protocol and request handling. - Loading and navigation events. - Display and focus events. - Mouse/keyboard events. - Popup browsers. - Callbacks in the renderer process. - Misc. functionality required for ceftests. This change also adds a new CefBrowserProcessHandler::GetCookieableSchemes callback for configuring global state that will be applied to all CefCookieManagers by default. This global callback is currently required by the chrome runtime because the primary ProfileImpl is created via ChromeBrowserMainParts::PreMainMessageLoopRun (CreatePrimaryProfile) before OnContextCreated can be called. ProfileImpl will use the "C:\Users\[user]\AppData\Local\CEF\User Data\Default" directory by default (on Windows). Cookies may persist in this directory when running ceftests and may need to be manually deleted if those tests fail. Remaining work includes: - Support for client-created request contexts. - Embedding the browser in a Views hierarchy (cefclient support). - TryCloseBrowser and DoClose support. - Most of the CefSettings configuration. - DevTools protocol and window control (ShowDevTools, ExecuteDevToolsMethod). - CEF-specific WebUI pages (about, license, webui-hosts). - Context menu customization (CefContextMenuHandler). - Auto resize (SetAutoResizeEnabled). - Zoom settings (SetZoomLevel). - File dialog runner (RunFileDialog). - File and JS dialog handlers (CefDialogHandler, CefJSDialogHandler). - Extension loading (LoadExtension, etc). - Plugin loading (OnBeforePluginLoad). - Widevine loading (CefRegisterWidevineCdm). - PDF and print preview does not display. - Crash reporting is untested. - Mac: Web content loads but does not display. The following ceftests are now passing when run with the "--enable-chrome-runtime" command-line flag: CorsTest.* DisplayTest.*:-DisplayTest.AutoResize DOMTest.* DraggableRegionsTest.* ImageTest.* MessageRouterTest.* NavigationTest.* ParserTest.* RequestContextTest.*Global* RequestTest.* ResourceManagerTest.* ResourceRequestHandlerTest.* ResponseTest.* SchemeHandlerTest.* ServerTest.* StreamResourceHandlerTest.* StreamTest.* StringTest.* TaskTest.* TestServerTest.* ThreadTest.* URLRequestTest.*Global* V8Test.*:-V8Test.OnUncaughtExceptionDevTools ValuesTest.* WaitableEventTest.* XmlReaderTest.* ZipReaderTest.*
This commit is contained in:
@@ -5,11 +5,20 @@
|
||||
#include "libcef/browser/browser_contents_delegate.h"
|
||||
|
||||
#include "libcef/browser/browser_host_base.h"
|
||||
#include "libcef/browser/browser_platform_delegate.h"
|
||||
#include "libcef/browser/browser_util.h"
|
||||
|
||||
#include "content/public/browser/keyboard_event_processing_result.h"
|
||||
#include "content/public/browser/native_web_keyboard_event.h"
|
||||
#include "content/public/browser/navigation_entry.h"
|
||||
#include "content/public/browser/navigation_handle.h"
|
||||
#include "content/public/browser/notification_details.h"
|
||||
#include "content/public/browser/notification_source.h"
|
||||
#include "content/public/browser/notification_types.h"
|
||||
#include "content/public/browser/render_view_host.h"
|
||||
|
||||
using content::KeyboardEventProcessingResult;
|
||||
|
||||
CefBrowserContentsDelegate::CefBrowserContentsDelegate(
|
||||
scoped_refptr<CefBrowserInfo> browser_info)
|
||||
: browser_info_(browser_info) {
|
||||
@@ -18,13 +27,29 @@ CefBrowserContentsDelegate::CefBrowserContentsDelegate(
|
||||
|
||||
void CefBrowserContentsDelegate::ObserveWebContents(
|
||||
content::WebContents* new_contents) {
|
||||
Observe(new_contents);
|
||||
WebContentsObserver::Observe(new_contents);
|
||||
|
||||
if (new_contents) {
|
||||
registrar_.reset(new content::NotificationRegistrar);
|
||||
|
||||
// When navigating through the history, the restored NavigationEntry's title
|
||||
// will be used. If the entry ends up having the same title after we return
|
||||
// to it, as will usually be the case, the
|
||||
// NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED will then be suppressed, since
|
||||
// the NavigationEntry's title hasn't changed.
|
||||
registrar_->Add(this, content::NOTIFICATION_LOAD_STOP,
|
||||
content::Source<content::NavigationController>(
|
||||
&new_contents->GetController()));
|
||||
|
||||
// Make sure RenderViewCreated is called at least one time.
|
||||
RenderViewCreated(new_contents->GetRenderViewHost());
|
||||
|
||||
// Create the frame representation before OnAfterCreated is called for a new
|
||||
// browser. Additionally, RenderFrameCreated is otherwise not called at all
|
||||
// for new popup browsers.
|
||||
RenderFrameCreated(new_contents->GetMainFrame());
|
||||
} else {
|
||||
registrar_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,6 +61,27 @@ void CefBrowserContentsDelegate::RemoveObserver(Observer* observer) {
|
||||
observers_.RemoveObserver(observer);
|
||||
}
|
||||
|
||||
// |source| may be NULL for navigations in the current tab, or if the
|
||||
// navigation originates from a guest view via MaybeAllowNavigation.
|
||||
content::WebContents* CefBrowserContentsDelegate::OpenURLFromTab(
|
||||
content::WebContents* source,
|
||||
const content::OpenURLParams& params) {
|
||||
bool cancel = false;
|
||||
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetRequestHandler()) {
|
||||
cancel = handler->OnOpenURLFromTab(
|
||||
browser(), browser()->GetFrame(params.frame_tree_node_id),
|
||||
params.url.spec(),
|
||||
static_cast<cef_window_open_disposition_t>(params.disposition),
|
||||
params.user_gesture);
|
||||
}
|
||||
}
|
||||
|
||||
// Returning nullptr will cancel the navigation.
|
||||
return cancel ? nullptr : web_contents();
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::LoadingStateChanged(
|
||||
content::WebContents* source,
|
||||
bool to_different_document) {
|
||||
@@ -126,6 +172,60 @@ void CefBrowserContentsDelegate::ExitFullscreenModeForTab(
|
||||
OnFullscreenModeChange(/*fullscreen=*/false);
|
||||
}
|
||||
|
||||
KeyboardEventProcessingResult
|
||||
CefBrowserContentsDelegate::PreHandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
if (auto delegate = platform_delegate()) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetKeyboardHandler()) {
|
||||
CefKeyEvent cef_event;
|
||||
if (browser_util::GetCefKeyEvent(event, cef_event)) {
|
||||
cef_event.focus_on_editable_field = focus_on_editable_field_;
|
||||
|
||||
auto event_handle = delegate->GetEventHandle(event);
|
||||
bool is_keyboard_shortcut = false;
|
||||
bool result = handler->OnPreKeyEvent(
|
||||
browser(), cef_event, event_handle, &is_keyboard_shortcut);
|
||||
if (result) {
|
||||
return KeyboardEventProcessingResult::HANDLED;
|
||||
} else if (is_keyboard_shortcut) {
|
||||
return KeyboardEventProcessingResult::NOT_HANDLED_IS_SHORTCUT;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return KeyboardEventProcessingResult::NOT_HANDLED;
|
||||
}
|
||||
|
||||
bool CefBrowserContentsDelegate::HandleKeyboardEvent(
|
||||
content::WebContents* source,
|
||||
const content::NativeWebKeyboardEvent& event) {
|
||||
// Check to see if event should be ignored.
|
||||
if (event.skip_in_browser)
|
||||
return false;
|
||||
|
||||
if (auto delegate = platform_delegate()) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetKeyboardHandler()) {
|
||||
CefKeyEvent cef_event;
|
||||
if (browser_util::GetCefKeyEvent(event, cef_event)) {
|
||||
cef_event.focus_on_editable_field = focus_on_editable_field_;
|
||||
|
||||
auto event_handle = delegate->GetEventHandle(event);
|
||||
if (handler->OnKeyEvent(browser(), cef_event, event_handle)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::RenderFrameCreated(
|
||||
content::RenderFrameHost* render_frame_host) {
|
||||
browser_info_->MaybeCreateFrame(render_frame_host, false /* is_guest_view */);
|
||||
@@ -149,6 +249,28 @@ void CefBrowserContentsDelegate::RenderFrameDeleted(
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::RenderViewCreated(
|
||||
content::RenderViewHost* render_view_host) {
|
||||
// May be already registered if the renderer crashed previously.
|
||||
if (!registrar_->IsRegistered(
|
||||
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
||||
content::Source<content::RenderViewHost>(render_view_host))) {
|
||||
registrar_->Add(this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
||||
content::Source<content::RenderViewHost>(render_view_host));
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::RenderViewDeleted(
|
||||
content::RenderViewHost* render_view_host) {
|
||||
if (registrar_->IsRegistered(
|
||||
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
||||
content::Source<content::RenderViewHost>(render_view_host))) {
|
||||
registrar_->Remove(
|
||||
this, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
|
||||
content::Source<content::RenderViewHost>(render_view_host));
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::RenderViewReady() {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetRequestHandler()) {
|
||||
@@ -358,12 +480,77 @@ void CefBrowserContentsDelegate::OnWebContentsFocused(
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::WebContentsDestroyed() {
|
||||
auto wc = web_contents();
|
||||
ObserveWebContents(nullptr);
|
||||
for (auto& observer : observers_) {
|
||||
observer.OnWebContentsDestroyed();
|
||||
observer.OnWebContentsDestroyed(wc);
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::Observe(
|
||||
int type,
|
||||
const content::NotificationSource& source,
|
||||
const content::NotificationDetails& details) {
|
||||
DCHECK(type == content::NOTIFICATION_LOAD_STOP ||
|
||||
type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE);
|
||||
|
||||
if (type == content::NOTIFICATION_LOAD_STOP) {
|
||||
content::NavigationController* controller =
|
||||
content::Source<content::NavigationController>(source).ptr();
|
||||
OnTitleChange(controller->GetWebContents()->GetTitle());
|
||||
} else if (type == content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE) {
|
||||
focus_on_editable_field_ = *content::Details<bool>(details).ptr();
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::OnLoadEnd(CefRefPtr<CefFrame> frame,
|
||||
const GURL& url,
|
||||
int http_status_code) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetLoadHandler()) {
|
||||
handler->OnLoadEnd(browser(), frame, http_status_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool CefBrowserContentsDelegate::OnSetFocus(cef_focus_source_t source) {
|
||||
// SetFocus() might be called while inside the OnSetFocus() callback. If
|
||||
// so, don't re-enter the callback.
|
||||
if (is_in_onsetfocus_)
|
||||
return true;
|
||||
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetFocusHandler()) {
|
||||
is_in_onsetfocus_ = true;
|
||||
bool handled = handler->OnSetFocus(browser(), source);
|
||||
is_in_onsetfocus_ = false;
|
||||
|
||||
return handled;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
CefRefPtr<CefClient> CefBrowserContentsDelegate::client() const {
|
||||
if (auto b = browser()) {
|
||||
return b->GetHost()->GetClient();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> CefBrowserContentsDelegate::browser() const {
|
||||
return browser_info_->browser();
|
||||
}
|
||||
|
||||
CefBrowserPlatformDelegate* CefBrowserContentsDelegate::platform_delegate()
|
||||
const {
|
||||
auto browser = browser_info_->browser();
|
||||
if (browser)
|
||||
return browser->platform_delegate();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::OnAddressChange(const GURL& url) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetDisplayHandler()) {
|
||||
@@ -400,16 +587,6 @@ void CefBrowserContentsDelegate::OnLoadError(CefRefPtr<CefFrame> frame,
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::OnLoadEnd(CefRefPtr<CefFrame> frame,
|
||||
const GURL& url,
|
||||
int http_status_code) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetLoadHandler()) {
|
||||
handler->OnLoadEnd(browser(), frame, http_status_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::OnTitleChange(const base::string16& title) {
|
||||
if (auto c = client()) {
|
||||
if (auto handler = c->GetDisplayHandler()) {
|
||||
@@ -418,17 +595,6 @@ void CefBrowserContentsDelegate::OnTitleChange(const base::string16& title) {
|
||||
}
|
||||
}
|
||||
|
||||
CefRefPtr<CefClient> CefBrowserContentsDelegate::client() const {
|
||||
if (auto b = browser()) {
|
||||
return b->GetHost()->GetClient();
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
CefRefPtr<CefBrowser> CefBrowserContentsDelegate::browser() const {
|
||||
return browser_info_->browser();
|
||||
}
|
||||
|
||||
void CefBrowserContentsDelegate::OnFullscreenModeChange(bool fullscreen) {
|
||||
if (fullscreen == is_fullscreen_)
|
||||
return;
|
||||
|
Reference in New Issue
Block a user