mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-24 07:58:11 +01:00
cefclient: Remove ClientHandler abstraction that is no longer necessary now that all platforms use RootWindow (issue #1500).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@2008 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
bd9b578f05
commit
50380c7be4
@ -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',
|
||||
|
@ -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<CefBrowser> browser) OVERRIDE;
|
||||
void OnBrowserClosing(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
void OnBrowserClosed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
@ -102,7 +102,7 @@ class BrowserWindow : public ClientHandlerSingle::Delegate {
|
||||
|
||||
Delegate* delegate_;
|
||||
CefRefPtr<CefBrowser> browser_;
|
||||
CefRefPtr<ClientHandlerSingle> client_handler_;
|
||||
CefRefPtr<ClientHandler> client_handler_;
|
||||
bool is_closing_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(BrowserWindow);
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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<CefBrowser> browser,
|
||||
|
||||
// Only update the address for the main (top-level) frame.
|
||||
if (frame->IsMain())
|
||||
SetAddress(browser, url);
|
||||
NotifyAddress(url);
|
||||
}
|
||||
|
||||
void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
SetTitle(browser, title);
|
||||
NotifyTitle(title);
|
||||
}
|
||||
|
||||
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
|
||||
@ -289,13 +299,13 @@ void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
|
||||
if (mouse_cursor_change_disabled_)
|
||||
browser->GetHost()->SetMouseCursorChangeDisabled(true);
|
||||
|
||||
BrowserCreated(browser);
|
||||
NotifyBrowserCreated(browser);
|
||||
}
|
||||
|
||||
bool ClientHandler::DoClose(CefRefPtr<CefBrowser> 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<CefBrowser> browser) {
|
||||
message_router_ = NULL;
|
||||
}
|
||||
|
||||
BrowserClosed(browser);
|
||||
NotifyBrowserClosed(browser);
|
||||
}
|
||||
|
||||
void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
@ -326,7 +336,7 @@ void ClientHandler::OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
|
||||
bool canGoForward) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
|
||||
SetLoadingState(browser, isLoading, canGoBack, canGoForward);
|
||||
NotifyLoadingState(isLoading, canGoBack, canGoForward);
|
||||
}
|
||||
|
||||
void ClientHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
|
||||
@ -433,27 +443,6 @@ void ClientHandler::OnRenderProcessTerminated(CefRefPtr<CefBrowser> 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<CefBrowser> browser) {
|
||||
browser->GetHost()->CloseDevTools();
|
||||
}
|
||||
|
||||
|
||||
bool ClientHandler::CreatePopupWindow(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
bool is_devtools,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& 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<CefBrowser> 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<CefBrowser> 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<CefBrowser> 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<CefMenuModel> model) {
|
||||
if (model->GetCount() > 0)
|
||||
model->AddSeparator();
|
||||
|
@ -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<CefBrowser> browser) = 0;
|
||||
|
||||
// Called when the browser is closing.
|
||||
virtual void OnBrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
|
||||
|
||||
// Called when the browser has been closed.
|
||||
virtual void OnBrowserClosed(CefRefPtr<CefBrowser> 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<CefMessageRouterBrowserSide::Handler*> 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<CefContextMenuHandler> GetContextMenuHandler() OVERRIDE {
|
||||
@ -175,12 +209,6 @@ class ClientHandler : public CefClient,
|
||||
void OnRenderProcessTerminated(CefRefPtr<CefBrowser> 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<CefBrowser> browser) = 0;
|
||||
|
||||
// A browser is closing.
|
||||
virtual void BrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
|
||||
|
||||
// A browser has been closed.
|
||||
virtual void BrowserClosed(CefRefPtr<CefBrowser> browser) = 0;
|
||||
|
||||
// Set the window URL address.
|
||||
virtual void SetAddress(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url) = 0;
|
||||
|
||||
// Set the window title.
|
||||
virtual void SetTitle(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) = 0;
|
||||
|
||||
// Set the loading state.
|
||||
virtual void SetLoadingState(CefRefPtr<CefBrowser> 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<CefBrowser> browser,
|
||||
bool is_devtools,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) = 0;
|
||||
CefBrowserSettings& settings);
|
||||
|
||||
// Execute Delegate notifications on the main thread.
|
||||
void NotifyBrowserCreated(CefRefPtr<CefBrowser> browser);
|
||||
void NotifyBrowserClosing(CefRefPtr<CefBrowser> browser);
|
||||
void NotifyBrowserClosed(CefRefPtr<CefBrowser> 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<CefMenuModel> 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<CefMessageRouterBrowserSide> 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_;
|
||||
|
@ -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<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (osr_delegate_)
|
||||
osr_delegate_->OnAfterCreated(browser);
|
||||
ClientHandlerSingle::OnAfterCreated(browser);
|
||||
ClientHandler::OnAfterCreated(browser);
|
||||
}
|
||||
|
||||
void ClientHandlerOsr::OnBeforeClose(CefRefPtr<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
if (osr_delegate_)
|
||||
osr_delegate_->OnBeforeClose(browser);
|
||||
ClientHandlerSingle::OnBeforeClose(browser);
|
||||
ClientHandler::OnBeforeClose(browser);
|
||||
}
|
||||
|
||||
bool ClientHandlerOsr::GetRootScreenRect(CefRefPtr<CefBrowser> browser,
|
||||
|
@ -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
|
||||
|
@ -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 <stdio.h>
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
#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<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyBrowserCreated(browser);
|
||||
}
|
||||
|
||||
void ClientHandlerSingle::BrowserClosing(CefRefPtr<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyBrowserClosing(browser);
|
||||
}
|
||||
|
||||
void ClientHandlerSingle::BrowserClosed(CefRefPtr<CefBrowser> browser) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyBrowserClosed(browser);
|
||||
}
|
||||
|
||||
void ClientHandlerSingle::SetAddress(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyAddress(url);
|
||||
}
|
||||
|
||||
void ClientHandlerSingle::SetTitle(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyTitle(title);
|
||||
}
|
||||
|
||||
void ClientHandlerSingle::SetLoadingState(CefRefPtr<CefBrowser> browser,
|
||||
bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) {
|
||||
CEF_REQUIRE_UI_THREAD();
|
||||
NotifyLoadingState(isLoading, canGoBack, canGoForward);
|
||||
}
|
||||
|
||||
bool ClientHandlerSingle::CreatePopupWindow(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
bool is_devtools,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& 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<CefBrowser> 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<CefBrowser> 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<CefBrowser> 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
|
@ -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 <list>
|
||||
#include <string>
|
||||
|
||||
#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<CefBrowser> browser) = 0;
|
||||
|
||||
// Called when the browser is closing.
|
||||
virtual void OnBrowserClosing(CefRefPtr<CefBrowser> browser) = 0;
|
||||
|
||||
// Called when the browser has been closed.
|
||||
virtual void OnBrowserClosed(CefRefPtr<CefBrowser> 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<CefBrowser> browser) OVERRIDE;
|
||||
void BrowserClosing(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
void BrowserClosed(CefRefPtr<CefBrowser> browser) OVERRIDE;
|
||||
void SetAddress(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& url) OVERRIDE;
|
||||
void SetTitle(CefRefPtr<CefBrowser> browser,
|
||||
const CefString& title) OVERRIDE;
|
||||
void SetLoadingState(CefRefPtr<CefBrowser> browser,
|
||||
bool isLoading,
|
||||
bool canGoBack,
|
||||
bool canGoForward) OVERRIDE;
|
||||
bool CreatePopupWindow(
|
||||
CefRefPtr<CefBrowser> browser,
|
||||
bool is_devtools,
|
||||
const CefPopupFeatures& popupFeatures,
|
||||
CefWindowInfo& windowInfo,
|
||||
CefRefPtr<CefClient>& client,
|
||||
CefBrowserSettings& settings) OVERRIDE;
|
||||
|
||||
private:
|
||||
void NotifyBrowserCreated(CefRefPtr<CefBrowser> browser);
|
||||
void NotifyBrowserClosing(CefRefPtr<CefBrowser> browser);
|
||||
void NotifyBrowserClosed(CefRefPtr<CefBrowser> 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_
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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<CefBrowser> browser) {
|
||||
scoped_refptr<RootWindow> 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,
|
||||
|
@ -43,16 +43,11 @@ class ClientDialogHandlerGtk : public CefDialogHandler,
|
||||
CefRefPtr<CefJSDialogCallback> callback) OVERRIDE;
|
||||
void OnResetDialogState(CefRefPtr<CefBrowser> 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<CefJSDialogCallback> js_dialog_callback_;
|
||||
|
||||
|
@ -10,7 +10,7 @@
|
||||
namespace client {
|
||||
|
||||
// static
|
||||
scoped_refptr<RootWindow> GetForBrowser(int browser_id) {
|
||||
scoped_refptr<RootWindow> RootWindow::GetForBrowser(int browser_id) {
|
||||
return MainContext::Get()->GetRootWindowManager()->GetWindowForBrowser(
|
||||
browser_id);
|
||||
}
|
||||
|
@ -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<RootWindow> CreateRootWindowAsPopup(
|
||||
bool with_controls,
|
||||
|
@ -3,22 +3,22 @@
|
||||
// can be found in the LICENSE file.
|
||||
|
||||
#include "cefclient/window_test.h"
|
||||
#include "cefclient/client_handler.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "cefclient/root_window.h"
|
||||
|
||||
namespace client {
|
||||
namespace window_test {
|
||||
|
||||
namespace {
|
||||
|
||||
GtkWindow* GetWindow(CefRefPtr<CefBrowser> 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<ClientHandler> handler =
|
||||
static_cast<ClientHandler*>(browser->GetHost()->GetClient().get());
|
||||
return GTK_WINDOW(gtk_widget_get_toplevel(handler->GetMainWindowHandle()));
|
||||
scoped_refptr<RootWindow> root_window =
|
||||
RootWindow::GetForBrowser(browser->GetIdentifier());
|
||||
if (root_window.get())
|
||||
return GTK_WINDOW(root_window->GetWindowHandle());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool IsMaximized(GtkWindow* window) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user