2014-10-31 18:17:05 +00:00
|
|
|
|
// Copyright (c) 2014 GitHub, Inc.
|
2014-04-25 09:49:37 +00:00
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
2014-04-24 08:45:25 +00:00
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/api/electron_api_web_contents.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
|
|
2020-03-13 23:13:05 +00:00
|
|
|
|
#include <limits>
|
2018-09-13 00:25:56 +00:00
|
|
|
|
#include <memory>
|
2015-04-25 04:43:52 +00:00
|
|
|
|
#include <set>
|
2015-12-11 15:54:32 +00:00
|
|
|
|
#include <string>
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include <unordered_set>
|
2018-09-13 00:25:56 +00:00
|
|
|
|
#include <utility>
|
2019-10-02 12:38:27 +00:00
|
|
|
|
#include <vector>
|
2015-04-25 04:43:52 +00:00
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
#include "base/containers/id_map.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "base/files/file_util.h"
|
|
|
|
|
#include "base/json/json_reader.h"
|
2019-01-10 16:28:15 +00:00
|
|
|
|
#include "base/no_destructor.h"
|
2014-04-25 08:13:16 +00:00
|
|
|
|
#include "base/strings/utf_string_conversions.h"
|
2020-07-22 05:34:34 +00:00
|
|
|
|
#include "base/task/current_thread.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "base/task/post_task.h"
|
|
|
|
|
#include "base/task/thread_pool.h"
|
|
|
|
|
#include "base/threading/scoped_blocking_call.h"
|
|
|
|
|
#include "base/threading/sequenced_task_runner_handle.h"
|
2018-09-18 18:00:31 +00:00
|
|
|
|
#include "base/threading/thread_restrictions.h"
|
2016-11-30 07:30:03 +00:00
|
|
|
|
#include "base/threading/thread_task_runner_handle.h"
|
2017-02-06 09:18:04 +00:00
|
|
|
|
#include "base/values.h"
|
2018-04-02 03:47:00 +00:00
|
|
|
|
#include "chrome/browser/browser_process.h"
|
2021-10-28 14:23:05 +00:00
|
|
|
|
#include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h"
|
2021-01-21 21:02:29 +00:00
|
|
|
|
#include "chrome/browser/ui/views/eye_dropper/eye_dropper.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "chrome/common/pref_names.h"
|
|
|
|
|
#include "components/prefs/pref_service.h"
|
|
|
|
|
#include "components/prefs/scoped_user_pref_update.h"
|
|
|
|
|
#include "components/security_state/content/content_utils.h"
|
|
|
|
|
#include "components/security_state/core/security_state.h"
|
2020-09-21 08:00:36 +00:00
|
|
|
|
#include "content/browser/renderer_host/frame_tree_node.h" // nogncheck
|
|
|
|
|
#include "content/browser/renderer_host/render_frame_host_manager.h" // nogncheck
|
2019-03-05 05:08:55 +00:00
|
|
|
|
#include "content/browser/renderer_host/render_widget_host_impl.h" // nogncheck
|
|
|
|
|
#include "content/browser/renderer_host/render_widget_host_view_base.h" // nogncheck
|
2017-06-30 22:47:41 +00:00
|
|
|
|
#include "content/public/browser/child_process_security_policy.h"
|
2020-03-14 20:54:14 +00:00
|
|
|
|
#include "content/public/browser/context_menu_params.h"
|
2021-10-26 00:03:59 +00:00
|
|
|
|
#include "content/public/browser/desktop_media_id.h"
|
|
|
|
|
#include "content/public/browser/desktop_streams_registry.h"
|
2018-04-12 07:30:51 +00:00
|
|
|
|
#include "content/public/browser/download_request_utils.h"
|
2015-04-20 06:50:04 +00:00
|
|
|
|
#include "content/public/browser/favicon_status.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "content/public/browser/file_select_listener.h"
|
2015-09-18 06:20:31 +00:00
|
|
|
|
#include "content/public/browser/native_web_keyboard_event.h"
|
2014-12-09 22:38:43 +00:00
|
|
|
|
#include "content/public/browser/navigation_details.h"
|
2015-03-05 14:39:27 +00:00
|
|
|
|
#include "content/public/browser/navigation_entry.h"
|
2016-07-14 00:19:28 +00:00
|
|
|
|
#include "content/public/browser/navigation_handle.h"
|
2014-07-28 07:29:51 +00:00
|
|
|
|
#include "content/public/browser/render_frame_host.h"
|
2018-03-16 07:28:06 +00:00
|
|
|
|
#include "content/public/browser/render_process_host.h"
|
|
|
|
|
#include "content/public/browser/render_view_host.h"
|
2016-03-08 14:28:53 +00:00
|
|
|
|
#include "content/public/browser/render_widget_host.h"
|
2015-09-18 06:20:31 +00:00
|
|
|
|
#include "content/public/browser/render_widget_host_view.h"
|
2015-04-30 13:15:19 +00:00
|
|
|
|
#include "content/public/browser/service_worker_context.h"
|
2014-10-24 12:20:56 +00:00
|
|
|
|
#include "content/public/browser/site_instance.h"
|
2016-08-26 22:30:02 +00:00
|
|
|
|
#include "content/public/browser/storage_partition.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
|
#include "content/public/browser/web_contents.h"
|
2020-03-26 18:05:45 +00:00
|
|
|
|
#include "content/public/common/referrer_type_converters.h"
|
2020-11-14 00:16:56 +00:00
|
|
|
|
#include "content/public/common/webplugininfo.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
#include "electron/buildflags/buildflags.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "electron/shell/common/api/api.mojom.h"
|
2020-07-20 18:07:02 +00:00
|
|
|
|
#include "gin/arguments.h"
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include "gin/data_object_builder.h"
|
|
|
|
|
#include "gin/handle.h"
|
|
|
|
|
#include "gin/object_template_builder.h"
|
|
|
|
|
#include "gin/wrappable.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
|
#include "mojo/public/cpp/bindings/associated_remote.h"
|
2020-06-22 17:35:10 +00:00
|
|
|
|
#include "mojo/public/cpp/bindings/pending_receiver.h"
|
|
|
|
|
#include "mojo/public/cpp/bindings/remote.h"
|
2019-04-02 22:38:16 +00:00
|
|
|
|
#include "mojo/public/cpp/system/platform_handle.h"
|
2019-10-09 17:59:37 +00:00
|
|
|
|
#include "ppapi/buildflags/buildflags.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "printing/buildflags/buildflags.h"
|
2021-04-27 21:27:34 +00:00
|
|
|
|
#include "printing/print_job_constants.h"
|
2021-10-05 22:30:31 +00:00
|
|
|
|
#include "services/resource_coordinator/public/cpp/memory_instrumentation/memory_instrumentation.h"
|
2021-02-09 20:16:21 +00:00
|
|
|
|
#include "services/service_manager/public/cpp/interface_provider.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/api/electron_api_browser_window.h"
|
|
|
|
|
#include "shell/browser/api/electron_api_debugger.h"
|
|
|
|
|
#include "shell/browser/api/electron_api_session.h"
|
2020-10-09 16:50:46 +00:00
|
|
|
|
#include "shell/browser/api/electron_api_web_frame_main.h"
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include "shell/browser/api/message_port.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/browser.h"
|
|
|
|
|
#include "shell/browser/child_web_contents_tracker.h"
|
2019-08-19 20:13:24 +00:00
|
|
|
|
#include "shell/browser/electron_autofill_driver_factory.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/electron_browser_client.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
|
#include "shell/browser/electron_browser_context.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/electron_browser_main_parts.h"
|
|
|
|
|
#include "shell/browser/electron_javascript_dialog_manager.h"
|
|
|
|
|
#include "shell/browser/electron_navigation_throttle.h"
|
2021-09-14 10:16:34 +00:00
|
|
|
|
#include "shell/browser/file_select_helper.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/native_window.h"
|
2019-07-03 15:05:45 +00:00
|
|
|
|
#include "shell/browser/session_preferences.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/ui/drag_util.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "shell/browser/ui/file_dialog.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents.h"
|
|
|
|
|
#include "shell/browser/ui/inspectable_web_contents_view.h"
|
|
|
|
|
#include "shell/browser/web_contents_permission_helper.h"
|
|
|
|
|
#include "shell/browser/web_contents_preferences.h"
|
|
|
|
|
#include "shell/browser/web_contents_zoom_controller.h"
|
|
|
|
|
#include "shell/browser/web_view_guest_delegate.h"
|
2021-07-02 00:56:29 +00:00
|
|
|
|
#include "shell/browser/web_view_manager.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/common/api/electron_api_native_image.h"
|
2021-10-05 22:30:31 +00:00
|
|
|
|
#include "shell/common/api/electron_bindings.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/common/color_util.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "shell/common/electron_constants.h"
|
2020-11-17 19:13:58 +00:00
|
|
|
|
#include "shell/common/gin_converters/base_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
|
#include "shell/common/gin_converters/blink_converter.h"
|
2019-10-21 07:05:40 +00:00
|
|
|
|
#include "shell/common/gin_converters/callback_converter.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
|
#include "shell/common/gin_converters/content_converter.h"
|
|
|
|
|
#include "shell/common/gin_converters/file_path_converter.h"
|
2020-10-09 16:50:46 +00:00
|
|
|
|
#include "shell/common/gin_converters/frame_converter.h"
|
2019-10-21 07:05:40 +00:00
|
|
|
|
#include "shell/common/gin_converters/gfx_converter.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
|
#include "shell/common/gin_converters/gurl_converter.h"
|
|
|
|
|
#include "shell/common/gin_converters/image_converter.h"
|
|
|
|
|
#include "shell/common/gin_converters/net_converter.h"
|
2019-10-31 07:56:00 +00:00
|
|
|
|
#include "shell/common/gin_converters/value_converter.h"
|
2019-10-18 00:31:29 +00:00
|
|
|
|
#include "shell/common/gin_helper/dictionary.h"
|
2019-10-25 13:03:28 +00:00
|
|
|
|
#include "shell/common/gin_helper/object_template_builder.h"
|
2020-05-04 17:49:29 +00:00
|
|
|
|
#include "shell/common/language_util.h"
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/common/mouse_util.h"
|
|
|
|
|
#include "shell/common/node_includes.h"
|
|
|
|
|
#include "shell/common/options_switches.h"
|
2021-01-13 09:01:51 +00:00
|
|
|
|
#include "shell/common/process_util.h"
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include "shell/common/v8_value_serializer.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "storage/browser/file_system/isolated_context.h"
|
2021-06-03 08:05:04 +00:00
|
|
|
|
#include "third_party/abseil-cpp/absl/types/optional.h"
|
2019-04-02 22:38:16 +00:00
|
|
|
|
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
|
2020-01-17 18:41:52 +00:00
|
|
|
|
#include "third_party/blink/public/common/input/web_input_event.h"
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include "third_party/blink/public/common/messaging/transferable_message_mojom_traits.h"
|
2019-10-18 19:57:34 +00:00
|
|
|
|
#include "third_party/blink/public/common/page/page_zoom.h"
|
2019-01-12 01:00:43 +00:00
|
|
|
|
#include "third_party/blink/public/mojom/frame/find_in_page.mojom.h"
|
2019-10-28 22:12:35 +00:00
|
|
|
|
#include "third_party/blink/public/mojom/frame/fullscreen.mojom.h"
|
2020-03-12 01:07:54 +00:00
|
|
|
|
#include "third_party/blink/public/mojom/messaging/transferable_message.mojom.h"
|
2020-05-04 17:49:29 +00:00
|
|
|
|
#include "third_party/blink/public/mojom/renderer_preferences.mojom.h"
|
2020-03-11 11:15:07 +00:00
|
|
|
|
#include "ui/base/cursor/cursor.h"
|
2020-05-26 20:06:26 +00:00
|
|
|
|
#include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
|
2016-07-21 12:03:38 +00:00
|
|
|
|
#include "ui/display/screen.h"
|
2017-04-13 10:21:30 +00:00
|
|
|
|
#include "ui/events/base_event_utils.h"
|
2014-04-24 08:45:25 +00:00
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2019-06-19 20:46:59 +00:00
|
|
|
|
#include "shell/browser/osr/osr_render_widget_host_view.h"
|
|
|
|
|
#include "shell/browser/osr/osr_web_contents_view.h"
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2016-08-15 21:13:24 +00:00
|
|
|
|
#include "ui/aura/window.h"
|
2019-08-30 14:39:46 +00:00
|
|
|
|
#else
|
|
|
|
|
#include "ui/base/cocoa/defaults_utils.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2019-08-30 14:39:46 +00:00
|
|
|
|
#include "ui/views/linux_ui/linux_ui.h"
|
2016-08-15 21:13:24 +00:00
|
|
|
|
#endif
|
2014-10-23 06:04:13 +00:00
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
|
2018-02-22 08:56:48 +00:00
|
|
|
|
#include "ui/gfx/font_render_params.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-07-24 23:01:08 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-03-05 14:56:21 +00:00
|
|
|
|
#include "extensions/browser/script_executor.h"
|
2020-09-08 11:55:40 +00:00
|
|
|
|
#include "extensions/browser/view_type_utils.h"
|
2021-03-05 23:41:32 +00:00
|
|
|
|
#include "extensions/common/mojom/view_type.mojom.h"
|
2020-02-03 22:01:10 +00:00
|
|
|
|
#include "shell/browser/extensions/electron_extension_web_contents_observer.h"
|
2019-07-24 23:01:08 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-08-15 01:51:28 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "components/printing/browser/print_manager_utils.h"
|
2020-11-17 22:14:09 +00:00
|
|
|
|
#include "printing/backend/print_backend.h" // nogncheck
|
2020-08-15 01:51:28 +00:00
|
|
|
|
#include "printing/mojom/print.mojom.h"
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#include "shell/browser/printing/print_preview_message_handler.h"
|
2021-05-19 23:15:47 +00:00
|
|
|
|
#include "shell/browser/printing/print_view_manager_electron.h"
|
2020-11-17 22:14:09 +00:00
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-11-17 22:14:09 +00:00
|
|
|
|
#include "printing/backend/win_helper.h"
|
|
|
|
|
#endif
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PICTURE_IN_PICTURE)
|
|
|
|
|
#include "chrome/browser/picture_in_picture/picture_in_picture_window_manager.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
|
#include "components/pdf/browser/pdf_web_contents_helper.h" // nogncheck
|
|
|
|
|
#include "shell/browser/electron_pdf_web_contents_helper_client.h"
|
2020-08-15 01:51:28 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2021-07-08 07:18:11 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
|
|
|
|
#include "content/public/browser/plugin_service.h"
|
|
|
|
|
#endif
|
|
|
|
|
|
2020-11-16 17:47:09 +00:00
|
|
|
|
#ifndef MAS_BUILD
|
|
|
|
|
#include "chrome/browser/hang_monitor/hang_crash_dump.h" // nogncheck
|
|
|
|
|
#endif
|
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
|
namespace gin {
|
2015-05-29 03:12:55 +00:00
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2019-06-30 05:12:00 +00:00
|
|
|
|
template <>
|
2020-08-15 01:51:28 +00:00
|
|
|
|
struct Converter<printing::mojom::MarginType> {
|
2019-06-30 05:12:00 +00:00
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::Value> val,
|
2020-08-15 01:51:28 +00:00
|
|
|
|
printing::mojom::MarginType* out) {
|
2019-06-30 05:12:00 +00:00
|
|
|
|
std::string type;
|
|
|
|
|
if (ConvertFromV8(isolate, val, &type)) {
|
|
|
|
|
if (type == "default") {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
*out = printing::mojom::MarginType::kDefaultMargins;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (type == "none") {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
*out = printing::mojom::MarginType::kNoMargins;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (type == "printableArea") {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
*out = printing::mojom::MarginType::kPrintableAreaMargins;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (type == "custom") {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
*out = printing::mojom::MarginType::kCustomMargins;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
template <>
|
2020-05-26 20:06:26 +00:00
|
|
|
|
struct Converter<printing::mojom::DuplexMode> {
|
2019-06-30 05:12:00 +00:00
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::Value> val,
|
2020-05-26 20:06:26 +00:00
|
|
|
|
printing::mojom::DuplexMode* out) {
|
2019-06-30 05:12:00 +00:00
|
|
|
|
std::string mode;
|
|
|
|
|
if (ConvertFromV8(isolate, val, &mode)) {
|
|
|
|
|
if (mode == "simplex") {
|
2020-05-26 20:06:26 +00:00
|
|
|
|
*out = printing::mojom::DuplexMode::kSimplex;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (mode == "longEdge") {
|
2020-05-26 20:06:26 +00:00
|
|
|
|
*out = printing::mojom::DuplexMode::kLongEdge;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
if (mode == "shortEdge") {
|
2020-05-26 20:06:26 +00:00
|
|
|
|
*out = printing::mojom::DuplexMode::kShortEdge;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
|
#endif
|
2017-02-06 09:18:04 +00:00
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
template <>
|
2015-06-23 08:34:22 +00:00
|
|
|
|
struct Converter<WindowOpenDisposition> {
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
|
WindowOpenDisposition val) {
|
|
|
|
|
std::string disposition = "other";
|
|
|
|
|
switch (val) {
|
2017-01-24 07:50:02 +00:00
|
|
|
|
case WindowOpenDisposition::CURRENT_TAB:
|
|
|
|
|
disposition = "default";
|
|
|
|
|
break;
|
|
|
|
|
case WindowOpenDisposition::NEW_FOREGROUND_TAB:
|
|
|
|
|
disposition = "foreground-tab";
|
|
|
|
|
break;
|
|
|
|
|
case WindowOpenDisposition::NEW_BACKGROUND_TAB:
|
|
|
|
|
disposition = "background-tab";
|
|
|
|
|
break;
|
|
|
|
|
case WindowOpenDisposition::NEW_POPUP:
|
|
|
|
|
case WindowOpenDisposition::NEW_WINDOW:
|
|
|
|
|
disposition = "new-window";
|
|
|
|
|
break;
|
|
|
|
|
case WindowOpenDisposition::SAVE_TO_DISK:
|
|
|
|
|
disposition = "save-to-disk";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2015-06-23 08:34:22 +00:00
|
|
|
|
}
|
2019-10-25 13:03:28 +00:00
|
|
|
|
return gin::ConvertToV8(isolate, disposition);
|
2015-06-23 08:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
template <>
|
2015-10-14 04:41:31 +00:00
|
|
|
|
struct Converter<content::SavePageType> {
|
2018-04-18 01:55:30 +00:00
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::Value> val,
|
2015-10-14 04:41:31 +00:00
|
|
|
|
content::SavePageType* out) {
|
|
|
|
|
std::string save_type;
|
|
|
|
|
if (!ConvertFromV8(isolate, val, &save_type))
|
|
|
|
|
return false;
|
2015-12-07 11:56:23 +00:00
|
|
|
|
save_type = base::ToLowerASCII(save_type);
|
2015-11-02 13:19:00 +00:00
|
|
|
|
if (save_type == "htmlonly") {
|
2015-10-14 04:41:31 +00:00
|
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_ONLY_HTML;
|
2015-11-02 13:19:00 +00:00
|
|
|
|
} else if (save_type == "htmlcomplete") {
|
2015-10-14 04:41:31 +00:00
|
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_COMPLETE_HTML;
|
2015-11-02 13:19:00 +00:00
|
|
|
|
} else if (save_type == "mhtml") {
|
2015-10-14 04:41:31 +00:00
|
|
|
|
*out = content::SAVE_PAGE_TYPE_AS_MHTML;
|
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
template <>
|
2016-06-14 16:09:54 +00:00
|
|
|
|
struct Converter<electron::api::WebContents::Type> {
|
|
|
|
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
|
|
|
|
electron::api::WebContents::Type val) {
|
2016-06-14 17:05:25 +00:00
|
|
|
|
using Type = electron::api::WebContents::Type;
|
2019-09-13 14:26:59 +00:00
|
|
|
|
std::string type;
|
2016-06-14 16:09:54 +00:00
|
|
|
|
switch (val) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kBackgroundPage:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "backgroundPage";
|
|
|
|
|
break;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kBrowserWindow:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "window";
|
|
|
|
|
break;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kBrowserView:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "browserView";
|
|
|
|
|
break;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kRemote:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "remote";
|
|
|
|
|
break;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kWebView:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "webview";
|
|
|
|
|
break;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
case Type::kOffScreen:
|
2018-04-18 01:55:30 +00:00
|
|
|
|
type = "offscreen";
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
2016-06-14 16:09:54 +00:00
|
|
|
|
}
|
2019-10-25 13:03:28 +00:00
|
|
|
|
return gin::ConvertToV8(isolate, type);
|
2016-06-14 16:09:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::Value> val,
|
2016-06-14 16:23:03 +00:00
|
|
|
|
electron::api::WebContents::Type* out) {
|
2016-06-14 17:05:25 +00:00
|
|
|
|
using Type = electron::api::WebContents::Type;
|
2016-06-14 16:23:03 +00:00
|
|
|
|
std::string type;
|
|
|
|
|
if (!ConvertFromV8(isolate, val, &type))
|
|
|
|
|
return false;
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
if (type == "backgroundPage") {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
*out = Type::kBackgroundPage;
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
} else if (type == "browserView") {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
*out = Type::kBrowserView;
|
Implement initial, experimental BrowserView API
Right now, `<webview>` is the only way to embed additional content in a
`BrowserWindow`. Unfortunately `<webview>` suffers from a [number of
problems](https://github.com/electron/electron/issues?utf8=%E2%9C%93&q=is%3Aissue%20is%3Aopen%20label%3Awebview%20).
To make matters worse, many of these are upstream Chromium bugs instead
of Electron-specific bugs.
For us at [Figma](https://www.figma.com), the main issue is very slow
performance.
Despite the upstream improvements to `<webview>` through the OOPIF work, it is
probable that there will continue to be `<webview>`-specific bugs in the
future.
Therefore, this introduces a `<webview>` alternative to called `BrowserView`,
which...
- is a thin wrapper around `api::WebContents` (so bugs in `BrowserView` will
likely also be bugs in `BrowserWindow` web contents)
- is instantiated in the main process like `BrowserWindow` (and unlike
`<webview>`, which lives in the DOM of a `BrowserWindow` web contents)
- needs to be added to a `BrowserWindow` to display something on the screen
This implements the most basic API. The API is expected to evolve and change in
the near future and has consequently been marked as experimental. Please do not
use this API in production unless you are prepared to deal with breaking
changes.
In the future, we will want to change the API to support multiple
`BrowserView`s per window. We will also want to consider z-ordering
auto-resizing, and possibly even nested views.
2017-04-11 17:47:30 +00:00
|
|
|
|
} else if (type == "webview") {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
*out = Type::kWebView;
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2016-07-28 10:10:56 +00:00
|
|
|
|
} else if (type == "offscreen") {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
*out = Type::kOffScreen;
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#endif
|
2016-06-14 16:23:03 +00:00
|
|
|
|
} else {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
};
|
2016-06-14 16:09:54 +00:00
|
|
|
|
|
2019-10-02 12:38:27 +00:00
|
|
|
|
template <>
|
|
|
|
|
struct Converter<scoped_refptr<content::DevToolsAgentHost>> {
|
|
|
|
|
static v8::Local<v8::Value> ToV8(
|
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
const scoped_refptr<content::DevToolsAgentHost>& val) {
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary dict(isolate, v8::Object::New(isolate));
|
2019-10-02 12:38:27 +00:00
|
|
|
|
dict.Set("id", val->GetId());
|
|
|
|
|
dict.Set("url", val->GetURL().spec());
|
|
|
|
|
return dict.GetHandle();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
|
} // namespace gin
|
2015-05-29 03:12:55 +00:00
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
|
namespace electron {
|
|
|
|
|
|
|
|
|
|
namespace api {
|
|
|
|
|
|
2014-10-23 05:31:10 +00:00
|
|
|
|
namespace {
|
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
base::IDMap<WebContents*>& GetAllWebContents() {
|
|
|
|
|
static base::NoDestructor<base::IDMap<WebContents*>> s_all_web_contents;
|
|
|
|
|
return *s_all_web_contents;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-06 16:32:58 +00:00
|
|
|
|
// Called when CapturePage is done.
|
2019-11-01 06:10:32 +00:00
|
|
|
|
void OnCapturePageDone(gin_helper::Promise<gfx::Image> promise,
|
2019-08-23 00:03:28 +00:00
|
|
|
|
const SkBitmap& bitmap) {
|
2018-04-10 10:07:15 +00:00
|
|
|
|
// Hack to enable transparency in captured image
|
2019-11-01 06:10:32 +00:00
|
|
|
|
promise.Resolve(gfx::Image::CreateFrom1xBitmap(bitmap));
|
2016-07-06 16:32:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-03 08:05:04 +00:00
|
|
|
|
absl::optional<base::TimeDelta> GetCursorBlinkInterval() {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2022-02-25 18:17:35 +00:00
|
|
|
|
absl::optional<base::TimeDelta> system_value(
|
|
|
|
|
ui::TextInsertionCaretBlinkPeriodFromDefaults());
|
|
|
|
|
if (system_value)
|
|
|
|
|
return *system_value;
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#elif BUILDFLAG(IS_LINUX)
|
2019-09-19 18:43:21 +00:00
|
|
|
|
if (auto* linux_ui = views::LinuxUI::instance())
|
|
|
|
|
return linux_ui->GetCursorBlinkInterval();
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2019-09-19 18:43:21 +00:00
|
|
|
|
const auto system_msec = ::GetCaretBlinkTime();
|
|
|
|
|
if (system_msec != 0) {
|
2021-11-24 08:45:59 +00:00
|
|
|
|
return (system_msec == INFINITE) ? base::TimeDelta()
|
|
|
|
|
: base::Milliseconds(system_msec);
|
2019-09-19 18:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-06-03 08:05:04 +00:00
|
|
|
|
return absl::nullopt;
|
2019-09-19 18:43:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 02:49:13 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
|
|
|
|
// This will return false if no printer with the provided device_name can be
|
|
|
|
|
// found on the network. We need to check this because Chromium does not do
|
|
|
|
|
// sanity checking of device_name validity and so will crash on invalid names.
|
2021-03-16 16:18:45 +00:00
|
|
|
|
bool IsDeviceNameValid(const std::u16string& device_name) {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2020-01-31 02:49:13 +00:00
|
|
|
|
base::ScopedCFTypeRef<CFStringRef> new_printer_id(
|
|
|
|
|
base::SysUTF16ToCFStringRef(device_name));
|
|
|
|
|
PMPrinter new_printer = PMPrinterCreateFromPrinterID(new_printer_id.get());
|
|
|
|
|
bool printer_exists = new_printer != nullptr;
|
|
|
|
|
PMRelease(new_printer);
|
|
|
|
|
return printer_exists;
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2020-01-31 02:49:13 +00:00
|
|
|
|
printing::ScopedPrinterHandle printer;
|
2021-07-12 04:33:26 +00:00
|
|
|
|
return printer.OpenPrinterWithName(base::as_wcstr(device_name));
|
2021-08-24 00:52:17 +00:00
|
|
|
|
#else
|
2020-01-31 02:49:13 +00:00
|
|
|
|
return true;
|
2021-08-24 00:52:17 +00:00
|
|
|
|
#endif
|
2020-01-31 02:49:13 +00:00
|
|
|
|
}
|
2020-01-31 19:20:11 +00:00
|
|
|
|
|
2021-10-05 07:16:04 +00:00
|
|
|
|
std::pair<std::string, std::u16string> GetDefaultPrinterAsync() {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-01-13 17:17:11 +00:00
|
|
|
|
// Blocking is needed here because Windows printer drivers are oftentimes
|
|
|
|
|
// not thread-safe and have to be accessed on the UI thread.
|
|
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
|
|
|
|
#endif
|
2020-01-31 19:20:11 +00:00
|
|
|
|
|
2020-09-21 20:42:27 +00:00
|
|
|
|
scoped_refptr<printing::PrintBackend> print_backend =
|
2020-01-31 19:20:11 +00:00
|
|
|
|
printing::PrintBackend::CreateInstance(
|
2020-09-21 08:00:36 +00:00
|
|
|
|
g_browser_process->GetApplicationLocale());
|
2021-06-05 02:03:31 +00:00
|
|
|
|
std::string printer_name;
|
2021-10-05 07:16:04 +00:00
|
|
|
|
printing::mojom::ResultCode code =
|
|
|
|
|
print_backend->GetDefaultPrinterName(printer_name);
|
2020-09-21 20:42:27 +00:00
|
|
|
|
|
2021-10-05 07:16:04 +00:00
|
|
|
|
// We don't want to return if this fails since some devices won't have a
|
|
|
|
|
// default printer.
|
|
|
|
|
if (code != printing::mojom::ResultCode::kSuccess)
|
|
|
|
|
LOG(ERROR) << "Failed to get default printer name";
|
|
|
|
|
|
|
|
|
|
// Check for existing printers and pick the first one should it exist.
|
2020-09-21 20:42:27 +00:00
|
|
|
|
if (printer_name.empty()) {
|
|
|
|
|
printing::PrinterList printers;
|
2021-10-05 07:16:04 +00:00
|
|
|
|
if (print_backend->EnumeratePrinters(&printers) !=
|
|
|
|
|
printing::mojom::ResultCode::kSuccess)
|
|
|
|
|
return std::make_pair("Failed to enumerate printers", std::u16string());
|
2020-10-22 20:24:59 +00:00
|
|
|
|
if (!printers.empty())
|
2020-09-21 20:42:27 +00:00
|
|
|
|
printer_name = printers.front().printer_name;
|
|
|
|
|
}
|
2021-10-05 07:16:04 +00:00
|
|
|
|
|
|
|
|
|
return std::make_pair(std::string(), base::UTF8ToUTF16(printer_name));
|
2020-01-31 19:20:11 +00:00
|
|
|
|
}
|
2021-01-13 17:17:11 +00:00
|
|
|
|
|
|
|
|
|
// Copied from
|
|
|
|
|
// chrome/browser/ui/webui/print_preview/local_printer_handler_default.cc:L36-L54
|
|
|
|
|
scoped_refptr<base::TaskRunner> CreatePrinterHandlerTaskRunner() {
|
|
|
|
|
// USER_VISIBLE because the result is displayed in the print preview dialog.
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if !BUILDFLAG(IS_WIN)
|
2021-01-13 17:17:11 +00:00
|
|
|
|
static constexpr base::TaskTraits kTraits = {
|
|
|
|
|
base::MayBlock(), base::TaskPriority::USER_VISIBLE};
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if defined(USE_CUPS)
|
|
|
|
|
// CUPS is thread safe.
|
|
|
|
|
return base::ThreadPool::CreateTaskRunner(kTraits);
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#elif BUILDFLAG(IS_WIN)
|
2021-01-13 17:17:11 +00:00
|
|
|
|
// Windows drivers are likely not thread-safe and need to be accessed on the
|
|
|
|
|
// UI thread.
|
|
|
|
|
return content::GetUIThreadTaskRunner(
|
|
|
|
|
{base::MayBlock(), base::TaskPriority::USER_VISIBLE});
|
|
|
|
|
#else
|
|
|
|
|
// Be conservative on unsupported platforms.
|
|
|
|
|
return base::ThreadPool::CreateSingleThreadTaskRunner(kTraits);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
2020-01-31 02:49:13 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
struct UserDataLink : public base::SupportsUserData::Data {
|
|
|
|
|
explicit UserDataLink(base::WeakPtr<WebContents> contents)
|
|
|
|
|
: web_contents(contents) {}
|
|
|
|
|
|
|
|
|
|
base::WeakPtr<WebContents> web_contents;
|
|
|
|
|
};
|
|
|
|
|
const void* kElectronApiWebContentsKey = &kElectronApiWebContentsKey;
|
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
const char kRootName[] = "<root>";
|
|
|
|
|
|
|
|
|
|
struct FileSystem {
|
|
|
|
|
FileSystem() = default;
|
|
|
|
|
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::string type;
|
|
|
|
|
std::string file_system_name;
|
|
|
|
|
std::string root_url;
|
|
|
|
|
std::string file_system_path;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::string RegisterFileSystem(content::WebContents* web_contents,
|
|
|
|
|
const base::FilePath& path) {
|
|
|
|
|
auto* isolated_context = storage::IsolatedContext::GetInstance();
|
|
|
|
|
std::string root_name(kRootName);
|
|
|
|
|
storage::IsolatedContext::ScopedFSHandle file_system =
|
|
|
|
|
isolated_context->RegisterFileSystemForPath(
|
2021-03-04 17:27:05 +00:00
|
|
|
|
storage::kFileSystemTypeLocal, std::string(), path, &root_name);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
|
|
|
|
|
content::ChildProcessSecurityPolicy* policy =
|
|
|
|
|
content::ChildProcessSecurityPolicy::GetInstance();
|
|
|
|
|
content::RenderViewHost* render_view_host = web_contents->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());
|
|
|
|
|
|
|
|
|
|
if (!policy->CanReadFile(renderer_id, path))
|
|
|
|
|
policy->GrantReadFile(renderer_id, path);
|
|
|
|
|
|
|
|
|
|
return file_system.id();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FileSystem CreateFileSystemStruct(content::WebContents* web_contents,
|
|
|
|
|
const std::string& file_system_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
const std::string& type) {
|
2021-11-24 08:45:59 +00:00
|
|
|
|
const GURL origin = web_contents->GetURL().DeprecatedGetOriginAsURL();
|
2020-11-10 17:06:56 +00:00
|
|
|
|
std::string file_system_name =
|
|
|
|
|
storage::GetIsolatedFileSystemName(origin, file_system_id);
|
|
|
|
|
std::string root_url = storage::GetIsolatedFileSystemRootURIString(
|
|
|
|
|
origin, file_system_id, kRootName);
|
|
|
|
|
return FileSystem(type, file_system_name, root_url, file_system_path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<base::DictionaryValue> CreateFileSystemValue(
|
|
|
|
|
const FileSystem& file_system) {
|
2021-06-08 02:00:05 +00:00
|
|
|
|
auto file_system_value = std::make_unique<base::DictionaryValue>();
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_system_value->SetString("type", file_system.type);
|
|
|
|
|
file_system_value->SetString("fileSystemName", file_system.file_system_name);
|
|
|
|
|
file_system_value->SetString("rootURL", file_system.root_url);
|
|
|
|
|
file_system_value->SetString("fileSystemPath", file_system.file_system_path);
|
|
|
|
|
return file_system_value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WriteToFile(const base::FilePath& path, const std::string& content) {
|
|
|
|
|
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
|
|
|
|
base::BlockingType::WILL_BLOCK);
|
|
|
|
|
DCHECK(!path.empty());
|
|
|
|
|
|
|
|
|
|
base::WriteFile(path, content.data(), content.size());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AppendToFile(const base::FilePath& path, const std::string& content) {
|
|
|
|
|
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
|
|
|
|
|
base::BlockingType::WILL_BLOCK);
|
|
|
|
|
DCHECK(!path.empty());
|
|
|
|
|
|
2021-05-19 23:15:47 +00:00
|
|
|
|
base::AppendToFile(path, content);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PrefService* GetPrefService(content::WebContents* web_contents) {
|
|
|
|
|
auto* context = web_contents->GetBrowserContext();
|
|
|
|
|
return static_cast<electron::ElectronBrowserContext*>(context)->prefs();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::map<std::string, std::string> GetAddedFileSystemPaths(
|
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
|
auto* pref_service = GetPrefService(web_contents);
|
2022-02-10 02:58:52 +00:00
|
|
|
|
const base::Value* file_system_paths_value =
|
2020-11-10 17:06:56 +00:00
|
|
|
|
pref_service->GetDictionary(prefs::kDevToolsFileSystemPaths);
|
|
|
|
|
std::map<std::string, std::string> result;
|
|
|
|
|
if (file_system_paths_value) {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
const base::DictionaryValue* file_system_paths_dict;
|
|
|
|
|
file_system_paths_value->GetAsDictionary(&file_system_paths_dict);
|
|
|
|
|
|
|
|
|
|
for (auto it : file_system_paths_dict->DictItems()) {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
std::string type =
|
2022-02-10 02:58:52 +00:00
|
|
|
|
it.second.is_string() ? it.second.GetString() : std::string();
|
|
|
|
|
result[it.first] = type;
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsDevToolsFileSystemAdded(content::WebContents* web_contents,
|
|
|
|
|
const std::string& file_system_path) {
|
|
|
|
|
auto file_system_paths = GetAddedFileSystemPaths(web_contents);
|
|
|
|
|
return file_system_paths.find(file_system_path) != file_system_paths.end();
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 14:56:35 +00:00
|
|
|
|
void SetBackgroundColor(content::RenderWidgetHostView* rwhv, SkColor color) {
|
|
|
|
|
rwhv->SetBackgroundColor(color);
|
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(rwhv)
|
|
|
|
|
->SetContentBackgroundColor(color);
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 05:31:10 +00:00
|
|
|
|
} // namespace
|
|
|
|
|
|
2020-09-08 11:55:40 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
|
2021-03-05 00:23:10 +00:00
|
|
|
|
WebContents::Type GetTypeFromViewType(extensions::mojom::ViewType view_type) {
|
2020-09-08 11:55:40 +00:00
|
|
|
|
switch (view_type) {
|
2021-03-05 23:41:32 +00:00
|
|
|
|
case extensions::mojom::ViewType::kExtensionBackgroundPage:
|
2020-10-27 17:51:45 +00:00
|
|
|
|
return WebContents::Type::kBackgroundPage;
|
2020-09-08 11:55:40 +00:00
|
|
|
|
|
2021-03-05 23:41:32 +00:00
|
|
|
|
case extensions::mojom::ViewType::kAppWindow:
|
|
|
|
|
case extensions::mojom::ViewType::kComponent:
|
|
|
|
|
case extensions::mojom::ViewType::kExtensionDialog:
|
|
|
|
|
case extensions::mojom::ViewType::kExtensionPopup:
|
|
|
|
|
case extensions::mojom::ViewType::kBackgroundContents:
|
|
|
|
|
case extensions::mojom::ViewType::kExtensionGuest:
|
|
|
|
|
case extensions::mojom::ViewType::kTabContents:
|
|
|
|
|
case extensions::mojom::ViewType::kInvalid:
|
2020-10-27 17:51:45 +00:00
|
|
|
|
return WebContents::Type::kRemote;
|
2020-09-08 11:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
2018-10-19 08:52:07 +00:00
|
|
|
|
WebContents::WebContents(v8::Isolate* isolate,
|
|
|
|
|
content::WebContents* web_contents)
|
2019-06-14 02:44:36 +00:00
|
|
|
|
: content::WebContentsObserver(web_contents),
|
2020-10-27 17:51:45 +00:00
|
|
|
|
type_(Type::kRemote),
|
2020-07-30 16:17:57 +00:00
|
|
|
|
id_(GetAllWebContents().Add(this)),
|
2021-06-08 02:00:05 +00:00
|
|
|
|
devtools_file_system_indexer_(
|
|
|
|
|
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
2021-10-28 14:23:05 +00:00
|
|
|
|
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_task_runner_(
|
2021-01-26 18:16:21 +00:00
|
|
|
|
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2021-01-26 18:16:21 +00:00
|
|
|
|
,
|
|
|
|
|
print_task_runner_(CreatePrinterHandlerTaskRunner())
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#endif
|
2021-01-26 18:16:21 +00:00
|
|
|
|
{
|
2020-09-08 11:55:40 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
// WebContents created by extension host will have valid ViewType set.
|
2021-03-05 00:23:10 +00:00
|
|
|
|
extensions::mojom::ViewType view_type = extensions::GetViewType(web_contents);
|
2021-03-05 23:41:32 +00:00
|
|
|
|
if (view_type != extensions::mojom::ViewType::kInvalid) {
|
2020-09-08 11:55:40 +00:00
|
|
|
|
InitWithExtensionView(isolate, web_contents, view_type);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
|
|
|
|
web_contents);
|
2021-06-08 02:00:05 +00:00
|
|
|
|
script_executor_ = std::make_unique<extensions::ScriptExecutor>(web_contents);
|
2020-09-08 11:55:40 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-06-11 03:57:51 +00:00
|
|
|
|
auto session = Session::CreateFrom(isolate, GetBrowserContext());
|
|
|
|
|
session_.Reset(isolate, session.ToV8());
|
|
|
|
|
|
2020-04-13 23:39:26 +00:00
|
|
|
|
web_contents->SetUserAgentOverride(blink::UserAgentOverride::UserAgentOnly(
|
|
|
|
|
GetBrowserContext()->GetUserAgent()),
|
2018-10-19 08:52:07 +00:00
|
|
|
|
false);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
web_contents->SetUserData(kElectronApiWebContentsKey,
|
|
|
|
|
std::make_unique<UserDataLink>(GetWeakPtr()));
|
2019-10-25 13:03:28 +00:00
|
|
|
|
InitZoomController(web_contents, gin::Dictionary::CreateEmpty(isolate));
|
2018-10-19 08:52:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-25 01:17:54 +00:00
|
|
|
|
WebContents::WebContents(v8::Isolate* isolate,
|
2018-10-22 18:02:25 +00:00
|
|
|
|
std::unique_ptr<content::WebContents> web_contents,
|
2016-08-17 00:15:10 +00:00
|
|
|
|
Type type)
|
2019-06-14 02:44:36 +00:00
|
|
|
|
: content::WebContentsObserver(web_contents.get()),
|
|
|
|
|
type_(type),
|
2020-07-30 16:17:57 +00:00
|
|
|
|
id_(GetAllWebContents().Add(this)),
|
2021-06-15 00:37:55 +00:00
|
|
|
|
devtools_file_system_indexer_(
|
|
|
|
|
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
2021-10-28 14:23:05 +00:00
|
|
|
|
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_task_runner_(
|
2021-01-26 18:16:21 +00:00
|
|
|
|
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2021-01-26 18:16:21 +00:00
|
|
|
|
,
|
|
|
|
|
print_task_runner_(CreatePrinterHandlerTaskRunner())
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#endif
|
2021-01-26 18:16:21 +00:00
|
|
|
|
{
|
2020-10-27 17:51:45 +00:00
|
|
|
|
DCHECK(type != Type::kRemote)
|
2019-05-03 18:11:41 +00:00
|
|
|
|
<< "Can't take ownership of a remote WebContents";
|
2018-10-19 08:52:07 +00:00
|
|
|
|
auto session = Session::CreateFrom(isolate, GetBrowserContext());
|
|
|
|
|
session_.Reset(isolate, session.ToV8());
|
2018-10-22 18:02:25 +00:00
|
|
|
|
InitWithSessionAndOptions(isolate, std::move(web_contents), session,
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin::Dictionary::CreateEmpty(isolate));
|
2014-10-23 06:04:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
|
WebContents::WebContents(v8::Isolate* isolate,
|
|
|
|
|
const gin_helper::Dictionary& options)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
: id_(GetAllWebContents().Add(this)),
|
2021-06-08 02:00:05 +00:00
|
|
|
|
devtools_file_system_indexer_(
|
|
|
|
|
base::MakeRefCounted<DevToolsFileSystemIndexer>()),
|
2021-10-28 14:23:05 +00:00
|
|
|
|
exclusive_access_manager_(std::make_unique<ExclusiveAccessManager>(this)),
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_task_runner_(
|
2021-01-26 18:16:21 +00:00
|
|
|
|
base::ThreadPool::CreateSequencedTaskRunner({base::MayBlock()}))
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2021-01-26 18:16:21 +00:00
|
|
|
|
,
|
|
|
|
|
print_task_runner_(CreatePrinterHandlerTaskRunner())
|
2021-01-25 16:27:25 +00:00
|
|
|
|
#endif
|
2021-01-26 18:16:21 +00:00
|
|
|
|
{
|
2016-04-08 06:54:33 +00:00
|
|
|
|
// Read options.
|
|
|
|
|
options.Get("backgroundThrottling", &background_throttling_);
|
|
|
|
|
|
2019-05-20 10:55:46 +00:00
|
|
|
|
// Get type
|
|
|
|
|
options.Get("type", &type_);
|
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2019-07-31 12:34:04 +00:00
|
|
|
|
bool b = false;
|
2019-05-20 10:55:46 +00:00
|
|
|
|
if (options.Get(options::kOffscreen, &b) && b)
|
2020-10-27 17:51:45 +00:00
|
|
|
|
type_ = Type::kOffScreen;
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#endif
|
2015-06-24 15:29:32 +00:00
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
|
// Init embedder earlier
|
|
|
|
|
options.Get("embedder", &embedder_);
|
|
|
|
|
|
2016-09-07 02:16:52 +00:00
|
|
|
|
// Whether to enable DevTools.
|
|
|
|
|
options.Get("devTools", &enable_devtools_);
|
2016-09-05 08:27:56 +00:00
|
|
|
|
|
2019-12-05 17:37:42 +00:00
|
|
|
|
// BrowserViews are not attached to a window initially so they should start
|
|
|
|
|
// off as hidden. This is also important for compositor recycling. See:
|
|
|
|
|
// https://github.com/electron/electron/pull/21372
|
2021-05-19 09:27:35 +00:00
|
|
|
|
bool initially_shown = type_ != Type::kBrowserView;
|
|
|
|
|
options.Get(options::kShow, &initially_shown);
|
2019-09-05 17:56:06 +00:00
|
|
|
|
|
2015-09-05 14:39:48 +00:00
|
|
|
|
// Obtain the session.
|
|
|
|
|
std::string partition;
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin::Handle<api::Session> session;
|
2018-02-12 19:46:29 +00:00
|
|
|
|
if (options.Get("session", &session) && !session.IsEmpty()) {
|
2016-07-12 12:01:49 +00:00
|
|
|
|
} else if (options.Get("partition", &partition)) {
|
|
|
|
|
session = Session::FromPartition(isolate, partition);
|
2015-09-05 14:39:48 +00:00
|
|
|
|
} else {
|
|
|
|
|
// Use the default session if not specified.
|
2016-07-12 12:01:49 +00:00
|
|
|
|
session = Session::FromPartition(isolate, "");
|
2015-09-05 14:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
session_.Reset(isolate, session.ToV8());
|
|
|
|
|
|
2018-09-15 00:16:22 +00:00
|
|
|
|
std::unique_ptr<content::WebContents> web_contents;
|
2016-06-14 16:23:03 +00:00
|
|
|
|
if (IsGuest()) {
|
2016-05-23 03:28:59 +00:00
|
|
|
|
scoped_refptr<content::SiteInstance> site_instance =
|
2018-04-18 01:55:30 +00:00
|
|
|
|
content::SiteInstance::CreateForURL(session->browser_context(),
|
|
|
|
|
GURL("chrome-guest://fake-host"));
|
|
|
|
|
content::WebContents::CreateParams params(session->browser_context(),
|
|
|
|
|
site_instance);
|
2019-09-16 22:12:00 +00:00
|
|
|
|
guest_delegate_ =
|
|
|
|
|
std::make_unique<WebViewGuestDelegate>(embedder_->web_contents(), this);
|
2015-06-25 06:28:13 +00:00
|
|
|
|
params.guest_delegate = guest_delegate_.get();
|
2017-03-05 15:18:57 +00:00
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2017-03-04 02:09:16 +00:00
|
|
|
|
if (embedder_ && embedder_->IsOffScreen()) {
|
2018-04-18 01:55:30 +00:00
|
|
|
|
auto* view = new OffScreenWebContentsView(
|
2019-05-03 19:08:41 +00:00
|
|
|
|
false,
|
|
|
|
|
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
|
2017-03-04 02:09:16 +00:00
|
|
|
|
params.view = view;
|
|
|
|
|
params.delegate_view = view;
|
2017-03-05 15:18:57 +00:00
|
|
|
|
|
2017-03-04 02:09:16 +00:00
|
|
|
|
web_contents = content::WebContents::Create(params);
|
2018-10-05 18:03:35 +00:00
|
|
|
|
view->SetWebContents(web_contents.get());
|
2017-03-04 02:09:16 +00:00
|
|
|
|
} else {
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#endif
|
2017-03-04 02:09:16 +00:00
|
|
|
|
web_contents = content::WebContents::Create(params);
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2017-03-04 02:09:16 +00:00
|
|
|
|
}
|
2016-07-31 10:19:56 +00:00
|
|
|
|
} else if (IsOffScreen()) {
|
2022-02-23 10:33:42 +00:00
|
|
|
|
// webPreferences does not have a transparent option, so if the window needs
|
|
|
|
|
// to be transparent, that will be set at electron_api_browser_window.cc#L57
|
|
|
|
|
// and we then need to pull it back out and check it here.
|
|
|
|
|
std::string background_color;
|
|
|
|
|
options.GetHidden(options::kBackgroundColor, &background_color);
|
2022-03-21 17:35:54 +00:00
|
|
|
|
bool transparent = ParseCSSColor(background_color) == SK_ColorTRANSPARENT;
|
2016-08-01 11:27:39 +00:00
|
|
|
|
|
2016-07-29 12:50:27 +00:00
|
|
|
|
content::WebContents::CreateParams params(session->browser_context());
|
2018-04-18 01:55:30 +00:00
|
|
|
|
auto* view = new OffScreenWebContentsView(
|
2019-05-03 19:08:41 +00:00
|
|
|
|
transparent,
|
|
|
|
|
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
|
2016-08-03 04:04:36 +00:00
|
|
|
|
params.view = view;
|
|
|
|
|
params.delegate_view = view;
|
2016-07-25 13:55:00 +00:00
|
|
|
|
|
2015-06-24 15:29:32 +00:00
|
|
|
|
web_contents = content::WebContents::Create(params);
|
2018-10-05 18:03:35 +00:00
|
|
|
|
view->SetWebContents(web_contents.get());
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#endif
|
2016-07-29 12:50:27 +00:00
|
|
|
|
} else {
|
|
|
|
|
content::WebContents::CreateParams params(session->browser_context());
|
2021-05-19 09:27:35 +00:00
|
|
|
|
params.initially_hidden = !initially_shown;
|
2016-07-27 23:58:23 +00:00
|
|
|
|
web_contents = content::WebContents::Create(params);
|
2015-06-24 14:14:46 +00:00
|
|
|
|
}
|
2015-06-09 07:50:20 +00:00
|
|
|
|
|
2018-10-22 18:02:25 +00:00
|
|
|
|
InitWithSessionAndOptions(isolate, std::move(web_contents), session, options);
|
2016-08-17 00:15:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-10-21 20:21:24 +00:00
|
|
|
|
void WebContents::InitZoomController(content::WebContents* web_contents,
|
2019-10-25 13:03:28 +00:00
|
|
|
|
const gin_helper::Dictionary& options) {
|
2017-10-21 20:21:24 +00:00
|
|
|
|
WebContentsZoomController::CreateForWebContents(web_contents);
|
|
|
|
|
zoom_controller_ = WebContentsZoomController::FromWebContents(web_contents);
|
|
|
|
|
double zoom_factor;
|
|
|
|
|
if (options.Get(options::kZoomFactor, &zoom_factor))
|
|
|
|
|
zoom_controller_->SetDefaultZoomFactor(zoom_factor);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-22 18:02:25 +00:00
|
|
|
|
void WebContents::InitWithSessionAndOptions(
|
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
std::unique_ptr<content::WebContents> owned_web_contents,
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin::Handle<api::Session> session,
|
|
|
|
|
const gin_helper::Dictionary& options) {
|
2018-10-22 18:02:25 +00:00
|
|
|
|
Observe(owned_web_contents.get());
|
2021-09-20 00:34:11 +00:00
|
|
|
|
InitWithWebContents(std::move(owned_web_contents), session->browser_context(),
|
2018-10-22 18:02:25 +00:00
|
|
|
|
IsGuest());
|
2015-06-05 07:01:51 +00:00
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->GetView()->SetDelegate(this);
|
2015-10-01 03:14:19 +00:00
|
|
|
|
|
2018-10-22 18:02:25 +00:00
|
|
|
|
auto* prefs = web_contents()->GetMutableRendererPrefs();
|
2020-05-04 17:49:29 +00:00
|
|
|
|
|
|
|
|
|
// Collect preferred languages from OS and browser process. accept_languages
|
|
|
|
|
// effects HTTP header, navigator.languages, and CJK fallback font selection.
|
|
|
|
|
//
|
|
|
|
|
// Note that an application locale set to the browser process might be
|
|
|
|
|
// different with the one set to the preference list.
|
|
|
|
|
// (e.g. overridden with --lang)
|
|
|
|
|
std::string accept_languages =
|
|
|
|
|
g_browser_process->GetApplicationLocale() + ",";
|
|
|
|
|
for (auto const& language : electron::GetPreferredLanguages()) {
|
|
|
|
|
if (language == g_browser_process->GetApplicationLocale())
|
|
|
|
|
continue;
|
|
|
|
|
accept_languages += language + ",";
|
|
|
|
|
}
|
|
|
|
|
accept_languages.pop_back();
|
|
|
|
|
prefs->accept_languages = accept_languages;
|
2018-04-02 03:47:00 +00:00
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_WIN)
|
2018-02-22 08:56:48 +00:00
|
|
|
|
// Update font settings.
|
2021-07-06 12:17:13 +00:00
|
|
|
|
static const gfx::FontRenderParams params(
|
2019-01-10 16:28:15 +00:00
|
|
|
|
gfx::GetFontRenderParams(gfx::FontRenderParamsQuery(), nullptr));
|
2021-07-06 12:17:13 +00:00
|
|
|
|
prefs->should_antialias_text = params.antialiasing;
|
|
|
|
|
prefs->use_subpixel_positioning = params.subpixel_positioning;
|
|
|
|
|
prefs->hinting = params.hinting;
|
|
|
|
|
prefs->use_autohinter = params.autohinter;
|
|
|
|
|
prefs->use_bitmaps = params.use_bitmaps;
|
|
|
|
|
prefs->subpixel_rendering = params.subpixel_rendering;
|
2018-02-22 08:56:48 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2019-09-19 18:43:21 +00:00
|
|
|
|
// Honor the system's cursor blink rate settings
|
|
|
|
|
if (auto interval = GetCursorBlinkInterval())
|
|
|
|
|
prefs->caret_blink_interval = *interval;
|
2019-08-30 14:39:46 +00:00
|
|
|
|
|
2015-09-22 13:56:56 +00:00
|
|
|
|
// Save the preferences in C++.
|
2020-11-10 17:06:03 +00:00
|
|
|
|
// If there's already a WebContentsPreferences object, we created it as part
|
|
|
|
|
// of the webContents.setWindowOpenHandler path, so don't overwrite it.
|
|
|
|
|
if (!WebContentsPreferences::From(web_contents())) {
|
|
|
|
|
new WebContentsPreferences(web_contents(), options);
|
|
|
|
|
}
|
2020-08-12 18:33:58 +00:00
|
|
|
|
// Trigger re-calculation of webkit prefs.
|
|
|
|
|
web_contents()->NotifyPreferencesChanged();
|
2015-09-04 16:44:22 +00:00
|
|
|
|
|
2018-10-22 18:02:25 +00:00
|
|
|
|
WebContentsPermissionHelper::CreateForWebContents(web_contents());
|
|
|
|
|
InitZoomController(web_contents(), options);
|
2019-07-24 23:01:08 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
2020-02-03 22:01:10 +00:00
|
|
|
|
extensions::ElectronExtensionWebContentsObserver::CreateForWebContents(
|
2019-07-24 23:01:08 +00:00
|
|
|
|
web_contents());
|
2021-06-08 02:00:05 +00:00
|
|
|
|
script_executor_ =
|
|
|
|
|
std::make_unique<extensions::ScriptExecutor>(web_contents());
|
2019-07-24 23:01:08 +00:00
|
|
|
|
#endif
|
2016-01-23 13:29:47 +00:00
|
|
|
|
|
2019-08-19 20:13:24 +00:00
|
|
|
|
AutofillDriverFactory::CreateForWebContents(web_contents());
|
2019-04-02 22:38:16 +00:00
|
|
|
|
|
2020-04-13 23:39:26 +00:00
|
|
|
|
web_contents()->SetUserAgentOverride(blink::UserAgentOverride::UserAgentOnly(
|
|
|
|
|
GetBrowserContext()->GetUserAgent()),
|
2018-10-22 18:02:25 +00:00
|
|
|
|
false);
|
2015-07-14 19:13:25 +00:00
|
|
|
|
|
2016-06-14 16:23:03 +00:00
|
|
|
|
if (IsGuest()) {
|
2015-06-24 15:29:32 +00:00
|
|
|
|
NativeWindow* owner_window = nullptr;
|
2017-03-04 02:09:16 +00:00
|
|
|
|
if (embedder_) {
|
2015-06-24 15:29:32 +00:00
|
|
|
|
// New WebContents's owner_window is the embedder's owner_window.
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* relay =
|
2016-02-17 08:52:19 +00:00
|
|
|
|
NativeWindowRelay::FromWebContents(embedder_->web_contents());
|
2015-06-24 15:29:32 +00:00
|
|
|
|
if (relay)
|
2018-10-02 22:14:43 +00:00
|
|
|
|
owner_window = relay->GetNativeWindow();
|
2015-06-24 15:29:32 +00:00
|
|
|
|
}
|
|
|
|
|
if (owner_window)
|
|
|
|
|
SetOwnerWindow(owner_window);
|
|
|
|
|
}
|
2016-04-25 01:17:54 +00:00
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
web_contents()->SetUserData(kElectronApiWebContentsKey,
|
|
|
|
|
std::make_unique<UserDataLink>(GetWeakPtr()));
|
2014-10-23 06:04:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-09-08 11:55:40 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
void WebContents::InitWithExtensionView(v8::Isolate* isolate,
|
|
|
|
|
content::WebContents* web_contents,
|
2021-03-05 00:23:10 +00:00
|
|
|
|
extensions::mojom::ViewType view_type) {
|
2020-09-08 11:55:40 +00:00
|
|
|
|
// Must reassign type prior to calling `Init`.
|
|
|
|
|
type_ = GetTypeFromViewType(view_type);
|
2021-07-26 16:02:16 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2020-09-08 11:55:40 +00:00
|
|
|
|
return;
|
2021-07-26 16:02:16 +00:00
|
|
|
|
if (type_ == Type::kBackgroundPage)
|
|
|
|
|
// non-background-page WebContents are retained by other classes. We need
|
|
|
|
|
// to pin here to prevent background-page WebContents from being GC'd.
|
|
|
|
|
// The background page api::WebContents will live until the underlying
|
|
|
|
|
// content::WebContents is destroyed.
|
|
|
|
|
Pin(isolate);
|
2020-09-08 11:55:40 +00:00
|
|
|
|
|
|
|
|
|
// Allow toggling DevTools for background pages
|
|
|
|
|
Observe(web_contents);
|
2021-09-20 00:34:11 +00:00
|
|
|
|
InitWithWebContents(std::unique_ptr<content::WebContents>(web_contents),
|
|
|
|
|
GetBrowserContext(), IsGuest());
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->GetView()->SetDelegate(this);
|
2020-09-08 11:55:40 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-09-20 00:34:11 +00:00
|
|
|
|
void WebContents::InitWithWebContents(
|
|
|
|
|
std::unique_ptr<content::WebContents> web_contents,
|
|
|
|
|
ElectronBrowserContext* browser_context,
|
|
|
|
|
bool is_guest) {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
browser_context_ = browser_context;
|
|
|
|
|
web_contents->SetDelegate(this);
|
|
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2021-09-20 00:34:11 +00:00
|
|
|
|
PrintPreviewMessageHandler::CreateForWebContents(web_contents.get());
|
|
|
|
|
PrintViewManagerElectron::CreateForWebContents(web_contents.get());
|
|
|
|
|
printing::CreateCompositeClientIfNeeded(web_contents.get(),
|
2020-11-10 17:06:56 +00:00
|
|
|
|
browser_context->GetUserAgent());
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PDF_VIEWER)
|
|
|
|
|
pdf::PDFWebContentsHelper::CreateForWebContentsWithClient(
|
2021-09-20 00:34:11 +00:00
|
|
|
|
web_contents.get(),
|
|
|
|
|
std::make_unique<ElectronPDFWebContentsHelperClient>());
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
// Determine whether the WebContents is offscreen.
|
2021-09-20 00:34:11 +00:00
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents.get());
|
2021-07-26 16:04:09 +00:00
|
|
|
|
offscreen_ = web_preferences && web_preferences->IsOffscreen();
|
2020-11-10 17:06:56 +00:00
|
|
|
|
|
|
|
|
|
// Create InspectableWebContents.
|
2021-06-08 02:00:05 +00:00
|
|
|
|
inspectable_web_contents_ = std::make_unique<InspectableWebContents>(
|
2021-09-20 00:34:11 +00:00
|
|
|
|
std::move(web_contents), browser_context->prefs(), is_guest);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->SetDelegate(this);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
|
WebContents::~WebContents() {
|
2021-09-23 11:00:11 +00:00
|
|
|
|
// clear out objects that have been granted permissions so that when
|
|
|
|
|
// WebContents::RenderFrameDeleted is called as a result of WebContents
|
|
|
|
|
// destruction it doesn't try to clear out a granted_devices_
|
|
|
|
|
// on a destructed object.
|
|
|
|
|
granted_devices_.clear();
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
if (!inspectable_web_contents_) {
|
|
|
|
|
WebContentsDestroyed();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-08 11:55:40 +00:00
|
|
|
|
|
2021-03-22 01:56:30 +00:00
|
|
|
|
inspectable_web_contents_->GetView()->SetDelegate(nullptr);
|
2018-02-22 07:52:08 +00:00
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
// This event is only for internal use, which is emitted when WebContents is
|
|
|
|
|
// being destroyed.
|
|
|
|
|
Emit("will-destroy");
|
2017-04-03 20:03:51 +00:00
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
// For guest view based on OOPIF, the WebContents is released by the embedder
|
|
|
|
|
// frame, and we need to clear the reference to the memory.
|
|
|
|
|
bool not_owned_by_this = IsGuest() && attached_;
|
|
|
|
|
#if BUILDFLAG(ENABLE_ELECTRON_EXTENSIONS)
|
|
|
|
|
// And background pages are owned by extensions::ExtensionHost.
|
|
|
|
|
if (type_ == Type::kBackgroundPage)
|
|
|
|
|
not_owned_by_this = true;
|
|
|
|
|
#endif
|
|
|
|
|
if (not_owned_by_this) {
|
|
|
|
|
inspectable_web_contents_->ReleaseWebContents();
|
|
|
|
|
WebContentsDestroyed();
|
2016-01-13 09:59:59 +00:00
|
|
|
|
}
|
2021-03-15 22:43:25 +00:00
|
|
|
|
|
|
|
|
|
// InspectableWebContents will be automatically destroyed.
|
2014-04-24 08:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-27 07:20:55 +00:00
|
|
|
|
void WebContents::DeleteThisIfAlive() {
|
|
|
|
|
// It is possible that the FirstWeakCallback has been called but the
|
|
|
|
|
// SecondWeakCallback has not, in this case the garbage collection of
|
|
|
|
|
// WebContents has already started and we should not |delete this|.
|
|
|
|
|
// Calling |GetWrapper| can detect this corner case.
|
|
|
|
|
auto* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
v8::Local<v8::Object> wrapper;
|
|
|
|
|
if (!GetWrapper(isolate).ToLocal(&wrapper))
|
|
|
|
|
return;
|
|
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
void WebContents::Destroy() {
|
|
|
|
|
// The content::WebContents should be destroyed asyncronously when possible
|
|
|
|
|
// as user may choose to destroy WebContents during an event of it.
|
2021-11-15 07:24:22 +00:00
|
|
|
|
if (Browser::Get()->is_shutting_down() || IsGuest()) {
|
2021-09-27 07:20:55 +00:00
|
|
|
|
DeleteThisIfAlive();
|
2021-03-15 22:43:25 +00:00
|
|
|
|
} else {
|
|
|
|
|
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
|
|
|
|
base::BindOnce(
|
|
|
|
|
[](base::WeakPtr<WebContents> contents) {
|
|
|
|
|
if (contents)
|
2021-09-27 07:20:55 +00:00
|
|
|
|
contents->DeleteThisIfAlive();
|
2021-03-15 22:43:25 +00:00
|
|
|
|
},
|
|
|
|
|
GetWeakPtr()));
|
|
|
|
|
}
|
2017-03-18 19:40:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-01 00:18:22 +00:00
|
|
|
|
bool WebContents::DidAddMessageToConsole(
|
|
|
|
|
content::WebContents* source,
|
|
|
|
|
blink::mojom::ConsoleMessageLevel level,
|
2021-03-16 16:18:45 +00:00
|
|
|
|
const std::u16string& message,
|
2019-05-01 00:18:22 +00:00
|
|
|
|
int32_t line_no,
|
2021-03-16 16:18:45 +00:00
|
|
|
|
const std::u16string& source_id) {
|
2019-05-01 00:18:22 +00:00
|
|
|
|
return Emit("console-message", static_cast<int32_t>(level), message, line_no,
|
|
|
|
|
source_id);
|
2014-10-25 02:01:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-09 23:30:38 +00:00
|
|
|
|
void WebContents::OnCreateWindow(
|
|
|
|
|
const GURL& target_url,
|
2018-04-05 23:13:24 +00:00
|
|
|
|
const content::Referrer& referrer,
|
2016-10-09 23:30:38 +00:00
|
|
|
|
const std::string& frame_name,
|
|
|
|
|
WindowOpenDisposition disposition,
|
2020-03-26 18:05:45 +00:00
|
|
|
|
const std::string& features,
|
2018-04-11 08:42:14 +00:00
|
|
|
|
const scoped_refptr<network::ResourceRequestBody>& body) {
|
2020-03-26 18:05:45 +00:00
|
|
|
|
Emit("-new-window", target_url, frame_name, disposition, features, referrer,
|
|
|
|
|
body);
|
2014-10-25 05:21:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-26 18:05:45 +00:00
|
|
|
|
void WebContents::WebContentsCreatedWithFullParams(
|
|
|
|
|
content::WebContents* source_contents,
|
|
|
|
|
int opener_render_process_id,
|
|
|
|
|
int opener_render_frame_id,
|
|
|
|
|
const content::mojom::CreateNewWindowParams& params,
|
|
|
|
|
content::WebContents* new_contents) {
|
2018-10-22 18:02:25 +00:00
|
|
|
|
ChildWebContentsTracker::CreateForWebContents(new_contents);
|
|
|
|
|
auto* tracker = ChildWebContentsTracker::FromWebContents(new_contents);
|
2020-03-26 18:05:45 +00:00
|
|
|
|
tracker->url = params.target_url;
|
|
|
|
|
tracker->frame_name = params.frame_name;
|
|
|
|
|
tracker->referrer = params.referrer.To<content::Referrer>();
|
|
|
|
|
tracker->raw_features = params.raw_features;
|
|
|
|
|
tracker->body = params.body;
|
2020-11-10 17:06:03 +00:00
|
|
|
|
|
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
|
|
|
|
|
gin_helper::Dictionary dict;
|
|
|
|
|
gin::ConvertFromV8(isolate, pending_child_web_preferences_.Get(isolate),
|
|
|
|
|
&dict);
|
|
|
|
|
pending_child_web_preferences_.Reset();
|
|
|
|
|
|
|
|
|
|
// Associate the preferences passed in via `setWindowOpenHandler` with the
|
|
|
|
|
// content::WebContents that was just created for the child window. These
|
|
|
|
|
// preferences will be picked up by the RenderWidgetHost via its call to the
|
|
|
|
|
// delegate's OverrideWebkitPrefs.
|
|
|
|
|
new WebContentsPreferences(new_contents, dict);
|
2016-08-16 00:13:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-04-13 15:37:41 +00:00
|
|
|
|
bool WebContents::IsWebContentsCreationOverridden(
|
|
|
|
|
content::SiteInstance* source_site_instance,
|
|
|
|
|
content::mojom::WindowContainerType window_container_type,
|
|
|
|
|
const GURL& opener_url,
|
2020-11-10 17:06:03 +00:00
|
|
|
|
const content::mojom::CreateNewWindowParams& params) {
|
2021-04-13 19:35:27 +00:00
|
|
|
|
bool default_prevented = Emit(
|
|
|
|
|
"-will-add-new-contents", params.target_url, params.frame_name,
|
|
|
|
|
params.raw_features, params.disposition, *params.referrer, params.body);
|
2020-11-10 17:06:03 +00:00
|
|
|
|
// If the app prevented the default, redirect to CreateCustomWebContents,
|
|
|
|
|
// which always returns nullptr, which will result in the window open being
|
|
|
|
|
// prevented (window.open() will return null in the renderer).
|
|
|
|
|
return default_prevented;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SetNextChildWebPreferences(
|
|
|
|
|
const gin_helper::Dictionary preferences) {
|
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
// Store these prefs for when Chrome calls WebContentsCreatedWithFullParams
|
|
|
|
|
// with the new child contents.
|
|
|
|
|
pending_child_web_preferences_.Reset(isolate, preferences.GetHandle());
|
2020-04-13 15:37:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content::WebContents* WebContents::CreateCustomWebContents(
|
|
|
|
|
content::RenderFrameHost* opener,
|
|
|
|
|
content::SiteInstance* source_site_instance,
|
|
|
|
|
bool is_new_browsing_instance,
|
|
|
|
|
const GURL& opener_url,
|
|
|
|
|
const std::string& frame_name,
|
|
|
|
|
const GURL& target_url,
|
2022-02-25 18:17:35 +00:00
|
|
|
|
const content::StoragePartitionConfig& partition_config,
|
2020-04-13 15:37:41 +00:00
|
|
|
|
content::SessionStorageNamespace* session_storage_namespace) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 00:16:22 +00:00
|
|
|
|
void WebContents::AddNewContents(
|
|
|
|
|
content::WebContents* source,
|
|
|
|
|
std::unique_ptr<content::WebContents> new_contents,
|
2020-05-26 20:06:26 +00:00
|
|
|
|
const GURL& target_url,
|
2018-09-15 00:16:22 +00:00
|
|
|
|
WindowOpenDisposition disposition,
|
|
|
|
|
const gfx::Rect& initial_rect,
|
|
|
|
|
bool user_gesture,
|
|
|
|
|
bool* was_blocked) {
|
2018-10-22 18:02:25 +00:00
|
|
|
|
auto* tracker = ChildWebContentsTracker::FromWebContents(new_contents.get());
|
|
|
|
|
DCHECK(tracker);
|
|
|
|
|
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2018-10-22 18:02:25 +00:00
|
|
|
|
auto api_web_contents =
|
2020-10-27 17:51:45 +00:00
|
|
|
|
CreateAndTake(isolate, std::move(new_contents), Type::kBrowserWindow);
|
2021-03-15 22:43:25 +00:00
|
|
|
|
|
|
|
|
|
// We call RenderFrameCreated here as at this point the empty "about:blank"
|
|
|
|
|
// render frame has already been created. If the window never navigates again
|
|
|
|
|
// RenderFrameCreated won't be called and certain prefs like
|
|
|
|
|
// "kBackgroundColor" will not be applied.
|
|
|
|
|
auto* frame = api_web_contents->MainFrame();
|
|
|
|
|
if (frame) {
|
|
|
|
|
api_web_contents->HandleNewRenderFrame(frame);
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-10 23:40:07 +00:00
|
|
|
|
if (Emit("-add-new-contents", api_web_contents, disposition, user_gesture,
|
2018-04-18 01:55:30 +00:00
|
|
|
|
initial_rect.x(), initial_rect.y(), initial_rect.width(),
|
2020-03-26 18:05:45 +00:00
|
|
|
|
initial_rect.height(), tracker->url, tracker->frame_name,
|
|
|
|
|
tracker->referrer, tracker->raw_features, tracker->body)) {
|
2021-03-15 22:43:25 +00:00
|
|
|
|
api_web_contents->Destroy();
|
2017-01-10 23:40:07 +00:00
|
|
|
|
}
|
2016-08-16 00:13:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 10:06:32 +00:00
|
|
|
|
content::WebContents* WebContents::OpenURLFromTab(
|
|
|
|
|
content::WebContents* source,
|
|
|
|
|
const content::OpenURLParams& params) {
|
2020-07-30 16:17:57 +00:00
|
|
|
|
auto weak_this = GetWeakPtr();
|
2017-01-24 07:50:02 +00:00
|
|
|
|
if (params.disposition != WindowOpenDisposition::CURRENT_TAB) {
|
2020-03-26 18:05:45 +00:00
|
|
|
|
Emit("-new-window", params.url, "", params.disposition, "", params.referrer,
|
|
|
|
|
params.post_data);
|
2014-12-17 22:55:22 +00:00
|
|
|
|
return nullptr;
|
2014-11-04 09:59:15 +00:00
|
|
|
|
}
|
2014-10-24 10:06:32 +00:00
|
|
|
|
|
2021-03-02 17:38:56 +00:00
|
|
|
|
if (!weak_this || !web_contents())
|
2016-12-21 00:51:03 +00:00
|
|
|
|
return nullptr;
|
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
content::NavigationController::LoadURLParams load_url_params(params.url);
|
|
|
|
|
load_url_params.referrer = params.referrer;
|
|
|
|
|
load_url_params.transition_type = params.transition;
|
|
|
|
|
load_url_params.extra_headers = params.extra_headers;
|
|
|
|
|
load_url_params.should_replace_current_entry =
|
|
|
|
|
params.should_replace_current_entry;
|
|
|
|
|
load_url_params.is_renderer_initiated = params.is_renderer_initiated;
|
|
|
|
|
load_url_params.started_from_context_menu = params.started_from_context_menu;
|
|
|
|
|
load_url_params.initiator_origin = params.initiator_origin;
|
|
|
|
|
load_url_params.source_site_instance = params.source_site_instance;
|
|
|
|
|
load_url_params.frame_tree_node_id = params.frame_tree_node_id;
|
|
|
|
|
load_url_params.redirect_chain = params.redirect_chain;
|
|
|
|
|
load_url_params.has_user_gesture = params.user_gesture;
|
|
|
|
|
load_url_params.blob_url_loader_factory = params.blob_url_loader_factory;
|
|
|
|
|
load_url_params.href_translate = params.href_translate;
|
|
|
|
|
load_url_params.reload_type = params.reload_type;
|
|
|
|
|
|
|
|
|
|
if (params.post_data) {
|
|
|
|
|
load_url_params.load_type =
|
|
|
|
|
content::NavigationController::LOAD_TYPE_HTTP_POST;
|
|
|
|
|
load_url_params.post_data = params.post_data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source->GetController().LoadURLWithParams(load_url_params);
|
|
|
|
|
return source;
|
2014-10-24 10:06:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-25 03:07:23 +00:00
|
|
|
|
void WebContents::BeforeUnloadFired(content::WebContents* tab,
|
|
|
|
|
bool proceed,
|
|
|
|
|
bool* proceed_to_fire_unload) {
|
2021-04-07 07:16:10 +00:00
|
|
|
|
if (type_ == Type::kBrowserWindow || type_ == Type::kOffScreen ||
|
|
|
|
|
type_ == Type::kBrowserView)
|
2015-06-25 03:07:23 +00:00
|
|
|
|
*proceed_to_fire_unload = proceed;
|
|
|
|
|
else
|
|
|
|
|
*proceed_to_fire_unload = true;
|
2020-05-26 13:21:38 +00:00
|
|
|
|
// Note that Chromium does not emit this for navigations.
|
|
|
|
|
Emit("before-unload-fired", proceed);
|
2015-06-25 03:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 21:56:09 +00:00
|
|
|
|
void WebContents::SetContentsBounds(content::WebContents* source,
|
2020-02-11 00:37:46 +00:00
|
|
|
|
const gfx::Rect& rect) {
|
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnSetContentBounds(rect);
|
2015-06-25 03:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::CloseContents(content::WebContents* source) {
|
2015-07-10 02:38:15 +00:00
|
|
|
|
Emit("close");
|
2019-08-19 20:13:24 +00:00
|
|
|
|
|
|
|
|
|
auto* autofill_driver_factory =
|
|
|
|
|
AutofillDriverFactory::FromWebContents(web_contents());
|
|
|
|
|
if (autofill_driver_factory) {
|
|
|
|
|
autofill_driver_factory->CloseAllPopups();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-22 07:52:08 +00:00
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnCloseContents();
|
2015-06-25 03:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::ActivateContents(content::WebContents* source) {
|
2020-02-11 00:37:46 +00:00
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnActivateContents();
|
2015-06-25 03:07:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-06-07 06:56:19 +00:00
|
|
|
|
void WebContents::UpdateTargetURL(content::WebContents* source,
|
|
|
|
|
const GURL& url) {
|
|
|
|
|
Emit("update-target-url", url);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-09 20:01:49 +00:00
|
|
|
|
bool WebContents::HandleKeyboardEvent(
|
2014-10-24 13:46:47 +00:00
|
|
|
|
content::WebContents* source,
|
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kWebView && embedder_) {
|
2015-06-25 03:07:23 +00:00
|
|
|
|
// Send the unhandled keyboard events back to the embedder.
|
2019-01-09 20:01:49 +00:00
|
|
|
|
return embedder_->HandleKeyboardEvent(source, event);
|
2016-05-18 04:47:50 +00:00
|
|
|
|
} else {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return PlatformHandleKeyboardEvent(source, event);
|
2015-06-25 03:07:23 +00:00
|
|
|
|
}
|
2014-10-24 13:46:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
// NOTE: The macOS version of this function is found in
|
|
|
|
|
// electron_api_web_contents_mac.mm, as it requires calling into objective-C
|
|
|
|
|
// code.
|
|
|
|
|
bool WebContents::PlatformHandleKeyboardEvent(
|
|
|
|
|
content::WebContents* source,
|
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
|
|
|
|
// Escape exits tabbed fullscreen mode.
|
|
|
|
|
if (event.windows_key_code == ui::VKEY_ESCAPE && is_html_fullscreen()) {
|
|
|
|
|
ExitFullscreenModeForTab(source);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Check if the webContents has preferences and to ignore shortcuts
|
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(source);
|
2021-07-26 16:04:09 +00:00
|
|
|
|
if (web_preferences && web_preferences->ShouldIgnoreMenuShortcuts())
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
// Let the NativeWindow handle other parts.
|
|
|
|
|
if (owner_window()) {
|
|
|
|
|
owner_window()->HandleKeyboardEvent(source, event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-06-16 21:35:43 +00:00
|
|
|
|
content::KeyboardEventProcessingResult WebContents::PreHandleKeyboardEvent(
|
2016-12-06 22:41:18 +00:00
|
|
|
|
content::WebContents* source,
|
2017-06-16 21:35:43 +00:00
|
|
|
|
const content::NativeWebKeyboardEvent& event) {
|
2022-02-09 09:40:50 +00:00
|
|
|
|
if (exclusive_access_manager_->HandleUserKeyEvent(event))
|
|
|
|
|
return content::KeyboardEventProcessingResult::HANDLED;
|
|
|
|
|
|
2017-06-16 20:42:33 +00:00
|
|
|
|
if (event.GetType() == blink::WebInputEvent::Type::kRawKeyDown ||
|
|
|
|
|
event.GetType() == blink::WebInputEvent::Type::kKeyUp) {
|
2017-06-16 21:35:43 +00:00
|
|
|
|
bool prevent_default = Emit("before-input-event", event);
|
|
|
|
|
if (prevent_default) {
|
|
|
|
|
return content::KeyboardEventProcessingResult::HANDLED;
|
|
|
|
|
}
|
2017-06-25 19:01:05 +00:00
|
|
|
|
}
|
2017-06-16 21:35:43 +00:00
|
|
|
|
|
|
|
|
|
return content::KeyboardEventProcessingResult::NOT_HANDLED;
|
2016-12-06 22:41:18 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-05-14 06:40:40 +00:00
|
|
|
|
void WebContents::ContentsZoomChange(bool zoom_in) {
|
|
|
|
|
Emit("zoom-changed", zoom_in ? "in" : "out");
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 14:23:05 +00:00
|
|
|
|
Profile* WebContents::GetProfile() {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsFullscreen() const {
|
|
|
|
|
return owner_window_ && owner_window_->IsFullscreen();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::EnterFullscreen(const GURL& url,
|
|
|
|
|
ExclusiveAccessBubbleType bubble_type,
|
|
|
|
|
const int64_t display_id) {}
|
|
|
|
|
|
|
|
|
|
void WebContents::ExitFullscreen() {}
|
|
|
|
|
|
|
|
|
|
void WebContents::UpdateExclusiveAccessExitBubbleContent(
|
|
|
|
|
const GURL& url,
|
|
|
|
|
ExclusiveAccessBubbleType bubble_type,
|
|
|
|
|
ExclusiveAccessBubbleHideCallback bubble_first_hide_callback,
|
|
|
|
|
bool force_update) {}
|
|
|
|
|
|
|
|
|
|
void WebContents::OnExclusiveAccessUserInput() {}
|
|
|
|
|
|
|
|
|
|
content::WebContents* WebContents::GetActiveWebContents() {
|
|
|
|
|
return web_contents();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::CanUserExitFullscreen() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsExclusiveAccessBubbleDisplayed() const {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 00:17:50 +00:00
|
|
|
|
void WebContents::EnterFullscreenModeForTab(
|
2020-06-01 20:34:34 +00:00
|
|
|
|
content::RenderFrameHost* requesting_frame,
|
2019-10-28 22:12:35 +00:00
|
|
|
|
const blink::mojom::FullscreenOptions& options) {
|
2020-06-01 20:34:34 +00:00
|
|
|
|
auto* source = content::WebContents::FromRenderFrameHost(requesting_frame);
|
2018-04-18 10:09:45 +00:00
|
|
|
|
auto* permission_helper =
|
|
|
|
|
WebContentsPermissionHelper::FromWebContents(source);
|
2019-05-03 19:08:41 +00:00
|
|
|
|
auto callback =
|
|
|
|
|
base::BindRepeating(&WebContents::OnEnterFullscreenModeForTab,
|
2020-06-01 20:34:34 +00:00
|
|
|
|
base::Unretained(this), requesting_frame, options);
|
2016-02-01 10:03:38 +00:00
|
|
|
|
permission_helper->RequestFullscreenPermission(callback);
|
2021-10-28 14:23:05 +00:00
|
|
|
|
exclusive_access_manager_->fullscreen_controller()->EnterFullscreenModeForTab(
|
|
|
|
|
requesting_frame, options.display_id);
|
2016-02-01 10:03:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 00:17:50 +00:00
|
|
|
|
void WebContents::OnEnterFullscreenModeForTab(
|
2020-06-01 20:34:34 +00:00
|
|
|
|
content::RenderFrameHost* requesting_frame,
|
2019-10-28 22:12:35 +00:00
|
|
|
|
const blink::mojom::FullscreenOptions& options,
|
2018-09-15 00:17:50 +00:00
|
|
|
|
bool allowed) {
|
2021-08-17 07:03:45 +00:00
|
|
|
|
if (!allowed || !owner_window_)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
2021-08-17 07:03:45 +00:00
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
auto* source = content::WebContents::FromRenderFrameHost(requesting_frame);
|
|
|
|
|
if (IsFullscreenForTabOrPending(source)) {
|
|
|
|
|
DCHECK_EQ(fullscreen_frame_, source->GetFocusedFrame());
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-08-17 07:03:45 +00:00
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
SetHtmlApiFullscreen(true);
|
|
|
|
|
|
|
|
|
|
if (native_fullscreen_) {
|
|
|
|
|
// Explicitly trigger a view resize, as the size is not actually changing if
|
|
|
|
|
// the browser is fullscreened, too.
|
|
|
|
|
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
|
|
|
|
}
|
2015-05-08 06:18:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-09 12:17:40 +00:00
|
|
|
|
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
if (!owner_window_)
|
|
|
|
|
return;
|
2021-08-17 07:03:45 +00:00
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
SetHtmlApiFullscreen(false);
|
|
|
|
|
|
|
|
|
|
if (native_fullscreen_) {
|
|
|
|
|
// Explicitly trigger a view resize, as the size is not actually changing if
|
|
|
|
|
// the browser is fullscreened, too. Chrome does this indirectly from
|
|
|
|
|
// `chrome/browser/ui/exclusive_access/fullscreen_controller.cc`.
|
|
|
|
|
source->GetRenderViewHost()->GetWidget()->SynchronizeVisualProperties();
|
|
|
|
|
}
|
2021-10-28 14:23:05 +00:00
|
|
|
|
|
|
|
|
|
exclusive_access_manager_->fullscreen_controller()->ExitFullscreenModeForTab(
|
|
|
|
|
source);
|
2015-05-08 06:18:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 09:59:40 +00:00
|
|
|
|
void WebContents::RendererUnresponsive(
|
|
|
|
|
content::WebContents* source,
|
2018-10-02 21:57:14 +00:00
|
|
|
|
content::RenderWidgetHost* render_widget_host,
|
|
|
|
|
base::RepeatingClosure hang_monitor_restarter) {
|
2015-06-25 03:07:23 +00:00
|
|
|
|
Emit("unresponsive");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 15:23:16 +00:00
|
|
|
|
void WebContents::RendererResponsive(
|
|
|
|
|
content::WebContents* source,
|
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
2015-06-25 03:07:23 +00:00
|
|
|
|
Emit("responsive");
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 08:45:59 +00:00
|
|
|
|
bool WebContents::HandleContextMenu(content::RenderFrameHost& render_frame_host,
|
2019-02-27 07:49:59 +00:00
|
|
|
|
const content::ContextMenuParams& params) {
|
2021-11-24 08:45:59 +00:00
|
|
|
|
Emit("context-menu", std::make_pair(params, &render_frame_host));
|
2015-11-02 15:28:45 +00:00
|
|
|
|
|
2015-10-31 13:39:07 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-19 19:53:47 +00:00
|
|
|
|
bool WebContents::OnGoToEntryOffset(int offset) {
|
|
|
|
|
GoToOffset(offset);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-17 17:27:56 +00:00
|
|
|
|
void WebContents::FindReply(content::WebContents* web_contents,
|
|
|
|
|
int request_id,
|
|
|
|
|
int number_of_matches,
|
|
|
|
|
const gfx::Rect& selection_rect,
|
|
|
|
|
int active_match_ordinal,
|
|
|
|
|
bool final_update) {
|
2016-09-09 10:50:43 +00:00
|
|
|
|
if (!final_update)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
gin_helper::Dictionary result = gin::Dictionary::CreateEmpty(isolate);
|
2016-09-08 05:27:10 +00:00
|
|
|
|
result.Set("requestId", request_id);
|
|
|
|
|
result.Set("matches", number_of_matches);
|
|
|
|
|
result.Set("selectionArea", selection_rect);
|
|
|
|
|
result.Set("activeMatchOrdinal", active_match_ordinal);
|
2016-09-09 10:50:43 +00:00
|
|
|
|
result.Set("finalUpdate", final_update); // Deprecate after 2.0
|
2019-10-21 07:05:40 +00:00
|
|
|
|
Emit("found-in-page", result.GetHandle());
|
2015-12-17 17:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-09 09:40:50 +00:00
|
|
|
|
void WebContents::RequestExclusivePointerAccess(
|
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
|
bool user_gesture,
|
|
|
|
|
bool last_unlocked_by_target,
|
|
|
|
|
bool allowed) {
|
|
|
|
|
if (allowed) {
|
|
|
|
|
exclusive_access_manager_->mouse_lock_controller()->RequestToLockMouse(
|
|
|
|
|
web_contents, user_gesture, last_unlocked_by_target);
|
|
|
|
|
} else {
|
|
|
|
|
web_contents->GotResponseToLockMouseRequest(
|
|
|
|
|
blink::mojom::PointerLockResult::kPermissionDenied);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::RequestToLockMouse(content::WebContents* web_contents,
|
|
|
|
|
bool user_gesture,
|
|
|
|
|
bool last_unlocked_by_target) {
|
|
|
|
|
auto* permission_helper =
|
|
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
|
|
|
permission_helper->RequestPointerLockPermission(
|
|
|
|
|
user_gesture, last_unlocked_by_target,
|
|
|
|
|
base::BindOnce(&WebContents::RequestExclusivePointerAccess,
|
|
|
|
|
base::Unretained(this)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::LostMouseLock() {
|
|
|
|
|
exclusive_access_manager_->mouse_lock_controller()->LostMouseLock();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-28 14:23:05 +00:00
|
|
|
|
void WebContents::RequestKeyboardLock(content::WebContents* web_contents,
|
|
|
|
|
bool esc_key_locked) {
|
|
|
|
|
exclusive_access_manager_->keyboard_lock_controller()->RequestKeyboardLock(
|
|
|
|
|
web_contents, esc_key_locked);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::CancelKeyboardLockRequest(
|
|
|
|
|
content::WebContents* web_contents) {
|
|
|
|
|
exclusive_access_manager_->keyboard_lock_controller()
|
|
|
|
|
->CancelKeyboardLockRequest(web_contents);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-09 14:30:28 +00:00
|
|
|
|
bool WebContents::CheckMediaAccessPermission(
|
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
|
const GURL& security_origin,
|
2019-07-03 01:22:09 +00:00
|
|
|
|
blink::mojom::MediaStreamType type) {
|
2018-09-09 14:30:28 +00:00
|
|
|
|
auto* web_contents =
|
|
|
|
|
content::WebContents::FromRenderFrameHost(render_frame_host);
|
2018-08-28 14:05:08 +00:00
|
|
|
|
auto* permission_helper =
|
|
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
|
|
|
|
return permission_helper->CheckMediaAccessPermission(security_origin, type);
|
2016-02-26 10:17:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-23 13:29:47 +00:00
|
|
|
|
void WebContents::RequestMediaAccessPermission(
|
|
|
|
|
content::WebContents* web_contents,
|
|
|
|
|
const content::MediaStreamRequest& request,
|
2018-10-02 18:09:25 +00:00
|
|
|
|
content::MediaResponseCallback callback) {
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* permission_helper =
|
2016-01-23 13:29:47 +00:00
|
|
|
|
WebContentsPermissionHelper::FromWebContents(web_contents);
|
2018-10-02 18:09:25 +00:00
|
|
|
|
permission_helper->RequestMediaAccessPermission(request, std::move(callback));
|
2016-01-23 13:29:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
content::JavaScriptDialogManager* WebContents::GetJavaScriptDialogManager(
|
2017-04-28 00:28:48 +00:00
|
|
|
|
content::WebContents* source) {
|
|
|
|
|
if (!dialog_manager_)
|
2020-07-16 23:16:05 +00:00
|
|
|
|
dialog_manager_ = std::make_unique<ElectronJavaScriptDialogManager>();
|
2017-04-28 00:28:48 +00:00
|
|
|
|
|
|
|
|
|
return dialog_manager_.get();
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 00:18:14 +00:00
|
|
|
|
void WebContents::OnAudioStateChanged(bool audible) {
|
2018-09-05 21:00:05 +00:00
|
|
|
|
Emit("-audio-state-changed", audible);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-12 01:00:43 +00:00
|
|
|
|
void WebContents::BeforeUnloadFired(bool proceed,
|
|
|
|
|
const base::TimeTicks& proceed_time) {
|
2015-06-25 03:07:23 +00:00
|
|
|
|
// Do nothing, we override this method just to avoid compilation error since
|
|
|
|
|
// there are two virtual functions named BeforeUnloadFired.
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
void WebContents::HandleNewRenderFrame(
|
2021-03-04 17:27:05 +00:00
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
auto* rwhv = render_frame_host->GetView();
|
|
|
|
|
if (!rwhv)
|
|
|
|
|
return;
|
2021-02-10 20:03:48 +00:00
|
|
|
|
|
2021-07-15 20:18:39 +00:00
|
|
|
|
// Set the background color of RenderWidgetHostView.
|
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
|
|
|
|
if (web_preferences) {
|
2021-11-09 16:36:29 +00:00
|
|
|
|
bool guest = IsGuest() || type_ == Type::kBrowserView;
|
2021-11-06 02:55:19 +00:00
|
|
|
|
absl::optional<SkColor> color =
|
2021-11-09 16:36:29 +00:00
|
|
|
|
guest ? SK_ColorTRANSPARENT : web_preferences->GetBackgroundColor();
|
2021-09-21 00:20:54 +00:00
|
|
|
|
web_contents()->SetPageBaseBackgroundColor(color);
|
2022-01-27 14:56:35 +00:00
|
|
|
|
SetBackgroundColor(rwhv, color.value_or(SK_ColorWHITE));
|
2021-07-15 20:18:39 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-04 17:27:05 +00:00
|
|
|
|
if (!background_throttling_)
|
|
|
|
|
render_frame_host->GetRenderViewHost()->SetSchedulerThrottling(false);
|
2019-12-02 18:29:03 +00:00
|
|
|
|
|
|
|
|
|
auto* rwh_impl =
|
|
|
|
|
static_cast<content::RenderWidgetHostImpl*>(rwhv->GetRenderWidgetHost());
|
|
|
|
|
if (rwh_impl)
|
|
|
|
|
rwh_impl->disable_hidden_ = !background_throttling_;
|
2021-02-09 20:16:21 +00:00
|
|
|
|
|
2021-08-18 18:23:41 +00:00
|
|
|
|
auto* web_frame = WebFrameMain::FromRenderFrameHost(render_frame_host);
|
|
|
|
|
if (web_frame)
|
|
|
|
|
web_frame->Connect();
|
2016-12-28 23:44:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 14:56:35 +00:00
|
|
|
|
void WebContents::OnBackgroundColorChanged() {
|
|
|
|
|
absl::optional<SkColor> color = web_contents()->GetBackgroundColor();
|
|
|
|
|
if (color.has_value()) {
|
|
|
|
|
auto* const view = web_contents()->GetRenderWidgetHostView();
|
|
|
|
|
static_cast<content::RenderWidgetHostViewBase*>(view)
|
|
|
|
|
->SetContentBackgroundColor(color.value());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
void WebContents::RenderFrameCreated(
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
HandleNewRenderFrame(render_frame_host);
|
2021-09-01 22:21:15 +00:00
|
|
|
|
|
|
|
|
|
// RenderFrameCreated is called for speculative frames which may not be
|
|
|
|
|
// used in certain cross-origin navigations. Invoking
|
|
|
|
|
// RenderFrameHost::GetLifecycleState currently crashes when called for
|
|
|
|
|
// speculative frames so we need to filter it out for now. Check
|
|
|
|
|
// https://crbug.com/1183639 for details on when this can be removed.
|
|
|
|
|
auto* rfh_impl =
|
|
|
|
|
static_cast<content::RenderFrameHostImpl*>(render_frame_host);
|
|
|
|
|
if (rfh_impl->lifecycle_state() ==
|
|
|
|
|
content::RenderFrameHostImpl::LifecycleStateImpl::kSpeculative) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content::RenderFrameHost::LifecycleState lifecycle_state =
|
|
|
|
|
render_frame_host->GetLifecycleState();
|
|
|
|
|
if (lifecycle_state == content::RenderFrameHost::LifecycleState::kActive) {
|
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
gin_helper::Dictionary details =
|
|
|
|
|
gin_helper::Dictionary::CreateEmpty(isolate);
|
|
|
|
|
details.SetGetter("frame", render_frame_host);
|
|
|
|
|
Emit("frame-created", details);
|
|
|
|
|
}
|
2021-03-15 22:43:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 18:23:41 +00:00
|
|
|
|
void WebContents::RenderFrameDeleted(
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
// A RenderFrameHost can be deleted when:
|
|
|
|
|
// - A WebContents is removed and its containing frames are disposed.
|
|
|
|
|
// - An <iframe> is removed from the DOM.
|
|
|
|
|
// - Cross-origin navigation creates a new RFH in a separate process which
|
|
|
|
|
// is swapped by content::RenderFrameHostManager.
|
|
|
|
|
//
|
2021-09-23 11:00:11 +00:00
|
|
|
|
|
|
|
|
|
// clear out objects that have been granted permissions
|
|
|
|
|
if (!granted_devices_.empty()) {
|
|
|
|
|
granted_devices_.erase(render_frame_host->GetFrameTreeNodeId());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-18 18:23:41 +00:00
|
|
|
|
// WebFrameMain::FromRenderFrameHost(rfh) will use the RFH's FrameTreeNode ID
|
|
|
|
|
// to find an existing instance of WebFrameMain. During a cross-origin
|
|
|
|
|
// navigation, the deleted RFH will be the old host which was swapped out. In
|
|
|
|
|
// this special case, we need to also ensure that WebFrameMain's internal RFH
|
|
|
|
|
// matches before marking it as disposed.
|
|
|
|
|
auto* web_frame = WebFrameMain::FromRenderFrameHost(render_frame_host);
|
|
|
|
|
if (web_frame && web_frame->render_frame_host() == render_frame_host)
|
|
|
|
|
web_frame->MarkRenderFrameDisposed();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::RenderFrameHostChanged(content::RenderFrameHost* old_host,
|
|
|
|
|
content::RenderFrameHost* new_host) {
|
|
|
|
|
// During cross-origin navigation, a FrameTreeNode will swap out its RFH.
|
|
|
|
|
// If an instance of WebFrameMain exists, it will need to have its RFH
|
|
|
|
|
// swapped as well.
|
|
|
|
|
//
|
2021-09-01 22:21:15 +00:00
|
|
|
|
// |old_host| can be a nullptr so we use |new_host| for looking up the
|
2021-08-18 18:23:41 +00:00
|
|
|
|
// WebFrameMain instance.
|
|
|
|
|
auto* web_frame =
|
|
|
|
|
WebFrameMain::FromFrameTreeNodeId(new_host->GetFrameTreeNodeId());
|
|
|
|
|
if (web_frame) {
|
|
|
|
|
web_frame->UpdateRenderFrameHost(new_host);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::FrameDeleted(int frame_tree_node_id) {
|
|
|
|
|
auto* web_frame = WebFrameMain::FromFrameTreeNodeId(frame_tree_node_id);
|
|
|
|
|
if (web_frame)
|
|
|
|
|
web_frame->Destroyed();
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 04:40:04 +00:00
|
|
|
|
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
2018-12-05 08:03:39 +00:00
|
|
|
|
// This event is necessary for tracking any states with respect to
|
|
|
|
|
// intermediate render view hosts aka speculative render view hosts. Currently
|
|
|
|
|
// used by object-registry.js to ref count remote objects.
|
2018-09-11 18:18:10 +00:00
|
|
|
|
Emit("render-view-deleted", render_view_host->GetProcess()->GetID());
|
2018-12-05 08:03:39 +00:00
|
|
|
|
|
2020-10-07 23:11:19 +00:00
|
|
|
|
if (web_contents()->GetRenderViewHost() == render_view_host) {
|
2018-12-05 08:03:39 +00:00
|
|
|
|
// When the RVH that has been deleted is the current RVH it means that the
|
|
|
|
|
// the web contents are being closed. This is communicated by this event.
|
2020-11-10 17:06:03 +00:00
|
|
|
|
// Currently tracked by guest-window-manager.ts to destroy the
|
2018-12-05 08:03:39 +00:00
|
|
|
|
// BrowserWindow.
|
|
|
|
|
Emit("current-render-view-deleted",
|
|
|
|
|
render_view_host->GetProcess()->GetID());
|
|
|
|
|
}
|
2014-04-25 03:51:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-24 08:45:59 +00:00
|
|
|
|
void WebContents::PrimaryMainFrameRenderProcessGone(
|
|
|
|
|
base::TerminationStatus status) {
|
2021-02-17 12:19:17 +00:00
|
|
|
|
auto weak_this = GetWeakPtr();
|
2016-09-18 00:00:45 +00:00
|
|
|
|
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
|
2021-02-17 12:19:17 +00:00
|
|
|
|
|
|
|
|
|
// User might destroy WebContents in the crashed event.
|
2021-03-02 17:38:56 +00:00
|
|
|
|
if (!weak_this || !web_contents())
|
2021-02-17 12:19:17 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
|
|
|
|
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
|
2020-05-11 20:42:24 +00:00
|
|
|
|
details.Set("reason", status);
|
2021-02-09 01:08:11 +00:00
|
|
|
|
details.Set("exitCode", web_contents()->GetCrashedErrorCode());
|
2020-05-11 20:42:24 +00:00
|
|
|
|
Emit("render-process-gone", details);
|
2014-04-25 03:51:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-12 19:35:56 +00:00
|
|
|
|
void WebContents::PluginCrashed(const base::FilePath& plugin_path,
|
|
|
|
|
base::ProcessId plugin_pid) {
|
2019-10-09 17:59:37 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PLUGINS)
|
2015-05-12 19:35:56 +00:00
|
|
|
|
content::WebPluginInfo info;
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* plugin_service = content::PluginService::GetInstance();
|
2015-05-12 19:35:56 +00:00
|
|
|
|
plugin_service->GetPluginInfoByPath(plugin_path, &info);
|
|
|
|
|
Emit("plugin-crashed", info.name, info.version);
|
2020-10-13 17:25:21 +00:00
|
|
|
|
#endif // BUILDFLAG(ENABLE_PLUGINS)
|
2015-05-12 19:35:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-23 09:59:40 +00:00
|
|
|
|
void WebContents::MediaStartedPlaying(const MediaPlayerInfo& video_type,
|
2019-04-20 17:20:37 +00:00
|
|
|
|
const content::MediaPlayerId& id) {
|
2015-12-20 03:16:22 +00:00
|
|
|
|
Emit("media-started-playing");
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-11 15:27:14 +00:00
|
|
|
|
void WebContents::MediaStoppedPlaying(
|
|
|
|
|
const MediaPlayerInfo& video_type,
|
2019-04-20 17:20:37 +00:00
|
|
|
|
const content::MediaPlayerId& id,
|
2018-04-11 15:27:14 +00:00
|
|
|
|
content::WebContentsObserver::MediaStoppedReason reason) {
|
2015-12-20 03:16:22 +00:00
|
|
|
|
Emit("media-paused");
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-17 18:41:52 +00:00
|
|
|
|
void WebContents::DidChangeThemeColor() {
|
|
|
|
|
auto theme_color = web_contents()->GetThemeColor();
|
2019-04-20 17:20:37 +00:00
|
|
|
|
if (theme_color) {
|
|
|
|
|
Emit("did-change-theme-color", electron::ToRGBHex(theme_color.value()));
|
2017-08-20 14:48:13 +00:00
|
|
|
|
} else {
|
2017-11-13 07:20:54 +00:00
|
|
|
|
Emit("did-change-theme-color", nullptr);
|
2017-08-20 14:48:13 +00:00
|
|
|
|
}
|
2015-12-22 22:16:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-13 21:02:56 +00:00
|
|
|
|
void WebContents::DidAcquireFullscreen(content::RenderFrameHost* rfh) {
|
|
|
|
|
set_fullscreen_frame(rfh);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-01 10:28:57 +00:00
|
|
|
|
void WebContents::OnWebContentsFocused(
|
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
|
|
|
|
Emit("focus");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::OnWebContentsLostFocus(
|
|
|
|
|
content::RenderWidgetHost* render_widget_host) {
|
|
|
|
|
Emit("blur");
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 19:57:34 +00:00
|
|
|
|
void WebContents::DOMContentLoaded(
|
2015-04-29 13:49:31 +00:00
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2021-09-01 22:21:15 +00:00
|
|
|
|
auto* web_frame = WebFrameMain::FromRenderFrameHost(render_frame_host);
|
|
|
|
|
if (web_frame)
|
|
|
|
|
web_frame->DOMContentLoaded();
|
|
|
|
|
|
2016-08-04 04:03:24 +00:00
|
|
|
|
if (!render_frame_host->GetParent())
|
2015-04-29 13:49:31 +00:00
|
|
|
|
Emit("dom-ready");
|
|
|
|
|
}
|
|
|
|
|
|
2014-10-11 11:11:34 +00:00
|
|
|
|
void WebContents::DidFinishLoad(content::RenderFrameHost* render_frame_host,
|
|
|
|
|
const GURL& validated_url) {
|
|
|
|
|
bool is_main_frame = !render_frame_host->GetParent();
|
2018-04-26 10:17:55 +00:00
|
|
|
|
int frame_process_id = render_frame_host->GetProcess()->GetID();
|
|
|
|
|
int frame_routing_id = render_frame_host->GetRoutingID();
|
2019-09-30 22:00:47 +00:00
|
|
|
|
auto weak_this = GetWeakPtr();
|
2018-05-10 20:52:42 +00:00
|
|
|
|
Emit("did-frame-finish-load", is_main_frame, frame_process_id,
|
2018-04-26 10:17:55 +00:00
|
|
|
|
frame_routing_id);
|
2014-06-09 04:03:19 +00:00
|
|
|
|
|
2019-09-30 22:00:47 +00:00
|
|
|
|
// ⚠️WARNING!⚠️
|
|
|
|
|
// Emit() triggers JS which can call destroy() on |this|. It's not safe to
|
|
|
|
|
// assume that |this| points to valid memory at this point.
|
2021-03-02 17:38:56 +00:00
|
|
|
|
if (is_main_frame && weak_this && web_contents())
|
2014-06-09 04:03:19 +00:00
|
|
|
|
Emit("did-finish-load");
|
2014-04-25 04:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-24 15:05:25 +00:00
|
|
|
|
void WebContents::DidFailLoad(content::RenderFrameHost* render_frame_host,
|
2016-04-13 10:33:59 +00:00
|
|
|
|
const GURL& url,
|
2020-01-29 12:01:37 +00:00
|
|
|
|
int error_code) {
|
2016-04-05 02:24:58 +00:00
|
|
|
|
bool is_main_frame = !render_frame_host->GetParent();
|
2018-04-26 10:17:55 +00:00
|
|
|
|
int frame_process_id = render_frame_host->GetProcess()->GetID();
|
|
|
|
|
int frame_routing_id = render_frame_host->GetRoutingID();
|
2020-01-29 12:01:37 +00:00
|
|
|
|
Emit("did-fail-load", error_code, "", url, is_main_frame, frame_process_id,
|
|
|
|
|
frame_routing_id);
|
2014-10-24 15:05:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 07:24:34 +00:00
|
|
|
|
void WebContents::DidStartLoading() {
|
2014-04-25 04:22:16 +00:00
|
|
|
|
Emit("did-start-loading");
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-22 07:24:34 +00:00
|
|
|
|
void WebContents::DidStopLoading() {
|
2020-10-21 22:44:19 +00:00
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
2021-07-26 16:04:09 +00:00
|
|
|
|
if (web_preferences && web_preferences->ShouldUsePreferredSizeMode())
|
2020-10-21 22:44:19 +00:00
|
|
|
|
web_contents()->GetRenderViewHost()->EnablePreferredSizeMode();
|
2020-11-30 05:03:07 +00:00
|
|
|
|
|
|
|
|
|
Emit("did-stop-loading");
|
2014-04-25 04:22:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 15:42:43 +00:00
|
|
|
|
bool WebContents::EmitNavigationEvent(
|
|
|
|
|
const std::string& event,
|
2018-04-26 10:17:55 +00:00
|
|
|
|
content::NavigationHandle* navigation_handle) {
|
|
|
|
|
bool is_main_frame = navigation_handle->IsInMainFrame();
|
|
|
|
|
int frame_tree_node_id = navigation_handle->GetFrameTreeNodeId();
|
|
|
|
|
content::FrameTreeNode* frame_tree_node =
|
2018-05-10 20:52:42 +00:00
|
|
|
|
content::FrameTreeNode::GloballyFindByID(frame_tree_node_id);
|
2018-04-26 10:17:55 +00:00
|
|
|
|
content::RenderFrameHostManager* render_manager =
|
2018-05-10 20:52:42 +00:00
|
|
|
|
frame_tree_node->render_manager();
|
2018-04-26 10:17:55 +00:00
|
|
|
|
content::RenderFrameHost* frame_host = nullptr;
|
|
|
|
|
if (render_manager) {
|
|
|
|
|
frame_host = render_manager->speculative_frame_host();
|
|
|
|
|
if (!frame_host)
|
|
|
|
|
frame_host = render_manager->current_frame_host();
|
|
|
|
|
}
|
|
|
|
|
int frame_process_id = -1, frame_routing_id = -1;
|
|
|
|
|
if (frame_host) {
|
|
|
|
|
frame_process_id = frame_host->GetProcess()->GetID();
|
|
|
|
|
frame_routing_id = frame_host->GetRoutingID();
|
|
|
|
|
}
|
|
|
|
|
bool is_same_document = navigation_handle->IsSameDocument();
|
|
|
|
|
auto url = navigation_handle->GetURL();
|
2018-09-15 15:42:43 +00:00
|
|
|
|
return Emit(event, url, is_same_document, is_main_frame, frame_process_id,
|
|
|
|
|
frame_routing_id);
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-02 22:38:16 +00:00
|
|
|
|
void WebContents::Message(bool internal,
|
|
|
|
|
const std::string& channel,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2019-12-06 21:15:23 +00:00
|
|
|
|
TRACE_EVENT1("electron", "WebContents::Message", "channel", channel);
|
2019-04-02 22:38:16 +00:00
|
|
|
|
// webContents.emit('-ipc-message', new Event(), internal, channel,
|
|
|
|
|
// arguments);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
EmitWithSender("-ipc-message", render_frame_host,
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronApiIPC::InvokeCallback(), internal,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
channel, std::move(arguments));
|
2019-04-02 22:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
|
void WebContents::Invoke(
|
|
|
|
|
bool internal,
|
|
|
|
|
const std::string& channel,
|
|
|
|
|
blink::CloneableMessage arguments,
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronApiIPC::InvokeCallback callback,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2019-12-06 21:15:23 +00:00
|
|
|
|
TRACE_EVENT1("electron", "WebContents::Invoke", "channel", channel);
|
2019-08-23 22:45:50 +00:00
|
|
|
|
// webContents.emit('-ipc-invoke', new Event(), internal, channel, arguments);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
EmitWithSender("-ipc-invoke", render_frame_host, std::move(callback),
|
|
|
|
|
internal, channel, std::move(arguments));
|
2019-05-31 17:25:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
|
void WebContents::OnFirstNonEmptyLayout(
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
if (render_frame_host == web_contents()->GetMainFrame()) {
|
2020-09-28 20:36:45 +00:00
|
|
|
|
Emit("ready-to-show");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
|
void WebContents::ReceivePostMessage(
|
|
|
|
|
const std::string& channel,
|
|
|
|
|
blink::TransferableMessage message,
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2020-03-12 01:07:54 +00:00
|
|
|
|
auto wrapped_ports =
|
2020-07-16 21:11:44 +00:00
|
|
|
|
MessagePort::EntanglePorts(isolate, std::move(message.ports));
|
2020-03-12 01:07:54 +00:00
|
|
|
|
v8::Local<v8::Value> message_value =
|
2020-07-16 21:11:44 +00:00
|
|
|
|
electron::DeserializeV8Value(isolate, message);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
EmitWithSender("-ipc-ports", render_frame_host,
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronApiIPC::InvokeCallback(), false,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
channel, message_value, std::move(wrapped_ports));
|
2020-03-12 01:07:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
|
void WebContents::MessageSync(
|
|
|
|
|
bool internal,
|
|
|
|
|
const std::string& channel,
|
|
|
|
|
blink::CloneableMessage arguments,
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronApiIPC::MessageSyncCallback callback,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2019-12-06 21:15:23 +00:00
|
|
|
|
TRACE_EVENT1("electron", "WebContents::MessageSync", "channel", channel);
|
2019-04-02 22:38:16 +00:00
|
|
|
|
// webContents.emit('-ipc-message-sync', new Event(sender, message), internal,
|
|
|
|
|
// channel, arguments);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
EmitWithSender("-ipc-message-sync", render_frame_host, std::move(callback),
|
|
|
|
|
internal, channel, std::move(arguments));
|
2019-04-02 22:38:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-18 04:26:18 +00:00
|
|
|
|
void WebContents::MessageTo(int32_t web_contents_id,
|
2019-04-03 21:22:23 +00:00
|
|
|
|
const std::string& channel,
|
2019-10-09 17:59:08 +00:00
|
|
|
|
blink::CloneableMessage arguments) {
|
2019-12-06 21:15:23 +00:00
|
|
|
|
TRACE_EVENT1("electron", "WebContents::MessageTo", "channel", channel);
|
2021-02-09 20:16:21 +00:00
|
|
|
|
auto* target_web_contents = FromID(web_contents_id);
|
|
|
|
|
|
|
|
|
|
if (target_web_contents) {
|
|
|
|
|
content::RenderFrameHost* frame = target_web_contents->MainFrame();
|
|
|
|
|
DCHECK(frame);
|
|
|
|
|
|
|
|
|
|
v8::HandleScope handle_scope(JavascriptEnvironment::GetIsolate());
|
|
|
|
|
gin::Handle<WebFrameMain> web_frame_main =
|
|
|
|
|
WebFrameMain::From(JavascriptEnvironment::GetIsolate(), frame);
|
2019-04-03 21:22:23 +00:00
|
|
|
|
|
2021-10-07 05:26:18 +00:00
|
|
|
|
if (!web_frame_main->CheckRenderFrame())
|
|
|
|
|
return;
|
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
|
int32_t sender_id = ID();
|
2021-06-18 04:26:18 +00:00
|
|
|
|
web_frame_main->GetRendererApi()->Message(false /* internal */, channel,
|
2021-02-09 20:16:21 +00:00
|
|
|
|
std::move(arguments), sender_id);
|
2019-04-03 21:22:23 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::MessageHost(const std::string& channel,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
blink::CloneableMessage arguments,
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
2019-12-06 21:15:23 +00:00
|
|
|
|
TRACE_EVENT1("electron", "WebContents::MessageHost", "channel", channel);
|
2019-04-03 21:22:23 +00:00
|
|
|
|
// webContents.emit('ipc-message-host', new Event(), channel, args);
|
2020-12-14 18:57:36 +00:00
|
|
|
|
EmitWithSender("ipc-message-host", render_frame_host,
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronApiIPC::InvokeCallback(), channel,
|
2020-12-14 18:57:36 +00:00
|
|
|
|
std::move(arguments));
|
2019-04-03 21:22:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-03 17:43:04 +00:00
|
|
|
|
void WebContents::UpdateDraggableRegions(
|
|
|
|
|
std::vector<mojom::DraggableRegionPtr> regions) {
|
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnDraggableRegionsUpdated(regions);
|
|
|
|
|
}
|
|
|
|
|
|
2018-09-15 15:42:43 +00:00
|
|
|
|
void WebContents::DidStartNavigation(
|
|
|
|
|
content::NavigationHandle* navigation_handle) {
|
|
|
|
|
EmitNavigationEvent("did-start-navigation", navigation_handle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DidRedirectNavigation(
|
|
|
|
|
content::NavigationHandle* navigation_handle) {
|
|
|
|
|
EmitNavigationEvent("did-redirect-navigation", navigation_handle);
|
2018-04-26 10:17:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 09:27:35 +00:00
|
|
|
|
void WebContents::ReadyToCommitNavigation(
|
|
|
|
|
content::NavigationHandle* navigation_handle) {
|
|
|
|
|
// Don't focus content in an inactive window.
|
|
|
|
|
if (!owner_window())
|
|
|
|
|
return;
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2021-05-19 09:27:35 +00:00
|
|
|
|
if (!owner_window()->IsActive())
|
|
|
|
|
return;
|
|
|
|
|
#else
|
|
|
|
|
if (!owner_window()->widget()->IsActive())
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
|
|
|
|
// Don't focus content after subframe navigations.
|
|
|
|
|
if (!navigation_handle->IsInMainFrame())
|
|
|
|
|
return;
|
|
|
|
|
// Only focus for top-level contents.
|
|
|
|
|
if (type_ != Type::kBrowserWindow)
|
|
|
|
|
return;
|
|
|
|
|
web_contents()->SetInitialFocus();
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-14 00:19:28 +00:00
|
|
|
|
void WebContents::DidFinishNavigation(
|
|
|
|
|
content::NavigationHandle* navigation_handle) {
|
2021-07-01 19:25:40 +00:00
|
|
|
|
if (owner_window_) {
|
|
|
|
|
owner_window_->NotifyLayoutWindowControlsOverlay();
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 10:17:55 +00:00
|
|
|
|
if (!navigation_handle->HasCommitted())
|
|
|
|
|
return;
|
2016-07-14 00:19:28 +00:00
|
|
|
|
bool is_main_frame = navigation_handle->IsInMainFrame();
|
2018-04-26 10:17:55 +00:00
|
|
|
|
content::RenderFrameHost* frame_host =
|
2018-05-10 20:52:42 +00:00
|
|
|
|
navigation_handle->GetRenderFrameHost();
|
2018-04-26 10:17:55 +00:00
|
|
|
|
int frame_process_id = -1, frame_routing_id = -1;
|
|
|
|
|
if (frame_host) {
|
|
|
|
|
frame_process_id = frame_host->GetProcess()->GetID();
|
|
|
|
|
frame_routing_id = frame_host->GetRoutingID();
|
|
|
|
|
}
|
|
|
|
|
if (!navigation_handle->IsErrorPage()) {
|
2019-09-30 22:00:47 +00:00
|
|
|
|
// FIXME: All the Emit() calls below could potentially result in |this|
|
|
|
|
|
// being destroyed (by JS listening for the event and calling
|
|
|
|
|
// webContents.destroy()).
|
2016-07-14 00:19:28 +00:00
|
|
|
|
auto url = navigation_handle->GetURL();
|
2017-08-08 00:49:20 +00:00
|
|
|
|
bool is_same_document = navigation_handle->IsSameDocument();
|
2018-05-01 04:34:41 +00:00
|
|
|
|
if (is_same_document) {
|
2018-05-10 20:52:42 +00:00
|
|
|
|
Emit("did-navigate-in-page", url, is_main_frame, frame_process_id,
|
|
|
|
|
frame_routing_id);
|
2018-05-01 04:34:41 +00:00
|
|
|
|
} else {
|
2018-05-10 20:52:42 +00:00
|
|
|
|
const net::HttpResponseHeaders* http_response =
|
|
|
|
|
navigation_handle->GetResponseHeaders();
|
2018-05-01 04:34:41 +00:00
|
|
|
|
std::string http_status_text;
|
|
|
|
|
int http_response_code = -1;
|
|
|
|
|
if (http_response) {
|
|
|
|
|
http_status_text = http_response->GetStatusText();
|
|
|
|
|
http_response_code = http_response->response_code();
|
|
|
|
|
}
|
2018-05-10 20:52:42 +00:00
|
|
|
|
Emit("did-frame-navigate", url, http_response_code, http_status_text,
|
|
|
|
|
is_main_frame, frame_process_id, frame_routing_id);
|
2018-05-01 04:34:41 +00:00
|
|
|
|
if (is_main_frame) {
|
|
|
|
|
Emit("did-navigate", url, http_response_code, http_status_text);
|
|
|
|
|
}
|
2016-07-14 00:19:28 +00:00
|
|
|
|
}
|
2018-08-16 22:57:40 +00:00
|
|
|
|
if (IsGuest())
|
|
|
|
|
Emit("load-commit", url, is_main_frame);
|
2016-07-14 00:19:28 +00:00
|
|
|
|
} else {
|
|
|
|
|
auto url = navigation_handle->GetURL();
|
|
|
|
|
int code = navigation_handle->GetNetErrorCode();
|
|
|
|
|
auto description = net::ErrorToShortString(code);
|
2018-05-10 20:52:42 +00:00
|
|
|
|
Emit("did-fail-provisional-load", code, description, url, is_main_frame,
|
|
|
|
|
frame_process_id, frame_routing_id);
|
2016-07-14 00:19:28 +00:00
|
|
|
|
|
|
|
|
|
// Do not emit "did-fail-load" for canceled requests.
|
2021-01-13 09:01:51 +00:00
|
|
|
|
if (code != net::ERR_ABORTED) {
|
|
|
|
|
EmitWarning(
|
|
|
|
|
node::Environment::GetCurrent(JavascriptEnvironment::GetIsolate()),
|
|
|
|
|
"Failed to load URL: " + url.possibly_invalid_spec() +
|
|
|
|
|
" with error: " + description,
|
|
|
|
|
"electron");
|
2018-05-10 20:52:42 +00:00
|
|
|
|
Emit("did-fail-load", code, description, url, is_main_frame,
|
|
|
|
|
frame_process_id, frame_routing_id);
|
2021-01-13 09:01:51 +00:00
|
|
|
|
}
|
2016-07-14 00:19:28 +00:00
|
|
|
|
}
|
2021-02-17 18:23:45 +00:00
|
|
|
|
content::NavigationEntry* entry = navigation_handle->GetNavigationEntry();
|
|
|
|
|
|
|
|
|
|
// This check is needed due to an issue in Chromium
|
|
|
|
|
// Check the Chromium issue to keep updated:
|
|
|
|
|
// https://bugs.chromium.org/p/chromium/issues/detail?id=1178663
|
|
|
|
|
// If a history entry has been made and the forward/back call has been made,
|
|
|
|
|
// proceed with setting the new title
|
|
|
|
|
if (entry && (entry->GetTransitionType() & ui::PAGE_TRANSITION_FORWARD_BACK))
|
|
|
|
|
WebContents::TitleWasSet(entry);
|
2014-12-09 22:38:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-18 00:19:21 +00:00
|
|
|
|
void WebContents::TitleWasSet(content::NavigationEntry* entry) {
|
2021-03-16 16:18:45 +00:00
|
|
|
|
std::u16string final_title;
|
2017-12-24 12:42:23 +00:00
|
|
|
|
bool explicit_set = true;
|
|
|
|
|
if (entry) {
|
|
|
|
|
auto title = entry->GetTitle();
|
|
|
|
|
auto url = entry->GetURL();
|
|
|
|
|
if (url.SchemeIsFile() && title.empty()) {
|
|
|
|
|
final_title = base::UTF8ToUTF16(url.ExtractFileName());
|
|
|
|
|
explicit_set = false;
|
|
|
|
|
} else {
|
|
|
|
|
final_title = title;
|
|
|
|
|
}
|
2021-06-30 17:53:10 +00:00
|
|
|
|
} else {
|
|
|
|
|
final_title = web_contents()->GetTitle();
|
2017-12-18 00:19:21 +00:00
|
|
|
|
}
|
2020-02-11 00:37:46 +00:00
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnPageTitleUpdated(final_title, explicit_set);
|
2017-12-18 07:54:44 +00:00
|
|
|
|
Emit("page-title-updated", final_title, explicit_set);
|
2015-04-05 09:20:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-04-17 19:55:31 +00:00
|
|
|
|
void WebContents::DidUpdateFaviconURL(
|
2020-06-22 17:35:10 +00:00
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
2020-03-03 21:35:05 +00:00
|
|
|
|
const std::vector<blink::mojom::FaviconURLPtr>& urls) {
|
2015-04-17 19:55:31 +00:00
|
|
|
|
std::set<GURL> unique_urls;
|
2016-07-10 11:32:40 +00:00
|
|
|
|
for (const auto& iter : urls) {
|
2020-03-03 21:35:05 +00:00
|
|
|
|
if (iter->icon_type != blink::mojom::FaviconIconType::kFavicon)
|
2015-04-17 19:55:31 +00:00
|
|
|
|
continue;
|
2020-03-03 21:35:05 +00:00
|
|
|
|
const GURL& url = iter->icon_url;
|
2015-04-17 19:55:31 +00:00
|
|
|
|
if (url.is_valid())
|
|
|
|
|
unique_urls.insert(url);
|
|
|
|
|
}
|
2015-04-20 06:50:04 +00:00
|
|
|
|
Emit("page-favicon-updated", unique_urls);
|
2015-04-17 19:55:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-12 07:36:12 +00:00
|
|
|
|
void WebContents::DevToolsReloadPage() {
|
|
|
|
|
Emit("devtools-reload-page");
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
|
void WebContents::DevToolsFocused() {
|
|
|
|
|
Emit("devtools-focused");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsOpened() {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
2021-03-22 01:56:30 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_->GetDevToolsWebContents());
|
2020-11-17 22:15:20 +00:00
|
|
|
|
auto handle = FromOrCreate(
|
|
|
|
|
isolate, inspectable_web_contents_->GetDevToolsWebContents());
|
2020-07-16 21:11:44 +00:00
|
|
|
|
devtools_web_contents_.Reset(isolate, handle.ToV8());
|
2015-10-01 03:14:19 +00:00
|
|
|
|
|
2016-05-26 10:29:39 +00:00
|
|
|
|
// Set inspected tabID.
|
2017-04-05 08:34:53 +00:00
|
|
|
|
base::Value tab_id(ID());
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction("DevToolsAPI.setInspectedTabId",
|
|
|
|
|
&tab_id, nullptr, nullptr);
|
2016-05-26 10:29:39 +00:00
|
|
|
|
|
2017-12-01 02:11:37 +00:00
|
|
|
|
// Inherit owner window in devtools when it doesn't have one.
|
2020-11-17 22:15:20 +00:00
|
|
|
|
auto* devtools = inspectable_web_contents_->GetDevToolsWebContents();
|
2019-01-21 16:56:54 +00:00
|
|
|
|
bool has_window = devtools->GetUserData(NativeWindowRelay::UserDataKey());
|
2017-12-01 02:11:37 +00:00
|
|
|
|
if (owner_window() && !has_window)
|
2017-11-30 07:37:26 +00:00
|
|
|
|
handle->SetOwnerWindow(devtools, owner_window());
|
2015-10-01 06:41:01 +00:00
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
|
Emit("devtools-opened");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsClosed() {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::Locker locker(isolate);
|
|
|
|
|
v8::HandleScope handle_scope(isolate);
|
2015-10-01 03:14:19 +00:00
|
|
|
|
devtools_web_contents_.Reset();
|
|
|
|
|
|
|
|
|
|
Emit("devtools-closed");
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 21:54:04 +00:00
|
|
|
|
void WebContents::DevToolsResized() {
|
|
|
|
|
for (ExtendedWebContentsObserver& observer : observers_)
|
|
|
|
|
observer.OnDevToolsResized();
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
void WebContents::SetOwnerWindow(NativeWindow* owner_window) {
|
|
|
|
|
SetOwnerWindow(GetWebContents(), owner_window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SetOwnerWindow(content::WebContents* web_contents,
|
|
|
|
|
NativeWindow* owner_window) {
|
|
|
|
|
if (owner_window) {
|
|
|
|
|
owner_window_ = owner_window->GetWeakPtr();
|
|
|
|
|
NativeWindowRelay::CreateForWebContents(web_contents,
|
|
|
|
|
owner_window->GetWeakPtr());
|
|
|
|
|
} else {
|
|
|
|
|
owner_window_ = nullptr;
|
|
|
|
|
web_contents->RemoveUserData(NativeWindowRelay::UserDataKey());
|
|
|
|
|
}
|
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
|
|
|
|
if (osr_wcv)
|
|
|
|
|
osr_wcv->SetNativeWindow(owner_window);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content::WebContents* WebContents::GetWebContents() const {
|
2020-11-17 22:15:20 +00:00
|
|
|
|
if (!inspectable_web_contents_)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return nullptr;
|
2020-11-17 22:15:20 +00:00
|
|
|
|
return inspectable_web_contents_->GetWebContents();
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content::WebContents* WebContents::GetDevToolsWebContents() const {
|
2020-11-17 22:15:20 +00:00
|
|
|
|
if (!inspectable_web_contents_)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return nullptr;
|
2020-11-17 22:15:20 +00:00
|
|
|
|
return inspectable_web_contents_->GetDevToolsWebContents();
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
void WebContents::WebContentsDestroyed() {
|
|
|
|
|
// Clear the pointer stored in wrapper.
|
2020-07-30 16:17:57 +00:00
|
|
|
|
if (GetAllWebContents().Lookup(id_))
|
|
|
|
|
GetAllWebContents().Remove(id_);
|
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
v8::HandleScope scope(isolate);
|
|
|
|
|
v8::Local<v8::Object> wrapper;
|
|
|
|
|
if (!GetWrapper(isolate).ToLocal(&wrapper))
|
|
|
|
|
return;
|
|
|
|
|
wrapper->SetAlignedPointerInInternalField(0, nullptr);
|
2016-01-12 13:10:24 +00:00
|
|
|
|
|
2021-10-11 00:33:35 +00:00
|
|
|
|
// Tell WebViewGuestDelegate that the WebContents has been destroyed.
|
|
|
|
|
if (guest_delegate_)
|
|
|
|
|
guest_delegate_->WillDestroy();
|
|
|
|
|
|
2021-03-15 22:43:25 +00:00
|
|
|
|
Observe(nullptr);
|
2016-01-12 13:10:24 +00:00
|
|
|
|
Emit("destroyed");
|
2014-04-25 03:22:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-05 14:39:27 +00:00
|
|
|
|
void WebContents::NavigationEntryCommitted(
|
2015-05-11 05:51:52 +00:00
|
|
|
|
const content::LoadCommittedDetails& details) {
|
2020-01-29 09:42:25 +00:00
|
|
|
|
Emit("navigation-entry-committed", details.entry->GetURL(),
|
2017-08-08 00:49:20 +00:00
|
|
|
|
details.is_same_document, details.did_replace_entry);
|
2015-03-05 14:39:27 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-14 13:11:45 +00:00
|
|
|
|
bool WebContents::GetBackgroundThrottling() const {
|
|
|
|
|
return background_throttling_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 00:32:22 +00:00
|
|
|
|
void WebContents::SetBackgroundThrottling(bool allowed) {
|
|
|
|
|
background_throttling_ = allowed;
|
|
|
|
|
|
2019-12-02 18:29:03 +00:00
|
|
|
|
auto* rfh = web_contents()->GetMainFrame();
|
|
|
|
|
if (!rfh)
|
2018-10-19 00:32:22 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-12-02 18:29:03 +00:00
|
|
|
|
auto* rwhv = rfh->GetView();
|
|
|
|
|
if (!rwhv)
|
2018-10-19 00:32:22 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-12-02 18:29:03 +00:00
|
|
|
|
auto* rwh_impl =
|
|
|
|
|
static_cast<content::RenderWidgetHostImpl*>(rwhv->GetRenderWidgetHost());
|
|
|
|
|
if (!rwh_impl)
|
2018-10-19 00:32:22 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2019-12-02 18:29:03 +00:00
|
|
|
|
rwh_impl->disable_hidden_ = !background_throttling_;
|
|
|
|
|
web_contents()->GetRenderViewHost()->SetSchedulerThrottling(allowed);
|
2018-10-19 00:32:22 +00:00
|
|
|
|
|
2019-12-02 18:29:03 +00:00
|
|
|
|
if (rwh_impl->is_hidden()) {
|
2020-09-21 08:00:36 +00:00
|
|
|
|
rwh_impl->WasShown({});
|
2018-10-19 00:32:22 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-06 01:28:40 +00:00
|
|
|
|
int WebContents::GetProcessID() const {
|
2017-12-18 02:46:23 +00:00
|
|
|
|
return web_contents()->GetMainFrame()->GetProcess()->GetID();
|
2015-06-23 08:16:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-15 20:29:34 +00:00
|
|
|
|
base::ProcessId WebContents::GetOSProcessID() const {
|
2018-06-25 20:30:00 +00:00
|
|
|
|
base::ProcessHandle process_handle =
|
2018-09-15 00:13:02 +00:00
|
|
|
|
web_contents()->GetMainFrame()->GetProcess()->GetProcess().Handle();
|
2017-04-18 10:31:20 +00:00
|
|
|
|
return base::GetProcId(process_handle);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-14 16:09:54 +00:00
|
|
|
|
WebContents::Type WebContents::GetType() const {
|
|
|
|
|
return type_;
|
2016-06-08 18:41:14 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-23 08:16:10 +00:00
|
|
|
|
bool WebContents::Equal(const WebContents* web_contents) const {
|
2018-07-23 09:08:36 +00:00
|
|
|
|
return ID() == web_contents->ID();
|
2015-06-23 08:16:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 23:11:18 +00:00
|
|
|
|
GURL WebContents::GetURL() const {
|
|
|
|
|
return web_contents()->GetLastCommittedURL();
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
|
void WebContents::LoadURL(const GURL& url,
|
|
|
|
|
const gin_helper::Dictionary& options) {
|
2017-01-21 09:29:20 +00:00
|
|
|
|
if (!url.is_valid() || url.spec().size() > url::kMaxURLChars) {
|
2018-04-18 01:55:30 +00:00
|
|
|
|
Emit("did-fail-load", static_cast<int>(net::ERR_INVALID_URL),
|
2016-02-11 02:54:50 +00:00
|
|
|
|
net::ErrorToShortString(net::ERR_INVALID_URL),
|
2018-04-18 01:55:30 +00:00
|
|
|
|
url.possibly_invalid_spec(), true);
|
2016-02-11 02:54:50 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-25 04:52:30 +00:00
|
|
|
|
content::NavigationController::LoadURLParams params(url);
|
2014-11-06 19:29:41 +00:00
|
|
|
|
|
2018-04-05 23:13:24 +00:00
|
|
|
|
if (!options.Get("httpReferrer", ¶ms.referrer)) {
|
|
|
|
|
GURL http_referrer;
|
|
|
|
|
if (options.Get("httpReferrer", &http_referrer))
|
2019-01-09 20:13:49 +00:00
|
|
|
|
params.referrer =
|
|
|
|
|
content::Referrer(http_referrer.GetAsReferrer(),
|
|
|
|
|
network::mojom::ReferrerPolicy::kDefault);
|
2018-04-05 23:13:24 +00:00
|
|
|
|
}
|
2014-11-06 19:29:41 +00:00
|
|
|
|
|
2015-05-06 04:01:41 +00:00
|
|
|
|
std::string user_agent;
|
2015-06-09 01:27:57 +00:00
|
|
|
|
if (options.Get("userAgent", &user_agent))
|
2020-04-13 23:39:26 +00:00
|
|
|
|
web_contents()->SetUserAgentOverride(
|
|
|
|
|
blink::UserAgentOverride::UserAgentOnly(user_agent), false);
|
2015-05-06 04:01:41 +00:00
|
|
|
|
|
2015-10-26 21:18:16 +00:00
|
|
|
|
std::string extra_headers;
|
|
|
|
|
if (options.Get("extraHeaders", &extra_headers))
|
|
|
|
|
params.extra_headers = extra_headers;
|
|
|
|
|
|
2018-04-11 08:42:14 +00:00
|
|
|
|
scoped_refptr<network::ResourceRequestBody> body;
|
2016-10-09 23:30:38 +00:00
|
|
|
|
if (options.Get("postData", &body)) {
|
|
|
|
|
params.post_data = body;
|
|
|
|
|
params.load_type = content::NavigationController::LOAD_TYPE_HTTP_POST;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-01 00:49:03 +00:00
|
|
|
|
GURL base_url_for_data_url;
|
|
|
|
|
if (options.Get("baseURLForDataURL", &base_url_for_data_url)) {
|
|
|
|
|
params.base_url_for_data_url = base_url_for_data_url;
|
|
|
|
|
params.load_type = content::NavigationController::LOAD_TYPE_DATA;
|
|
|
|
|
}
|
2017-03-02 18:50:48 +00:00
|
|
|
|
|
2019-11-25 19:12:58 +00:00
|
|
|
|
bool reload_ignoring_cache = false;
|
|
|
|
|
if (options.Get("reloadIgnoringCache", &reload_ignoring_cache) &&
|
|
|
|
|
reload_ignoring_cache) {
|
|
|
|
|
params.reload_type = content::ReloadType::BYPASSING_CACHE;
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-30 22:00:47 +00:00
|
|
|
|
// Calling LoadURLWithParams() can trigger JS which destroys |this|.
|
|
|
|
|
auto weak_this = GetWeakPtr();
|
|
|
|
|
|
2021-06-02 00:17:15 +00:00
|
|
|
|
params.transition_type = ui::PageTransitionFromInt(
|
|
|
|
|
ui::PAGE_TRANSITION_TYPED | ui::PAGE_TRANSITION_FROM_ADDRESS_BAR);
|
2014-04-25 04:52:30 +00:00
|
|
|
|
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
2019-03-28 18:13:05 +00:00
|
|
|
|
// Discord non-committed entries to ensure that we don't re-use a pending
|
|
|
|
|
// entry
|
|
|
|
|
web_contents()->GetController().DiscardNonCommittedEntries();
|
2017-02-19 20:43:17 +00:00
|
|
|
|
web_contents()->GetController().LoadURLWithParams(params);
|
2017-04-07 17:34:14 +00:00
|
|
|
|
|
2019-09-30 22:00:47 +00:00
|
|
|
|
// ⚠️WARNING!⚠️
|
|
|
|
|
// LoadURLWithParams() triggers JS events which can call destroy() on |this|.
|
|
|
|
|
// It's not safe to assume that |this| points to valid memory at this point.
|
2021-03-02 17:38:56 +00:00
|
|
|
|
if (!weak_this || !web_contents())
|
2019-09-30 22:00:47 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
|
// Required to make beforeunload handler work.
|
|
|
|
|
NotifyUserActivation();
|
2014-04-25 04:52:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 23:11:18 +00:00
|
|
|
|
// TODO(MarshallOfSound): Figure out what we need to do with post data here, I
|
|
|
|
|
// believe the default behavior when we pass "true" is to phone out to the
|
|
|
|
|
// delegate and then the controller expects this method to be called again with
|
|
|
|
|
// "false" if the user approves the reload. For now this would result in
|
|
|
|
|
// ".reload()" calls on POST data domains failing silently. Passing false would
|
|
|
|
|
// result in them succeeding, but reposting which although more correct could be
|
|
|
|
|
// considering a breaking change.
|
|
|
|
|
void WebContents::Reload() {
|
|
|
|
|
web_contents()->GetController().Reload(content::ReloadType::NORMAL,
|
|
|
|
|
/* check_for_repost */ true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::ReloadIgnoringCache() {
|
|
|
|
|
web_contents()->GetController().Reload(content::ReloadType::BYPASSING_CACHE,
|
|
|
|
|
/* check_for_repost */ true);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-02 21:49:30 +00:00
|
|
|
|
void WebContents::DownloadURL(const GURL& url) {
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* browser_context = web_contents()->GetBrowserContext();
|
2021-05-19 23:15:47 +00:00
|
|
|
|
auto* download_manager = browser_context->GetDownloadManager();
|
2018-04-12 07:30:51 +00:00
|
|
|
|
std::unique_ptr<download::DownloadUrlParameters> download_params(
|
|
|
|
|
content::DownloadRequestUtils::CreateDownloadForWebContentsMainFrame(
|
2019-07-03 21:48:55 +00:00
|
|
|
|
web_contents(), url, MISSING_TRAFFIC_ANNOTATION));
|
2018-04-12 07:30:51 +00:00
|
|
|
|
download_manager->DownloadUrl(std::move(download_params));
|
2015-12-02 21:49:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
|
std::u16string WebContents::GetTitle() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
|
return web_contents()->GetTitle();
|
2014-04-24 09:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsLoading() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
|
return web_contents()->IsLoading();
|
2014-04-24 09:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-04-18 17:37:08 +00:00
|
|
|
|
bool WebContents::IsLoadingMainFrame() const {
|
2021-11-24 08:45:59 +00:00
|
|
|
|
return web_contents()->ShouldShowLoadingUI();
|
2016-04-18 17:37:08 +00:00
|
|
|
|
}
|
2014-04-24 09:00:41 +00:00
|
|
|
|
|
|
|
|
|
bool WebContents::IsWaitingForResponse() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
|
return web_contents()->IsWaitingForResponse();
|
2014-04-24 09:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Stop() {
|
2014-04-25 05:10:16 +00:00
|
|
|
|
web_contents()->Stop();
|
2014-04-24 09:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-04-27 23:11:18 +00:00
|
|
|
|
bool WebContents::CanGoBack() const {
|
|
|
|
|
return web_contents()->GetController().CanGoBack();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 06:30:26 +00:00
|
|
|
|
void WebContents::GoBack() {
|
2021-04-27 23:11:18 +00:00
|
|
|
|
if (CanGoBack())
|
|
|
|
|
web_contents()->GetController().GoBack();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::CanGoForward() const {
|
|
|
|
|
return web_contents()->GetController().CanGoForward();
|
2015-05-11 06:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::GoForward() {
|
2021-04-27 23:11:18 +00:00
|
|
|
|
if (CanGoForward())
|
|
|
|
|
web_contents()->GetController().GoForward();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::CanGoToOffset(int offset) const {
|
|
|
|
|
return web_contents()->GetController().CanGoToOffset(offset);
|
2015-05-11 06:30:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-05-11 08:44:01 +00:00
|
|
|
|
void WebContents::GoToOffset(int offset) {
|
2021-04-27 23:11:18 +00:00
|
|
|
|
if (CanGoToOffset(offset))
|
|
|
|
|
web_contents()->GetController().GoToOffset(offset);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::CanGoToIndex(int index) const {
|
|
|
|
|
return index >= 0 && index < GetHistoryLength();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::GoToIndex(int index) {
|
|
|
|
|
if (CanGoToIndex(index))
|
|
|
|
|
web_contents()->GetController().GoToIndex(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WebContents::GetActiveIndex() const {
|
|
|
|
|
return web_contents()->GetController().GetCurrentEntryIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::ClearHistory() {
|
|
|
|
|
// In some rare cases (normally while there is no real history) we are in a
|
|
|
|
|
// state where we can't prune navigation entries
|
|
|
|
|
if (web_contents()->GetController().CanPruneAllButLastCommitted()) {
|
|
|
|
|
web_contents()->GetController().PruneAllButLastCommitted();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WebContents::GetHistoryLength() const {
|
|
|
|
|
return web_contents()->GetController().GetEntryCount();
|
2015-05-11 08:44:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-09 03:06:26 +00:00
|
|
|
|
const std::string WebContents::GetWebRTCIPHandlingPolicy() const {
|
2018-04-18 01:55:30 +00:00
|
|
|
|
return web_contents()->GetMutableRendererPrefs()->webrtc_ip_handling_policy;
|
2017-03-08 14:55:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SetWebRTCIPHandlingPolicy(
|
2017-03-09 03:06:26 +00:00
|
|
|
|
const std::string& webrtc_ip_handling_policy) {
|
2017-03-08 14:55:59 +00:00
|
|
|
|
if (GetWebRTCIPHandlingPolicy() == webrtc_ip_handling_policy)
|
|
|
|
|
return;
|
|
|
|
|
web_contents()->GetMutableRendererPrefs()->webrtc_ip_handling_policy =
|
2018-04-18 01:55:30 +00:00
|
|
|
|
webrtc_ip_handling_policy;
|
2017-03-08 14:55:59 +00:00
|
|
|
|
|
2019-10-28 22:12:35 +00:00
|
|
|
|
web_contents()->SyncRendererPrefs();
|
2017-03-08 14:55:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-26 00:03:59 +00:00
|
|
|
|
std::string WebContents::GetMediaSourceID(
|
|
|
|
|
content::WebContents* request_web_contents) {
|
|
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
|
|
|
|
if (!frame_host)
|
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
|
|
content::DesktopMediaID media_id(
|
|
|
|
|
content::DesktopMediaID::TYPE_WEB_CONTENTS,
|
|
|
|
|
content::DesktopMediaID::kNullId,
|
|
|
|
|
content::WebContentsMediaCaptureId(frame_host->GetProcess()->GetID(),
|
|
|
|
|
frame_host->GetRoutingID()));
|
|
|
|
|
|
|
|
|
|
auto* request_frame_host = request_web_contents->GetMainFrame();
|
|
|
|
|
if (!request_frame_host)
|
|
|
|
|
return std::string();
|
|
|
|
|
|
|
|
|
|
std::string id =
|
|
|
|
|
content::DesktopStreamsRegistry::GetInstance()->RegisterStream(
|
|
|
|
|
request_frame_host->GetProcess()->GetID(),
|
|
|
|
|
request_frame_host->GetRoutingID(),
|
2021-11-24 08:45:59 +00:00
|
|
|
|
url::Origin::Create(request_frame_host->GetLastCommittedURL()
|
|
|
|
|
.DeprecatedGetOriginAsURL()),
|
2021-10-26 00:03:59 +00:00
|
|
|
|
media_id, "", content::kRegistryStreamTypeTab);
|
|
|
|
|
|
|
|
|
|
return id;
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 09:00:41 +00:00
|
|
|
|
bool WebContents::IsCrashed() const {
|
2014-04-25 05:10:16 +00:00
|
|
|
|
return web_contents()->IsCrashed();
|
2014-04-24 09:00:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-02 21:50:24 +00:00
|
|
|
|
void WebContents::ForcefullyCrashRenderer() {
|
|
|
|
|
content::RenderWidgetHostView* view =
|
|
|
|
|
web_contents()->GetRenderWidgetHostView();
|
|
|
|
|
if (!view)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
content::RenderWidgetHost* rwh = view->GetRenderWidgetHost();
|
|
|
|
|
if (!rwh)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
content::RenderProcessHost* rph = rwh->GetProcess();
|
|
|
|
|
if (rph) {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
|
2020-10-02 21:50:24 +00:00
|
|
|
|
// A generic |CrashDumpHungChildProcess()| is not implemented for Linux.
|
|
|
|
|
// Instead we send an explicit IPC to crash on the renderer's IO thread.
|
|
|
|
|
rph->ForceCrash();
|
|
|
|
|
#else
|
|
|
|
|
// Try to generate a crash report for the hung process.
|
2020-11-16 17:47:09 +00:00
|
|
|
|
#ifndef MAS_BUILD
|
2020-10-02 21:50:24 +00:00
|
|
|
|
CrashDumpHungChildProcess(rph->GetProcess().Handle());
|
2020-11-16 17:47:09 +00:00
|
|
|
|
#endif
|
2020-10-02 21:50:24 +00:00
|
|
|
|
rph->Shutdown(content::RESULT_CODE_HUNG);
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::SetUserAgent(const std::string& user_agent) {
|
2020-04-13 23:39:26 +00:00
|
|
|
|
web_contents()->SetUserAgentOverride(
|
|
|
|
|
blink::UserAgentOverride::UserAgentOnly(user_agent), false);
|
2014-10-24 12:57:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-22 04:25:10 +00:00
|
|
|
|
std::string WebContents::GetUserAgent() {
|
2020-04-13 23:39:26 +00:00
|
|
|
|
return web_contents()->GetUserAgentOverride().ua_string_override;
|
2015-07-22 04:25:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-14 17:03:28 +00:00
|
|
|
|
v8::Local<v8::Promise> WebContents::SavePage(
|
|
|
|
|
const base::FilePath& full_file_path,
|
|
|
|
|
const content::SavePageType& save_type) {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-03-13 21:30:21 +00:00
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2019-02-14 17:03:28 +00:00
|
|
|
|
|
2022-02-07 08:51:59 +00:00
|
|
|
|
if (!full_file_path.IsAbsolute()) {
|
|
|
|
|
promise.RejectWithErrorMessage("Path must be absolute");
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 12:32:44 +00:00
|
|
|
|
auto* handler = new SavePageHandler(web_contents(), std::move(promise));
|
|
|
|
|
handler->Handle(full_file_path, save_type);
|
2019-03-13 21:30:21 +00:00
|
|
|
|
|
|
|
|
|
return handle;
|
2015-10-14 04:41:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::OpenDevTools(gin::Arguments* args) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-06-05 07:41:03 +00:00
|
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
|
2016-09-07 02:16:52 +00:00
|
|
|
|
if (!enable_devtools_)
|
2016-09-05 08:27:56 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2016-04-19 12:42:05 +00:00
|
|
|
|
std::string state;
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kWebView || type_ == Type::kBackgroundPage ||
|
2020-09-08 11:55:40 +00:00
|
|
|
|
!owner_window()) {
|
2016-04-19 12:42:05 +00:00
|
|
|
|
state = "detach";
|
2017-12-01 02:11:37 +00:00
|
|
|
|
}
|
2018-11-27 09:34:44 +00:00
|
|
|
|
bool activate = true;
|
2017-12-01 02:11:37 +00:00
|
|
|
|
if (args && args->Length() == 1) {
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary options;
|
2016-04-19 12:42:05 +00:00
|
|
|
|
if (args->GetNext(&options)) {
|
|
|
|
|
options.Get("mode", &state);
|
2018-11-27 09:34:44 +00:00
|
|
|
|
options.Get("activate", &activate);
|
2016-04-19 12:42:05 +00:00
|
|
|
|
}
|
2015-06-05 09:01:17 +00:00
|
|
|
|
}
|
2020-09-08 11:55:40 +00:00
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
|
|
|
|
inspectable_web_contents_->SetDockState(state);
|
|
|
|
|
inspectable_web_contents_->ShowDevTools(activate);
|
2014-11-02 14:34:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-11-03 14:12:56 +00:00
|
|
|
|
void WebContents::CloseDevTools() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-06-05 07:41:03 +00:00
|
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
|
|
|
|
inspectable_web_contents_->CloseDevTools();
|
2014-11-03 14:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsDevToolsOpened() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-06-05 07:41:03 +00:00
|
|
|
|
return false;
|
2015-06-25 06:32:38 +00:00
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
|
|
|
|
return inspectable_web_contents_->IsDevToolsViewShowing();
|
2014-11-03 14:12:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-01-01 05:11:21 +00:00
|
|
|
|
bool WebContents::IsDevToolsFocused() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2016-01-01 05:11:21 +00:00
|
|
|
|
return false;
|
2016-01-01 09:45:03 +00:00
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
|
|
|
|
return inspectable_web_contents_->GetView()->IsDevToolsViewFocused();
|
2016-01-01 05:11:21 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-09-18 03:06:38 +00:00
|
|
|
|
void WebContents::EnableDeviceEmulation(
|
2020-08-12 18:33:58 +00:00
|
|
|
|
const blink::DeviceEmulationParams& params) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-08-31 09:19:19 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-09-08 11:55:40 +00:00
|
|
|
|
DCHECK(web_contents());
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
2017-12-30 16:25:09 +00:00
|
|
|
|
if (frame_host) {
|
2021-05-24 02:32:55 +00:00
|
|
|
|
auto* widget_host_impl = static_cast<content::RenderWidgetHostImpl*>(
|
|
|
|
|
frame_host->GetView()->GetRenderWidgetHost());
|
2020-08-12 18:33:58 +00:00
|
|
|
|
if (widget_host_impl) {
|
|
|
|
|
auto& frame_widget = widget_host_impl->GetAssociatedFrameWidget();
|
|
|
|
|
frame_widget->EnableDeviceEmulation(params);
|
|
|
|
|
}
|
2017-12-30 16:25:09 +00:00
|
|
|
|
}
|
2015-08-31 09:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DisableDeviceEmulation() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-08-31 09:19:19 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-09-08 11:55:40 +00:00
|
|
|
|
DCHECK(web_contents());
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
2017-12-30 16:25:09 +00:00
|
|
|
|
if (frame_host) {
|
2021-05-24 02:32:55 +00:00
|
|
|
|
auto* widget_host_impl = static_cast<content::RenderWidgetHostImpl*>(
|
|
|
|
|
frame_host->GetView()->GetRenderWidgetHost());
|
2020-08-12 18:33:58 +00:00
|
|
|
|
if (widget_host_impl) {
|
|
|
|
|
auto& frame_widget = widget_host_impl->GetAssociatedFrameWidget();
|
|
|
|
|
frame_widget->DisableDeviceEmulation();
|
|
|
|
|
}
|
2017-12-30 16:25:09 +00:00
|
|
|
|
}
|
2015-08-31 09:19:19 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-05 09:01:17 +00:00
|
|
|
|
void WebContents::ToggleDevTools() {
|
|
|
|
|
if (IsDevToolsOpened())
|
|
|
|
|
CloseDevTools();
|
|
|
|
|
else
|
|
|
|
|
OpenDevTools(nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-22 07:30:10 +00:00
|
|
|
|
void WebContents::InspectElement(int x, int y) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-06-05 07:41:03 +00:00
|
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
|
2016-09-07 02:16:52 +00:00
|
|
|
|
if (!enable_devtools_)
|
2016-09-06 09:53:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2020-11-17 22:15:20 +00:00
|
|
|
|
DCHECK(inspectable_web_contents_);
|
|
|
|
|
if (!inspectable_web_contents_->GetDevToolsWebContents())
|
2016-08-23 22:26:13 +00:00
|
|
|
|
OpenDevTools(nullptr);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->InspectElement(x, y);
|
2015-04-22 07:30:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-02 12:38:27 +00:00
|
|
|
|
void WebContents::InspectSharedWorkerById(const std::string& workerId) {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2019-10-02 12:38:27 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!enable_devtools_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
|
|
|
if (agent_host->GetType() ==
|
|
|
|
|
content::DevToolsAgentHost::kTypeSharedWorker) {
|
|
|
|
|
if (agent_host->GetId() == workerId) {
|
|
|
|
|
OpenDevTools(nullptr);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->AttachTo(agent_host);
|
2019-10-02 12:38:27 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<scoped_refptr<content::DevToolsAgentHost>>
|
|
|
|
|
WebContents::GetAllSharedWorkers() {
|
|
|
|
|
std::vector<scoped_refptr<content::DevToolsAgentHost>> shared_workers;
|
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2019-10-02 12:38:27 +00:00
|
|
|
|
return shared_workers;
|
|
|
|
|
|
|
|
|
|
if (!enable_devtools_)
|
|
|
|
|
return shared_workers;
|
|
|
|
|
|
|
|
|
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
|
|
|
if (agent_host->GetType() ==
|
|
|
|
|
content::DevToolsAgentHost::kTypeSharedWorker) {
|
|
|
|
|
shared_workers.push_back(agent_host);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return shared_workers;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-01 18:44:24 +00:00
|
|
|
|
void WebContents::InspectSharedWorker() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2019-02-01 18:44:24 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (!enable_devtools_)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
|
|
|
if (agent_host->GetType() ==
|
|
|
|
|
content::DevToolsAgentHost::kTypeSharedWorker) {
|
|
|
|
|
OpenDevTools(nullptr);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->AttachTo(agent_host);
|
2019-02-01 18:44:24 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
|
void WebContents::InspectServiceWorker() {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (type_ == Type::kRemote)
|
2015-06-05 07:41:03 +00:00
|
|
|
|
return;
|
2015-06-24 14:23:38 +00:00
|
|
|
|
|
2016-09-07 02:16:52 +00:00
|
|
|
|
if (!enable_devtools_)
|
2016-09-06 09:53:42 +00:00
|
|
|
|
return;
|
|
|
|
|
|
2015-06-05 07:41:03 +00:00
|
|
|
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
|
|
|
if (agent_host->GetType() ==
|
2017-01-24 07:50:02 +00:00
|
|
|
|
content::DevToolsAgentHost::kTypeServiceWorker) {
|
2015-06-05 09:01:17 +00:00
|
|
|
|
OpenDevTools(nullptr);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->AttachTo(agent_host);
|
2015-06-05 07:41:03 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-25 19:01:05 +00:00
|
|
|
|
void WebContents::SetIgnoreMenuShortcuts(bool ignore) {
|
2018-09-10 10:06:16 +00:00
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
|
|
|
|
DCHECK(web_preferences);
|
2021-07-26 16:04:09 +00:00
|
|
|
|
web_preferences->SetIgnoreMenuShortcuts(ignore);
|
2017-06-25 19:01:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-06-15 13:40:49 +00:00
|
|
|
|
void WebContents::SetAudioMuted(bool muted) {
|
|
|
|
|
web_contents()->SetAudioMuted(muted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsAudioMuted() {
|
|
|
|
|
return web_contents()->IsAudioMuted();
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-12 11:35:11 +00:00
|
|
|
|
bool WebContents::IsCurrentlyAudible() {
|
|
|
|
|
return web_contents()->IsCurrentlyAudible();
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-13 01:57:04 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2020-01-31 19:20:11 +00:00
|
|
|
|
void WebContents::OnGetDefaultPrinter(
|
|
|
|
|
base::Value print_settings,
|
|
|
|
|
printing::CompletionCallback print_callback,
|
2021-03-16 16:18:45 +00:00
|
|
|
|
std::u16string device_name,
|
2020-01-31 19:20:11 +00:00
|
|
|
|
bool silent,
|
2021-10-05 07:16:04 +00:00
|
|
|
|
// <error, default_printer>
|
|
|
|
|
std::pair<std::string, std::u16string> info) {
|
2020-02-05 15:48:51 +00:00
|
|
|
|
// The content::WebContents might be already deleted at this point, and the
|
2021-05-19 23:15:47 +00:00
|
|
|
|
// PrintViewManagerElectron class does not do null check.
|
2020-02-05 15:48:51 +00:00
|
|
|
|
if (!web_contents()) {
|
|
|
|
|
if (print_callback)
|
|
|
|
|
std::move(print_callback).Run(false, "failed");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 07:16:04 +00:00
|
|
|
|
if (!info.first.empty()) {
|
|
|
|
|
if (print_callback)
|
|
|
|
|
std::move(print_callback).Run(false, info.first);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// If the user has passed a deviceName use it, otherwise use default printer.
|
|
|
|
|
std::u16string printer_name = device_name.empty() ? info.second : device_name;
|
2020-03-04 02:20:31 +00:00
|
|
|
|
|
|
|
|
|
// If there are no valid printers available on the network, we bail.
|
|
|
|
|
if (printer_name.empty() || !IsDeviceNameValid(printer_name)) {
|
|
|
|
|
if (print_callback)
|
|
|
|
|
std::move(print_callback).Run(false, "no valid printers available");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-01-31 19:20:11 +00:00
|
|
|
|
print_settings.SetStringKey(printing::kSettingDeviceName, printer_name);
|
|
|
|
|
|
|
|
|
|
auto* print_view_manager =
|
2021-05-19 23:15:47 +00:00
|
|
|
|
PrintViewManagerElectron::FromWebContents(web_contents());
|
|
|
|
|
if (!print_view_manager)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-01-31 19:20:11 +00:00
|
|
|
|
auto* focused_frame = web_contents()->GetFocusedFrame();
|
|
|
|
|
auto* rfh = focused_frame && focused_frame->HasSelection()
|
|
|
|
|
? focused_frame
|
|
|
|
|
: web_contents()->GetMainFrame();
|
|
|
|
|
|
|
|
|
|
print_view_manager->PrintNow(rfh, silent, std::move(print_settings),
|
|
|
|
|
std::move(print_callback));
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::Print(gin::Arguments* args) {
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary options =
|
|
|
|
|
gin::Dictionary::CreateEmpty(args->isolate());
|
2019-11-08 18:01:50 +00:00
|
|
|
|
base::Value settings(base::Value::Type::DICTIONARY);
|
2019-08-07 14:47:24 +00:00
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
|
if (args->Length() >= 1 && !args->GetNext(&options)) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("webContents.print(): Invalid print settings specified.");
|
2015-06-13 13:23:45 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-08-07 14:47:24 +00:00
|
|
|
|
|
2018-11-09 03:42:34 +00:00
|
|
|
|
printing::CompletionCallback callback;
|
|
|
|
|
if (args->Length() == 2 && !args->GetNext(&callback)) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("webContents.print(): Invalid optional callback provided.");
|
2018-11-09 03:42:34 +00:00
|
|
|
|
return;
|
2017-07-21 07:16:27 +00:00
|
|
|
|
}
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
|
|
|
|
// Set optional silent printing
|
|
|
|
|
bool silent = false;
|
2018-11-09 03:42:34 +00:00
|
|
|
|
options.Get("silent", &silent);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-07 14:47:24 +00:00
|
|
|
|
bool print_background = false;
|
|
|
|
|
options.Get("printBackground", &print_background);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingShouldPrintBackgrounds,
|
2019-08-07 14:47:24 +00:00
|
|
|
|
print_background);
|
|
|
|
|
|
2019-06-30 05:12:00 +00:00
|
|
|
|
// Set custom margin settings
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary margins =
|
|
|
|
|
gin::Dictionary::CreateEmpty(args->isolate());
|
2019-06-30 05:12:00 +00:00
|
|
|
|
if (options.Get("margins", &margins)) {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
printing::mojom::MarginType margin_type =
|
|
|
|
|
printing::mojom::MarginType::kDefaultMargins;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
margins.Get("marginType", &margin_type);
|
2020-08-15 01:51:28 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingMarginsType,
|
|
|
|
|
static_cast<int>(margin_type));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2020-08-15 01:51:28 +00:00
|
|
|
|
if (margin_type == printing::mojom::MarginType::kCustomMargins) {
|
2020-02-13 17:15:25 +00:00
|
|
|
|
base::Value custom_margins(base::Value::Type::DICTIONARY);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int top = 0;
|
|
|
|
|
margins.Get("top", &top);
|
2020-02-13 17:15:25 +00:00
|
|
|
|
custom_margins.SetIntKey(printing::kSettingMarginTop, top);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int bottom = 0;
|
|
|
|
|
margins.Get("bottom", &bottom);
|
2020-02-13 17:15:25 +00:00
|
|
|
|
custom_margins.SetIntKey(printing::kSettingMarginBottom, bottom);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int left = 0;
|
|
|
|
|
margins.Get("left", &left);
|
2020-02-13 17:15:25 +00:00
|
|
|
|
custom_margins.SetIntKey(printing::kSettingMarginLeft, left);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int right = 0;
|
|
|
|
|
margins.Get("right", &right);
|
2020-02-13 17:15:25 +00:00
|
|
|
|
custom_margins.SetIntKey(printing::kSettingMarginRight, right);
|
|
|
|
|
settings.SetPath(printing::kSettingMarginsCustom,
|
|
|
|
|
std::move(custom_margins));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
2020-08-15 01:51:28 +00:00
|
|
|
|
settings.SetIntKey(
|
|
|
|
|
printing::kSettingMarginsType,
|
|
|
|
|
static_cast<int>(printing::mojom::MarginType::kDefaultMargins));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set whether to print color or greyscale
|
|
|
|
|
bool print_color = true;
|
|
|
|
|
options.Get("color", &print_color);
|
2020-09-21 08:00:36 +00:00
|
|
|
|
auto const color_model = print_color ? printing::mojom::ColorModel::kColor
|
|
|
|
|
: printing::mojom::ColorModel::kGray;
|
|
|
|
|
settings.SetIntKey(printing::kSettingColor, static_cast<int>(color_model));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// Is the orientation landscape or portrait.
|
2019-06-30 05:12:00 +00:00
|
|
|
|
bool landscape = false;
|
|
|
|
|
options.Get("landscape", &landscape);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingLandscape, landscape);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2020-01-31 19:20:11 +00:00
|
|
|
|
// We set the default to the system's default printer and only update
|
|
|
|
|
// if at the Chromium level if the user overrides.
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// Printer device name as opened by the OS.
|
2021-03-16 16:18:45 +00:00
|
|
|
|
std::u16string device_name;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
options.Get("deviceName", &device_name);
|
2020-01-31 02:49:13 +00:00
|
|
|
|
if (!device_name.empty() && !IsDeviceNameValid(device_name)) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("webContents.print(): Invalid deviceName provided.");
|
2020-01-31 02:49:13 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
|
|
|
|
int scale_factor = 100;
|
|
|
|
|
options.Get("scaleFactor", &scale_factor);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingScaleFactor, scale_factor);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
|
|
|
|
int pages_per_sheet = 1;
|
|
|
|
|
options.Get("pagesPerSheet", &pages_per_sheet);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingPagesPerSheet, pages_per_sheet);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// True if the user wants to print with collate.
|
2019-06-30 05:12:00 +00:00
|
|
|
|
bool collate = true;
|
|
|
|
|
options.Get("collate", &collate);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingCollate, collate);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// The number of individual copies to print
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int copies = 1;
|
|
|
|
|
options.Get("copies", &copies);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingCopies, copies);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// Strings to be printed as headers and footers if requested by the user.
|
|
|
|
|
std::string header;
|
|
|
|
|
options.Get("header", &header);
|
|
|
|
|
std::string footer;
|
|
|
|
|
options.Get("footer", &footer);
|
|
|
|
|
|
|
|
|
|
if (!(header.empty() && footer.empty())) {
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingHeaderFooterEnabled, true);
|
2019-08-09 20:16:25 +00:00
|
|
|
|
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetStringKey(printing::kSettingHeaderFooterTitle, header);
|
|
|
|
|
settings.SetStringKey(printing::kSettingHeaderFooterURL, footer);
|
2019-08-24 01:14:23 +00:00
|
|
|
|
} else {
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingHeaderFooterEnabled, false);
|
2019-08-09 20:16:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// We don't want to allow the user to enable these settings
|
2019-06-30 05:12:00 +00:00
|
|
|
|
// but we need to set them or a CHECK is hit.
|
2020-04-15 00:14:38 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingPrinterType,
|
2021-07-26 16:02:16 +00:00
|
|
|
|
static_cast<int>(printing::mojom::PrinterType::kLocal));
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetBoolKey(printing::kSettingShouldPrintSelectionOnly, false);
|
|
|
|
|
settings.SetBoolKey(printing::kSettingRasterizePdf, false);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
|
|
|
|
// Set custom page ranges to print
|
2019-10-25 13:03:28 +00:00
|
|
|
|
std::vector<gin_helper::Dictionary> page_ranges;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
if (options.Get("pageRanges", &page_ranges)) {
|
2019-11-08 18:01:50 +00:00
|
|
|
|
base::Value page_range_list(base::Value::Type::LIST);
|
2019-09-13 14:26:59 +00:00
|
|
|
|
for (auto& range : page_ranges) {
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int from, to;
|
2019-09-13 14:26:59 +00:00
|
|
|
|
if (range.Get("from", &from) && range.Get("to", &to)) {
|
2019-11-08 18:01:50 +00:00
|
|
|
|
base::Value range(base::Value::Type::DICTIONARY);
|
2020-08-28 03:21:29 +00:00
|
|
|
|
// Chromium uses 1-based page ranges, so increment each by 1.
|
|
|
|
|
range.SetIntKey(printing::kSettingPageRangeFrom, from + 1);
|
|
|
|
|
range.SetIntKey(printing::kSettingPageRangeTo, to + 1);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
page_range_list.Append(std::move(range));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
} else {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-02-25 18:17:35 +00:00
|
|
|
|
if (!page_range_list.GetListDeprecated().empty())
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetPath(printing::kSettingPageRange, std::move(page_range_list));
|
2018-11-09 03:42:34 +00:00
|
|
|
|
}
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2019-08-09 20:16:25 +00:00
|
|
|
|
// Duplex type user wants to use.
|
2020-07-13 15:31:39 +00:00
|
|
|
|
printing::mojom::DuplexMode duplex_mode =
|
|
|
|
|
printing::mojom::DuplexMode::kSimplex;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
options.Get("duplexMode", &duplex_mode);
|
2020-05-26 20:06:26 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingDuplexMode,
|
|
|
|
|
static_cast<int>(duplex_mode));
|
2019-06-30 05:12:00 +00:00
|
|
|
|
|
2020-02-05 04:25:02 +00:00
|
|
|
|
// We've already done necessary parameter sanitization at the
|
|
|
|
|
// JS level, so we can simply pass this through.
|
|
|
|
|
base::Value media_size(base::Value::Type::DICTIONARY);
|
|
|
|
|
if (options.Get("mediaSize", &media_size))
|
|
|
|
|
settings.SetKey(printing::kSettingMediaSize, std::move(media_size));
|
|
|
|
|
|
2019-06-30 05:12:00 +00:00
|
|
|
|
// Set custom dots per inch (dpi)
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary dpi_settings;
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int dpi = 72;
|
|
|
|
|
if (options.Get("dpi", &dpi_settings)) {
|
|
|
|
|
int horizontal = 72;
|
|
|
|
|
dpi_settings.Get("horizontal", &horizontal);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingDpiHorizontal, horizontal);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
int vertical = 72;
|
|
|
|
|
dpi_settings.Get("vertical", &vertical);
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingDpiVertical, vertical);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
} else {
|
2019-11-08 18:01:50 +00:00
|
|
|
|
settings.SetIntKey(printing::kSettingDpiHorizontal, dpi);
|
|
|
|
|
settings.SetIntKey(printing::kSettingDpiVertical, dpi);
|
2019-06-30 05:12:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-13 17:17:11 +00:00
|
|
|
|
print_task_runner_->PostTaskAndReplyWithResult(
|
|
|
|
|
FROM_HERE, base::BindOnce(&GetDefaultPrinterAsync),
|
2020-01-31 19:20:11 +00:00
|
|
|
|
base::BindOnce(&WebContents::OnGetDefaultPrinter,
|
|
|
|
|
weak_factory_.GetWeakPtr(), std::move(settings),
|
|
|
|
|
std::move(callback), device_name, silent));
|
2017-02-06 09:18:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 05:30:59 +00:00
|
|
|
|
v8::Local<v8::Promise> WebContents::PrintToPDF(base::DictionaryValue settings) {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
|
|
|
|
|
gin_helper::Promise<v8::Local<v8::Value>> promise(isolate);
|
2019-02-21 12:32:44 +00:00
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2018-11-09 03:42:34 +00:00
|
|
|
|
PrintPreviewMessageHandler::FromWebContents(web_contents())
|
2019-10-30 05:30:59 +00:00
|
|
|
|
->PrintToPDF(std::move(settings), std::move(promise));
|
2019-02-21 12:32:44 +00:00
|
|
|
|
return handle;
|
2015-06-09 05:07:40 +00:00
|
|
|
|
}
|
2018-11-09 03:42:34 +00:00
|
|
|
|
#endif
|
2015-06-09 05:07:40 +00:00
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::AddWorkSpace(gin::Arguments* args,
|
2015-09-07 08:12:31 +00:00
|
|
|
|
const base::FilePath& path) {
|
2015-07-24 09:39:11 +00:00
|
|
|
|
if (path.empty()) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("path cannot be empty");
|
2015-07-24 09:39:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2018-09-12 13:45:08 +00:00
|
|
|
|
DevToolsAddFileSystem(std::string(), path);
|
2015-07-24 09:39:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::RemoveWorkSpace(gin::Arguments* args,
|
2015-09-07 08:12:31 +00:00
|
|
|
|
const base::FilePath& path) {
|
2015-07-24 09:39:11 +00:00
|
|
|
|
if (path.empty()) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("path cannot be empty");
|
2015-07-24 09:39:11 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
DevToolsRemoveFileSystem(path);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 20:09:47 +00:00
|
|
|
|
void WebContents::Undo() {
|
|
|
|
|
web_contents()->Undo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Redo() {
|
|
|
|
|
web_contents()->Redo();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Cut() {
|
|
|
|
|
web_contents()->Cut();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Copy() {
|
|
|
|
|
web_contents()->Copy();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Paste() {
|
|
|
|
|
web_contents()->Paste();
|
|
|
|
|
}
|
|
|
|
|
|
2015-05-15 07:15:19 +00:00
|
|
|
|
void WebContents::PasteAndMatchStyle() {
|
|
|
|
|
web_contents()->PasteAndMatchStyle();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-19 20:09:47 +00:00
|
|
|
|
void WebContents::Delete() {
|
|
|
|
|
web_contents()->Delete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SelectAll() {
|
|
|
|
|
web_contents()->SelectAll();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::Unselect() {
|
2017-04-13 10:21:30 +00:00
|
|
|
|
web_contents()->CollapseSelection();
|
2015-01-19 20:09:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
|
void WebContents::Replace(const std::u16string& word) {
|
2015-01-19 20:09:47 +00:00
|
|
|
|
web_contents()->Replace(word);
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-16 16:18:45 +00:00
|
|
|
|
void WebContents::ReplaceMisspelling(const std::u16string& word) {
|
2015-01-19 20:09:47 +00:00
|
|
|
|
web_contents()->ReplaceMisspelling(word);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
uint32_t WebContents::FindInPage(gin::Arguments* args) {
|
2021-03-16 16:18:45 +00:00
|
|
|
|
std::u16string search_text;
|
2015-12-17 23:10:42 +00:00
|
|
|
|
if (!args->GetNext(&search_text) || search_text.empty()) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("Must provide a non-empty search content");
|
2015-12-17 23:10:42 +00:00
|
|
|
|
return 0;
|
2015-12-17 17:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-17 22:15:07 +00:00
|
|
|
|
uint32_t request_id = ++find_in_page_request_id_;
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary dict;
|
2019-01-12 01:00:43 +00:00
|
|
|
|
auto options = blink::mojom::FindOptions::New();
|
|
|
|
|
if (args->GetNext(&dict)) {
|
|
|
|
|
dict.Get("forward", &options->forward);
|
|
|
|
|
dict.Get("matchCase", &options->match_case);
|
2020-06-22 17:35:10 +00:00
|
|
|
|
dict.Get("findNext", &options->new_session);
|
2019-01-12 01:00:43 +00:00
|
|
|
|
}
|
2015-12-17 17:27:56 +00:00
|
|
|
|
|
2019-01-12 01:00:43 +00:00
|
|
|
|
web_contents()->Find(request_id, search_text, std::move(options));
|
2015-12-17 23:10:42 +00:00
|
|
|
|
return request_id;
|
2015-12-17 17:27:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::StopFindInPage(content::StopFindAction action) {
|
|
|
|
|
web_contents()->StopFinding(action);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:12:38 +00:00
|
|
|
|
void WebContents::ShowDefinitionForSelection() {
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_MAC)
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* const view = web_contents()->GetRenderWidgetHostView();
|
2016-06-02 17:12:38 +00:00
|
|
|
|
if (view)
|
|
|
|
|
view->ShowDefinitionForSelection();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-26 19:06:11 +00:00
|
|
|
|
void WebContents::CopyImageAt(int x, int y) {
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* const host = web_contents()->GetMainFrame();
|
2016-07-26 19:06:11 +00:00
|
|
|
|
if (host)
|
|
|
|
|
host->CopyImageAt(x, y);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-24 04:58:28 +00:00
|
|
|
|
void WebContents::Focus() {
|
2020-03-02 07:51:02 +00:00
|
|
|
|
// Focusing on WebContents does not automatically focus the window on macOS
|
|
|
|
|
// and Linux, do it manually to match the behavior on Windows.
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_MAC) || BUILDFLAG(IS_LINUX)
|
2020-03-02 07:51:02 +00:00
|
|
|
|
if (owner_window())
|
|
|
|
|
owner_window()->Focus(true);
|
|
|
|
|
#endif
|
2015-07-24 04:58:28 +00:00
|
|
|
|
web_contents()->Focus();
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2016-08-03 03:29:55 +00:00
|
|
|
|
bool WebContents::IsFocused() const {
|
2018-05-16 19:12:45 +00:00
|
|
|
|
auto* view = web_contents()->GetRenderWidgetHostView();
|
2018-04-18 01:55:30 +00:00
|
|
|
|
if (!view)
|
|
|
|
|
return false;
|
2016-08-15 21:13:24 +00:00
|
|
|
|
|
2020-10-27 17:51:45 +00:00
|
|
|
|
if (GetType() != Type::kBackgroundPage) {
|
2018-05-16 19:12:45 +00:00
|
|
|
|
auto* window = web_contents()->GetNativeView()->GetToplevelWindow();
|
2016-08-15 21:13:24 +00:00
|
|
|
|
if (window && !window->IsVisible())
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return view->HasFocus();
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2015-09-18 06:20:31 +00:00
|
|
|
|
void WebContents::SendInputEvent(v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::Value> input_event) {
|
2018-04-12 12:54:04 +00:00
|
|
|
|
content::RenderWidgetHostView* view =
|
|
|
|
|
web_contents()->GetRenderWidgetHostView();
|
2015-09-18 06:20:31 +00:00
|
|
|
|
if (!view)
|
|
|
|
|
return;
|
|
|
|
|
|
2018-04-12 12:54:04 +00:00
|
|
|
|
content::RenderWidgetHost* rwh = view->GetRenderWidgetHost();
|
2018-04-18 01:55:30 +00:00
|
|
|
|
blink::WebInputEvent::Type type =
|
2019-10-31 07:56:00 +00:00
|
|
|
|
gin::GetWebInputEventType(isolate, input_event);
|
2017-06-16 20:42:33 +00:00
|
|
|
|
if (blink::WebInputEvent::IsMouseEventType(type)) {
|
2015-09-18 06:20:31 +00:00
|
|
|
|
blink::WebMouseEvent mouse_event;
|
2019-10-31 07:56:00 +00:00
|
|
|
|
if (gin::ConvertFromV8(isolate, input_event, &mouse_event)) {
|
2018-05-15 01:59:22 +00:00
|
|
|
|
if (IsOffScreen()) {
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-05-15 01:59:22 +00:00
|
|
|
|
GetOffScreenRenderWidgetHostView()->SendMouseEvent(mouse_event);
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
|
|
|
|
rwh->ForwardMouseEvent(mouse_event);
|
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2017-06-16 20:42:33 +00:00
|
|
|
|
} else if (blink::WebInputEvent::IsKeyboardEventType(type)) {
|
2017-04-13 10:21:30 +00:00
|
|
|
|
content::NativeWebKeyboardEvent keyboard_event(
|
2020-05-26 20:06:26 +00:00
|
|
|
|
blink::WebKeyboardEvent::Type::kRawKeyDown,
|
|
|
|
|
blink::WebInputEvent::Modifiers::kNoModifiers, ui::EventTimeForNow());
|
2019-10-25 13:03:28 +00:00
|
|
|
|
if (gin::ConvertFromV8(isolate, input_event, &keyboard_event)) {
|
2018-04-12 12:54:04 +00:00
|
|
|
|
rwh->ForwardKeyboardEvent(keyboard_event);
|
2015-09-18 06:20:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2020-05-26 20:06:26 +00:00
|
|
|
|
} else if (type == blink::WebInputEvent::Type::kMouseWheel) {
|
2015-09-18 06:20:31 +00:00
|
|
|
|
blink::WebMouseWheelEvent mouse_wheel_event;
|
2019-10-31 07:56:00 +00:00
|
|
|
|
if (gin::ConvertFromV8(isolate, input_event, &mouse_wheel_event)) {
|
2018-05-15 01:59:22 +00:00
|
|
|
|
if (IsOffScreen()) {
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-05-15 01:59:22 +00:00
|
|
|
|
GetOffScreenRenderWidgetHostView()->SendMouseWheelEvent(
|
|
|
|
|
mouse_wheel_event);
|
|
|
|
|
#endif
|
|
|
|
|
} else {
|
2019-04-16 16:23:38 +00:00
|
|
|
|
// Chromium expects phase info in wheel events (and applies a
|
|
|
|
|
// DCHECK to verify it). See: https://crbug.com/756524.
|
|
|
|
|
mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseBegan;
|
2020-04-21 00:25:38 +00:00
|
|
|
|
mouse_wheel_event.dispatch_type =
|
|
|
|
|
blink::WebInputEvent::DispatchType::kBlocking;
|
2019-04-16 16:23:38 +00:00
|
|
|
|
rwh->ForwardWheelEvent(mouse_wheel_event);
|
|
|
|
|
|
|
|
|
|
// Send a synthetic wheel event with phaseEnded to finish scrolling.
|
|
|
|
|
mouse_wheel_event.has_synthetic_phase = true;
|
|
|
|
|
mouse_wheel_event.delta_x = 0;
|
|
|
|
|
mouse_wheel_event.delta_y = 0;
|
|
|
|
|
mouse_wheel_event.phase = blink::WebMouseWheelEvent::kPhaseEnded;
|
|
|
|
|
mouse_wheel_event.dispatch_type =
|
2020-04-21 00:25:38 +00:00
|
|
|
|
blink::WebInputEvent::DispatchType::kEventNonBlocking;
|
2018-05-15 01:59:22 +00:00
|
|
|
|
rwh->ForwardWheelEvent(mouse_wheel_event);
|
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
isolate->ThrowException(
|
2019-10-25 13:03:28 +00:00
|
|
|
|
v8::Exception::Error(gin::StringToV8(isolate, "Invalid event object")));
|
2015-09-18 06:20:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::BeginFrameSubscription(gin::Arguments* args) {
|
2018-05-14 17:09:05 +00:00
|
|
|
|
bool only_dirty = false;
|
2016-06-26 02:46:40 +00:00
|
|
|
|
FrameSubscriber::FrameCaptureCallback callback;
|
2016-06-21 00:15:39 +00:00
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
if (args->Length() > 1) {
|
|
|
|
|
if (!args->GetNext(&only_dirty)) {
|
|
|
|
|
args->ThrowError();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-25 16:23:40 +00:00
|
|
|
|
if (!args->GetNext(&callback)) {
|
2016-06-26 02:46:40 +00:00
|
|
|
|
args->ThrowError();
|
|
|
|
|
return;
|
2016-06-25 16:23:40 +00:00
|
|
|
|
}
|
2016-06-21 00:15:39 +00:00
|
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
|
frame_subscriber_ =
|
|
|
|
|
std::make_unique<FrameSubscriber>(web_contents(), callback, only_dirty);
|
2015-09-18 07:57:43 +00:00
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
|
2015-09-18 07:57:43 +00:00
|
|
|
|
void WebContents::EndFrameSubscription() {
|
2018-04-18 00:45:15 +00:00
|
|
|
|
frame_subscriber_.reset();
|
2015-09-18 07:57:43 +00:00
|
|
|
|
}
|
2015-09-18 06:20:31 +00:00
|
|
|
|
|
2019-10-25 13:03:28 +00:00
|
|
|
|
void WebContents::StartDrag(const gin_helper::Dictionary& item,
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin::Arguments* args) {
|
2016-07-03 04:58:31 +00:00
|
|
|
|
base::FilePath file;
|
|
|
|
|
std::vector<base::FilePath> files;
|
|
|
|
|
if (!item.Get("files", &files) && item.Get("file", &file)) {
|
|
|
|
|
files.push_back(file);
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-04 20:58:31 +00:00
|
|
|
|
v8::Local<v8::Value> icon_value;
|
|
|
|
|
if (!item.Get("icon", &icon_value)) {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
2021-01-04 20:58:31 +00:00
|
|
|
|
.ThrowError("'icon' parameter is required");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NativeImage* icon = nullptr;
|
|
|
|
|
if (!NativeImage::TryConvertNativeImage(args->isolate(), icon_value, &icon) ||
|
|
|
|
|
icon->image().IsEmpty()) {
|
2016-07-03 04:58:31 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Start dragging.
|
|
|
|
|
if (!files.empty()) {
|
2020-07-22 05:34:34 +00:00
|
|
|
|
base::CurrentThread::ScopedNestableTaskAllower allow;
|
2016-07-03 04:58:31 +00:00
|
|
|
|
DragFileItems(files, icon->image(), web_contents()->GetNativeView());
|
|
|
|
|
} else {
|
2020-07-20 18:07:02 +00:00
|
|
|
|
gin_helper::ErrorThrower(args->isolate())
|
|
|
|
|
.ThrowError("Must specify either 'file' or 'files' option");
|
2016-07-03 04:58:31 +00:00
|
|
|
|
}
|
2016-07-03 03:26:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
v8::Local<v8::Promise> WebContents::CapturePage(gin::Arguments* args) {
|
2016-07-05 22:43:57 +00:00
|
|
|
|
gfx::Rect rect;
|
2020-07-16 21:11:44 +00:00
|
|
|
|
gin_helper::Promise<gfx::Image> promise(args->isolate());
|
2019-02-21 12:32:44 +00:00
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2016-07-05 22:43:57 +00:00
|
|
|
|
|
2018-11-28 04:50:53 +00:00
|
|
|
|
// get rect arguments if they exist
|
|
|
|
|
args->GetNext(&rect);
|
2016-07-05 22:43:57 +00:00
|
|
|
|
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* const view = web_contents()->GetRenderWidgetHostView();
|
2017-04-13 10:21:30 +00:00
|
|
|
|
if (!view) {
|
2019-11-01 06:10:32 +00:00
|
|
|
|
promise.Resolve(gfx::Image());
|
2019-02-21 12:32:44 +00:00
|
|
|
|
return handle;
|
2016-07-05 22:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if !BUILDFLAG(IS_MAC)
|
2021-03-15 22:43:25 +00:00
|
|
|
|
// If the view's renderer is suspended this may fail on Windows/Linux -
|
|
|
|
|
// bail if so. See CopyFromSurface in
|
|
|
|
|
// content/public/browser/render_widget_host_view.h.
|
|
|
|
|
auto* rfh = web_contents()->GetMainFrame();
|
|
|
|
|
if (rfh &&
|
|
|
|
|
rfh->GetVisibilityState() == blink::mojom::PageVisibilityState::kHidden) {
|
|
|
|
|
promise.Resolve(gfx::Image());
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#endif // BUILDFLAG(IS_MAC)
|
2021-03-15 22:43:25 +00:00
|
|
|
|
|
2016-07-05 22:43:57 +00:00
|
|
|
|
// Capture full page if user doesn't specify a |rect|.
|
2018-04-18 01:55:30 +00:00
|
|
|
|
const gfx::Size view_size =
|
|
|
|
|
rect.IsEmpty() ? view->GetViewBounds().size() : rect.size();
|
2016-07-05 22:43:57 +00:00
|
|
|
|
|
|
|
|
|
// By default, the requested bitmap size is the view size in screen
|
|
|
|
|
// coordinates. However, if there's more pixel detail available on the
|
|
|
|
|
// current system, increase the requested bitmap size to capture it all.
|
|
|
|
|
gfx::Size bitmap_size = view_size;
|
|
|
|
|
const gfx::NativeView native_view = view->GetNativeView();
|
2018-04-18 01:55:30 +00:00
|
|
|
|
const float scale = display::Screen::GetScreen()
|
|
|
|
|
->GetDisplayNearestView(native_view)
|
|
|
|
|
.device_scale_factor();
|
2016-07-05 22:43:57 +00:00
|
|
|
|
if (scale > 1.0f)
|
|
|
|
|
bitmap_size = gfx::ScaleToCeiledSize(view_size, scale);
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
view->CopyFromSurface(gfx::Rect(rect.origin(), view_size), bitmap_size,
|
2019-02-21 12:32:44 +00:00
|
|
|
|
base::BindOnce(&OnCapturePageDone, std::move(promise)));
|
|
|
|
|
return handle;
|
2016-07-05 22:43:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::IncrementCapturerCount(gin::Arguments* args) {
|
2020-01-25 00:43:42 +00:00
|
|
|
|
gfx::Size size;
|
|
|
|
|
bool stay_hidden = false;
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
|
bool stay_awake = false;
|
2020-01-25 00:43:42 +00:00
|
|
|
|
|
|
|
|
|
// get size arguments if they exist
|
|
|
|
|
args->GetNext(&size);
|
|
|
|
|
// get stayHidden arguments if they exist
|
|
|
|
|
args->GetNext(&stay_hidden);
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
|
// get stayAwake arguments if they exist
|
|
|
|
|
args->GetNext(&stay_awake);
|
2020-01-25 00:43:42 +00:00
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
std::ignore =
|
|
|
|
|
web_contents()->IncrementCapturerCount(size, stay_hidden, stay_awake);
|
2020-01-25 00:43:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-20 18:07:02 +00:00
|
|
|
|
void WebContents::DecrementCapturerCount(gin::Arguments* args) {
|
2020-01-25 00:43:42 +00:00
|
|
|
|
bool stay_hidden = false;
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
|
bool stay_awake = false;
|
2020-01-25 00:43:42 +00:00
|
|
|
|
|
|
|
|
|
// get stayHidden arguments if they exist
|
|
|
|
|
args->GetNext(&stay_hidden);
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
|
// get stayAwake arguments if they exist
|
|
|
|
|
args->GetNext(&stay_awake);
|
2020-01-25 00:43:42 +00:00
|
|
|
|
|
chore: bump chromium to 92.0.4475.0 (master) (#28462)
* chore: bump chromium in DEPS to 91.0.4464.0
* chore: rebuild chromium/dcheck.patch with import-patches -3
Mechanical only; no code changes
* chore: remove content_browser_main_loop.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
The function being patched (BrowserMainLoop::MainMessageLoopRun()) no
longer exists.
NB: if removing this introduces regressions the likely fix will be to
add a similar patch for ShellBrowserMainParts::WillRunMainMessageLoop()
which has similar code and was added at the same time this was removed.
* chore: rebuild chromium/put_back_deleted_colors_for_autofill.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/disable_color_correct_rendering.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/eat_allow_disabling_blink_scheduler_throttling_per_renderview.patch with patch
Mechanical only; no code changes
* chore: rebuild chromium/gpu_notify_when_dxdiag_request_fails.patch with import-patches -3
Mechanical only; no code changes
* chore: rebuild chromium/ui_gtk_public_header.patch manually
no code changes
* chore: rebuild chromium/web_contents.patch with import-patches -3
Mechanical only; no code changes
* chore: remove v8/skip_global_registration_of_shared_arraybuffer_backing_stores.patch
Refs: https://chromium-review.googlesource.com/c/v8/v8/+/2763874
This patch has been merged upstream
* chore: export patches
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785841
SkColorFromColorId() no longer takes theme, scheme args
* chore: sync chromium/put_back_deleted_colors_for_autofill.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2772143
Change new calls to GetDarkSchemeColor to fit our patched call signature
* chore: update add_trustedauthclient_to_urlloaderfactory.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2757969
Sync with removal of render_frame_id_ in our mojom
* chore: update chromium/frame_host_manager.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update chromium/revert_remove_contentrendererclient_shouldfork.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2755314
Upstream has removed `history_list_length_` which we were comparing to 0
to calculate our `is_initial_navigation` bool when calling ShouldFork().
ShouldFork() is ours and none of the code paths actually use that param,
so this commit removes it altogether.
* chore: update permissions_to_register
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2789074
Replace all uses of APIPermission::ID enum with Mojo type
* refactor: update return type of PreMainMessageLoopRun()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
Used to return void; now returns an int errorcode.
Note: 2725153 also has some nice doc updates about Browser's "stages"
* refactor: sync ElectronBrowserMainParts to MainParts changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
RunMainMessageLoopParts has been replaced with WillRunMainMessageLoop
so `BrowserMainLoop::result_code_` is no longer available to us for our
exit_code_ pointer.
This variable held a dual role: (1) of course, hold the exit code, but
also (2) was a nullptr before the message loop was ready, indicating to
anyone calling SetExitCode() that we were still in startup and could
just exit() without any extra steps. exit_code_ still fulfills these two
roles but is now a base::Optional.
* chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2725153
BrowserMainParts::BrowsePreDefaultMainMesssageLoopRun() has been
removed; move that work to the new WillRunMainMessageLoop().
* refactor: stop using CallbackList; it has been removed.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2785973
* refactor: update use of threadpools.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2773408
The upstream code is still in flux (e.g. reverts and re-lands) but the
tl;dr for this commit is (1) include thread_pool.h if you're using it
and (2) don't instantiate pools directly.
* refactor: remove routing_id from CreateLoaderAndStart
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
NB: One logic branch in ProxyingURLLoaderFactory::CreateLoaderAndStart
calls std::make_unique<InProgressRequest>, which needs a routing_id.
This PR uses the member field `routing_id_` since there's no longer one
being passed into CreateLoaderAndStart.
* refactor: sync to upstream ParittionOptions churn
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
PartitionOptions' enums have changed.
* refactor: update Manifest::Location usage
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
tldr: s/Manifest::FOO/ManifestLocation::kFoo/
* chore: bump chromium in DEPS to 91.0.4465.0
* update patches
* refactor: update extensions::Manifest to upstream
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771320
- extensions::Manifest::COMPONENT
+ extensions::mojom::ManifestLocation::kExternalComponent
* refactor: sync with upstream UrlInfo ctor changes
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2740008
UrlInfo ctor now takes UrlInfo::OriginIsolationRequest instead of a bool
* chore: update invocation of convert_protocol_to_json.py
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2792623
python3 is being used in parts of the upstream build, but the copy of
convert_protocol_to_json.py invoked in v8/third_party/inspector_protocol
is not python3-friendly. Node has a py2+3-friendly version of it in its
tools directory, so call it instead.
* chore: use extensions::mojom::APIPermissionID
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791122
tldr:
- extensions::APIPermission::kFoo
+ extensions::mojom::APIPermissionID::kFoo
* chore: Remove support for TLS1.0/1.1 in SSLVersionMin policy
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2765737
Remove TLS v1.0 & 1.1 from our SSLProtocolVersionFromString() function.
This is the same change made upstream at
https://chromium-review.googlesource.com/c/chromium/src/+/2765737/8/chrome/browser/ssl/ssl_config_service_manager_pref.cc
* fixup! chore: update ElectronBrowserMainParts::PreDefaultMainMessageLoopRun
* chore: Use IDType for permission change subscriptions.
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791431
tldr: {Subscribe,Unsubscribe}PermissionStatusChange's tag type used to
be an int; now it's the new SubscriptionId type (which is an IdType64).
* chore: sync PowerMonitor code to upstream refactor
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2752635
tldr: PowerMonitor has been split into PowerStateObserver,
PowerSuspendObserver, and PowerThermalObserver to reduce number of tasks
posted to consumers who only need notifications for one of those things
instead of all of them.
* chore: use PartitionOptions's new Cookies field
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2771318
* Revert "refactor: remove routing_id from CreateLoaderAndStart"
This reverts commit 8c9773b87a3c84f9073a47089eb2b6889d745245.
8c9773b was only a partial fix; reverting to start & try again.
* update patches
* chore: bump chromium in DEPS to 91.0.4466.0
* chore: update chromium/accelerator.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2795472
tldr: sync patch with upstream renamed variable & macro names.
* chore: update chromium/gtk_visibility.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796200
tldr: no code changes; just updating the diff to apply cleanly.
note: ooh upstream Wayland hacking!
* chore: update chromium/picture-in-picture.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2710023
tldr: no code changes; just updating the diff to apply cleanly.
* chore: update chromium/worker_feat_add_hook_to_notify_script_ready.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2775573
tldr: no code changes; just updating the diff to apply cleanly.
* chore: export_all_patches
* chore: update chromium/feat_add_set_theme_source_to_allow_apps_to.patch
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2796511
tldr: NotifyObservers has been renamed to NotifyOnNativeThemeUpdated,
so update the invocation in our patch.
* chore: update ElectronBrowserClient w/upstream API
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797454
tldr: GetDevToolsManagerDelegate() was returning an owned raw pointer.
Replaced it with CreateDevToolsManagerDelegate() which uses unique_ptr<>.
* chore: handle new content::PermissionType::FILE_HANDLING in toV8()
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762201
`file-handling` string confirmed in https://chromium-review.googlesource.com/c/chromium/src/+/2762201/18/chrome/browser/ui/webui/settings/site_settings_helper.cc
* refactor: remove routing_id from CreateLoaderAndStart pt 1
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2762858
Part 1: the easiest ones
* 2796724: Support Python3
https://chromium-review.googlesource.com/c/infra/luci/python-adb/+/2796724
* chore: bump chromium in DEPS to 91.0.4468.0
* 2668974: WebShare: Implement SharingServicePicker
https://chromium-review.googlesource.com/c/chromium/src/+/2668974
* 2802766: Apply modernize-make-unique to media/
https://chromium-review.googlesource.com/c/chromium/src/+/2802766
* 2802823: Apply modernize-make-unique to gpu/
https://chromium-review.googlesource.com/c/chromium/src/+/2802823
* 2803041: Apply modernize-make-unique to remaining files
https://chromium-review.googlesource.com/c/chromium/src/+/2803041
* 2798873: Convert GtkKeyBindingsHandler build checks to runtime checks
https://chromium-review.googlesource.com/c/chromium/src/+/2798873
* 2733595: [ch-r] Parse ACCEPT_CH H2/3 frame and restart with new headers if needed
https://chromium-review.googlesource.com/c/chromium/src/+/2733595
* chore: update patch indices
* 2795107: Remove unused PermissionRequest IDs.
https://chromium-review.googlesource.com/c/chromium/src/+/2795107
* chore: bump chromium in DEPS to 91.0.4469.0
* chore: fixup patch indices
* chore: bump chromium in DEPS to 91.0.4469.5
* PiP 1.5: Add microphone, camera, and hang up buttons to the PiP window
https://chromium-review.googlesource.com/c/chromium/src/+/2710023
* fixup! refactor: remove routing_id from CreateLoaderAndStart
* refactor: use URLLoaderNetworkServiceObserver for auth requests from SimpleURLLoader
* fixup! chore: fixup patch indices
* 2724817: Expand scope of wasm-eval to all URLs
https://chromium-review.googlesource.com/c/chromium/src/+/2724817
* Fixup patch after rebase
* chore: bump chromium in DEPS to 91.0.4472.0
* 2797341: [ozone/x11] Enabled the global shortcut listener.
https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* 2805553: Reland Add GTK ColorMixers to ColorPipeline P1
https://chromium-review.googlesource.com/c/chromium/src/+/2805553
* 2804366: PiP 1.5: Label back to tab button with origin and center it
https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* 2784730: Fix crash on AX mode change in NativeViewHost without a Widget
https://chromium-review.googlesource.com/c/chromium/src/+/2784730
* chore: update patch indices
* 2810174: Add PdfAnnotationsEnabled policy.
https://chromium-review.googlesource.com/c/chromium/src/+/2810174
* 2807829: Allow capturers to indicate if they want a WakeLock or not.
https://chromium-review.googlesource.com/c/chromium/src/+/2807829
* chore: bump chromium in DEPS to 92.0.4473.0
* chore: bump chromium in DEPS to 92.0.4474.0
* chore: bump chromium in DEPS to 92.0.4475.0
* chore: update patches
* chore: updates patches
* chore: update is_media_key patch to handle new ozone impl
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
* fix: ExecuteJavascript requests now need to be flagged as non-bf-aware
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2787195
* chore: icon_util_x11 is now icon_util_linux
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2791362
* build: update sysroots
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2628496
* build: fix missing symbols on linux build
* use_ozone and use_x11 are not exclusive
* new button view to build for pip
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2797341
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2804366
* chore: fix broken gtk_util color patch
* chore: remove patch conflict
* build: update linux manifests
* chore: build bttlb on all platforms for pip
* chore: add thread_pool include for views delegate win
* chore: fix lint
* chore: add node patches for V8 changes
* build: add missing base include on windows
* fix: update frame host manager patch for new state transitions
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2714464
* chore: update windows zip manifests
* chore: update mac zip manifests
* chore: fix patch linting
* refactor: implement missing URLLoaderNetworkServiceObserver methods
It is against The Mojo Rules to leave hanging callbacks. These always
have to be called.
Refs: https://github.com/electron/electron/commit/186528aab9f8e29d658f07d220bb7f627980edda
* spec: fix locale test on local linux
* fix: pass the exit code correctly in new PreMainMessageLoopRun
Refs: https://github.com/electron/electron/commit/2622e91c4493ceb032e2f80cb484885bb8f97475
* fix: ensure we early-exit when request_handler_ is not provided
Refs: https://github.com/electron/electron/commit/93077afbfb6db248a0c0cc447d7ad2c9ccfda1d5
* fix: strongly set result_code in the BrowserMainLoop
* fix: invalid usage of non-targetted PostTask
You must always either use a host threadpool or specify a target
thread. In this case we did neither after this refactor.
Refs: https://github.com/electron/electron/pull/28462/commits/4e33ee0ad35a710bd34641cb0376bdee6aea2d1f
* chore: fix gn check
* chore: remove stray .rej files in patch
* chore: add mojo error code to url loader failure
* build: ensure CI is truthy in arm test env
* fix: handle windowCaptureMacV2 being enabled when fetching media source id
Refs: https://chromium-review.googlesource.com/c/chromium/src/+/2709931
Co-authored-by: Charles Kerr <charles@charleskerr.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
Co-authored-by: deepak1556 <hop2deep@gmail.com>
Co-authored-by: Samuel Attard <samuel.r.attard@gmail.com>
Co-authored-by: Samuel Attard <sattard@slack-corp.com>
2021-04-15 17:44:35 +00:00
|
|
|
|
web_contents()->DecrementCapturerCount(stay_hidden, stay_awake);
|
2020-01-25 00:43:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsBeingCaptured() {
|
|
|
|
|
return web_contents()->IsBeingCaptured();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-26 20:06:26 +00:00
|
|
|
|
void WebContents::OnCursorChanged(const content::WebCursor& webcursor) {
|
2020-03-14 20:54:14 +00:00
|
|
|
|
const ui::Cursor& cursor = webcursor.cursor();
|
2016-01-31 16:00:14 +00:00
|
|
|
|
|
2020-03-14 20:54:14 +00:00
|
|
|
|
if (cursor.type() == ui::mojom::CursorType::kCustom) {
|
|
|
|
|
Emit("cursor-changed", CursorTypeToString(cursor),
|
|
|
|
|
gfx::Image::CreateFrom1xBitmap(cursor.custom_bitmap()),
|
|
|
|
|
cursor.image_scale_factor(),
|
|
|
|
|
gfx::Size(cursor.custom_bitmap().width(),
|
|
|
|
|
cursor.custom_bitmap().height()),
|
|
|
|
|
cursor.custom_hotspot());
|
2016-01-31 16:00:14 +00:00
|
|
|
|
} else {
|
2020-03-14 20:54:14 +00:00
|
|
|
|
Emit("cursor-changed", CursorTypeToString(cursor));
|
2016-01-31 16:00:14 +00:00
|
|
|
|
}
|
2016-01-30 05:33:55 +00:00
|
|
|
|
}
|
2016-07-18 06:54:52 +00:00
|
|
|
|
|
2015-06-05 07:18:15 +00:00
|
|
|
|
bool WebContents::IsGuest() const {
|
2020-10-27 17:51:45 +00:00
|
|
|
|
return type_ == Type::kWebView;
|
2015-06-05 07:18:15 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-16 22:57:40 +00:00
|
|
|
|
void WebContents::AttachToIframe(content::WebContents* embedder_web_contents,
|
|
|
|
|
int embedder_frame_id) {
|
2021-03-15 22:43:25 +00:00
|
|
|
|
attached_ = true;
|
2018-08-16 22:57:40 +00:00
|
|
|
|
if (guest_delegate_)
|
|
|
|
|
guest_delegate_->AttachToIframe(embedder_web_contents, embedder_frame_id);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-28 10:10:56 +00:00
|
|
|
|
bool WebContents::IsOffScreen() const {
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2020-10-27 17:51:45 +00:00
|
|
|
|
return type_ == Type::kOffScreen;
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
2016-07-28 10:10:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2016-08-04 04:47:52 +00:00
|
|
|
|
void WebContents::OnPaint(const gfx::Rect& dirty_rect, const SkBitmap& bitmap) {
|
2017-04-12 14:16:27 +00:00
|
|
|
|
Emit("paint", dirty_rect, gfx::Image::CreateFrom1xBitmap(bitmap));
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::StartPainting() {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
2018-01-25 13:46:30 +00:00
|
|
|
|
if (osr_wcv)
|
|
|
|
|
osr_wcv->SetPainting(true);
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::StopPainting() {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
2018-01-25 13:46:30 +00:00
|
|
|
|
if (osr_wcv)
|
|
|
|
|
osr_wcv->SetPainting(false);
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsPainting() const {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
2018-01-25 13:46:30 +00:00
|
|
|
|
return osr_wcv && osr_wcv->IsPainting();
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SetFrameRate(int frame_rate) {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
2018-01-25 13:46:30 +00:00
|
|
|
|
if (osr_wcv)
|
|
|
|
|
osr_wcv->SetFrameRate(frame_rate);
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int WebContents::GetFrameRate() const {
|
2018-03-20 01:25:51 +00:00
|
|
|
|
auto* osr_wcv = GetOffScreenWebContentsView();
|
2018-01-25 13:46:30 +00:00
|
|
|
|
return osr_wcv ? osr_wcv->GetFrameRate() : 0;
|
2016-08-03 03:29:55 +00:00
|
|
|
|
}
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#endif
|
2016-08-03 03:29:55 +00:00
|
|
|
|
|
2016-09-01 17:25:12 +00:00
|
|
|
|
void WebContents::Invalidate() {
|
2017-02-08 07:08:03 +00:00
|
|
|
|
if (IsOffScreen()) {
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2018-05-15 01:59:22 +00:00
|
|
|
|
auto* osr_rwhv = GetOffScreenRenderWidgetHostView();
|
2017-02-08 07:08:03 +00:00
|
|
|
|
if (osr_rwhv)
|
|
|
|
|
osr_rwhv->Invalidate();
|
2017-06-26 09:13:05 +00:00
|
|
|
|
#endif
|
2017-02-08 08:05:16 +00:00
|
|
|
|
} else {
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* const window = owner_window();
|
2017-02-14 20:30:23 +00:00
|
|
|
|
if (window)
|
|
|
|
|
window->Invalidate();
|
2017-02-08 07:08:03 +00:00
|
|
|
|
}
|
2016-09-01 17:25:12 +00:00
|
|
|
|
}
|
2016-08-03 03:29:55 +00:00
|
|
|
|
|
2019-07-03 01:22:09 +00:00
|
|
|
|
gfx::Size WebContents::GetSizeForNewRenderView(content::WebContents* wc) {
|
2017-05-11 21:48:14 +00:00
|
|
|
|
if (IsOffScreen() && wc == web_contents()) {
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(web_contents());
|
2017-05-11 21:48:14 +00:00
|
|
|
|
if (relay) {
|
2018-10-02 22:14:43 +00:00
|
|
|
|
auto* owner_window = relay->GetNativeWindow();
|
|
|
|
|
return owner_window ? owner_window->GetSize() : gfx::Size();
|
2017-05-11 21:48:14 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return gfx::Size();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-29 14:13:20 +00:00
|
|
|
|
void WebContents::SetZoomLevel(double level) {
|
2017-01-30 11:18:40 +00:00
|
|
|
|
zoom_controller_->SetZoomLevel(level);
|
2017-01-29 14:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 17:15:23 +00:00
|
|
|
|
double WebContents::GetZoomLevel() const {
|
2017-01-30 11:18:40 +00:00
|
|
|
|
return zoom_controller_->GetZoomLevel();
|
2017-01-29 14:13:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-13 23:13:05 +00:00
|
|
|
|
void WebContents::SetZoomFactor(gin_helper::ErrorThrower thrower,
|
|
|
|
|
double factor) {
|
|
|
|
|
if (factor < std::numeric_limits<double>::epsilon()) {
|
|
|
|
|
thrower.ThrowError("'zoomFactor' must be a double greater than 0.0");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 19:57:34 +00:00
|
|
|
|
auto level = blink::PageZoomFactorToZoomLevel(factor);
|
2017-01-29 14:13:20 +00:00
|
|
|
|
SetZoomLevel(level);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 17:15:23 +00:00
|
|
|
|
double WebContents::GetZoomFactor() const {
|
2017-01-29 14:13:20 +00:00
|
|
|
|
auto level = GetZoomLevel();
|
2019-10-18 19:57:34 +00:00
|
|
|
|
return blink::PageZoomLevelToZoomFactor(level);
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-04 01:18:23 +00:00
|
|
|
|
void WebContents::SetTemporaryZoomLevel(double level) {
|
2017-01-30 17:06:50 +00:00
|
|
|
|
zoom_controller_->SetTemporaryZoomLevel(level);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-14 18:57:36 +00:00
|
|
|
|
void WebContents::DoGetZoomLevel(
|
2022-03-19 02:50:05 +00:00
|
|
|
|
electron::mojom::ElectronWebContentsUtility::DoGetZoomLevelCallback
|
|
|
|
|
callback) {
|
2019-06-04 01:18:23 +00:00
|
|
|
|
std::move(callback).Run(GetZoomLevel());
|
2016-09-01 17:25:12 +00:00
|
|
|
|
}
|
2016-08-03 03:29:55 +00:00
|
|
|
|
|
2020-11-10 17:06:03 +00:00
|
|
|
|
std::vector<base::FilePath> WebContents::GetPreloadPaths() const {
|
2019-07-03 15:05:45 +00:00
|
|
|
|
auto result = SessionPreferences::GetValidPreloads(GetBrowserContext());
|
|
|
|
|
|
2018-08-10 22:19:49 +00:00
|
|
|
|
if (auto* web_preferences = WebContentsPreferences::From(web_contents())) {
|
2020-11-10 17:06:03 +00:00
|
|
|
|
base::FilePath preload;
|
2018-08-10 22:19:49 +00:00
|
|
|
|
if (web_preferences->GetPreloadPath(&preload)) {
|
2019-07-03 15:05:45 +00:00
|
|
|
|
result.emplace_back(preload);
|
2018-08-10 22:19:49 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-07-03 15:05:45 +00:00
|
|
|
|
|
|
|
|
|
return result;
|
2018-08-10 22:19:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-08-09 17:15:23 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::GetLastWebPreferences(
|
|
|
|
|
v8::Isolate* isolate) const {
|
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
2018-03-15 04:56:46 +00:00
|
|
|
|
if (!web_preferences)
|
|
|
|
|
return v8::Null(isolate);
|
2019-10-25 13:03:28 +00:00
|
|
|
|
return gin::ConvertToV8(isolate, *web_preferences->last_preference());
|
2018-03-15 04:56:46 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::GetOwnerBrowserWindow(
|
|
|
|
|
v8::Isolate* isolate) const {
|
2015-10-01 05:45:59 +00:00
|
|
|
|
if (owner_window())
|
2020-07-16 21:11:44 +00:00
|
|
|
|
return BrowserWindow::From(isolate, owner_window());
|
2015-10-01 05:45:59 +00:00
|
|
|
|
else
|
2020-07-16 21:11:44 +00:00
|
|
|
|
return v8::Null(isolate);
|
2015-10-01 05:45:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::Session(v8::Isolate* isolate) {
|
|
|
|
|
return v8::Local<v8::Value>::New(isolate, session_);
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-19 20:13:24 +00:00
|
|
|
|
content::WebContents* WebContents::HostWebContents() const {
|
2016-02-17 08:52:19 +00:00
|
|
|
|
if (!embedder_)
|
|
|
|
|
return nullptr;
|
|
|
|
|
return embedder_->web_contents();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-08 17:01:01 +00:00
|
|
|
|
void WebContents::SetEmbedder(const WebContents* embedder) {
|
|
|
|
|
if (embedder) {
|
|
|
|
|
NativeWindow* owner_window = nullptr;
|
2018-04-17 22:41:47 +00:00
|
|
|
|
auto* relay = NativeWindowRelay::FromWebContents(embedder->web_contents());
|
2016-09-08 17:01:01 +00:00
|
|
|
|
if (relay) {
|
2018-10-02 22:14:43 +00:00
|
|
|
|
owner_window = relay->GetNativeWindow();
|
2016-09-08 17:01:01 +00:00
|
|
|
|
}
|
|
|
|
|
if (owner_window)
|
|
|
|
|
SetOwnerWindow(owner_window);
|
|
|
|
|
|
|
|
|
|
content::RenderWidgetHostView* rwhv =
|
|
|
|
|
web_contents()->GetRenderWidgetHostView();
|
|
|
|
|
if (rwhv) {
|
|
|
|
|
rwhv->Hide();
|
|
|
|
|
rwhv->Show();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-30 07:37:26 +00:00
|
|
|
|
void WebContents::SetDevToolsWebContents(const WebContents* devtools) {
|
2020-11-17 22:15:20 +00:00
|
|
|
|
if (inspectable_web_contents_)
|
|
|
|
|
inspectable_web_contents_->SetDevToolsWebContents(devtools->web_contents());
|
2017-11-30 07:37:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::GetNativeView(v8::Isolate* isolate) const {
|
2017-08-21 10:50:12 +00:00
|
|
|
|
gfx::NativeView ptr = web_contents()->GetNativeView();
|
2020-07-16 21:11:44 +00:00
|
|
|
|
auto buffer = node::Buffer::Copy(isolate, reinterpret_cast<char*>(&ptr),
|
2018-04-18 01:55:30 +00:00
|
|
|
|
sizeof(gfx::NativeView));
|
2017-08-21 10:50:12 +00:00
|
|
|
|
if (buffer.IsEmpty())
|
2020-07-16 21:11:44 +00:00
|
|
|
|
return v8::Null(isolate);
|
2017-08-21 10:50:12 +00:00
|
|
|
|
else
|
|
|
|
|
return buffer.ToLocalChecked();
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-01 03:14:19 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::DevToolsWebContents(v8::Isolate* isolate) {
|
|
|
|
|
if (devtools_web_contents_.IsEmpty())
|
|
|
|
|
return v8::Null(isolate);
|
|
|
|
|
else
|
|
|
|
|
return v8::Local<v8::Value>::New(isolate, devtools_web_contents_);
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-21 18:22:23 +00:00
|
|
|
|
v8::Local<v8::Value> WebContents::Debugger(v8::Isolate* isolate) {
|
|
|
|
|
if (debugger_.IsEmpty()) {
|
|
|
|
|
auto handle = electron::api::Debugger::Create(isolate, web_contents());
|
|
|
|
|
debugger_.Reset(isolate, handle.ToV8());
|
|
|
|
|
}
|
|
|
|
|
return v8::Local<v8::Value>::New(isolate, debugger_);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-09 16:50:46 +00:00
|
|
|
|
content::RenderFrameHost* WebContents::MainFrame() {
|
|
|
|
|
return web_contents()->GetMainFrame();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-26 13:21:38 +00:00
|
|
|
|
void WebContents::NotifyUserActivation() {
|
2021-02-09 20:16:21 +00:00
|
|
|
|
content::RenderFrameHost* frame = web_contents()->GetMainFrame();
|
|
|
|
|
if (frame)
|
|
|
|
|
frame->NotifyUserActivation(
|
|
|
|
|
blink::mojom::UserActivationNotificationType::kInteraction);
|
2020-05-26 13:21:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-06-08 02:00:22 +00:00
|
|
|
|
void WebContents::SetImageAnimationPolicy(const std::string& new_policy) {
|
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(web_contents());
|
2021-07-26 16:04:09 +00:00
|
|
|
|
web_preferences->SetImageAnimationPolicy(new_policy);
|
2021-06-08 02:00:22 +00:00
|
|
|
|
web_contents()->OnWebPreferencesChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-05 22:30:31 +00:00
|
|
|
|
v8::Local<v8::Promise> WebContents::GetProcessMemoryInfo(v8::Isolate* isolate) {
|
|
|
|
|
gin_helper::Promise<gin_helper::Dictionary> promise(isolate);
|
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
|
|
|
|
|
|
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
|
|
|
|
if (!frame_host) {
|
|
|
|
|
promise.RejectWithErrorMessage("Failed to create memory dump");
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto pid = frame_host->GetProcess()->GetProcess().Pid();
|
|
|
|
|
v8::Global<v8::Context> context(isolate, isolate->GetCurrentContext());
|
|
|
|
|
memory_instrumentation::MemoryInstrumentation::GetInstance()
|
|
|
|
|
->RequestGlobalDumpForPid(
|
|
|
|
|
pid, std::vector<std::string>(),
|
|
|
|
|
base::BindOnce(&ElectronBindings::DidReceiveMemoryDump,
|
|
|
|
|
std::move(context), std::move(promise), pid));
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-29 17:11:11 +00:00
|
|
|
|
v8::Local<v8::Promise> WebContents::TakeHeapSnapshot(
|
2020-07-16 21:11:44 +00:00
|
|
|
|
v8::Isolate* isolate,
|
2019-04-29 17:11:11 +00:00
|
|
|
|
const base::FilePath& file_path) {
|
2020-07-16 21:11:44 +00:00
|
|
|
|
gin_helper::Promise<void> promise(isolate);
|
2019-04-29 17:11:11 +00:00
|
|
|
|
v8::Local<v8::Promise> handle = promise.GetHandle();
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
2019-04-29 17:11:11 +00:00
|
|
|
|
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
2018-09-18 18:00:31 +00:00
|
|
|
|
base::File file(file_path,
|
|
|
|
|
base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE);
|
2019-04-02 22:38:16 +00:00
|
|
|
|
if (!file.IsValid()) {
|
2019-04-29 17:11:11 +00:00
|
|
|
|
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
|
|
|
|
|
return handle;
|
2019-04-02 22:38:16 +00:00
|
|
|
|
}
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
|
|
|
|
auto* frame_host = web_contents()->GetMainFrame();
|
2019-04-02 22:38:16 +00:00
|
|
|
|
if (!frame_host) {
|
2019-04-29 17:11:11 +00:00
|
|
|
|
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
|
|
|
|
|
return handle;
|
2019-04-02 22:38:16 +00:00
|
|
|
|
}
|
2018-09-18 18:00:31 +00:00
|
|
|
|
|
2021-02-09 20:16:21 +00:00
|
|
|
|
if (!frame_host->IsRenderFrameCreated()) {
|
|
|
|
|
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
|
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-02 22:38:16 +00:00
|
|
|
|
// This dance with `base::Owned` is to ensure that the interface stays alive
|
|
|
|
|
// until the callback is called. Otherwise it would be closed at the end of
|
|
|
|
|
// this function.
|
2019-10-28 22:12:35 +00:00
|
|
|
|
auto electron_renderer =
|
2021-02-09 20:16:21 +00:00
|
|
|
|
std::make_unique<mojo::Remote<mojom::ElectronRenderer>>();
|
|
|
|
|
frame_host->GetRemoteInterfaces()->GetInterface(
|
|
|
|
|
electron_renderer->BindNewPipeAndPassReceiver());
|
2019-10-28 22:12:35 +00:00
|
|
|
|
auto* raw_ptr = electron_renderer.get();
|
2019-04-02 22:38:16 +00:00
|
|
|
|
(*raw_ptr)->TakeHeapSnapshot(
|
2020-10-28 00:33:04 +00:00
|
|
|
|
mojo::WrapPlatformFile(base::ScopedPlatformFile(file.TakePlatformFile())),
|
2019-04-29 17:11:11 +00:00
|
|
|
|
base::BindOnce(
|
2021-02-09 20:16:21 +00:00
|
|
|
|
[](mojo::Remote<mojom::ElectronRenderer>* ep,
|
2019-11-01 06:10:32 +00:00
|
|
|
|
gin_helper::Promise<void> promise, bool success) {
|
2019-04-29 17:11:11 +00:00
|
|
|
|
if (success) {
|
|
|
|
|
promise.Resolve();
|
|
|
|
|
} else {
|
|
|
|
|
promise.RejectWithErrorMessage("takeHeapSnapshot failed");
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-10-28 22:12:35 +00:00
|
|
|
|
base::Owned(std::move(electron_renderer)), std::move(promise)));
|
2019-04-29 17:11:11 +00:00
|
|
|
|
return handle;
|
2018-09-18 18:00:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-09-23 11:00:11 +00:00
|
|
|
|
void WebContents::GrantDevicePermission(
|
|
|
|
|
const url::Origin& origin,
|
|
|
|
|
const base::Value* device,
|
|
|
|
|
content::PermissionType permissionType,
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
granted_devices_[render_frame_host->GetFrameTreeNodeId()][permissionType]
|
|
|
|
|
[origin]
|
|
|
|
|
.push_back(
|
|
|
|
|
std::make_unique<base::Value>(device->Clone()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<base::Value> WebContents::GetGrantedDevices(
|
|
|
|
|
const url::Origin& origin,
|
|
|
|
|
content::PermissionType permissionType,
|
|
|
|
|
content::RenderFrameHost* render_frame_host) {
|
|
|
|
|
const auto& devices_for_frame_host_it =
|
|
|
|
|
granted_devices_.find(render_frame_host->GetFrameTreeNodeId());
|
|
|
|
|
if (devices_for_frame_host_it == granted_devices_.end())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
const auto& current_devices_it =
|
|
|
|
|
devices_for_frame_host_it->second.find(permissionType);
|
|
|
|
|
if (current_devices_it == devices_for_frame_host_it->second.end())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
const auto& origin_devices_it = current_devices_it->second.find(origin);
|
|
|
|
|
if (origin_devices_it == current_devices_it->second.end())
|
|
|
|
|
return {};
|
|
|
|
|
|
|
|
|
|
std::vector<base::Value> results;
|
|
|
|
|
for (const auto& object : origin_devices_it->second)
|
|
|
|
|
results.push_back(object->Clone());
|
|
|
|
|
|
|
|
|
|
return results;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-21 22:44:19 +00:00
|
|
|
|
void WebContents::UpdatePreferredSize(content::WebContents* web_contents,
|
|
|
|
|
const gfx::Size& pref_size) {
|
|
|
|
|
Emit("preferred-size-changed", pref_size);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
bool WebContents::CanOverscrollContent() {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-21 21:02:29 +00:00
|
|
|
|
std::unique_ptr<content::EyeDropper> WebContents::OpenEyeDropper(
|
|
|
|
|
content::RenderFrameHost* frame,
|
|
|
|
|
content::EyeDropperListener* listener) {
|
|
|
|
|
return ShowEyeDropper(frame, listener);
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-10 17:06:56 +00:00
|
|
|
|
void WebContents::RunFileChooser(
|
|
|
|
|
content::RenderFrameHost* render_frame_host,
|
|
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
|
|
|
|
const blink::mojom::FileChooserParams& params) {
|
2021-09-14 10:16:34 +00:00
|
|
|
|
FileSelectHelper::RunFileChooser(render_frame_host, std::move(listener),
|
|
|
|
|
params);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::EnumerateDirectory(
|
2021-09-14 10:16:34 +00:00
|
|
|
|
content::WebContents* web_contents,
|
2020-11-10 17:06:56 +00:00
|
|
|
|
scoped_refptr<content::FileSelectListener> listener,
|
|
|
|
|
const base::FilePath& path) {
|
2021-09-14 10:16:34 +00:00
|
|
|
|
FileSelectHelper::EnumerateDirectory(web_contents, std::move(listener), path);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::IsFullscreenForTabOrPending(
|
|
|
|
|
const content::WebContents* source) {
|
|
|
|
|
return html_fullscreen_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool WebContents::TakeFocus(content::WebContents* source, bool reverse) {
|
|
|
|
|
if (source && source->GetOutermostWebContents() == source) {
|
|
|
|
|
// If this is the outermost web contents and the user has tabbed or
|
|
|
|
|
// shift + tabbed through all the elements, reset the focus back to
|
|
|
|
|
// the first or last element so that it doesn't stay in the body.
|
|
|
|
|
source->FocusThroughTabTraversal(reverse);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
content::PictureInPictureResult WebContents::EnterPictureInPicture(
|
2022-02-25 18:17:35 +00:00
|
|
|
|
content::WebContents* web_contents) {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PICTURE_IN_PICTURE)
|
2022-02-25 18:17:35 +00:00
|
|
|
|
return PictureInPictureWindowManager::GetInstance()
|
|
|
|
|
->EnterVideoPictureInPicture(web_contents);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
#else
|
|
|
|
|
return content::PictureInPictureResult::kNotSupported;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::ExitPictureInPicture() {
|
|
|
|
|
#if BUILDFLAG(ENABLE_PICTURE_IN_PICTURE)
|
|
|
|
|
PictureInPictureWindowManager::GetInstance()->ExitPictureInPicture();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsSaveToFile(const std::string& url,
|
|
|
|
|
const std::string& content,
|
|
|
|
|
bool save_as) {
|
|
|
|
|
base::FilePath path;
|
|
|
|
|
auto it = saved_files_.find(url);
|
|
|
|
|
if (it != saved_files_.end() && !save_as) {
|
|
|
|
|
path = it->second;
|
|
|
|
|
} else {
|
|
|
|
|
file_dialog::DialogSettings settings;
|
|
|
|
|
settings.parent_window = owner_window();
|
|
|
|
|
settings.force_detached = offscreen_;
|
|
|
|
|
settings.title = url;
|
|
|
|
|
settings.default_path = base::FilePath::FromUTF8Unsafe(url);
|
|
|
|
|
if (!file_dialog::ShowSaveDialogSync(settings, &path)) {
|
|
|
|
|
base::Value url_value(url);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.canceledSaveURL", &url_value, nullptr, nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
saved_files_[url] = path;
|
|
|
|
|
// Notify DevTools.
|
|
|
|
|
base::Value url_value(url);
|
|
|
|
|
base::Value file_system_path_value(path.AsUTF8Unsafe());
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.savedURL", &url_value, &file_system_path_value, nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_task_runner_->PostTask(FROM_HERE,
|
|
|
|
|
base::BindOnce(&WriteToFile, path, content));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsAppendToFile(const std::string& url,
|
|
|
|
|
const std::string& content) {
|
|
|
|
|
auto it = saved_files_.find(url);
|
|
|
|
|
if (it == saved_files_.end())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
// Notify DevTools.
|
|
|
|
|
base::Value url_value(url);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction("DevToolsAPI.appendedToURL",
|
|
|
|
|
&url_value, nullptr, nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
file_task_runner_->PostTask(
|
|
|
|
|
FROM_HERE, base::BindOnce(&AppendToFile, it->second, content));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsRequestFileSystems() {
|
|
|
|
|
auto file_system_paths = GetAddedFileSystemPaths(GetDevToolsWebContents());
|
|
|
|
|
if (file_system_paths.empty()) {
|
|
|
|
|
base::ListValue empty_file_system_value;
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.fileSystemsLoaded", &empty_file_system_value, nullptr,
|
|
|
|
|
nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<FileSystem> file_systems;
|
|
|
|
|
for (const auto& file_system_path : file_system_paths) {
|
|
|
|
|
base::FilePath path =
|
|
|
|
|
base::FilePath::FromUTF8Unsafe(file_system_path.first);
|
|
|
|
|
std::string file_system_id =
|
|
|
|
|
RegisterFileSystem(GetDevToolsWebContents(), path);
|
|
|
|
|
FileSystem file_system =
|
|
|
|
|
CreateFileSystemStruct(GetDevToolsWebContents(), file_system_id,
|
|
|
|
|
file_system_path.first, file_system_path.second);
|
|
|
|
|
file_systems.push_back(file_system);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base::ListValue file_system_value;
|
|
|
|
|
for (const auto& file_system : file_systems)
|
|
|
|
|
file_system_value.Append(CreateFileSystemValue(file_system));
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.fileSystemsLoaded", &file_system_value, nullptr, nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsAddFileSystem(
|
|
|
|
|
const std::string& type,
|
|
|
|
|
const base::FilePath& file_system_path) {
|
|
|
|
|
base::FilePath path = file_system_path;
|
|
|
|
|
if (path.empty()) {
|
|
|
|
|
std::vector<base::FilePath> paths;
|
|
|
|
|
file_dialog::DialogSettings settings;
|
|
|
|
|
settings.parent_window = owner_window();
|
|
|
|
|
settings.force_detached = offscreen_;
|
|
|
|
|
settings.properties = file_dialog::OPEN_DIALOG_OPEN_DIRECTORY;
|
|
|
|
|
if (!file_dialog::ShowOpenDialogSync(settings, &paths))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
path = paths[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string file_system_id =
|
|
|
|
|
RegisterFileSystem(GetDevToolsWebContents(), path);
|
|
|
|
|
if (IsDevToolsFileSystemAdded(GetDevToolsWebContents(), path.AsUTF8Unsafe()))
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
FileSystem file_system = CreateFileSystemStruct(
|
|
|
|
|
GetDevToolsWebContents(), file_system_id, path.AsUTF8Unsafe(), type);
|
|
|
|
|
std::unique_ptr<base::DictionaryValue> file_system_value(
|
|
|
|
|
CreateFileSystemValue(file_system));
|
|
|
|
|
|
|
|
|
|
auto* pref_service = GetPrefService(GetDevToolsWebContents());
|
|
|
|
|
DictionaryPrefUpdate update(pref_service, prefs::kDevToolsFileSystemPaths);
|
2022-02-10 02:58:52 +00:00
|
|
|
|
update.Get()->SetKey(path.AsUTF8Unsafe(), base::Value(type));
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.fileSystemAdded", nullptr, file_system_value.get(), nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsRemoveFileSystem(
|
|
|
|
|
const base::FilePath& file_system_path) {
|
2020-11-17 22:15:20 +00:00
|
|
|
|
if (!inspectable_web_contents_)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
std::string path = file_system_path.AsUTF8Unsafe();
|
|
|
|
|
storage::IsolatedContext::GetInstance()->RevokeFileSystemByPath(
|
|
|
|
|
file_system_path);
|
|
|
|
|
|
|
|
|
|
auto* pref_service = GetPrefService(GetDevToolsWebContents());
|
|
|
|
|
DictionaryPrefUpdate update(pref_service, prefs::kDevToolsFileSystemPaths);
|
2021-08-24 00:52:17 +00:00
|
|
|
|
update.Get()->RemoveKey(path);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
|
|
|
|
|
base::Value file_system_path_value(path);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction("DevToolsAPI.fileSystemRemoved",
|
|
|
|
|
&file_system_path_value,
|
|
|
|
|
nullptr, nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsIndexPath(
|
|
|
|
|
int request_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
const std::string& excluded_folders_message) {
|
|
|
|
|
if (!IsDevToolsFileSystemAdded(GetDevToolsWebContents(), file_system_path)) {
|
|
|
|
|
OnDevToolsIndexingDone(request_id, file_system_path);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (devtools_indexing_jobs_.count(request_id) != 0)
|
|
|
|
|
return;
|
|
|
|
|
std::vector<std::string> excluded_folders;
|
|
|
|
|
std::unique_ptr<base::Value> parsed_excluded_folders =
|
|
|
|
|
base::JSONReader::ReadDeprecated(excluded_folders_message);
|
|
|
|
|
if (parsed_excluded_folders && parsed_excluded_folders->is_list()) {
|
2022-02-25 18:17:35 +00:00
|
|
|
|
for (const base::Value& folder_path :
|
|
|
|
|
parsed_excluded_folders->GetListDeprecated()) {
|
2020-11-10 17:06:56 +00:00
|
|
|
|
if (folder_path.is_string())
|
|
|
|
|
excluded_folders.push_back(folder_path.GetString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
devtools_indexing_jobs_[request_id] =
|
|
|
|
|
scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>(
|
|
|
|
|
devtools_file_system_indexer_->IndexPath(
|
|
|
|
|
file_system_path, excluded_folders,
|
|
|
|
|
base::BindRepeating(
|
|
|
|
|
&WebContents::OnDevToolsIndexingWorkCalculated,
|
|
|
|
|
weak_factory_.GetWeakPtr(), request_id, file_system_path),
|
|
|
|
|
base::BindRepeating(&WebContents::OnDevToolsIndexingWorked,
|
|
|
|
|
weak_factory_.GetWeakPtr(), request_id,
|
|
|
|
|
file_system_path),
|
|
|
|
|
base::BindRepeating(&WebContents::OnDevToolsIndexingDone,
|
|
|
|
|
weak_factory_.GetWeakPtr(), request_id,
|
|
|
|
|
file_system_path)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsStopIndexing(int request_id) {
|
|
|
|
|
auto it = devtools_indexing_jobs_.find(request_id);
|
|
|
|
|
if (it == devtools_indexing_jobs_.end())
|
|
|
|
|
return;
|
|
|
|
|
it->second->Stop();
|
|
|
|
|
devtools_indexing_jobs_.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::DevToolsSearchInPath(int request_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
const std::string& query) {
|
|
|
|
|
if (!IsDevToolsFileSystemAdded(GetDevToolsWebContents(), file_system_path)) {
|
|
|
|
|
OnDevToolsSearchCompleted(request_id, file_system_path,
|
|
|
|
|
std::vector<std::string>());
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
devtools_file_system_indexer_->SearchInPath(
|
|
|
|
|
file_system_path, query,
|
|
|
|
|
base::BindRepeating(&WebContents::OnDevToolsSearchCompleted,
|
|
|
|
|
weak_factory_.GetWeakPtr(), request_id,
|
|
|
|
|
file_system_path));
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-17 13:42:51 +00:00
|
|
|
|
void WebContents::DevToolsSetEyeDropperActive(bool active) {
|
|
|
|
|
auto* web_contents = GetWebContents();
|
|
|
|
|
if (!web_contents)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (active) {
|
|
|
|
|
eye_dropper_ = std::make_unique<DevToolsEyeDropper>(
|
|
|
|
|
web_contents, base::BindRepeating(&WebContents::ColorPickedInEyeDropper,
|
|
|
|
|
base::Unretained(this)));
|
|
|
|
|
} else {
|
|
|
|
|
eye_dropper_.reset();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::ColorPickedInEyeDropper(int r, int g, int b, int a) {
|
|
|
|
|
base::DictionaryValue color;
|
|
|
|
|
color.SetInteger("r", r);
|
|
|
|
|
color.SetInteger("g", g);
|
|
|
|
|
color.SetInteger("b", b);
|
|
|
|
|
color.SetInteger("a", a);
|
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.eyeDropperPickedColor", &color, nullptr, nullptr);
|
|
|
|
|
}
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if defined(TOOLKIT_VIEWS) && !BUILDFLAG(IS_MAC)
|
2021-06-08 20:22:43 +00:00
|
|
|
|
ui::ImageModel WebContents::GetDevToolsWindowIcon() {
|
|
|
|
|
return owner_window() ? owner_window()->GetWindowAppIcon() : ui::ImageModel{};
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
|
#if BUILDFLAG(IS_LINUX)
|
2020-11-10 17:06:56 +00:00
|
|
|
|
void WebContents::GetDevToolsWindowWMClass(std::string* name,
|
|
|
|
|
std::string* class_name) {
|
|
|
|
|
*class_name = Browser::Get()->GetName();
|
|
|
|
|
*name = base::ToLowerASCII(*class_name);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void WebContents::OnDevToolsIndexingWorkCalculated(
|
|
|
|
|
int request_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
int total_work) {
|
|
|
|
|
base::Value request_id_value(request_id);
|
|
|
|
|
base::Value file_system_path_value(file_system_path);
|
|
|
|
|
base::Value total_work_value(total_work);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.indexingTotalWorkCalculated", &request_id_value,
|
|
|
|
|
&file_system_path_value, &total_work_value);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::OnDevToolsIndexingWorked(int request_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
int worked) {
|
|
|
|
|
base::Value request_id_value(request_id);
|
|
|
|
|
base::Value file_system_path_value(file_system_path);
|
|
|
|
|
base::Value worked_value(worked);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.indexingWorked", &request_id_value, &file_system_path_value,
|
|
|
|
|
&worked_value);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::OnDevToolsIndexingDone(int request_id,
|
|
|
|
|
const std::string& file_system_path) {
|
|
|
|
|
devtools_indexing_jobs_.erase(request_id);
|
|
|
|
|
base::Value request_id_value(request_id);
|
|
|
|
|
base::Value file_system_path_value(file_system_path);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.indexingDone", &request_id_value, &file_system_path_value,
|
|
|
|
|
nullptr);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::OnDevToolsSearchCompleted(
|
|
|
|
|
int request_id,
|
|
|
|
|
const std::string& file_system_path,
|
|
|
|
|
const std::vector<std::string>& file_paths) {
|
|
|
|
|
base::ListValue file_paths_value;
|
|
|
|
|
for (const auto& file_path : file_paths) {
|
2021-10-06 02:21:00 +00:00
|
|
|
|
file_paths_value.Append(file_path);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
base::Value request_id_value(request_id);
|
|
|
|
|
base::Value file_system_path_value(file_system_path);
|
2020-11-17 22:15:20 +00:00
|
|
|
|
inspectable_web_contents_->CallClientFunction(
|
|
|
|
|
"DevToolsAPI.searchCompleted", &request_id_value, &file_system_path_value,
|
|
|
|
|
&file_paths_value);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void WebContents::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
|
|
|
|
// Window is already in fullscreen mode, save the state.
|
|
|
|
|
if (enter_fullscreen && owner_window_->IsFullscreen()) {
|
|
|
|
|
native_fullscreen_ = true;
|
2021-07-02 00:56:29 +00:00
|
|
|
|
UpdateHtmlApiFullscreen(true);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Exit html fullscreen state but not window's fullscreen mode.
|
|
|
|
|
if (!enter_fullscreen && native_fullscreen_) {
|
2021-07-02 00:56:29 +00:00
|
|
|
|
UpdateHtmlApiFullscreen(false);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Set fullscreen on window if allowed.
|
|
|
|
|
auto* web_preferences = WebContentsPreferences::From(GetWebContents());
|
|
|
|
|
bool html_fullscreenable =
|
2021-07-26 16:04:09 +00:00
|
|
|
|
web_preferences
|
|
|
|
|
? !web_preferences->ShouldDisableHtmlFullscreenWindowResize()
|
|
|
|
|
: true;
|
2020-11-10 17:06:56 +00:00
|
|
|
|
|
|
|
|
|
if (html_fullscreenable) {
|
|
|
|
|
owner_window_->SetFullScreen(enter_fullscreen);
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 00:56:29 +00:00
|
|
|
|
UpdateHtmlApiFullscreen(enter_fullscreen);
|
2020-11-10 17:06:56 +00:00
|
|
|
|
native_fullscreen_ = false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 00:56:29 +00:00
|
|
|
|
void WebContents::UpdateHtmlApiFullscreen(bool fullscreen) {
|
2021-08-17 07:03:45 +00:00
|
|
|
|
if (fullscreen == is_html_fullscreen())
|
2021-07-02 00:56:29 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
html_fullscreen_ = fullscreen;
|
|
|
|
|
|
|
|
|
|
// Notify renderer of the html fullscreen change.
|
|
|
|
|
web_contents()
|
|
|
|
|
->GetRenderViewHost()
|
|
|
|
|
->GetWidget()
|
|
|
|
|
->SynchronizeVisualProperties();
|
|
|
|
|
|
2021-08-17 07:03:45 +00:00
|
|
|
|
// The embedder WebContents is separated from the frame tree of webview, so
|
2021-07-02 00:56:29 +00:00
|
|
|
|
// we must manually sync their fullscreen states.
|
|
|
|
|
if (embedder_)
|
|
|
|
|
embedder_->SetHtmlApiFullscreen(fullscreen);
|
|
|
|
|
|
2021-08-17 07:03:45 +00:00
|
|
|
|
if (fullscreen) {
|
|
|
|
|
Emit("enter-html-full-screen");
|
|
|
|
|
owner_window_->NotifyWindowEnterHtmlFullScreen();
|
|
|
|
|
} else {
|
|
|
|
|
Emit("leave-html-full-screen");
|
|
|
|
|
owner_window_->NotifyWindowLeaveHtmlFullScreen();
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-02 00:56:29 +00:00
|
|
|
|
// Make sure all child webviews quit html fullscreen.
|
|
|
|
|
if (!fullscreen && !IsGuest()) {
|
|
|
|
|
auto* manager = WebViewManager::GetWebViewManager(web_contents());
|
|
|
|
|
manager->ForEachGuest(
|
|
|
|
|
web_contents(), base::BindRepeating([](content::WebContents* guest) {
|
|
|
|
|
WebContents* api_web_contents = WebContents::From(guest);
|
2021-07-14 11:51:26 +00:00
|
|
|
|
api_web_contents->SetHtmlApiFullscreen(false);
|
2021-07-02 00:56:29 +00:00
|
|
|
|
return false;
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-03 08:04:46 +00:00
|
|
|
|
// static
|
2020-07-30 16:17:57 +00:00
|
|
|
|
v8::Local<v8::ObjectTemplate> WebContents::FillObjectTemplate(
|
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
v8::Local<v8::ObjectTemplate> templ) {
|
|
|
|
|
gin::InvokerOptions options;
|
|
|
|
|
options.holder_is_first_argument = true;
|
|
|
|
|
options.holder_type = "WebContents";
|
|
|
|
|
templ->Set(
|
|
|
|
|
gin::StringToSymbol(isolate, "isDestroyed"),
|
|
|
|
|
gin::CreateFunctionTemplate(
|
|
|
|
|
isolate, base::BindRepeating(&gin_helper::Destroyable::IsDestroyed),
|
|
|
|
|
options));
|
|
|
|
|
// We use gin_helper::ObjectTemplateBuilder instead of
|
|
|
|
|
// gin::ObjectTemplateBuilder here to handle the fact that WebContents is
|
|
|
|
|
// destroyable.
|
|
|
|
|
return gin_helper::ObjectTemplateBuilder(isolate, templ)
|
2021-03-15 22:43:25 +00:00
|
|
|
|
.SetMethod("destroy", &WebContents::Destroy)
|
2020-05-14 13:11:45 +00:00
|
|
|
|
.SetMethod("getBackgroundThrottling",
|
|
|
|
|
&WebContents::GetBackgroundThrottling)
|
2018-10-19 00:32:22 +00:00
|
|
|
|
.SetMethod("setBackgroundThrottling",
|
|
|
|
|
&WebContents::SetBackgroundThrottling)
|
2016-09-06 01:28:40 +00:00
|
|
|
|
.SetMethod("getProcessId", &WebContents::GetProcessID)
|
2017-04-18 10:31:20 +00:00
|
|
|
|
.SetMethod("getOSProcessId", &WebContents::GetOSProcessID)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("equal", &WebContents::Equal)
|
|
|
|
|
.SetMethod("_loadURL", &WebContents::LoadURL)
|
2021-04-27 23:11:18 +00:00
|
|
|
|
.SetMethod("reload", &WebContents::Reload)
|
|
|
|
|
.SetMethod("reloadIgnoringCache", &WebContents::ReloadIgnoringCache)
|
2015-12-03 18:31:51 +00:00
|
|
|
|
.SetMethod("downloadURL", &WebContents::DownloadURL)
|
2021-04-27 23:11:18 +00:00
|
|
|
|
.SetMethod("getURL", &WebContents::GetURL)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("getTitle", &WebContents::GetTitle)
|
|
|
|
|
.SetMethod("isLoading", &WebContents::IsLoading)
|
2016-04-18 17:37:08 +00:00
|
|
|
|
.SetMethod("isLoadingMainFrame", &WebContents::IsLoadingMainFrame)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("isWaitingForResponse", &WebContents::IsWaitingForResponse)
|
2021-04-27 23:11:18 +00:00
|
|
|
|
.SetMethod("stop", &WebContents::Stop)
|
|
|
|
|
.SetMethod("canGoBack", &WebContents::CanGoBack)
|
|
|
|
|
.SetMethod("goBack", &WebContents::GoBack)
|
|
|
|
|
.SetMethod("canGoForward", &WebContents::CanGoForward)
|
|
|
|
|
.SetMethod("goForward", &WebContents::GoForward)
|
|
|
|
|
.SetMethod("canGoToOffset", &WebContents::CanGoToOffset)
|
|
|
|
|
.SetMethod("goToOffset", &WebContents::GoToOffset)
|
|
|
|
|
.SetMethod("canGoToIndex", &WebContents::CanGoToIndex)
|
|
|
|
|
.SetMethod("goToIndex", &WebContents::GoToIndex)
|
|
|
|
|
.SetMethod("getActiveIndex", &WebContents::GetActiveIndex)
|
|
|
|
|
.SetMethod("clearHistory", &WebContents::ClearHistory)
|
|
|
|
|
.SetMethod("length", &WebContents::GetHistoryLength)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("isCrashed", &WebContents::IsCrashed)
|
2020-10-02 21:50:24 +00:00
|
|
|
|
.SetMethod("forcefullyCrashRenderer",
|
|
|
|
|
&WebContents::ForcefullyCrashRenderer)
|
2020-03-13 17:16:08 +00:00
|
|
|
|
.SetMethod("setUserAgent", &WebContents::SetUserAgent)
|
|
|
|
|
.SetMethod("getUserAgent", &WebContents::GetUserAgent)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("savePage", &WebContents::SavePage)
|
|
|
|
|
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
|
|
|
|
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
|
|
|
|
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
2016-01-01 05:11:21 +00:00
|
|
|
|
.SetMethod("isDevToolsFocused", &WebContents::IsDevToolsFocused)
|
2017-06-25 19:01:05 +00:00
|
|
|
|
.SetMethod("enableDeviceEmulation", &WebContents::EnableDeviceEmulation)
|
|
|
|
|
.SetMethod("disableDeviceEmulation", &WebContents::DisableDeviceEmulation)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
|
|
|
|
.SetMethod("inspectElement", &WebContents::InspectElement)
|
2018-04-18 01:55:30 +00:00
|
|
|
|
.SetMethod("setIgnoreMenuShortcuts", &WebContents::SetIgnoreMenuShortcuts)
|
2020-03-13 17:16:08 +00:00
|
|
|
|
.SetMethod("setAudioMuted", &WebContents::SetAudioMuted)
|
|
|
|
|
.SetMethod("isAudioMuted", &WebContents::IsAudioMuted)
|
2018-07-12 11:35:11 +00:00
|
|
|
|
.SetMethod("isCurrentlyAudible", &WebContents::IsCurrentlyAudible)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("undo", &WebContents::Undo)
|
|
|
|
|
.SetMethod("redo", &WebContents::Redo)
|
|
|
|
|
.SetMethod("cut", &WebContents::Cut)
|
|
|
|
|
.SetMethod("copy", &WebContents::Copy)
|
|
|
|
|
.SetMethod("paste", &WebContents::Paste)
|
|
|
|
|
.SetMethod("pasteAndMatchStyle", &WebContents::PasteAndMatchStyle)
|
|
|
|
|
.SetMethod("delete", &WebContents::Delete)
|
|
|
|
|
.SetMethod("selectAll", &WebContents::SelectAll)
|
|
|
|
|
.SetMethod("unselect", &WebContents::Unselect)
|
|
|
|
|
.SetMethod("replace", &WebContents::Replace)
|
|
|
|
|
.SetMethod("replaceMisspelling", &WebContents::ReplaceMisspelling)
|
2015-12-17 17:27:56 +00:00
|
|
|
|
.SetMethod("findInPage", &WebContents::FindInPage)
|
|
|
|
|
.SetMethod("stopFindInPage", &WebContents::StopFindInPage)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("focus", &WebContents::Focus)
|
2016-08-03 03:29:55 +00:00
|
|
|
|
.SetMethod("isFocused", &WebContents::IsFocused)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("sendInputEvent", &WebContents::SendInputEvent)
|
2017-06-25 19:01:05 +00:00
|
|
|
|
.SetMethod("beginFrameSubscription", &WebContents::BeginFrameSubscription)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("endFrameSubscription", &WebContents::EndFrameSubscription)
|
2016-07-03 03:26:43 +00:00
|
|
|
|
.SetMethod("startDrag", &WebContents::StartDrag)
|
2018-08-16 22:57:40 +00:00
|
|
|
|
.SetMethod("attachToIframe", &WebContents::AttachToIframe)
|
2019-01-12 06:50:33 +00:00
|
|
|
|
.SetMethod("detachFromOuterFrame", &WebContents::DetachFromOuterFrame)
|
2016-08-03 03:29:55 +00:00
|
|
|
|
.SetMethod("isOffscreen", &WebContents::IsOffScreen)
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_OSR)
|
2016-08-03 03:29:55 +00:00
|
|
|
|
.SetMethod("startPainting", &WebContents::StartPainting)
|
|
|
|
|
.SetMethod("stopPainting", &WebContents::StopPainting)
|
|
|
|
|
.SetMethod("isPainting", &WebContents::IsPainting)
|
2020-03-13 17:16:08 +00:00
|
|
|
|
.SetMethod("setFrameRate", &WebContents::SetFrameRate)
|
|
|
|
|
.SetMethod("getFrameRate", &WebContents::GetFrameRate)
|
2018-10-01 20:00:53 +00:00
|
|
|
|
#endif
|
2016-09-01 17:25:12 +00:00
|
|
|
|
.SetMethod("invalidate", &WebContents::Invalidate)
|
2020-03-13 17:16:08 +00:00
|
|
|
|
.SetMethod("setZoomLevel", &WebContents::SetZoomLevel)
|
|
|
|
|
.SetMethod("getZoomLevel", &WebContents::GetZoomLevel)
|
|
|
|
|
.SetMethod("setZoomFactor", &WebContents::SetZoomFactor)
|
|
|
|
|
.SetMethod("getZoomFactor", &WebContents::GetZoomFactor)
|
2016-06-08 18:41:14 +00:00
|
|
|
|
.SetMethod("getType", &WebContents::GetType)
|
2019-07-03 15:05:45 +00:00
|
|
|
|
.SetMethod("_getPreloadPaths", &WebContents::GetPreloadPaths)
|
2018-03-15 04:56:46 +00:00
|
|
|
|
.SetMethod("getLastWebPreferences", &WebContents::GetLastWebPreferences)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("getOwnerBrowserWindow", &WebContents::GetOwnerBrowserWindow)
|
|
|
|
|
.SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker)
|
2019-02-01 18:44:24 +00:00
|
|
|
|
.SetMethod("inspectSharedWorker", &WebContents::InspectSharedWorker)
|
2019-10-02 12:38:27 +00:00
|
|
|
|
.SetMethod("inspectSharedWorkerById",
|
|
|
|
|
&WebContents::InspectSharedWorkerById)
|
|
|
|
|
.SetMethod("getAllSharedWorkers", &WebContents::GetAllSharedWorkers)
|
2018-11-09 03:42:34 +00:00
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
|
|
|
|
.SetMethod("_print", &WebContents::Print)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
2018-11-09 03:42:34 +00:00
|
|
|
|
#endif
|
2020-11-10 17:06:03 +00:00
|
|
|
|
.SetMethod("_setNextChildWebPreferences",
|
|
|
|
|
&WebContents::SetNextChildWebPreferences)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
|
|
|
|
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
2016-06-07 20:13:49 +00:00
|
|
|
|
.SetMethod("showDefinitionForSelection",
|
|
|
|
|
&WebContents::ShowDefinitionForSelection)
|
2016-07-26 19:06:11 +00:00
|
|
|
|
.SetMethod("copyImageAt", &WebContents::CopyImageAt)
|
2016-07-05 22:43:57 +00:00
|
|
|
|
.SetMethod("capturePage", &WebContents::CapturePage)
|
2016-09-08 17:01:01 +00:00
|
|
|
|
.SetMethod("setEmbedder", &WebContents::SetEmbedder)
|
2017-11-30 07:37:26 +00:00
|
|
|
|
.SetMethod("setDevToolsWebContents", &WebContents::SetDevToolsWebContents)
|
2017-08-21 10:50:12 +00:00
|
|
|
|
.SetMethod("getNativeView", &WebContents::GetNativeView)
|
2020-01-25 00:43:42 +00:00
|
|
|
|
.SetMethod("incrementCapturerCount", &WebContents::IncrementCapturerCount)
|
|
|
|
|
.SetMethod("decrementCapturerCount", &WebContents::DecrementCapturerCount)
|
|
|
|
|
.SetMethod("isBeingCaptured", &WebContents::IsBeingCaptured)
|
2017-03-08 14:55:59 +00:00
|
|
|
|
.SetMethod("setWebRTCIPHandlingPolicy",
|
|
|
|
|
&WebContents::SetWebRTCIPHandlingPolicy)
|
2021-10-26 00:03:59 +00:00
|
|
|
|
.SetMethod("getMediaSourceId", &WebContents::GetMediaSourceID)
|
2017-03-08 14:55:59 +00:00
|
|
|
|
.SetMethod("getWebRTCIPHandlingPolicy",
|
|
|
|
|
&WebContents::GetWebRTCIPHandlingPolicy)
|
2019-04-29 17:11:11 +00:00
|
|
|
|
.SetMethod("takeHeapSnapshot", &WebContents::TakeHeapSnapshot)
|
2021-06-08 02:00:22 +00:00
|
|
|
|
.SetMethod("setImageAnimationPolicy",
|
|
|
|
|
&WebContents::SetImageAnimationPolicy)
|
2021-10-05 22:30:31 +00:00
|
|
|
|
.SetMethod("_getProcessMemoryInfo", &WebContents::GetProcessMemoryInfo)
|
2016-05-17 12:56:47 +00:00
|
|
|
|
.SetProperty("id", &WebContents::ID)
|
2015-12-03 08:04:46 +00:00
|
|
|
|
.SetProperty("session", &WebContents::Session)
|
2016-02-17 08:52:19 +00:00
|
|
|
|
.SetProperty("hostWebContents", &WebContents::HostWebContents)
|
2016-01-21 18:22:23 +00:00
|
|
|
|
.SetProperty("devToolsWebContents", &WebContents::DevToolsWebContents)
|
2020-07-30 16:17:57 +00:00
|
|
|
|
.SetProperty("debugger", &WebContents::Debugger)
|
2020-10-09 16:50:46 +00:00
|
|
|
|
.SetProperty("mainFrame", &WebContents::MainFrame)
|
2020-07-30 16:17:57 +00:00
|
|
|
|
.Build();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* WebContents::GetTypeName() {
|
|
|
|
|
return "WebContents";
|
2015-07-06 10:21:04 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-07-14 19:13:25 +00:00
|
|
|
|
ElectronBrowserContext* WebContents::GetBrowserContext() const {
|
|
|
|
|
return static_cast<ElectronBrowserContext*>(
|
|
|
|
|
web_contents()->GetBrowserContext());
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
|
// static
|
2020-11-17 22:14:33 +00:00
|
|
|
|
gin::Handle<WebContents> WebContents::New(
|
2019-10-25 13:03:28 +00:00
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
const gin_helper::Dictionary& options) {
|
2020-07-30 16:17:57 +00:00
|
|
|
|
gin::Handle<WebContents> handle =
|
|
|
|
|
gin::CreateHandle(isolate, new WebContents(isolate, options));
|
2021-05-11 20:57:11 +00:00
|
|
|
|
v8::TryCatch try_catch(isolate);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
2021-05-11 20:57:11 +00:00
|
|
|
|
if (try_catch.HasCaught()) {
|
|
|
|
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
|
|
|
|
}
|
2020-07-30 16:17:57 +00:00
|
|
|
|
return handle;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-19 08:52:07 +00:00
|
|
|
|
// static
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin::Handle<WebContents> WebContents::CreateAndTake(
|
2018-04-18 01:55:30 +00:00
|
|
|
|
v8::Isolate* isolate,
|
2018-10-22 18:02:25 +00:00
|
|
|
|
std::unique_ptr<content::WebContents> web_contents,
|
2018-04-18 01:55:30 +00:00
|
|
|
|
Type type) {
|
2020-07-30 16:17:57 +00:00
|
|
|
|
gin::Handle<WebContents> handle = gin::CreateHandle(
|
2018-10-22 18:02:25 +00:00
|
|
|
|
isolate, new WebContents(isolate, std::move(web_contents), type));
|
2021-05-11 20:57:11 +00:00
|
|
|
|
v8::TryCatch try_catch(isolate);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
gin_helper::CallMethod(isolate, handle.get(), "_init");
|
2021-05-11 20:57:11 +00:00
|
|
|
|
if (try_catch.HasCaught()) {
|
|
|
|
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
|
|
|
|
}
|
2020-07-30 16:17:57 +00:00
|
|
|
|
return handle;
|
2014-04-24 08:45:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-10-23 06:04:13 +00:00
|
|
|
|
// static
|
2020-07-16 23:16:05 +00:00
|
|
|
|
WebContents* WebContents::From(content::WebContents* web_contents) {
|
2020-07-30 16:17:57 +00:00
|
|
|
|
if (!web_contents)
|
|
|
|
|
return nullptr;
|
2020-10-26 18:56:31 +00:00
|
|
|
|
auto* data = static_cast<UserDataLink*>(
|
2020-07-30 16:17:57 +00:00
|
|
|
|
web_contents->GetUserData(kElectronApiWebContentsKey));
|
|
|
|
|
return data ? data->web_contents.get() : nullptr;
|
2018-10-19 08:52:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// static
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin::Handle<WebContents> WebContents::FromOrCreate(
|
2018-10-19 08:52:07 +00:00
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
content::WebContents* web_contents) {
|
2020-07-16 23:16:05 +00:00
|
|
|
|
WebContents* api_web_contents = From(web_contents);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
if (!api_web_contents) {
|
2020-07-16 23:16:05 +00:00
|
|
|
|
api_web_contents = new WebContents(isolate, web_contents);
|
2021-05-11 20:57:11 +00:00
|
|
|
|
v8::TryCatch try_catch(isolate);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
gin_helper::CallMethod(isolate, api_web_contents, "_init");
|
2021-05-11 20:57:11 +00:00
|
|
|
|
if (try_catch.HasCaught()) {
|
|
|
|
|
node::errors::TriggerUncaughtException(isolate, try_catch);
|
|
|
|
|
}
|
2020-07-30 16:17:57 +00:00
|
|
|
|
}
|
2020-07-16 23:16:05 +00:00
|
|
|
|
return gin::CreateHandle(isolate, api_web_contents);
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-15 23:52:43 +00:00
|
|
|
|
// static
|
|
|
|
|
gin::Handle<WebContents> WebContents::CreateFromWebPreferences(
|
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
const gin_helper::Dictionary& web_preferences) {
|
|
|
|
|
// Check if webPreferences has |webContents| option.
|
|
|
|
|
gin::Handle<WebContents> web_contents;
|
|
|
|
|
if (web_preferences.GetHidden("webContents", &web_contents) &&
|
|
|
|
|
!web_contents.IsEmpty()) {
|
|
|
|
|
// Set webPreferences from options if using an existing webContents.
|
|
|
|
|
// These preferences will be used when the webContent launches new
|
|
|
|
|
// render processes.
|
|
|
|
|
auto* existing_preferences =
|
|
|
|
|
WebContentsPreferences::From(web_contents->web_contents());
|
2021-07-26 16:04:09 +00:00
|
|
|
|
gin_helper::Dictionary web_preferences_dict;
|
2020-12-15 23:52:43 +00:00
|
|
|
|
if (gin::ConvertFromV8(isolate, web_preferences.GetHandle(),
|
|
|
|
|
&web_preferences_dict)) {
|
2021-07-26 16:04:09 +00:00
|
|
|
|
existing_preferences->SetFromDictionary(web_preferences_dict);
|
2021-09-21 00:20:54 +00:00
|
|
|
|
absl::optional<SkColor> color =
|
|
|
|
|
existing_preferences->GetBackgroundColor();
|
|
|
|
|
web_contents->web_contents()->SetPageBaseBackgroundColor(color);
|
2021-11-03 18:16:18 +00:00
|
|
|
|
// Because web preferences don't recognize transparency,
|
|
|
|
|
// only set rwhv background color if a color exists
|
2021-09-21 00:20:54 +00:00
|
|
|
|
auto* rwhv = web_contents->web_contents()->GetRenderWidgetHostView();
|
2021-11-03 18:16:18 +00:00
|
|
|
|
if (rwhv && color.has_value())
|
2022-01-27 14:56:35 +00:00
|
|
|
|
SetBackgroundColor(rwhv, color.value());
|
2020-12-15 23:52:43 +00:00
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Create one if not.
|
|
|
|
|
web_contents = WebContents::New(isolate, web_preferences);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return web_contents;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 23:16:05 +00:00
|
|
|
|
// static
|
|
|
|
|
WebContents* WebContents::FromID(int32_t id) {
|
2020-07-30 16:17:57 +00:00
|
|
|
|
return GetAllWebContents().Lookup(id);
|
2014-10-23 06:04:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
// static
|
|
|
|
|
gin::WrapperInfo WebContents::kWrapperInfo = {gin::kEmbedderNativeGin};
|
|
|
|
|
|
2014-04-24 08:45:25 +00:00
|
|
|
|
} // namespace api
|
|
|
|
|
|
|
|
|
|
} // namespace electron
|
2014-10-23 06:04:13 +00:00
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
using electron::api::GetAllWebContents;
|
2016-08-02 11:38:35 +00:00
|
|
|
|
using electron::api::WebContents;
|
|
|
|
|
|
2020-11-23 17:21:00 +00:00
|
|
|
|
gin::Handle<WebContents> WebContentsFromID(v8::Isolate* isolate, int32_t id) {
|
|
|
|
|
WebContents* contents = WebContents::FromID(id);
|
|
|
|
|
return contents ? gin::CreateHandle(isolate, contents)
|
|
|
|
|
: gin::Handle<WebContents>();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 21:01:24 +00:00
|
|
|
|
gin::Handle<WebContents> WebContentsFromDevToolsTargetID(
|
|
|
|
|
v8::Isolate* isolate,
|
|
|
|
|
std::string target_id) {
|
|
|
|
|
auto agent_host = content::DevToolsAgentHost::GetForId(target_id);
|
|
|
|
|
WebContents* contents =
|
|
|
|
|
agent_host ? WebContents::From(agent_host->GetWebContents()) : nullptr;
|
|
|
|
|
return contents ? gin::CreateHandle(isolate, contents)
|
|
|
|
|
: gin::Handle<WebContents>();
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-30 16:17:57 +00:00
|
|
|
|
std::vector<gin::Handle<WebContents>> GetAllWebContentsAsV8(
|
|
|
|
|
v8::Isolate* isolate) {
|
|
|
|
|
std::vector<gin::Handle<WebContents>> list;
|
|
|
|
|
for (auto iter = base::IDMap<WebContents*>::iterator(&GetAllWebContents());
|
|
|
|
|
!iter.IsAtEnd(); iter.Advance()) {
|
|
|
|
|
list.push_back(gin::CreateHandle(isolate, iter.GetCurrentValue()));
|
|
|
|
|
}
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-18 01:55:30 +00:00
|
|
|
|
void Initialize(v8::Local<v8::Object> exports,
|
|
|
|
|
v8::Local<v8::Value> unused,
|
|
|
|
|
v8::Local<v8::Context> context,
|
|
|
|
|
void* priv) {
|
2014-10-23 06:04:13 +00:00
|
|
|
|
v8::Isolate* isolate = context->GetIsolate();
|
2019-10-25 13:03:28 +00:00
|
|
|
|
gin_helper::Dictionary dict(isolate, exports);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
dict.Set("WebContents", WebContents::GetConstructor(context));
|
2020-11-23 17:21:00 +00:00
|
|
|
|
dict.SetMethod("fromId", &WebContentsFromID);
|
2021-08-27 21:01:24 +00:00
|
|
|
|
dict.SetMethod("fromDevToolsTargetId", &WebContentsFromDevToolsTargetID);
|
2020-07-30 16:17:57 +00:00
|
|
|
|
dict.SetMethod("getAllWebContents", &GetAllWebContentsAsV8);
|
2014-10-23 06:04:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2020-02-14 11:25:39 +00:00
|
|
|
|
NODE_LINKED_MODULE_CONTEXT_AWARE(electron_browser_web_contents, Initialize)
|