From d3331237e034e9a8191b801c65c1ba22a2629cd5 Mon Sep 17 00:00:00 2001 From: gaopengzhen Date: Tue, 3 Dec 2024 16:41:27 +0800 Subject: [PATCH] [DevTools] Add OpenDevtools & CloseDevtools API Signed-off-by: gaopengzhen Change-Id: I21d138d5015e58de697709fc824e034f9f57b906 --- BUILD.gn | 10 + cef_paths.gypi | 10 + include/capi/cef_browser_capi.h | 10 + ...f_devtools_message_handler_delegate_capi.h | 118 ++++++ include/cef_browser.h | 15 + .../cef_devtools_message_handler_delegate.h | 85 ++++ .../browser/alloy/alloy_browser_host_impl.cc | 15 + .../browser/alloy/alloy_browser_host_impl.h | 6 + libcef/browser/browser_host_base.h | 11 + .../browser/devtools/devtools_file_manager.cc | 390 ++++++++++++++++++ .../browser/devtools/devtools_file_manager.h | 106 +++++ libcef/browser/devtools/devtools_frontend.cc | 234 +++++++++++ libcef/browser/devtools/devtools_frontend.h | 45 ++ libcef/browser/devtools/devtools_manager.cc | 30 ++ libcef/browser/devtools/devtools_manager.h | 6 + .../devtools/devtools_message_handler.cc | 284 +++++++++++++ .../devtools/devtools_message_handler.h | 63 +++ .../osr/render_widget_host_view_osr.cc | 9 + libcef_dll/cpptoc/browser_host_cpptoc.cc | 42 ++ libcef_dll/cpptoc/browser_host_cpptoc.h | 2 + ...v_tools_message_handler_delegate_cpptoc.cc | 194 +++++++++ ...ev_tools_message_handler_delegate_cpptoc.h | 38 ++ libcef_dll/cpptoc/info_bar_callback_cpptoc.cc | 65 +++ libcef_dll/cpptoc/info_bar_callback_cpptoc.h | 38 ++ libcef_dll/ctocpp/browser_host_ctocpp.cc | 33 ++ libcef_dll/ctocpp/browser_host_ctocpp.h | 5 + ...v_tools_message_handler_delegate_ctocpp.cc | 184 +++++++++ ...ev_tools_message_handler_delegate_ctocpp.h | 53 +++ libcef_dll/ctocpp/info_bar_callback_ctocpp.cc | 58 +++ libcef_dll/ctocpp/info_bar_callback_ctocpp.h | 41 ++ libcef_dll/wrapper_types.h | 2 + 31 files changed, 2202 insertions(+) create mode 100644 include/capi/cef_devtools_message_handler_delegate_capi.h create mode 100644 include/cef_devtools_message_handler_delegate.h create mode 100644 libcef/browser/devtools/devtools_message_handler.cc create mode 100644 libcef/browser/devtools/devtools_message_handler.h create mode 100644 libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.cc create mode 100644 libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h create mode 100644 libcef_dll/cpptoc/info_bar_callback_cpptoc.cc create mode 100644 libcef_dll/cpptoc/info_bar_callback_cpptoc.h create mode 100644 libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.cc create mode 100644 libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h create mode 100644 libcef_dll/ctocpp/info_bar_callback_ctocpp.cc create mode 100644 libcef_dll/ctocpp/info_bar_callback_ctocpp.h diff --git a/BUILD.gn b/BUILD.gn index 093fc59b9..9091fabbe 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -1177,6 +1177,16 @@ source_set("libcef_static") { ] #endif + #if defined(OHOS_DEVTOOLS) + if (defined(ohos_devtools) && ohos_devtools) { + sources += [ + "include/cef_devtools_message_handler_delegate.h", + "libcef/browser/devtools/devtools_message_handler.cc", + "libcef/browser/devtools/devtools_message_handler.h", + ] + } + #endif // OHOS_DEVTOOLS + configs += [ "libcef/features:config", "//build/config:precompiled_headers", diff --git a/cef_paths.gypi b/cef_paths.gypi index b3529910d..6131ff5e5 100644 --- a/cef_paths.gypi +++ b/cef_paths.gypi @@ -29,6 +29,7 @@ 'include/cef_cookie.h', 'include/cef_crash_util.h', 'include/cef_data_base.h', + 'include/cef_devtools_message_handler_delegate.h', 'include/cef_devtools_message_observer.h', 'include/cef_dialog_handler.h', 'include/cef_display_handler.h', @@ -146,6 +147,7 @@ 'include/capi/cef_cookie_capi.h', 'include/capi/cef_crash_util_capi.h', 'include/capi/cef_data_base_capi.h', + 'include/capi/cef_devtools_message_handler_delegate_capi.h', 'include/capi/cef_devtools_message_observer_capi.h', 'include/capi/cef_dialog_handler_capi.h', 'include/capi/cef_display_handler_capi.h', @@ -313,6 +315,8 @@ 'libcef_dll/cpptoc/date_time_chooser_callback_cpptoc.h', 'libcef_dll/ctocpp/delete_cookies_callback_ctocpp.cc', 'libcef_dll/ctocpp/delete_cookies_callback_ctocpp.h', + 'libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.cc', + 'libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h', 'libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.cc', 'libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h', 'libcef_dll/ctocpp/dialog_handler_ctocpp.cc', @@ -375,6 +379,8 @@ 'libcef_dll/ctocpp/get_saved_passwords_callback_ctocpp.h', 'libcef_dll/cpptoc/image_cpptoc.cc', 'libcef_dll/cpptoc/image_cpptoc.h', + 'libcef_dll/cpptoc/info_bar_callback_cpptoc.cc', + 'libcef_dll/cpptoc/info_bar_callback_cpptoc.h', 'libcef_dll/cpptoc/jsdialog_callback_cpptoc.cc', 'libcef_dll/cpptoc/jsdialog_callback_cpptoc.h', 'libcef_dll/ctocpp/jsdialog_handler_ctocpp.cc', @@ -703,6 +709,8 @@ 'libcef_dll/ctocpp/date_time_chooser_callback_ctocpp.h', 'libcef_dll/cpptoc/delete_cookies_callback_cpptoc.cc', 'libcef_dll/cpptoc/delete_cookies_callback_cpptoc.h', + 'libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.cc', + 'libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h', 'libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.cc', 'libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h', 'libcef_dll/cpptoc/dialog_handler_cpptoc.cc', @@ -765,6 +773,8 @@ 'libcef_dll/cpptoc/get_saved_passwords_callback_cpptoc.h', 'libcef_dll/ctocpp/image_ctocpp.cc', 'libcef_dll/ctocpp/image_ctocpp.h', + 'libcef_dll/ctocpp/info_bar_callback_ctocpp.cc', + 'libcef_dll/ctocpp/info_bar_callback_ctocpp.h', 'libcef_dll/ctocpp/jsdialog_callback_ctocpp.cc', 'libcef_dll/ctocpp/jsdialog_callback_ctocpp.h', 'libcef_dll/cpptoc/jsdialog_handler_cpptoc.cc', diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 24b6ab9ab..dd2cdffe6 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -59,6 +59,7 @@ extern "C" { struct _cef_browser_host_t; struct _cef_client_t; +struct _cef_dev_tools_message_handler_delegate_t; /// /// Structure to implement to be notified of asynchronous completion via @@ -844,6 +845,15 @@ typedef struct _cef_browser_host_t { const struct _cef_browser_settings_t* settings, const cef_point_t* inspect_element_at); + /// + /// Opend DevTools with frontend_browser. + /// + void(CEF_CALLBACK* show_dev_tools_with)( + struct _cef_browser_host_t* self, + struct _cef_browser_host_t* frontend_browser, + struct _cef_dev_tools_message_handler_delegate_t* delegate, + const cef_point_t* inspect_element_at); + /// /// Explicitly close the associated DevTools browser, if any. /// diff --git a/include/capi/cef_devtools_message_handler_delegate_capi.h b/include/capi/cef_devtools_message_handler_delegate_capi.h new file mode 100644 index 000000000..327b81342 --- /dev/null +++ b/include/capi/cef_devtools_message_handler_delegate_capi.h @@ -0,0 +1,118 @@ +// Copyright (c) 2024 Marshall A. Greenblatt. All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above +// copyright notice, this list of conditions and the following disclaimer +// in the documentation and/or other materials provided with the +// distribution. +// * Neither the name of Google Inc. nor the name Chromium Embedded +// Framework nor the names of its contributors may be used to endorse +// or promote products derived from this software without specific prior +// written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool and should not edited +// by hand. See the translator.README.txt file in the tools directory for +// more information. +// +// $hash=dce7493fc618caf7a722a4e273c86f5c41b24519$ +// + +#ifndef CEF_INCLUDE_CAPI_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_CAPI_H_ +#define CEF_INCLUDE_CAPI_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_CAPI_H_ +#pragma once + +#include "include/capi/cef_base_capi.h" +#include "include/capi/cef_dialog_handler_capi.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/// +/// Callback structure for info bar. +/// +typedef struct _cef_info_bar_callback_t { + /// + /// Base structure. + /// + cef_base_ref_counted_t base; + + /// + /// Allow to continue or not. + /// + void(CEF_CALLBACK* allow)(struct _cef_info_bar_callback_t* self, int allow); +} cef_info_bar_callback_t; + +/// +/// Implement this structure to handle devtools message. +/// +typedef struct _cef_dev_tools_message_handler_delegate_t { + /// + /// Base structure. + /// + cef_base_ref_counted_t base; + + /// + /// Called when devtools request to open file chooser. + /// + int(CEF_CALLBACK* show_file_chooser)( + struct _cef_dev_tools_message_handler_delegate_t* self, + cef_file_dialog_mode_t mode, + const cef_string_t* title, + const cef_string_t* default_file_path, + cef_string_list_t accept_filters, + int capture, + struct _cef_file_dialog_callback_t* callback); + + /// + /// Called when devtools request to show info bar. + /// + void(CEF_CALLBACK* show_info_bar)( + struct _cef_dev_tools_message_handler_delegate_t* self, + const cef_string_t* message, + const cef_string_t* path, + struct _cef_info_bar_callback_t* callback); + + /// + /// Called when devtools request to display in front. + /// + int(CEF_CALLBACK* bring_to_front)( + struct _cef_dev_tools_message_handler_delegate_t* self); + + /// + /// Called when devtools request to close browser window. + /// + int(CEF_CALLBACK* close_window)( + struct _cef_dev_tools_message_handler_delegate_t* self); + + /// + /// Called when devtools request to display in front. + /// + int(CEF_CALLBACK* active_dev_tools_window)( + struct _cef_dev_tools_message_handler_delegate_t* self); +} cef_dev_tools_message_handler_delegate_t; + +#ifdef __cplusplus +} +#endif + +#endif // CEF_INCLUDE_CAPI_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_CAPI_H_ diff --git a/include/cef_browser.h b/include/cef_browser.h index fad0ad24b..7a5a82c51 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -58,6 +58,10 @@ #include "include/internal/cef_string_map.h" #endif // BUILDFLAG(IS_OHOS) +#ifdef OHOS_DEVTOOLS +class CefDevToolsMessageHandlerDelegate; +#endif // OHOS_DEVTOOLS + class CefBrowserHost; class CefClient; @@ -878,6 +882,17 @@ class CefBrowserHost : public virtual CefBaseRefCounted { const CefBrowserSettings& settings, const CefPoint& inspect_element_at) = 0; +#ifdef OHOS_DEVTOOLS + /// + /// Opend DevTools with frontend_browser. + /// + /*--cef()--*/ + virtual void ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) = 0; +#endif // OHOS_DEVTOOLS + /// /// Explicitly close the associated DevTools browser, if any. /// diff --git a/include/cef_devtools_message_handler_delegate.h b/include/cef_devtools_message_handler_delegate.h new file mode 100644 index 000000000..36588f6c5 --- /dev/null +++ b/include/cef_devtools_message_handler_delegate.h @@ -0,0 +1,85 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_H_ +#define CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_H_ +#pragma once + +#include "include/cef_base.h" +#include "include/cef_dialog_handler.h" + +/// +/// Callback interface for info bar. +/// +/*--cef(source=library)--*/ +class CefInfoBarCallback : public virtual CefBaseRefCounted { + public: + /// + /// Allow to continue or not. + /// + /*--cef()--*/ + virtual void Allow(bool allow) = 0; +}; + +/// +/// Implement this interface to handle devtools message. +/// +/*--cef(source=client)--*/ +class CefDevToolsMessageHandlerDelegate : public virtual CefBaseRefCounted { + public: + typedef cef_file_dialog_mode_t FileDialogMode; + + /// + /// Called when devtools request to open file chooser. + /// + /*--cef(optional_param=title,optional_param=default_file_path, + optional_param=accept_filters)--*/ + virtual bool ShowFileChooser( + FileDialogMode mode, + const CefString& title, + const CefString& default_file_path, + const std::vector& accept_filters, + bool capture, + CefRefPtr callback) { + return false; + } + + /// + /// Called when devtools request to show info bar. + /// + /*--cef()--*/ + virtual void ShowInfoBar( + const CefString& message, + const CefString& path, + CefRefPtr callback) {} + + /// + /// Called when devtools request to display in front. + /// + /*--cef()--*/ + virtual bool BringToFront() { return false; } + /// + /// Called when devtools request to close browser window. + /// + /*--cef()--*/ + virtual bool CloseWindow() { return false; } + /// + /// Called when devtools request to display in front. + /// + /*--cef()--*/ + virtual bool ActiveDevToolsWindow() { return false; } +}; + +#endif // CEF_INCLUDE_CEF_DEVTOOLS_MESSAGE_HANDLER_DELEGATE_H_ diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index 3756e5231..a87956ce3 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -633,6 +633,21 @@ void AlloyBrowserHostImpl::ShowDevTools(const CefWindowInfo& windowInfo, inspect_element_at); } +#ifdef OHOS_DEVTOOLS +void AlloyBrowserHostImpl::ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) { + LOG(INFO) << "ShowDevToolsWith"; + CEF_REQUIRE_UIT(); + if (!EnsureDevToolsManager()) { + return; + } + devtools_manager_->ShowDevToolsWith( + frontend_browser, delegate, inspect_element_at); +} +#endif // OHOS_DEVTOOLS + void AlloyBrowserHostImpl::CloseDevTools() { if (!CEF_CURRENTLY_ON_UIT()) { CEF_POST_TASK(CEF_UIT, diff --git a/libcef/browser/alloy/alloy_browser_host_impl.h b/libcef/browser/alloy/alloy_browser_host_impl.h index b3106145e..f542211b3 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.h +++ b/libcef/browser/alloy/alloy_browser_host_impl.h @@ -119,6 +119,12 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, CefRefPtr client, const CefBrowserSettings& settings, const CefPoint& inspect_element_at) override; +#ifdef OHOS_DEVTOOLS + void ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) override; +#endif // OHOS_DEVTOOLS void CloseDevTools() override; bool HasDevTools() override; bool IsWindowRenderingDisabled() override; diff --git a/libcef/browser/browser_host_base.h b/libcef/browser/browser_host_base.h index 148525f5e..b1dd2717b 100644 --- a/libcef/browser/browser_host_base.h +++ b/libcef/browser/browser_host_base.h @@ -39,6 +39,10 @@ #include "components/js_injection/browser/js_communication_host.h" #endif //IS_OHOS +#ifdef OHOS_DEVTOOLS +#include "include/cef_devtools_message_handler_delegate.h" +#endif // OHOS_DEVTOOLS + namespace extensions { class Extension; } @@ -253,6 +257,13 @@ class CefBrowserHostBase : public CefBrowserHost, CefRefPtr GetVisibleNavigationEntry() override; void NotifyMoveOrResizeStarted() override; +#ifdef OHOS_DEVTOOLS + void ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) override {} +#endif // OHOS_DEVTOOLS + #if BUILDFLAG(IS_OHOS) /* ohos webview begin */ void PostTaskToUIThread(CefRefPtr task) override; diff --git a/libcef/browser/devtools/devtools_file_manager.cc b/libcef/browser/devtools/devtools_file_manager.cc index 2d8220b48..994d9e9e1 100644 --- a/libcef/browser/devtools/devtools_file_manager.cc +++ b/libcef/browser/devtools/devtools_file_manager.cc @@ -22,8 +22,30 @@ #include "components/prefs/scoped_user_pref_update.h" #include "content/public/browser/web_contents.h" +#ifdef OHOS_DEVTOOLS +#include "libcef/browser/devtools/devtools_message_handler.h" +#include "base/datashare_uri_utils.h" +#include "chrome/grit/generated_resources.h" +#include "content/public/browser/child_process_security_policy.h" +#include "content/public/browser/render_process_host.h" +#include "content/public/browser/render_view_host.h" +#include "content/public/common/url_constants.h" +#include "storage/browser/file_system/file_system_url.h" +#include "storage/browser/file_system/isolated_context.h" +#include "storage/common/file_system/file_system_util.h" +#include "ui/base/l10n/l10n_util.h" +#endif // OHOS_DEVTOOLS + namespace { +#ifdef OHOS_DEVTOOLS +static const char kRootName[] = ""; +static const char kNoHandler[] = ""; +static const char kPermissionDenied[] = ""; +static const char kSelectionCancelled[] = ""; +static const char kDevToolsFileSystemPaths[] = "devtools.file_system_paths"; +#endif // OHOS_DEVTOOLS + base::LazyInstance::Leaky g_last_save_path = LAZY_INSTANCE_INITIALIZER; @@ -37,8 +59,127 @@ void AppendToFile(const base::FilePath& path, const std::string& content) { base::AppendToFile(path, base::StringPiece(content)); } +#ifdef OHOS_DEVTOOLS +using HandleRealPathsCallback = + base::OnceCallback&)>; +void TranslateToRealPaths( + HandleRealPathsCallback callback, + const std::vector& file_paths) { + if (!callback) { + return; + } + std::vector real_paths; + for (const auto& path: file_paths) { + if (path.IsDataShareUri()) { + real_paths.push_back(base::FilePath(base::GetRealPath(path))); + } else { + real_paths.push_back(path); + } + } + std::move(callback).Run(real_paths); +} + +void RunOnUIThread(base::OnceClosure callback) { + content::GetUIThreadTaskRunner({})->PostTask(FROM_HERE, std::move(callback)); +} + +base::Value::Dict CreateFileSystemValue( + CefDevToolsFileManager::FileSystem file_system) { + base::Value::Dict file_system_value; + file_system_value.Set("type", file_system.type); + file_system_value.Set("fileSystemName", file_system.file_system_name); + file_system_value.Set("rootURL", file_system.root_url); + file_system_value.Set("fileSystemPath", file_system.file_system_path); + return file_system_value; +} + +storage::IsolatedContext* isolated_context() { + CEF_REQUIRE_UIT(); + storage::IsolatedContext* isolated_context = + storage::IsolatedContext::GetInstance(); + CHECK(isolated_context); + return isolated_context; +} + +std::string RegisterFileSystem(content::WebContents* web_contents, + const base::FilePath& path) { + CEF_REQUIRE_UIT(); + CHECK(web_contents->GetLastCommittedURL().SchemeIs( + content::kChromeDevToolsScheme)); + std::string root_name(kRootName); + storage::IsolatedContext::ScopedFSHandle file_system = + isolated_context()->RegisterFileSystemForPath( + storage::kFileSystemTypeLocal, std::string(), path, &root_name); + + content::ChildProcessSecurityPolicy* policy = + content::ChildProcessSecurityPolicy::GetInstance(); + content::RenderViewHost* render_view_host = + web_contents->GetPrimaryMainFrame()->GetRenderViewHost(); + int renderer_id = render_view_host->GetProcess()->GetID(); + policy->GrantReadFileSystem(renderer_id, file_system.id()); + policy->GrantWriteFileSystem(renderer_id, file_system.id()); + policy->GrantCreateFileForFileSystem(renderer_id, file_system.id()); + policy->GrantDeleteFromFileSystem(renderer_id, file_system.id()); + + // We only need file level access for reading FileEntries. Saving FileEntries + // just needs the file system to have read/write access, which is granted + // above if required. + if (!policy->CanReadFile(renderer_id, path)) + policy->GrantReadFile(renderer_id, path); + return file_system.id(); +} + +CefDevToolsFileManager::FileSystem CreateFileSystemStruct( + content::WebContents* web_contents, + const std::string& type, + const std::string& file_system_id, + const std::string& file_system_path) { + const GURL origin = + web_contents->GetLastCommittedURL().DeprecatedGetOriginAsURL(); + std::string file_system_name = + storage::GetIsolatedFileSystemName(origin, file_system_id); + std::string root_url = storage::GetIsolatedFileSystemRootURIString( + origin, file_system_id, kRootName); + return CefDevToolsFileManager::FileSystem( + type, file_system_name, root_url, file_system_path); +} + + +using PathToType = std::map; +PathToType GetAddedFileSystemPaths(PrefService* prefs) { + if (!prefs) { + return {}; + } + const base::Value::Dict& file_systems_paths_value = + prefs->GetDict(kDevToolsFileSystemPaths); + PathToType result; + for (auto pair : file_systems_paths_value) { + std::string type = + pair.second.is_string() ? pair.second.GetString() : std::string(); + result[pair.first] = type; + } + return result; +} +#endif // OHOS_DEVTOOLS + } // namespace +#ifdef OHOS_DEVTOOLS +CefDevToolsFileManager::CefDevToolsFileManager( + AlloyBrowserHostImpl* browser_impl, + Delegate* delegate, + PrefService* prefs) + : browser_impl_(browser_impl), + delegate_(delegate), + prefs_(prefs), + file_task_runner_( + base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()})), + weak_factory_(this) { + pref_change_registrar_.Init(prefs_); + web_contents_ = browser_impl_->web_contents(); +} +#endif // OHOS_DEVTOOLS + CefDevToolsFileManager::CefDevToolsFileManager( AlloyBrowserHostImpl* browser_impl, PrefService* prefs) @@ -115,11 +256,28 @@ void CefDevToolsFileManager::Save(const std::string& url, } } +#ifdef OHOS_DEVTOOLS + auto fileChooserCallback = base::BindOnce( + &CefDevToolsFileManager::SaveAsDialogDismissed, + weak_factory_.GetWeakPtr(), url, content, + std::move(saveCallback), std::move(cancelCallback)); + if (devtools_message_handler_) { + fileChooserCallback = devtools_message_handler_->ShowFileChooser( + params, std::move(fileChooserCallback)); + } + if (fileChooserCallback) { + auto translateFilePathCallback = base::BindOnce( + &TranslateToRealPaths, std::move(fileChooserCallback)); + browser_impl_->RunFileChooserForBrowser( + params, std::move(translateFilePathCallback)); + } +#else browser_impl_->RunFileChooserForBrowser( params, base::BindOnce(&CefDevToolsFileManager::SaveAsDialogDismissed, weak_factory_.GetWeakPtr(), url, content, std::move(saveCallback), std::move(cancelCallback))); +#endif // OHOS_DEVTOOLS } void CefDevToolsFileManager::SaveAsDialogDismissed( @@ -204,3 +362,235 @@ void CefDevToolsFileManager::CallClientFunction( browser_impl_->web_contents()->GetPrimaryMainFrame()->ExecuteJavaScript( base::UTF8ToUTF16(javascript), base::NullCallback()); } + +#ifdef OHOS_DEVTOOLS +void CefDevToolsFileManager::CallClientMethod( + const std::string& object_name, + const std::string& method_name, + base::Value arg1, + base::Value arg2, + base::Value arg3, + base::OnceCallback completion_callback) { + // If the client renderer is gone (e.g., the window was closed with both the + // inspector and client being destroyed), the message can not be sent. + if (!web_contents_->GetPrimaryMainFrame()->IsRenderFrameLive()) + return; + base::Value::List arguments; + if (!arg1.is_none()) { + arguments.Append(std::move(arg1)); + if (!arg2.is_none()) { + arguments.Append(std::move(arg2)); + if (!arg3.is_none()) { + arguments.Append(std::move(arg3)); + } + } + } + web_contents_->GetPrimaryMainFrame()->ExecuteJavaScriptMethod( + base::ASCIIToUTF16(object_name), base::ASCIIToUTF16(method_name), + std::move(arguments), std::move(completion_callback)); +} + +void CefDevToolsFileManager::SetDevToolsMessageHandler( + CefDevToolsMessageHandler* devtools_message_Handler) { + devtools_message_handler_ = devtools_message_Handler; +} + +CefDevToolsFileManager::FileSystem::FileSystem() = default; + +CefDevToolsFileManager::FileSystem::~FileSystem() = default; + +CefDevToolsFileManager::FileSystem::FileSystem( + const FileSystem& other) = default; + +CefDevToolsFileManager::FileSystem::FileSystem( + const std::string& type, + const std::string& file_system_name, + const std::string& root_url, + const std::string& file_system_path) + : type(type), + file_system_name(file_system_name), + root_url(root_url), + file_system_path(file_system_path) {} + +std::vector CefDevToolsFileManager::GetFileSystems() { + file_system_paths_ = GetAddedFileSystemPaths(prefs_); + std::vector file_systems; + if (!file_watcher_) { + file_watcher_.reset(new DevToolsFileWatcher( + base::BindRepeating(&CefDevToolsFileManager::FilePathsChanged, + weak_factory_.GetWeakPtr()), + base::SequencedTaskRunner::GetCurrentDefault())); + auto change_handler_on_ui = base::BindRepeating( + &CefDevToolsFileManager::FileSystemPathsSettingChangedOnUI, + weak_factory_.GetWeakPtr()); + pref_change_registrar_.Add( + kDevToolsFileSystemPaths, + base::BindRepeating(RunOnUIThread, change_handler_on_ui)); + } + for (auto file_system_path : file_system_paths_) { + base::FilePath path = + base::FilePath::FromUTF8Unsafe(file_system_path.first); + std::string file_system_id = RegisterFileSystem(web_contents_, path); + FileSystem filesystem = + CreateFileSystemStruct(web_contents_, file_system_path.second, + file_system_id, file_system_path.first); + file_systems.push_back(filesystem); + file_watcher_->AddWatch(std::move(path)); + } + return file_systems; +} + +void CefDevToolsFileManager::AddFileSystem(const std::string& type) { + if (!devtools_message_handler_) { + FileSystemAdded(kNoHandler, nullptr); + return; + } + + blink::mojom::FileChooserParams params; + params.mode = blink::mojom::FileChooserParams::Mode::kUploadFolder; + + auto selectedCallback = base::BindOnce( + &CefDevToolsFileManager::ShowDevToolsInfoBar, + weak_factory_.GetWeakPtr(), type); + auto cancelCallback = base::BindOnce( + &CefDevToolsFileManager::FileSystemAdded, + weak_factory_.GetWeakPtr(), + std::string(kSelectionCancelled), nullptr); + + auto callback = devtools_message_handler_->ShowFileChooser( + params, + base::BindOnce( + &CefDevToolsFileManager::FileSystemSelectionDialogDismissed, + weak_factory_.GetWeakPtr(), + std::move(selectedCallback), std::move(cancelCallback))); + if (callback) { + std::move(callback).Run({}); + } +} + +void CefDevToolsFileManager::RemoveFileSystem( + const std::string& file_system_path) { + CEF_REQUIRE_UIT(); + base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system_path); + isolated_context()->RevokeFileSystemByPath(path); + + ScopedDictPrefUpdate update(prefs_, kDevToolsFileSystemPaths); + base::Value::Dict& file_systems_paths_value = update.Get(); + file_systems_paths_value.Remove(file_system_path); +} + +bool CefDevToolsFileManager::IsFileSystemAdded( + const std::string& file_system_path) { + CEF_REQUIRE_UIT(); + const base::Value::Dict& file_systems_paths_value = + prefs_->GetDict(kDevToolsFileSystemPaths); + return file_systems_paths_value.Find(file_system_path); +} + +void CefDevToolsFileManager::FileSystemAdded( + const std::string& error, + const FileSystem* file_system) { + if (file_system) { + CallClientMethod("DevToolsAPI", "fileSystemAdded", base::Value(error), + base::Value(CreateFileSystemValue(*file_system))); + } else { + CallClientMethod("DevToolsAPI", "fileSystemAdded", base::Value(error)); + } +} + +void CefDevToolsFileManager::RequestFileSystems() { + base::Value::List file_systems_value; + for (auto const& file_system : GetFileSystems()) { + file_systems_value.Append(CreateFileSystemValue(file_system)); + } + CallClientMethod("DevToolsAPI", "fileSystemsLoaded", + base::Value(std::move(file_systems_value))); +} + +void CefDevToolsFileManager::InnerAddFileSystem( + const std::string& type, + const base::FilePath& path, + bool allowed) { + LOG(INFO) << "InnerAddFileSystem(" << type + << ", " << path << ", " << allowed << ")"; + if (!allowed) { + FileSystemAdded(kPermissionDenied, nullptr); + return; + } + std::string file_system_id = RegisterFileSystem(web_contents_, path); + std::string file_system_path = path.AsUTF8Unsafe(); + + ScopedDictPrefUpdate update(prefs_, + kDevToolsFileSystemPaths); + base::Value::Dict& file_systems_paths_value = update.Get(); + file_systems_paths_value.Set(file_system_path, type); +} + +void CefDevToolsFileManager::FileSystemSelectionDialogDismissed( + FileSystemSelectedCallback selected_cb, + FileSystemSelectionCancelCallback cancel_cb, + const std::vector& file_paths) { + if (file_paths.empty()) { + std::move(cancel_cb).Run(); + return; + } + std::move(selected_cb).Run(file_paths[0]); +} + +void CefDevToolsFileManager::FileSystemPathsSettingChangedOnUI() { + CEF_REQUIRE_UIT(); + PathToType remaining; + remaining.swap(file_system_paths_); + DCHECK(file_watcher_.get()); + + for (auto file_system : GetAddedFileSystemPaths(prefs_)) { + if (remaining.find(file_system.first) == remaining.end()) { + base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system.first); + std::string file_system_id = RegisterFileSystem(web_contents_, path); + FileSystem filesystem = CreateFileSystemStruct( + web_contents_, file_system.second, file_system_id, file_system.first); + delegate_->FileSystemAdded(std::string(), &filesystem); + file_watcher_->AddWatch(std::move(path)); + } else { + remaining.erase(file_system.first); + } + file_system_paths_[file_system.first] = file_system.second; + } + + for (auto file_system : remaining) { + delegate_->FileSystemRemoved(file_system.first); + base::FilePath path = base::FilePath::FromUTF8Unsafe(file_system.first); + file_watcher_->RemoveWatch(std::move(path)); + } +} +void CefDevToolsFileManager::FilePathsChanged( + const std::vector& changed_paths, + const std::vector& added_paths, + const std::vector& removed_paths) { + delegate_->FilePathsChanged(changed_paths, added_paths, removed_paths); +} + +void CefDevToolsFileManager::ShowDevToolsInfoBar( + const std::string& type, + const base::FilePath& path) { + std::string file_system_path = path.AsUTF8Unsafe(); + if (IsFileSystemAdded(file_system_path)) { + RemoveFileSystem(file_system_path); + } + + std::string path_display_name = path.AsEndingWithSeparator().AsUTF8Unsafe(); + std::string message = l10n_util::GetStringFUTF8( + IDS_DEV_TOOLS_CONFIRM_ADD_FILE_SYSTEM_MESSAGE, + base::UTF8ToUTF16(path_display_name)); + auto info_bar_cb = base::BindOnce( + &CefDevToolsFileManager::InnerAddFileSystem, + weak_factory_.GetWeakPtr(), type, path); + if (!devtools_message_handler_) { + // default is allow to add file system. + std::move(info_bar_cb).Run(true); + return; + } + devtools_message_handler_->ShowInfoBar( + message, path_display_name, std::move(info_bar_cb)); +} +#endif // OHOS_DEVTOOLS diff --git a/libcef/browser/devtools/devtools_file_manager.h b/libcef/browser/devtools/devtools_file_manager.h index 08b2b830a..1bb9d439b 100644 --- a/libcef/browser/devtools/devtools_file_manager.h +++ b/libcef/browser/devtools/devtools_file_manager.h @@ -11,6 +11,13 @@ #include #include +#ifdef OHOS_DEVTOOLS +#include "base/functional/callback_helpers.h" +#include "base/values.h" +#include "chrome/browser/devtools/devtools_file_watcher.h" +#include "components/prefs/pref_change_registrar.h" +#endif // OHOS_DEVTOOLS + namespace base { class FilePath; class SequencedTaskRunner; @@ -20,11 +27,50 @@ class Value; class AlloyBrowserHostImpl; class PrefService; +#ifdef OHOS_DEVTOOLS +namespace content { +class WebContents; +} // namespace content + +class CefDevToolsMessageHandler; +#endif // OHOS_DEVTOOLS + // File management helper for DevTools. // Based on chrome/browser/devtools/devtools_ui_bindings.cc and // chrome/browser/devtools/devtools_file_helper.cc. class CefDevToolsFileManager { +#ifdef OHOS_DEVTOOLS public: + struct FileSystem { + FileSystem(); + ~FileSystem(); + FileSystem(const FileSystem& other); + FileSystem(const std::string& type, + const std::string& file_system_name, + const std::string& root_url, + const std::string& file_system_path); + + std::string type; + std::string file_system_name; + std::string root_url; + std::string file_system_path; + }; + + class Delegate { + public: + virtual ~Delegate() {} + virtual void FileSystemAdded(const std::string& error, + const FileSystem* file_system) = 0; + virtual void FileSystemRemoved(const std::string& file_system_path) = 0; + virtual void FilePathsChanged( + const std::vector& changed_paths, + const std::vector& added_paths, + const std::vector& removed_paths) = 0; + }; + CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl, + Delegate* delegate, + PrefService* prefs); +#endif // OHOS_DEVTOOLS CefDevToolsFileManager(AlloyBrowserHostImpl* browser_impl, PrefService* prefs); @@ -36,6 +82,15 @@ class CefDevToolsFileManager { bool save_as); void AppendToFile(const std::string& url, const std::string& content); +#ifdef OHOS_DEVTOOLS + void SetDevToolsMessageHandler( + CefDevToolsMessageHandler* devtools_message_Handler); + void RequestFileSystems(); + std::vector GetFileSystems(); + void AddFileSystem(const std::string& type); + void RemoveFileSystem(const std::string& file_system_path); +#endif // OHOS_DEVTOOLS + private: // SaveToFile implementation: using SaveCallback = base::OnceCallback; @@ -69,13 +124,64 @@ class CefDevToolsFileManager { const base::Value* arg2, const base::Value* arg3); +#ifdef OHOS_DEVTOOLS + void CallClientMethod( + const std::string& object_name, + const std::string& method_name, + const base::Value arg1 = {}, + const base::Value arg2 = {}, + const base::Value arg3 = {}, + base::OnceCallback cb = base::NullCallback()); + + bool IsFileSystemAdded(const std::string& file_system_path); + void FileSystemAdded( + const std::string& error, + const FileSystem* file_system); + void InnerAddFileSystem( + const std::string& type, + const base::FilePath& path, + bool allowed); + + using FileSystemSelectedCallback = + base::OnceCallback; + using FileSystemSelectionCancelCallback = base::OnceCallback; + void FileSystemSelectionDialogDismissed( + FileSystemSelectedCallback selectedCallback, + FileSystemSelectionCancelCallback cancelCallback, + const std::vector& file_paths); + + void FileSystemPathsSettingChangedOnUI(); + void FilePathsChanged( + const std::vector& changed_paths, + const std::vector& added_paths, + const std::vector& removed_paths); + + void ShowDevToolsInfoBar( + const std::string& type, + const base::FilePath& path); +#endif // OHOS_DEVTOOLS + // Guaranteed to outlive this object. AlloyBrowserHostImpl* browser_impl_; +#ifdef OHOS_DEVTOOLS + Delegate* delegate_; +#endif // OHOS_DEVTOOLS PrefService* prefs_; using PathsMap = std::map; PathsMap saved_files_; scoped_refptr file_task_runner_; + +#ifdef OHOS_DEVTOOLS + CefDevToolsMessageHandler* devtools_message_handler_ = nullptr; + content::WebContents* web_contents_; + PrefChangeRegistrar pref_change_registrar_; + using PathToType = std::map; + PathToType file_system_paths_; + std::unique_ptr + file_watcher_; +#endif // OHOS_DEVTOOLS + base::WeakPtrFactory weak_factory_; }; diff --git a/libcef/browser/devtools/devtools_frontend.cc b/libcef/browser/devtools/devtools_frontend.cc index ab4633ef2..d99283f34 100644 --- a/libcef/browser/devtools/devtools_frontend.cc +++ b/libcef/browser/devtools/devtools_frontend.cc @@ -71,10 +71,20 @@ constexpr size_t kMaxMessageChunkSize = IPC::Channel::kMaximumMessageSize / 4; constexpr int kMaxLogLineLength = 1024; +#ifdef OHOS_DEVTOOLS +static const char kTitleFormat[] = "DevTools - %s"; +#endif // OHOS_DEVTOOLS + static std::string GetFrontendURL() { +#ifdef OHOS_DEVTOOLS + return base::StringPrintf("%s://%s/devtools_app.html?can_dock=true&dockSide=undocked", + content::kChromeDevToolsScheme, + scheme::kChromeDevToolsHost); +#else return base::StringPrintf("%s://%s/devtools_app.html", content::kChromeDevToolsScheme, scheme::kChromeDevToolsHost); +#endif // OHOS_DEVTOOLS } base::Value::Dict BuildObjectForResponse(const net::HttpResponseHeaders* rh, @@ -170,6 +180,18 @@ void LogProtocolMessage(const base::FilePath& log_file, } } +#ifdef OHOS_DEVTOOLS +base::Value::Dict CreateFileSystemValue( + CefDevToolsFileManager::FileSystem file_system) { + base::Value::Dict file_system_value; + file_system_value.Set("type", file_system.type); + file_system_value.Set("fileSystemName", file_system.file_system_name); + file_system_value.Set("rootURL", file_system.root_url); + file_system_value.Set("fileSystemPath", file_system.file_system_path); + return file_system_value; +} +#endif // OHOS_DEVTOOLS + } // namespace class CefDevToolsFrontend::NetworkResourceLoader @@ -282,6 +304,36 @@ CefDevToolsFrontend* CefDevToolsFrontend::Show( return devtools_frontend; } +#ifdef OHOS_DEVTOOLS +// static +CefDevToolsFrontend* CefDevToolsFrontend::ShowWith( + CefRefPtr frontend_browser, + CefRefPtr devtools_message_handler, + AlloyBrowserHostImpl* inspected_browser, + const CefPoint& inspect_element_at, + base::OnceClosure frontend_destroyed_callback) { + LOG(INFO) << "CefDevToolsFrontend::ShowWith({" + << inspect_element_at.x << "*" << inspect_element_at.y << "})"; + content::WebContents* inspected_contents = inspected_browser->web_contents(); + + AlloyBrowserHostImpl* alloy_frontend_browser = + static_cast(frontend_browser.get()); + auto handler = std::make_unique( + std::move(devtools_message_handler)); + // CefDevToolsFrontend will delete itself when the frontend WebContents is + // destroyed. + CefDevToolsFrontend* devtools_frontend = new CefDevToolsFrontend( + alloy_frontend_browser, std::move(handler), + inspected_contents, inspect_element_at, + std::move(frontend_destroyed_callback)); + + // Need to load the URL after creating the DevTools objects. + alloy_frontend_browser->GetMainFrame()->LoadURL(GetFrontendURL()); + + return devtools_frontend; +} +#endif // OHOS_DEVTOOLS + void CefDevToolsFrontend::Activate() { frontend_browser_->ActivateContents(web_contents()); } @@ -322,12 +374,44 @@ CefDevToolsFrontend::CefDevToolsFrontend( DCHECK(!frontend_destroyed_callback_.is_null()); } +#ifdef OHOS_DEVTOOLS +CefDevToolsFrontend::CefDevToolsFrontend( + AlloyBrowserHostImpl* frontend_browser, + std::unique_ptr devtools_message_handler, + content::WebContents* inspected_contents, + const CefPoint& inspect_element_at, + base::OnceClosure frontend_destroyed_callback) + : content::WebContentsObserver(frontend_browser->web_contents()), + frontend_browser_(frontend_browser), + inspected_contents_(inspected_contents), + inspect_element_at_(inspect_element_at), + frontend_destroyed_callback_(std::move(frontend_destroyed_callback)), + file_manager_(frontend_browser, this, GetPrefs()), + protocol_log_file_( + base::CommandLine::ForCurrentProcess()->GetSwitchValuePath( + switches::kDevToolsProtocolLogFile)), + devtools_message_handler_(std::move(devtools_message_handler)), + weak_factory_(this) { + DCHECK(!frontend_destroyed_callback_.is_null()); + file_manager_.SetDevToolsMessageHandler(devtools_message_handler_.get()); +} +#endif // OHOS_DEVTOOLS + CefDevToolsFrontend::~CefDevToolsFrontend() {} void CefDevToolsFrontend::ReadyToCommitNavigation( content::NavigationHandle* navigation_handle) { content::RenderFrameHost* frame = navigation_handle->GetRenderFrameHost(); if (navigation_handle->IsInMainFrame()) { +#ifdef OHOS_DEVTOOLS + if (agent_host_.get()) { + agent_host_->DetachClient(this); + agent_host_->AttachClient(this); + } + if (frontend_host_) { + return; + } +#endif // OHOS_DEVTOOLS frontend_host_ = content::DevToolsFrontendHost::Create( frame, base::BindRepeating( &CefDevToolsFrontend::HandleMessageFromDevToolsFrontend, @@ -359,8 +443,20 @@ void CefDevToolsFrontend::PrimaryMainDocumentElementAvailable() { agent_host_ = agent_host; agent_host_->AttachClient(this); if (!inspect_element_at_.IsEmpty()) { +#ifdef OHOS_DEVTOOLS + content::RenderFrameHost* rfh = inspected_contents_->GetFocusedFrame(); + if (!rfh) { + rfh = inspected_contents_->GetPrimaryMainFrame(); + } + if (!rfh) { + return; + } + agent_host_->InspectElement(rfh, + inspect_element_at_.x, inspect_element_at_.y); +#else agent_host_->InspectElement(inspected_contents_->GetFocusedFrame(), inspect_element_at_.x, inspect_element_at_.y); +#endif // OHOS_DEVTOOLS } } } @@ -390,6 +486,18 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend( params = std::move(*params_value); } +#ifdef OHOS_DEVTOOLS + if (devtools_message_handler_) { + if (devtools_message_handler_->HandleMessage( + request_id, *method, params)) { + if (request_id) { + SendMessageAck(request_id, base::Value::Dict()); + } + return; + } + } +#endif // OHOS_DEVTOOLS + if (*method == "dispatchProtocolMessage") { if (params.size() < 1) { return; @@ -516,8 +624,12 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend( ScopedDictPrefUpdate update(GetPrefs(), prefs::kDevToolsPreferences); update->Remove(*name); } else if (*method == "requestFileSystems") { +#ifdef OHOS_DEVTOOLS + RequestFileSystems(); +#else web_contents()->GetPrimaryMainFrame()->ExecuteJavaScriptForTests( u"DevToolsAPI.fileSystemsLoaded([]);", base::NullCallback()); +#endif // OHOS_DEVTOOLS } else if (*method == "reattach") { if (!agent_host_) { return; @@ -555,6 +667,65 @@ void CefDevToolsFrontend::HandleMessageFromDevToolsFrontend( return; } file_manager_.AppendToFile(*url, *content); +#ifdef OHOS_DEVTOOLS + } else if (*method == "openInNewTab") { + if (params.size() < 1) { + return; + } + const std::string* url = params[0].GetIfString(); + if (url == nullptr) { + return; + } + content::OpenURLParams urlParams(GURL(*url), content::Referrer(), + WindowOpenDisposition::NEW_FOREGROUND_TAB, + ui::PAGE_TRANSITION_LINK, false); + if (inspected_contents_ != nullptr) { + inspected_contents_->OpenURL(urlParams); + } + return; + } else if (*method == "addFileSystem") { + if (params.size() < 1) { + return; + } + const std::string* type = params[0].GetIfString(); + if (!type) { + return; + } + file_manager_.AddFileSystem(*type); + } else if (*method == "removeFileSystem") { + if (params.size() < 1) { + return; + } + const std::string* file_system_path = params[0].GetIfString(); + if (!file_system_path) { + return; + } + file_manager_.RemoveFileSystem(*file_system_path); + } else if (*method == "inspectedURLChanged") { + if (params.size() < 1) { + return; + } + const std::string* url = params[0].GetIfString(); + if (!url) { + return; + } + content::NavigationController& controller = web_contents()->GetController(); + content::NavigationEntry* entry = controller.GetActiveEntry(); + const std::string kHttpPrefix = "http://"; + const std::string kHttpsPrefix = "https://"; + const std::string simplified_url = + base::StartsWith(*url, kHttpsPrefix, base::CompareCase::SENSITIVE) + ? url->substr(kHttpsPrefix.length()) + : base::StartsWith(*url, kHttpPrefix, base::CompareCase::SENSITIVE) + ? url->substr(kHttpPrefix.length()) + : *url; + // DevTools UI is not localized. + web_contents()->UpdateTitleForEntry( + entry, base::UTF8ToUTF16( + base::StringPrintf(kTitleFormat, simplified_url.c_str()))); + + return; +#endif // OHOS_DEVTOOLS } else { return; } @@ -663,3 +834,66 @@ PrefService* CefDevToolsFrontend::GetPrefs() const { ->AsProfile() ->GetPrefs(); } + +#ifdef OHOS_DEVTOOLS +void CefDevToolsFrontend::FileSystemAdded( + const std::string& error, + const CefDevToolsFileManager::FileSystem* file_system) { + if (file_system) { + CallClientFunction("DevToolsAPI", "fileSystemAdded", base::Value(error), + base::Value(CreateFileSystemValue(*file_system))); + } else { + CallClientFunction("DevToolsAPI", "fileSystemAdded", base::Value(error)); + } +} + +void CefDevToolsFrontend::FileSystemRemoved(const std::string& file_system_path) { + CallClientFunction("DevToolsAPI", "fileSystemRemoved", + base::Value(file_system_path)); +} + +void CefDevToolsFrontend::FilePathsChanged( + const std::vector& changed_paths, + const std::vector& added_paths, + const std::vector& removed_paths) { + const int kMaxPathsPerMessage = 1000; + size_t changed_index = 0; + size_t added_index = 0; + size_t removed_index = 0; + // Dispatch limited amount of file paths in a time to avoid + // IPC max message size limit. See https://crbug.com/797817. + while (changed_index < changed_paths.size() || + added_index < added_paths.size() || + removed_index < removed_paths.size()) { + int budget = kMaxPathsPerMessage; + base::Value::List changed; + base::Value::List added; + base::Value::List removed; + while (budget > 0 && changed_index < changed_paths.size()) { + changed.Append(changed_paths[changed_index++]); + --budget; + } + while (budget > 0 && added_index < added_paths.size()) { + added.Append(added_paths[added_index++]); + --budget; + } + while (budget > 0 && removed_index < removed_paths.size()) { + removed.Append(removed_paths[removed_index++]); + --budget; + } + CallClientFunction("DevToolsAPI", "fileSystemFilesChangedAddedRemoved", + base::Value(std::move(changed)), + base::Value(std::move(added)), + base::Value(std::move(removed))); + } +} + +void CefDevToolsFrontend::RequestFileSystems() { + base::Value::List file_systems_value; + for (auto const& file_system : file_manager_.GetFileSystems()) { + file_systems_value.Append(CreateFileSystemValue(file_system)); + } + CallClientFunction("DevToolsAPI", "fileSystemsLoaded", + base::Value(std::move(file_systems_value))); +} +#endif // OHOS_DEVTOOLS diff --git a/libcef/browser/devtools/devtools_frontend.h b/libcef/browser/devtools/devtools_frontend.h index 36af6f116..bc36c935d 100644 --- a/libcef/browser/devtools/devtools_frontend.h +++ b/libcef/browser/devtools/devtools_frontend.h @@ -18,6 +18,11 @@ #include "content/public/browser/devtools_frontend_host.h" #include "content/public/browser/web_contents_observer.h" +#ifdef OHOS_DEVTOOLS +#include "include/cef_devtools_message_handler_delegate.h" +#include "libcef/browser/devtools/devtools_message_handler.h" +#endif // OHOS_DEVTOOLS + namespace base { class Value; } @@ -37,6 +42,9 @@ enum class ProtocolMessageType { }; class CefDevToolsFrontend : public content::WebContentsObserver, +#ifdef OHOS_DEVTOOLS + public CefDevToolsFileManager::Delegate, +#endif // OHOS_DEVTOOLS public content::DevToolsAgentHostClient { public: CefDevToolsFrontend(const CefDevToolsFrontend&) = delete; @@ -50,6 +58,15 @@ class CefDevToolsFrontend : public content::WebContentsObserver, const CefPoint& inspect_element_at, base::OnceClosure frontend_destroyed_callback); +#ifdef OHOS_DEVTOOLS + static CefDevToolsFrontend* ShowWith( + CefRefPtr frontend_browser, + CefRefPtr devtools_message_handler, + AlloyBrowserHostImpl* inspected_browser, + const CefPoint& inspect_element_at, + base::OnceClosure frontend_destroyed_callback); +#endif // OHOS_DEVTOOLS + void Activate(); void Focus(); void InspectElementAt(int x, int y); @@ -68,6 +85,14 @@ class CefDevToolsFrontend : public content::WebContentsObserver, content::WebContents* inspected_contents, const CefPoint& inspect_element_at, base::OnceClosure destroyed_callback); +#ifdef OHOS_DEVTOOLS + CefDevToolsFrontend(AlloyBrowserHostImpl* frontend_browser, + std::unique_ptr + devtools_message_handler, + content::WebContents* inspected_contents, + const CefPoint& inspect_element_at, + base::OnceClosure destroyed_callback); +#endif // OHOS_DEVTOOLS ~CefDevToolsFrontend() override; // content::DevToolsAgentHostClient implementation. @@ -76,6 +101,18 @@ class CefDevToolsFrontend : public content::WebContentsObserver, base::span message) override; void HandleMessageFromDevToolsFrontend(base::Value::Dict message); +#ifdef OHOS_DEVTOOLS + // CefDevToolsFileManager::Delegate implementation. + void FileSystemAdded( + const std::string& error, + const CefDevToolsFileManager::FileSystem* file_system) override; + void FileSystemRemoved(const std::string& file_system_path) override; + void FilePathsChanged( + const std::vector& changed_paths, + const std::vector& added_paths, + const std::vector& removed_paths) override; +#endif // OHOS_DEVTOOLS + private: // WebContentsObserver overrides void ReadyToCommitNavigation( @@ -91,6 +128,10 @@ class CefDevToolsFrontend : public content::WebContentsObserver, PrefService* GetPrefs() const; +#ifdef OHOS_DEVTOOLS + void RequestFileSystems(); +#endif // OHOS_DEVTOOLS + CefRefPtr frontend_browser_; content::WebContents* inspected_contents_; scoped_refptr agent_host_; @@ -108,6 +149,10 @@ class CefDevToolsFrontend : public content::WebContentsObserver, const base::FilePath protocol_log_file_; +#ifdef OHOS_DEVTOOLS + std::unique_ptr devtools_message_handler_; +#endif // OHOS_DEVTOOLS + base::WeakPtrFactory weak_factory_; }; diff --git a/libcef/browser/devtools/devtools_manager.cc b/libcef/browser/devtools/devtools_manager.cc index 170f60956..6332134e8 100644 --- a/libcef/browser/devtools/devtools_manager.cc +++ b/libcef/browser/devtools/devtools_manager.cc @@ -131,6 +131,36 @@ void CefDevToolsManager::ShowDevTools(const CefWindowInfo& windowInfo, } } +#ifdef OHOS_DEVTOOLS +void CefDevToolsManager::ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr devtools_message_handler, + const CefPoint& inspect_element_at) { + LOG(INFO) << "CefDevToolsManager::ShowDevToolsWith({" + << inspect_element_at.x << "*" << inspect_element_at.y << "})"; + CEF_REQUIRE_UIT(); + if (devtools_frontend_) { + if (!inspect_element_at.IsEmpty()) { + devtools_frontend_->InspectElementAt(inspect_element_at.x, + inspect_element_at.y); + } + devtools_frontend_->Focus(); + return; + } + + if (cef::IsChromeRuntimeEnabled()) { + NOTIMPLEMENTED(); + } else { + auto alloy_browser = static_cast(inspected_browser_); + devtools_frontend_ = CefDevToolsFrontend::ShowWith( + frontend_browser, std::move(devtools_message_handler), + alloy_browser, inspect_element_at, + base::BindOnce(&CefDevToolsManager::OnFrontEndDestroyed, + weak_ptr_factory_.GetWeakPtr())); + } +} +#endif // OHOS_DEVTOOLS + void CefDevToolsManager::CloseDevTools() { CEF_REQUIRE_UIT(); if (!devtools_frontend_) { diff --git a/libcef/browser/devtools/devtools_manager.h b/libcef/browser/devtools/devtools_manager.h index d390e4989..6605063b5 100644 --- a/libcef/browser/devtools/devtools_manager.h +++ b/libcef/browser/devtools/devtools_manager.h @@ -35,6 +35,12 @@ class CefDevToolsManager { CefRefPtr client, const CefBrowserSettings& settings, const CefPoint& inspect_element_at); +#ifdef OHOS_DEVTOOLS + void ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr devtools_message_handler, + const CefPoint& inspect_element_at); +#endif // OHOS_DEVTOOLS void CloseDevTools(); bool HasDevTools(); bool SendDevToolsMessage(const void* message, size_t message_size); diff --git a/libcef/browser/devtools/devtools_message_handler.cc b/libcef/browser/devtools/devtools_message_handler.cc new file mode 100644 index 000000000..46f8b3e7a --- /dev/null +++ b/libcef/browser/devtools/devtools_message_handler.cc @@ -0,0 +1,284 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "libcef/browser/devtools/devtools_message_handler.h" + +#include "base/datashare_uri_utils.h" +#include "base/logging.h" +#include "base/json/json_reader.h" +#include "libcef/browser/thread_util.h" +#include "third_party/abseil-cpp/absl/types/optional.h" + +namespace { + +absl::optional ExtractProtocolMessage( + const base::Value::List& params) { + if (params.size() < 1) { + return absl::nullopt; + } + const std::string* protocol_message = params[0].GetIfString(); + if (!protocol_message) { + return absl::nullopt; + } + auto result = base::JSONReader::Read(*protocol_message); + if (!result.has_value()) { + return absl::nullopt; + } + if (!result->is_dict()) { + return absl::nullopt; + } + return std::move(result->GetDict()); +} + +class CefFileDialogCallbackImpl : public CefFileDialogCallback { + public: + using CallbackType = CefFileDialogManager::RunFileChooserCallback; + + explicit CefFileDialogCallbackImpl(CallbackType callback) + : callback_(std::move(callback)) {} + + ~CefFileDialogCallbackImpl() override { + CEF_REQUIRE_UIT(); + if (!callback_.is_null()) { + CancelNow(std::move(callback_)); + } + } + + void Continue(const std::vector& file_paths) override { + CEF_REQUIRE_UIT(); + if (!callback_.is_null()) { + std::vector vec; + std::vector::const_iterator it = file_paths.begin(); + for (; it != file_paths.end(); ++it) { + base::FilePath path(*it); + if (path.IsDataShareUri()) { + vec.push_back(base::FilePath(base::GetRealPath(path))); + } else { + vec.push_back(path); + } + } + std::move(callback_).Run(vec); + } + } + + void Cancel() override { + CEF_REQUIRE_UIT(); + if (!callback_.is_null()) { + CancelNow(std::move(callback_)); + } + } + + CallbackType ReleaseCallback() { + return std::move(callback_); + } + + private: + static void CancelNow(CallbackType callback) { + CEF_REQUIRE_UIT(); + std::vector file_paths; + std::move(callback).Run(file_paths); + } + + CallbackType callback_; + + IMPLEMENT_REFCOUNTING(CefFileDialogCallbackImpl); +}; + +class CefInfoBarCallbackImpl : public CefInfoBarCallback { + public: + using CallbackType = CefDevToolsMessageHandler::InfoBarCallback; + + explicit CefInfoBarCallbackImpl(CallbackType callback) + : callback_(std::move(callback)) {} + + ~CefInfoBarCallbackImpl() override { + CEF_REQUIRE_UIT(); + if (!callback_.is_null()) { + std::move(callback_).Run(default_value_); + } + } + + void Allow(bool allow) override { + if (!callback_.is_null()) { + std::move(callback_).Run(allow); + } + } + private: + CallbackType callback_; + bool default_value_ = true; + + IMPLEMENT_REFCOUNTING(CefInfoBarCallbackImpl); +}; + +} // namespace + +CefDevToolsMessageHandler::CefDevToolsMessageHandler( + CefRefPtr delegate) + : delegate_(std::move(delegate)) { + method_handlers_["dispatchProtocolMessage"] = base::BindRepeating( + &CefDevToolsMessageHandler::HandleProtocolMessage, base::Unretained(this)); + method_handlers_["bringToFront"] = base::BindRepeating( + &CefDevToolsMessageHandler::BringToFront, base::Unretained(this)); + method_handlers_["closeWindow"] = base::BindRepeating( + &CefDevToolsMessageHandler::CloseWindow, base::Unretained(this)); + method_handlers_["inspectedURLChanged"] = base::BindRepeating( + &CefDevToolsMessageHandler::InspectedURLChanged, base::Unretained(this)); + + protocol_message_handlers_["Page.bringToFront"] = base::BindRepeating( + &CefDevToolsMessageHandler::PageBringToFront, base::Unretained(this)); +} + +CefDevToolsMessageHandler::CefDevToolsMessageHandler( + CefDevToolsMessageHandler&& other) + : delegate_(std::move(other.delegate_)), + method_handlers_(std::move(other.method_handlers_)), + protocol_message_handlers_(std::move(other.protocol_message_handlers_)) {} + +CefDevToolsMessageHandler::~CefDevToolsMessageHandler() {} + +CefFileDialogManager::RunFileChooserCallback +CefDevToolsMessageHandler::ShowFileChooser( + const blink::mojom::FileChooserParams& params, + CefFileDialogManager::RunFileChooserCallback callback) { + LOG(INFO) << "CefDevToolsMessageHandler::ShowFileChooser"; + if (!delegate_) { + LOG(INFO) << "ShowFileChooser, no delegate_"; + return callback; + } + + int mode = FILE_DIALOG_OPEN; + switch (params.mode) { + case blink::mojom::FileChooserParams::Mode::kOpen: + mode = FILE_DIALOG_OPEN; + break; + case blink::mojom::FileChooserParams::Mode::kOpenMultiple: + mode = FILE_DIALOG_OPEN_MULTIPLE; + break; + case blink::mojom::FileChooserParams::Mode::kUploadFolder: + mode = FILE_DIALOG_OPEN_FOLDER; + break; + case blink::mojom::FileChooserParams::Mode::kSave: + mode = FILE_DIALOG_SAVE; + break; + default: + DCHECK(false); + break; + } + + std::vector::const_iterator it = params.accept_types.begin(); + std::vector accept_filters; + for (; it != params.accept_types.end(); ++it) { + accept_filters.push_back(*it); + } + + CefRefPtr callback_impl( + new CefFileDialogCallbackImpl(std::move(callback))); + + bool handled = delegate_->ShowFileChooser( + static_cast(mode), params.title, + params.default_file_name.value(), accept_filters, + params.use_media_capture, callback_impl.get()); + if (handled) { + return CefFileDialogManager::RunFileChooserCallback(); + } + + return callback_impl->ReleaseCallback(); +} + +void CefDevToolsMessageHandler::ShowInfoBar( + const std::string& message, + const std::string& path, + InfoBarCallback callback) { + LOG(INFO) << "CefDevToolsMessageHandler::ShowInfoBar"; + if (!delegate_) { + LOG(INFO) << "ShowInfoBar, no delegate_"; + return; + } + + CefRefPtr callback_impl( + new CefInfoBarCallbackImpl(std::move(callback))); + delegate_->ShowInfoBar(message, path, callback_impl); +} + +bool CefDevToolsMessageHandler::HandleMessage(int request_id, + const std::string& method, + const base::Value::List& params) { + auto iter = method_handlers_.find(method); + if (iter == method_handlers_.end()) { + return false; + } + return iter->second.Run(params); +} + +bool CefDevToolsMessageHandler::HandleProtocolMessage( + const base::Value::List& message_params) { + auto message = ExtractProtocolMessage(message_params); + if (!message) { + return false; + } + const std::string* method = message->FindString("method"); + if (!method) { + return false; + } + + const base::Value::List* params_value = message->FindList("params"); + + auto iter = protocol_message_handlers_.find(*method); + if (iter == protocol_message_handlers_.end()) { + return false; + } + + if (params_value) { + return iter->second.Run(*params_value); + } else { + return iter->second.Run({}); + } +} + +bool CefDevToolsMessageHandler::BringToFront(const base::Value::List&) { + LOG(INFO) << "CefDevToolsMessageHandler::BringToFront"; + if (!delegate_) { + LOG(INFO) << "BringToFront, no delegate_"; + return false; + } + return delegate_->ActiveDevToolsWindow(); +} + +bool CefDevToolsMessageHandler::CloseWindow(const base::Value::List&) { + LOG(INFO) << "CefDevToolsMessageHandler::CloseWindow"; + if (!delegate_) { + LOG(INFO) << "CloseWindow, no delegate_"; + return false; + } + return delegate_->CloseWindow(); +} + +bool CefDevToolsMessageHandler::InspectedURLChanged(const base::Value::List& param) { + LOG(INFO) << "CefDevToolsMessageHandler::InspectedURLChanged"; + if (!delegate_) { + LOG(INFO) << "InspectedURLChanged, no delegate_"; + return false; + } + return false; +} + +bool CefDevToolsMessageHandler::PageBringToFront(const base::Value::List&) { + LOG(INFO) << "CefDevToolsMessageHandler::PageBringToFront"; + if (!delegate_) { + LOG(INFO) << "PageBringToFront, no delegate_"; + return false; + } + return delegate_->BringToFront(); +} diff --git a/libcef/browser/devtools/devtools_message_handler.h b/libcef/browser/devtools/devtools_message_handler.h new file mode 100644 index 000000000..a8969ed3c --- /dev/null +++ b/libcef/browser/devtools/devtools_message_handler.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MESSAGE_HANDLER_H_ +#define CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MESSAGE_HANDLER_H_ + +#include "base/values.h" +#include "base/functional/bind.h" + +#include "libcef/browser/file_dialog_manager.h" +#include "include/cef_devtools_message_handler_delegate.h" + +namespace blink::mojom { +class FileChooserParams; +} + +class CefDevToolsMessageHandler final { + public: + explicit CefDevToolsMessageHandler( + CefRefPtr delegate); + CefDevToolsMessageHandler(const CefDevToolsMessageHandler&) = delete; + CefDevToolsMessageHandler(CefDevToolsMessageHandler&&); + ~CefDevToolsMessageHandler(); + + CefFileDialogManager::RunFileChooserCallback ShowFileChooser( + const blink::mojom::FileChooserParams& params, + CefFileDialogManager::RunFileChooserCallback callback); + + using InfoBarCallback = base::OnceCallback; + void ShowInfoBar( + const std::string& message, + const std::string& path, + InfoBarCallback callback); + + bool HandleMessage(int request_id, const std::string& method, + const base::Value::List& params); + + private: + bool HandleProtocolMessage(const base::Value::List&); + bool BringToFront(const base::Value::List&); + bool CloseWindow(const base::Value::List&); + bool InspectedURLChanged(const base::Value::List&); + bool PageBringToFront(const base::Value::List&); + + CefRefPtr delegate_; + + using Handler = base::RepeatingCallback; + std::map method_handlers_; + std::map protocol_message_handlers_; +}; +#endif // CEF_LIBCEF_BROWSER_DEVTOOLS_DEVTOOLS_MESSAGE_HANDLER_H_ diff --git a/libcef/browser/osr/render_widget_host_view_osr.cc b/libcef/browser/osr/render_widget_host_view_osr.cc index 8eba27db9..41d65fa84 100644 --- a/libcef/browser/osr/render_widget_host_view_osr.cc +++ b/libcef/browser/osr/render_widget_host_view_osr.cc @@ -70,6 +70,8 @@ #include "content/browser/browser_main_loop.h" #include "ohos_adapter_helper.h" #include "ui/events/gesture_detection/gesture_configuration.h" +#include "ui/gfx/text_elider.h" + // static std::unordered_map CefRenderWidgetHostViewOSR::compositor_map_; @@ -1207,7 +1209,14 @@ void CefRenderWidgetHostViewOSR::UpdateTooltipUnderCursor( return; } +#if BUILDFLAG(IS_OHOS) + const size_t kMaxTooltipLength = 1024; + std::u16string truncated_text = + gfx::TruncateString(tooltip_text, kMaxTooltipLength, gfx::WORD_BREAK); + CefString tooltip(truncated_text); +#else CefString tooltip(tooltip_text); +#endif // BUILDFLAG(IS_OHOS) CefRefPtr handler = browser_impl_->GetClient()->GetDisplayHandler(); if (handler.get()) { diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.cc b/libcef_dll/cpptoc/browser_host_cpptoc.cc index 035cc2e02..cc3bebff2 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_host_cpptoc.cc @@ -25,6 +25,7 @@ #include "libcef_dll/cpptoc/request_context_cpptoc.h" #include "libcef_dll/cpptoc/value_cpptoc.h" #include "libcef_dll/ctocpp/client_ctocpp.h" +#include "libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h" #include "libcef_dll/ctocpp/dev_tools_message_observer_ctocpp.h" #include "libcef_dll/ctocpp/download_image_callback_ctocpp.h" #include "libcef_dll/ctocpp/java_script_result_callback_ctocpp.h" @@ -557,6 +558,46 @@ browser_host_show_dev_tools(struct _cef_browser_host_t* self, inspect_element_atVal); } +void CEF_CALLBACK browser_host_show_dev_tools_with( + struct _cef_browser_host_t* self, + struct _cef_browser_host_t* frontend_browser, + struct _cef_dev_tools_message_handler_delegate_t* delegate, + const cef_point_t* inspect_element_at) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return; + } + // Verify param: frontend_browser; type: refptr_same + DCHECK(frontend_browser); + if (!frontend_browser) { + return; + } + // Verify param: delegate; type: refptr_diff + DCHECK(delegate); + if (!delegate) { + return; + } + // Verify param: inspect_element_at; type: simple_byref_const + DCHECK(inspect_element_at); + if (!inspect_element_at) { + return; + } + + // Translate param: inspect_element_at; type: simple_byref_const + CefPoint inspect_element_atVal = + inspect_element_at ? *inspect_element_at : CefPoint(); + + // Execute + CefBrowserHostCppToC::Get(self)->ShowDevToolsWith( + CefBrowserHostCppToC::Unwrap(frontend_browser), + CefDevToolsMessageHandlerDelegateCToCpp::Wrap(delegate), + inspect_element_atVal); +} + void CEF_CALLBACK browser_host_close_dev_tools(struct _cef_browser_host_t* self) { shutdown_checker::AssertNotShutdown(); @@ -3857,6 +3898,7 @@ CefBrowserHostCppToC::CefBrowserHostCppToC() { GetStruct()->find = browser_host_find; GetStruct()->stop_finding = browser_host_stop_finding; GetStruct()->show_dev_tools = browser_host_show_dev_tools; + GetStruct()->show_dev_tools_with = browser_host_show_dev_tools_with; GetStruct()->close_dev_tools = browser_host_close_dev_tools; GetStruct()->has_dev_tools = browser_host_has_dev_tools; GetStruct()->send_dev_tools_message = browser_host_send_dev_tools_message; diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.h b/libcef_dll/cpptoc/browser_host_cpptoc.h index 343ba2f4b..66057eb4d 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.h +++ b/libcef_dll/cpptoc/browser_host_cpptoc.h @@ -22,8 +22,10 @@ #include "include/capi/cef_browser_capi.h" #include "include/capi/cef_client_capi.h" +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" #include "include/cef_browser.h" #include "include/cef_client.h" +#include "include/cef_devtools_message_handler_delegate.h" #include "libcef_dll/cpptoc/cpptoc_ref_counted.h" // Wrap a C++ class with a C structure. diff --git a/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.cc b/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.cc new file mode 100644 index 000000000..656bdc063 --- /dev/null +++ b/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.cc @@ -0,0 +1,194 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=81d627a9f460640b9f561824b7fca895526145b3$ +// + +#include "libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h" +#include "libcef_dll/ctocpp/file_dialog_callback_ctocpp.h" +#include "libcef_dll/ctocpp/info_bar_callback_ctocpp.h" +#include "libcef_dll/shutdown_checker.h" +#include "libcef_dll/transfer_util.h" + +namespace { + +// MEMBER FUNCTIONS - Body may be edited by hand. + +int CEF_CALLBACK dev_tools_message_handler_delegate_show_file_chooser( + struct _cef_dev_tools_message_handler_delegate_t* self, + cef_file_dialog_mode_t mode, + const cef_string_t* title, + const cef_string_t* default_file_path, + cef_string_list_t accept_filters, + int capture, + struct _cef_file_dialog_callback_t* callback) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + // Verify param: callback; type: refptr_diff + DCHECK(callback); + if (!callback) { + return 0; + } + // Unverified params: title, default_file_path, accept_filters + + // Translate param: accept_filters; type: string_vec_byref_const + std::vector accept_filtersList; + transfer_string_list_contents(accept_filters, accept_filtersList); + + // Execute + bool _retval = + CefDevToolsMessageHandlerDelegateCppToC::Get(self)->ShowFileChooser( + mode, CefString(title), CefString(default_file_path), + accept_filtersList, capture ? true : false, + CefFileDialogCallbackCToCpp::Wrap(callback)); + + // Return type: bool + return _retval; +} + +void CEF_CALLBACK dev_tools_message_handler_delegate_show_info_bar( + struct _cef_dev_tools_message_handler_delegate_t* self, + const cef_string_t* message, + const cef_string_t* path, + cef_info_bar_callback_t* callback) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return; + } + // Verify param: message; type: string_byref_const + DCHECK(message); + if (!message) { + return; + } + // Verify param: path; type: string_byref_const + DCHECK(path); + if (!path) { + return; + } + // Verify param: callback; type: refptr_diff + DCHECK(callback); + if (!callback) { + return; + } + + // Execute + CefDevToolsMessageHandlerDelegateCppToC::Get(self)->ShowInfoBar( + CefString(message), CefString(path), + CefInfoBarCallbackCToCpp::Wrap(callback)); +} + +int CEF_CALLBACK dev_tools_message_handler_delegate_bring_to_front( + struct _cef_dev_tools_message_handler_delegate_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefDevToolsMessageHandlerDelegateCppToC::Get(self)->BringToFront(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK dev_tools_message_handler_delegate_close_window( + struct _cef_dev_tools_message_handler_delegate_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = + CefDevToolsMessageHandlerDelegateCppToC::Get(self)->CloseWindow(); + + // Return type: bool + return _retval; +} + +int CEF_CALLBACK dev_tools_message_handler_delegate_active_dev_tools_window( + struct _cef_dev_tools_message_handler_delegate_t* self) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return 0; + } + + // Execute + bool _retval = CefDevToolsMessageHandlerDelegateCppToC::Get(self) + ->ActiveDevToolsWindow(); + + // Return type: bool + return _retval; +} + +} // namespace + +// CONSTRUCTOR - Do not edit by hand. + +CefDevToolsMessageHandlerDelegateCppToC:: + CefDevToolsMessageHandlerDelegateCppToC() { + GetStruct()->show_file_chooser = + dev_tools_message_handler_delegate_show_file_chooser; + GetStruct()->show_info_bar = dev_tools_message_handler_delegate_show_info_bar; + GetStruct()->bring_to_front = + dev_tools_message_handler_delegate_bring_to_front; + GetStruct()->close_window = dev_tools_message_handler_delegate_close_window; + GetStruct()->active_dev_tools_window = + dev_tools_message_handler_delegate_active_dev_tools_window; +} + +// DESTRUCTOR - Do not edit by hand. + +CefDevToolsMessageHandlerDelegateCppToC:: + ~CefDevToolsMessageHandlerDelegateCppToC() { + shutdown_checker::AssertNotShutdown(); +} + +template <> +CefRefPtr +CefCppToCRefCounted:: + UnwrapDerived(CefWrapperType type, + cef_dev_tools_message_handler_delegate_t* s) { + DCHECK(false) << "Unexpected class type: " << type; + return nullptr; +} + +template <> +CefWrapperType CefCppToCRefCounted< + CefDevToolsMessageHandlerDelegateCppToC, + CefDevToolsMessageHandlerDelegate, + cef_dev_tools_message_handler_delegate_t>::kWrapperType = + WT_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE; diff --git a/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h b/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h new file mode 100644 index 000000000..1a68780fb --- /dev/null +++ b/libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h @@ -0,0 +1,38 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=0b0e2a7a941174564ca41749af99930658c8123d$ +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CPPTOC_H_ +#pragma once + +#if !defined(WRAPPING_CEF_SHARED) +#error This file can be included wrapper-side only +#endif + +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" +#include "include/cef_devtools_message_handler_delegate.h" +#include "libcef_dll/cpptoc/cpptoc_ref_counted.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed wrapper-side only. +class CefDevToolsMessageHandlerDelegateCppToC + : public CefCppToCRefCounted { + public: + CefDevToolsMessageHandlerDelegateCppToC(); + virtual ~CefDevToolsMessageHandlerDelegateCppToC(); +}; + +#endif // CEF_LIBCEF_DLL_CPPTOC_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CPPTOC_H_ diff --git a/libcef_dll/cpptoc/info_bar_callback_cpptoc.cc b/libcef_dll/cpptoc/info_bar_callback_cpptoc.cc new file mode 100644 index 000000000..3667de381 --- /dev/null +++ b/libcef_dll/cpptoc/info_bar_callback_cpptoc.cc @@ -0,0 +1,65 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=2fa98f74944a4a9a5d3a362e3eb2fdeae9d7f178$ +// + +#include "libcef_dll/cpptoc/info_bar_callback_cpptoc.h" +#include "libcef_dll/shutdown_checker.h" + +namespace { + +// MEMBER FUNCTIONS - Body may be edited by hand. + +void CEF_CALLBACK info_bar_callback_allow(struct _cef_info_bar_callback_t* self, + int allow) { + shutdown_checker::AssertNotShutdown(); + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) { + return; + } + + // Execute + CefInfoBarCallbackCppToC::Get(self)->Allow(allow ? true : false); +} + +} // namespace + +// CONSTRUCTOR - Do not edit by hand. + +CefInfoBarCallbackCppToC::CefInfoBarCallbackCppToC() { + GetStruct()->allow = info_bar_callback_allow; +} + +// DESTRUCTOR - Do not edit by hand. + +CefInfoBarCallbackCppToC::~CefInfoBarCallbackCppToC() { + shutdown_checker::AssertNotShutdown(); +} + +template <> +CefRefPtr CefCppToCRefCounted< + CefInfoBarCallbackCppToC, + CefInfoBarCallback, + cef_info_bar_callback_t>::UnwrapDerived(CefWrapperType type, + cef_info_bar_callback_t* s) { + DCHECK(false) << "Unexpected class type: " << type; + return nullptr; +} + +template <> +CefWrapperType CefCppToCRefCounted::kWrapperType = + WT_INFO_BAR_CALLBACK; diff --git a/libcef_dll/cpptoc/info_bar_callback_cpptoc.h b/libcef_dll/cpptoc/info_bar_callback_cpptoc.h new file mode 100644 index 000000000..74aa896e4 --- /dev/null +++ b/libcef_dll/cpptoc/info_bar_callback_cpptoc.h @@ -0,0 +1,38 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=8aaee2cf300843a14fd130a13f7217928262948e$ +// + +#ifndef CEF_LIBCEF_DLL_CPPTOC_INFO_BAR_CALLBACK_CPPTOC_H_ +#define CEF_LIBCEF_DLL_CPPTOC_INFO_BAR_CALLBACK_CPPTOC_H_ +#pragma once + +#if !defined(BUILDING_CEF_SHARED) +#error This file can be included DLL-side only +#endif + +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" +#include "include/cef_devtools_message_handler_delegate.h" +#include "libcef_dll/cpptoc/cpptoc_ref_counted.h" + +// Wrap a C++ class with a C structure. +// This class may be instantiated and accessed DLL-side only. +class CefInfoBarCallbackCppToC + : public CefCppToCRefCounted { + public: + CefInfoBarCallbackCppToC(); + virtual ~CefInfoBarCallbackCppToC(); +}; + +#endif // CEF_LIBCEF_DLL_CPPTOC_INFO_BAR_CALLBACK_CPPTOC_H_ diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index 8ada2c30b..4f467a528 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -14,6 +14,7 @@ #include "libcef_dll/ctocpp/browser_host_ctocpp.h" #include "libcef_dll/cpptoc/client_cpptoc.h" +#include "libcef_dll/cpptoc/dev_tools_message_handler_delegate_cpptoc.h" #include "libcef_dll/cpptoc/dev_tools_message_observer_cpptoc.h" #include "libcef_dll/cpptoc/download_image_callback_cpptoc.h" #include "libcef_dll/cpptoc/java_script_result_callback_cpptoc.h" @@ -472,6 +473,38 @@ void CefBrowserHostCToCpp::ShowDevTools(const CefWindowInfo& windowInfo, &settings, &inspect_element_at); } +NO_SANITIZE("cfi-icall") +void CefBrowserHostCToCpp::ShowDevToolsWith( + CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) { + shutdown_checker::AssertNotShutdown(); + + cef_browser_host_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, show_dev_tools_with)) { + return; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: frontend_browser; type: refptr_same + DCHECK(frontend_browser.get()); + if (!frontend_browser.get()) { + return; + } + // Verify param: delegate; type: refptr_diff + DCHECK(delegate.get()); + if (!delegate.get()) { + return; + } + + // Execute + _struct->show_dev_tools_with( + _struct, CefBrowserHostCToCpp::Unwrap(frontend_browser), + CefDevToolsMessageHandlerDelegateCppToC::Wrap(delegate), + &inspect_element_at); +} + NO_SANITIZE("cfi-icall") void CefBrowserHostCToCpp::CloseDevTools() { shutdown_checker::AssertNotShutdown(); diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.h b/libcef_dll/ctocpp/browser_host_ctocpp.h index a1cf7d017..3f683db7f 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.h +++ b/libcef_dll/ctocpp/browser_host_ctocpp.h @@ -23,8 +23,10 @@ #include #include "include/capi/cef_browser_capi.h" #include "include/capi/cef_client_capi.h" +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" #include "include/cef_browser.h" #include "include/cef_client.h" +#include "include/cef_devtools_message_handler_delegate.h" #include "libcef_dll/ctocpp/ctocpp_ref_counted.h" // Wrap a C structure with a C++ class. @@ -73,6 +75,9 @@ class CefBrowserHostCToCpp : public CefCToCppRefCounted client, const CefBrowserSettings& settings, const CefPoint& inspect_element_at) override; + void ShowDevToolsWith(CefRefPtr frontend_browser, + CefRefPtr delegate, + const CefPoint& inspect_element_at) override; void CloseDevTools() override; bool HasDevTools() override; bool SendDevToolsMessage(const void* message, size_t message_size) override; diff --git a/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.cc b/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.cc new file mode 100644 index 000000000..99fd20a00 --- /dev/null +++ b/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.cc @@ -0,0 +1,184 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=4aff840b4eb7f83a552254e49b9feff0a65fdf0b$ +// + +#include "libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h" +#include "libcef_dll/cpptoc/file_dialog_callback_cpptoc.h" +#include "libcef_dll/cpptoc/info_bar_callback_cpptoc.h" +#include "libcef_dll/shutdown_checker.h" +#include "libcef_dll/transfer_util.h" + +// VIRTUAL METHODS - Body may be edited by hand. + +NO_SANITIZE("cfi-icall") +bool CefDevToolsMessageHandlerDelegateCToCpp::ShowFileChooser( + FileDialogMode mode, + const CefString& title, + const CefString& default_file_path, + const std::vector& accept_filters, + bool capture, + CefRefPtr callback) { + shutdown_checker::AssertNotShutdown(); + + cef_dev_tools_message_handler_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, show_file_chooser)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: callback; type: refptr_diff + DCHECK(callback.get()); + if (!callback.get()) { + return false; + } + // Unverified params: title, default_file_path, accept_filters + + // Translate param: accept_filters; type: string_vec_byref_const + cef_string_list_t accept_filtersList = cef_string_list_alloc(); + DCHECK(accept_filtersList); + if (accept_filtersList) { + transfer_string_list_contents(accept_filters, accept_filtersList); + } + + // Execute + int _retval = _struct->show_file_chooser( + _struct, mode, title.GetStruct(), default_file_path.GetStruct(), + accept_filtersList, capture, CefFileDialogCallbackCppToC::Wrap(callback)); + + // Restore param:accept_filters; type: string_vec_byref_const + if (accept_filtersList) { + cef_string_list_free(accept_filtersList); + } + + // Return type: bool + return _retval ? true : false; +} + +NO_SANITIZE("cfi-icall") +void CefDevToolsMessageHandlerDelegateCToCpp::ShowInfoBar( + const CefString& message, + const CefString& path, + CefRefPtr callback) { + shutdown_checker::AssertNotShutdown(); + + cef_dev_tools_message_handler_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, show_info_bar)) { + return; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Verify param: message; type: string_byref_const + DCHECK(!message.empty()); + if (message.empty()) { + return; + } + // Verify param: path; type: string_byref_const + DCHECK(!path.empty()); + if (path.empty()) { + return; + } + // Verify param: callback; type: refptr_diff + DCHECK(callback.get()); + if (!callback.get()) { + return; + } + + // Execute + _struct->show_info_bar(_struct, message.GetStruct(), path.GetStruct(), + CefInfoBarCallbackCppToC::Wrap(callback)); +} + +NO_SANITIZE("cfi-icall") +bool CefDevToolsMessageHandlerDelegateCToCpp::BringToFront() { + shutdown_checker::AssertNotShutdown(); + + cef_dev_tools_message_handler_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, bring_to_front)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->bring_to_front(_struct); + + // Return type: bool + return _retval ? true : false; +} + +NO_SANITIZE("cfi-icall") +bool CefDevToolsMessageHandlerDelegateCToCpp::CloseWindow() { + shutdown_checker::AssertNotShutdown(); + + cef_dev_tools_message_handler_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, close_window)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->close_window(_struct); + + // Return type: bool + return _retval ? true : false; +} + +NO_SANITIZE("cfi-icall") +bool CefDevToolsMessageHandlerDelegateCToCpp::ActiveDevToolsWindow() { + shutdown_checker::AssertNotShutdown(); + + cef_dev_tools_message_handler_delegate_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, active_dev_tools_window)) { + return false; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + int _retval = _struct->active_dev_tools_window(_struct); + + // Return type: bool + return _retval ? true : false; +} + +// CONSTRUCTOR - Do not edit by hand. + +CefDevToolsMessageHandlerDelegateCToCpp:: + CefDevToolsMessageHandlerDelegateCToCpp() {} + +// DESTRUCTOR - Do not edit by hand. + +CefDevToolsMessageHandlerDelegateCToCpp:: + ~CefDevToolsMessageHandlerDelegateCToCpp() { + shutdown_checker::AssertNotShutdown(); +} + +template <> +cef_dev_tools_message_handler_delegate_t* +CefCToCppRefCounted:: + UnwrapDerived(CefWrapperType type, CefDevToolsMessageHandlerDelegate* c) { + DCHECK(false) << "Unexpected class type: " << type; + return nullptr; +} + +template <> +CefWrapperType CefCToCppRefCounted< + CefDevToolsMessageHandlerDelegateCToCpp, + CefDevToolsMessageHandlerDelegate, + cef_dev_tools_message_handler_delegate_t>::kWrapperType = + WT_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE; diff --git a/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h b/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h new file mode 100644 index 000000000..dc52a5b17 --- /dev/null +++ b/libcef_dll/ctocpp/dev_tools_message_handler_delegate_ctocpp.h @@ -0,0 +1,53 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=fd18cfd208d896bde2458b0f242946240f863da4$ +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CTOCPP_H_ +#pragma once + +#if !defined(BUILDING_CEF_SHARED) +#error This file can be included DLL-side only +#endif + +#include +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" +#include "include/cef_devtools_message_handler_delegate.h" +#include "libcef_dll/ctocpp/ctocpp_ref_counted.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed DLL-side only. +class CefDevToolsMessageHandlerDelegateCToCpp + : public CefCToCppRefCounted { + public: + CefDevToolsMessageHandlerDelegateCToCpp(); + virtual ~CefDevToolsMessageHandlerDelegateCToCpp(); + + // CefDevToolsMessageHandlerDelegate methods. + bool ShowFileChooser(FileDialogMode mode, + const CefString& title, + const CefString& default_file_path, + const std::vector& accept_filters, + bool capture, + CefRefPtr callback) override; + void ShowInfoBar(const CefString& message, + const CefString& path, + CefRefPtr callback) override; + bool BringToFront() override; + bool CloseWindow() override; + bool ActiveDevToolsWindow() override; +}; + +#endif // CEF_LIBCEF_DLL_CTOCPP_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE_CTOCPP_H_ diff --git a/libcef_dll/ctocpp/info_bar_callback_ctocpp.cc b/libcef_dll/ctocpp/info_bar_callback_ctocpp.cc new file mode 100644 index 000000000..6d65a7b9a --- /dev/null +++ b/libcef_dll/ctocpp/info_bar_callback_ctocpp.cc @@ -0,0 +1,58 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=04ea484d6a097c4d8d55af574ebb5a44ad1daa15$ +// + +#include "libcef_dll/ctocpp/info_bar_callback_ctocpp.h" +#include "libcef_dll/shutdown_checker.h" + +// VIRTUAL METHODS - Body may be edited by hand. + +NO_SANITIZE("cfi-icall") void CefInfoBarCallbackCToCpp::Allow(bool allow) { + shutdown_checker::AssertNotShutdown(); + + cef_info_bar_callback_t* _struct = GetStruct(); + if (CEF_MEMBER_MISSING(_struct, allow)) { + return; + } + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + _struct->allow(_struct, allow); +} + +// CONSTRUCTOR - Do not edit by hand. + +CefInfoBarCallbackCToCpp::CefInfoBarCallbackCToCpp() {} + +// DESTRUCTOR - Do not edit by hand. + +CefInfoBarCallbackCToCpp::~CefInfoBarCallbackCToCpp() { + shutdown_checker::AssertNotShutdown(); +} + +template <> +cef_info_bar_callback_t* CefCToCppRefCounted< + CefInfoBarCallbackCToCpp, + CefInfoBarCallback, + cef_info_bar_callback_t>::UnwrapDerived(CefWrapperType type, + CefInfoBarCallback* c) { + DCHECK(false) << "Unexpected class type: " << type; + return nullptr; +} + +template <> +CefWrapperType CefCToCppRefCounted::kWrapperType = + WT_INFO_BAR_CALLBACK; diff --git a/libcef_dll/ctocpp/info_bar_callback_ctocpp.h b/libcef_dll/ctocpp/info_bar_callback_ctocpp.h new file mode 100644 index 000000000..9cff08ab2 --- /dev/null +++ b/libcef_dll/ctocpp/info_bar_callback_ctocpp.h @@ -0,0 +1,41 @@ +// Copyright (c) 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. +// +// --------------------------------------------------------------------------- +// +// This file was generated by the CEF translator tool. If making changes by +// hand only do so within the body of existing method and function +// implementations. See the translator.README.txt file in the tools directory +// for more information. +// +// $hash=5fb6d93456472b19eebd1ec3c6ce7601a36819f1$ +// + +#ifndef CEF_LIBCEF_DLL_CTOCPP_INFO_BAR_CALLBACK_CTOCPP_H_ +#define CEF_LIBCEF_DLL_CTOCPP_INFO_BAR_CALLBACK_CTOCPP_H_ +#pragma once + +#if !defined(WRAPPING_CEF_SHARED) +#error This file can be included wrapper-side only +#endif + +#include "include/capi/cef_devtools_message_handler_delegate_capi.h" +#include "include/cef_devtools_message_handler_delegate.h" +#include "libcef_dll/ctocpp/ctocpp_ref_counted.h" + +// Wrap a C structure with a C++ class. +// This class may be instantiated and accessed wrapper-side only. +class CefInfoBarCallbackCToCpp + : public CefCToCppRefCounted { + public: + CefInfoBarCallbackCToCpp(); + virtual ~CefInfoBarCallbackCToCpp(); + + // CefInfoBarCallback methods. + void Allow(bool allow) override; +}; + +#endif // CEF_LIBCEF_DLL_CTOCPP_INFO_BAR_CALLBACK_CTOCPP_H_ diff --git a/libcef_dll/wrapper_types.h b/libcef_dll/wrapper_types.h index f4fc059fc..2d8cba048 100644 --- a/libcef_dll/wrapper_types.h +++ b/libcef_dll/wrapper_types.h @@ -54,6 +54,7 @@ enum CefWrapperType { WT_DATA_BASE, WT_DATE_TIME_CHOOSER_CALLBACK, WT_DELETE_COOKIES_CALLBACK, + WT_DEV_TOOLS_MESSAGE_HANDLER_DELEGATE, WT_DEV_TOOLS_MESSAGE_OBSERVER, WT_DIALOG_HANDLER, WT_DICTIONARY_VALUE, @@ -84,6 +85,7 @@ enum CefWrapperType { WT_GET_PASSWORD_CALLBACK, WT_GET_SAVED_PASSWORDS_CALLBACK, WT_IMAGE, + WT_INFO_BAR_CALLBACK, WT_JSDIALOG_CALLBACK, WT_JSDIALOG_HANDLER, WT_JAVA_SCRIPT_RESULT_CALLBACK, -- Gitee