ShowDevTools should inspect element in existing window (issue #1487)

This commit is contained in:
Marshall Greenblatt 2016-06-10 12:43:53 -04:00
parent acdb4bb564
commit b23c0f1097
3 changed files with 17 additions and 17 deletions

View File

@ -805,6 +805,10 @@ void CefBrowserHostImpl::ShowDevTools(
return; return;
if (devtools_frontend_) { if (devtools_frontend_) {
if (!inspect_element_at.IsEmpty()) {
devtools_frontend_->InspectElementAt(inspect_element_at.x,
inspect_element_at.y);
}
devtools_frontend_->Focus(); devtools_frontend_->Focus();
return; return;
} }

View File

@ -123,38 +123,28 @@ CefDevToolsFrontend* CefDevToolsFrontend::Show(
CefBrowserHostImpl::Create(create_params); CefBrowserHostImpl::Create(create_params);
content::WebContents* inspected_contents = inspected_browser->web_contents(); content::WebContents* inspected_contents = inspected_browser->web_contents();
if (!inspect_element_at.IsEmpty()) {
scoped_refptr<content::DevToolsAgentHost> agent_host =
content::DevToolsAgentHost::GetOrCreateFor(inspected_contents);
agent_host->InspectElement(inspect_element_at.x, inspect_element_at.y);
}
// CefDevToolsFrontend will delete itself when the frontend WebContents is // CefDevToolsFrontend will delete itself when the frontend WebContents is
// destroyed. // destroyed.
CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend( CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend(
static_cast<CefBrowserHostImpl*>(frontend_browser.get()), static_cast<CefBrowserHostImpl*>(frontend_browser.get()),
inspected_contents); inspected_contents, inspect_element_at);
// Need to load the URL after creating the DevTools objects. // Need to load the URL after creating the DevTools objects.
CefDevToolsDelegate* delegate = CefDevToolsDelegate* delegate =
CefContentBrowserClient::Get()->devtools_delegate(); CefContentBrowserClient::Get()->devtools_delegate();
frontend_browser->GetMainFrame()->LoadURL(delegate->GetChromeDevToolsURL()); frontend_browser->GetMainFrame()->LoadURL(delegate->GetChromeDevToolsURL());
devtools_frontend->Activate();
devtools_frontend->Focus();
return devtools_frontend; return devtools_frontend;
} }
void CefDevToolsFrontend::Activate() {
frontend_browser_->ActivateContents(web_contents());
}
void CefDevToolsFrontend::Focus() { void CefDevToolsFrontend::Focus() {
web_contents()->Focus(); frontend_browser_->SetFocus(true);
} }
void CefDevToolsFrontend::InspectElementAt(int x, int y) { void CefDevToolsFrontend::InspectElementAt(int x, int y) {
if (inspect_element_at_.x != x || inspect_element_at_.y != y)
inspect_element_at_.Set(x, y);
if (agent_host_) if (agent_host_)
agent_host_->InspectElement(x, y); agent_host_->InspectElement(x, y);
} }
@ -174,10 +164,12 @@ void CefDevToolsFrontend::DisconnectFromTarget() {
CefDevToolsFrontend::CefDevToolsFrontend( CefDevToolsFrontend::CefDevToolsFrontend(
CefRefPtr<CefBrowserHostImpl> frontend_browser, CefRefPtr<CefBrowserHostImpl> frontend_browser,
content::WebContents* inspected_contents) content::WebContents* inspected_contents,
const CefPoint& inspect_element_at)
: WebContentsObserver(frontend_browser->web_contents()), : WebContentsObserver(frontend_browser->web_contents()),
frontend_browser_(frontend_browser), frontend_browser_(frontend_browser),
inspected_contents_(inspected_contents), inspected_contents_(inspected_contents),
inspect_element_at_(inspect_element_at),
weak_factory_(this) { weak_factory_(this) {
} }
@ -206,6 +198,9 @@ void CefDevToolsFrontend::DocumentAvailableInMainFrame() {
if (agent_host != agent_host_) { if (agent_host != agent_host_) {
agent_host_ = agent_host; agent_host_ = agent_host;
agent_host_->AttachClient(this); agent_host_->AttachClient(this);
if (!inspect_element_at_.IsEmpty())
InspectElementAt(inspect_element_at_.x, inspect_element_at_.y);
} }
} }

View File

@ -36,7 +36,6 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
const CefBrowserSettings& settings, const CefBrowserSettings& settings,
const CefPoint& inspect_element_at); const CefPoint& inspect_element_at);
void Activate();
void Focus(); void Focus();
void InspectElementAt(int x, int y); void InspectElementAt(int x, int y);
void Close(); void Close();
@ -54,7 +53,8 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
private: private:
CefDevToolsFrontend(CefRefPtr<CefBrowserHostImpl> frontend_browser, CefDevToolsFrontend(CefRefPtr<CefBrowserHostImpl> frontend_browser,
content::WebContents* inspected_contents); content::WebContents* inspected_contents,
const CefPoint& inspect_element_at);
~CefDevToolsFrontend() override; ~CefDevToolsFrontend() override;
// content::DevToolsAgentHostClient implementation. // content::DevToolsAgentHostClient implementation.
@ -79,6 +79,7 @@ class CefDevToolsFrontend : public content::WebContentsObserver,
CefRefPtr<CefBrowserHostImpl> frontend_browser_; CefRefPtr<CefBrowserHostImpl> frontend_browser_;
content::WebContents* inspected_contents_; content::WebContents* inspected_contents_;
CefPoint inspect_element_at_;
scoped_refptr<content::DevToolsAgentHost> agent_host_; scoped_refptr<content::DevToolsAgentHost> agent_host_;
std::unique_ptr<content::DevToolsFrontendHost> frontend_host_; std::unique_ptr<content::DevToolsFrontendHost> frontend_host_;
using PendingRequestsMap = std::map<const net::URLFetcher*, int>; using PendingRequestsMap = std::map<const net::URLFetcher*, int>;