cefclient: Don't create multiple DevTools windows (issue #1920)

This commit is contained in:
Marshall Greenblatt 2016-06-10 14:33:07 -04:00
parent b23c0f1097
commit 18d882b5d2
8 changed files with 96 additions and 35 deletions

View File

@ -448,10 +448,13 @@ typedef struct _cef_browser_host_t {
int clearSelection);
///
// Open developer tools in its own window. If |inspect_element_at| is non-
// NULL the element at the specified (x,y) location will be inspected. The
// |windowInfo| parameter will be ignored if this browser is wrapped in a
// cef_browser_view_t.
// Open developer tools (DevTools) in its own browser. The DevTools browser
// will remain associated with this browser. If the DevTools browser is
// already open then it will be focused, in which case the |windowInfo|,
// |client| and |settings| parameters will be ignored. If |inspect_element_at|
// is non-NULL then the element at the specified (x,y) location will be
// inspected. The |windowInfo| parameter will be ignored if this browser is
// wrapped in a cef_browser_view_t.
///
void (CEF_CALLBACK *show_dev_tools)(struct _cef_browser_host_t* self,
const struct _cef_window_info_t* windowInfo,
@ -460,11 +463,16 @@ typedef struct _cef_browser_host_t {
const cef_point_t* inspect_element_at);
///
// Explicitly close the developer tools window if one exists for this browser
// instance.
// Explicitly close the associated DevTools browser, if any.
///
void (CEF_CALLBACK *close_dev_tools)(struct _cef_browser_host_t* self);
///
// Returns true (1) if this browser currently has an associated DevTools
// browser. Must be called on the browser process UI thread.
///
int (CEF_CALLBACK *has_dev_tools)(struct _cef_browser_host_t* self);
///
// Retrieve a snapshot of current navigation entries as values sent to the
// specified visitor. If |current_only| is true (1) only the current

View File

@ -490,24 +490,34 @@ class CefBrowserHost : public virtual CefBase {
virtual void StopFinding(bool clearSelection) =0;
///
// Open developer tools in its own window. If |inspect_element_at| is non-
// empty the element at the specified (x,y) location will be inspected. The
// |windowInfo| parameter will be ignored if this browser is wrapped in a
// CefBrowserView.
// Open developer tools (DevTools) in its own browser. The DevTools browser
// will remain associated with this browser. If the DevTools browser is
// already open then it will be focused, in which case the |windowInfo|,
// |client| and |settings| parameters will be ignored. If |inspect_element_at|
// is non-empty then the element at the specified (x,y) location will be
// inspected. The |windowInfo| parameter will be ignored if this browser is
// wrapped in a CefBrowserView.
///
/*--cef(optional_param=inspect_element_at)--*/
/*--cef(optional_param=windowInfo,optional_param=client,
optional_param=settings,optional_param=inspect_element_at)--*/
virtual void ShowDevTools(const CefWindowInfo& windowInfo,
CefRefPtr<CefClient> client,
const CefBrowserSettings& settings,
const CefPoint& inspect_element_at) =0;
///
// Explicitly close the developer tools window if one exists for this browser
// instance.
// Explicitly close the associated DevTools browser, if any.
///
/*--cef()--*/
virtual void CloseDevTools() =0;
///
// Returns true if this browser currently has an associated DevTools browser.
// Must be called on the browser process UI thread.
///
/*--cef()--*/
virtual bool HasDevTools() =0;
///
// Retrieve a snapshot of current navigation entries as values sent to the
// specified visitor. If |current_only| is true only the current navigation

View File

@ -836,6 +836,15 @@ void CefBrowserHostImpl::CloseDevTools() {
}
}
bool CefBrowserHostImpl::HasDevTools() {
if (!CEF_CURRENTLY_ON_UIT()) {
NOTREACHED() << "called on invalid thread";
return false;
}
return (devtools_frontend_ != nullptr);
}
void CefBrowserHostImpl::GetNavigationEntries(
CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) {

View File

@ -180,6 +180,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
const CefBrowserSettings& settings,
const CefPoint& inspect_element_at) override;
void CloseDevTools() override;
bool HasDevTools() override;
void GetNavigationEntries(
CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) override;

View File

@ -425,19 +425,7 @@ void CEF_CALLBACK browser_host_show_dev_tools(struct _cef_browser_host_t* self,
DCHECK(self);
if (!self)
return;
// Verify param: windowInfo; type: struct_byref_const
DCHECK(windowInfo);
if (!windowInfo)
return;
// Verify param: client; type: refptr_diff
DCHECK(client);
if (!client)
return;
// Verify param: settings; type: struct_byref_const
DCHECK(settings);
if (!settings)
return;
// Unverified params: inspect_element_at
// Unverified params: windowInfo, client, settings, inspect_element_at
// Translate param: windowInfo; type: struct_byref_const
CefWindowInfo windowInfoObj;
@ -471,6 +459,20 @@ void CEF_CALLBACK browser_host_close_dev_tools(
CefBrowserHostCppToC::Get(self)->CloseDevTools();
}
int CEF_CALLBACK browser_host_has_dev_tools(struct _cef_browser_host_t* self) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return 0;
// Execute
bool _retval = CefBrowserHostCppToC::Get(self)->HasDevTools();
// Return type: bool
return _retval;
}
void CEF_CALLBACK browser_host_get_navigation_entries(
struct _cef_browser_host_t* self, cef_navigation_entry_visitor_t* visitor,
int current_only) {
@ -962,6 +964,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() {
GetStruct()->stop_finding = browser_host_stop_finding;
GetStruct()->show_dev_tools = browser_host_show_dev_tools;
GetStruct()->close_dev_tools = browser_host_close_dev_tools;
GetStruct()->has_dev_tools = browser_host_has_dev_tools;
GetStruct()->get_navigation_entries = browser_host_get_navigation_entries;
GetStruct()->set_mouse_cursor_change_disabled =
browser_host_set_mouse_cursor_change_disabled;

View File

@ -375,11 +375,7 @@ void CefBrowserHostCToCpp::ShowDevTools(const CefWindowInfo& windowInfo,
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: client; type: refptr_diff
DCHECK(client.get());
if (!client.get())
return;
// Unverified params: inspect_element_at
// Unverified params: windowInfo, client, settings, inspect_element_at
// Execute
_struct->show_dev_tools(_struct,
@ -400,6 +396,20 @@ void CefBrowserHostCToCpp::CloseDevTools() {
_struct->close_dev_tools(_struct);
}
bool CefBrowserHostCToCpp::HasDevTools() {
cef_browser_host_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, has_dev_tools))
return false;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Execute
int _retval = _struct->has_dev_tools(_struct);
// Return type: bool
return _retval?true:false;
}
void CefBrowserHostCToCpp::GetNavigationEntries(
CefRefPtr<CefNavigationEntryVisitor> visitor, bool current_only) {
cef_browser_host_t* _struct = GetStruct();

View File

@ -63,6 +63,7 @@ class CefBrowserHostCToCpp
CefRefPtr<CefClient> client, const CefBrowserSettings& settings,
const CefPoint& inspect_element_at) OVERRIDE;
void CloseDevTools() OVERRIDE;
bool HasDevTools() OVERRIDE;
void GetNavigationEntries(CefRefPtr<CefNavigationEntryVisitor> visitor,
bool current_only) OVERRIDE;
void SetMouseCursorChangeDisabled(bool disabled) OVERRIDE;

View File

@ -687,14 +687,33 @@ int ClientHandler::GetBrowserCount() const {
void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser,
const CefPoint& inspect_element_at) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&ClientHandler::ShowDevTools, this, browser,
inspect_element_at));
return;
}
CefWindowInfo windowInfo;
CefRefPtr<CefClient> client;
CefBrowserSettings settings;
if (CreatePopupWindow(browser, true, CefPopupFeatures(), windowInfo, client,
settings)) {
browser->GetHost()->ShowDevTools(windowInfo, client, settings,
inspect_element_at);
CefRefPtr<CefBrowserHost> host = browser->GetHost();
// Test if the DevTools browser already exists.
bool has_devtools = host->HasDevTools();
if (!has_devtools) {
// Create a new RootWindow for the DevTools browser that will be created
// by ShowDevTools().
has_devtools = CreatePopupWindow(browser, true, CefPopupFeatures(),
windowInfo, client, settings);
}
if (has_devtools) {
// Create the DevTools browser if it doesn't already exist.
// Otherwise, focus the existing DevTools browser and inspect the element
// at |inspect_element_at| if non-empty.
host->ShowDevTools(windowInfo, client, settings, inspect_element_at);
}
}