2024-04-17 18:01:26 +02:00
|
|
|
// Copyright 2024 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.
|
|
|
|
|
2024-07-02 20:27:11 +02:00
|
|
|
#include "cef/libcef/browser/devtools/devtools_window_runner.h"
|
2024-04-17 18:01:26 +02:00
|
|
|
|
2024-04-30 17:45:07 +02:00
|
|
|
#include "cef/libcef/browser/chrome/chrome_browser_host_impl.h"
|
|
|
|
#include "cef/libcef/browser/request_context_impl.h"
|
|
|
|
#include "cef/libcef/browser/thread_util.h"
|
2024-04-17 18:01:26 +02:00
|
|
|
#include "chrome/browser/devtools/devtools_window.h"
|
|
|
|
|
2024-07-02 20:27:11 +02:00
|
|
|
void CefDevToolsWindowRunner::ShowDevTools(
|
2024-04-17 18:01:26 +02:00
|
|
|
CefBrowserHostBase* opener,
|
|
|
|
std::unique_ptr<CefShowDevToolsParams> params) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
auto* web_contents = opener->GetWebContents();
|
|
|
|
if (!web_contents) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto* profile = CefRequestContextImpl::GetProfile(opener->request_context());
|
|
|
|
if (!DevToolsWindow::AllowDevToolsFor(profile, web_contents)) {
|
|
|
|
LOG(WARNING) << "DevTools is not allowed for this browser";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto inspect_element_at = params->inspect_element_at_;
|
|
|
|
|
|
|
|
if (!browser_host_) {
|
|
|
|
// Configure parameters for ChromeBrowserDelegate::CreateDevToolsBrowser
|
|
|
|
// which will be called indirectly to create the DevTools window.
|
|
|
|
DCHECK(!pending_params_);
|
|
|
|
pending_params_ = std::move(params);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Focus the existing DevTools window or create a new one.
|
|
|
|
if (!inspect_element_at.IsEmpty()) {
|
|
|
|
DevToolsWindow::InspectElement(web_contents->GetPrimaryMainFrame(),
|
|
|
|
inspect_element_at.x, inspect_element_at.y);
|
|
|
|
} else {
|
|
|
|
DevToolsWindow::OpenDevToolsWindow(web_contents, profile,
|
|
|
|
DevToolsOpenedByAction::kUnknown);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The DevTools browser host should now exist.
|
|
|
|
DCHECK(browser_host_);
|
|
|
|
}
|
|
|
|
|
2024-07-02 20:27:11 +02:00
|
|
|
void CefDevToolsWindowRunner::CloseDevTools() {
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
if (browser_host_) {
|
|
|
|
browser_host_->TryCloseBrowser();
|
|
|
|
browser_host_ = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-02 20:27:11 +02:00
|
|
|
bool CefDevToolsWindowRunner::HasDevTools() {
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
return !!browser_host_;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::unique_ptr<CefShowDevToolsParams>
|
2024-07-02 20:27:11 +02:00
|
|
|
CefDevToolsWindowRunner::TakePendingParams() {
|
2024-04-17 18:01:26 +02:00
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
return std::move(pending_params_);
|
|
|
|
}
|
|
|
|
|
2024-07-02 20:27:11 +02:00
|
|
|
void CefDevToolsWindowRunner::SetDevToolsBrowserHost(
|
2024-04-17 18:01:26 +02:00
|
|
|
base::WeakPtr<ChromeBrowserHostImpl> browser_host) {
|
|
|
|
CEF_REQUIRE_UIT();
|
|
|
|
DCHECK(!browser_host_);
|
|
|
|
browser_host_ = browser_host;
|
|
|
|
}
|