diff --git a/cef_paths2.gypi b/cef_paths2.gypi index 0d2717597..4e2328ec5 100644 --- a/cef_paths2.gypi +++ b/cef_paths2.gypi @@ -160,8 +160,6 @@ 'tests/cefclient/client_handler.h', 'tests/cefclient/client_handler_osr.cc', 'tests/cefclient/client_handler_osr.h', - 'tests/cefclient/client_handler_single.cc', - 'tests/cefclient/client_handler_single.h', 'tests/cefclient/client_handler_std.cc', 'tests/cefclient/client_handler_std.h', 'tests/cefclient/client_renderer.cc', diff --git a/tests/cefclient/browser_window.h b/tests/cefclient/browser_window.h index 6b5c3deca..16b78cef3 100644 --- a/tests/cefclient/browser_window.h +++ b/tests/cefclient/browser_window.h @@ -7,7 +7,7 @@ #include "include/base/cef_scoped_ptr.h" #include "include/cef_browser.h" -#include "cefclient/client_handler_single.h" +#include "cefclient/client_handler.h" #include "cefclient/client_types.h" namespace client { @@ -15,7 +15,7 @@ namespace client { // Represents a native child window hosting a single browser instance. The // methods of this class must be called on the main thread unless otherwise // indicated. -class BrowserWindow : public ClientHandlerSingle::Delegate { +class BrowserWindow : public ClientHandler::Delegate { public: // This interface is implemented by the owner of the BrowserWindowWin. The // methods of this class will be called on the main thread. @@ -90,7 +90,7 @@ class BrowserWindow : public ClientHandlerSingle::Delegate { // |root_window| and |delegate| must outlive this object. explicit BrowserWindow(Delegate* delegate); - // ClientHandlerSingle::Delegate methods. + // ClientHandler::Delegate methods. void OnBrowserCreated(CefRefPtr browser) OVERRIDE; void OnBrowserClosing(CefRefPtr browser) OVERRIDE; void OnBrowserClosed(CefRefPtr browser) OVERRIDE; @@ -102,7 +102,7 @@ class BrowserWindow : public ClientHandlerSingle::Delegate { Delegate* delegate_; CefRefPtr browser_; - CefRefPtr client_handler_; + CefRefPtr client_handler_; bool is_closing_; DISALLOW_COPY_AND_ASSIGN(BrowserWindow); diff --git a/tests/cefclient/browser_window_osr_gtk.cc b/tests/cefclient/browser_window_osr_gtk.cc index 2d9a8c023..905dbad54 100644 --- a/tests/cefclient/browser_window_osr_gtk.cc +++ b/tests/cefclient/browser_window_osr_gtk.cc @@ -929,9 +929,6 @@ void BrowserWindowOsrGtk::CreateBrowser(ClientWindowHandle parent_handle, const CefBrowserSettings& settings) { REQUIRE_MAIN_THREAD(); - // Set the window handle for GTK dialogs. - client_handler_->SetMainWindowHandle(parent_handle); - // Create the native window. Create(parent_handle); @@ -964,9 +961,6 @@ void BrowserWindowOsrGtk::ShowPopup(ClientWindowHandle parent_handle, REQUIRE_MAIN_THREAD(); DCHECK(browser_.get()); - // Set the window handle for GTK dialogs. - client_handler_->SetMainWindowHandle(parent_handle); - // Create the native window. Create(parent_handle); diff --git a/tests/cefclient/browser_window_std_gtk.cc b/tests/cefclient/browser_window_std_gtk.cc index 25645a99f..7e2f3de92 100644 --- a/tests/cefclient/browser_window_std_gtk.cc +++ b/tests/cefclient/browser_window_std_gtk.cc @@ -94,9 +94,6 @@ void BrowserWindowStdGtk::CreateBrowser(ClientWindowHandle parent_handle, const CefBrowserSettings& settings) { REQUIRE_MAIN_THREAD(); - // Set the window handle for GTK dialogs. - client_handler_->SetMainWindowHandle(parent_handle); - CefWindowInfo window_info; window_info.SetAsChild(GetXWindowForWidget(parent_handle), rect); @@ -119,9 +116,6 @@ void BrowserWindowStdGtk::ShowPopup(ClientWindowHandle parent_handle, int x, int y, size_t width, size_t height) { REQUIRE_MAIN_THREAD(); - // Set the window handle for GTK dialogs. - client_handler_->SetMainWindowHandle(parent_handle); - if (browser_) { ::Window parent_xwindow = GetXWindowForWidget(parent_handle); ::Display* xdisplay = cef_get_xdisplay(); diff --git a/tests/cefclient/client_handler.cc b/tests/cefclient/client_handler.cc index 6a0f657e7..c7a440530 100644 --- a/tests/cefclient/client_handler.cc +++ b/tests/cefclient/client_handler.cc @@ -17,6 +17,7 @@ #include "cefclient/client_switches.h" #include "cefclient/main_context.h" #include "cefclient/resource_util.h" +#include "cefclient/root_window_manager.h" #include "cefclient/test_runner.h" namespace client { @@ -43,12 +44,13 @@ enum client_menu_ids { } // namespace -ClientHandler::ClientHandler(const std::string& startup_url, - bool is_osr) - : startup_url_(startup_url), - is_osr_(is_osr), +ClientHandler::ClientHandler(Delegate* delegate, + bool is_osr, + const std::string& startup_url) + : is_osr_(is_osr), + startup_url_(startup_url), + delegate_(delegate), browser_count_(0), - main_handle_(NULL), console_log_file_(MainContext::Get()->GetConsoleLogPath()), first_console_message_(true), focus_on_editable_field_(false) { @@ -66,7 +68,15 @@ ClientHandler::ClientHandler(const std::string& startup_url, command_line->HasSwitch(switches::kMouseCursorChangeDisabled); } -ClientHandler::~ClientHandler() { +void ClientHandler::DetachDelegate() { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE(base::Bind(&ClientHandler::DetachDelegate, this)); + return; + } + + DCHECK(delegate_); + delegate_ = NULL; } bool ClientHandler::OnProcessMessageReceived( @@ -147,14 +157,14 @@ void ClientHandler::OnAddressChange(CefRefPtr browser, // Only update the address for the main (top-level) frame. if (frame->IsMain()) - SetAddress(browser, url); + NotifyAddress(url); } void ClientHandler::OnTitleChange(CefRefPtr browser, const CefString& title) { CEF_REQUIRE_UI_THREAD(); - SetTitle(browser, title); + NotifyTitle(title); } bool ClientHandler::OnConsoleMessage(CefRefPtr browser, @@ -289,13 +299,13 @@ void ClientHandler::OnAfterCreated(CefRefPtr browser) { if (mouse_cursor_change_disabled_) browser->GetHost()->SetMouseCursorChangeDisabled(true); - BrowserCreated(browser); + NotifyBrowserCreated(browser); } bool ClientHandler::DoClose(CefRefPtr browser) { CEF_REQUIRE_UI_THREAD(); - BrowserClosing(browser); + NotifyBrowserClosing(browser); // Allow the close. For windowed browsers this will result in the OS close // event being sent. @@ -317,7 +327,7 @@ void ClientHandler::OnBeforeClose(CefRefPtr browser) { message_router_ = NULL; } - BrowserClosed(browser); + NotifyBrowserClosed(browser); } void ClientHandler::OnLoadingStateChange(CefRefPtr browser, @@ -326,7 +336,7 @@ void ClientHandler::OnLoadingStateChange(CefRefPtr browser, bool canGoForward) { CEF_REQUIRE_UI_THREAD(); - SetLoadingState(browser, isLoading, canGoBack, canGoForward); + NotifyLoadingState(isLoading, canGoBack, canGoForward); } void ClientHandler::OnLoadError(CefRefPtr browser, @@ -433,27 +443,6 @@ void ClientHandler::OnRenderProcessTerminated(CefRefPtr browser, frame->LoadURL(startup_url_); } -void ClientHandler::SetMainWindowHandle(ClientWindowHandle handle) { - if (!CefCurrentlyOn(TID_UI)) { - // Execute on the UI thread. - CefPostTask(TID_UI, - base::Bind(&ClientHandler::SetMainWindowHandle, this, handle)); - return; - } - - main_handle_ = handle; - -#if defined(OS_LINUX) - // Associate |handle| with the GTK dialog handler. - dialog_handler_->set_parent(handle); -#endif -} - -ClientWindowHandle ClientHandler::GetMainWindowHandle() const { - CEF_REQUIRE_UI_THREAD(); - return main_handle_; -} - int ClientHandler::GetBrowserCount() const { CEF_REQUIRE_UI_THREAD(); return browser_count_; @@ -476,6 +465,100 @@ void ClientHandler::CloseDevTools(CefRefPtr browser) { browser->GetHost()->CloseDevTools(); } + +bool ClientHandler::CreatePopupWindow( + CefRefPtr browser, + bool is_devtools, + const CefPopupFeatures& popupFeatures, + CefWindowInfo& windowInfo, + CefRefPtr& client, + CefBrowserSettings& settings) { + // Note: This method will be called on multiple threads. + + // The popup browser will be parented to a new native window. + // Don't show URL bar and navigation buttons on DevTools windows. + MainContext::Get()->GetRootWindowManager()->CreateRootWindowAsPopup( + !is_devtools, is_osr(), popupFeatures, windowInfo, client, settings); + + return true; +} + + +void ClientHandler::NotifyBrowserCreated(CefRefPtr browser) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyBrowserCreated, this, browser)); + return; + } + + if (delegate_) + delegate_->OnBrowserCreated(browser); +} + +void ClientHandler::NotifyBrowserClosing(CefRefPtr browser) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyBrowserClosing, this, browser)); + return; + } + + if (delegate_) + delegate_->OnBrowserClosing(browser); +} + +void ClientHandler::NotifyBrowserClosed(CefRefPtr browser) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyBrowserClosed, this, browser)); + return; + } + + if (delegate_) + delegate_->OnBrowserClosed(browser); +} + +void ClientHandler::NotifyAddress(const CefString& url) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyAddress, this, url)); + return; + } + + if (delegate_) + delegate_->OnSetAddress(url); +} + +void ClientHandler::NotifyTitle(const CefString& title) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyTitle, this, title)); + return; + } + + if (delegate_) + delegate_->OnSetTitle(title); +} + +void ClientHandler::NotifyLoadingState(bool isLoading, + bool canGoBack, + bool canGoForward) { + if (!CURRENTLY_ON_MAIN_THREAD()) { + // Execute this method on the main thread. + MAIN_POST_CLOSURE( + base::Bind(&ClientHandler::NotifyLoadingState, this, + isLoading, canGoBack, canGoForward)); + return; + } + + if (delegate_) + delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward); +} + void ClientHandler::BuildTestMenu(CefRefPtr model) { if (model->GetCount() > 0) model->AddSeparator(); diff --git a/tests/cefclient/client_handler.h b/tests/cefclient/client_handler.h index 3a791fc60..1dfe2c33b 100644 --- a/tests/cefclient/client_handler.h +++ b/tests/cefclient/client_handler.h @@ -33,11 +33,45 @@ class ClientHandler : public CefClient, public CefLoadHandler, public CefRequestHandler { public: + // Implement this interface to receive notification of ClientHandler + // events. The methods of this class will be called on the main thread. + class Delegate { + public: + // Called when the browser is created. + virtual void OnBrowserCreated(CefRefPtr browser) = 0; + + // Called when the browser is closing. + virtual void OnBrowserClosing(CefRefPtr browser) = 0; + + // Called when the browser has been closed. + virtual void OnBrowserClosed(CefRefPtr browser) = 0; + + // Set the window URL address. + virtual void OnSetAddress(const std::string& url) = 0; + + // Set the window title. + virtual void OnSetTitle(const std::string& title) = 0; + + // Set the loading state. + virtual void OnSetLoadingState(bool isLoading, + bool canGoBack, + bool canGoForward) = 0; + + protected: + virtual ~Delegate() {} + }; + typedef std::set MessageHandlerSet; - ClientHandler(const std::string& startup_url, - bool is_osr); - ~ClientHandler(); + // Constructor may be called on any thread. + // |delegate| must outlive this object or DetachDelegate() must be called. + ClientHandler(Delegate* delegate, + bool is_osr, + const std::string& startup_url); + + // This object may outlive the Delegate object so it's necessary for the + // Delegate to detach itself before destruction. + void DetachDelegate(); // CefClient methods CefRefPtr GetContextMenuHandler() OVERRIDE { @@ -175,12 +209,6 @@ class ClientHandler : public CefClient, void OnRenderProcessTerminated(CefRefPtr browser, TerminationStatus status) OVERRIDE; - // Set the main frame window handle. - void SetMainWindowHandle(ClientWindowHandle handle); - - // Get the main frame window handle. Can only be called on the CEF UI thread. - ClientWindowHandle GetMainWindowHandle() const; - // Returns the number of browsers currently using this handler. Can only be // called on the CEF UI thread. int GetBrowserCount() const; @@ -198,46 +226,29 @@ class ClientHandler : public CefClient, // Returns true if this handler uses off-screen rendering. bool is_osr() const { return is_osr_; } - protected: - // The following virtual methods are called on the CEF UI thread unless - // otherwise indicated. - - // A browser has been created. - virtual void BrowserCreated(CefRefPtr browser) = 0; - - // A browser is closing. - virtual void BrowserClosing(CefRefPtr browser) = 0; - - // A browser has been closed. - virtual void BrowserClosed(CefRefPtr browser) = 0; - - // Set the window URL address. - virtual void SetAddress(CefRefPtr browser, - const CefString& url) = 0; - - // Set the window title. - virtual void SetTitle(CefRefPtr browser, - const CefString& title) = 0; - - // Set the loading state. - virtual void SetLoadingState(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) = 0; - + private: // Create a new popup window using the specified information. |is_devtools| // will be true if the window will be used for DevTools. Return true to // proceed with popup browser creation or false to cancel the popup browser. // May be called on any thead. - virtual bool CreatePopupWindow( + bool CreatePopupWindow( CefRefPtr browser, bool is_devtools, const CefPopupFeatures& popupFeatures, CefWindowInfo& windowInfo, CefRefPtr& client, - CefBrowserSettings& settings) = 0; + CefBrowserSettings& settings); + + // Execute Delegate notifications on the main thread. + void NotifyBrowserCreated(CefRefPtr browser); + void NotifyBrowserClosing(CefRefPtr browser); + void NotifyBrowserClosed(CefRefPtr browser); + void NotifyAddress(const CefString& url); + void NotifyTitle(const CefString& title); + void NotifyLoadingState(bool isLoading, + bool canGoBack, + bool canGoForward); - private: // Test context menu creation. void BuildTestMenu(CefRefPtr model); bool ExecuteTestMenu(int command_id); @@ -245,12 +256,12 @@ class ClientHandler : public CefClient, // THREAD SAFE MEMBERS // The following members may be accessed from any thread. - // The startup URL. - const std::string startup_url_; - // True if this handler uses off-screen rendering. const bool is_osr_; + // The startup URL. + const std::string startup_url_; + // True if mouse cursor change is disabled. bool mouse_cursor_change_disabled_; @@ -263,6 +274,13 @@ class ClientHandler : public CefClient, // in client_renderer.cc. CefRefPtr message_router_; + // MAIN THREAD MEMBERS + // The following members will only be accessed on the main thread. This will + // be the same as the CEF UI thread except when using multi-threaded message + // loop mode on Windows. + + Delegate* delegate_; + // UI THREAD MEMBERS // The following members will only be accessed on the CEF UI thread. @@ -276,9 +294,6 @@ class ClientHandler : public CefClient, // The current number of browsers using this handler. int browser_count_; - // The main frame window handle. - ClientWindowHandle main_handle_; - // Console logging state. const std::string console_log_file_; bool first_console_message_; diff --git a/tests/cefclient/client_handler_osr.cc b/tests/cefclient/client_handler_osr.cc index ada29b169..044d340fa 100644 --- a/tests/cefclient/client_handler_osr.cc +++ b/tests/cefclient/client_handler_osr.cc @@ -13,7 +13,7 @@ namespace client { ClientHandlerOsr::ClientHandlerOsr(Delegate* delegate, OsrDelegate* osr_delegate, const std::string& startup_url) - : ClientHandlerSingle(delegate, true, startup_url), + : ClientHandler(delegate, true, startup_url), osr_delegate_(osr_delegate) { DCHECK(osr_delegate_); } @@ -33,14 +33,14 @@ void ClientHandlerOsr::OnAfterCreated(CefRefPtr browser) { CEF_REQUIRE_UI_THREAD(); if (osr_delegate_) osr_delegate_->OnAfterCreated(browser); - ClientHandlerSingle::OnAfterCreated(browser); + ClientHandler::OnAfterCreated(browser); } void ClientHandlerOsr::OnBeforeClose(CefRefPtr browser) { CEF_REQUIRE_UI_THREAD(); if (osr_delegate_) osr_delegate_->OnBeforeClose(browser); - ClientHandlerSingle::OnBeforeClose(browser); + ClientHandler::OnBeforeClose(browser); } bool ClientHandlerOsr::GetRootScreenRect(CefRefPtr browser, diff --git a/tests/cefclient/client_handler_osr.h b/tests/cefclient/client_handler_osr.h index 5b80c15c3..ddbfd0009 100644 --- a/tests/cefclient/client_handler_osr.h +++ b/tests/cefclient/client_handler_osr.h @@ -5,13 +5,13 @@ #ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_OSR_H_ #define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_OSR_H_ -#include "cefclient/client_handler_single.h" +#include "cefclient/client_handler.h" namespace client { // Client handler implementation for windowless browsers. There will only ever // be one browser per handler instance. -class ClientHandlerOsr : public ClientHandlerSingle, +class ClientHandlerOsr : public ClientHandler, public CefRenderHandler { public: // Implement this interface to receive notification of ClientHandlerOsr diff --git a/tests/cefclient/client_handler_single.cc b/tests/cefclient/client_handler_single.cc deleted file mode 100644 index 77a54faf7..000000000 --- a/tests/cefclient/client_handler_single.cc +++ /dev/null @@ -1,166 +0,0 @@ -// Copyright (c) 2015 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 "cefclient/client_handler_single.h" - -#include -#include -#include - -#include "include/base/cef_bind.h" -#include "include/cef_command_line.h" -#include "include/wrapper/cef_closure_task.h" -#include "cefclient/main_context.h" -#include "cefclient/main_message_loop.h" -#include "cefclient/root_window_manager.h" - -namespace client { - -ClientHandlerSingle::ClientHandlerSingle(Delegate* delegate, - bool is_osr, - const std::string& startup_url) - : ClientHandler(startup_url, is_osr), - delegate_(delegate) { - DCHECK(delegate_); -} - -void ClientHandlerSingle::DetachDelegate() { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE(base::Bind(&ClientHandlerSingle::DetachDelegate, this)); - return; - } - - DCHECK(delegate_); - delegate_ = NULL; -} - -void ClientHandlerSingle::BrowserCreated(CefRefPtr browser) { - CEF_REQUIRE_UI_THREAD(); - NotifyBrowserCreated(browser); -} - -void ClientHandlerSingle::BrowserClosing(CefRefPtr browser) { - CEF_REQUIRE_UI_THREAD(); - NotifyBrowserClosing(browser); -} - -void ClientHandlerSingle::BrowserClosed(CefRefPtr browser) { - CEF_REQUIRE_UI_THREAD(); - NotifyBrowserClosed(browser); -} - -void ClientHandlerSingle::SetAddress(CefRefPtr browser, - const CefString& url) { - CEF_REQUIRE_UI_THREAD(); - NotifyAddress(url); -} - -void ClientHandlerSingle::SetTitle(CefRefPtr browser, - const CefString& title) { - CEF_REQUIRE_UI_THREAD(); - NotifyTitle(title); -} - -void ClientHandlerSingle::SetLoadingState(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) { - CEF_REQUIRE_UI_THREAD(); - NotifyLoadingState(isLoading, canGoBack, canGoForward); -} - -bool ClientHandlerSingle::CreatePopupWindow( - CefRefPtr browser, - bool is_devtools, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - CefRefPtr& client, - CefBrowserSettings& settings) { - // Note: This method will be called on multiple threads. - - // The popup browser will be parented to a new native window. - // Don't show URL bar and navigation buttons on DevTools windows. - MainContext::Get()->GetRootWindowManager()->CreateRootWindowAsPopup( - !is_devtools, is_osr(), popupFeatures, windowInfo, client, settings); - - return true; -} - -void ClientHandlerSingle::NotifyBrowserCreated(CefRefPtr browser) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyBrowserCreated, this, browser)); - return; - } - - if (delegate_) - delegate_->OnBrowserCreated(browser); -} - -void ClientHandlerSingle::NotifyBrowserClosing(CefRefPtr browser) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyBrowserClosing, this, browser)); - return; - } - - if (delegate_) - delegate_->OnBrowserClosing(browser); -} - -void ClientHandlerSingle::NotifyBrowserClosed(CefRefPtr browser) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyBrowserClosed, this, browser)); - return; - } - - if (delegate_) - delegate_->OnBrowserClosed(browser); -} - -void ClientHandlerSingle::NotifyAddress(const CefString& url) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyAddress, this, url)); - return; - } - - if (delegate_) - delegate_->OnSetAddress(url); -} - -void ClientHandlerSingle::NotifyTitle(const CefString& title) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyTitle, this, title)); - return; - } - - if (delegate_) - delegate_->OnSetTitle(title); -} - -void ClientHandlerSingle::NotifyLoadingState(bool isLoading, - bool canGoBack, - bool canGoForward) { - if (!CURRENTLY_ON_MAIN_THREAD()) { - // Execute this method on the main thread. - MAIN_POST_CLOSURE( - base::Bind(&ClientHandlerSingle::NotifyLoadingState, this, - isLoading, canGoBack, canGoForward)); - return; - } - - if (delegate_) - delegate_->OnSetLoadingState(isLoading, canGoBack, canGoForward); -} - -} // namespace client diff --git a/tests/cefclient/client_handler_single.h b/tests/cefclient/client_handler_single.h deleted file mode 100644 index 1d37ed9af..000000000 --- a/tests/cefclient/client_handler_single.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) 2015 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. - -#ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_SINGLE_H_ -#define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_SINGLE_H_ -#pragma once - -#include -#include - -#include "include/base/cef_lock.h" -#include "cefclient/client_handler.h" - -namespace client { - -// Client handler implementation that is used by a single browser. -class ClientHandlerSingle : public ClientHandler { - public: - // Implement this interface to receive notification of ClientHandlerSingle - // events. The methods of this class will be called on the main thread. - class Delegate { - public: - // Called when the browser is created. - virtual void OnBrowserCreated(CefRefPtr browser) = 0; - - // Called when the browser is closing. - virtual void OnBrowserClosing(CefRefPtr browser) = 0; - - // Called when the browser has been closed. - virtual void OnBrowserClosed(CefRefPtr browser) = 0; - - // Set the window URL address. - virtual void OnSetAddress(const std::string& url) = 0; - - // Set the window title. - virtual void OnSetTitle(const std::string& title) = 0; - - // Set the loading state. - virtual void OnSetLoadingState(bool isLoading, - bool canGoBack, - bool canGoForward) = 0; - - protected: - virtual ~Delegate() {} - }; - - // This object may outlive the Delegate object so it's necessary for the - // Delegate to detach itself before destruction. - void DetachDelegate(); - - protected: - // Constructor may be called on any thread. - // |delegate| must outlive this object or DetachDelegate() must be called. - ClientHandlerSingle(Delegate* delegate, - bool is_osr, - const std::string& startup_url); - - // ClientHandler methods - void BrowserCreated(CefRefPtr browser) OVERRIDE; - void BrowserClosing(CefRefPtr browser) OVERRIDE; - void BrowserClosed(CefRefPtr browser) OVERRIDE; - void SetAddress(CefRefPtr browser, - const CefString& url) OVERRIDE; - void SetTitle(CefRefPtr browser, - const CefString& title) OVERRIDE; - void SetLoadingState(CefRefPtr browser, - bool isLoading, - bool canGoBack, - bool canGoForward) OVERRIDE; - bool CreatePopupWindow( - CefRefPtr browser, - bool is_devtools, - const CefPopupFeatures& popupFeatures, - CefWindowInfo& windowInfo, - CefRefPtr& client, - CefBrowserSettings& settings) OVERRIDE; - - private: - void NotifyBrowserCreated(CefRefPtr browser); - void NotifyBrowserClosing(CefRefPtr browser); - void NotifyBrowserClosed(CefRefPtr browser); - void NotifyAddress(const CefString& url); - void NotifyTitle(const CefString& title); - void NotifyLoadingState(bool isLoading, - bool canGoBack, - bool canGoForward); - - // Only accessed on the main thread. - Delegate* delegate_; - - DISALLOW_COPY_AND_ASSIGN(ClientHandlerSingle); -}; - -} // namespace client - -#endif // CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_SINGLE_H_ diff --git a/tests/cefclient/client_handler_std.cc b/tests/cefclient/client_handler_std.cc index 983db5083..a2919c345 100644 --- a/tests/cefclient/client_handler_std.cc +++ b/tests/cefclient/client_handler_std.cc @@ -8,7 +8,7 @@ namespace client { ClientHandlerStd::ClientHandlerStd(Delegate* delegate, const std::string& startup_url) - : ClientHandlerSingle(delegate, false, startup_url) { + : ClientHandler(delegate, false, startup_url) { } } // namespace client diff --git a/tests/cefclient/client_handler_std.h b/tests/cefclient/client_handler_std.h index f8bc7696f..d162a0199 100644 --- a/tests/cefclient/client_handler_std.h +++ b/tests/cefclient/client_handler_std.h @@ -5,13 +5,13 @@ #ifndef CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_STD_H_ #define CEF_TESTS_CEFCLIENT_CLIENT_HANDLER_STD_H_ -#include "cefclient/client_handler_single.h" +#include "cefclient/client_handler.h" namespace client { // Client handler implementation for windowed browsers. There will only ever be // one browser per handler instance. -class ClientHandlerStd : public ClientHandlerSingle { +class ClientHandlerStd : public ClientHandler { public: ClientHandlerStd(Delegate* delegate, const std::string& startup_url); diff --git a/tests/cefclient/dialog_handler_gtk.cc b/tests/cefclient/dialog_handler_gtk.cc index e99591a85..684966d46 100644 --- a/tests/cefclient/dialog_handler_gtk.cc +++ b/tests/cefclient/dialog_handler_gtk.cc @@ -3,9 +3,11 @@ // can be found in the LICENSE file. #include "cefclient/dialog_handler_gtk.h" + #include "include/cef_browser.h" #include "include/cef_url.h" #include "include/wrapper/cef_helpers.h" +#include "cefclient/root_window.h" namespace client { @@ -124,12 +126,19 @@ void AddFilters(GtkFileChooser* chooser, } } +GtkWidget* GetWindow(CefRefPtr browser) { + scoped_refptr root_window = + RootWindow::GetForBrowser(browser->GetIdentifier()); + if (root_window.get()) + return root_window->GetWindowHandle(); + return NULL; +} + } // namespace ClientDialogHandlerGtk::ClientDialogHandlerGtk() - : gtk_parent_(NULL), - gtk_dialog_(NULL) { + : gtk_dialog_(NULL) { } bool ClientDialogHandlerGtk::OnFileDialog( @@ -185,9 +194,9 @@ bool ClientDialogHandlerGtk::OnFileDialog( } } - DCHECK(gtk_parent_); - GtkWidget* window = gtk_widget_get_ancestor( - GTK_WIDGET(gtk_parent_), GTK_TYPE_WINDOW); + GtkWidget* window = GetWindow(browser); + DCHECK(window); + GtkWidget* dialog = gtk_file_chooser_dialog_new( title_str.c_str(), GTK_WINDOW(window), @@ -310,9 +319,9 @@ bool ClientDialogHandlerGtk::OnJSDialog( title += origin_url.ToString(); } - DCHECK(gtk_parent_); - GtkWidget* window = gtk_widget_get_ancestor( - GTK_WIDGET(gtk_parent_), GTK_TYPE_WINDOW); + GtkWidget* window = GetWindow(browser); + DCHECK(window); + gtk_dialog_ = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, gtk_message_type, diff --git a/tests/cefclient/dialog_handler_gtk.h b/tests/cefclient/dialog_handler_gtk.h index fa772c299..2ad177d8f 100644 --- a/tests/cefclient/dialog_handler_gtk.h +++ b/tests/cefclient/dialog_handler_gtk.h @@ -43,16 +43,11 @@ class ClientDialogHandlerGtk : public CefDialogHandler, CefRefPtr callback) OVERRIDE; void OnResetDialogState(CefRefPtr browser) OVERRIDE; - void set_parent(GtkWidget* parent) { - gtk_parent_ = parent; - } - private: static void OnDialogResponse(GtkDialog *dialog, gint response_id, ClientDialogHandlerGtk* handler); - GtkWidget* gtk_parent_; GtkWidget* gtk_dialog_; CefRefPtr js_dialog_callback_; diff --git a/tests/cefclient/root_window.cc b/tests/cefclient/root_window.cc index 5ccbf1ca4..6c4b5b4d4 100644 --- a/tests/cefclient/root_window.cc +++ b/tests/cefclient/root_window.cc @@ -10,7 +10,7 @@ namespace client { // static -scoped_refptr GetForBrowser(int browser_id) { +scoped_refptr RootWindow::GetForBrowser(int browser_id) { return MainContext::Get()->GetRootWindowManager()->GetWindowForBrowser( browser_id); } diff --git a/tests/cefclient/root_window_manager.h b/tests/cefclient/root_window_manager.h index 6e26f215b..2ff330b15 100644 --- a/tests/cefclient/root_window_manager.h +++ b/tests/cefclient/root_window_manager.h @@ -43,7 +43,7 @@ class RootWindowManager : public RootWindow::Delegate { // Create a new native popup window. // If |with_controls| is true the window will show controls. // If |with_osr| is true the window will use off-screen rendering. - // This method is called from ClientHandlerSingle::CreatePopupWindow() to + // This method is called from ClientHandler::CreatePopupWindow() to // create a new popup or DevTools window. scoped_refptr CreateRootWindowAsPopup( bool with_controls, diff --git a/tests/cefclient/window_test_gtk.cc b/tests/cefclient/window_test_gtk.cc index 13036a591..7492825d5 100644 --- a/tests/cefclient/window_test_gtk.cc +++ b/tests/cefclient/window_test_gtk.cc @@ -3,22 +3,22 @@ // can be found in the LICENSE file. #include "cefclient/window_test.h" -#include "cefclient/client_handler.h" #include +#include "cefclient/root_window.h" + namespace client { namespace window_test { namespace { GtkWindow* GetWindow(CefRefPtr browser) { - // We can't get the GtkWidget* from the X11 Window that would be returned via - // CefBrowserHost::GetWindowHandle so retrieve it via the ClientHandler - // instance instead. - CefRefPtr handler = - static_cast(browser->GetHost()->GetClient().get()); - return GTK_WINDOW(gtk_widget_get_toplevel(handler->GetMainWindowHandle())); + scoped_refptr root_window = + RootWindow::GetForBrowser(browser->GetIdentifier()); + if (root_window.get()) + return GTK_WINDOW(root_window->GetWindowHandle()); + return NULL; } bool IsMaximized(GtkWindow* window) {