diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 754c2ae27..abd54dd49 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -805,6 +805,10 @@ void CefBrowserHostImpl::ShowDevTools( return; if (devtools_frontend_) { + if (!inspect_element_at.IsEmpty()) { + devtools_frontend_->InspectElementAt(inspect_element_at.x, + inspect_element_at.y); + } devtools_frontend_->Focus(); return; } diff --git a/libcef/browser/devtools_frontend.cc b/libcef/browser/devtools_frontend.cc index 7af2b7e2b..c2d18059d 100644 --- a/libcef/browser/devtools_frontend.cc +++ b/libcef/browser/devtools_frontend.cc @@ -123,38 +123,28 @@ CefDevToolsFrontend* CefDevToolsFrontend::Show( CefBrowserHostImpl::Create(create_params); content::WebContents* inspected_contents = inspected_browser->web_contents(); - if (!inspect_element_at.IsEmpty()) { - scoped_refptr 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 // destroyed. CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend( static_cast(frontend_browser.get()), - inspected_contents); + inspected_contents, inspect_element_at); // Need to load the URL after creating the DevTools objects. CefDevToolsDelegate* delegate = CefContentBrowserClient::Get()->devtools_delegate(); frontend_browser->GetMainFrame()->LoadURL(delegate->GetChromeDevToolsURL()); - devtools_frontend->Activate(); - devtools_frontend->Focus(); - return devtools_frontend; } -void CefDevToolsFrontend::Activate() { - frontend_browser_->ActivateContents(web_contents()); -} - void CefDevToolsFrontend::Focus() { - web_contents()->Focus(); + frontend_browser_->SetFocus(true); } 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_) agent_host_->InspectElement(x, y); } @@ -174,10 +164,12 @@ void CefDevToolsFrontend::DisconnectFromTarget() { CefDevToolsFrontend::CefDevToolsFrontend( CefRefPtr frontend_browser, - content::WebContents* inspected_contents) + content::WebContents* inspected_contents, + const CefPoint& inspect_element_at) : WebContentsObserver(frontend_browser->web_contents()), frontend_browser_(frontend_browser), inspected_contents_(inspected_contents), + inspect_element_at_(inspect_element_at), weak_factory_(this) { } @@ -206,6 +198,9 @@ void CefDevToolsFrontend::DocumentAvailableInMainFrame() { if (agent_host != agent_host_) { agent_host_ = agent_host; agent_host_->AttachClient(this); + + if (!inspect_element_at_.IsEmpty()) + InspectElementAt(inspect_element_at_.x, inspect_element_at_.y); } } diff --git a/libcef/browser/devtools_frontend.h b/libcef/browser/devtools_frontend.h index 57007ff7c..b0e4e697b 100644 --- a/libcef/browser/devtools_frontend.h +++ b/libcef/browser/devtools_frontend.h @@ -36,7 +36,6 @@ class CefDevToolsFrontend : public content::WebContentsObserver, const CefBrowserSettings& settings, const CefPoint& inspect_element_at); - void Activate(); void Focus(); void InspectElementAt(int x, int y); void Close(); @@ -54,7 +53,8 @@ class CefDevToolsFrontend : public content::WebContentsObserver, private: CefDevToolsFrontend(CefRefPtr frontend_browser, - content::WebContents* inspected_contents); + content::WebContents* inspected_contents, + const CefPoint& inspect_element_at); ~CefDevToolsFrontend() override; // content::DevToolsAgentHostClient implementation. @@ -79,6 +79,7 @@ class CefDevToolsFrontend : public content::WebContentsObserver, CefRefPtr frontend_browser_; content::WebContents* inspected_contents_; + CefPoint inspect_element_at_; scoped_refptr agent_host_; std::unique_ptr frontend_host_; using PendingRequestsMap = std::map;