[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | 93ddb3c | 2012-04-11 21:44:29 | [diff] [blame] | 5 | #include "content/browser/web_contents/web_contents_impl.h" |
[email protected] | 3952656 | 2011-02-05 03:41:51 | [diff] [blame] | 6 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 7 | #include <stddef.h> |
| 8 | |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 9 | #include <cmath> |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 10 | #include <utility> |
rkaplow | e56a5203 | 2017-02-07 00:14:54 | [diff] [blame] | 11 | #include <vector> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 12 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 13 | #include "base/command_line.h" |
creis | fafed88 | 2016-07-29 00:03:09 | [diff] [blame] | 14 | #include "base/debug/dump_without_crashing.h" |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 15 | #include "base/feature_list.h" |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 16 | #include "base/i18n/character_encoding.h" |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 17 | #include "base/lazy_instance.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 18 | #include "base/location.h" |
[email protected] | 6d636e6 | 2013-07-31 03:15:56 | [diff] [blame] | 19 | #include "base/logging.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 20 | #include "base/macros.h" |
fdoray | ba12142 | 2016-12-23 19:51:48 | [diff] [blame] | 21 | #include "base/memory/ptr_util.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 22 | #include "base/memory/ref_counted.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 23 | #include "base/metrics/histogram_macros.h" |
bratell | 0a7406f | 2017-03-28 07:46:37 | [diff] [blame] | 24 | #include "base/metrics/user_metrics.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 25 | #include "base/process/process.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 26 | #include "base/single_thread_task_runner.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 27 | #include "base/strings/string16.h" |
| 28 | #include "base/strings/string_number_conversions.h" |
| 29 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 30 | #include "base/strings/utf_string_conversions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 31 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 32 | #include "base/time/time.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 33 | #include "base/trace_event/trace_event.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 34 | #include "build/build_config.h" |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 35 | #include "components/download/public/common/download_stats.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 36 | #include "components/rappor/public/rappor_utils.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 37 | #include "components/url_formatter/url_formatter.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 38 | #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 39 | #include "content/browser/bad_message.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 40 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 41 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 42 | #include "content/browser/child_process_security_policy_impl.h" |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 43 | #include "content/browser/devtools/protocol/page_handler.h" |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 44 | #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 45 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 46 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 47 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 48 | #include "content/browser/download/save_package.h" |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 49 | #include "content/browser/find_request_manager.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 50 | #include "content/browser/frame_host/cross_process_frame_connector.h" |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 51 | #include "content/browser/frame_host/frame_tree_node.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 52 | #include "content/browser/frame_host/interstitial_page_impl.h" |
| 53 | #include "content/browser/frame_host/navigation_entry_impl.h" |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 54 | #include "content/browser/frame_host/navigation_handle_impl.h" |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 55 | #include "content/browser/frame_host/navigation_request.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 56 | #include "content/browser/frame_host/navigator_impl.h" |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 57 | #include "content/browser/frame_host/render_frame_host_impl.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 58 | #include "content/browser/frame_host/render_frame_proxy_host.h" |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 59 | #include "content/browser/gpu/gpu_data_manager_impl.h" |
csharrison | 2e8c98e | 2016-08-01 23:56:25 | [diff] [blame] | 60 | #include "content/browser/loader/loader_io_thread_notifier.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 61 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 62 | #include "content/browser/manifest/manifest_manager_host.h" |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 63 | #include "content/browser/media/audio_stream_broker.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 64 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 65 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 66 | #include "content/browser/media/media_web_contents_observer.h" |
zqzhang | 1adf3cb | 2016-11-01 11:26:45 | [diff] [blame] | 67 | #include "content/browser/media/session/media_session_impl.h" |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 68 | #include "content/browser/plugin_content_origin_whitelist.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 69 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 70 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 71 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 72 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 73 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 74 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
Ken Buchanan | daef006b | 2017-08-17 18:32:15 | [diff] [blame] | 75 | #include "content/browser/renderer_host/render_widget_host_view_child_frame.h" |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 76 | #include "content/browser/renderer_host/text_input_manager.h" |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 77 | #include "content/browser/screen_orientation/screen_orientation_provider.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 78 | #include "content/browser/site_instance_impl.h" |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 79 | #include "content/browser/web_contents/web_contents_view_child_frame.h" |
[email protected] | b5a4084 | 2012-11-28 15:26:11 | [diff] [blame] | 80 | #include "content/browser/web_contents/web_contents_view_guest.h" |
[email protected] | eb2ef21 | 2013-01-29 04:27:58 | [diff] [blame] | 81 | #include "content/browser/webui/generic_handler.h" |
[email protected] | 86a0a6e | 2013-01-28 06:33:03 | [diff] [blame] | 82 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 83 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 84 | #include "content/common/browser_plugin/browser_plugin_constants.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 85 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 86 | #include "content/common/drag_messages.h" |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 87 | #include "content/common/frame_messages.h" |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 88 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 89 | #include "content/common/page_messages.h" |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 90 | #include "content/common/page_state_serialization.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 91 | #include "content/common/render_message_filter.mojom.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 92 | #include "content/common/view_messages.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 93 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 94 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 95 | #include "content/public/browser/browser_plugin_guest_manager.h" |
Gabriel Charette | 790754c | 2018-03-16 21:32:59 | [diff] [blame] | 96 | #include "content/public/browser/browser_thread.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 97 | #include "content/public/browser/content_browser_client.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 98 | #include "content/public/browser/download_manager.h" |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 99 | #include "content/public/browser/focused_node_details.h" |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 100 | #include "content/public/browser/guest_mode.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 101 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 102 | #include "content/public/browser/javascript_dialog_manager.h" |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 103 | #include "content/public/browser/keyboard_event_processing_result.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 104 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 105 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 106 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 107 | #include "content/public/browser/notification_service.h" |
scottmg | 011d96e3 | 2016-06-29 19:15:08 | [diff] [blame] | 108 | #include "content/public/browser/notification_types.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 109 | #include "content/public/browser/render_widget_host_iterator.h" |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 110 | #include "content/public/browser/restore_type.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 111 | #include "content/public/browser/security_style_explanations.h" |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 112 | #include "content/public/browser/ssl_status.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 113 | #include "content/public/browser/storage_partition.h" |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 114 | #include "content/public/browser/web_contents_binding_set.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 115 | #include "content/public/browser/web_contents_delegate.h" |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 116 | #include "content/public/browser/web_ui_controller.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 117 | #include "content/public/common/bindings_policy.h" |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 118 | #include "content/public/common/browser_side_navigation_policy.h" |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 119 | #include "content/public/common/child_process_host.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 120 | #include "content/public/common/content_constants.h" |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 121 | #include "content/public/common/content_features.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 122 | #include "content/public/common/content_switches.h" |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 123 | #include "content/public/common/page_state.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 124 | #include "content/public/common/page_zoom.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 125 | #include "content/public/common/result_codes.h" |
Ke He | 7319dbe | 2017-11-09 05:54:44 | [diff] [blame] | 126 | #include "content/public/common/service_manager_connection.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 127 | #include "content/public/common/url_utils.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 128 | #include "content/public/common/web_preferences.h" |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 129 | #include "net/base/url_util.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 130 | #include "net/http/http_cache.h" |
| 131 | #include "net/http/http_transaction_factory.h" |
rhalavati | 0fbaeef3 | 2017-06-01 15:56:30 | [diff] [blame] | 132 | #include "net/traffic_annotation/network_traffic_annotation.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 133 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 134 | #include "net/url_request/url_request_context_getter.h" |
Scott Violet | 02e38b9 | 2018-03-27 23:42:14 | [diff] [blame] | 135 | #include "ppapi/buildflags/buildflags.h" |
Ke He | 31d0bb0 | 2018-02-24 07:16:24 | [diff] [blame] | 136 | #include "services/device/public/mojom/constants.mojom.h" |
Mounir Lamouri | fd9dcefa | 2017-07-06 10:26:55 | [diff] [blame] | 137 | #include "services/metrics/public/cpp/ukm_recorder.h" |
Ke He | 7319dbe | 2017-11-09 05:54:44 | [diff] [blame] | 138 | #include "services/service_manager/public/cpp/connector.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 139 | #include "services/service_manager/public/cpp/interface_provider.h" |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 140 | #include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h" |
Blink Reformat | a30d423 | 2018-04-07 15:31:06 | [diff] [blame] | 141 | #include "third_party/blink/public/common/frame/sandbox_flags.h" |
| 142 | #include "third_party/blink/public/common/mime_util/mime_util.h" |
| 143 | #include "third_party/blink/public/platform/web_security_style.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 144 | #include "third_party/skia/include/core/SkBitmap.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 145 | #include "ui/accessibility/ax_tree_combiner.h" |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 146 | #include "ui/base/layout.h" |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 147 | #include "ui/events/base_event_utils.h" |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 148 | #include "ui/events/blink/web_input_event_traits.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 149 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 150 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 151 | #if defined(OS_WIN) |
| 152 | #include "content/browser/renderer_host/dip_util.h" |
| 153 | #include "ui/gfx/geometry/dip_util.h" |
| 154 | #endif |
| 155 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 156 | #if defined(OS_ANDROID) |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 157 | #include "content/browser/android/content_video_view.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 158 | #include "content/browser/android/date_time_chooser_android.h" |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 159 | #include "content/browser/android/java_interfaces_impl.h" |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 160 | #include "content/browser/media/android/media_web_contents_observer_android.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 161 | #include "content/browser/web_contents/web_contents_android.h" |
Ke He | 31d0bb0 | 2018-02-24 07:16:24 | [diff] [blame] | 162 | #include "services/device/public/mojom/nfc.mojom.h" |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 163 | #else // !OS_ANDROID |
| 164 | #include "content/browser/host_zoom_map_impl.h" |
| 165 | #include "content/browser/host_zoom_map_observer.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 166 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 167 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 168 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 169 | #include "content/browser/media/session/pepper_playback_observer.h" |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 170 | #endif |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 171 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 172 | namespace content { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 173 | namespace { |
| 174 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 175 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 176 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 177 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 178 | #if defined(OS_ANDROID) |
rob.buis | f06a8bf | 2017-03-10 18:11:32 | [diff] [blame] | 179 | const void* const kWebContentsAndroidKey = &kWebContentsAndroidKey; |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 180 | #endif |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 181 | |
Avi Drissman | a911482 | 2018-03-23 18:25:55 | [diff] [blame] | 182 | base::LazyInstance<std::vector< |
| 183 | WebContentsImpl::FriendWrapper::CreatedCallback>>::DestructorAtExit |
| 184 | g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 185 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 186 | void NotifyCacheOnIO( |
| 187 | scoped_refptr<net::URLRequestContextGetter> request_context, |
| 188 | const GURL& url, |
| 189 | const std::string& http_method) { |
gunsch | e668855c | 2015-03-05 02:37:58 | [diff] [blame] | 190 | net::HttpCache* cache = request_context->GetURLRequestContext()-> |
| 191 | http_transaction_factory()->GetCache(); |
| 192 | if (cache) |
| 193 | cache->OnExternalCacheHit(url, http_method); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 194 | } |
| 195 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 196 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 197 | for (FrameTreeNode* node : tree->Nodes()) { |
| 198 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 199 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 200 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 201 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 202 | } |
| 203 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 204 | bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) { |
| 205 | // This method scans the frame tree rather than checking whether |
| 206 | // host->delegate() == this, which allows it to return false when the host |
| 207 | // for a frame that is pending or pending deletion. |
| 208 | if (!host) |
| 209 | return false; |
| 210 | |
| 211 | for (FrameTreeNode* node : tree->Nodes()) { |
| 212 | if (node->current_frame_host()->GetRenderWidgetHost() == host) |
| 213 | return true; |
| 214 | } |
| 215 | return false; |
| 216 | } |
| 217 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 218 | void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) { |
| 219 | static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 220 | } |
| 221 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 222 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 223 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 224 | } |
| 225 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 226 | // Helper for GetInnerWebContents(). |
| 227 | bool GetInnerWebContentsHelper( |
| 228 | std::vector<WebContentsImpl*>* all_guest_contents, |
| 229 | WebContents* guest_contents) { |
| 230 | all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents)); |
| 231 | return false; |
| 232 | } |
| 233 | |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 234 | RenderFrameHostImpl* FindOpenerRFH(const WebContents::CreateParams& params) { |
| 235 | RenderFrameHostImpl* opener_rfh = nullptr; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 236 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 237 | opener_rfh = RenderFrameHostImpl::FromID(params.opener_render_process_id, |
| 238 | params.opener_render_frame_id); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 239 | } |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 240 | return opener_rfh; |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 241 | } |
| 242 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 243 | // Ensures that OnDialogClosed is only called once. |
| 244 | class CloseDialogCallbackWrapper |
| 245 | : public base::RefCountedThreadSafe<CloseDialogCallbackWrapper> { |
| 246 | public: |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 247 | using CloseCallback = |
| 248 | base::OnceCallback<void(bool, bool, const base::string16&)>; |
| 249 | |
| 250 | explicit CloseDialogCallbackWrapper(CloseCallback callback) |
| 251 | : callback_(std::move(callback)) {} |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 252 | |
| 253 | void Run(bool dialog_was_suppressed, |
| 254 | bool success, |
| 255 | const base::string16& user_input) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 256 | if (callback_.is_null()) |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 257 | return; |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 258 | std::move(callback_).Run(dialog_was_suppressed, success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | private: |
| 262 | friend class base::RefCountedThreadSafe<CloseDialogCallbackWrapper>; |
| 263 | ~CloseDialogCallbackWrapper() {} |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 264 | |
| 265 | CloseCallback callback_; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 266 | }; |
| 267 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 268 | } // namespace |
| 269 | |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 270 | std::unique_ptr<WebContents> WebContents::Create( |
| 271 | const WebContents::CreateParams& params) { |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 272 | return WebContentsImpl::CreateWithOpener(params, FindOpenerRFH(params)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 273 | } |
| 274 | |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 275 | std::unique_ptr<WebContents> WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 276 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 277 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
erikchen | ade1fef | 2018-05-02 22:07:57 | [diff] [blame] | 278 | std::unique_ptr<WebContentsImpl> new_contents( |
| 279 | new WebContentsImpl(params.browser_context)); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 280 | RenderFrameHostImpl* opener_rfh = FindOpenerRFH(params); |
| 281 | FrameTreeNode* opener = nullptr; |
| 282 | if (opener_rfh) |
| 283 | opener = opener_rfh->frame_tree_node(); |
| 284 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 285 | |
| 286 | for (SessionStorageNamespaceMap::const_iterator it = |
| 287 | session_storage_namespace_map.begin(); |
| 288 | it != session_storage_namespace_map.end(); |
| 289 | ++it) { |
| 290 | new_contents->GetController() |
| 291 | .SetSessionStorageNamespace(it->first, it->second.get()); |
| 292 | } |
| 293 | |
Sam McNally | 69a3377 | 2018-06-27 16:54:12 | [diff] [blame] | 294 | if (params.guest_delegate) { |
| 295 | // This makes |new_contents| act as a guest. |
| 296 | // For more info, see comment above class BrowserPluginGuest. |
| 297 | BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate); |
| 298 | } |
| 299 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 300 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 301 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 302 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 303 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 304 | void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 305 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 306 | g_created_callbacks.Get().push_back(callback); |
| 307 | } |
| 308 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 309 | void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 310 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 311 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
| 312 | if (g_created_callbacks.Get().at(i).Equals(callback)) { |
| 313 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 314 | return; |
| 315 | } |
| 316 | } |
| 317 | } |
| 318 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 319 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
| 320 | if (!rvh) |
| 321 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 322 | return rvh->GetDelegate()->GetAsWebContents(); |
| 323 | } |
| 324 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 325 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 326 | if (!rfh) |
| 327 | return nullptr; |
| 328 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 329 | } |
| 330 | |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 331 | WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) { |
| 332 | FrameTreeNode* frame_tree_node = |
| 333 | FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
ananta | b8cfa3b | 2016-10-14 22:43:19 | [diff] [blame] | 334 | if (!frame_tree_node) |
| 335 | return nullptr; |
jam | 8c4edd0 | 2017-05-06 18:50:33 | [diff] [blame] | 336 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 337 | } |
| 338 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 339 | void WebContents::SetScreenOrientationDelegate( |
| 340 | ScreenOrientationDelegate* delegate) { |
| 341 | ScreenOrientationProvider::SetDelegate(delegate); |
| 342 | } |
| 343 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 344 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 345 | |
| 346 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 347 | public: |
| 348 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
| 349 | : WebContentsObserver(watched_contents), |
| 350 | owner_(owner) { |
| 351 | } |
| 352 | |
| 353 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 354 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 355 | owner_->OnWebContentsDestroyed( |
| 356 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | private: |
| 360 | WebContentsImpl* owner_; |
| 361 | |
| 362 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 363 | }; |
| 364 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 365 | // WebContentsImpl::ColorChooser ---------------------------------------------- |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 366 | class WebContentsImpl::ColorChooser : public blink::mojom::ColorChooser { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 367 | public: |
| 368 | ColorChooser(content::ColorChooser* chooser, |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 369 | blink::mojom::ColorChooserRequest request, |
| 370 | blink::mojom::ColorChooserClientPtr client) |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 371 | : chooser_(chooser), |
| 372 | binding_(this, std::move(request)), |
| 373 | client_(std::move(client)) { |
| 374 | binding_.set_connection_error_handler( |
| 375 | base::BindOnce([](content::ColorChooser* chooser) { chooser->End(); }, |
| 376 | base::Unretained(chooser))); |
| 377 | } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 378 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 379 | ~ColorChooser() override { chooser_->End(); } |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 380 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 381 | void SetSelectedColor(SkColor color) override { |
| 382 | chooser_->SetSelectedColor(color); |
| 383 | } |
| 384 | |
| 385 | void DidChooseColorInColorChooser(SkColor color) { |
| 386 | client_->DidChooseColor(color); |
| 387 | } |
| 388 | |
| 389 | private: |
| 390 | // Color chooser that was opened by this tab. |
| 391 | std::unique_ptr<content::ColorChooser> chooser_; |
| 392 | |
| 393 | // mojo bindings. |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 394 | mojo::Binding<blink::mojom::ColorChooser> binding_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 395 | |
| 396 | // mojo renderer client. |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 397 | blink::mojom::ColorChooserClientPtr client_; |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 398 | }; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 399 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 400 | // WebContentsImpl::DisplayCutoutHostImpl -------------------------------------- |
| 401 | |
| 402 | class WebContentsImpl::DisplayCutoutHostImpl |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 403 | : public blink::mojom::DisplayCutoutHost, |
| 404 | public WebContentsObserver { |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 405 | public: |
| 406 | explicit DisplayCutoutHostImpl(WebContentsImpl* web_contents) |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 407 | : WebContentsObserver(web_contents), bindings_(web_contents, this) {} |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 408 | |
| 409 | // blink::mojom::DisplayCutoutHost |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 410 | void NotifyViewportFitChanged(blink::mojom::ViewportFit value) override { |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 411 | ViewportFitChangedForFrame(bindings_.GetCurrentTargetFrame(), value); |
| 412 | } |
| 413 | |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 414 | // Stores the updated viewport fit value for a |frame| and notifies observers |
| 415 | // if it has changed. |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 416 | void ViewportFitChangedForFrame(RenderFrameHost* rfh, |
| 417 | blink::mojom::ViewportFit value) { |
| 418 | if (GetValueOrDefault(rfh) == value) |
| 419 | return; |
| 420 | |
| 421 | values_[rfh] = value; |
| 422 | |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 423 | // If we are the current |RenderFrameHost| frame then notify |
| 424 | // WebContentsObservers about the new value. |
| 425 | if (current_rfh_ == rfh) |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 426 | NotifyObservers(value); |
| 427 | } |
| 428 | |
| 429 | // WebContentsObserver override. |
| 430 | void DidAcquireFullscreen(RenderFrameHost* rfh) override { |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 431 | SetCurrentRenderFrameHost(rfh); |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | // WebContentsObserver override. |
| 435 | void DidToggleFullscreenModeForTab(bool entered_fullscreen, |
| 436 | bool will_cause_resize) override { |
| 437 | if (!entered_fullscreen) |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 438 | SetCurrentRenderFrameHost(nullptr); |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 439 | } |
| 440 | |
Becca Hughes | bda2c4d | 2018-07-10 00:54:12 | [diff] [blame] | 441 | // WebContentsObserver override. |
| 442 | void DidFinishNavigation(NavigationHandle* navigation_handle) override { |
| 443 | // If the navigation is not in the main frame or if we are a same document |
| 444 | // navigation then we should stop now. |
| 445 | if (!navigation_handle->IsInMainFrame() || |
| 446 | navigation_handle->IsSameDocument()) { |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | // If we finish a main frame navigation and the |WebDisplayMode| is |
| 451 | // fullscreen or standalone then we should make the main frame the |
| 452 | // current |RenderFrameHost|. |
| 453 | RenderWidgetHostImpl* rwh = |
| 454 | web_contents_impl()->GetRenderViewHost()->GetWidget(); |
| 455 | blink::WebDisplayMode mode = web_contents_impl()->GetDisplayMode(rwh); |
| 456 | if (mode == blink::WebDisplayMode::kWebDisplayModeFullscreen || |
| 457 | mode == blink::WebDisplayMode::kWebDisplayModeStandalone) { |
| 458 | SetCurrentRenderFrameHost(web_contents_impl()->GetMainFrame()); |
| 459 | } |
| 460 | } |
| 461 | |
| 462 | // WebContentsObserver override. Removes any state built up by a render frame. |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 463 | void RenderFrameDeleted(RenderFrameHost* rfh) override { |
| 464 | values_.erase(rfh); |
| 465 | |
| 466 | // If we were the current |RenderFrameHost| then we should clear that. |
| 467 | if (current_rfh_ == rfh) |
| 468 | SetCurrentRenderFrameHost(nullptr); |
| 469 | } |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 470 | |
Becca Hughes | bda2c4d | 2018-07-10 00:54:12 | [diff] [blame] | 471 | // WebContentsObserver override. |
| 472 | void RenderFrameCreated(RenderFrameHost* rfh) override { |
| 473 | ViewportFitChangedForFrame(rfh, blink::mojom::ViewportFit::kAuto); |
| 474 | } |
| 475 | |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 476 | // Updates the safe area insets on the current frame. |
| 477 | void SetDisplayCutoutSafeArea(gfx::Insets insets) { |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 478 | insets_ = insets; |
| 479 | |
| 480 | if (current_rfh_) |
| 481 | SendSafeAreaToFrame(current_rfh_, insets); |
| 482 | } |
| 483 | |
| 484 | private: |
| 485 | // Set the current |RenderFrameHost| that should have control over the |
| 486 | // viewport fit value and we should set safe area insets on. |
| 487 | void SetCurrentRenderFrameHost(RenderFrameHost* rfh) { |
| 488 | if (current_rfh_ == rfh) |
| 489 | return; |
| 490 | |
| 491 | // If we had a previous frame then we should clear the insets on that frame. |
| 492 | if (current_rfh_) |
| 493 | SendSafeAreaToFrame(current_rfh_, gfx::Insets()); |
| 494 | |
| 495 | // If the new RenderFrameHost is nullptr we should stop here and notify |
| 496 | // observers that the new viewport fit is kAuto (the default). |
| 497 | current_rfh_ = rfh; |
| 498 | if (!rfh) { |
| 499 | NotifyObservers(blink::mojom::ViewportFit::kAuto); |
| 500 | return; |
| 501 | } |
| 502 | |
| 503 | // Send the current safe area to the new frame. |
| 504 | SendSafeAreaToFrame(rfh, insets_); |
| 505 | |
| 506 | // Notify the WebContentsObservers that the viewport fit value has changed. |
| 507 | NotifyObservers(GetValueOrDefault(rfh)); |
| 508 | } |
| 509 | |
| 510 | // Send the safe area insets to a |RenderFrameHost|. |
| 511 | void SendSafeAreaToFrame(RenderFrameHost* rfh, gfx::Insets insets) { |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 512 | blink::AssociatedInterfaceProvider* provider = |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 513 | rfh->GetRemoteAssociatedInterfaces(); |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 514 | if (!provider) |
| 515 | return; |
| 516 | |
| 517 | blink::mojom::DisplayCutoutClientAssociatedPtr client; |
| 518 | provider->GetInterface(&client); |
| 519 | client->SetSafeArea(blink::mojom::DisplayCutoutSafeArea::New( |
| 520 | insets.top(), insets.left(), insets.bottom(), insets.right())); |
| 521 | } |
| 522 | |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 523 | // Notify WebContentsObservers that the viewport fit value has changed. |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 524 | void NotifyObservers(blink::mojom::ViewportFit value) { |
| 525 | for (auto& observer : web_contents_impl()->observers_) |
| 526 | observer.ViewportFitChanged(value); |
| 527 | } |
| 528 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 529 | // Get the stored viewport fit value for a frame or kAuto if there is no |
| 530 | // stored value. |
| 531 | blink::mojom::ViewportFit GetValueOrDefault(RenderFrameHost* rfh) const { |
| 532 | auto value = values_.find(rfh); |
| 533 | if (value != values_.end()) |
| 534 | return value->second; |
| 535 | return blink::mojom::ViewportFit::kAuto; |
| 536 | } |
| 537 | |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 538 | WebContentsImpl* web_contents_impl() { |
| 539 | return static_cast<WebContentsImpl*>(web_contents()); |
| 540 | } |
| 541 | |
Becca Hughes | 9ef7f45 | 2018-06-27 16:57:31 | [diff] [blame] | 542 | // Stores the current safe area insets. |
| 543 | gfx::Insets insets_ = gfx::Insets(); |
| 544 | |
| 545 | // Stores the current |RenderFrameHost| that has the applied safe area insets |
| 546 | // and is controlling the viewport fit value. |
| 547 | RenderFrameHost* current_rfh_ = nullptr; |
| 548 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 549 | // Stores a map of RenderFrameHosts and their current viewport fit values. |
| 550 | std::map<RenderFrameHost*, blink::mojom::ViewportFit> values_; |
| 551 | |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 552 | WebContentsFrameBindingSet<blink::mojom::DisplayCutoutHost> bindings_; |
| 553 | }; |
| 554 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 555 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 556 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode( |
| 557 | WebContentsImpl* current_web_contents) |
| 558 | : current_web_contents_(current_web_contents), |
| 559 | outer_web_contents_(nullptr), |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 560 | outer_contents_frame_tree_node_id_( |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 561 | FrameTreeNode::kFrameTreeNodeInvalidId), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 562 | focused_web_contents_(current_web_contents) {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 563 | |
| 564 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 565 | if (OuterContentsFrameTreeNode()) |
| 566 | OuterContentsFrameTreeNode()->RemoveObserver(this); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 567 | |
| 568 | if (outer_web_contents_) |
| 569 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 573 | WebContentsImpl* outer_web_contents, |
| 574 | RenderFrameHostImpl* outer_contents_frame) { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 575 | focused_web_contents_ = nullptr; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 576 | outer_web_contents_ = outer_web_contents; |
| 577 | outer_contents_frame_tree_node_id_ = |
| 578 | outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 579 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 580 | outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_); |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 581 | outer_contents_frame->frame_tree_node()->AddObserver(this); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 582 | } |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 583 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 584 | void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents( |
| 585 | WebContentsImpl* inner_web_contents) { |
| 586 | inner_web_contents_.push_back(inner_web_contents); |
| 587 | } |
| 588 | |
| 589 | void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents( |
| 590 | WebContentsImpl* inner_web_contents) { |
| 591 | DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(), |
| 592 | inner_web_contents) != inner_web_contents_.end()); |
| 593 | inner_web_contents_.erase( |
| 594 | std::remove(inner_web_contents_.begin(), inner_web_contents_.end(), |
| 595 | inner_web_contents), |
| 596 | inner_web_contents_.end()); |
| 597 | } |
| 598 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 599 | FrameTreeNode* |
| 600 | WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const { |
| 601 | return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 602 | } |
| 603 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 604 | void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed( |
| 605 | FrameTreeNode* node) { |
| 606 | DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id()) |
| 607 | << "WebContentsTreeNode should only receive notifications for the " |
| 608 | "FrameTreeNode in its outer WebContents that hosts it."; |
| 609 | delete current_web_contents_; // deletes |this| too. |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 610 | } |
| 611 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 612 | void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
| 613 | WebContentsImpl* web_contents) { |
| 614 | DCHECK(!outer_web_contents()) |
| 615 | << "Only the outermost WebContents tracks focus."; |
| 616 | focused_web_contents_ = web_contents; |
| 617 | } |
| 618 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 619 | WebContentsImpl* |
| 620 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame( |
| 621 | const FrameTreeNode* frame) { |
| 622 | auto ftn_id = frame->frame_tree_node_id(); |
| 623 | for (WebContentsImpl* contents : inner_web_contents_) { |
| 624 | if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) { |
| 625 | return contents; |
| 626 | } |
| 627 | } |
| 628 | return nullptr; |
| 629 | } |
| 630 | |
| 631 | const std::vector<WebContentsImpl*>& |
| 632 | WebContentsImpl::WebContentsTreeNode::inner_web_contents() const { |
| 633 | return inner_web_contents_; |
| 634 | } |
| 635 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 636 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 637 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 638 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 639 | : delegate_(nullptr), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 640 | controller_(this, browser_context), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 641 | render_view_host_delegate_view_(nullptr), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 642 | created_with_opener_(false), |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 643 | frame_tree_(new NavigatorImpl(&controller_, this), |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 644 | this, |
| 645 | this, |
| 646 | this, |
| 647 | this), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 648 | node_(this), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 649 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 650 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 651 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 652 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 653 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 654 | upload_size_(0), |
| 655 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 656 | is_resume_pending_(false), |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 657 | interstitial_page_(nullptr), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 658 | has_accessed_initial_document_(false), |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 659 | theme_color_(SK_ColorTRANSPARENT), |
| 660 | last_sent_theme_color_(SK_ColorTRANSPARENT), |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 661 | did_first_visually_non_empty_paint_(false), |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 662 | capturer_count_(0), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 663 | is_being_destroyed_(false), |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 664 | is_notifying_observers_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 665 | notify_disconnection_(false), |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 666 | dialog_manager_(nullptr), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 667 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 668 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 669 | closed_by_user_gesture_(false), |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 670 | minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 671 | maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 672 | zoom_scroll_remainder_(0), |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 673 | fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 674 | fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 675 | fullscreen_widget_had_focus_at_shutdown_(false), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 676 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 677 | last_dialog_suppressed_(false), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 678 | accessibility_mode_( |
| 679 | BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 680 | audio_stream_monitor_(this), |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 681 | bluetooth_connected_device_count_(0), |
Guido Urdaneta | f400800 | 2018-05-03 10:43:04 | [diff] [blame] | 682 | media_device_group_id_salt_base_( |
| 683 | BrowserContext::CreateRandomMediaDeviceIDSalt()), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 684 | #if !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 685 | page_scale_factor_is_one_(true), |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 686 | #endif // !defined(OS_ANDROID) |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 687 | is_overlay_content_(false), |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 688 | showing_context_menu_(false), |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 689 | loading_weak_factory_(this), |
| 690 | weak_factory_(this) { |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 691 | frame_tree_.SetFrameRemoveListener( |
| 692 | base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 693 | base::Unretained(this))); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 694 | #if defined(OS_ANDROID) |
| 695 | media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); |
| 696 | #else |
qinmin | 58567c8 | 2015-01-07 21:00:20 | [diff] [blame] | 697 | media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 698 | #endif |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 699 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 700 | pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
| 701 | #endif |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 702 | |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 703 | loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 704 | #if !defined(OS_ANDROID) |
scottmg | 276753cf | 2016-10-27 18:25:22 | [diff] [blame] | 705 | host_zoom_map_observer_.reset(new HostZoomMapObserver(this)); |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 706 | #endif // !defined(OS_ANDROID) |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 707 | |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 708 | #if defined(OS_ANDROID) |
| 709 | if (base::FeatureList::IsEnabled(features::kDisplayCutoutAPI)) |
| 710 | display_cutout_host_impl_ = std::make_unique<DisplayCutoutHostImpl>(this); |
| 711 | #endif |
Becca Hughes | 6fe54e43 | 2018-06-09 04:18:56 | [diff] [blame] | 712 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 713 | registry_.AddInterface(base::BindRepeating( |
| 714 | &WebContentsImpl::OnColorChooserFactoryRequest, base::Unretained(this))); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 715 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 716 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 717 | WebContentsImpl::~WebContentsImpl() { |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 718 | // Imperfect sanity check against double free, given some crashes unexpectedly |
| 719 | // observed in the wild. |
| 720 | CHECK(!is_being_destroyed_); |
| 721 | |
| 722 | // We generally keep track of is_being_destroyed_ to let other features know |
| 723 | // to avoid certain actions during destruction. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 724 | is_being_destroyed_ = true; |
| 725 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 726 | // A WebContents should never be deleted while it is notifying observers, |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame] | 727 | // since this will lead to a use-after-free as it continues to notify later |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 728 | // observers. |
| 729 | CHECK(!is_notifying_observers_); |
| 730 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 731 | rwh_input_event_router_.reset(); |
| 732 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 733 | for (auto& entry : binding_sets_) |
| 734 | entry.second->CloseAllBindings(); |
| 735 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 736 | WebContentsImpl* outermost = GetOutermostWebContents(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 737 | if (this != outermost && ContainsOrIsFocusedWebContents()) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 738 | // If the current WebContents is in focus, unset it. |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 739 | outermost->SetAsFocusedWebContentsIfNecessary(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 740 | } |
| 741 | |
Nick Carter | d73635b | 2018-03-13 18:31:41 | [diff] [blame] | 742 | if (mouse_lock_widget_) |
| 743 | mouse_lock_widget_->RejectMouseLockOrUnlockIfNecessary(); |
| 744 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 745 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 746 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 747 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 748 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 749 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 750 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 751 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 752 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 753 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 754 | created_widgets_.clear(); |
| 755 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 756 | // Clear out any JavaScript state. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 757 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 758 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 759 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 760 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 761 | color_chooser_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 762 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 763 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 764 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 765 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 766 | NotificationService::current()->Notify( |
| 767 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 768 | Source<WebContents>(this), |
| 769 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 770 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 771 | // Destroy all frame tree nodes except for the root; this notifies observers. |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 772 | frame_tree_.root()->ResetForNewProcess(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 773 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 774 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 775 | // Manually call the observer methods for the root frame tree node. It is |
| 776 | // necessary to manually delete all objects tracking navigations |
| 777 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 778 | // notified of these navigations stopping before the WebContents is |
| 779 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 780 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 781 | |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 782 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 783 | root->current_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 784 | |
Arthur Hemery | c338017 | 2018-01-22 14:00:17 | [diff] [blame] | 785 | // Do not update state as the WebContents is being destroyed. |
| 786 | frame_tree_.root()->ResetNavigationRequest(true, true); |
| 787 | if (root->speculative_frame_host()) { |
| 788 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
clamy | fc3850d | 2018-02-23 14:35:28 | [diff] [blame] | 789 | root->speculative_frame_host()->ResetNavigationRequests(); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 790 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 791 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 792 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 793 | // Call this before WebContentsDestroyed() is broadcasted since |
| 794 | // AudioFocusManager will be destroyed after that. |
| 795 | pepper_playback_observer_.reset(); |
| 796 | #endif // defined(ENABLED_PLUGINS) |
| 797 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 798 | // If audio is playing then notify external observers of the audio stream |
| 799 | // disappearing. |
| 800 | if (is_currently_audible_) { |
| 801 | is_currently_audible_ = false; |
| 802 | for (auto& observer : observers_) |
| 803 | observer.OnAudioStateChanged(false); |
| 804 | |
| 805 | if (GetOuterWebContents()) |
| 806 | GetOuterWebContents()->OnAudioStateChanged(); |
| 807 | } |
| 808 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 809 | for (auto& observer : observers_) |
| 810 | observer.FrameDeleted(root->current_frame_host()); |
nasko | a83483fb | 2015-02-27 16:57:10 | [diff] [blame] | 811 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 812 | for (auto& observer : observers_) |
| 813 | observer.RenderViewDeleted(root->current_host()); |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 814 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 815 | for (auto& observer : observers_) |
| 816 | observer.WebContentsDestroyed(); |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 817 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 818 | for (auto& observer : observers_) |
| 819 | observer.ResetWebContents(); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 820 | |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 821 | SetDelegate(nullptr); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 822 | } |
| 823 | |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 824 | std::unique_ptr<WebContentsImpl> WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 825 | const WebContents::CreateParams& params, |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 826 | RenderFrameHostImpl* opener_rfh) { |
[email protected] | e11f0e9 | 2013-06-12 15:12:03 | [diff] [blame] | 827 | TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 828 | FrameTreeNode* opener = nullptr; |
| 829 | if (opener_rfh) |
| 830 | opener = opener_rfh->frame_tree_node(); |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 831 | std::unique_ptr<WebContentsImpl> new_contents( |
| 832 | new WebContentsImpl(params.browser_context)); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 833 | new_contents->SetOpenerForNewContents(opener, params.opener_suppressed); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 834 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 835 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 836 | // flags, and these flags take effect immediately. An exception is if the |
| 837 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 838 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 839 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 840 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 841 | if (opener) { |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 842 | blink::WebSandboxFlags opener_flags = opener_rfh->active_sandbox_flags(); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 843 | const blink::WebSandboxFlags inherit_flag = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 844 | blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 845 | if ((opener_flags & inherit_flag) == inherit_flag) { |
Ian Clelland | cdc4f31 | 2017-10-13 22:24:12 | [diff] [blame] | 846 | // TODO(iclelland): Transfer correct container policy from opener as well. |
| 847 | // https://crbug.com/774620 |
| 848 | new_root->SetPendingFramePolicy({opener_flags, {}}); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 849 | } |
| 850 | } |
| 851 | |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 852 | // Apply starting sandbox flags. |
Luna Lu | c3fdacdf | 2017-11-08 04:48:53 | [diff] [blame] | 853 | blink::FramePolicy frame_policy(new_root->pending_frame_policy()); |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 854 | frame_policy.sandbox_flags |= params.starting_sandbox_flags; |
| 855 | new_root->SetPendingFramePolicy(frame_policy); |
| 856 | new_root->CommitPendingFramePolicy(); |
| 857 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 858 | // This may be true even when opener is null, such as when opening blocked |
| 859 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 860 | if (params.created_with_opener) |
| 861 | new_contents->created_with_opener_ = true; |
| 862 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 863 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 864 | // This makes |new_contents| act as a guest. |
| 865 | // For more info, see comment above class BrowserPluginGuest. |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 866 | BrowserPluginGuest::Create(new_contents.get(), params.guest_delegate); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 867 | } |
mark a. foltz | ef394fce | 2017-10-21 09:11:02 | [diff] [blame] | 868 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 869 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 870 | return new_contents; |
| 871 | } |
| 872 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 873 | // static |
| 874 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
| 875 | std::vector<WebContentsImpl*> result; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 876 | std::unique_ptr<RenderWidgetHostIterator> widgets( |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 877 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 878 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 879 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 880 | if (!rvh) |
| 881 | continue; |
| 882 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 883 | if (!web_contents) |
| 884 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 885 | if (web_contents->GetRenderViewHost() != rvh) |
| 886 | continue; |
| 887 | // Because a WebContents can only have one current RVH at a time, there will |
| 888 | // be no duplicate WebContents here. |
| 889 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 890 | } |
| 891 | return result; |
| 892 | } |
| 893 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 894 | // static |
| 895 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 896 | const FrameTreeNode* frame_tree_node) { |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 897 | return static_cast<WebContentsImpl*>( |
| 898 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 899 | } |
| 900 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 901 | // static |
| 902 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 903 | int render_frame_host_id) { |
| 904 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 905 | RenderFrameHost* render_frame_host = |
| 906 | RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); |
| 907 | if (!render_frame_host) |
| 908 | return nullptr; |
| 909 | |
| 910 | return WebContents::FromRenderFrameHost(render_frame_host); |
| 911 | } |
| 912 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 913 | // static |
| 914 | WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode( |
| 915 | const FrameTreeNode* frame_tree_node) { |
| 916 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node) |
| 917 | ->node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 918 | } |
| 919 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 920 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 921 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 922 | } |
| 923 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 924 | bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host, |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 925 | const IPC::Message& message) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 926 | for (auto& observer : observers_) { |
Lukasz Anforowicz | 89f2c1b | 2017-08-30 21:36:46 | [diff] [blame] | 927 | // TODO(nick, creis): https://crbug.com/758026: Replace all uses of this |
| 928 | // variant of OnMessageReceived with the version that takes a |
| 929 | // RenderFrameHost, and then delete it. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 930 | if (observer.OnMessageReceived(message)) |
| 931 | return true; |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 932 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 933 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 934 | bool handled = true; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 935 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host) |
| 936 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
| 937 | OnFirstVisuallyNonEmptyPaint) |
| 938 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
| 939 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
| 940 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged, |
| 941 | OnPageScaleFactorChanged) |
| 942 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
| 943 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 944 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 945 | IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 946 | OnRequestPpapiBrokerPermission) |
| 947 | #endif |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 948 | #if defined(OS_ANDROID) |
| 949 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog) |
| 950 | #endif |
| 951 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 952 | IPC_END_MESSAGE_MAP() |
| 953 | |
| 954 | return handled; |
| 955 | } |
| 956 | |
| 957 | bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host, |
| 958 | const IPC::Message& message) { |
Lukasz Anforowicz | 0292310 | 2017-10-09 18:11:37 | [diff] [blame] | 959 | { |
| 960 | WebUIImpl* web_ui = render_frame_host->web_ui(); |
| 961 | if (web_ui && web_ui->OnMessageReceived(message, render_frame_host)) |
| 962 | return true; |
| 963 | } |
| 964 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 965 | for (auto& observer : observers_) { |
| 966 | if (observer.OnMessageReceived(message, render_frame_host)) |
| 967 | return true; |
| 968 | } |
| 969 | |
| 970 | bool handled = true; |
| 971 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host) |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 972 | IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, |
| 973 | OnDomOperationResponse) |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 974 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 975 | OnThemeColorChanged) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 976 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 977 | OnDocumentLoadedInFrame) |
| 978 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
avi | 7830c85 | 2015-08-31 23:46:25 | [diff] [blame] | 979 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 980 | OnDidLoadResourceFromMemoryCache) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 981 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 982 | OnDidDisplayInsecureContent) |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 983 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction, |
| 984 | OnDidContainInsecureFormAction) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 985 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 986 | OnDidRunInsecureContent) |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 987 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, |
| 988 | OnDidDisplayContentWithCertificateErrors) |
| 989 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors, |
| 990 | OnDidRunContentWithCertificateErrors) |
avi | a23e16b | 2015-07-09 14:18:48 | [diff] [blame] | 991 | IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler, |
| 992 | OnRegisterProtocolHandler) |
| 993 | IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler, |
| 994 | OnUnregisterProtocolHandler) |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 995 | IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals, |
| 996 | OnUpdatePageImportanceSignals) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 997 | IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply) |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 998 | IPC_MESSAGE_HANDLER(FrameHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 999 | #if BUILDFLAG(ENABLE_PLUGINS) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 1000 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 1001 | OnPepperInstanceCreated) |
| 1002 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 1003 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1004 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 1005 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback, |
| 1006 | OnPepperStartsPlayback) |
| 1007 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback, |
| 1008 | OnPepperStopsPlayback) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 1009 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1010 | IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 1011 | OnBrowserPluginMessage(render_frame_host, |
| 1012 | message)) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 1013 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1014 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 1015 | IPC_END_MESSAGE_MAP() |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1016 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1017 | return handled; |
| 1018 | } |
| 1019 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1020 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1021 | return controller_; |
| 1022 | } |
| 1023 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1024 | const NavigationControllerImpl& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 1025 | return controller_; |
| 1026 | } |
| 1027 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1028 | BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 1029 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1030 | } |
| 1031 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1032 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1033 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1034 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1035 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1036 | } |
| 1037 | |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 1038 | const GURL& WebContentsImpl::GetVisibleURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1039 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1040 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 1041 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1042 | } |
| 1043 | |
| 1044 | const GURL& WebContentsImpl::GetLastCommittedURL() const { |
| 1045 | // We may not have a navigation entry yet. |
| 1046 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1047 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 1048 | } |
| 1049 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1050 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1051 | return delegate_; |
| 1052 | } |
| 1053 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1054 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1055 | // TODO(cbentzel): remove this debugging code? |
| 1056 | if (delegate == delegate_) |
| 1057 | return; |
| 1058 | if (delegate_) |
| 1059 | delegate_->Detach(this); |
| 1060 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1061 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1062 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1063 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 1064 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 1065 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 1066 | if (GetRenderViewHost()) |
| 1067 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 1068 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1069 | } |
| 1070 | |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 1071 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() const { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 1072 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 1073 | } |
| 1074 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 1075 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 1076 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 1077 | if (!focused_node) |
| 1078 | return nullptr; |
| 1079 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 1080 | } |
| 1081 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1082 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1083 | int frame_tree_node_id, |
| 1084 | int process_id) { |
| 1085 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1086 | |
| 1087 | // Sanity check that this is in the caller's expected process. Otherwise a |
| 1088 | // recent cross-process navigation may have led to a privilege change that the |
| 1089 | // caller is not expecting. |
| 1090 | if (!frame || |
| 1091 | frame->current_frame_host()->GetProcess()->GetID() != process_id) |
| 1092 | return nullptr; |
| 1093 | |
| 1094 | return frame->current_frame_host(); |
| 1095 | } |
| 1096 | |
| 1097 | RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId( |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1098 | int frame_tree_node_id) { |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 1099 | // Beware using this! The RenderFrameHost may have changed since the caller |
| 1100 | // obtained frame_tree_node_id. |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 1101 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 1102 | return frame ? frame->current_frame_host() : nullptr; |
| 1103 | } |
| 1104 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1105 | void WebContentsImpl::ForEachFrame( |
Lei Zhang | ebcc630 | 2018-01-12 19:46:45 | [diff] [blame] | 1106 | const base::RepeatingCallback<void(RenderFrameHost*)>& on_frame) { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1107 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1108 | on_frame.Run(node->current_frame_host()); |
| 1109 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1110 | } |
| 1111 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1112 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
| 1113 | std::vector<RenderFrameHost*> frame_hosts; |
| 1114 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 1115 | frame_hosts.push_back(node->current_frame_host()); |
| 1116 | return frame_hosts; |
| 1117 | } |
| 1118 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 1119 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 1120 | int number_of_messages = 0; |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1121 | for (RenderFrameHost* rfh : GetAllFrames()) { |
lukasza | 1a9ab242 | 2016-03-02 18:47:25 | [diff] [blame] | 1122 | if (!rfh->IsRenderFrameLive()) |
| 1123 | continue; |
| 1124 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1125 | ++number_of_messages; |
| 1126 | IPC::Message* message_copy = new IPC::Message(*message); |
| 1127 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 1128 | rfh->Send(message_copy); |
| 1129 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1130 | delete message; |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 1131 | return number_of_messages; |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 1132 | } |
| 1133 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1134 | void WebContentsImpl::SendPageMessage(IPC::Message* msg) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 1135 | frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr); |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 1136 | } |
| 1137 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1138 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1139 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1140 | } |
| 1141 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1142 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 1143 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 1144 | dialog_manager_->CancelDialogs(this, /*reset_state=*/false); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 1145 | } |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 1146 | if (browser_plugin_embedder_) |
| 1147 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 1148 | } |
| 1149 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 1150 | void WebContentsImpl::ClosePage() { |
| 1151 | GetRenderViewHost()->ClosePage(); |
| 1152 | } |
| 1153 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1154 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1155 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1156 | } |
| 1157 | |
lfg | 265a267 | 2016-04-23 03:11:02 | [diff] [blame] | 1158 | RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() { |
| 1159 | if (GetOuterWebContents()) |
| 1160 | return GetOuterWebContents()->GetTopLevelRenderWidgetHostView(); |
| 1161 | return GetRenderManager()->GetRenderWidgetHostView(); |
| 1162 | } |
| 1163 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1164 | RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() |
| 1165 | const { |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 1166 | if (auto* widget_host = GetFullscreenRenderWidgetHost()) |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 1167 | return widget_host->GetView(); |
| 1168 | return nullptr; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1169 | } |
| 1170 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1171 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1172 | return view_.get(); |
| 1173 | } |
| 1174 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 1175 | void WebContentsImpl::OnScreenOrientationChange() { |
| 1176 | DCHECK(screen_orientation_provider_); |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 1177 | screen_orientation_provider_->OnOrientationChange(); |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 1178 | } |
| 1179 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 1180 | SkColor WebContentsImpl::GetThemeColor() const { |
| 1181 | return theme_color_; |
| 1182 | } |
| 1183 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1184 | void WebContentsImpl::SetAccessibilityMode(ui::AXMode mode) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1185 | if (mode == accessibility_mode_) |
| 1186 | return; |
| 1187 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1188 | // Don't allow accessibility to be enabled for WebContents that are never |
| 1189 | // visible, like background pages. |
| 1190 | if (IsNeverVisible()) |
| 1191 | return; |
| 1192 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1193 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1194 | |
| 1195 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1196 | UpdateAccessibilityModeOnFrame(node->current_frame_host()); |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 1197 | // Also update accessibility mode on the speculative RenderFrameHost for |
| 1198 | // this FrameTreeNode, if one exists. |
Alex Moshchuk | 3d8a1f39 | 2017-10-24 19:01:26 | [diff] [blame] | 1199 | RenderFrameHost* speculative_frame_host = |
| 1200 | node->render_manager()->speculative_frame_host(); |
| 1201 | if (speculative_frame_host) |
| 1202 | UpdateAccessibilityModeOnFrame(speculative_frame_host); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1203 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1204 | } |
| 1205 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1206 | void WebContentsImpl::AddAccessibilityMode(ui::AXMode mode) { |
| 1207 | ui::AXMode new_mode(accessibility_mode_); |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1208 | new_mode |= mode; |
| 1209 | SetAccessibilityMode(new_mode); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1210 | } |
| 1211 | |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1212 | // Helper class used by WebContentsImpl::RequestAXTreeSnapshot. |
| 1213 | // Handles the callbacks from parallel snapshot requests to each frame, |
| 1214 | // and feeds the results to an AXTreeCombiner, which converts them into a |
| 1215 | // single combined accessibility tree. |
| 1216 | class WebContentsImpl::AXTreeSnapshotCombiner |
| 1217 | : public base::RefCounted<AXTreeSnapshotCombiner> { |
| 1218 | public: |
| 1219 | explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) |
| 1220 | : callback_(std::move(callback)) {} |
| 1221 | |
| 1222 | AXTreeSnapshotCallback AddFrame(bool is_root) { |
| 1223 | // Adds a reference to |this|. |
| 1224 | return base::BindOnce(&AXTreeSnapshotCombiner::ReceiveSnapshot, this, |
| 1225 | is_root); |
| 1226 | } |
| 1227 | |
| 1228 | void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { |
| 1229 | combiner_.AddTree(snapshot, is_root); |
| 1230 | } |
| 1231 | |
| 1232 | private: |
| 1233 | friend class base::RefCounted<AXTreeSnapshotCombiner>; |
| 1234 | |
| 1235 | // This is called automatically after the last call to ReceiveSnapshot |
| 1236 | // when there are no more references to this object. |
| 1237 | ~AXTreeSnapshotCombiner() { |
| 1238 | combiner_.Combine(); |
| 1239 | std::move(callback_).Run(combiner_.combined()); |
| 1240 | } |
| 1241 | |
| 1242 | ui::AXTreeCombiner combiner_; |
| 1243 | AXTreeSnapshotCallback callback_; |
| 1244 | }; |
| 1245 | |
| 1246 | void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback, |
| 1247 | ui::AXMode ax_mode) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1248 | // Send a request to each of the frames in parallel. Each one will return |
| 1249 | // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine |
| 1250 | // them into a single tree and call |callback| with that result, then |
| 1251 | // delete |combiner|. |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1252 | FrameTreeNode* root_node = frame_tree_.root(); |
Avi Drissman | b30851c | 2018-03-08 20:34:33 | [diff] [blame] | 1253 | AXTreeSnapshotCombiner* combiner = |
| 1254 | new AXTreeSnapshotCombiner(std::move(callback)); |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1255 | |
| 1256 | RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, ax_mode); |
| 1257 | } |
| 1258 | |
| 1259 | void WebContentsImpl::RecursiveRequestAXTreeSnapshotOnFrame( |
| 1260 | FrameTreeNode* root_node, |
| 1261 | AXTreeSnapshotCombiner* combiner, |
| 1262 | ui::AXMode ax_mode) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1263 | for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { |
Avi Drissman | 1e620f3 | 2018-03-16 13:57:29 | [diff] [blame] | 1264 | WebContentsImpl* inner_contents = |
| 1265 | node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 1266 | if (inner_contents) { |
| 1267 | inner_contents->RecursiveRequestAXTreeSnapshotOnFrame(root_node, combiner, |
| 1268 | ax_mode); |
| 1269 | } else { |
| 1270 | bool is_root = frame_tree_node == root_node; |
| 1271 | frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( |
| 1272 | combiner->AddFrame(is_root), ax_mode); |
| 1273 | } |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1274 | } |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 1275 | } |
| 1276 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1277 | #if !defined(OS_ANDROID) |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1278 | void WebContentsImpl::UpdateZoom() { |
| 1279 | RenderWidgetHostImpl* rwh = GetRenderViewHost()->GetWidget(); |
| 1280 | if (rwh->GetView()) |
| 1281 | rwh->SynchronizeVisualProperties(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1282 | } |
| 1283 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1284 | |
| 1285 | void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1286 | const std::string& host) { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1287 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 1288 | if (!entry) |
| 1289 | return; |
| 1290 | |
| 1291 | GURL url = HostZoomMap::GetURLFromEntry(entry); |
| 1292 | if (host != net::GetHostOrSpecFromURL(url) || |
| 1293 | (!scheme.empty() && !url.SchemeIs(scheme))) { |
| 1294 | return; |
| 1295 | } |
| 1296 | |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 1297 | UpdateZoom(); |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1298 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 1299 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1300 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1301 | base::Closure WebContentsImpl::AddBindingSet( |
| 1302 | const std::string& interface_name, |
| 1303 | WebContentsBindingSet* binding_set) { |
| 1304 | auto result = |
| 1305 | binding_sets_.insert(std::make_pair(interface_name, binding_set)); |
| 1306 | DCHECK(result.second); |
| 1307 | return base::Bind(&WebContentsImpl::RemoveBindingSet, |
| 1308 | weak_factory_.GetWeakPtr(), interface_name); |
| 1309 | } |
| 1310 | |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1311 | WebContentsBindingSet* WebContentsImpl::GetBindingSet( |
| 1312 | const std::string& interface_name) { |
| 1313 | auto it = binding_sets_.find(interface_name); |
| 1314 | if (it == binding_sets_.end()) |
| 1315 | return nullptr; |
| 1316 | return it->second; |
| 1317 | } |
| 1318 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1319 | std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() { |
| 1320 | if (browser_plugin_embedder_) { |
| 1321 | std::vector<WebContentsImpl*> inner_contents; |
| 1322 | GetBrowserContext()->GetGuestManager()->ForEachGuest( |
Mark Pilgrim | d8412173 | 2018-03-22 14:12:12 | [diff] [blame] | 1323 | this, base::BindRepeating(&GetInnerWebContentsHelper, &inner_contents)); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1324 | return inner_contents; |
| 1325 | } |
| 1326 | |
| 1327 | return node_.inner_web_contents(); |
| 1328 | } |
| 1329 | |
| 1330 | std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() { |
| 1331 | std::vector<WebContentsImpl*> all_contents(1, this); |
| 1332 | |
| 1333 | for (size_t i = 0; i != all_contents.size(); ++i) { |
| 1334 | for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) { |
| 1335 | all_contents.push_back(inner_contents); |
| 1336 | } |
| 1337 | } |
| 1338 | |
| 1339 | return all_contents; |
| 1340 | } |
| 1341 | |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1342 | void WebContentsImpl::NotifyManifestUrlChanged( |
| 1343 | const base::Optional<GURL>& manifest_url) { |
| 1344 | for (auto& observer : observers_) |
| 1345 | observer.DidUpdateWebManifestURL(manifest_url); |
| 1346 | } |
| 1347 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1348 | WebUI* WebContentsImpl::GetWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1349 | WebUI* commited_web_ui = GetCommittedWebUI(); |
| 1350 | return commited_web_ui ? commited_web_ui |
| 1351 | : GetRenderManager()->GetNavigatingWebUI(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1352 | } |
| 1353 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1354 | WebUI* WebContentsImpl::GetCommittedWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1355 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1356 | } |
| 1357 | |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1358 | void WebContentsImpl::SetUserAgentOverride(const std::string& override, |
| 1359 | bool override_in_new_tabs) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1360 | if (GetUserAgentOverride() == override) |
| 1361 | return; |
| 1362 | |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1363 | should_override_user_agent_in_new_tabs_ = override_in_new_tabs; |
| 1364 | |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1365 | renderer_preferences_.user_agent_override = override; |
| 1366 | |
| 1367 | // Send the new override string to the renderer. |
| 1368 | RenderViewHost* host = GetRenderViewHost(); |
| 1369 | if (host) |
| 1370 | host->SyncRendererPrefs(); |
| 1371 | |
| 1372 | // Reload the page if a load is currently in progress to avoid having |
| 1373 | // different parts of the page loaded using different user agents. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 1374 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 1375 | if (IsLoading() && entry != nullptr && entry->GetIsOverridingUserAgent()) |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 1376 | controller_.Reload(ReloadType::BYPASSING_CACHE, true); |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 1377 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1378 | for (auto& observer : observers_) |
| 1379 | observer.UserAgentOverrideSet(override); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | const std::string& WebContentsImpl::GetUserAgentOverride() const { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1383 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1384 | } |
| 1385 | |
Changwan Ryu | c1134a8 | 2018-03-07 02:10:14 | [diff] [blame] | 1386 | bool WebContentsImpl::ShouldOverrideUserAgentInNewTabs() { |
| 1387 | return should_override_user_agent_in_new_tabs_; |
| 1388 | } |
| 1389 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1390 | void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1391 | if (!GetAccessibilityMode().is_mode_off()) { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1392 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 1393 | ResetAccessibility(rfh); |
| 1394 | } else { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1395 | AddAccessibilityMode(ui::kAXModeWebContentsOnly); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1396 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1397 | } |
| 1398 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1399 | bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1400 | return accessibility_mode_ == ui::kAXModeWebContentsOnly; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 1404 | return accessibility_mode_ == ui::kAXModeComplete; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1405 | } |
| 1406 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 1407 | const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const { |
| 1408 | return page_importance_signals_; |
| 1409 | } |
| 1410 | |
Guido Urdaneta | f400800 | 2018-05-03 10:43:04 | [diff] [blame] | 1411 | const std::string& WebContentsImpl::GetMediaDeviceGroupIDSaltBase() const { |
| 1412 | return media_device_group_id_salt_base_; |
| 1413 | } |
| 1414 | |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1415 | #if defined(OS_ANDROID) |
| 1416 | |
| 1417 | void WebContentsImpl::SetDisplayCutoutSafeArea(gfx::Insets insets) { |
Becca Hughes | 8633462 | 2018-07-09 21:29:38 | [diff] [blame] | 1418 | if (display_cutout_host_impl_) |
| 1419 | display_cutout_host_impl_->SetDisplayCutoutSafeArea(insets); |
Becca Hughes | 6daf566 | 2018-06-27 16:50:54 | [diff] [blame] | 1420 | } |
| 1421 | |
| 1422 | #endif |
| 1423 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1424 | const base::string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 1425 | // Transient entries take precedence. They are used for interstitial pages |
| 1426 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1427 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1428 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1429 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1430 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1431 | |
| 1432 | WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI(); |
| 1433 | WebUI* our_web_ui = navigating_web_ui |
| 1434 | ? navigating_web_ui |
| 1435 | : GetRenderManager()->current_frame_host()->web_ui(); |
| 1436 | |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1437 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1438 | // Don't override the title in view source mode. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1439 | entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1440 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1441 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1442 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1443 | if (!title.empty()) |
| 1444 | return title; |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | // We use the title for the last committed entry rather than a pending |
| 1449 | // navigation entry. For example, when the user types in a URL, we want to |
| 1450 | // keep the old page's title until the new load has committed and we get a new |
| 1451 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1452 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1453 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 1454 | // We make an exception for initial navigations. We only want to use the title |
| 1455 | // from the visible entry if: |
| 1456 | // 1. The pending entry has been explicitly assigned a title to display. |
| 1457 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 1458 | // which case there is a pending entry index other than -1. |
| 1459 | // |
| 1460 | // Otherwise, we want to stick with the last committed entry's title during |
| 1461 | // new navigations, which have pending entries at index -1 with no title. |
| 1462 | if (controller_.IsInitialNavigation() && |
| 1463 | ((controller_.GetVisibleEntry() && |
| 1464 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 1465 | controller_.GetPendingEntryIndex() != -1)) { |
| 1466 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 1467 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1468 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1469 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1470 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1471 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1472 | |
| 1473 | // |page_title_when_no_navigation_entry_| is finally used |
| 1474 | // if no title cannot be retrieved. |
| 1475 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1476 | } |
| 1477 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1478 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1479 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1480 | } |
| 1481 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1482 | bool WebContentsImpl::IsLoading() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1483 | return frame_tree_.IsLoading() && |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 1484 | !(ShowingInterstitialPage() && interstitial_page_->pause_throbber()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1485 | } |
| 1486 | |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1487 | bool WebContentsImpl::IsLoadingToDifferentDocument() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1488 | return IsLoading() && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1489 | } |
| 1490 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1491 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1492 | return waiting_for_response_ && is_load_to_different_document_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1493 | } |
| 1494 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1495 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1496 | return load_state_; |
| 1497 | } |
| 1498 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1499 | const base::string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1500 | return load_state_host_; |
| 1501 | } |
| 1502 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1503 | uint64_t WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1504 | return upload_size_; |
| 1505 | } |
| 1506 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1507 | uint64_t WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1508 | return upload_position_; |
| 1509 | } |
| 1510 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1511 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 1512 | return canonical_encoding_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1513 | } |
| 1514 | |
Shubhie Panicker | ddf2a4e | 2018-03-06 00:09:06 | [diff] [blame] | 1515 | void WebContentsImpl::SetWasDiscarded(bool was_discarded) { |
| 1516 | GetFrameTree()->root()->set_was_discarded(); |
| 1517 | } |
| 1518 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1519 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1520 | DCHECK(!is_being_destroyed_); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1521 | const bool was_captured = IsBeingCaptured(); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1522 | ++capturer_count_; |
| 1523 | DVLOG(1) << "There are now " << capturer_count_ |
| 1524 | << " capturing(s) of WebContentsImpl@" << this; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1525 | |
| 1526 | // Note: This provides a hint to upstream code to size the views optimally |
| 1527 | // for quality (e.g., to avoid scaling). |
| 1528 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1529 | preferred_size_for_capture_ = capture_size; |
| 1530 | OnPreferredSizeChanged(preferred_size_); |
| 1531 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1532 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1533 | if (GetVisibility() != Visibility::VISIBLE && !was_captured) { |
| 1534 | // Ensure that all views act as if they were visible before capture begins. |
| 1535 | // TODO(fdoray): Replace RenderWidgetHostView::WasUnOccluded() with a method |
| 1536 | // to explicitly notify the RenderWidgetHostView that capture began. |
| 1537 | // https://crbug.com/668690 |
| 1538 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) |
| 1539 | view->WasUnOccluded(); |
| 1540 | } |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1541 | } |
| 1542 | |
| 1543 | void WebContentsImpl::DecrementCapturerCount() { |
| 1544 | --capturer_count_; |
| 1545 | DVLOG(1) << "There are now " << capturer_count_ |
| 1546 | << " capturing(s) of WebContentsImpl@" << this; |
| 1547 | DCHECK_LE(0, capturer_count_); |
| 1548 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1549 | if (is_being_destroyed_) |
| 1550 | return; |
| 1551 | |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 1552 | if (!IsBeingCaptured()) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1553 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1554 | preferred_size_for_capture_ = gfx::Size(); |
| 1555 | OnPreferredSizeChanged(old_size); |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1556 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1557 | if (visibility_ == Visibility::HIDDEN) { |
Francois Doray | 1880097 | 2017-08-25 22:38:58 | [diff] [blame] | 1558 | DVLOG(1) << "Executing delayed WasHidden()."; |
| 1559 | WasHidden(); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1560 | } else if (visibility_ == Visibility::OCCLUDED) { |
Mitsuru Oshima | 04a8024 | 2018-03-03 03:06:15 | [diff] [blame] | 1561 | WasOccluded(); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1562 | } |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1563 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1564 | } |
| 1565 | |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 1566 | bool WebContentsImpl::IsBeingCaptured() const { |
| 1567 | return capturer_count_ > 0; |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1568 | } |
| 1569 | |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1570 | bool WebContentsImpl::IsAudioMuted() const { |
Max Morin | b5506f7 | 2018-05-16 07:33:10 | [diff] [blame] | 1571 | if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) { |
| 1572 | return audio_stream_factory_ && audio_stream_factory_->IsMuted(); |
| 1573 | } |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1574 | return audio_muter_.get() && audio_muter_->is_muting(); |
| 1575 | } |
| 1576 | |
| 1577 | void WebContentsImpl::SetAudioMuted(bool mute) { |
| 1578 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1579 | << " for WebContentsImpl@" << this; |
| 1580 | |
| 1581 | if (mute == IsAudioMuted()) |
| 1582 | return; |
| 1583 | |
Max Morin | b5506f7 | 2018-05-16 07:33:10 | [diff] [blame] | 1584 | if (base::FeatureList::IsEnabled(features::kAudioServiceAudioStreams)) { |
| 1585 | GetAudioStreamFactory()->SetMuted(mute); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1586 | } else { |
Max Morin | b5506f7 | 2018-05-16 07:33:10 | [diff] [blame] | 1587 | if (mute) { |
| 1588 | if (!audio_muter_) |
| 1589 | audio_muter_.reset(new WebContentsAudioMuter(this)); |
| 1590 | audio_muter_->StartMuting(); |
| 1591 | } else { |
| 1592 | DCHECK(audio_muter_); |
| 1593 | audio_muter_->StopMuting(); |
| 1594 | } |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1595 | } |
| 1596 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1597 | for (auto& observer : observers_) |
| 1598 | observer.DidUpdateAudioMutingState(mute); |
wjmaclean | 2f797c78 | 2016-01-07 14:52:03 | [diff] [blame] | 1599 | |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1600 | // Notification for UI updates in response to the changed muting state. |
| 1601 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 1602 | } |
| 1603 | |
| 1604 | bool WebContentsImpl::IsCurrentlyAudible() { |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1605 | return is_currently_audible_; |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1606 | } |
| 1607 | |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 1608 | bool WebContentsImpl::IsConnectedToBluetoothDevice() const { |
| 1609 | return bluetooth_connected_device_count_ > 0; |
ortuno | 32e7db3c | 2016-03-29 16:14:20 | [diff] [blame] | 1610 | } |
| 1611 | |
sawtelle | a7333a8 | 2018-05-31 02:36:36 | [diff] [blame] | 1612 | bool WebContentsImpl::HasPictureInPictureVideo() const { |
| 1613 | return has_picture_in_picture_video_; |
| 1614 | } |
| 1615 | |
| 1616 | void WebContentsImpl::SetHasPictureInPictureVideo( |
| 1617 | bool has_picture_in_picture_video) { |
| 1618 | // If status of |this| is already accurate, there is no need to update. |
| 1619 | if (has_picture_in_picture_video == has_picture_in_picture_video_) |
| 1620 | return; |
| 1621 | has_picture_in_picture_video_ = has_picture_in_picture_video; |
| 1622 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 1623 | } |
| 1624 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1625 | bool WebContentsImpl::IsCrashed() const { |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1626 | switch (crashed_status_) { |
| 1627 | case base::TERMINATION_STATUS_PROCESS_CRASHED: |
| 1628 | case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
| 1629 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
| 1630 | case base::TERMINATION_STATUS_OOM: |
| 1631 | case base::TERMINATION_STATUS_LAUNCH_FAILED: |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1632 | #if defined(OS_CHROMEOS) |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1633 | case base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM: |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1634 | #endif |
Dominic Mazzoni | 73a4832 | 2018-05-25 18:14:07 | [diff] [blame] | 1635 | #if defined(OS_ANDROID) |
| 1636 | case base::TERMINATION_STATUS_OOM_PROTECTED: |
| 1637 | #endif |
| 1638 | return true; |
| 1639 | case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
| 1640 | case base::TERMINATION_STATUS_STILL_RUNNING: |
| 1641 | return false; |
| 1642 | case base::TERMINATION_STATUS_MAX_ENUM: |
| 1643 | NOTREACHED(); |
| 1644 | return false; |
| 1645 | } |
| 1646 | |
| 1647 | NOTREACHED(); |
| 1648 | return false; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1649 | } |
| 1650 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1651 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1652 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1653 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1654 | return; |
| 1655 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1656 | crashed_status_ = status; |
| 1657 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1658 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1659 | } |
| 1660 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1661 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1662 | return crashed_status_; |
| 1663 | } |
| 1664 | |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 1665 | int WebContentsImpl::GetCrashedErrorCode() const { |
| 1666 | return crashed_error_code_; |
| 1667 | } |
| 1668 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1669 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1670 | return is_being_destroyed_; |
| 1671 | } |
| 1672 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1673 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1674 | InvalidateTypes changed_flags) { |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1675 | // Notify the media observer of potential audibility changes. |
| 1676 | if (changed_flags & INVALIDATE_TYPE_TAB) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1677 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1678 | } |
| 1679 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1680 | if (delegate_) |
| 1681 | delegate_->NavigationStateChanged(this, changed_flags); |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 1682 | |
| 1683 | if (GetOuterWebContents()) |
| 1684 | GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1685 | } |
| 1686 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1687 | void WebContentsImpl::OnAudioStateChanged() { |
| 1688 | // This notification can come from any embedded contents or from this |
| 1689 | // WebContents' stream monitor. Aggregate these signals to get the actual |
| 1690 | // state. |
| 1691 | bool is_currently_audible = |
| 1692 | audio_stream_monitor_.IsCurrentlyAudible() || |
| 1693 | (browser_plugin_embedder_ && |
| 1694 | browser_plugin_embedder_->AreAnyGuestsCurrentlyAudible()); |
| 1695 | if (is_currently_audible == is_currently_audible_) |
| 1696 | return; |
| 1697 | |
| 1698 | // Update internal state. |
| 1699 | is_currently_audible_ = is_currently_audible; |
| 1700 | was_ever_audible_ = was_ever_audible_ || is_currently_audible_; |
| 1701 | |
| 1702 | SendPageMessage( |
| 1703 | new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_currently_audible_)); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1704 | |
altimin | ec87fd1f | 2016-11-17 20:22:49 | [diff] [blame] | 1705 | // Notification for UI updates in response to the changed audio state. |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1706 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
Jan Rucka | 442c83f | 2017-08-08 13:27:54 | [diff] [blame] | 1707 | |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1708 | // Ensure that audio state changes propagate from innermost to outermost |
| 1709 | // WebContents. |
| 1710 | if (GetOuterWebContents()) |
| 1711 | GetOuterWebContents()->OnAudioStateChanged(); |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 1712 | |
Chris Hamilton | eb41198f | 2018-05-24 18:41:26 | [diff] [blame] | 1713 | for (auto& observer : observers_) |
Chris Hamilton | df0d72cd | 2018-05-29 16:23:53 | [diff] [blame] | 1714 | observer.OnAudioStateChanged(is_currently_audible_); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1715 | } |
| 1716 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1717 | base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 1718 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1719 | } |
| 1720 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 1721 | void WebContentsImpl::WasShown() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1722 | controller_.SetActive(true); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1723 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 1724 | if (auto* view = GetRenderWidgetHostView()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1725 | view->Show(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1726 | #if defined(OS_MACOSX) |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1727 | view->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1728 | #endif |
| 1729 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1730 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 1731 | if (!ShowingInterstitialPage()) |
| 1732 | SetVisibilityForChildViews(true); |
| 1733 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1734 | SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE)); |
| 1735 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1736 | last_active_time_ = base::TimeTicks::Now(); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1737 | SetVisibility(Visibility::VISIBLE); |
Lukasz Anforowicz | 873e608 | 2018-05-17 00:12:33 | [diff] [blame] | 1738 | |
| 1739 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1740 | RenderFrameProxyHost* parent = node->render_manager()->GetProxyToParent(); |
| 1741 | if (!parent) |
| 1742 | continue; |
| 1743 | |
| 1744 | if (parent->cross_process_frame_connector()->IsVisible()) { |
| 1745 | // MaybeLogCrash will check 1) if there was a crash or not and 2) if the |
| 1746 | // crash might have been already logged earlier as kCrashedWhileVisible. |
| 1747 | parent->cross_process_frame_connector()->MaybeLogCrash( |
| 1748 | CrossProcessFrameConnector::CrashVisibility::kShownAfterCrashing); |
| 1749 | } |
| 1750 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1751 | } |
| 1752 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1753 | void WebContentsImpl::WasHidden() { |
Jennifer Apacible | 72c3141 | 2018-06-19 16:52:24 | [diff] [blame] | 1754 | // If there are entities capturing screenshots or video (e.g. mirroring), |
| 1755 | // or in Picture-in-Picture mode, don't activate the "disable rendering" |
| 1756 | // optimization. |
| 1757 | if (!IsBeingCaptured() && !HasPictureInPictureVideo()) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1758 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1759 | // open a tab in the background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1760 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1761 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1762 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1763 | // calls us). |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 1764 | if (auto* view = GetRenderWidgetHostView()) |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1765 | view->Hide(); |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1766 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 1767 | if (!ShowingInterstitialPage()) |
Igor Eremeev | ef59187a | 2017-09-29 00:25:42 | [diff] [blame] | 1768 | SetVisibilityForChildViews(false); |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 1769 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1770 | SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1771 | } |
| 1772 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1773 | SetVisibility(Visibility::HIDDEN); |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 1774 | } |
| 1775 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 1776 | bool WebContentsImpl::HasRecentInteractiveInputEvent() const { |
| 1777 | static constexpr base::TimeDelta kMaxInterval = |
| 1778 | base::TimeDelta::FromSeconds(5); |
| 1779 | base::TimeDelta delta = |
| 1780 | ui::EventTimeForNow() - last_interactive_input_event_time_; |
| 1781 | // Note: the expectation is that the caller is typically expecting an input |
| 1782 | // event, e.g. validating that a WebUI message that requires a gesture is |
| 1783 | // actually attached to a gesture. Logging to UMA here should hopefully give |
| 1784 | // sufficient data if 5 seconds is actually sufficient (or even too high a |
| 1785 | // threshhold). |
| 1786 | UMA_HISTOGRAM_TIMES("Tabs.TimeSinceLastInteraction", delta); |
| 1787 | return delta <= kMaxInterval; |
| 1788 | } |
| 1789 | |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 1790 | #if defined(OS_ANDROID) |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 1791 | void WebContentsImpl::SetMainFrameImportance( |
| 1792 | ChildProcessImportance importance) { |
| 1793 | GetMainFrame()->GetRenderWidgetHost()->SetImportance(importance); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1794 | if (ShowingInterstitialPage()) { |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 1795 | static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame()) |
| 1796 | ->GetRenderWidgetHost() |
| 1797 | ->SetImportance(importance); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1798 | } |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1799 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 1800 | #endif |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 1801 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1802 | void WebContentsImpl::WasOccluded() { |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 1803 | if (!IsBeingCaptured()) { |
Francois Doray | 1880097 | 2017-08-25 22:38:58 | [diff] [blame] | 1804 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) |
| 1805 | view->WasOccluded(); |
| 1806 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1807 | SetVisibility(Visibility::OCCLUDED); |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1808 | } |
| 1809 | |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 1810 | Visibility WebContentsImpl::GetVisibility() const { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1811 | return visibility_; |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 1812 | } |
| 1813 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1814 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1815 | // TODO(creis): Should we fire even for interstitial pages? |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1816 | return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
jam | 4044498 | 2017-04-11 03:01:41 | [diff] [blame] | 1817 | !GetRenderViewHost()->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1818 | } |
| 1819 | |
nasko | 148bb0b9 | 2016-05-10 21:03:19 | [diff] [blame] | 1820 | void WebContentsImpl::DispatchBeforeUnload() { |
| 1821 | bool for_cross_site_transition = false; |
clamy | bfd6a81 | 2016-05-30 16:25:17 | [diff] [blame] | 1822 | GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1823 | } |
| 1824 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1825 | void WebContentsImpl::AttachToOuterWebContentsFrame( |
| 1826 | WebContents* outer_web_contents, |
| 1827 | RenderFrameHost* outer_contents_frame) { |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 1828 | DCHECK(!node_.outer_web_contents()); |
| 1829 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1830 | RenderFrameHostManager* render_manager = GetRenderManager(); |
| 1831 | |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 1832 | // When attaching a WebContents as an inner WebContents, we need to replace |
| 1833 | // the Webcontents' view with a WebContentsViewChildFrame. |
| 1834 | view_.reset(new WebContentsViewChildFrame( |
| 1835 | this, GetContentClient()->browser()->GetWebContentsViewDelegate(this), |
| 1836 | &render_view_host_delegate_view_)); |
| 1837 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1838 | // When the WebContents being initialized has an opener, the browser side |
| 1839 | // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
| 1840 | // created. This is needed because the usual initialization happens during |
| 1841 | // the first navigation, but when attaching a new window we don't navigate |
| 1842 | // before attaching. If the browser side is already initialized, the calls |
| 1843 | // below will just early return. |
| 1844 | render_manager->InitRenderView(GetRenderViewHost(), nullptr); |
| 1845 | GetMainFrame()->Init(); |
| 1846 | if (!render_manager->GetRenderWidgetHostView()) |
| 1847 | CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost()); |
| 1848 | |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1849 | auto* outer_web_contents_impl = |
| 1850 | static_cast<WebContentsImpl*>(outer_web_contents); |
| 1851 | auto* outer_contents_frame_impl = |
| 1852 | static_cast<RenderFrameHostImpl*>(outer_contents_frame); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1853 | // Create a link to our outer WebContents. |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1854 | node_.ConnectToOuterWebContents(outer_web_contents_impl, |
| 1855 | outer_contents_frame_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1856 | |
| 1857 | DCHECK(outer_contents_frame); |
| 1858 | |
| 1859 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 1860 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 1861 | // postMessage to the inner WebContents. |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1862 | render_manager->CreateOuterDelegateProxy( |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1863 | outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1864 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 1865 | ReattachToOuterWebContentsFrame(); |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 1866 | |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1867 | if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() == |
| 1868 | outer_contents_frame_impl->frame_tree_node()) { |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 1869 | SetFocusedFrame(frame_tree_.root(), |
| 1870 | outer_contents_frame->GetSiteInstance()); |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1871 | } |
| 1872 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 1873 | // At this point, we should destroy the TextInputManager which will notify all |
| 1874 | // the RWHV in this WebContents. The RWHV in this WebContents should use the |
| 1875 | // TextInputManager owned by the outer WebContents. |
| 1876 | // TODO(ekaramad): Is it possible to have TextInputState before attaching to |
| 1877 | // outer WebContents? In such a case, is this still the right way to hand off |
| 1878 | // state tracking from inner WebContents's TextInputManager to that of the |
| 1879 | // outer WebContent (crbug.com/609846)? |
| 1880 | text_input_manager_.reset(nullptr); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1881 | } |
| 1882 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 1883 | void WebContentsImpl::ReattachToOuterWebContentsFrame() { |
| 1884 | DCHECK(node_.outer_web_contents()); |
| 1885 | auto* render_manager = GetRenderManager(); |
| 1886 | auto* parent_frame = |
| 1887 | node_.OuterContentsFrameTreeNode()->current_frame_host()->GetParent(); |
| 1888 | render_manager->SetRWHViewForInnerContents( |
| 1889 | render_manager->GetRenderWidgetHostView()); |
| 1890 | |
| 1891 | static_cast<RenderWidgetHostViewChildFrame*>( |
| 1892 | render_manager->GetRenderWidgetHostView()) |
| 1893 | ->RegisterFrameSinkId(); |
| 1894 | |
| 1895 | // Set up the the guest's AX tree to point back at the embedder's AX tree. |
| 1896 | GetMainFrame()->set_browser_plugin_embedder_ax_tree_id( |
| 1897 | parent_frame->GetAXTreeID()); |
| 1898 | GetMainFrame()->UpdateAXTreeData(); |
| 1899 | } |
| 1900 | |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 1901 | void WebContentsImpl::DidChangeVisibleSecurityState() { |
| 1902 | if (delegate_) { |
| 1903 | delegate_->VisibleSecurityStateChanged(this); |
cjgrant | 6d1d727a | 2016-12-09 21:16:57 | [diff] [blame] | 1904 | for (auto& observer : observers_) |
| 1905 | observer.DidChangeVisibleSecurityState(); |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 1906 | } |
| 1907 | } |
| 1908 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1909 | void WebContentsImpl::NotifyPreferencesChanged() { |
| 1910 | std::set<RenderViewHost*> render_view_host_set; |
| 1911 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
Giovanni Ortuño Urquidi | 17a5d7c | 2018-04-30 06:48:53 | [diff] [blame] | 1912 | render_view_host_set.insert( |
| 1913 | node->current_frame_host()->GetRenderViewHost()); |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1914 | } |
Giovanni Ortuño Urquidi | 17a5d7c | 2018-04-30 06:48:53 | [diff] [blame] | 1915 | |
Ahmed Fakhry | d70bf37b | 2018-04-04 17:07:24 | [diff] [blame] | 1916 | for (RenderViewHost* render_view_host : render_view_host_set) |
| 1917 | render_view_host->OnWebkitPreferencesChanged(); |
| 1918 | } |
| 1919 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1920 | void WebContentsImpl::Stop() { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1921 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 1922 | node->StopLoading(); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1923 | for (auto& observer : observers_) |
| 1924 | observer.NavigationStopped(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1925 | } |
| 1926 | |
Francois Doray | 47f759d | 2018-06-11 18:13:51 | [diff] [blame] | 1927 | void WebContentsImpl::SetPageFrozen(bool frozen) { |
| 1928 | // A visible page is never frozen. |
| 1929 | DCHECK_NE(Visibility::VISIBLE, GetVisibility()); |
| 1930 | |
| 1931 | SendPageMessage(new PageMsg_SetPageFrozen(MSG_ROUTING_NONE, frozen)); |
Fadi Meawad | a6573e0 | 2018-03-10 00:52:11 | [diff] [blame] | 1932 | } |
| 1933 | |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 1934 | std::unique_ptr<WebContents> WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1935 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1936 | // We pass our own opener so that the cloned page can access it if it was set |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 1937 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1938 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1939 | create_params.initial_size = GetContainerBounds().size(); |
Ian Clelland | 5cbaaf8 | 2017-11-27 22:00:03 | [diff] [blame] | 1940 | FrameTreeNode* opener = frame_tree_.root()->opener(); |
| 1941 | RenderFrameHostImpl* opener_rfh = nullptr; |
| 1942 | if (opener) |
| 1943 | opener_rfh = opener->current_frame_host(); |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 1944 | std::unique_ptr<WebContentsImpl> tc = |
erikchen | 50735fd | 2018-05-05 15:08:33 | [diff] [blame] | 1945 | CreateWithOpener(create_params, opener_rfh); |
Francois Doray | eaace78 | 2017-06-21 16:37:24 | [diff] [blame] | 1946 | tc->GetController().CopyStateFrom(controller_, true); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1947 | for (auto& observer : observers_) |
erikchen | 6c7df7f7a | 2018-05-03 18:13:59 | [diff] [blame] | 1948 | observer.DidCloneToNewWebContents(this, tc.get()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1949 | return tc; |
| 1950 | } |
| 1951 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1952 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1953 | const NotificationSource& source, |
| 1954 | const NotificationDetails& details) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1955 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1956 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1957 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1958 | RenderWidgetHostView* view = host->GetView(); |
| 1959 | if (view == GetFullscreenRenderWidgetHostView()) { |
| 1960 | // We cannot just call view_->RestoreFocus() here. On some platforms, |
| 1961 | // attempting to focus the currently-invisible WebContentsView will be |
| 1962 | // flat-out ignored. Therefore, this boolean is used to track whether |
| 1963 | // we will request focus after the fullscreen widget has been |
| 1964 | // destroyed. |
| 1965 | fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
| 1966 | } else { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 1967 | for (auto i = pending_widget_views_.begin(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1968 | i != pending_widget_views_.end(); ++i) { |
| 1969 | if (host->GetView() == i->second) { |
| 1970 | pending_widget_views_.erase(i); |
| 1971 | break; |
| 1972 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1973 | } |
| 1974 | } |
| 1975 | break; |
| 1976 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1977 | default: |
| 1978 | NOTREACHED(); |
| 1979 | } |
| 1980 | } |
| 1981 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 1982 | WebContents* WebContentsImpl::GetWebContents() { |
| 1983 | return this; |
| 1984 | } |
| 1985 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1986 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1987 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1988 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1989 | // it should be hidden. |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 1990 | visibility_ = |
| 1991 | params.initially_hidden ? Visibility::HIDDEN : Visibility::VISIBLE; |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1992 | |
Sebastien Marchand | 28cf2318 | 2018-06-20 02:39:35 | [diff] [blame] | 1993 | if (!params.last_active_time.is_null()) |
| 1994 | last_active_time_ = params.last_active_time; |
| 1995 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1996 | // The routing ids must either all be set or all be unset. |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1997 | DCHECK((params.routing_id == MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1998 | params.main_frame_routing_id == MSG_ROUTING_NONE && |
| 1999 | params.main_frame_widget_routing_id == MSG_ROUTING_NONE) || |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 2000 | (params.routing_id != MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2001 | params.main_frame_routing_id != MSG_ROUTING_NONE && |
| 2002 | params.main_frame_widget_routing_id != MSG_ROUTING_NONE)); |
| 2003 | |
| 2004 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 2005 | if (!site_instance) |
| 2006 | site_instance = SiteInstance::Create(params.browser_context); |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2007 | if (params.desired_renderer_state == CreateParams::kNoRendererProcess) { |
| 2008 | static_cast<SiteInstanceImpl*>(site_instance.get()) |
| 2009 | ->PreventAssociationWithSpareProcess(); |
| 2010 | } |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2011 | |
| 2012 | // A main RenderFrameHost always has a RenderWidgetHost, since it is always a |
| 2013 | // local root by definition. |
| 2014 | // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no |
| 2015 | // longer be necessary to eagerly grab a routing ID for the view. |
| 2016 | // https://crbug.com/545684 |
| 2017 | int32_t view_routing_id = params.routing_id; |
| 2018 | int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id; |
| 2019 | if (main_frame_widget_routing_id == MSG_ROUTING_NONE) { |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 2020 | view_routing_id = site_instance->GetProcess()->GetNextRoutingID(); |
| 2021 | main_frame_widget_routing_id = |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2022 | site_instance->GetProcess()->GetNextRoutingID(); |
| 2023 | } |
| 2024 | |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 2025 | DCHECK_NE(view_routing_id, main_frame_widget_routing_id); |
| 2026 | |
Dave Tapuska | 485aca9 | 2017-08-08 00:47:58 | [diff] [blame] | 2027 | GetRenderManager()->Init( |
| 2028 | site_instance.get(), view_routing_id, params.main_frame_routing_id, |
| 2029 | main_frame_widget_routing_id, params.renderer_initiated_creation); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2030 | |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 2031 | // blink::FrameTree::setName always keeps |unique_name| empty in case of a |
| 2032 | // main frame - let's do the same thing here. |
| 2033 | std::string unique_name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 2034 | frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2035 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2036 | WebContentsViewDelegate* delegate = |
| 2037 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 2038 | |
sky | 52a39e34 | 2016-12-17 17:23:22 | [diff] [blame] | 2039 | if (GuestMode::IsCrossProcessFrameGuest(this)) { |
| 2040 | view_.reset(new WebContentsViewChildFrame( |
| 2041 | this, delegate, &render_view_host_delegate_view_)); |
| 2042 | } else { |
| 2043 | view_.reset(CreateWebContentsView(this, delegate, |
| 2044 | &render_view_host_delegate_view_)); |
Scott Violet | c884c7fd | 2017-11-03 23:51:01 | [diff] [blame] | 2045 | if (browser_plugin_guest_) { |
| 2046 | view_ = std::make_unique<WebContentsViewGuest>( |
| 2047 | this, browser_plugin_guest_.get(), std::move(view_), |
| 2048 | &render_view_host_delegate_view_); |
| 2049 | } |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2050 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2051 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2052 | CHECK(view_.get()); |
| 2053 | |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 2054 | gfx::Size initial_size = params.initial_size; |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2055 | view_->CreateView(initial_size, params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2056 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 2057 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 2058 | plugin_content_origin_whitelist_.reset( |
| 2059 | new PluginContentOriginWhitelist(this)); |
| 2060 | #endif |
| 2061 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2062 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2063 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 2064 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 2065 | |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 2066 | screen_orientation_provider_.reset(new ScreenOrientationProvider(this)); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 2067 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 2068 | manifest_manager_host_.reset(new ManifestManagerHost(this)); |
| 2069 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 2070 | #if defined(OS_ANDROID) |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 2071 | date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 2072 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 2073 | |
| 2074 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
| 2075 | // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
| 2076 | if (browser_plugin_guest_) |
| 2077 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 2078 | |
| 2079 | for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 2080 | g_created_callbacks.Get().at(i).Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2081 | |
| 2082 | // If the WebContents creation was renderer-initiated, it means that the |
| 2083 | // corresponding RenderView and main RenderFrame have already been created. |
| 2084 | // Ensure observers are notified about this. |
| 2085 | if (params.renderer_initiated_creation) { |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2086 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 2087 | GetRenderViewHost()->DispatchRenderViewCreated(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 2088 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 2089 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2090 | |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2091 | // Create the renderer process in advance if requested. |
Lukasz Anforowicz | 3caa837 | 2018-06-05 17:22:07 | [diff] [blame] | 2092 | if (params.desired_renderer_state == |
| 2093 | CreateParams::kInitializeAndWarmupRendererProcess) { |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 2094 | if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) { |
| 2095 | GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
| 2096 | } |
| 2097 | } |
| 2098 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 2099 | // Ensure that observers are notified of the creation of this WebContents's |
| 2100 | // main RenderFrameHost. It must be done here for main frames, since the |
| 2101 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 2102 | // happens after RenderFrameHostManager::Init. |
| 2103 | NotifySwappedFromRenderManager( |
| 2104 | nullptr, GetRenderManager()->current_frame_host(), true); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2105 | } |
| 2106 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2107 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 2108 | RemoveDestructionObserver(web_contents); |
| 2109 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2110 | // Clear a pending contents that has been closed before being shown. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2111 | for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2112 | ++iter) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2113 | if (iter->second.get() != web_contents) |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2114 | continue; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2115 | |
| 2116 | // Someone else has deleted the WebContents. That should never happen! |
| 2117 | // TODO(erikchen): Fix semantics here. https://crbug.com/832879. |
| 2118 | iter->second.release(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2119 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 2120 | return; |
| 2121 | } |
| 2122 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2123 | } |
| 2124 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2125 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
| 2126 | if (!ContainsKey(destruction_observers_, web_contents)) { |
| 2127 | destruction_observers_[web_contents] = |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 2128 | std::make_unique<DestructionObserver>(this, web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2129 | } |
| 2130 | } |
| 2131 | |
| 2132 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 2133 | destruction_observers_.erase(web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2134 | } |
| 2135 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2136 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2137 | observers_.AddObserver(observer); |
| 2138 | } |
| 2139 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2140 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2141 | observers_.RemoveObserver(observer); |
| 2142 | } |
| 2143 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2144 | std::set<RenderWidgetHostView*> |
| 2145 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 2146 | std::set<RenderWidgetHostView*> set; |
| 2147 | if (ShowingInterstitialPage()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 2148 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) |
| 2149 | set.insert(rwhv); |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2150 | } else { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 2151 | for (RenderFrameHost* rfh : GetAllFrames()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 2152 | if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 2153 | ->frame_tree_node() |
| 2154 | ->render_manager() |
| 2155 | ->GetRenderWidgetHostView()) { |
| 2156 | set.insert(rwhv); |
| 2157 | } |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 2158 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 2159 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 2160 | return set; |
| 2161 | } |
| 2162 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2163 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2164 | if (delegate_) |
| 2165 | delegate_->ActivateContents(this); |
| 2166 | } |
| 2167 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2168 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
| 2169 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 2170 | return; |
| 2171 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2172 | if (delegate_) |
| 2173 | delegate_->LostCapture(); |
| 2174 | } |
| 2175 | |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 2176 | ukm::SourceId WebContentsImpl::GetUkmSourceIdForLastCommittedSource() const { |
| 2177 | return last_committed_source_id_; |
| 2178 | } |
| 2179 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2180 | void WebContentsImpl::RenderWidgetCreated( |
| 2181 | RenderWidgetHostImpl* render_widget_host) { |
| 2182 | created_widgets_.insert(render_widget_host); |
| 2183 | } |
| 2184 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2185 | void WebContentsImpl::RenderWidgetDeleted( |
| 2186 | RenderWidgetHostImpl* render_widget_host) { |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2187 | // Note that |is_being_destroyed_| can be true at this point as |
| 2188 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 2189 | // us here. |
| 2190 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2191 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 2192 | if (is_being_destroyed_) |
| 2193 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2194 | |
| 2195 | if (render_widget_host && |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2196 | render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ && |
| 2197 | render_widget_host->GetProcess()->GetID() == |
| 2198 | fullscreen_widget_process_id_) { |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2199 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2200 | delegate_->ExitFullscreenModeForTab(this); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2201 | for (auto& observer : observers_) |
| 2202 | observer.DidDestroyFullscreenWidget(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2203 | fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2204 | fullscreen_widget_routing_id_ = MSG_ROUTING_NONE; |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2205 | if (fullscreen_widget_had_focus_at_shutdown_) |
| 2206 | view_->RestoreFocus(); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 2207 | } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2208 | |
lfg | 7d4caad | 2017-03-22 09:01:45 | [diff] [blame] | 2209 | if (render_widget_host == mouse_lock_widget_) |
lfg | ff8dfc8d | 2016-10-21 17:42:32 | [diff] [blame] | 2210 | LostMouseLock(mouse_lock_widget_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2211 | |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 2212 | CancelKeyboardLock(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2213 | } |
| 2214 | |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2215 | void WebContentsImpl::RenderWidgetGotFocus( |
| 2216 | RenderWidgetHostImpl* render_widget_host) { |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2217 | // Notify the observers if an embedded fullscreen widget was focused. |
| 2218 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 2219 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 2220 | NotifyWebContentsFocused(render_widget_host); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2221 | } |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2222 | } |
| 2223 | |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 2224 | void WebContentsImpl::RenderWidgetLostFocus( |
| 2225 | RenderWidgetHostImpl* render_widget_host) { |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 2226 | // Notify the observers if an embedded fullscreen widget lost focus. |
| 2227 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 2228 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
| 2229 | NotifyWebContentsLostFocus(render_widget_host); |
| 2230 | } |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 2231 | } |
| 2232 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2233 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 2234 | RenderWidgetHostImpl* render_widget_host, |
Christopher Cameron | 07f666b | 2018-02-13 23:41:19 | [diff] [blame] | 2235 | const ScreenInfo& screen_info, |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 2236 | bool width_changed) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2237 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 2238 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2239 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2240 | |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 2241 | SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info)); |
| 2242 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2243 | for (auto& observer : observers_) |
| 2244 | observer.MainFrameWasResized(width_changed); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 2245 | } |
| 2246 | |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 2247 | KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent( |
| 2248 | const NativeWebKeyboardEvent& event) { |
| 2249 | return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event) |
| 2250 | : KeyboardEventProcessingResult::NOT_HANDLED; |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2251 | } |
| 2252 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2253 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 2254 | if (browser_plugin_embedder_ && |
| 2255 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
| 2256 | return; |
| 2257 | } |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2258 | if (delegate_) |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 2259 | delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 2260 | } |
| 2261 | |
[email protected] | d92026ef | 2014-03-03 21:04:13 | [diff] [blame] | 2262 | bool WebContentsImpl::HandleWheelEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2263 | const blink::WebMouseWheelEvent& event) { |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 2264 | #if !defined(OS_MACOSX) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 2265 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 2266 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 2267 | // -the OS already has a gesture to do this through pinch-zoom |
| 2268 | // -if a user starts an inertial scroll, let's go, and presses control |
| 2269 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 2270 | // with control key set which isn't what the user wants |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2271 | if (delegate_ && event.wheel_ticks_y && |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 2272 | !ui::WebInputEventTraits::CanCauseScroll(event)) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 2273 | // Count only integer cumulative scrolls as zoom events; this handles |
| 2274 | // smooth scroll and regular scroll device behavior. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2275 | zoom_scroll_remainder_ += event.wheel_ticks_y; |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 2276 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 2277 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 2278 | if (whole_zoom_scroll_remainder_ != 0) { |
| 2279 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 2280 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 2281 | return true; |
| 2282 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 2283 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 2284 | return false; |
| 2285 | } |
| 2286 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 2287 | bool WebContentsImpl::PreHandleGestureEvent( |
| 2288 | const blink::WebGestureEvent& event) { |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 2289 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 2290 | } |
| 2291 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 2292 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 2293 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 2294 | return GetOuterWebContents()->GetInputEventRouter(); |
| 2295 | |
| 2296 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 2297 | rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter); |
| 2298 | return rwh_input_event_router_.get(); |
| 2299 | } |
| 2300 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 2301 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
| 2302 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 2303 | // send the message in this case, as the main frame's RenderFrameHost and |
| 2304 | // other state has already been cleared. |
| 2305 | if (is_being_destroyed_) |
| 2306 | return; |
| 2307 | |
| 2308 | frame_tree_.ReplicatePageFocus(is_focused); |
| 2309 | } |
| 2310 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2311 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 2312 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2313 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 2314 | // forwarded directly to the widget they arrived on. |
| 2315 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 2316 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2317 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2318 | WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 2319 | |
| 2320 | // If the focused WebContents is showing an interstitial, return the |
| 2321 | // interstitial's widget. |
| 2322 | if (focused_contents->ShowingInterstitialPage()) { |
| 2323 | return static_cast<RenderFrameHostImpl*>( |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 2324 | focused_contents->interstitial_page_->GetMainFrame()) |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2325 | ->GetRenderWidgetHost(); |
| 2326 | } |
| 2327 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 2328 | // If the focused WebContents is a guest WebContents, then get the focused |
| 2329 | // frame in the embedder WebContents instead. |
| 2330 | FrameTreeNode* focused_frame = nullptr; |
| 2331 | if (focused_contents->browser_plugin_guest_ && |
| 2332 | !GuestMode::IsCrossProcessFrameGuest(focused_contents)) { |
| 2333 | focused_frame = frame_tree_.GetFocusedFrame(); |
| 2334 | } else { |
| 2335 | focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
| 2336 | } |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2337 | |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2338 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 2339 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2340 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 2341 | // The view may be null if a subframe's renderer process has crashed while |
| 2342 | // the subframe has focus. Drop the event in that case. Do not give |
| 2343 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 2344 | // wrong frame if a focused subframe renderer crashes while they type. |
| 2345 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 2346 | if (!view) |
| 2347 | return nullptr; |
| 2348 | |
| 2349 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 2350 | } |
| 2351 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 2352 | RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2353 | WebContentsImpl* focused_web_contents = GetFocusedWebContents(); |
| 2354 | |
| 2355 | if (focused_web_contents->ShowingInterstitialPage()) { |
| 2356 | return static_cast<RenderFrameHostImpl*>( |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 2357 | focused_web_contents->interstitial_page_->GetMainFrame()) |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2358 | ->GetRenderWidgetHost(); |
| 2359 | } |
Alex Vallée | dc80ae2ed | 2017-09-06 21:55:44 | [diff] [blame] | 2360 | if (!GuestMode::IsCrossProcessFrameGuest(focused_web_contents) && |
| 2361 | focused_web_contents->browser_plugin_guest_) { |
| 2362 | // If this is a guest, we need to be controlled by our embedder. |
| 2363 | return focused_web_contents->GetOuterWebContents() |
| 2364 | ->GetMainFrame() |
| 2365 | ->GetRenderWidgetHost(); |
| 2366 | } |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2367 | |
| 2368 | return focused_web_contents->GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 2369 | } |
| 2370 | |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 2371 | void WebContentsImpl::EnterFullscreenMode( |
| 2372 | const GURL& origin, |
| 2373 | const blink::WebFullscreenOptions& options) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2374 | // This method is being called to enter renderer-initiated fullscreen mode. |
| 2375 | // Make sure any existing fullscreen widget is shut down first. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2376 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2377 | if (widget_view) { |
| 2378 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2379 | ->ShutdownAndDestroyWidget(true); |
| 2380 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2381 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2382 | if (delegate_) { |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 2383 | delegate_->EnterFullscreenModeForTab(this, origin, options); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2384 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2385 | if (keyboard_lock_widget_) |
| 2386 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
| 2387 | } |
| 2388 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2389 | for (auto& observer : observers_) |
| 2390 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2391 | } |
| 2392 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2393 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2394 | // This method is being called to leave renderer-initiated fullscreen mode. |
| 2395 | // Make sure any existing fullscreen widget is shut down first. |
| 2396 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2397 | if (widget_view) { |
| 2398 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2399 | ->ShutdownAndDestroyWidget(true); |
| 2400 | } |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2401 | |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 2402 | #if defined(OS_ANDROID) |
| 2403 | ContentVideoView* video_view = ContentVideoView::GetInstance(); |
| 2404 | if (video_view != NULL) |
watk | 9829229 | 2016-01-19 22:24:08 | [diff] [blame] | 2405 | video_view->ExitFullscreen(); |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 2406 | #endif |
| 2407 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2408 | if (delegate_) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2409 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 2410 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2411 | if (keyboard_lock_widget_) |
| 2412 | delegate_->CancelKeyboardLockRequest(this); |
| 2413 | } |
| 2414 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2415 | // The fullscreen state is communicated to the renderer through a resize |
| 2416 | // message. If the change in fullscreen state doesn't cause a view resize |
| 2417 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 2418 | // sending a resize message. This is required for the situation of the browser |
| 2419 | // moving the view into a "browser fullscreen" state and then the contents |
| 2420 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 2421 | // have the side effect of the view resizing, hence the explicit call here is |
| 2422 | // required. |
| 2423 | if (!will_cause_resize) { |
| 2424 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 2425 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 2426 | render_widget_host->SynchronizeVisualProperties(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2427 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 2428 | } |
| 2429 | |
Becca Hughes | e9e2795 | 2018-06-25 17:08:27 | [diff] [blame] | 2430 | // Clear the current fullscreen frame ID. |
| 2431 | current_fullscreen_frame_tree_node_id_ = RenderFrameHost::kNoFrameTreeNodeId; |
| 2432 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2433 | for (auto& observer : observers_) { |
| 2434 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), |
| 2435 | will_cause_resize); |
| 2436 | } |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 2437 | } |
| 2438 | |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 2439 | void WebContentsImpl::FullscreenStateChanged(RenderFrameHost* rfh, |
| 2440 | bool is_fullscreen) { |
| 2441 | int frame_tree_node_id = rfh->GetFrameTreeNodeId(); |
| 2442 | auto it = fullscreen_frame_tree_nodes_.find(frame_tree_node_id); |
| 2443 | bool changed = false; |
| 2444 | |
| 2445 | if (is_fullscreen) { |
| 2446 | // If we are fullscreen then add the FrameTreeNode ID to the set. |
| 2447 | if (it == fullscreen_frame_tree_nodes_.end()) { |
| 2448 | fullscreen_frame_tree_nodes_.insert(frame_tree_node_id); |
| 2449 | changed = true; |
| 2450 | } |
| 2451 | } else { |
| 2452 | FrameTreeNode* ancestor = |
| 2453 | static_cast<RenderFrameHostImpl*>(rfh)->frame_tree_node(); |
| 2454 | DCHECK(ancestor); |
| 2455 | |
| 2456 | // If we are not fullscreen then remove this frame and any descendants |
| 2457 | // from the set. |
| 2458 | for (it = fullscreen_frame_tree_nodes_.begin(); |
| 2459 | it != fullscreen_frame_tree_nodes_.end();) { |
| 2460 | FrameTreeNode* node = FrameTreeNode::GloballyFindByID(*it); |
| 2461 | |
| 2462 | if (!node || frame_tree_node_id == *it || |
| 2463 | node->IsDescendantOf(ancestor)) { |
| 2464 | it = fullscreen_frame_tree_nodes_.erase(it); |
| 2465 | changed = true; |
| 2466 | } else { |
| 2467 | ++it; |
| 2468 | } |
| 2469 | } |
| 2470 | } |
| 2471 | |
| 2472 | // If we have changed then find the current fullscreen FrameTreeNode |
| 2473 | // and call the observers. If we have exited fullscreen then this |
| 2474 | // will be the last frame that was fullscreen. |
| 2475 | if (changed && fullscreen_frame_tree_nodes_.size() > 0) { |
| 2476 | unsigned int max_depth = 0; |
| 2477 | RenderFrameHost* max_depth_rfh = nullptr; |
| 2478 | |
| 2479 | for (auto node_id : fullscreen_frame_tree_nodes_) { |
| 2480 | FrameTreeNode* fullscreen_node = FrameTreeNode::GloballyFindByID(node_id); |
| 2481 | DCHECK(fullscreen_node); |
| 2482 | |
| 2483 | if (max_depth_rfh == nullptr || fullscreen_node->depth() > max_depth) { |
| 2484 | max_depth = fullscreen_node->depth(); |
| 2485 | max_depth_rfh = fullscreen_node->current_frame_host(); |
| 2486 | } |
| 2487 | } |
| 2488 | |
| 2489 | // If we have already notified observers about this frame then we should not |
| 2490 | // fire the observers again. |
| 2491 | DCHECK(max_depth_rfh); |
| 2492 | if (max_depth_rfh->GetFrameTreeNodeId() == |
| 2493 | current_fullscreen_frame_tree_node_id_) |
| 2494 | return; |
| 2495 | |
| 2496 | current_fullscreen_frame_tree_node_id_ = |
| 2497 | max_depth_rfh->GetFrameTreeNodeId(); |
| 2498 | |
| 2499 | for (auto& observer : observers_) |
| 2500 | observer.DidAcquireFullscreen(max_depth_rfh); |
| 2501 | } else if (fullscreen_frame_tree_nodes_.size() == 0) { |
| 2502 | current_fullscreen_frame_tree_node_id_ = |
| 2503 | RenderFrameHost::kNoFrameTreeNodeId; |
| 2504 | } |
| 2505 | } |
| 2506 | |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 2507 | bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 2508 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 2509 | } |
| 2510 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 2511 | bool WebContentsImpl::IsFullscreen() { |
| 2512 | return IsFullscreenForCurrentTab(); |
| 2513 | } |
| 2514 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 2515 | blink::WebDisplayMode WebContentsImpl::GetDisplayMode( |
| 2516 | RenderWidgetHostImpl* render_widget_host) const { |
| 2517 | if (!RenderViewHostImpl::From(render_widget_host)) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2518 | return blink::kWebDisplayModeBrowser; |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 2519 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 2520 | return delegate_ ? delegate_->GetDisplayMode(this) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2521 | : blink::kWebDisplayModeBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 2522 | } |
| 2523 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2524 | void WebContentsImpl::RequestToLockMouse( |
| 2525 | RenderWidgetHostImpl* render_widget_host, |
| 2526 | bool user_gesture, |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2527 | bool last_unlocked_by_target, |
| 2528 | bool privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2529 | for (WebContentsImpl* current = this; current; |
| 2530 | current = current->GetOuterWebContents()) { |
| 2531 | if (current->mouse_lock_widget_) { |
| 2532 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 2533 | return; |
| 2534 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2535 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2536 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2537 | if (privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2538 | DCHECK(!GetOuterWebContents()); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2539 | mouse_lock_widget_ = render_widget_host; |
| 2540 | render_widget_host->GotResponseToLockMouseRequest(true); |
| 2541 | return; |
| 2542 | } |
| 2543 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2544 | bool widget_in_frame_tree = false; |
| 2545 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 2546 | if (node->current_frame_host()->GetRenderWidgetHost() == |
| 2547 | render_widget_host) { |
| 2548 | widget_in_frame_tree = true; |
| 2549 | break; |
| 2550 | } |
| 2551 | } |
| 2552 | |
| 2553 | if (widget_in_frame_tree && delegate_) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2554 | for (WebContentsImpl* current = this; current; |
| 2555 | current = current->GetOuterWebContents()) { |
| 2556 | current->mouse_lock_widget_ = render_widget_host; |
| 2557 | } |
| 2558 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2559 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2560 | } else { |
| 2561 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 2562 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2563 | } |
| 2564 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2565 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2566 | CHECK(mouse_lock_widget_); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2567 | |
| 2568 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) |
| 2569 | return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host); |
| 2570 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2571 | mouse_lock_widget_->SendMouseLockLost(); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2572 | for (WebContentsImpl* current = this; current; |
| 2573 | current = current->GetOuterWebContents()) { |
| 2574 | current->mouse_lock_widget_ = nullptr; |
| 2575 | } |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2576 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2577 | if (delegate_) |
| 2578 | delegate_->LostMouseLock(); |
| 2579 | } |
| 2580 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2581 | bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 2582 | // To verify if the mouse is locked, the mouse_lock_widget_ needs to be |
| 2583 | // assigned to the widget that requested the mouse lock, and the top-level |
| 2584 | // platform RenderWidgetHostView needs to hold the mouse lock from the OS. |
| 2585 | return mouse_lock_widget_ == render_widget_host && |
| 2586 | GetTopLevelRenderWidgetHostView()->IsMouseLocked(); |
| 2587 | } |
| 2588 | |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 2589 | RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() { |
lfg | e2176fb | 2017-03-26 00:45:47 | [diff] [blame] | 2590 | if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() || |
| 2591 | (GetFullscreenRenderWidgetHostView() && |
| 2592 | GetFullscreenRenderWidgetHostView()->IsMouseLocked())) |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 2593 | return mouse_lock_widget_; |
| 2594 | |
| 2595 | return nullptr; |
| 2596 | } |
| 2597 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2598 | bool WebContentsImpl::RequestKeyboardLock( |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2599 | RenderWidgetHostImpl* render_widget_host, |
| 2600 | bool esc_key_locked) { |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2601 | DCHECK(render_widget_host); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2602 | if (render_widget_host->delegate()->GetAsWebContents() != this) { |
| 2603 | NOTREACHED(); |
| 2604 | return false; |
| 2605 | } |
| 2606 | |
| 2607 | // KeyboardLock is only supported when called by the top-level browsing |
| 2608 | // context and is not supported in embedded content scenarios. |
| 2609 | if (GetOuterWebContents()) |
| 2610 | return false; |
| 2611 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2612 | esc_key_locked_ = esc_key_locked; |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2613 | keyboard_lock_widget_ = render_widget_host; |
| 2614 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2615 | if (delegate_) |
| 2616 | delegate_->RequestKeyboardLock(this, esc_key_locked_); |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2617 | return true; |
| 2618 | } |
| 2619 | |
| 2620 | void WebContentsImpl::CancelKeyboardLock( |
| 2621 | RenderWidgetHostImpl* render_widget_host) { |
| 2622 | if (!keyboard_lock_widget_ || render_widget_host != keyboard_lock_widget_) |
| 2623 | return; |
| 2624 | |
| 2625 | RenderWidgetHostImpl* old_keyboard_lock_widget = keyboard_lock_widget_; |
| 2626 | keyboard_lock_widget_ = nullptr; |
| 2627 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 2628 | if (delegate_) |
| 2629 | delegate_->CancelKeyboardLockRequest(this); |
| 2630 | |
Joe Downing | 192998b2 | 2018-03-22 15:51:36 | [diff] [blame] | 2631 | old_keyboard_lock_widget->CancelKeyboardLock(); |
| 2632 | } |
| 2633 | |
| 2634 | RenderWidgetHostImpl* WebContentsImpl::GetKeyboardLockWidget() { |
| 2635 | return keyboard_lock_widget_; |
| 2636 | } |
| 2637 | |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2638 | void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) { |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 2639 | if (visible && !GetOuterWebContents()->IsHidden()) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2640 | WasShown(); |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 2641 | else if (!visible) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2642 | WasHidden(); |
| 2643 | } |
| 2644 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2645 | void WebContentsImpl::CreateNewWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2646 | RenderFrameHost* opener, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2647 | int32_t render_view_route_id, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2648 | int32_t main_frame_route_id, |
| 2649 | int32_t main_frame_widget_route_id, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 2650 | const mojom::CreateNewWindowParams& params, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 2651 | SessionStorageNamespace* session_storage_namespace) { |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2652 | // We should have zero valid routing ids, or three valid routing IDs. |
| 2653 | DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), |
| 2654 | (main_frame_route_id == MSG_ROUTING_NONE)); |
| 2655 | DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), |
| 2656 | (main_frame_widget_route_id == MSG_ROUTING_NONE)); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2657 | DCHECK(opener); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2658 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2659 | int render_process_id = opener->GetProcess()->GetID(); |
| 2660 | SiteInstance* source_site_instance = opener->GetSiteInstance(); |
| 2661 | |
| 2662 | // The route IDs passed into this function can be trusted not to already |
| 2663 | // be in use; they were allocated by the RenderWidgetHelper by the caller. |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2664 | DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id)); |
| 2665 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2666 | // We usually create the new window in the same BrowsingInstance (group of |
| 2667 | // script-related windows), by passing in the current SiteInstance. However, |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2668 | // if the opener is being suppressed (in a non-guest), we create a new |
| 2669 | // SiteInstance in its own BrowsingInstance. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 2670 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2671 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2672 | // If the opener is to be suppressed, the new window can be in any process. |
| 2673 | // Since routing ids are process specific, we must not have one passed in |
| 2674 | // as argument here. |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2675 | DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2676 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2677 | scoped_refptr<SiteInstance> site_instance = |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2678 | params.opener_suppressed && !is_guest |
| 2679 | ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) |
| 2680 | : source_site_instance; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2681 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2682 | // We must assign the SessionStorageNamespace before calling Init(). |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 2683 | // |
| 2684 | // http://crbug.com/142685 |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2685 | const std::string& partition_id = |
| 2686 | GetContentClient()->browser()-> |
| 2687 | GetStoragePartitionIdForSite(GetBrowserContext(), |
| 2688 | site_instance->GetSiteURL()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2689 | StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 2690 | GetBrowserContext(), site_instance.get()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 2691 | DOMStorageContextWrapper* dom_storage_context = |
| 2692 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2693 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 2694 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 2695 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2696 | |
| 2697 | if (delegate_ && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2698 | !delegate_->ShouldCreateWebContents( |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 2699 | this, opener, source_site_instance, render_view_route_id, |
| 2700 | main_frame_route_id, main_frame_widget_route_id, |
| 2701 | params.window_container_type, opener->GetLastCommittedURL(), |
| 2702 | params.frame_name, params.target_url, partition_id, |
| 2703 | session_storage_namespace)) { |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2704 | // Note: even though we're not creating a WebContents here, it could have |
| 2705 | // been created by the embedder so ensure that the RenderFrameHost is |
| 2706 | // properly initialized. |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 2707 | // It's safe to only target the frame because the render process will not |
| 2708 | // have a chance to create more frames at this point. |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2709 | RenderFrameHostImpl* rfh = |
| 2710 | RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2711 | if (rfh) { |
| 2712 | DCHECK(rfh->IsRenderFrameLive()); |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2713 | rfh->Init(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2714 | } |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2715 | return; |
| 2716 | } |
| 2717 | |
| 2718 | // Create the new web contents. This will automatically create the new |
| 2719 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2720 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2721 | create_params.routing_id = render_view_route_id; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2722 | create_params.main_frame_routing_id = main_frame_route_id; |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2723 | create_params.main_frame_widget_routing_id = main_frame_widget_route_id; |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 2724 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2725 | create_params.opener_render_process_id = render_process_id; |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2726 | create_params.opener_render_frame_id = opener->GetRoutingID(); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2727 | create_params.opener_suppressed = params.opener_suppressed; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2728 | if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2729 | create_params.initially_hidden = true; |
lfg | 269b702f | 2015-06-08 19:28:19 | [diff] [blame] | 2730 | create_params.renderer_initiated_creation = |
| 2731 | main_frame_route_id != MSG_ROUTING_NONE; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2732 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2733 | std::unique_ptr<WebContents> new_contents; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2734 | if (!is_guest) { |
| 2735 | create_params.context = view_->GetNativeView(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2736 | create_params.initial_size = GetContainerBounds().size(); |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 2737 | new_contents = WebContents::Create(create_params); |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 2738 | } else { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2739 | new_contents = base::WrapUnique( |
| 2740 | GetBrowserPluginGuest()->CreateNewGuestWindow(create_params)); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2741 | } |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2742 | WebContentsImpl* raw_new_contents = |
| 2743 | static_cast<WebContentsImpl*>(new_contents.get()); |
| 2744 | raw_new_contents->GetController().SetSessionStorageNamespace( |
| 2745 | partition_id, session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2746 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 2747 | // If the new frame has a name, make sure any SiteInstances that can find |
| 2748 | // this named frame have proxies for it. Must be called after |
| 2749 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 2750 | // GetSessionStorageNamespace. |
| 2751 | if (!params.frame_name.empty()) |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2752 | raw_new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 2753 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2754 | // Save the window for later if we're not suppressing the opener (since it |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2755 | // will be shown immediately). |
| 2756 | if (!params.opener_suppressed) { |
| 2757 | if (!is_guest) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2758 | WebContentsView* new_view = raw_new_contents->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2759 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2760 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 2761 | // newly created object and give it one of its own member variables. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2762 | new_view->CreateViewForWidget( |
| 2763 | new_contents->GetRenderViewHost()->GetWidget(), false); |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2764 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2765 | // Save the created window associated with the route so we can show it |
| 2766 | // later. |
Albert J. Wong | cb00463 | 2018-07-10 22:58:25 | [diff] [blame] | 2767 | // |
| 2768 | // TODO(ajwong): This should be keyed off the RenderFrame routing id or the |
| 2769 | // FrameTreeNode id instead of the routing id of the Widget for the main |
| 2770 | // frame. https://crbug.com/545684 |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2771 | DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2772 | pending_contents_[std::make_pair(render_process_id, |
| 2773 | main_frame_widget_route_id)] = |
| 2774 | std::move(new_contents); |
| 2775 | AddDestructionObserver(raw_new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | if (delegate_) { |
Bryan McQuade | d2b93c0 | 2017-07-14 22:26:31 | [diff] [blame] | 2779 | delegate_->WebContentsCreated(this, render_process_id, |
| 2780 | opener->GetRoutingID(), params.frame_name, |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2781 | params.target_url, raw_new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2782 | } |
| 2783 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2784 | if (opener) { |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 2785 | for (auto& observer : observers_) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2786 | observer.DidOpenRequestedURL(raw_new_contents, opener, params.target_url, |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2787 | params.referrer, params.disposition, |
| 2788 | ui::PAGE_TRANSITION_LINK, |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 2789 | false, // started_from_context_menu |
| 2790 | true); // renderer_initiated |
| 2791 | } |
| 2792 | } |
| 2793 | |
Avi Drissman | ba3b1b34 | 2017-08-29 18:16:13 | [diff] [blame] | 2794 | // Any new WebContents opened while this WebContents is in fullscreen can be |
| 2795 | // used to confuse the user, so drop fullscreen. |
| 2796 | if (IsFullscreenForCurrentTab()) |
| 2797 | ExitFullscreen(true); |
| 2798 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2799 | if (params.opener_suppressed) { |
| 2800 | // When the opener is suppressed, the original renderer cannot access the |
| 2801 | // new window. As a result, we need to show and navigate the window here. |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2802 | bool was_blocked = false; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2803 | |
| 2804 | base::WeakPtr<WebContentsImpl> weak_new_contents = |
| 2805 | raw_new_contents->weak_factory_.GetWeakPtr(); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2806 | if (delegate_) { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2807 | gfx::Rect initial_rect; |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2808 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2809 | delegate_->AddNewContents(this, std::move(new_contents), |
| 2810 | params.disposition, initial_rect, |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 2811 | params.mimic_user_gesture, &was_blocked); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2812 | if (!weak_new_contents) |
| 2813 | return; // The delegate deleted |new_contents| during AddNewContents(). |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2814 | } |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2815 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2816 | if (!was_blocked) { |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2817 | OpenURLParams open_params(params.target_url, params.referrer, |
| 2818 | WindowOpenDisposition::CURRENT_TAB, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 2819 | ui::PAGE_TRANSITION_LINK, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2820 | true /* is_renderer_initiated */); |
Mustaq Ahmed | c4cb716 | 2018-06-05 16:28:36 | [diff] [blame] | 2821 | open_params.user_gesture = params.mimic_user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2822 | |
| 2823 | if (delegate_ && !is_guest && |
| 2824 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2825 | DCHECK(weak_new_contents); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2826 | // We are in asynchronous add new contents path, delay opening url |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2827 | weak_new_contents->delayed_open_url_params_.reset( |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2828 | new OpenURLParams(open_params)); |
| 2829 | } else { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2830 | weak_new_contents->OpenURL(open_params); |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2831 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2832 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2833 | } |
| 2834 | } |
| 2835 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2836 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2837 | int32_t route_id, |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 2838 | mojom::WidgetPtr widget, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2839 | blink::WebPopupType popup_type) { |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 2840 | CreateNewWidget(render_process_id, route_id, false, std::move(widget), |
| 2841 | popup_type); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2842 | } |
| 2843 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2844 | void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id, |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 2845 | int32_t route_id, |
| 2846 | mojom::WidgetPtr widget) { |
| 2847 | CreateNewWidget(render_process_id, route_id, true, std::move(widget), |
| 2848 | blink::kWebPopupTypeNone); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2849 | } |
| 2850 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2851 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2852 | int32_t route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2853 | bool is_fullscreen, |
Dave Tapuska | 1bdf183 | 2017-07-07 18:07:19 | [diff] [blame] | 2854 | mojom::WidgetPtr widget, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2855 | blink::WebPopupType popup_type) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2856 | RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 2857 | // A message to create a new widget can only come from an active process for |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2858 | // this WebContentsImpl instance. If any other process sends the request, |
| 2859 | // it is invalid and the process must be terminated. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2860 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
Lukasz Anforowicz | 6f74628 | 2018-01-04 23:24:51 | [diff] [blame] | 2861 | ReceivedBadMessage(process, bad_message::WCI_NEW_WIDGET_PROCESS_MISMATCH); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2862 | return; |
| 2863 | } |
| 2864 | |
Dave Tapuska | 485aca9 | 2017-08-08 00:47:58 | [diff] [blame] | 2865 | RenderWidgetHostImpl* widget_host = new RenderWidgetHostImpl( |
| 2866 | this, process, route_id, std::move(widget), IsHidden()); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2867 | |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2868 | RenderWidgetHostViewBase* widget_view = |
| 2869 | static_cast<RenderWidgetHostViewBase*>( |
| 2870 | view_->CreateViewForPopupWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 2871 | if (!widget_view) |
| 2872 | return; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2873 | if (!is_fullscreen) { |
| 2874 | // Popups should not get activated. |
| 2875 | widget_view->SetPopupType(popup_type); |
| 2876 | } |
| 2877 | // Save the created widget associated with the route so we can show it later. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2878 | pending_widget_views_[std::make_pair(render_process_id, route_id)] = |
| 2879 | widget_view; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2880 | } |
| 2881 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2882 | void WebContentsImpl::ShowCreatedWindow(int process_id, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2883 | int main_frame_widget_route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2884 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2885 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2886 | bool user_gesture) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2887 | std::unique_ptr<WebContents> popup = |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2888 | GetCreatedWindow(process_id, main_frame_widget_route_id); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2889 | if (popup) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2890 | WebContentsImpl* raw_popup = static_cast<WebContentsImpl*>(popup.get()); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2891 | WebContentsDelegate* delegate = GetDelegate(); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2892 | raw_popup->is_resume_pending_ = true; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2893 | if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2894 | raw_popup->ResumeLoadingCreatedWebContents(); |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2895 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2896 | base::WeakPtr<WebContentsImpl> weak_popup = |
| 2897 | raw_popup->weak_factory_.GetWeakPtr(); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2898 | if (delegate) { |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2899 | delegate->AddNewContents(this, std::move(popup), disposition, |
| 2900 | initial_rect, user_gesture, nullptr); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2901 | if (!weak_popup) |
| 2902 | return; // The delegate deleted |popup| during AddNewContents(). |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2903 | } |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2904 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2905 | RenderWidgetHostImpl* rwh = |
| 2906 | weak_popup->GetMainFrame()->GetRenderWidgetHost(); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2907 | DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID()); |
Avi Drissman | 014dec7 | 2018-06-07 02:34:01 | [diff] [blame] | 2908 | rwh->Send(new ViewMsg_SetBounds_ACK(rwh->GetRoutingID())); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2909 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2910 | } |
| 2911 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2912 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2913 | int route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2914 | const gfx::Rect& initial_rect) { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2915 | ShowCreatedWidget(process_id, route_id, false, initial_rect); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2916 | } |
| 2917 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2918 | void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id, |
| 2919 | int route_id) { |
| 2920 | ShowCreatedWidget(process_id, route_id, true, gfx::Rect()); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2921 | } |
| 2922 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2923 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2924 | int route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2925 | bool is_fullscreen, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2926 | const gfx::Rect& initial_rect) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2927 | RenderWidgetHostViewBase* widget_host_view = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2928 | static_cast<RenderWidgetHostViewBase*>( |
| 2929 | GetCreatedWidget(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2930 | if (!widget_host_view) |
| 2931 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2932 | |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 2933 | RenderWidgetHostView* view = nullptr; |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 2934 | if (GetOuterWebContents()) { |
| 2935 | view = GetOuterWebContents()->GetRenderWidgetHostView(); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2936 | } else { |
| 2937 | view = GetRenderWidgetHostView(); |
| 2938 | } |
| 2939 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2940 | if (is_fullscreen) { |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2941 | DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2942 | view_->StoreFocus(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2943 | fullscreen_widget_process_id_ = |
| 2944 | widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2945 | fullscreen_widget_routing_id_ = route_id; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2946 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| 2947 | widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView()); |
Dave Tapuska | 3ed4419 | 2018-05-01 18:53:30 | [diff] [blame] | 2948 | delegate_->EnterFullscreenModeForTab(this, GURL(), |
| 2949 | blink::WebFullscreenOptions()); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2950 | } else { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2951 | widget_host_view->InitAsFullscreen(view); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2952 | } |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2953 | for (auto& observer : observers_) |
| 2954 | observer.DidShowFullscreenWidget(); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2955 | if (!widget_host_view->HasFocus()) |
| 2956 | widget_host_view->Focus(); |
| 2957 | } else { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2958 | widget_host_view->InitAsPopup(view, initial_rect); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2959 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 2960 | |
yiyix | cb1fbc4f | 2018-03-16 19:54:08 | [diff] [blame] | 2961 | RenderWidgetHostImpl* render_widget_host_impl = widget_host_view->host(); |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 2962 | render_widget_host_impl->Init(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2963 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 2964 | // used to implement Pepper Flash fullscreen. |
| 2965 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2966 | } |
| 2967 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2968 | std::unique_ptr<WebContents> WebContentsImpl::GetCreatedWindow( |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2969 | int process_id, |
| 2970 | int main_frame_widget_route_id) { |
| 2971 | auto key = std::make_pair(process_id, main_frame_widget_route_id); |
| 2972 | auto iter = pending_contents_.find(key); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2973 | |
| 2974 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 2975 | // in creating one, just return NULL. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2976 | if (iter == pending_contents_.end()) |
| 2977 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2978 | |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2979 | std::unique_ptr<WebContents> new_contents = std::move(iter->second); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2980 | pending_contents_.erase(key); |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2981 | WebContentsImpl* raw_new_contents = |
| 2982 | static_cast<WebContentsImpl*>(new_contents.get()); |
| 2983 | RemoveDestructionObserver(raw_new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2984 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2985 | // Don't initialize the guest WebContents immediately. |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 2986 | if (BrowserPluginGuest::IsGuest(raw_new_contents)) |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2987 | return new_contents; |
| 2988 | |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 2989 | if (!new_contents->GetMainFrame()->GetProcess()->IsInitializedAndNotDead() || |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2990 | !new_contents->GetMainFrame()->GetView()) { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2991 | return nullptr; |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2992 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2993 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2994 | return new_contents; |
| 2995 | } |
| 2996 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2997 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
| 2998 | int route_id) { |
| 2999 | auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3000 | if (iter == pending_widget_views_.end()) { |
| 3001 | DCHECK(false); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3002 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | RenderWidgetHostView* widget_host_view = iter->second; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3006 | pending_widget_views_.erase(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3007 | |
| 3008 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
Lukasz Anforowicz | 5510ed65 | 2018-06-06 16:16:19 | [diff] [blame] | 3009 | if (!widget_host->GetProcess()->IsInitializedAndNotDead()) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3010 | // The view has gone away or the renderer crashed. Nothing to do. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 3011 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | return widget_host_view; |
| 3015 | } |
| 3016 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3017 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 3018 | const MediaStreamRequest& request, |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3019 | MediaResponseCallback callback) { |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3020 | if (delegate_) { |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3021 | delegate_->RequestMediaAccessPermission(this, request, std::move(callback)); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3022 | } else { |
Mark Pilgrim | 5749908 | 2018-06-12 12:38:30 | [diff] [blame] | 3023 | std::move(callback).Run(MediaStreamDevices(), |
| 3024 | MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
| 3025 | std::unique_ptr<MediaStreamUI>()); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 3026 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 3027 | } |
| 3028 | |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3029 | bool WebContentsImpl::CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3030 | RenderFrameHost* render_frame_host, |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3031 | const url::Origin& security_origin, |
| 3032 | MediaStreamType type) { |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 3033 | DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 3034 | type == MEDIA_DEVICE_VIDEO_CAPTURE); |
Chandan Padhi | a4b8bcb7 | 2017-09-12 16:41:04 | [diff] [blame] | 3035 | return delegate_ && delegate_->CheckMediaAccessPermission( |
Raymes Khoury | ad7c24a1 | 2018-03-05 23:22:58 | [diff] [blame] | 3036 | render_frame_host, security_origin.GetURL(), type); |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 3037 | } |
| 3038 | |
guidou | 8a440b84 | 2017-01-30 13:58:43 | [diff] [blame] | 3039 | std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) { |
| 3040 | if (!delegate_) |
| 3041 | return std::string(); |
| 3042 | return delegate_->GetDefaultMediaDeviceID(this, type); |
| 3043 | } |
| 3044 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 3045 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 3046 | SiteInstance* instance) { |
| 3047 | return controller_.GetSessionStorageNamespace(instance); |
| 3048 | } |
| 3049 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 3050 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 3051 | return controller_.GetSessionStorageNamespaceMap(); |
| 3052 | } |
| 3053 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 3054 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 3055 | return &frame_tree_; |
| 3056 | } |
| 3057 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 3058 | bool WebContentsImpl::IsOverridingUserAgent() { |
| 3059 | return GetController().GetVisibleEntry() && |
| 3060 | GetController().GetVisibleEntry()->GetIsOverridingUserAgent(); |
| 3061 | } |
| 3062 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 3063 | bool WebContentsImpl::IsJavaScriptDialogShowing() const { |
| 3064 | return is_showing_javascript_dialog_; |
| 3065 | } |
| 3066 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 3067 | bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() { |
| 3068 | // Ignore unresponsive renderers if the debugger is attached to them since the |
| 3069 | // unresponsiveness might be a result of the renderer sitting on a breakpoint. |
| 3070 | // |
| 3071 | // TODO(pfeldman): Fix this to only return true if the renderer is *actually* |
| 3072 | // sitting on a breakpoint. https://crbug.com/684202 |
| 3073 | return DevToolsAgentHost::IsDebuggerAttached(this); |
| 3074 | } |
| 3075 | |
Doug Turner | 63f3c7b | 2017-07-29 05:10:01 | [diff] [blame] | 3076 | ui::AXMode WebContentsImpl::GetAccessibilityMode() const { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3077 | return accessibility_mode_; |
| 3078 | } |
| 3079 | |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 3080 | void WebContentsImpl::AccessibilityEventReceived( |
Dominic Mazzoni | ccbaa9b | 2018-06-06 07:44:23 | [diff] [blame] | 3081 | const AXEventNotificationDetails& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3082 | for (auto& observer : observers_) |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 3083 | observer.AccessibilityEventReceived(details); |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 3084 | } |
| 3085 | |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 3086 | void WebContentsImpl::AccessibilityLocationChangesReceived( |
| 3087 | const std::vector<AXLocationChangeNotificationDetails>& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3088 | for (auto& observer : observers_) |
Dominic Mazzoni | a7b0edb2 | 2017-08-09 16:32:51 | [diff] [blame] | 3089 | observer.AccessibilityLocationChangesReceived(details); |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 3090 | } |
| 3091 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3092 | RenderFrameHost* WebContentsImpl::GetGuestByInstanceID( |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3093 | RenderFrameHost* render_frame_host, |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3094 | int browser_plugin_instance_id) { |
| 3095 | BrowserPluginGuestManager* guest_manager = |
| 3096 | GetBrowserContext()->GetGuestManager(); |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 3097 | if (!guest_manager) |
| 3098 | return nullptr; |
| 3099 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3100 | WebContents* guest = guest_manager->GetGuestByInstanceID( |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 3101 | render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id); |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3102 | if (!guest) |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 3103 | return nullptr; |
| 3104 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 3105 | return guest->GetMainFrame(); |
| 3106 | } |
| 3107 | |
Ke He | 7319dbe | 2017-11-09 05:54:44 | [diff] [blame] | 3108 | device::mojom::GeolocationContext* WebContentsImpl::GetGeolocationContext() { |
| 3109 | if (geolocation_context_) |
| 3110 | return geolocation_context_.get(); |
| 3111 | |
| 3112 | auto request = mojo::MakeRequest(&geolocation_context_); |
| 3113 | if (!ServiceManagerConnection::GetForProcess()) |
| 3114 | return geolocation_context_.get(); |
| 3115 | |
| 3116 | service_manager::Connector* connector = |
| 3117 | ServiceManagerConnection::GetForProcess()->GetConnector(); |
| 3118 | connector->BindInterface(device::mojom::kServiceName, std::move(request)); |
Conley Owens | 6894c4f | 2017-07-10 19:29:13 | [diff] [blame] | 3119 | return geolocation_context_.get(); |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 3120 | } |
| 3121 | |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 3122 | device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() { |
blundell | d8cd72b | 2017-03-28 07:18:38 | [diff] [blame] | 3123 | if (!wake_lock_context_host_) |
| 3124 | wake_lock_context_host_.reset(new WakeLockContextHost(this)); |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 3125 | return wake_lock_context_host_->GetWakeLockContext(); |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 3126 | } |
| 3127 | |
juncai | 8e8d6ec | 2017-06-06 20:48:18 | [diff] [blame] | 3128 | device::mojom::WakeLock* WebContentsImpl::GetRendererWakeLock() { |
| 3129 | // WebContents creates a long-lived connection to one WakeLock. |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 3130 | // All the frames' requests will be added into the BindingSet of |
juncai | 8e8d6ec | 2017-06-06 20:48:18 | [diff] [blame] | 3131 | // WakeLock via this connection. |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 3132 | if (!renderer_wake_lock_) { |
| 3133 | device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext(); |
| 3134 | if (!wake_lock_context) { |
| 3135 | return nullptr; |
| 3136 | } |
ke.he | f435c1e8 | 2017-05-11 04:09:10 | [diff] [blame] | 3137 | wake_lock_context->GetWakeLock( |
Daniel Erat | 28922ba | 2017-11-08 16:18:26 | [diff] [blame] | 3138 | device::mojom::WakeLockType::kPreventDisplaySleep, |
| 3139 | device::mojom::WakeLockReason::kOther, "Wake Lock API", |
ke.he | f435c1e8 | 2017-05-11 04:09:10 | [diff] [blame] | 3140 | mojo::MakeRequest(&renderer_wake_lock_)); |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 3141 | } |
| 3142 | return renderer_wake_lock_.get(); |
| 3143 | } |
| 3144 | |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 3145 | #if defined(OS_ANDROID) |
Han Leon | f6a2e5f | 2017-05-23 13:40:47 | [diff] [blame] | 3146 | void WebContentsImpl::GetNFC(device::mojom::NFCRequest request) { |
blundell | f5316fc | 2017-05-15 11:49:03 | [diff] [blame] | 3147 | if (!nfc_host_) |
| 3148 | nfc_host_.reset(new NFCHost(this)); |
| 3149 | nfc_host_->GetNFC(std::move(request)); |
| 3150 | } |
| 3151 | #endif |
| 3152 | |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 3153 | void WebContentsImpl::SetNotWaitingForResponse() { |
| 3154 | if (waiting_for_response_ == false) |
| 3155 | return; |
| 3156 | |
| 3157 | waiting_for_response_ = false; |
| 3158 | if (delegate_) |
| 3159 | delegate_->LoadingStateChanged(this, is_load_to_different_document_); |
Chris Hamilton | f82f2a70 | 2018-02-15 19:37:29 | [diff] [blame] | 3160 | for (auto& observer : observers_) |
| 3161 | observer.DidReceiveResponse(); |
Evan Stade | 5e750ad0 | 2017-08-07 21:59:27 | [diff] [blame] | 3162 | } |
| 3163 | |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 3164 | void WebContentsImpl::SendScreenRects() { |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 3165 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
kenrb | 0e8dc20 | 2016-05-30 19:51:40 | [diff] [blame] | 3166 | if (node->current_frame_host()->is_local_root()) |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 3167 | node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects(); |
| 3168 | } |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 3169 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 3170 | RenderWidgetHostViewBase* rwhv = |
| 3171 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3172 | if (rwhv) { |
| 3173 | SendPageMessage(new PageMsg_UpdateWindowScreenRect( |
| 3174 | MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow())); |
| 3175 | } |
| 3176 | |
avallee | 9f43b01 | 2016-11-26 07:02:10 | [diff] [blame] | 3177 | if (browser_plugin_embedder_ && !is_being_destroyed_) |
[email protected] | a7568e6 | 2013-06-14 07:50:44 | [diff] [blame] | 3178 | browser_plugin_embedder_->DidSendScreenRects(); |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 3179 | } |
| 3180 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 3181 | TextInputManager* WebContentsImpl::GetTextInputManager() { |
| 3182 | if (GetOuterWebContents()) |
| 3183 | return GetOuterWebContents()->GetTextInputManager(); |
| 3184 | |
Darren Shen | ca53d5f | 2018-05-15 04:56:01 | [diff] [blame] | 3185 | if (!text_input_manager_) { |
| 3186 | text_input_manager_.reset(new TextInputManager( |
| 3187 | GetBrowserContext() && |
| 3188 | !GetBrowserContext()->IsOffTheRecord()) /* should_do_learning */); |
| 3189 | } |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 3190 | |
| 3191 | return text_input_manager_.get(); |
| 3192 | } |
| 3193 | |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 3194 | bool WebContentsImpl::OnUpdateDragCursor() { |
| 3195 | if (browser_plugin_embedder_) |
| 3196 | return browser_plugin_embedder_->OnUpdateDragCursor(); |
| 3197 | return false; |
| 3198 | } |
| 3199 | |
kenrb | 11f213a | 2017-03-24 18:12:06 | [diff] [blame] | 3200 | bool WebContentsImpl::IsWidgetForMainFrame( |
| 3201 | RenderWidgetHostImpl* render_widget_host) { |
| 3202 | return render_widget_host == GetMainFrame()->GetRenderWidgetHost(); |
| 3203 | } |
| 3204 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3205 | BrowserAccessibilityManager* |
| 3206 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
Dominic Mazzoni | efb5f9e3 | 2017-12-21 01:08:22 | [diff] [blame] | 3207 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( |
| 3208 | ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame() |
| 3209 | : GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 3210 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3211 | } |
| 3212 | |
| 3213 | BrowserAccessibilityManager* |
| 3214 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
Dominic Mazzoni | efb5f9e3 | 2017-12-21 01:08:22 | [diff] [blame] | 3215 | RenderFrameHostImpl* rfh = static_cast<RenderFrameHostImpl*>( |
| 3216 | ShowingInterstitialPage() ? GetInterstitialPage()->GetMainFrame() |
| 3217 | : GetMainFrame()); |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 3218 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3219 | } |
| 3220 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3221 | void WebContentsImpl::ExecuteEditCommand( |
| 3222 | const std::string& command, |
| 3223 | const base::Optional<base::string16>& value) { |
| 3224 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
| 3225 | if (!focused_frame) |
| 3226 | return; |
| 3227 | |
| 3228 | focused_frame->GetFrameInputHandler()->ExecuteEditCommand(command, value); |
| 3229 | } |
| 3230 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3231 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3232 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3233 | if (!focused_frame) |
| 3234 | return; |
| 3235 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3236 | focused_frame->GetFrameInputHandler()->MoveRangeSelectionExtent(extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3237 | } |
| 3238 | |
| 3239 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 3240 | const gfx::Point& extent) { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3241 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3242 | if (!focused_frame) |
| 3243 | return; |
| 3244 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3245 | focused_frame->GetFrameInputHandler()->SelectRange(base, extent); |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 3246 | } |
| 3247 | |
Tessa Nijssen | c4b10123 | 2018-06-25 20:28:08 | [diff] [blame] | 3248 | #if defined(OS_MACOSX) |
Tessa Nijssen | dbef474 | 2018-06-29 21:02:08 | [diff] [blame] | 3249 | void WebContentsImpl::DidChangeTextSelection(const base::string16& text, |
| 3250 | const gfx::Range& range) { |
| 3251 | for (auto& observer : observers_) |
| 3252 | observer.DidChangeTextSelection(text, range); |
Tessa Nijssen | c4b10123 | 2018-06-25 20:28:08 | [diff] [blame] | 3253 | } |
| 3254 | #endif |
| 3255 | |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3256 | void WebContentsImpl::MoveCaret(const gfx::Point& extent) { |
| 3257 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
| 3258 | if (!focused_frame) |
| 3259 | return; |
| 3260 | |
| 3261 | focused_frame->GetFrameInputHandler()->MoveCaret(extent); |
| 3262 | } |
| 3263 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3264 | void WebContentsImpl::AdjustSelectionByCharacterOffset( |
| 3265 | int start_adjust, |
| 3266 | int end_adjust, |
| 3267 | bool show_selection_menu) { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3268 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 3269 | if (!focused_frame) |
| 3270 | return; |
| 3271 | |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3272 | using blink::mojom::SelectionMenuBehavior; |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3273 | focused_frame->GetFrameInputHandler()->AdjustSelectionByCharacterOffset( |
Shimi Zhang | 37deeb2 | 2017-09-28 00:59:01 | [diff] [blame] | 3274 | start_adjust, end_adjust, |
| 3275 | show_selection_menu ? SelectionMenuBehavior::kShow |
| 3276 | : SelectionMenuBehavior::kHide); |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 3277 | } |
| 3278 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3279 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3280 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 3281 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3282 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 3283 | } |
| 3284 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3285 | void WebContentsImpl::ResizeDueToAutoResize( |
| 3286 | RenderWidgetHostImpl* render_widget_host, |
Fady Samuel | 9794711 | 2018-05-05 16:24:54 | [diff] [blame] | 3287 | const gfx::Size& new_size) { |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3288 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 3289 | return; |
| 3290 | |
kenrb | e4f9108 | 2017-06-02 20:32:08 | [diff] [blame] | 3291 | auto_resize_size_ = new_size; |
| 3292 | |
| 3293 | // Out-of-process iframe visible viewport sizes usually come from the |
| 3294 | // top-level RenderWidgetHostView, but when auto-resize is enabled on the |
| 3295 | // top frame then that size is used instead. |
| 3296 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 3297 | if (node->current_frame_host()->is_local_root()) { |
| 3298 | RenderWidgetHostImpl* host = |
| 3299 | node->current_frame_host()->GetRenderWidgetHost(); |
| 3300 | if (host != render_widget_host) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 3301 | host->SynchronizeVisualProperties(); |
kenrb | e4f9108 | 2017-06-02 20:32:08 | [diff] [blame] | 3302 | } |
| 3303 | } |
| 3304 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 3305 | if (delegate_) |
| 3306 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 3307 | } |
| 3308 | |
kenrb | e4f9108 | 2017-06-02 20:32:08 | [diff] [blame] | 3309 | gfx::Size WebContentsImpl::GetAutoResizeSize() { |
| 3310 | return auto_resize_size_; |
| 3311 | } |
| 3312 | |
| 3313 | void WebContentsImpl::ResetAutoResizeSize() { |
| 3314 | auto_resize_size_ = gfx::Size(); |
| 3315 | } |
| 3316 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3317 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 3318 | if (!delegate_) { |
| 3319 | // Embedder can delay setting a delegate on new WebContents with |
| 3320 | // WebContentsDelegate::ShouldResumeRequestsForCreatedWindow. In the mean |
| 3321 | // time, navigations, including the initial one, that goes through OpenURL |
| 3322 | // should be delayed until embedder is ready to resume loading. |
| 3323 | delayed_open_url_params_ = std::make_unique<OpenURLParams>(params); |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 3324 | return nullptr; |
Bo Liu | 300c605 | 2018-06-12 04:46:07 | [diff] [blame] | 3325 | } |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 3326 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 3327 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 3328 | |
| 3329 | RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID( |
| 3330 | params.source_render_process_id, params.source_render_frame_id); |
| 3331 | |
| 3332 | if (source_render_frame_host && params.source_site_instance) { |
| 3333 | CHECK_EQ(source_render_frame_host->GetSiteInstance(), |
| 3334 | params.source_site_instance.get()); |
| 3335 | } |
| 3336 | |
| 3337 | if (new_contents && source_render_frame_host && new_contents != this) { |
| 3338 | for (auto& observer : observers_) { |
| 3339 | observer.DidOpenRequestedURL(new_contents, source_render_frame_host, |
| 3340 | params.url, params.referrer, |
| 3341 | params.disposition, params.transition, |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 3342 | params.started_from_context_menu, false); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 3343 | } |
| 3344 | } |
| 3345 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 3346 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 3347 | } |
| 3348 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 3349 | void WebContentsImpl::RenderFrameForInterstitialPageCreated( |
| 3350 | RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3351 | for (auto& observer : observers_) |
| 3352 | observer.RenderFrameForInterstitialPageCreated(render_frame_host); |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 3353 | } |
| 3354 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 3355 | void WebContentsImpl::AttachInterstitialPage( |
| 3356 | InterstitialPageImpl* interstitial_page) { |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 3357 | DCHECK(!interstitial_page_ && interstitial_page); |
| 3358 | interstitial_page_ = interstitial_page; |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 3359 | |
| 3360 | // Cancel any visible dialogs so that they don't interfere with the |
| 3361 | // interstitial. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 3362 | CancelActiveAndPendingDialogs(); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 3363 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3364 | for (auto& observer : observers_) |
| 3365 | observer.DidAttachInterstitialPage(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3366 | |
| 3367 | // Stop the throbber if needed while the interstitial page is shown. |
| 3368 | if (frame_tree_.IsLoading()) |
| 3369 | LoadingStateChanged(true, true, nullptr); |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 3370 | |
| 3371 | // Connect to outer WebContents if necessary. |
| 3372 | if (node_.OuterContentsFrameTreeNode()) { |
| 3373 | if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 3374 | DCHECK( |
| 3375 | static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView()) |
| 3376 | ->IsRenderWidgetHostViewChildFrame()); |
| 3377 | RenderWidgetHostViewChildFrame* view = |
| 3378 | static_cast<RenderWidgetHostViewChildFrame*>( |
| 3379 | interstitial_page->GetView()); |
| 3380 | GetRenderManager()->SetRWHViewForInnerContents(view); |
| 3381 | } |
| 3382 | } |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 3383 | |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 3384 | #if defined(OS_ANDROID) |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 3385 | // Update importance of the interstitial. |
| 3386 | static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame()) |
| 3387 | ->GetRenderWidgetHost() |
| 3388 | ->SetImportance(GetMainFrame()->GetRenderWidgetHost()->importance()); |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 3389 | #endif |
Dominic Mazzoni | efb5f9e3 | 2017-12-21 01:08:22 | [diff] [blame] | 3390 | |
| 3391 | if (accessibility_mode_.has_mode(ui::AXMode::kNativeAPIs)) { |
| 3392 | // Make sure that the main page's accessibility tree is hidden and the |
| 3393 | // interstitial gets focus. |
| 3394 | RenderFrameHostImpl* rfh = |
| 3395 | static_cast<RenderFrameHostImpl*>(GetMainFrame()); |
| 3396 | if (rfh) { |
| 3397 | BrowserAccessibilityManager* accessibility_manager = |
| 3398 | rfh->browser_accessibility_manager(); |
| 3399 | if (accessibility_manager) |
| 3400 | accessibility_manager->set_hidden_by_interstitial_page(true); |
| 3401 | } |
| 3402 | rfh = static_cast<RenderFrameHostImpl*>( |
| 3403 | GetInterstitialPage()->GetMainFrame()); |
| 3404 | if (rfh) { |
| 3405 | BrowserAccessibilityManager* accessibility_manager = |
| 3406 | rfh->GetOrCreateBrowserAccessibilityManager(); |
| 3407 | if (accessibility_manager) |
| 3408 | accessibility_manager->OnWindowFocused(); |
| 3409 | } |
| 3410 | } |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3411 | } |
| 3412 | |
| 3413 | void WebContentsImpl::DidProceedOnInterstitial() { |
| 3414 | // The interstitial page should no longer be pausing the throbber. |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 3415 | DCHECK(!(ShowingInterstitialPage() && interstitial_page_->pause_throbber())); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3416 | |
| 3417 | // Restart the throbber now that the interstitial page no longer pauses it. |
| 3418 | if (ShowingInterstitialPage() && frame_tree_.IsLoading()) |
| 3419 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 3420 | } |
| 3421 | |
Lucas Furukawa Gadani | 7f1241d | 2017-07-12 01:45:04 | [diff] [blame] | 3422 | void WebContentsImpl::DetachInterstitialPage(bool has_focus) { |
Lucas Furukawa Gadani | 69b60919 | 2017-07-10 17:08:34 | [diff] [blame] | 3423 | bool interstitial_pausing_throbber = |
| 3424 | ShowingInterstitialPage() && interstitial_page_->pause_throbber(); |
| 3425 | if (ShowingInterstitialPage()) |
| 3426 | interstitial_page_ = nullptr; |
Lucas Furukawa Gadani | 7f1241d | 2017-07-12 01:45:04 | [diff] [blame] | 3427 | |
Dominic Mazzoni | efb5f9e3 | 2017-12-21 01:08:22 | [diff] [blame] | 3428 | // Make sure that the main page's accessibility tree is no longer |
| 3429 | // suppressed. |
| 3430 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 3431 | if (rfh) { |
| 3432 | BrowserAccessibilityManager* accessibility_manager = |
| 3433 | rfh->browser_accessibility_manager(); |
| 3434 | if (accessibility_manager) |
| 3435 | accessibility_manager->set_hidden_by_interstitial_page(false); |
| 3436 | } |
| 3437 | |
Lucas Furukawa Gadani | 7f1241d | 2017-07-12 01:45:04 | [diff] [blame] | 3438 | // If the focus was on the interstitial, let's keep it to the page. |
| 3439 | // (Note that in unit-tests the RVH may not have a view). |
| 3440 | if (has_focus && GetRenderViewHost()->GetWidget()->GetView()) |
| 3441 | GetRenderViewHost()->GetWidget()->GetView()->Focus(); |
| 3442 | |
Lucas Furukawa Gadani | 69b60919 | 2017-07-10 17:08:34 | [diff] [blame] | 3443 | for (auto& observer : observers_) |
| 3444 | observer.DidDetachInterstitialPage(); |
| 3445 | |
| 3446 | // Disconnect from outer WebContents if necessary. This must happen after the |
| 3447 | // interstitial page is cleared above, since the call to |
| 3448 | // SetRWHViewForInnerContents below may loop over all the |
| 3449 | // RenderWidgetHostViews in the tree (otherwise, including the now-deleted |
| 3450 | // view for the interstitial). |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 3451 | if (node_.OuterContentsFrameTreeNode()) { |
| 3452 | if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 3453 | DCHECK(static_cast<RenderWidgetHostViewBase*>( |
| 3454 | GetRenderManager()->current_frame_host()->GetView()) |
| 3455 | ->IsRenderWidgetHostViewChildFrame()); |
| 3456 | RenderWidgetHostViewChildFrame* view = |
| 3457 | static_cast<RenderWidgetHostViewChildFrame*>( |
| 3458 | GetRenderManager()->current_frame_host()->GetView()); |
| 3459 | GetRenderManager()->SetRWHViewForInnerContents(view); |
| 3460 | } |
| 3461 | } |
| 3462 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3463 | // Restart the throbber if needed now that the interstitial page is going |
| 3464 | // away. |
| 3465 | if (interstitial_pausing_throbber && frame_tree_.IsLoading()) |
| 3466 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 3467 | } |
| 3468 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 3469 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 3470 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 3471 | SendPageMessage(new PageMsg_SetHistoryOffsetAndLength( |
| 3472 | MSG_ROUTING_NONE, history_offset, history_length)); |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 3473 | } |
| 3474 | |
| 3475 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 3476 | RenderViewHost* render_view_host, |
| 3477 | int history_offset, |
| 3478 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 3479 | render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength( |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 3480 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 3481 | } |
| 3482 | |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 3483 | void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) { |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3484 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3485 | if (!focused_frame) |
| 3486 | return; |
| 3487 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3488 | focused_frame->Send(new FrameMsg_Reload( |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 3489 | focused_frame->GetRoutingID(), bypass_cache)); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3490 | } |
| 3491 | |
megjablon | 3f594107 | 2016-02-04 23:27:52 | [diff] [blame] | 3492 | void WebContentsImpl::ReloadLoFiImages() { |
| 3493 | SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE)); |
| 3494 | } |
| 3495 | |
Ryan Sturm | c65dbe4 | 2018-05-31 20:37:04 | [diff] [blame] | 3496 | std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> |
| 3497 | WebContentsImpl::PauseSubresourceLoading() { |
| 3498 | std::vector<blink::mojom::PauseSubresourceLoadingHandlePtr> handles; |
| 3499 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 3500 | if (!rfh->IsRenderFrameLive()) |
| 3501 | continue; |
| 3502 | handles.push_back(rfh->PauseSubresourceLoading()); |
| 3503 | } |
| 3504 | return handles; |
| 3505 | } |
| 3506 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3507 | void WebContentsImpl::Undo() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3508 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3509 | if (!focused_frame) |
| 3510 | return; |
| 3511 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3512 | focused_frame->GetFrameInputHandler()->Undo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3513 | RecordAction(base::UserMetricsAction("Undo")); |
| 3514 | } |
| 3515 | |
| 3516 | void WebContentsImpl::Redo() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3517 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3518 | if (!focused_frame) |
| 3519 | return; |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3520 | focused_frame->GetFrameInputHandler()->Redo(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3521 | RecordAction(base::UserMetricsAction("Redo")); |
| 3522 | } |
| 3523 | |
| 3524 | void WebContentsImpl::Cut() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3525 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3526 | if (!focused_frame) |
| 3527 | return; |
| 3528 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3529 | focused_frame->GetFrameInputHandler()->Cut(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3530 | RecordAction(base::UserMetricsAction("Cut")); |
| 3531 | } |
| 3532 | |
| 3533 | void WebContentsImpl::Copy() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3534 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3535 | if (!focused_frame) |
| 3536 | return; |
| 3537 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3538 | focused_frame->GetFrameInputHandler()->Copy(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3539 | RecordAction(base::UserMetricsAction("Copy")); |
| 3540 | } |
| 3541 | |
| 3542 | void WebContentsImpl::CopyToFindPboard() { |
| 3543 | #if defined(OS_MACOSX) |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3544 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3545 | if (!focused_frame) |
| 3546 | return; |
| 3547 | |
| 3548 | // Windows/Linux don't have the concept of a find pasteboard. |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3549 | focused_frame->GetFrameInputHandler()->CopyToFindPboard(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3550 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 3551 | #endif |
| 3552 | } |
| 3553 | |
| 3554 | void WebContentsImpl::Paste() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3555 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3556 | if (!focused_frame) |
| 3557 | return; |
| 3558 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3559 | focused_frame->GetFrameInputHandler()->Paste(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3560 | RecordAction(base::UserMetricsAction("Paste")); |
| 3561 | } |
| 3562 | |
| 3563 | void WebContentsImpl::PasteAndMatchStyle() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3564 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3565 | if (!focused_frame) |
| 3566 | return; |
| 3567 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3568 | focused_frame->GetFrameInputHandler()->PasteAndMatchStyle(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3569 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 3570 | } |
| 3571 | |
| 3572 | void WebContentsImpl::Delete() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3573 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3574 | if (!focused_frame) |
| 3575 | return; |
| 3576 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3577 | focused_frame->GetFrameInputHandler()->Delete(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3578 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 3579 | } |
| 3580 | |
| 3581 | void WebContentsImpl::SelectAll() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3582 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3583 | if (!focused_frame) |
| 3584 | return; |
| 3585 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3586 | focused_frame->GetFrameInputHandler()->SelectAll(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3587 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 3588 | } |
| 3589 | |
yabinh | 351e7ec | 2017-03-10 02:43:24 | [diff] [blame] | 3590 | void WebContentsImpl::CollapseSelection() { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3591 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3592 | if (!focused_frame) |
| 3593 | return; |
| 3594 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3595 | focused_frame->GetFrameInputHandler()->CollapseSelection(); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3596 | } |
| 3597 | |
| 3598 | void WebContentsImpl::Replace(const base::string16& word) { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3599 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3600 | if (!focused_frame) |
| 3601 | return; |
| 3602 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3603 | focused_frame->GetFrameInputHandler()->Replace(word); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3604 | } |
| 3605 | |
| 3606 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
Dave Tapuska | b336b92 | 2017-07-06 19:24:05 | [diff] [blame] | 3607 | RenderFrameHostImpl* focused_frame = GetFocusedFrame(); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3608 | if (!focused_frame) |
| 3609 | return; |
| 3610 | |
dtapuska | 9d46ef7d | 2017-05-26 19:06:06 | [diff] [blame] | 3611 | focused_frame->GetFrameInputHandler()->ReplaceMisspelling(word); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3612 | } |
| 3613 | |
| 3614 | void WebContentsImpl::NotifyContextMenuClosed( |
| 3615 | const CustomContextMenuContext& context) { |
| 3616 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3617 | if (!focused_frame) |
| 3618 | return; |
| 3619 | |
| 3620 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 3621 | focused_frame->GetRoutingID(), context)); |
| 3622 | } |
| 3623 | |
| 3624 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 3625 | int action, const CustomContextMenuContext& context) { |
| 3626 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3627 | if (!focused_frame) |
| 3628 | return; |
| 3629 | |
| 3630 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 3631 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 3632 | } |
| 3633 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3634 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 3635 | return view_->GetNativeView(); |
| 3636 | } |
| 3637 | |
| 3638 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 3639 | return view_->GetContentNativeView(); |
| 3640 | } |
| 3641 | |
| 3642 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 3643 | return view_->GetTopLevelNativeWindow(); |
| 3644 | } |
| 3645 | |
| 3646 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 3647 | return view_->GetViewBounds(); |
| 3648 | } |
| 3649 | |
| 3650 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
| 3651 | gfx::Rect rv; |
| 3652 | view_->GetContainerBounds(&rv); |
| 3653 | return rv; |
| 3654 | } |
| 3655 | |
| 3656 | DropData* WebContentsImpl::GetDropData() { |
| 3657 | return view_->GetDropData(); |
| 3658 | } |
| 3659 | |
| 3660 | void WebContentsImpl::Focus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3661 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3662 | } |
| 3663 | |
| 3664 | void WebContentsImpl::SetInitialFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3665 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3666 | } |
| 3667 | |
| 3668 | void WebContentsImpl::StoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3669 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3670 | } |
| 3671 | |
| 3672 | void WebContentsImpl::RestoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3673 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3674 | } |
| 3675 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3676 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
Maxim Podgorodskiy | a926c4ff | 2017-11-20 02:06:39 | [diff] [blame] | 3677 | view_->FocusThroughTabTraversal(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3678 | } |
| 3679 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3680 | bool WebContentsImpl::ShowingInterstitialPage() const { |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 3681 | return interstitial_page_ != nullptr; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3682 | } |
| 3683 | |
Pete Williamson | 89aa140 | 2017-07-07 19:58:41 | [diff] [blame] | 3684 | void WebContentsImpl::AdjustPreviewsStateForNavigation( |
| 3685 | PreviewsState* previews_state) { |
| 3686 | if (delegate_) |
Doug Arnett | c681bbe | 2018-04-06 04:04:46 | [diff] [blame] | 3687 | delegate_->AdjustPreviewsStateForNavigation(this, previews_state); |
Pete Williamson | 89aa140 | 2017-07-07 19:58:41 | [diff] [blame] | 3688 | } |
| 3689 | |
Maxim Podgorodskiy | a926c4ff | 2017-11-20 02:06:39 | [diff] [blame] | 3690 | InterstitialPageImpl* WebContentsImpl::GetInterstitialPage() const { |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 3691 | return interstitial_page_; |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3692 | } |
| 3693 | |
Gyuyoung Kim | 80143f5e | 2018-04-02 02:40:25 | [diff] [blame] | 3694 | void WebContentsImpl::PausePageScheduledTasks(bool paused) { |
| 3695 | SendPageMessage( |
| 3696 | new PageMsg_PausePageScheduledTasks(MSG_ROUTING_NONE, paused)); |
| 3697 | } |
| 3698 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3699 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3700 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 3701 | // so we also support this MIME type. |
| 3702 | return contents_mime_type_ == "text/html" || |
| 3703 | contents_mime_type_ == "text/xml" || |
| 3704 | contents_mime_type_ == "application/xhtml+xml" || |
| 3705 | contents_mime_type_ == "text/plain" || |
| 3706 | contents_mime_type_ == "text/css" || |
Kinuko Yasuda | 74702f9 | 2017-07-31 03:27:53 | [diff] [blame] | 3707 | blink::IsSupportedJavascriptMimeType(contents_mime_type_); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3708 | } |
| 3709 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3710 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3711 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3712 | if (!IsSavable()) { |
Min Qin | da0ed206 | 2018-02-23 22:00:53 | [diff] [blame] | 3713 | download::RecordSavePackageEvent( |
| 3714 | download::SAVE_PACKAGE_DOWNLOAD_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3715 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 3716 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3717 | } |
| 3718 | |
| 3719 | Stop(); |
| 3720 | |
| 3721 | // Create the save package and possibly prompt the user for the name to save |
| 3722 | // the page as. The user prompt is an asynchronous operation that runs on |
| 3723 | // another thread. |
| 3724 | save_package_ = new SavePackage(this); |
| 3725 | save_package_->GetSaveInfo(); |
| 3726 | } |
| 3727 | |
| 3728 | // Used in automated testing to bypass prompting the user for file names. |
| 3729 | // Instead, the names and paths are hard coded rather than running them through |
| 3730 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3731 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 3732 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3733 | SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3734 | // Stop the page from navigating. |
| 3735 | Stop(); |
| 3736 | |
| 3737 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3738 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3739 | } |
| 3740 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3741 | void WebContentsImpl::SaveFrame(const GURL& url, |
| 3742 | const Referrer& referrer) { |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 3743 | SaveFrameWithHeaders(url, referrer, std::string(), base::string16()); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3744 | } |
| 3745 | |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 3746 | void WebContentsImpl::SaveFrameWithHeaders( |
| 3747 | const GURL& url, |
| 3748 | const Referrer& referrer, |
| 3749 | const std::string& headers, |
| 3750 | const base::string16& suggested_filename) { |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3751 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3752 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 3753 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 3754 | return; |
| 3755 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3756 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3757 | // by explicitly passing in which frame this method should target. This would |
| 3758 | // indicate whether it's the main frame, and also tell us the frame pointer |
| 3759 | // to use for routing. |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3760 | bool is_main_frame = (url == GetLastCommittedURL()); |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3761 | RenderFrameHost* frame_host = GetMainFrame(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3762 | |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3763 | StoragePartition* storage_partition = BrowserContext::GetStoragePartition( |
| 3764 | GetBrowserContext(), frame_host->GetSiteInstance()); |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 3765 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3766 | if (is_main_frame) { |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3767 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3768 | if (entry) |
| 3769 | post_id = entry->GetPostID(); |
| 3770 | } |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 3771 | net::NetworkTrafficAnnotationTag traffic_annotation = |
| 3772 | net::DefineNetworkTrafficAnnotation("download_web_contents_frame", R"( |
| 3773 | semantics { |
| 3774 | sender: "Save Page Action" |
| 3775 | description: |
| 3776 | "Saves the given frame's URL to the local file system." |
| 3777 | trigger: |
| 3778 | "The user has triggered a save operation on the frame through a " |
| 3779 | "context menu or other mechanism." |
| 3780 | data: "None." |
| 3781 | destination: WEBSITE |
| 3782 | } |
| 3783 | policy { |
Ramin Halavati | 3b97978 | 2017-07-21 11:40:26 | [diff] [blame] | 3784 | cookies_allowed: YES |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 3785 | cookies_store: "user" |
| 3786 | setting: |
| 3787 | "This feature cannot be disabled by settings, but it's is only " |
| 3788 | "triggered by user request." |
| 3789 | policy_exception_justification: "Not implemented." |
| 3790 | })"); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 3791 | auto params = std::make_unique<download::DownloadUrlParameters>( |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3792 | url, frame_host->GetProcess()->GetID(), |
| 3793 | frame_host->GetRenderViewHost()->GetRoutingID(), |
Ramin Halavati | 03efa73 | 2017-06-12 09:28:20 | [diff] [blame] | 3794 | frame_host->GetRoutingID(), storage_partition->GetURLRequestContext(), |
Ramin Halavati | 24e2101 | 2017-07-10 12:56:06 | [diff] [blame] | 3795 | traffic_annotation); |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 3796 | params->set_referrer(referrer.url); |
| 3797 | params->set_referrer_policy( |
| 3798 | Referrer::ReferrerPolicyForUrlRequest(referrer.policy)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3799 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3800 | if (post_id >= 0) |
| 3801 | params->set_method("POST"); |
| 3802 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3803 | |
| 3804 | if (headers.empty()) { |
| 3805 | params->set_prefer_cache(true); |
| 3806 | } else { |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 3807 | for (download::DownloadUrlParameters::RequestHeadersNameValuePair |
| 3808 | key_value : ParseDownloadHeaders(headers)) { |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 3809 | params->add_request_header(key_value.first, key_value.second); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3810 | } |
| 3811 | } |
Xing Liu | 10329bf | 2018-03-20 19:22:14 | [diff] [blame] | 3812 | params->set_suggested_name(suggested_filename); |
Min Qin | 0ca8e1ee | 2018-01-31 00:49:35 | [diff] [blame] | 3813 | params->set_download_source(download::DownloadSource::WEB_CONTENTS_API); |
thestig | 859c7889 | 2017-05-15 21:17:06 | [diff] [blame] | 3814 | BrowserContext::GetDownloadManager(GetBrowserContext()) |
Ramin Halavati | 03efa73 | 2017-06-12 09:28:20 | [diff] [blame] | 3815 | ->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3816 | } |
| 3817 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3818 | void WebContentsImpl::GenerateMHTML( |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 3819 | const MHTMLGenerationParams& params, |
Avi Drissman | 149b783 | 2018-03-23 14:31:49 | [diff] [blame] | 3820 | base::OnceCallback<void(int64_t)> callback) { |
| 3821 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, |
| 3822 | std::move(callback)); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 3823 | } |
| 3824 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3825 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3826 | return contents_mime_type_; |
| 3827 | } |
| 3828 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3829 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3830 | return notify_disconnection_; |
| 3831 | } |
| 3832 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3833 | RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3834 | return &renderer_preferences_; |
| 3835 | } |
| 3836 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 3837 | void WebContentsImpl::Close() { |
| 3838 | Close(GetRenderViewHost()); |
| 3839 | } |
| 3840 | |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 3841 | void WebContentsImpl::DragSourceEndedAt(float client_x, |
| 3842 | float client_y, |
| 3843 | float screen_x, |
| 3844 | float screen_y, |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3845 | blink::WebDragOperation operation, |
| 3846 | RenderWidgetHost* source_rwh) { |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3847 | if (browser_plugin_embedder_.get()) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 3848 | browser_plugin_embedder_->DragSourceEndedAt( |
| 3849 | client_x, client_y, screen_x, screen_y, operation); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3850 | if (source_rwh) { |
Ella Ge | 80a52dce | 2017-11-15 18:01:52 | [diff] [blame] | 3851 | source_rwh->DragSourceEndedAt(gfx::PointF(client_x, client_y), |
| 3852 | gfx::PointF(screen_x, screen_y), operation); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3853 | } |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3854 | } |
| 3855 | |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 3856 | void WebContentsImpl::LoadStateChanged( |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 3857 | const std::string& host, |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 3858 | const net::LoadStateWithParam& load_state, |
| 3859 | uint64_t upload_position, |
| 3860 | uint64_t upload_size) { |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 3861 | base::string16 host16 = url_formatter::IDNToUnicode(host); |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 3862 | // Drop no-op updates. |
| 3863 | if (load_state_.state == load_state.state && |
| 3864 | load_state_.param == load_state.param && |
| 3865 | upload_position_ == upload_position && upload_size_ == upload_size && |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 3866 | load_state_host_ == host16) { |
Elly Fong-Jones | cad9c3d1 | 2018-01-31 17:26:10 | [diff] [blame] | 3867 | return; |
| 3868 | } |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 3869 | load_state_ = load_state; |
| 3870 | upload_position_ = upload_position; |
| 3871 | upload_size_ = upload_size; |
Charles Harrison | 911fa06 | 2018-03-06 21:01:46 | [diff] [blame] | 3872 | load_state_host_ = host16; |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 3873 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
| 3874 | SetNotWaitingForResponse(); |
| 3875 | if (IsLoading()) { |
| 3876 | NotifyNavigationStateChanged(static_cast<InvalidateTypes>( |
| 3877 | INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB)); |
| 3878 | } |
| 3879 | } |
| 3880 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 3881 | void WebContentsImpl::SetVisibility(Visibility visibility) { |
| 3882 | const Visibility previous_visibility = visibility_; |
| 3883 | visibility_ = visibility; |
| 3884 | |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 3885 | // Notify observers if the visibility changed or if WasShown() is being called |
| 3886 | // for the first time. |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 3887 | if (visibility != previous_visibility || |
| 3888 | (visibility == Visibility::VISIBLE && !did_first_set_visible_)) { |
| 3889 | for (auto& observer : observers_) |
| 3890 | observer.OnVisibilityChanged(visibility); |
| 3891 | } |
| 3892 | } |
| 3893 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 3894 | void WebContentsImpl::NotifyWebContentsFocused( |
| 3895 | RenderWidgetHost* render_widget_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3896 | for (auto& observer : observers_) |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 3897 | observer.OnWebContentsFocused(render_widget_host); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 3898 | } |
| 3899 | |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 3900 | void WebContentsImpl::NotifyWebContentsLostFocus( |
| 3901 | RenderWidgetHost* render_widget_host) { |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 3902 | for (auto& observer : observers_) |
Michael Thiessen | 896405db | 2017-07-20 17:52:32 | [diff] [blame] | 3903 | observer.OnWebContentsLostFocus(render_widget_host); |
zijiehe | 3bee08e2 | 2017-05-17 04:14:46 | [diff] [blame] | 3904 | } |
| 3905 | |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3906 | void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) { |
| 3907 | if (source_rwh) |
| 3908 | source_rwh->DragSourceSystemDragEnded(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3909 | if (browser_plugin_embedder_.get()) |
| 3910 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 3911 | } |
| 3912 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 3913 | void WebContentsImpl::NavigatedByUser() { |
| 3914 | OnUserInteraction(blink::WebInputEvent::kUndefined); |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 3915 | } |
| 3916 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3917 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3918 | closed_by_user_gesture_ = value; |
| 3919 | } |
| 3920 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3921 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3922 | return closed_by_user_gesture_; |
| 3923 | } |
| 3924 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3925 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3926 | return minimum_zoom_percent_; |
| 3927 | } |
| 3928 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3929 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3930 | return maximum_zoom_percent_; |
| 3931 | } |
| 3932 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3933 | void WebContentsImpl::SetPageScale(float page_scale_factor) { |
Lukasz Anforowicz | f4357ca | 2017-09-07 01:43:32 | [diff] [blame] | 3934 | GetRenderViewHost()->Send(new ViewMsg_SetPageScale( |
| 3935 | GetRenderViewHost()->GetRoutingID(), page_scale_factor)); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 3936 | } |
| 3937 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3938 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
Francois Doray | 24fc62c | 2017-12-11 17:27:33 | [diff] [blame] | 3939 | return IsBeingCaptured() ? preferred_size_for_capture_ : preferred_size_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 3940 | } |
| 3941 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3942 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3943 | if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) && |
| 3944 | GetBrowserPluginGuest()) |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 3945 | return GetBrowserPluginGuest()->LockMouse(allowed); |
| 3946 | |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3947 | if (mouse_lock_widget_) { |
| 3948 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 3949 | return mouse_lock_widget_->delegate() |
| 3950 | ->GetAsWebContents() |
| 3951 | ->GotResponseToLockMouseRequest(allowed); |
| 3952 | } |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3953 | |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3954 | if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed)) |
| 3955 | return true; |
| 3956 | } |
| 3957 | |
| 3958 | for (WebContentsImpl* current = this; current; |
| 3959 | current = current->GetOuterWebContents()) { |
| 3960 | current->mouse_lock_widget_ = nullptr; |
| 3961 | } |
| 3962 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3963 | return false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3964 | } |
| 3965 | |
Joe Downing | 13dd76b | 2018-04-09 18:32:15 | [diff] [blame] | 3966 | bool WebContentsImpl::GotResponseToKeyboardLockRequest(bool allowed) { |
| 3967 | if (!keyboard_lock_widget_) |
| 3968 | return false; |
| 3969 | |
| 3970 | if (keyboard_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 3971 | NOTREACHED(); |
| 3972 | return false; |
| 3973 | } |
| 3974 | |
| 3975 | // KeyboardLock is only supported when called by the top-level browsing |
| 3976 | // context and is not supported in embedded content scenarios. |
| 3977 | if (GetOuterWebContents()) |
| 3978 | return false; |
| 3979 | |
| 3980 | keyboard_lock_widget_->GotResponseToKeyboardLockRequest(allowed); |
| 3981 | return true; |
| 3982 | } |
| 3983 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3984 | bool WebContentsImpl::HasOpener() const { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 3985 | return GetOpener() != nullptr; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 3986 | } |
| 3987 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 3988 | RenderFrameHostImpl* WebContentsImpl::GetOpener() const { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 3989 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 3990 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 3991 | } |
| 3992 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 3993 | bool WebContentsImpl::HasOriginalOpener() const { |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 3994 | return GetOriginalOpener() != nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 3995 | } |
| 3996 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 3997 | RenderFrameHostImpl* WebContentsImpl::GetOriginalOpener() const { |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 3998 | FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 3999 | return opener_ftn ? opener_ftn->current_frame_host() : nullptr; |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 4000 | } |
| 4001 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4002 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4003 | color_chooser_->DidChooseColorInColorChooser(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4004 | } |
| 4005 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4006 | void WebContentsImpl::DidEndColorChooser() { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4007 | color_chooser_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4008 | } |
| 4009 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4010 | int WebContentsImpl::DownloadImage( |
| 4011 | const GURL& url, |
| 4012 | bool is_favicon, |
| 4013 | uint32_t max_bitmap_size, |
| 4014 | bool bypass_cache, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4015 | WebContents::ImageDownloadCallback callback) { |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4016 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4017 | static int next_image_download_id = 0; |
leon.han | 6e9dee2 | 2016-02-25 03:44:06 | [diff] [blame] | 4018 | const content::mojom::ImageDownloaderPtr& mojo_image_downloader = |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4019 | GetMainFrame()->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4020 | const int download_id = ++next_image_download_id; |
| 4021 | if (!mojo_image_downloader) { |
| 4022 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 4023 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4024 | // hang the callback indefinitely since the IPC would be dropped. Now, |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4025 | // respond with a 400 HTTP error code to indicate that something went wrong. |
| 4026 | BrowserThread::PostTask( |
| 4027 | BrowserThread::UI, FROM_HERE, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4028 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4029 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4030 | download_id, url, 400, std::vector<SkBitmap>(), |
| 4031 | std::vector<gfx::Size>())); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4032 | return download_id; |
| 4033 | } |
| 4034 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 4035 | mojo_image_downloader->DownloadImage( |
sammc | f6f4fcf | 2016-06-21 05:39:39 | [diff] [blame] | 4036 | url, is_favicon, max_bitmap_size, bypass_cache, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4037 | base::BindOnce(&WebContentsImpl::OnDidDownloadImage, |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4038 | weak_factory_.GetWeakPtr(), std::move(callback), |
| 4039 | download_id, url)); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 4040 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4041 | } |
| 4042 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4043 | void WebContentsImpl::Find(int request_id, |
| 4044 | const base::string16& search_text, |
| 4045 | const blink::WebFindOptions& options) { |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 4046 | // Cowardly refuse to search for no text. |
| 4047 | if (search_text.empty()) { |
| 4048 | NOTREACHED(); |
| 4049 | return; |
| 4050 | } |
| 4051 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 4052 | GetOrCreateFindRequestManager()->Find(request_id, search_text, options); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | void WebContentsImpl::StopFinding(StopFindAction action) { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 4056 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 4057 | manager->StopFinding(action); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 4058 | } |
| 4059 | |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4060 | bool WebContentsImpl::WasEverAudible() { |
| 4061 | return was_ever_audible_; |
| 4062 | } |
| 4063 | |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 4064 | void WebContentsImpl::GetManifest(GetManifestCallback callback) { |
| 4065 | manifest_manager_host_->GetManifest(std::move(callback)); |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 4066 | } |
| 4067 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4068 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4069 | // Clean up related state and initiate the fullscreen exit. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 4070 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4071 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 4072 | } |
| 4073 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4074 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 4075 | if (delayed_open_url_params_.get()) { |
| 4076 | OpenURL(*delayed_open_url_params_.get()); |
| 4077 | delayed_open_url_params_.reset(nullptr); |
| 4078 | return; |
| 4079 | } |
| 4080 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4081 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 4082 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 4083 | if (is_resume_pending_) { |
| 4084 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 4085 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 4086 | GetMainFrame()->Init(); |
| 4087 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 4088 | } |
| 4089 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4090 | bool WebContentsImpl::FocusLocationBarByDefault() { |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 4091 | // When the browser is started with about:blank as the startup URL, focus |
| 4092 | // the location bar (which will also select its contents) so people can |
| 4093 | // simply begin typing to navigate elsewhere. |
| 4094 | // |
| 4095 | // We need to be careful not to trigger this for anything other than the |
| 4096 | // startup navigation. In particular, if we allow an attacker to open a |
| 4097 | // popup to about:blank, then navigate, focusing the Omnibox will cause the |
| 4098 | // end of the new URL to be scrolled into view instead of the start, |
| 4099 | // allowing the attacker to spoof other URLs. The conditions checked here |
| 4100 | // are all aimed at ensuring no such attacker-controlled navigation can |
| 4101 | // trigger this. |
| 4102 | // |
| 4103 | // Note that we check the pending entry instead of the visible one; for the |
| 4104 | // startup URL case these are the same, but for the attacker-controlled |
| 4105 | // navigation case the visible entry is the committed "about:blank" URL and |
| 4106 | // the pending entry is the problematic navigation elsewhere. |
| 4107 | NavigationEntryImpl* entry = controller_.GetPendingEntry(); |
| 4108 | if (controller_.IsInitialNavigation() && entry && |
| 4109 | !entry->is_renderer_initiated() && |
csharrison | a3bd0b3 | 2016-10-19 18:40:48 | [diff] [blame] | 4110 | entry->GetURL() == url::kAboutBlankURL) { |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 4111 | return true; |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 4112 | } |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 4113 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4114 | } |
| 4115 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4116 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 4117 | if (delegate_) |
| 4118 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 4119 | } |
| 4120 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4121 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4122 | TRACE_EVENT1("navigation", "WebContentsImpl::DidStartNavigation", |
| 4123 | "navigation_handle", navigation_handle); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4124 | for (auto& observer : observers_) |
| 4125 | observer.DidStartNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4126 | } |
| 4127 | |
| 4128 | void WebContentsImpl::DidRedirectNavigation( |
| 4129 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4130 | TRACE_EVENT1("navigation", "WebContentsImpl::DidRedirectNavigation", |
| 4131 | "navigation_handle", navigation_handle); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4132 | for (auto& observer : observers_) |
| 4133 | observer.DidRedirectNavigation(navigation_handle); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4134 | |
| 4135 | // Notify accessibility if this is a reload. This has to called on the |
| 4136 | // BrowserAccessibilityManager associated with the old RFHI. |
| 4137 | if (navigation_handle->GetReloadType() != ReloadType::NONE) { |
| 4138 | NavigationHandleImpl* nhi = |
| 4139 | static_cast<NavigationHandleImpl*>(navigation_handle); |
| 4140 | BrowserAccessibilityManager* manager = |
| 4141 | nhi->frame_tree_node() |
| 4142 | ->current_frame_host() |
| 4143 | ->browser_accessibility_manager(); |
| 4144 | if (manager) |
| 4145 | manager->UserIsReloading(); |
| 4146 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4147 | } |
| 4148 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 4149 | void WebContentsImpl::ReadyToCommitNavigation( |
| 4150 | NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4151 | TRACE_EVENT1("navigation", "WebContentsImpl::ReadyToCommitNavigation", |
| 4152 | "navigation_handle", navigation_handle); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4153 | for (auto& observer : observers_) |
| 4154 | observer.ReadyToCommitNavigation(navigation_handle); |
John Abd-El-Malek | d488264 | 2017-12-04 21:45:19 | [diff] [blame] | 4155 | |
Kenneth Russell | 954ed9ce | 2018-04-12 23:07:01 | [diff] [blame] | 4156 | // If any domains are blocked from accessing 3D APIs because they may |
| 4157 | // have caused the GPU to reset recently, unblock them here if the user |
| 4158 | // initiated this navigation. This implies that the user was involved in |
| 4159 | // the decision to navigate, so there's no concern about |
| 4160 | // denial-of-service issues. Want to do this as early as |
| 4161 | // possible to avoid race conditions with pages attempting to access |
| 4162 | // WebGL early on. |
| 4163 | // |
| 4164 | // TODO(crbug.com/617904): currently navigations initiated by the browser |
| 4165 | // (reload button, reload menu option, pressing return in the Omnibox) |
| 4166 | // return false from HasUserGesture(). If or when that is addressed, |
| 4167 | // remove the check for IsRendererInitiated() below. |
| 4168 | // |
| 4169 | // TODO(crbug.com/832180): HasUserGesture comes from the renderer |
| 4170 | // process and isn't validated. Until it is, don't trust it. |
| 4171 | if (!navigation_handle->IsRendererInitiated()) { |
| 4172 | GpuDataManagerImpl::GetInstance()->UnblockDomainFrom3DAPIs( |
| 4173 | navigation_handle->GetURL()); |
| 4174 | } |
| 4175 | |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 4176 | if (navigation_handle->IsSameDocument()) |
| 4177 | return; |
| 4178 | |
John Abd-El-Malek | d488264 | 2017-12-04 21:45:19 | [diff] [blame] | 4179 | controller_.ssl_manager()->DidStartResourceResponse( |
| 4180 | navigation_handle->GetURL(), |
| 4181 | net::IsCertStatusError(navigation_handle->GetSSLInfo().cert_status)); |
John Abd-El-Malek | fde08e6da | 2017-12-05 04:06:24 | [diff] [blame] | 4182 | |
| 4183 | SetNotWaitingForResponse(); |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 4184 | } |
| 4185 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4186 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
Charles Harrison | 53096ba | 2017-12-15 15:39:48 | [diff] [blame] | 4187 | TRACE_EVENT1("navigation", "WebContentsImpl::DidFinishNavigation", |
| 4188 | "navigation_handle", navigation_handle); |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 4189 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4190 | for (auto& observer : observers_) |
| 4191 | observer.DidFinishNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 4192 | |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4193 | if (navigation_handle->HasCommitted()) { |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4194 | BrowserAccessibilityManager* manager = |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 4195 | static_cast<RenderFrameHostImpl*>( |
| 4196 | navigation_handle->GetRenderFrameHost()) |
| 4197 | ->browser_accessibility_manager(); |
| 4198 | if (manager) { |
| 4199 | if (navigation_handle->IsErrorPage()) { |
| 4200 | manager->NavigationFailed(); |
| 4201 | } else { |
| 4202 | manager->NavigationSucceeded(); |
| 4203 | } |
| 4204 | } |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4205 | |
| 4206 | if (navigation_handle->IsInMainFrame() && |
| 4207 | !navigation_handle->IsSameDocument()) { |
| 4208 | was_ever_audible_ = false; |
Steven Holte | 3804134 | 2018-06-22 22:00:57 | [diff] [blame] | 4209 | last_committed_source_id_ = |
| 4210 | ukm::ConvertToSourceId(navigation_handle->GetNavigationId(), |
| 4211 | ukm::SourceIdType::NAVIGATION_ID); |
Tommy Steimel | 1836051 | 2017-11-01 00:38:19 | [diff] [blame] | 4212 | } |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4213 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 4214 | } |
| 4215 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4216 | void WebContentsImpl::DidFailLoadWithError( |
| 4217 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4218 | const GURL& url, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4219 | int error_code, |
Yutaka Hirano | 16d3c5d | 2017-07-31 06:17:30 | [diff] [blame] | 4220 | const base::string16& error_description) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4221 | for (auto& observer : observers_) { |
Yutaka Hirano | 16d3c5d | 2017-07-31 06:17:30 | [diff] [blame] | 4222 | observer.DidFailLoad(render_frame_host, url, error_code, error_description); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4223 | } |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 4224 | } |
| 4225 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 4226 | void WebContentsImpl::NotifyChangedNavigationState( |
| 4227 | InvalidateTypes changed_flags) { |
| 4228 | NotifyNavigationStateChanged(changed_flags); |
| 4229 | } |
| 4230 | |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 4231 | void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url, |
| 4232 | ReloadType reload_type) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4233 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4234 | for (auto& observer : observers_) |
| 4235 | observer.DidStartNavigationToPendingEntry(url, reload_type); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4236 | } |
| 4237 | |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 4238 | bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) { |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 4239 | if (!delegate_) |
| 4240 | return true; |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 4241 | return delegate_->ShouldTransferNavigation(is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 4242 | } |
| 4243 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 4244 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
| 4245 | if (!delegate_) |
| 4246 | return false; |
| 4247 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 4248 | } |
| 4249 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4250 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 4251 | bool navigation_is_within_page) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4252 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 4253 | // different page. The next page will not start out assuming it is in |
| 4254 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 4255 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 4256 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4257 | return; |
| 4258 | } |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 4259 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4260 | ExitFullscreen(false); |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 4261 | DCHECK(!IsFullscreenForCurrentTab()); |
Joe Downing | c1a57efe | 2018-05-09 18:23:54 | [diff] [blame] | 4262 | |
| 4263 | // Clean up keyboard lock state when navigating. |
| 4264 | CancelKeyboardLock(keyboard_lock_widget_); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4265 | } |
| 4266 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4267 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4268 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4269 | const LoadCommittedDetails& details, |
| 4270 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 4271 | if (details.is_navigation_to_different_page()) { |
| 4272 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 4273 | // doesn't let us know that the cursor left an element during a |
| 4274 | // transition (this is also why the mouse cursor remains as a hand after |
| 4275 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 4276 | // clear the bubble when a user navigates to a named anchor in the same |
| 4277 | // page. |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 4278 | ClearTargetURL(); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 4279 | |
| 4280 | RenderWidgetHostViewBase* rwhvb = |
| 4281 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 4282 | if (rwhvb) |
| 4283 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4284 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4285 | did_first_visually_non_empty_paint_ = false; |
| 4286 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4287 | // Reset theme color on navigation to new page. |
| 4288 | theme_color_ = SK_ColorTRANSPARENT; |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4289 | } |
| 4290 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4291 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4292 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4293 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4294 | } |
| 4295 | |
| 4296 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 4297 | RenderFrameHostImpl* render_frame_host, |
| 4298 | const LoadCommittedDetails& details, |
| 4299 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4300 | // Now that something has committed, we don't need to track whether the |
| 4301 | // initial page has been accessed. |
| 4302 | has_accessed_initial_document_ = false; |
| 4303 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4304 | // If we navigate off the page, close all JavaScript dialogs. |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 4305 | if (!details.is_same_document) |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 4306 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4307 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 4308 | // If this is a user-initiated navigation, start allowing JavaScript dialogs |
| 4309 | // again. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 4310 | if (params.gesture == NavigationGestureUser && dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 4311 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 4312 | } |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4313 | } |
| 4314 | |
| 4315 | void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { |
| 4316 | contents_mime_type_ = mime_type; |
| 4317 | } |
| 4318 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 4319 | bool WebContentsImpl::CanOverscrollContent() const { |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4320 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 4321 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4322 | return false; |
| 4323 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 4324 | if (delegate_) |
| 4325 | return delegate_->CanOverscrollContent(); |
| 4326 | |
| 4327 | return false; |
| 4328 | } |
| 4329 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4330 | void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source, |
| 4331 | SkColor theme_color) { |
| 4332 | if (source != GetMainFrame()) { |
| 4333 | // Only the main frame may control the theme. |
| 4334 | return; |
| 4335 | } |
| 4336 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4337 | // Update the theme color. This is to be published to observers after the |
| 4338 | // first visually non-empty paint. |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4339 | theme_color_ = theme_color; |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4340 | |
| 4341 | if (did_first_visually_non_empty_paint_ && |
| 4342 | last_sent_theme_color_ != theme_color_) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4343 | for (auto& observer : observers_) |
| 4344 | observer.DidChangeThemeColor(theme_color_); |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4345 | last_sent_theme_color_ = theme_color_; |
| 4346 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 4347 | } |
| 4348 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4349 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4350 | RenderFrameHostImpl* source, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 4351 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 4352 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 4353 | const std::string& mime_type, |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 4354 | ResourceType resource_type) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4355 | for (auto& observer : observers_) |
| 4356 | observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type); |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 4357 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 4358 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4359 | StoragePartition* partition = source->GetProcess()->GetStoragePartition(); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 4360 | scoped_refptr<net::URLRequestContextGetter> request_context( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4361 | resource_type == RESOURCE_TYPE_MEDIA |
| 4362 | ? partition->GetMediaURLRequestContext() |
| 4363 | : partition->GetURLRequestContext()); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 4364 | BrowserThread::PostTask( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4365 | BrowserThread::IO, FROM_HERE, |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 4366 | base::BindOnce(&NotifyCacheOnIO, request_context, url, http_method)); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 4367 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 4368 | } |
| 4369 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4370 | void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) { |
| 4371 | // Any frame can trigger display of insecure content, so we don't check |
| 4372 | // |source| here. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 4373 | DidDisplayInsecureContent(); |
| 4374 | } |
| 4375 | |
| 4376 | void WebContentsImpl::DidDisplayInsecureContent() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 4377 | controller_.ssl_manager()->DidDisplayMixedContent(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 4378 | } |
| 4379 | |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 4380 | void WebContentsImpl::OnDidContainInsecureFormAction( |
| 4381 | RenderFrameHostImpl* source) { |
| 4382 | controller_.ssl_manager()->DidContainInsecureFormAction(); |
| 4383 | } |
| 4384 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4385 | void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source, |
| 4386 | const GURL& security_origin, |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 4387 | const GURL& target_url) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4388 | // TODO(nick, estark): Should we call FilterURL using |source|'s process on |
| 4389 | // these parameters? |target_url| seems unused, except for a log message. And |
| 4390 | // |security_origin| might be replaceable with the origin of the main frame. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 4391 | DidRunInsecureContent(security_origin, target_url); |
| 4392 | } |
| 4393 | |
| 4394 | void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin, |
| 4395 | const GURL& target_url) { |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 4396 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 4397 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 4398 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 4399 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 4400 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 4401 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 4402 | controller_.ssl_manager()->DidRunMixedContent(security_origin); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 4403 | } |
| 4404 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 4405 | void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) { |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 4406 | if (delegate_) { |
| 4407 | delegate_->PassiveInsecureContentFound(resource_url); |
| 4408 | } |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 4409 | } |
| 4410 | |
| 4411 | bool WebContentsImpl::ShouldAllowRunningInsecureContent( |
| 4412 | WebContents* web_contents, |
| 4413 | bool allowed_per_prefs, |
| 4414 | const url::Origin& origin, |
| 4415 | const GURL& resource_url) { |
Sergey Kuznetsov | 3ebc01b | 2018-02-01 04:57:36 | [diff] [blame] | 4416 | if (delegate_) { |
| 4417 | return delegate_->ShouldAllowRunningInsecureContent( |
| 4418 | web_contents, allowed_per_prefs, origin, resource_url); |
| 4419 | } |
| 4420 | |
| 4421 | return allowed_per_prefs; |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 4422 | } |
| 4423 | |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 4424 | void WebContentsImpl::ViewSource(RenderFrameHostImpl* frame) { |
| 4425 | DCHECK_EQ(this, WebContents::FromRenderFrameHost(frame)); |
| 4426 | |
| 4427 | // Don't do anything if there is no |delegate_| that could accept and show the |
| 4428 | // new WebContents containing the view-source. |
| 4429 | if (!delegate_) |
| 4430 | return; |
| 4431 | |
| 4432 | // Use the last committed entry, since the pending entry hasn't loaded yet and |
| 4433 | // won't be copied into the cloned tab. |
| 4434 | NavigationEntryImpl* last_committed_entry = |
| 4435 | static_cast<NavigationEntryImpl*>(frame->frame_tree_node() |
| 4436 | ->navigator() |
| 4437 | ->GetController() |
| 4438 | ->GetLastCommittedEntry()); |
| 4439 | if (!last_committed_entry) |
| 4440 | return; |
| 4441 | |
| 4442 | FrameNavigationEntry* frame_entry = |
| 4443 | last_committed_entry->GetFrameEntry(frame->frame_tree_node()); |
| 4444 | if (!frame_entry) |
| 4445 | return; |
| 4446 | |
| 4447 | // Any new WebContents opened while this WebContents is in fullscreen can be |
| 4448 | // used to confuse the user, so drop fullscreen. |
| 4449 | if (IsFullscreenForCurrentTab()) |
| 4450 | ExitFullscreen(true); |
| 4451 | |
| 4452 | // We intentionally don't share the SiteInstance with the original frame so |
| 4453 | // that view source has a consistent process model and always ends up in a new |
| 4454 | // process (https://crbug.com/699493). |
| 4455 | scoped_refptr<SiteInstanceImpl> site_instance_for_view_source = nullptr; |
| 4456 | // Referrer is not important, because view-source should not hit the network, |
| 4457 | // but should be served from the cache instead. |
| 4458 | Referrer referrer_for_view_source; |
| 4459 | // Do not restore title, derive it from the url. |
| 4460 | base::string16 title_for_view_source; |
| 4461 | auto navigation_entry = std::make_unique<NavigationEntryImpl>( |
| 4462 | site_instance_for_view_source, frame_entry->url(), |
| 4463 | referrer_for_view_source, title_for_view_source, ui::PAGE_TRANSITION_LINK, |
Marijn Kruisselbrink | 7a0d5e18 | 2018-05-24 22:55:09 | [diff] [blame] | 4464 | /* is_renderer_initiated = */ false, |
| 4465 | /* blob_url_loader_factory = */ nullptr); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 4466 | navigation_entry->SetVirtualURL(GURL(content::kViewSourceScheme + |
| 4467 | std::string(":") + |
| 4468 | frame_entry->url().spec())); |
| 4469 | |
| 4470 | // Do not restore scroller position. |
| 4471 | // TODO(creis, lukasza, arthursonzogni): Do not reuse the original PageState, |
| 4472 | // but start from a new one and only copy the needed data. |
| 4473 | const PageState& new_page_state = |
| 4474 | frame_entry->page_state().RemoveScrollOffset(); |
| 4475 | |
| 4476 | scoped_refptr<FrameNavigationEntry> new_frame_entry = |
| 4477 | navigation_entry->root_node()->frame_entry; |
| 4478 | new_frame_entry->set_method(frame_entry->method()); |
| 4479 | new_frame_entry->SetPageState(new_page_state); |
| 4480 | |
| 4481 | // Create a new WebContents, which is used to display the source code. |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 4482 | std::unique_ptr<WebContents> view_source_contents = |
Erik Chen | bb8e738e | 2018-04-28 14:10:43 | [diff] [blame] | 4483 | Create(CreateParams(GetBrowserContext())); |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 4484 | |
| 4485 | // Restore the previously created NavigationEntry. |
| 4486 | std::vector<std::unique_ptr<NavigationEntry>> navigation_entries; |
| 4487 | navigation_entries.push_back(std::move(navigation_entry)); |
| 4488 | view_source_contents->GetController().Restore(0, RestoreType::CURRENT_SESSION, |
| 4489 | &navigation_entries); |
| 4490 | |
| 4491 | // Add |view_source_contents| as a new tab. |
| 4492 | gfx::Rect initial_rect; |
| 4493 | constexpr bool kUserGesture = true; |
| 4494 | bool ignored_was_blocked; |
erikchen | bee5c962 | 2018-04-27 19:30:25 | [diff] [blame] | 4495 | delegate_->AddNewContents(this, std::move(view_source_contents), |
Lukasz Anforowicz | e1b954d9 | 2017-10-30 21:28:06 | [diff] [blame] | 4496 | WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 4497 | initial_rect, kUserGesture, &ignored_was_blocked); |
| 4498 | // Note that the |delegate_| could have deleted |view_source_contents| during |
| 4499 | // AddNewContents method call. |
| 4500 | } |
| 4501 | |
Jay Civelli | d5904f0 | 2018-03-23 19:43:57 | [diff] [blame] | 4502 | void WebContentsImpl::SubresourceResponseStarted(const GURL& url, |
| 4503 | net::CertStatus cert_status) { |
| 4504 | controller_.ssl_manager()->DidStartResourceResponse(url, cert_status); |
| 4505 | SetNotWaitingForResponse(); |
| 4506 | } |
| 4507 | |
Jay Civelli | 116683f | 2018-03-27 19:56:23 | [diff] [blame] | 4508 | void WebContentsImpl::ResourceLoadComplete( |
Jay Civelli | 52a6330 | 2018-04-30 22:39:55 | [diff] [blame] | 4509 | RenderFrameHost* render_frame_host, |
Jay Civelli | 116683f | 2018-03-27 19:56:23 | [diff] [blame] | 4510 | mojom::ResourceLoadInfoPtr resource_load_info) { |
John Abd-El-Malek | 9b8f7fa | 2017-12-04 23:52:25 | [diff] [blame] | 4511 | for (auto& observer : observers_) { |
Jay Civelli | 718fd6c0 | 2018-05-11 21:04:27 | [diff] [blame] | 4512 | observer.ResourceLoadComplete(render_frame_host, *resource_load_info); |
John Abd-El-Malek | 9b8f7fa | 2017-12-04 23:52:25 | [diff] [blame] | 4513 | } |
John Abd-El-Malek | d488264 | 2017-12-04 21:45:19 | [diff] [blame] | 4514 | } |
| 4515 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 4516 | void WebContentsImpl::PrintCrossProcessSubframe( |
| 4517 | const gfx::Rect& rect, |
| 4518 | int document_cookie, |
| 4519 | RenderFrameHost* subframe_host) { |
Wei Li | 5c0b4d1 | 2018-03-22 15:05:22 | [diff] [blame] | 4520 | auto* outer_contents = GetOuterWebContents(); |
| 4521 | if (outer_contents) { |
| 4522 | // When an extension or app page is printed, the content should be |
| 4523 | // composited with outer content, so the outer contents should handle the |
| 4524 | // print request. |
| 4525 | outer_contents->PrintCrossProcessSubframe(rect, document_cookie, |
| 4526 | subframe_host); |
| 4527 | return; |
| 4528 | } |
| 4529 | |
Wei Li | 5bb65974 | 2018-02-14 03:07:58 | [diff] [blame] | 4530 | // If there is no delegate such as in tests or during deletion, do nothing. |
| 4531 | if (!delegate_) |
| 4532 | return; |
| 4533 | |
| 4534 | delegate_->PrintCrossProcessSubframe(this, rect, document_cookie, |
| 4535 | subframe_host); |
| 4536 | } |
| 4537 | |
rob.buis | 300b087 | 2017-03-10 20:43:58 | [diff] [blame] | 4538 | #if defined(OS_ANDROID) |
| 4539 | base::android::ScopedJavaLocalRef<jobject> |
| 4540 | WebContentsImpl::GetJavaRenderFrameHostDelegate() { |
| 4541 | return GetJavaWebContents(); |
| 4542 | } |
| 4543 | #endif |
| 4544 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 4545 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors( |
Zhuoyu Qian | 4353f7f | 2018-01-08 05:33:00 | [diff] [blame] | 4546 | RenderFrameHostImpl* source) { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 4547 | controller_.ssl_manager()->DidDisplayContentWithCertErrors(); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 4548 | } |
| 4549 | |
| 4550 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
Zhuoyu Qian | 4353f7f | 2018-01-08 05:33:00 | [diff] [blame] | 4551 | RenderFrameHostImpl* source) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4552 | // TODO(nick, estark): Do we need to consider |source| here somehow? |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 4553 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 4554 | if (!entry) |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 4555 | return; |
| 4556 | |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 4557 | // TODO(estark): check that this does something reasonable for |
| 4558 | // about:blank and sandboxed origins. https://crbug.com/609527 |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 4559 | controller_.ssl_manager()->DidRunContentWithCertErrors( |
| 4560 | entry->GetURL().GetOrigin()); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 4561 | } |
| 4562 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4563 | void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4564 | for (auto& observer : observers_) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4565 | observer.DocumentLoadedInFrame(source); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 4566 | } |
| 4567 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4568 | void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source, |
| 4569 | const GURL& url) { |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 4570 | GURL validated_url(url); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4571 | source->GetProcess()->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 4572 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4573 | for (auto& observer : observers_) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4574 | observer.DidFinishLoad(source, validated_url); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 4575 | } |
| 4576 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4577 | void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source, |
| 4578 | int offset) { |
| 4579 | // All frames are allowed to navigate the global history. |
avi | 6ddfcae | 2015-06-30 15:50:57 | [diff] [blame] | 4580 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
| 4581 | controller_.GoToOffset(offset); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4582 | } |
| 4583 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4584 | void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source, |
| 4585 | int minimum_percent, |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 4586 | int maximum_percent) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4587 | minimum_zoom_percent_ = minimum_percent; |
| 4588 | maximum_zoom_percent_ = maximum_percent; |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 4589 | } |
| 4590 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4591 | void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source, |
| 4592 | float page_scale_factor) { |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 4593 | #if !defined(OS_ANDROID) |
| 4594 | // While page scale factor is used on mobile, this PageScaleFactorIsOne logic |
| 4595 | // is only needed on desktop. |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 4596 | bool is_one = page_scale_factor == 1.f; |
| 4597 | if (is_one != page_scale_factor_is_one_) { |
| 4598 | page_scale_factor_is_one_ = is_one; |
| 4599 | |
| 4600 | HostZoomMapImpl* host_zoom_map = |
| 4601 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 4602 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4603 | if (host_zoom_map) { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 4604 | host_zoom_map->SetPageScaleFactorIsOneForView( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4605 | source->GetProcess()->GetID(), source->GetRoutingID(), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 4606 | page_scale_factor_is_one_); |
| 4607 | } |
| 4608 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 4609 | #endif // !defined(OS_ANDROID) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 4610 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4611 | for (auto& observer : observers_) |
| 4612 | observer.OnPageScaleFactorChanged(page_scale_factor); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 4613 | } |
| 4614 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4615 | void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source, |
| 4616 | int request_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 4617 | const base::FilePath& path) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 4618 | if (!delegate_) |
| 4619 | return; |
| 4620 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 4621 | ChildProcessSecurityPolicyImpl* policy = |
| 4622 | ChildProcessSecurityPolicyImpl::GetInstance(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4623 | if (policy->CanReadFile(source->GetProcess()->GetID(), path)) { |
| 4624 | // TODO(nick): |this| param in the call below ought to be a RenderFrameHost. |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 4625 | delegate_->EnumerateDirectory(this, request_id, path); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4626 | } |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 4627 | } |
| 4628 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4629 | void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source, |
| 4630 | const std::string& protocol, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4631 | const GURL& url, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4632 | const base::string16& title, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 4633 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4634 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
| 4635 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 4636 | if (!delegate_) |
| 4637 | return; |
| 4638 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 4639 | ChildProcessSecurityPolicyImpl* policy = |
| 4640 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 4641 | if (policy->IsPseudoScheme(protocol)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 4642 | return; |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 4643 | |
[email protected] | c125e53 | 2014-05-10 20:39:06 | [diff] [blame] | 4644 | delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 4645 | } |
| 4646 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4647 | void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source, |
| 4648 | const std::string& protocol, |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 4649 | const GURL& url, |
| 4650 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4651 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
| 4652 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 4653 | if (!delegate_) |
| 4654 | return; |
| 4655 | |
| 4656 | ChildProcessSecurityPolicyImpl* policy = |
| 4657 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 4658 | if (policy->IsPseudoScheme(protocol)) |
| 4659 | return; |
| 4660 | |
| 4661 | delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture); |
| 4662 | } |
| 4663 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 4664 | void WebContentsImpl::OnUpdatePageImportanceSignals( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4665 | RenderFrameHostImpl* source, |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 4666 | const PageImportanceSignals& signals) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4667 | // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets |
| 4668 | // written to this one field. |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 4669 | page_importance_signals_ = signals; |
| 4670 | } |
| 4671 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4672 | void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source, |
| 4673 | int request_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4674 | int number_of_matches, |
| 4675 | const gfx::Rect& selection_rect, |
| 4676 | int active_match_ordinal, |
| 4677 | bool final_update) { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 4678 | if (active_match_ordinal > 0) |
| 4679 | SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance()); |
| 4680 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 4681 | // Forward the find reply to the FindRequestManager, along with the |
| 4682 | // RenderFrameHost associated with the frame that the reply came from. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4683 | GetOrCreateFindRequestManager()->OnFindReply( |
| 4684 | source, request_id, number_of_matches, selection_rect, |
| 4685 | active_match_ordinal, final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 4686 | } |
| 4687 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 4688 | #if defined(OS_ANDROID) |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 4689 | void WebContentsImpl::OnOpenDateTimeDialog( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4690 | RenderViewHostImpl* source, |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 4691 | const ViewHostMsg_DateTimeDialogValue_Params& value) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4692 | date_time_chooser_->ShowDialog( |
| 4693 | GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value, |
| 4694 | value.minimum, value.maximum, value.step, value.suggestions); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 4695 | } |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 4696 | #endif |
| 4697 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4698 | void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source, |
| 4699 | const std::string& json_string) { |
| 4700 | // TODO(nick, lukasza): The notification below should probably be updated to |
| 4701 | // include |source|. |
avi | 60bd490 | 2015-09-23 20:39:24 | [diff] [blame] | 4702 | std::string json = json_string; |
| 4703 | NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 4704 | Source<WebContents>(this), |
| 4705 | Details<std::string>(&json)); |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 4706 | } |
| 4707 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4708 | void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source, |
| 4709 | const GURL& manifest_url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4710 | bool blocked_by_policy) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4711 | // TODO(nick): Should we consider |source| here? Should we call FilterURL on |
| 4712 | // |manifest_url|? |
| 4713 | |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 4714 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4715 | for (auto& observer : observers_) |
| 4716 | observer.AppCacheAccessed(manifest_url, blocked_by_policy); |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 4717 | } |
| 4718 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4719 | void WebContentsImpl::OnColorChooserFactoryRequest( |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 4720 | blink::mojom::ColorChooserFactoryRequest request) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4721 | color_chooser_factory_bindings_.AddBinding(this, std::move(request)); |
| 4722 | } |
| 4723 | |
| 4724 | void WebContentsImpl::OpenColorChooser( |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 4725 | blink::mojom::ColorChooserRequest chooser_request, |
| 4726 | blink::mojom::ColorChooserClientPtr client, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 4727 | SkColor color, |
Joel Hockey | 163835a | 2017-12-20 11:51:57 | [diff] [blame] | 4728 | std::vector<blink::mojom::ColorSuggestionPtr> suggestions) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4729 | content::ColorChooser* new_color_chooser = |
Ivan Kotenkov | 2c0d2bb3 | 2017-11-01 15:41:28 | [diff] [blame] | 4730 | delegate_ ? delegate_->OpenColorChooser(this, color, suggestions) |
| 4731 | : nullptr; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 4732 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 4733 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 4734 | |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 4735 | color_chooser_.reset(); |
| 4736 | color_chooser_ = std::make_unique<ColorChooser>( |
| 4737 | new_color_chooser, std::move(chooser_request), std::move(client)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4738 | } |
| 4739 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4740 | #if BUILDFLAG(ENABLE_PLUGINS) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4741 | void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source, |
| 4742 | int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4743 | for (auto& observer : observers_) |
| 4744 | observer.PepperInstanceCreated(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4745 | pepper_playback_observer_->PepperInstanceCreated(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 4746 | } |
| 4747 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4748 | void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source, |
| 4749 | int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4750 | for (auto& observer : observers_) |
| 4751 | observer.PepperInstanceDeleted(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4752 | pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 4753 | } |
| 4754 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4755 | void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source, |
| 4756 | int plugin_child_id, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4757 | const base::FilePath& path, |
| 4758 | bool is_hung) { |
| 4759 | UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1); |
| 4760 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4761 | for (auto& observer : observers_) |
| 4762 | observer.PluginHungStatusChanged(plugin_child_id, path, is_hung); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4763 | } |
| 4764 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4765 | void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source, |
| 4766 | int32_t pp_instance) { |
| 4767 | pepper_playback_observer_->PepperStartsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 4768 | } |
| 4769 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4770 | void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source, |
| 4771 | int32_t pp_instance) { |
| 4772 | pepper_playback_observer_->PepperStopsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 4773 | } |
| 4774 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4775 | void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source, |
| 4776 | const base::FilePath& plugin_path, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4777 | base::ProcessId plugin_pid) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4778 | // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted, |
| 4779 | // and is only used by BlinkTestController. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4780 | for (auto& observer : observers_) |
| 4781 | observer.PluginCrashed(plugin_path, plugin_pid); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4782 | } |
| 4783 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4784 | void WebContentsImpl::OnRequestPpapiBrokerPermission( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4785 | RenderViewHostImpl* source, |
| 4786 | int ppb_broker_route_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4787 | const GURL& url, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 4788 | const base::FilePath& plugin_path) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4789 | base::Callback<void(bool)> permission_result_callback = base::Bind( |
| 4790 | &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this), |
| 4791 | source->GetProcess()->GetID(), ppb_broker_route_id); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4792 | if (!delegate_) { |
Tommy Nyquist | 4b749d0 | 2018-03-20 21:46:29 | [diff] [blame] | 4793 | std::move(permission_result_callback).Run(false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4794 | return; |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4795 | } |
| 4796 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4797 | if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path, |
| 4798 | permission_result_callback)) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4799 | NOTIMPLEMENTED(); |
Tommy Nyquist | 4b749d0 | 2018-03-20 21:46:29 | [diff] [blame] | 4800 | std::move(permission_result_callback).Run(false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4801 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4802 | } |
| 4803 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4804 | void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id, |
| 4805 | int ppb_broker_route_id, |
| 4806 | bool result) { |
| 4807 | RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
| 4808 | if (rph) { |
| 4809 | // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it |
| 4810 | // is not routed to a RenderView. |
| 4811 | rph->Send( |
| 4812 | new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result)); |
| 4813 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4814 | } |
| 4815 | |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 4816 | void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host, |
| 4817 | const IPC::Message& message) { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4818 | CHECK(!browser_plugin_embedder_.get()); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 4819 | CreateBrowserPluginEmbedderIfNecessary(); |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 4820 | browser_plugin_embedder_->OnMessageReceived(message, render_frame_host); |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 4821 | } |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4822 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 4823 | |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4824 | void WebContentsImpl::OnUpdateFaviconURL( |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 4825 | RenderFrameHostImpl* source, |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4826 | const std::vector<FaviconURL>& candidates) { |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 4827 | // Ignore favicons for non-main frame. |
| 4828 | if (source->GetParent()) { |
| 4829 | NOTREACHED(); |
| 4830 | return; |
| 4831 | } |
| 4832 | |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 4833 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 4834 | // navigation occurs while a page is still loading, the initial page |
| 4835 | // may stop loading and send us updated favicon URLs after the navigation |
| 4836 | // for the new page has committed. |
lukasza | 178ff09 | 2017-06-07 23:39:50 | [diff] [blame] | 4837 | if (!source->IsCurrent()) |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 4838 | return; |
| 4839 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4840 | for (auto& observer : observers_) |
| 4841 | observer.DidUpdateFaviconURL(candidates); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4842 | } |
| 4843 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 4844 | void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) { |
| 4845 | is_overlay_content_ = is_overlay_content; |
| 4846 | } |
| 4847 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4848 | void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) { |
| 4849 | // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if |
| 4850 | // |source| is the main frame. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4851 | for (auto& observer : observers_) |
| 4852 | observer.DidFirstVisuallyNonEmptyPaint(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4853 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4854 | did_first_visually_non_empty_paint_ = true; |
| 4855 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4856 | if (theme_color_ != last_sent_theme_color_) { |
| 4857 | // Theme color should have updated by now if there was one. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4858 | for (auto& observer : observers_) |
| 4859 | observer.DidChangeThemeColor(theme_color_); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4860 | last_sent_theme_color_ = theme_color_; |
| 4861 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 4862 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 4863 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 4864 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4865 | for (auto& observer : observers_) |
| 4866 | observer.BeforeFormRepostWarningShow(); |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 4867 | } |
| 4868 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 4869 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
| 4870 | Activate(); |
| 4871 | if (delegate_) |
| 4872 | delegate_->ShowRepostFormWarningDialog(this); |
| 4873 | } |
| 4874 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4875 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 4876 | return has_accessed_initial_document_; |
| 4877 | } |
| 4878 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4879 | void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4880 | const base::string16& title) { |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4881 | base::string16 final_title; |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 4882 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4883 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4884 | // If a page is created via window.open and never navigated, |
| 4885 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4886 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4887 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4888 | if (final_title == entry->GetTitle()) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4889 | return; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4890 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4891 | entry->SetTitle(final_title); |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 4892 | |
| 4893 | // The title for display may differ from the title just set; grab it. |
| 4894 | final_title = entry->GetTitleForDisplay(); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4895 | } else { |
| 4896 | if (page_title_when_no_navigation_entry_ == final_title) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4897 | return; // Nothing changed, don't bother. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4898 | |
| 4899 | page_title_when_no_navigation_entry_ = final_title; |
| 4900 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4901 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4902 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 4903 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4904 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4905 | for (auto& observer : observers_) |
Avi Drissman | 9300221 | 2017-09-27 03:20:52 | [diff] [blame] | 4906 | observer.TitleWasSet(entry); |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 4907 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4908 | // Broadcast notifications when the UI should be updated. |
| 4909 | if (entry == controller_.GetEntryAtOffset(0)) |
| 4910 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4911 | } |
| 4912 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4913 | void WebContentsImpl::SendChangeLoadProgress() { |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4914 | loading_last_progress_update_ = base::TimeTicks::Now(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4915 | if (delegate_) |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4916 | delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4917 | } |
| 4918 | |
| 4919 | void WebContentsImpl::ResetLoadProgressState() { |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 4920 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4921 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 4922 | loading_last_progress_update_ = base::TimeTicks(); |
| 4923 | } |
| 4924 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4925 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 4926 | // loading, or done loading. |
| 4927 | void WebContentsImpl::LoadingStateChanged(bool to_different_document, |
| 4928 | bool due_to_interstitial, |
| 4929 | LoadNotificationDetails* details) { |
| 4930 | // Do not send notifications about loading changes in the FrameTree while the |
| 4931 | // interstitial page is pausing the throbber. |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 4932 | if (ShowingInterstitialPage() && interstitial_page_->pause_throbber() && |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4933 | !due_to_interstitial) { |
| 4934 | return; |
| 4935 | } |
| 4936 | |
| 4937 | bool is_loading = IsLoading(); |
| 4938 | |
| 4939 | if (!is_loading) { |
| 4940 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 4941 | base::string16()); |
| 4942 | load_state_host_.clear(); |
| 4943 | upload_size_ = 0; |
| 4944 | upload_position_ = 0; |
| 4945 | } |
| 4946 | |
| 4947 | GetRenderManager()->SetIsLoading(is_loading); |
| 4948 | |
| 4949 | waiting_for_response_ = is_loading; |
| 4950 | is_load_to_different_document_ = to_different_document; |
| 4951 | |
| 4952 | if (delegate_) |
| 4953 | delegate_->LoadingStateChanged(this, to_different_document); |
| 4954 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
| 4955 | |
| 4956 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
| 4957 | if (is_loading) { |
| 4958 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 4959 | this, "URL", url, "Main FrameTreeNode id", |
| 4960 | GetFrameTree()->root()->frame_tree_node_id()); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4961 | for (auto& observer : observers_) |
| 4962 | observer.DidStartLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4963 | } else { |
| 4964 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 4965 | this, "URL", url); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4966 | for (auto& observer : observers_) |
| 4967 | observer.DidStopLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4968 | } |
| 4969 | |
| 4970 | // TODO(avi): Remove. http://crbug.com/170921 |
| 4971 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 4972 | NotificationDetails det = NotificationService::NoDetails(); |
| 4973 | if (details) |
| 4974 | det = Details<LoadNotificationDetails>(details); |
| 4975 | NotificationService::current()->Notify( |
| 4976 | type, Source<NavigationController>(&controller_), det); |
| 4977 | } |
| 4978 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4979 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host, |
| 4980 | RenderViewHost* new_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4981 | // After sending out a swap notification, we need to send a disconnect |
| 4982 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 4983 | // pointer. See Bug 1230284. |
| 4984 | notify_disconnection_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4985 | for (auto& observer : observers_) |
| 4986 | observer.RenderViewHostChanged(old_host, new_host); |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4987 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4988 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 4989 | // gets swapped, so we don't reuse the same embedder next time a |
| 4990 | // RenderViewHost is attached to this WebContents. |
| 4991 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4992 | } |
| 4993 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4994 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host, |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 4995 | RenderFrameHost* new_host, |
| 4996 | bool is_main_frame) { |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 4997 | #if defined(OS_ANDROID) |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 4998 | // Copy importance from |old_host| if |new_host| is a main frame. |
| 4999 | if (old_host && !new_host->GetParent()) { |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 5000 | static_cast<RenderFrameHostImpl*>(new_host) |
| 5001 | ->GetRenderWidgetHost() |
Bo Liu | 16dd7b832 | 2018-05-02 21:19:50 | [diff] [blame] | 5002 | ->SetImportance(static_cast<RenderFrameHostImpl*>(old_host) |
| 5003 | ->GetRenderWidgetHost() |
| 5004 | ->importance()); |
Bo Liu | 7c6779e9 | 2017-08-16 02:02:28 | [diff] [blame] | 5005 | } |
Bo Liu | 168c864 | 2017-08-28 18:26:02 | [diff] [blame] | 5006 | #endif |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5007 | for (auto& observer : observers_) |
| 5008 | observer.RenderFrameHostChanged(old_host, new_host); |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 5009 | |
| 5010 | view_->RenderFrameSwappedIn(old_host, new_host, is_main_frame); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5011 | } |
| 5012 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 5013 | // TODO(avi): Remove this entire function because this notification is already |
| 5014 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5015 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5016 | if (!notify_disconnection_) |
| 5017 | return; |
| 5018 | |
| 5019 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5020 | NotificationService::current()->Notify( |
| 5021 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 5022 | Source<WebContents>(this), |
| 5023 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5024 | } |
| 5025 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 5026 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 5027 | const LoadCommittedDetails& load_details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5028 | for (auto& observer : observers_) |
| 5029 | observer.NavigationEntryCommitted(load_details); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 5030 | } |
| 5031 | |
Sam McNally | 5c087a3 | 2017-08-25 01:46:14 | [diff] [blame] | 5032 | void WebContentsImpl::NotifyNavigationEntryChanged( |
| 5033 | const EntryChangedDetails& change_details) { |
| 5034 | for (auto& observer : observers_) |
| 5035 | observer.NavigationEntryChanged(change_details); |
| 5036 | } |
| 5037 | |
| 5038 | void WebContentsImpl::NotifyNavigationListPruned( |
| 5039 | const PrunedDetails& pruned_details) { |
| 5040 | for (auto& observer : observers_) |
| 5041 | observer.NavigationListPruned(pruned_details); |
| 5042 | } |
| 5043 | |
Christian Dullweber | 1af31e6 | 2018-02-22 11:49:48 | [diff] [blame] | 5044 | void WebContentsImpl::NotifyNavigationEntriesDeleted() { |
| 5045 | for (auto& observer : observers_) |
| 5046 | observer.NavigationEntriesDeleted(); |
| 5047 | } |
| 5048 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 5049 | void WebContentsImpl::OnAssociatedInterfaceRequest( |
| 5050 | RenderFrameHost* render_frame_host, |
| 5051 | const std::string& interface_name, |
| 5052 | mojo::ScopedInterfaceEndpointHandle handle) { |
| 5053 | auto it = binding_sets_.find(interface_name); |
| 5054 | if (it != binding_sets_.end()) |
| 5055 | it->second->OnRequestForFrame(render_frame_host, std::move(handle)); |
| 5056 | } |
| 5057 | |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 5058 | void WebContentsImpl::OnInterfaceRequest( |
| 5059 | RenderFrameHost* render_frame_host, |
| 5060 | const std::string& interface_name, |
| 5061 | mojo::ScopedMessagePipeHandle* interface_pipe) { |
Joel Hockey | 85b379d | 2017-12-11 10:42:13 | [diff] [blame] | 5062 | registry_.TryBindInterface(interface_name, interface_pipe); |
Ben Goodger | 9e24929e | 2017-07-21 03:13:40 | [diff] [blame] | 5063 | for (auto& observer : observers_) { |
| 5064 | observer.OnInterfaceRequestFromFrame(render_frame_host, interface_name, |
| 5065 | interface_pipe); |
| 5066 | if (!interface_pipe->is_valid()) |
| 5067 | break; |
| 5068 | } |
| 5069 | } |
| 5070 | |
Nicolas Dossou-gbete | bcab247 | 2017-09-09 12:28:40 | [diff] [blame] | 5071 | void WebContentsImpl::OnDidBlockFramebust(const GURL& url) { |
| 5072 | if (delegate_) |
| 5073 | delegate_->OnDidBlockFramebust(this, url); |
| 5074 | } |
| 5075 | |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 5076 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
| 5077 | return GetLastCommittedURL(); |
| 5078 | } |
| 5079 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5080 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5081 | for (auto& observer : observers_) |
| 5082 | observer.RenderFrameCreated(render_frame_host); |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 5083 | UpdateAccessibilityModeOnFrame(render_frame_host); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 5084 | |
| 5085 | if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent()) |
| 5086 | return; |
| 5087 | |
| 5088 | NavigationEntry* entry = controller_.GetPendingEntry(); |
| 5089 | if (entry && entry->IsViewSourceMode()) { |
| 5090 | // Put the renderer in view source mode. |
| 5091 | render_frame_host->Send( |
| 5092 | new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID())); |
| 5093 | } |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5094 | } |
| 5095 | |
| 5096 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
creis | 363889745 | 2017-05-09 22:07:50 | [diff] [blame] | 5097 | is_notifying_observers_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5098 | for (auto& observer : observers_) |
| 5099 | observer.RenderFrameDeleted(render_frame_host); |
creis | 363889745 | 2017-05-09 22:07:50 | [diff] [blame] | 5100 | is_notifying_observers_ = false; |
zqzhang | 7b6f4f0 | 2016-12-07 22:10:22 | [diff] [blame] | 5101 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 5102 | pepper_playback_observer_->RenderFrameDeleted(render_frame_host); |
| 5103 | #endif |
Becca Hughes | fd5d8f89 | 2018-06-14 18:23:36 | [diff] [blame] | 5104 | |
| 5105 | // Remove any fullscreen state that the frame has stored. |
| 5106 | FullscreenStateChanged(render_frame_host, false /* is_fullscreen */); |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 5107 | } |
| 5108 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5109 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 5110 | const ContextMenuParams& params) { |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 5111 | // If a renderer fires off a second command to show a context menu before the |
| 5112 | // first context menu is closed, just ignore it. https://crbug.com/707534 |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 5113 | if (showing_context_menu_) |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 5114 | return; |
| 5115 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 5116 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5117 | // Allow WebContentsDelegates to handle the context menu operation first. |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 5118 | if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5119 | return; |
| 5120 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 5121 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 5122 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 5123 | } |
| 5124 | |
avi | 777ff45 | 2017-02-09 19:04:48 | [diff] [blame] | 5125 | void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host, |
| 5126 | const base::string16& message, |
| 5127 | const base::string16& default_prompt, |
avi | 777ff45 | 2017-02-09 19:04:48 | [diff] [blame] | 5128 | JavaScriptDialogType dialog_type, |
| 5129 | IPC::Message* reply_msg) { |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 5130 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 5131 | // the contents of the previous page aren't shown behind it. This is required |
| 5132 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 5133 | // from it. https://crbug.com/823353 |
| 5134 | auto* render_widget_host_impl = |
| 5135 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 5136 | ->GetRenderWidgetHost(); |
| 5137 | if (render_widget_host_impl) |
| 5138 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 5139 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 5140 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 5141 | // http://crbug.com/728276 |
| 5142 | if (IsFullscreenForCurrentTab()) |
| 5143 | ExitFullscreen(true); |
| 5144 | |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5145 | auto callback = |
| 5146 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 5147 | render_frame_host->GetProcess()->GetID(), |
| 5148 | render_frame_host->GetRoutingID(), reply_msg); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5149 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5150 | std::vector<protocol::PageHandler*> page_handlers = |
| 5151 | protocol::PageHandler::EnabledForWebContents(this); |
| 5152 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 5153 | if (delegate_) |
| 5154 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 5155 | |
| 5156 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 5157 | // showing an interstitial as it's shown over the previous page and we don't |
| 5158 | // want the hidden page's dialogs to interfere with the interstitial. |
| 5159 | bool should_suppress = ShowingInterstitialPage() || |
| 5160 | (delegate_ && delegate_->ShouldSuppressDialogs(this)); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 5161 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 5162 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 5163 | bool suppress_this_message = should_suppress || !has_handlers; |
| 5164 | |
| 5165 | if (suppress_this_message) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5166 | std::move(callback).Run(true, false, base::string16()); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5167 | return; |
| 5168 | } |
| 5169 | |
| 5170 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5171 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5172 | |
| 5173 | is_showing_javascript_dialog_ = true; |
| 5174 | |
| 5175 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5176 | handler->DidRunJavaScriptDialog( |
Avi Drissman | 2fefc4b | 2018-02-22 20:41:01 | [diff] [blame] | 5177 | render_frame_host->GetLastCommittedURL(), message, default_prompt, |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 5178 | dialog_type, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5179 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | if (dialog_manager_) { |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5183 | dialog_manager_->RunJavaScriptDialog( |
Avi Drissman | 2fefc4b | 2018-02-22 20:41:01 | [diff] [blame] | 5184 | this, render_frame_host, dialog_type, message, default_prompt, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5185 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false), |
| 5186 | &suppress_this_message); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | if (suppress_this_message) { |
| 5190 | // If we are suppressing messages, just reply as if the user immediately |
| 5191 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5192 | wrapper->Run(true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5193 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 5197 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5198 | bool is_reload, |
| 5199 | IPC::Message* reply_msg) { |
Avi Drissman | 2ccbb40 | 2018-03-20 21:11:36 | [diff] [blame] | 5200 | // Ensure that if showing a dialog is the first thing that a page does, that |
| 5201 | // the contents of the previous page aren't shown behind it. This is required |
| 5202 | // because showing a dialog freezes the renderer, so no frames will be coming |
| 5203 | // from it. https://crbug.com/823353 |
| 5204 | auto* render_widget_host_impl = |
| 5205 | static_cast<RenderFrameHostImpl*>(render_frame_host) |
| 5206 | ->GetRenderWidgetHost(); |
| 5207 | if (render_widget_host_impl) |
| 5208 | render_widget_host_impl->ForceFirstFrameAfterNavigationTimeout(); |
| 5209 | |
avi | 0720b02e | 2017-06-13 03:22:13 | [diff] [blame] | 5210 | // Running a dialog causes an exit to webpage-initiated fullscreen. |
| 5211 | // http://crbug.com/728276 |
| 5212 | if (IsFullscreenForCurrentTab()) |
| 5213 | ExitFullscreen(true); |
| 5214 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 5215 | RenderFrameHostImpl* rfhi = |
| 5216 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5217 | if (delegate_) |
| 5218 | delegate_->WillRunBeforeUnloadConfirm(); |
| 5219 | |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5220 | auto callback = |
| 5221 | base::BindOnce(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
| 5222 | render_frame_host->GetProcess()->GetID(), |
| 5223 | render_frame_host->GetRoutingID(), reply_msg); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5224 | |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5225 | std::vector<protocol::PageHandler*> page_handlers = |
| 5226 | protocol::PageHandler::EnabledForWebContents(this); |
| 5227 | |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 5228 | if (delegate_) |
| 5229 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
| 5230 | |
| 5231 | bool should_suppress = ShowingInterstitialPage() || !rfhi->is_active() || |
| 5232 | (delegate_ && delegate_->ShouldSuppressDialogs(this)); |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 5233 | bool has_non_devtools_handlers = delegate_ && dialog_manager_; |
| 5234 | bool has_handlers = page_handlers.size() || has_non_devtools_handlers; |
Pavel Feldman | fab3cb6 | 2017-10-05 01:02:01 | [diff] [blame] | 5235 | if (should_suppress || !has_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5236 | std::move(callback).Run(false, true, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5237 | return; |
| 5238 | } |
| 5239 | |
| 5240 | is_showing_before_unload_dialog_ = true; |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5241 | |
| 5242 | scoped_refptr<CloseDialogCallbackWrapper> wrapper = |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5243 | new CloseDialogCallbackWrapper(std::move(callback)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5244 | |
| 5245 | GURL frame_url = rfhi->GetLastCommittedURL(); |
| 5246 | for (auto* handler : page_handlers) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5247 | handler->DidRunBeforeUnloadConfirm( |
Pavel Feldman | 1c587bc5 | 2018-04-04 21:16:05 | [diff] [blame] | 5248 | frame_url, has_non_devtools_handlers, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5249 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5250 | } |
| 5251 | |
| 5252 | if (dialog_manager_) { |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5253 | dialog_manager_->RunBeforeUnloadDialog( |
Avi Drissman | ff9ed75 | 2017-11-28 21:18:12 | [diff] [blame] | 5254 | this, render_frame_host, is_reload, |
Avi Drissman | e04d399 | 2017-10-05 15:11:36 | [diff] [blame] | 5255 | base::BindOnce(&CloseDialogCallbackWrapper::Run, wrapper, false)); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 5256 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5257 | } |
| 5258 | |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 5259 | void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host, |
| 5260 | const FileChooserParams& params) { |
| 5261 | if (delegate_) |
| 5262 | delegate_->RunFileChooser(render_frame_host, params); |
| 5263 | } |
| 5264 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 5265 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 5266 | return this; |
| 5267 | } |
| 5268 | |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5269 | #if !defined(OS_ANDROID) |
akaba | c6bd121 | 2018-06-25 20:10:48 | [diff] [blame] | 5270 | double WebContentsImpl::GetPendingPageZoomLevel() const { |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 5271 | NavigationEntry* pending_entry = GetController().GetPendingEntry(); |
| 5272 | if (!pending_entry) |
| 5273 | return HostZoomMap::GetZoomLevel(this); |
| 5274 | |
| 5275 | GURL url = pending_entry->GetURL(); |
| 5276 | return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme( |
| 5277 | url.scheme(), net::GetHostOrSpecFromURL(url)); |
| 5278 | } |
mcnee | 336ea2c | 2017-05-23 22:50:59 | [diff] [blame] | 5279 | #endif // !defined(OS_ANDROID) |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 5280 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 5281 | bool WebContentsImpl::HideDownloadUI() const { |
| 5282 | return is_overlay_content_; |
| 5283 | } |
| 5284 | |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5285 | bool WebContentsImpl::HasPersistentVideo() const { |
| 5286 | return has_persistent_video_; |
| 5287 | } |
| 5288 | |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 5289 | RenderFrameHost* WebContentsImpl::GetPendingMainFrame() { |
clamy | 610c63b3 | 2017-12-22 15:05:18 | [diff] [blame] | 5290 | return GetRenderManager()->speculative_frame_host(); |
Alex Moshchuk | 27caae8 | 2017-09-11 23:11:18 | [diff] [blame] | 5291 | } |
| 5292 | |
mlamouri | e52c1b54 | 2017-02-23 14:57:50 | [diff] [blame] | 5293 | bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const { |
| 5294 | return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo(); |
| 5295 | } |
| 5296 | |
François Beaufort | ad6c523 | 2018-02-26 11:00:44 | [diff] [blame] | 5297 | bool WebContentsImpl::IsPictureInPictureAllowedForFullscreenVideo() const { |
| 5298 | return media_web_contents_observer_ |
| 5299 | ->IsPictureInPictureAllowedForFullscreenVideo(); |
| 5300 | } |
| 5301 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 5302 | bool WebContentsImpl::IsFocusedElementEditable() { |
| 5303 | RenderFrameHostImpl* frame = GetFocusedFrame(); |
| 5304 | return frame && frame->has_focused_editable_element(); |
| 5305 | } |
| 5306 | |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 5307 | bool WebContentsImpl::IsShowingContextMenu() const { |
| 5308 | return showing_context_menu_; |
| 5309 | } |
| 5310 | |
| 5311 | void WebContentsImpl::SetShowingContextMenu(bool showing) { |
| 5312 | DCHECK_NE(showing_context_menu_, showing); |
| 5313 | showing_context_menu_ = showing; |
| 5314 | |
| 5315 | if (auto* view = GetRenderWidgetHostView()) { |
| 5316 | // Notify the main frame's RWHV to run the platform-specific code, if any. |
| 5317 | static_cast<RenderWidgetHostViewBase*>(view)->SetShowingContextMenu( |
| 5318 | showing); |
| 5319 | } |
| 5320 | } |
| 5321 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 5322 | void WebContentsImpl::ClearFocusedElement() { |
| 5323 | if (auto* frame = GetFocusedFrame()) |
| 5324 | frame->ClearFocusedElement(); |
| 5325 | } |
| 5326 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 5327 | bool WebContentsImpl::IsNeverVisible() { |
| 5328 | if (!delegate_) |
| 5329 | return false; |
| 5330 | return delegate_->IsNeverVisible(this); |
| 5331 | } |
| 5332 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 5333 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 5334 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5335 | } |
| 5336 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5337 | RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 5338 | BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 5339 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 5340 | } |
| 5341 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5342 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 5343 | if (browser_plugin_embedder_) |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5344 | browser_plugin_embedder_.reset(); |
| 5345 | } |
| 5346 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5347 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 5348 | if (GuestMode::IsCrossProcessFrameGuest(this)) |
| 5349 | return node_.outer_web_contents(); |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 5350 | |
| 5351 | if (browser_plugin_guest_) |
| 5352 | return browser_plugin_guest_->embedder_web_contents(); |
| 5353 | |
Lucas Furukawa Gadani | 105de1e81 | 2018-05-31 19:38:39 | [diff] [blame] | 5354 | return node_.outer_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5355 | } |
| 5356 | |
| 5357 | WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 5358 | return GetOutermostWebContents()->node_.focused_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5359 | } |
| 5360 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5361 | bool WebContentsImpl::ContainsOrIsFocusedWebContents() { |
| 5362 | for (WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 5363 | focused_contents; |
| 5364 | focused_contents = focused_contents->GetOuterWebContents()) { |
| 5365 | if (focused_contents == this) |
| 5366 | return true; |
| 5367 | } |
| 5368 | |
| 5369 | return false; |
| 5370 | } |
| 5371 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5372 | WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { |
| 5373 | WebContentsImpl* root = this; |
| 5374 | while (root->GetOuterWebContents()) |
| 5375 | root = root->GetOuterWebContents(); |
| 5376 | return root; |
| 5377 | } |
| 5378 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 5379 | void WebContentsImpl::FocusOuterAttachmentFrameChain() { |
| 5380 | WebContentsImpl* outer_contents = GetOuterWebContents(); |
| 5381 | if (!outer_contents) |
| 5382 | return; |
| 5383 | |
| 5384 | FrameTreeNode* outer_node = |
| 5385 | FrameTreeNode::GloballyFindByID(GetOuterDelegateFrameTreeNodeId()); |
| 5386 | outer_contents->frame_tree_.SetFocusedFrame(outer_node, nullptr); |
| 5387 | |
| 5388 | // For a browser initiated focus change, let embedding renderer know of the |
| 5389 | // change. Otherwise, if the currently focused element is just across a |
| 5390 | // process boundary in focus order, it will not be possible to move across |
| 5391 | // that boundary. This is because the target element will already be focused |
| 5392 | // (that renderer was not notified) and drop the event. |
| 5393 | if (GetRenderManager()->GetProxyToOuterDelegate()) |
| 5394 | GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); |
| 5395 | |
| 5396 | outer_contents->FocusOuterAttachmentFrameChain(); |
| 5397 | } |
| 5398 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5399 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 5400 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 5401 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 5402 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5403 | NotificationService::current()->Notify( |
| 5404 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 5405 | Source<WebContents>(this), |
| 5406 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5407 | |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 5408 | view_->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 5409 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5410 | for (auto& observer : observers_) |
| 5411 | observer.RenderViewCreated(render_view_host); |
Joel Einbinder | 848001c | 2017-09-19 21:39:31 | [diff] [blame] | 5412 | if (delegate_) |
| 5413 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5414 | } |
| 5415 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5416 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5417 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5418 | // Don't notify the world, since this came from a renderer in the |
| 5419 | // background. |
| 5420 | return; |
| 5421 | } |
| 5422 | |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 5423 | RenderWidgetHostViewBase* rwhv = |
| 5424 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 5425 | if (rwhv) |
| 5426 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 5427 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 5428 | notify_disconnection_ = true; |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 5429 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 5430 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 5431 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 5432 | |
| 5433 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 5434 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 5435 | if (was_crashed && !FocusLocationBarByDefault() && |
| 5436 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 5437 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 5438 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 5439 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5440 | for (auto& observer : observers_) |
| 5441 | observer.RenderViewReady(); |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 5442 | |
| 5443 | view_->RenderViewReady(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5444 | } |
| 5445 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 5446 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 5447 | base::TerminationStatus status, |
| 5448 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5449 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5450 | // The pending page's RenderViewHost is gone. |
| 5451 | return; |
| 5452 | } |
| 5453 | |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 5454 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 5455 | // renderer may not have made a clean exit. |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 5456 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 5457 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 5458 | |
Jennifer Apacible | b4b972a | 2018-06-07 04:41:02 | [diff] [blame] | 5459 | // Ensure any video in Picture-in-Picture is exited in the |delegate_| since |
| 5460 | // a crashed renderer may not have made a clean exit. |
| 5461 | if (HasPictureInPictureVideo()) |
| 5462 | ExitPictureInPicture(); |
| 5463 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 5464 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 5465 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 5466 | |
dalecurtis | 3d1e130 | 2017-02-20 22:33:25 | [diff] [blame] | 5467 | audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID()); |
| 5468 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 5469 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 5470 | // "renderer crash" when there is more than one renderer process serving a |
| 5471 | // webpage? Once this function is called at a more granular frame level, we |
| 5472 | // probably will need to more granularly reset the state here. |
| 5473 | ResetLoadProgressState(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5474 | NotifyDisconnected(); |
| 5475 | SetIsCrashed(status, error_code); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 5476 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5477 | for (auto& observer : observers_) |
| 5478 | observer.RenderProcessGone(GetCrashedStatus()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5479 | } |
| 5480 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5481 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5482 | for (auto& observer : observers_) |
| 5483 | observer.RenderViewDeleted(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 5484 | } |
| 5485 | |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 5486 | void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host, |
| 5487 | const GURL& url) { |
| 5488 | if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) { |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 5489 | // If we're in flash fullscreen (i.e. Pepper plugin fullscreen) only update |
| 5490 | // the url if it's from the fullscreen renderer. |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 5491 | RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView(); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 5492 | if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget()) |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 5493 | return; |
| 5494 | } |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 5495 | |
| 5496 | // In case of racey updates from multiple RenderViewHosts, the last URL should |
| 5497 | // be shown - see also some discussion in https://crbug.com/807776. |
| 5498 | if (!url.is_valid() && render_view_host != view_that_set_last_target_url_) |
| 5499 | return; |
| 5500 | view_that_set_last_target_url_ = url.is_valid() ? render_view_host : nullptr; |
| 5501 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 5502 | if (delegate_) |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 5503 | delegate_->UpdateTargetURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5504 | } |
| 5505 | |
Lukasz Anforowicz | fd70714 | 2018-02-07 19:46:13 | [diff] [blame] | 5506 | void WebContentsImpl::ClearTargetURL() { |
| 5507 | view_that_set_last_target_url_ = nullptr; |
| 5508 | if (delegate_) |
| 5509 | delegate_->UpdateTargetURL(this, GURL()); |
| 5510 | } |
| 5511 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5512 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 5513 | #if defined(OS_MACOSX) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 5514 | // The UI may be in an event-tracking loop, such as between the |
| 5515 | // mouse-down and mouse-up in text selection or a button click. |
| 5516 | // Defer the close until after tracking is complete, so that we |
| 5517 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 5518 | // TODO(shess): This could get more fine-grained. For instance, |
| 5519 | // closing a tab in another window while selecting text in the |
| 5520 | // current window's Omnibox should be just fine. |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 5521 | if (view_->IsEventTracking()) { |
| 5522 | view_->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 5523 | return; |
| 5524 | } |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 5525 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 5526 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5527 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 5528 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 5529 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5530 | } |
| 5531 | |
Avi Drissman | 014dec7 | 2018-06-07 02:34:01 | [diff] [blame] | 5532 | void WebContentsImpl::RequestSetBounds(const gfx::Rect& new_bounds) { |
| 5533 | if (delegate_) |
| 5534 | delegate_->SetContentsBounds(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5535 | } |
| 5536 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 5537 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 5538 | bool to_different_document) { |
Evan Stade | c3b2602 | 2017-07-14 19:50:24 | [diff] [blame] | 5539 | LoadingStateChanged(frame_tree_node->IsMainFrame() && to_different_document, |
| 5540 | false, nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 5541 | |
| 5542 | // Notify accessibility that the user is navigating away from the |
| 5543 | // current document. |
| 5544 | // |
| 5545 | // TODO(dmazzoni): do this using a WebContentsObserver. |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 5546 | BrowserAccessibilityManager* manager = |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 5547 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 5548 | if (manager) |
| 5549 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5550 | } |
| 5551 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 5552 | void WebContentsImpl::DidStopLoading() { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 5553 | std::unique_ptr<LoadNotificationDetails> details; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5554 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 5555 | // Use the last committed entry rather than the active one, in case a |
| 5556 | // pending entry has been created. |
| 5557 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 5558 | Navigator* navigator = frame_tree_.root()->navigator(); |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 5559 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5560 | // An entry may not exist for a stop when loading an initial blank page or |
| 5561 | // if an iframe injected by script into a blank page finishes loading. |
| 5562 | if (entry) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 5563 | base::TimeDelta elapsed = |
| 5564 | base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5565 | |
| 5566 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 5567 | entry->GetVirtualURL(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5568 | elapsed, |
| 5569 | &controller_, |
| 5570 | controller_.GetCurrentEntryIndex())); |
| 5571 | } |
| 5572 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5573 | LoadingStateChanged(true, false, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5574 | } |
| 5575 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 5576 | void WebContentsImpl::DidChangeLoadProgress() { |
| 5577 | double load_progress = frame_tree_.load_progress(); |
| 5578 | |
| 5579 | // The delegate is notified immediately for the first and last updates. Also, |
| 5580 | // since the message loop may be pretty busy when a page is loaded, it might |
| 5581 | // not execute a posted task in a timely manner so the progress report is sent |
| 5582 | // immediately if enough time has passed. |
| 5583 | base::TimeDelta min_delay = |
| 5584 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 5585 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 5586 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 5587 | |
| 5588 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 5589 | // If there is a pending task to send progress, it is now obsolete. |
| 5590 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 5591 | |
| 5592 | // Notify the load progress change. |
| 5593 | SendChangeLoadProgress(); |
| 5594 | |
| 5595 | // Clean-up the states if needed. |
| 5596 | if (load_progress == 1.0) |
| 5597 | ResetLoadProgressState(); |
| 5598 | return; |
| 5599 | } |
| 5600 | |
| 5601 | if (loading_weak_factory_.HasWeakPtrs()) |
| 5602 | return; |
| 5603 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 5604 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
tzik | e2aca99 | 2017-09-05 08:50:54 | [diff] [blame] | 5605 | FROM_HERE, |
| 5606 | base::BindOnce(&WebContentsImpl::SendChangeLoadProgress, |
| 5607 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 5608 | min_delay); |
| 5609 | } |
| 5610 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 5611 | std::vector<std::unique_ptr<NavigationThrottle>> |
| 5612 | WebContentsImpl::CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 5613 | NavigationHandle* navigation_handle) { |
| 5614 | return GetContentClient()->browser()->CreateThrottlesForNavigation( |
| 5615 | navigation_handle); |
| 5616 | } |
| 5617 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 5618 | std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData( |
| 5619 | NavigationHandle* navigation_handle) { |
| 5620 | DCHECK(IsBrowserSideNavigationEnabled()); |
| 5621 | return GetContentClient()->browser()->GetNavigationUIData(navigation_handle); |
| 5622 | } |
| 5623 | |
pdr | 15f5b5b | 2017-06-20 00:58:00 | [diff] [blame] | 5624 | void WebContentsImpl::DidCancelLoading() { |
| 5625 | controller_.DiscardNonCommittedEntries(); |
| 5626 | |
| 5627 | // Update the URL display. |
| 5628 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 5629 | } |
| 5630 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 5631 | void WebContentsImpl::DidAccessInitialDocument() { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 5632 | has_accessed_initial_document_ = true; |
| 5633 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 5634 | // We may have left a failed browser-initiated navigation in the address bar |
| 5635 | // to let the user edit it and try again. Clear it now that content might |
| 5636 | // show up underneath it. |
| 5637 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 5638 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 5639 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 5640 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 5641 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 5642 | } |
| 5643 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 5644 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 5645 | const std::string& name) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5646 | for (auto& observer : observers_) |
| 5647 | observer.FrameNameChanged(render_frame_host, name); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 5648 | } |
| 5649 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 5650 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 5651 | RenderFrameHost* render_frame_host) { |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 5652 | ShowInsecureLocalhostWarningIfNeeded(); |
| 5653 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 5654 | is_notifying_observers_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5655 | for (auto& observer : observers_) |
| 5656 | observer.DocumentOnLoadCompletedInMainFrame(); |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 5657 | is_notifying_observers_ = false; |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 5658 | |
| 5659 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5660 | NotificationService::current()->Notify( |
| 5661 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 5662 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 5663 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 5664 | } |
| 5665 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 5666 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
| 5667 | const PageState& page_state) { |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 5668 | // The state update affects the last NavigationEntry associated with the given |
| 5669 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 5670 | // in the case of an UpdateState from a frame being swapped out). We track |
| 5671 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 5672 | RenderFrameHostImpl* rfhi = |
| 5673 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 5674 | NavigationEntryImpl* entry = |
| 5675 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 5676 | if (!entry) |
| 5677 | return; |
| 5678 | |
| 5679 | FrameNavigationEntry* frame_entry = |
| 5680 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 5681 | if (!frame_entry) |
| 5682 | return; |
| 5683 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 5684 | // The SiteInstance might not match if we do a cross-process navigation with |
| 5685 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 5686 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 5687 | // has already been replaced and destroyed. |
| 5688 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 5689 | return; |
| 5690 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 5691 | if (page_state == frame_entry->page_state()) |
| 5692 | return; // Nothing to update. |
| 5693 | |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 5694 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 5695 | |
| 5696 | // The document_sequence_number and item_sequence_number recorded in the |
| 5697 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 5698 | // since it must come from the same document. Do not update it if a difference |
| 5699 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 5700 | ExplodedPageState exploded_state; |
| 5701 | if (!DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 5702 | return; |
| 5703 | |
| 5704 | if (exploded_state.top.document_sequence_number != |
| 5705 | frame_entry->document_sequence_number() || |
| 5706 | exploded_state.top.item_sequence_number != |
| 5707 | frame_entry->item_sequence_number()) { |
| 5708 | return; |
| 5709 | } |
| 5710 | |
nasko | 04a322f25a | 2016-09-01 00:00:34 | [diff] [blame] | 5711 | frame_entry->SetPageState(page_state); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 5712 | controller_.NotifyEntryChanged(entry); |
| 5713 | } |
| 5714 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5715 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5716 | const base::string16& title, |
| 5717 | base::i18n::TextDirection title_direction) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5718 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 5719 | // For example, it might be from a recently swapped out RFH. |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 5720 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
creis | ad8c31a | 2016-05-24 17:07:04 | [diff] [blame] | 5721 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5722 | |
| 5723 | // We can handle title updates when we don't have an entry in |
| 5724 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 5725 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 5726 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5727 | return; |
| 5728 | |
| 5729 | // TODO(evan): make use of title_direction. |
| 5730 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 5731 | UpdateTitleForEntry(entry, title); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5732 | } |
| 5733 | |
| 5734 | void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
| 5735 | const std::string& encoding) { |
| 5736 | SetEncoding(encoding); |
| 5737 | } |
| 5738 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 5739 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 5740 | RenderViewHost* render_view_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5741 | for (auto& observer : observers_) |
| 5742 | observer.DocumentAvailableInMainFrame(); |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 5743 | } |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 5744 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 5745 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 5746 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 5747 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 5748 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 5749 | // It is possible to receive it from one that has just been swapped in, |
| 5750 | // in which case we might as well deliver the message anyway. |
| 5751 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 5752 | ClosePage(); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 5753 | } |
| 5754 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 5755 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 5756 | RenderFrameHost* target_rfh, |
| 5757 | SiteInstance* source_site_instance) const { |
| 5758 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 5759 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 5760 | // Note: This check means that an embedder could theoretically receive a |
| 5761 | // postMessage from anyone (not just its own guests). However, this is |
| 5762 | // probably not a risk for apps since other pages won't have references |
| 5763 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 5764 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 5765 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5766 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 5767 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 5768 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 5769 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5770 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 5771 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5772 | // If this message is going to outer WebContents from inner WebContents, |
| 5773 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 5774 | // already created a RenderFrameProxyHost for that purpose. |
| 5775 | if (GetBrowserPluginEmbedder() && |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 5776 | GuestMode::IsCrossProcessFrameGuest(source_web_contents)) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5777 | return; |
| 5778 | } |
| 5779 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 5780 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | b3041b98a4 | 2016-03-12 04:43:06 | [diff] [blame] | 5781 | // We create a RenderFrameProxyHost for the embedder in the guest's render |
| 5782 | // process but we intentionally do not expose the embedder's opener chain |
| 5783 | // to it. |
| 5784 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 5785 | GetSiteInstance()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5786 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 5787 | RenderFrameHostImpl* source_rfhi = |
| 5788 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 5789 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 5790 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5791 | } |
| 5792 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 5793 | } |
| 5794 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5795 | void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { |
| 5796 | // Only change focus if we are not currently focused. |
| 5797 | WebContentsImpl* old_contents = GetFocusedWebContents(); |
| 5798 | if (old_contents == this) |
| 5799 | return; |
| 5800 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 5801 | GetOutermostWebContents()->node_.SetFocusedWebContents(this); |
| 5802 | |
Greg Thompson | fb95760 | 2017-09-04 10:25:52 | [diff] [blame] | 5803 | if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 5804 | return; |
| 5805 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5806 | // Send a page level blur to the old contents so that it displays inactive UI |
| 5807 | // and focus this contents to activate it. |
| 5808 | if (old_contents) |
| 5809 | old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 5810 | |
| 5811 | // Make sure the outer web contents knows our frame is focused. Otherwise, the |
| 5812 | // outer renderer could have the element before or after the frame element |
| 5813 | // focused which would return early without actually advancing focus. |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 5814 | FocusOuterAttachmentFrameChain(); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 5815 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 5816 | if (ShowingInterstitialPage()) { |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 5817 | static_cast<RenderFrameHostImpl*>(interstitial_page_->GetMainFrame()) |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 5818 | ->GetRenderWidgetHost() |
| 5819 | ->SetPageFocus(true); |
| 5820 | } else { |
| 5821 | GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); |
| 5822 | } |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5823 | } |
| 5824 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5825 | void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 5826 | SiteInstance* source) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5827 | frame_tree_.SetFocusedFrame(node, source); |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 5828 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 5829 | if (auto* inner_contents = node_.GetInnerWebContentsInFrame(node)) { |
| 5830 | // |this| is an outer WebContents and |node| represents an inner |
| 5831 | // WebContents. Transfer the focus to the inner contents if |this| is |
| 5832 | // focused. |
| 5833 | if (GetFocusedWebContents() == this) |
| 5834 | inner_contents->SetAsFocusedWebContentsIfNecessary(); |
| 5835 | } else if (node_.OuterContentsFrameTreeNode() && |
| 5836 | node_.OuterContentsFrameTreeNode() |
| 5837 | ->current_frame_host() |
| 5838 | ->GetSiteInstance() == source) { |
| 5839 | // |this| is an inner WebContents, |node| is its main FrameTreeNode and |
| 5840 | // the outer WebContents FrameTreeNode is at |source|'s SiteInstance. |
| 5841 | // Transfer the focus to the inner WebContents if the outer WebContents is |
| 5842 | // focused. This branch is used when an inner WebContents is focused through |
| 5843 | // its RenderFrameProxyHost (via FrameHostMsg_FrameFocused IPC, used to |
| 5844 | // implement the window.focus() API). |
| 5845 | if (GetFocusedWebContents() == GetOuterWebContents()) |
| 5846 | SetAsFocusedWebContentsIfNecessary(); |
| 5847 | } else if (!GetOuterWebContents()) { |
| 5848 | // This is an outermost WebContents. |
| 5849 | SetAsFocusedWebContentsIfNecessary(); |
| 5850 | } else if (!GuestMode::IsCrossProcessFrameGuest(this) && |
| 5851 | GetOuterWebContents()) { |
| 5852 | // TODO(lfg, paulmeyer): Allows BrowserPlugins to set themselves as the |
| 5853 | // focused WebContents. This works around a bug in FindRequestManager that |
| 5854 | // doesn't support properly traversing BrowserPlugins. |
| 5855 | SetAsFocusedWebContentsIfNecessary(); |
| 5856 | } |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 5857 | } |
| 5858 | |
Avi Drissman | 36f801f | 2018-02-01 20:06:04 | [diff] [blame] | 5859 | void WebContentsImpl::DidCallFocus() { |
| 5860 | // Any explicit focusing of another window while this WebContents is in |
| 5861 | // fullscreen can be used to confuse the user, so drop fullscreen. |
| 5862 | if (IsFullscreenForCurrentTab()) |
| 5863 | ExitFullscreen(true); |
| 5864 | } |
| 5865 | |
avallee | d68cdd1 | 2017-06-21 22:07:27 | [diff] [blame] | 5866 | RenderFrameHost* WebContentsImpl::GetFocusedFrameIncludingInnerWebContents() { |
| 5867 | WebContentsImpl* contents = this; |
| 5868 | FrameTreeNode* focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 5869 | |
| 5870 | // If there is no focused frame in the outer WebContents, we need to return |
| 5871 | // null. |
| 5872 | if (!focused_node) |
| 5873 | return nullptr; |
| 5874 | |
| 5875 | // If the focused frame is embedding an inner WebContents, we must descend |
| 5876 | // into that contents. If the current WebContents does not have a focused |
| 5877 | // frame, return the main frame of this contents instead of the focused empty |
| 5878 | // frame embedding this contents. |
| 5879 | while (true) { |
| 5880 | contents = contents->node_.GetInnerWebContentsInFrame(focused_node); |
| 5881 | if (!contents) |
| 5882 | return focused_node->current_frame_host(); |
| 5883 | |
| 5884 | focused_node = contents->frame_tree_.GetFocusedFrame(); |
| 5885 | if (!focused_node) |
| 5886 | return contents->GetMainFrame(); |
| 5887 | } |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 5888 | } |
| 5889 | |
Lucas Furukawa Gadani | abbfa34 | 2017-08-29 19:37:57 | [diff] [blame] | 5890 | void WebContentsImpl::OnAdvanceFocus(RenderFrameHostImpl* source_rfh) { |
| 5891 | // When a RenderFrame needs to advance focus to a RenderFrameProxy (by hitting |
| 5892 | // TAB), the RenderFrameProxy sends an IPC to RenderFrameProxyHost. When this |
| 5893 | // RenderFrameProxyHost represents an inner WebContents, the outer WebContents |
| 5894 | // needs to focus the inner WebContents. |
| 5895 | if (GetOuterWebContents() && |
| 5896 | GetOuterWebContents() == source_rfh->delegate()->GetAsWebContents() && |
| 5897 | GetFocusedWebContents() == GetOuterWebContents()) { |
| 5898 | SetAsFocusedWebContentsIfNecessary(); |
| 5899 | } |
| 5900 | } |
| 5901 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 5902 | void WebContentsImpl::OnFocusedElementChangedInFrame( |
| 5903 | RenderFrameHostImpl* frame, |
| 5904 | const gfx::Rect& bounds_in_root_view) { |
| 5905 | RenderWidgetHostViewBase* root_view = |
| 5906 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 5907 | if (!root_view || !frame->GetView()) |
| 5908 | return; |
| 5909 | |
| 5910 | // Converting to screen coordinates. |
| 5911 | gfx::Point origin = bounds_in_root_view.origin(); |
| 5912 | origin += root_view->GetViewBounds().OffsetFromOrigin(); |
| 5913 | gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size()); |
| 5914 | |
| 5915 | root_view->FocusedNodeChanged(frame->has_focused_editable_element(), |
| 5916 | bounds_in_screen); |
| 5917 | |
| 5918 | FocusedNodeDetails details = {frame->has_focused_editable_element(), |
| 5919 | bounds_in_screen}; |
| 5920 | |
| 5921 | // TODO(ekaramad): We should replace this with an observer notification |
| 5922 | // (https://crbug.com/675975). |
| 5923 | NotificationService::current()->Notify( |
| 5924 | NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 5925 | Source<RenderViewHost>(GetRenderViewHost()), |
| 5926 | Details<FocusedNodeDetails>(&details)); |
| 5927 | } |
| 5928 | |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 5929 | bool WebContentsImpl::DidAddMessageToConsole(int32_t level, |
| 5930 | const base::string16& message, |
| 5931 | int32_t line_no, |
| 5932 | const base::string16& source_id) { |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 5933 | if (!delegate_) |
| 5934 | return false; |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 5935 | return delegate_->DidAddMessageToConsole(this, level, message, line_no, |
| 5936 | source_id); |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 5937 | } |
| 5938 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 5939 | void WebContentsImpl::DidReceiveInputEvent( |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 5940 | RenderWidgetHostImpl* render_widget_host, |
| 5941 | const blink::WebInputEvent::Type type) { |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 5942 | // Ideally, this list would be based more off of |
| 5943 | // https://whatwg.org/C/interaction.html#triggered-by-user-activation. |
| 5944 | if (type != blink::WebInputEvent::kMouseDown && |
| 5945 | type != blink::WebInputEvent::kGestureScrollBegin && |
| 5946 | type != blink::WebInputEvent::kTouchStart && |
| 5947 | type != blink::WebInputEvent::kRawKeyDown) |
| 5948 | return; |
| 5949 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 5950 | // Ignore unless the widget is currently in the frame tree. |
| 5951 | if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5952 | return; |
| 5953 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 5954 | if (type != blink::WebInputEvent::kGestureScrollBegin) |
| 5955 | last_interactive_input_event_time_ = ui::EventTimeForNow(); |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 5956 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 5957 | OnUserInteraction(type); |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 5958 | } |
| 5959 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5960 | void WebContentsImpl::FocusOwningWebContents( |
| 5961 | RenderWidgetHostImpl* render_widget_host) { |
| 5962 | // The PDF plugin still runs as a BrowserPlugin and must go through the |
| 5963 | // input redirection mechanism. It must not become focused direcly. |
| 5964 | if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) |
| 5965 | return; |
| 5966 | |
| 5967 | RenderWidgetHostImpl* focused_widget = |
| 5968 | GetFocusedRenderWidgetHost(render_widget_host); |
| 5969 | |
| 5970 | if (focused_widget != render_widget_host && |
avallee | 8e88159 | 2016-11-19 00:39:30 | [diff] [blame] | 5971 | (!focused_widget || |
| 5972 | focused_widget->delegate() != render_widget_host->delegate())) { |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5973 | SetAsFocusedWebContentsIfNecessary(); |
| 5974 | } |
| 5975 | } |
| 5976 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5977 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 5978 | // Notify observers. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5979 | for (auto& observer : observers_) |
| 5980 | observer.DidGetIgnoredUIEvent(); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 5981 | } |
| 5982 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5983 | void WebContentsImpl::RendererUnresponsive( |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 5984 | RenderWidgetHostImpl* render_widget_host, |
| 5985 | base::RepeatingClosure hang_monitor_restarter) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5986 | for (auto& observer : observers_) |
Avi Drissman | 1572e8c3c | 2018-02-02 19:06:36 | [diff] [blame] | 5987 | observer.OnRendererUnresponsive(render_widget_host->GetProcess()); |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 5988 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 5989 | if (ShouldIgnoreUnresponsiveRenderer()) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 5990 | return; |
| 5991 | |
Avi Drissman | 8920def | 2018-01-31 19:53:36 | [diff] [blame] | 5992 | if (!render_widget_host->renderer_initialized()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 5993 | return; |
| 5994 | |
Dave Tapuska | c6146c5 | 2017-12-20 22:48:15 | [diff] [blame] | 5995 | if (delegate_) |
Lukasz Anforowicz | 52b9372 | 2018-06-20 16:11:39 | [diff] [blame] | 5996 | delegate_->RendererUnresponsive(this, render_widget_host, |
| 5997 | std::move(hang_monitor_restarter)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5998 | } |
| 5999 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 6000 | void WebContentsImpl::RendererResponsive( |
| 6001 | RenderWidgetHostImpl* render_widget_host) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 6002 | if (delegate_) |
Avi Drissman | 1572e8c3c | 2018-02-02 19:06:36 | [diff] [blame] | 6003 | delegate_->RendererResponsive(this, render_widget_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6004 | } |
| 6005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6006 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 6007 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6008 | bool* proceed_to_fire_unload) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 6009 | for (auto& observer : observers_) |
| 6010 | observer.BeforeUnloadFired(proceed_time); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 6011 | if (delegate_) |
| 6012 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 6013 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6014 | } |
| 6015 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 6016 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 6017 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 6018 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 6019 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 6020 | } |
| 6021 | |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6022 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager(bool is_main_frame) { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 6023 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6024 | gfx::Size size = GetSizeForNewRenderView(is_main_frame); |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 6025 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 6026 | // here during container initialization and normal window size will be set |
| 6027 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 6028 | // normal size later so just ignore it. |
| 6029 | if (!size.IsEmpty()) |
| 6030 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6031 | } |
| 6032 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 6033 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
| 6034 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 6035 | // deferrer would prevent us from swapping out. We also clear the state |
| 6036 | // because this is a cross-process navigation, which means that it's a new |
| 6037 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 6038 | // |
| 6039 | // Note that we don't bother telling browser_plugin_embedder_ because the |
| 6040 | // cross-process navigation will either destroy the browser plugins or not |
| 6041 | // require their dialogs to close. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 6042 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 6043 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 6044 | } |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 6045 | } |
| 6046 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 6047 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host, |
| 6048 | RenderFrameHost* new_host, |
| 6049 | bool is_main_frame) { |
| 6050 | if (is_main_frame) { |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 6051 | NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 6052 | new_host->GetRenderViewHost()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 6053 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 6054 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 6055 | if (delegate_) |
| 6056 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 6057 | |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 6058 | RenderWidgetHostViewBase* rwhv = |
| 6059 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 6060 | if (rwhv) |
| 6061 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 6062 | } |
| 6063 | |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 6064 | NotifyFrameSwapped(old_host, new_host, is_main_frame); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 6065 | } |
| 6066 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 6067 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
Jinsuk Kim | 895b2c5 | 2018-07-03 06:49:16 | [diff] [blame] | 6068 | RenderFrameHost* old_host, |
| 6069 | RenderFrameHost* new_host) { |
| 6070 | NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr, |
| 6071 | new_host->GetRenderViewHost()); |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 6072 | } |
| 6073 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6074 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 6075 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 6076 | } |
| 6077 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 6078 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 6079 | const GURL& url) { |
Dan Beam | 055fe8f | 2017-10-04 23:23:36 | [diff] [blame] | 6080 | return CreateWebUI(url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6081 | } |
| 6082 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 6083 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6084 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6085 | return controller_.GetLastCommittedEntry(); |
| 6086 | } |
| 6087 | |
creis | adca986 | 2017-06-16 19:12:11 | [diff] [blame] | 6088 | InterstitialPageImpl* WebContentsImpl::GetInterstitialForRenderManager() { |
| 6089 | return interstitial_page_; |
| 6090 | } |
| 6091 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 6092 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 6093 | RenderViewHost* render_view_host) { |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 6094 | RenderWidgetHostViewBase* rwh_view = |
| 6095 | view_->CreateViewForWidget(render_view_host->GetWidget(), false); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 6096 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6097 | // Now that the RenderView has been created, we need to tell it its size. |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 6098 | if (rwh_view) |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6099 | rwh_view->SetSize(GetSizeForNewRenderView(true)); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 6100 | } |
| 6101 | |
| 6102 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 6103 | RenderViewHost* render_view_host, |
| 6104 | int opener_frame_routing_id, |
| 6105 | int proxy_routing_id, |
Pavel Feldman | 2523472 | 2017-10-11 02:49:06 | [diff] [blame] | 6106 | const base::UnguessableToken& devtools_frame_token, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 6107 | const FrameReplicationState& replicated_frame_state) { |
| 6108 | TRACE_EVENT0("browser,navigation", |
| 6109 | "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 6110 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 6111 | if (proxy_routing_id == MSG_ROUTING_NONE) |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 6112 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 6113 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 6114 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
| 6115 | ->CreateRenderView(opener_frame_routing_id, proxy_routing_id, |
Pavel Feldman | 2523472 | 2017-10-11 02:49:06 | [diff] [blame] | 6116 | devtools_frame_token, replicated_frame_state, |
| 6117 | created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 6118 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 6119 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 6120 | |
Lucas Furukawa Gadani | aed1fed | 2017-10-13 17:34:14 | [diff] [blame] | 6121 | if (proxy_routing_id == MSG_ROUTING_NONE && node_.outer_web_contents()) |
| 6122 | ReattachToOuterWebContentsFrame(); |
| 6123 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 6124 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 6125 | controller_.GetLastCommittedEntryIndex(), |
| 6126 | controller_.GetEntryCount()); |
| 6127 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 6128 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 6129 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 6130 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 6131 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 6132 | if (rwh_view) { |
| 6133 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
Fady Samuel | 0b91182 | 2018-04-25 13:22:16 | [diff] [blame] | 6134 | render_widget_host->SynchronizeVisualProperties(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 6135 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 6136 | #endif |
| 6137 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 6138 | return true; |
| 6139 | } |
| 6140 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 6141 | bool WebContentsImpl::CreateRenderFrameForRenderManager( |
| 6142 | RenderFrameHost* render_frame_host, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 6143 | int proxy_routing_id, |
| 6144 | int opener_routing_id, |
japhet | e6adf14 | 2014-10-31 00:01:49 | [diff] [blame] | 6145 | int parent_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 6146 | int previous_sibling_routing_id) { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 6147 | TRACE_EVENT0("browser,navigation", |
| 6148 | "WebContentsImpl::CreateRenderFrameForRenderManager"); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 6149 | |
| 6150 | RenderFrameHostImpl* rfh = |
| 6151 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 6152 | if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id, |
| 6153 | parent_routing_id, previous_sibling_routing_id)) |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 6154 | return false; |
| 6155 | |
| 6156 | // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed |
| 6157 | // RenderFrameHost will have to be associated with the appropriate |
| 6158 | // RenderWidgetHostView or a new one should be created here. |
| 6159 | |
| 6160 | return true; |
| 6161 | } |
| 6162 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 6163 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6164 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 6165 | base::android::ScopedJavaLocalRef<jobject> |
| 6166 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 6167 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 6168 | return GetWebContentsAndroid()->GetJavaObject(); |
| 6169 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 6170 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 6171 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 6172 | WebContentsAndroid* web_contents_android = |
| 6173 | static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey)); |
| 6174 | if (!web_contents_android) { |
| 6175 | web_contents_android = new WebContentsAndroid(this); |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 6176 | SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android)); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 6177 | } |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 6178 | return web_contents_android; |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 6179 | } |
| 6180 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 6181 | void WebContentsImpl::ActivateNearestFindResult(float x, |
| 6182 | float y) { |
| 6183 | GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y); |
| 6184 | } |
| 6185 | |
| 6186 | void WebContentsImpl::RequestFindMatchRects(int current_version) { |
| 6187 | GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version); |
| 6188 | } |
| 6189 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 6190 | bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 6191 | return CreateRenderViewForRenderManager( |
| 6192 | GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
Pavel Feldman | 2523472 | 2017-10-11 02:49:06 | [diff] [blame] | 6193 | frame_tree_.root()->devtools_frame_token(), |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 6194 | frame_tree_.root()->current_replication_state()); |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 6195 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6196 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 6197 | service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() { |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 6198 | if (!java_interfaces_) { |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 6199 | service_manager::mojom::InterfaceProviderPtr provider; |
blundell | e0a9f158 | 2016-12-20 11:23:32 | [diff] [blame] | 6200 | BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this); |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 6201 | java_interfaces_.reset(new service_manager::InterfaceProvider); |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 6202 | java_interfaces_->Bind(std::move(provider)); |
| 6203 | } |
| 6204 | return java_interfaces_.get(); |
| 6205 | } |
| 6206 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6207 | #elif defined(OS_MACOSX) |
| 6208 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 6209 | void WebContentsImpl::SetAllowOtherViews(bool allow) { |
| 6210 | view_->SetAllowOtherViews(allow); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6211 | } |
| 6212 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 6213 | bool WebContentsImpl::GetAllowOtherViews() { |
| 6214 | return view_->GetAllowOtherViews(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6215 | } |
| 6216 | |
spqchan | e72c3cb | 2017-06-30 23:02:10 | [diff] [blame] | 6217 | bool WebContentsImpl::CompletedFirstVisuallyNonEmptyPaint() const { |
| 6218 | return did_first_visually_non_empty_paint_; |
| 6219 | } |
| 6220 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 6221 | #endif |
| 6222 | |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 6223 | void WebContentsImpl::OnDidDownloadImage( |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 6224 | ImageDownloadCallback callback, |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 6225 | int id, |
| 6226 | const GURL& image_url, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 6227 | int32_t http_status_code, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 6228 | const std::vector<SkBitmap>& images, |
| 6229 | const std::vector<gfx::Size>& original_image_sizes) { |
Avi Drissman | a5a52dd | 2018-03-27 03:39:02 | [diff] [blame] | 6230 | std::move(callback).Run(id, http_status_code, image_url, images, |
| 6231 | original_image_sizes); |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 6232 | } |
| 6233 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 6234 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 6235 | int render_frame_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6236 | IPC::Message* reply_msg, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6237 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6238 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 6239 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 6240 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 6241 | render_frame_id); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6242 | last_dialog_suppressed_ = dialog_was_suppressed; |
| 6243 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 6244 | if (is_showing_before_unload_dialog_ && !success) { |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 6245 | // It is possible for the current RenderFrameHost to have changed in the |
| 6246 | // meantime. Do not reset the navigation state in that case. |
| 6247 | if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 6248 | rfh->frame_tree_node()->BeforeUnloadCanceled(); |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 6249 | controller_.DiscardNonCommittedEntries(); |
| 6250 | } |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 6251 | |
Charles Reis | 15d60b13 | 2017-11-03 17:43:47 | [diff] [blame] | 6252 | // Update the URL display either way, to avoid showing a stale URL. |
| 6253 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
| 6254 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 6255 | for (auto& observer : observers_) |
| 6256 | observer.BeforeUnloadDialogCancelled(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 6257 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 6258 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 6259 | if (rfh) { |
avi | 44acfaa8 | 2017-05-03 22:55:35 | [diff] [blame] | 6260 | rfh->JavaScriptDialogClosed(reply_msg, success, user_input); |
Pavel Feldman | 3c1842b | 2017-08-02 05:00:16 | [diff] [blame] | 6261 | |
| 6262 | std::vector<protocol::PageHandler*> page_handlers = |
| 6263 | protocol::PageHandler::EnabledForWebContents(this); |
| 6264 | for (auto* handler : page_handlers) |
| 6265 | handler->DidCloseJavaScriptDialog(success, user_input); |
| 6266 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 6267 | } else { |
| 6268 | // Don't leak the sync IPC reply if the RFH or process is gone. |
| 6269 | delete reply_msg; |
| 6270 | } |
avi | 1c51fb6 | 2017-02-27 20:43:03 | [diff] [blame] | 6271 | |
| 6272 | is_showing_javascript_dialog_ = false; |
| 6273 | is_showing_before_unload_dialog_ = false; |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 6274 | } |
| 6275 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 6276 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 6277 | if (encoding == last_reported_encoding_) |
| 6278 | return; |
| 6279 | last_reported_encoding_ = encoding; |
| 6280 | |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 6281 | canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 6282 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 6283 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 6284 | bool WebContentsImpl::IsHidden() { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6285 | return !IsBeingCaptured() && visibility_ != Visibility::VISIBLE; |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 6286 | } |
| 6287 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 6288 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 6289 | return node_.outer_contents_frame_tree_node_id(); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 6290 | } |
| 6291 | |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 6292 | RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const { |
| 6293 | return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_, |
| 6294 | fullscreen_widget_routing_id_); |
| 6295 | } |
| 6296 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 6297 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 6298 | return frame_tree_.root()->render_manager(); |
| 6299 | } |
| 6300 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 6301 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 6302 | return browser_plugin_guest_.get(); |
| 6303 | } |
| 6304 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 6305 | void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 6306 | CHECK(!browser_plugin_guest_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 6307 | CHECK(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 6308 | browser_plugin_guest_.reset(guest); |
| 6309 | } |
| 6310 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 6311 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 6312 | return browser_plugin_embedder_.get(); |
| 6313 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6314 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 6315 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 6316 | if (browser_plugin_embedder_) |
| 6317 | return; |
| 6318 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 6319 | } |
| 6320 | |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6321 | gfx::Size WebContentsImpl::GetSizeForNewRenderView(bool is_main_frame) { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 6322 | gfx::Size size; |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6323 | if (is_main_frame) |
| 6324 | size = device_emulation_size_; |
| 6325 | if (size.IsEmpty() && delegate_) |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 6326 | size = delegate_->GetSizeForNewRenderView(this); |
| 6327 | if (size.IsEmpty()) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 6328 | size = GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 6329 | return size; |
| 6330 | } |
| 6331 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 6332 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 6333 | for (auto& observer : observers_) |
| 6334 | observer.FrameDeleted(render_frame_host); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 6335 | } |
| 6336 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 6337 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 6338 | if (!delegate_) |
| 6339 | return; |
| 6340 | const gfx::Size new_size = GetPreferredSize(); |
| 6341 | if (new_size != old_size) |
| 6342 | delegate_->UpdatePreferredSize(this, new_size); |
| 6343 | } |
| 6344 | |
Daniel Cheng | 90196c8 | 2018-04-25 21:49:14 | [diff] [blame] | 6345 | void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { |
| 6346 | for (auto& observer : observers_) |
| 6347 | observer.DidGetUserInteraction(type); |
| 6348 | |
| 6349 | // TODO(https://crbug.com/827659): This used to check if type != kMouseWheel. |
| 6350 | // However, due to the caller already filtering event types, this would never |
| 6351 | // be called with type == kMouseWheel so checking for that here is pointless. |
| 6352 | // However, mouse wheel events *also* generate a kGestureScrollBegin event... |
| 6353 | // which is *not* filtered out. Maybe they should be? |
| 6354 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 6355 | if (rdh) // null in unittests. =( |
| 6356 | rdh->OnUserGesture(); |
| 6357 | } |
| 6358 | |
Dan Beam | 055fe8f | 2017-10-04 23:23:36 | [diff] [blame] | 6359 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI(const GURL& url) { |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 6360 | std::unique_ptr<WebUIImpl> web_ui = std::make_unique<WebUIImpl>(this); |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 6361 | std::unique_ptr<WebUIController> controller( |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 6362 | WebUIControllerFactoryRegistry::GetInstance() |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 6363 | ->CreateWebUIControllerForURL(web_ui.get(), url)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 6364 | if (controller) { |
Jeremy Roman | 04f27c37 | 2017-10-27 15:20:55 | [diff] [blame] | 6365 | web_ui->AddMessageHandler(std::make_unique<GenericHandler>()); |
Lei Zhang | ee3b63ad | 2018-06-06 23:25:31 | [diff] [blame] | 6366 | web_ui->SetController(std::move(controller)); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 6367 | return web_ui; |
| 6368 | } |
| 6369 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 6370 | return nullptr; |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 6371 | } |
| 6372 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 6373 | FindRequestManager* WebContentsImpl::GetFindRequestManager() { |
| 6374 | for (WebContentsImpl* contents = this; contents; |
| 6375 | contents = contents->GetOuterWebContents()) { |
| 6376 | if (contents->find_request_manager_) |
| 6377 | return contents->find_request_manager_.get(); |
| 6378 | } |
| 6379 | |
| 6380 | return nullptr; |
| 6381 | } |
| 6382 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 6383 | FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 6384 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 6385 | return manager; |
| 6386 | |
| 6387 | // No existing FindRequestManager found, so one must be created. |
| 6388 | find_request_manager_.reset(new FindRequestManager(this)); |
| 6389 | |
| 6390 | // Concurrent find sessions must not overlap, so destroy any existing |
| 6391 | // FindRequestManagers in any inner WebContentses. |
| 6392 | for (WebContentsImpl* contents : GetWebContentsAndAllInner()) { |
| 6393 | if (contents == this) |
| 6394 | continue; |
| 6395 | if (contents->find_request_manager_) { |
| 6396 | contents->find_request_manager_->StopFinding( |
| 6397 | content::STOP_FIND_ACTION_CLEAR_SELECTION); |
| 6398 | contents->find_request_manager_.release(); |
| 6399 | } |
| 6400 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 6401 | |
| 6402 | return find_request_manager_.get(); |
| 6403 | } |
| 6404 | |
| 6405 | void WebContentsImpl::NotifyFindReply(int request_id, |
| 6406 | int number_of_matches, |
| 6407 | const gfx::Rect& selection_rect, |
| 6408 | int active_match_ordinal, |
| 6409 | bool final_update) { |
Sebastien Marchand | cf97ed5 | 2017-07-24 23:50:34 | [diff] [blame] | 6410 | if (delegate_ && !is_being_destroyed_ && |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 6411 | !GetMainFrame()->GetProcess()->FastShutdownStarted()) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 6412 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 6413 | active_match_ordinal, final_update); |
| 6414 | } |
| 6415 | } |
| 6416 | |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 6417 | void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() { |
| 6418 | // Trying to invalidate the tab state while being destroyed could result in a |
| 6419 | // use after free. |
| 6420 | if (IsBeingDestroyed()) { |
| 6421 | return; |
| 6422 | } |
| 6423 | // Notify for UI updates if the state changes. |
| 6424 | bluetooth_connected_device_count_++; |
| 6425 | if (bluetooth_connected_device_count_ == 1) { |
| 6426 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 6427 | } |
| 6428 | } |
| 6429 | |
| 6430 | void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() { |
| 6431 | // Trying to invalidate the tab state while being destroyed could result in a |
| 6432 | // use after free. |
| 6433 | if (IsBeingDestroyed()) { |
| 6434 | return; |
| 6435 | } |
| 6436 | // Notify for UI updates if the state changes. |
Lukasz Anforowicz | e9ae372 | 2017-09-29 17:37:38 | [diff] [blame] | 6437 | DCHECK_NE(bluetooth_connected_device_count_, 0u); |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 6438 | bluetooth_connected_device_count_--; |
| 6439 | if (bluetooth_connected_device_count_ == 0) { |
| 6440 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 6441 | } |
| 6442 | } |
| 6443 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 6444 | void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) { |
| 6445 | if (has_persistent_video_ == has_persistent_video) |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6446 | return; |
| 6447 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 6448 | has_persistent_video_ = has_persistent_video; |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6449 | NotifyPreferencesChanged(); |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 6450 | media_web_contents_observer()->RequestPersistentVideo(has_persistent_video); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6451 | } |
| 6452 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 6453 | void WebContentsImpl::BrowserPluginGuestWillDetach() { |
| 6454 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 6455 | if (this != outermost && ContainsOrIsFocusedWebContents()) |
| 6456 | outermost->SetAsFocusedWebContentsIfNecessary(); |
| 6457 | } |
| 6458 | |
Mounir Lamouri | 11e9ef4 | 2018-05-22 03:10:16 | [diff] [blame] | 6459 | gfx::Size WebContentsImpl::EnterPictureInPicture( |
| 6460 | const viz::SurfaceId& surface_id, |
| 6461 | const gfx::Size& natural_size) { |
| 6462 | return delegate_ ? delegate_->EnterPictureInPicture(surface_id, natural_size) |
| 6463 | : gfx::Size(); |
| 6464 | } |
| 6465 | |
Mounir Lamouri | 6d759e1 | 2018-05-16 20:01:30 | [diff] [blame] | 6466 | void WebContentsImpl::ExitPictureInPicture() { |
| 6467 | if (delegate_) |
| 6468 | delegate_->ExitPictureInPicture(); |
| 6469 | } |
| 6470 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 6471 | #if defined(OS_ANDROID) |
| 6472 | void WebContentsImpl::NotifyFindMatchRectsReply( |
| 6473 | int version, |
| 6474 | const std::vector<gfx::RectF>& rects, |
| 6475 | const gfx::RectF& active_rect) { |
| 6476 | if (delegate_) |
| 6477 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 6478 | } |
| 6479 | #endif |
| 6480 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 6481 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 6482 | force_disable_overscroll_content_ = force_disable; |
| 6483 | if (view_) |
| 6484 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 6485 | } |
| 6486 | |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6487 | bool WebContentsImpl::SetDeviceEmulationSize(const gfx::Size& new_size) { |
| 6488 | device_emulation_size_ = new_size; |
| 6489 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 6490 | |
| 6491 | const gfx::Size current_size = rwhv->GetViewBounds().size(); |
| 6492 | if (view_size_before_emulation_.IsEmpty()) |
| 6493 | view_size_before_emulation_ = current_size; |
| 6494 | |
| 6495 | if (current_size != new_size) |
| 6496 | rwhv->SetSize(new_size); |
| 6497 | |
| 6498 | return current_size != new_size; |
| 6499 | } |
| 6500 | |
| 6501 | void WebContentsImpl::ClearDeviceEmulationSize() { |
| 6502 | RenderWidgetHostView* rwhv = GetMainFrame()->GetView(); |
| 6503 | // WebContentsView could get resized during emulation, which also resizes |
| 6504 | // RWHV. If it happens, assume user would like to keep using the size after |
| 6505 | // emulation. |
| 6506 | // TODO(jzfeng): Prohibit resizing RWHV through any other means (at least when |
| 6507 | // WebContentsView size changes). |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 6508 | if (!view_size_before_emulation_.IsEmpty() && rwhv && |
| 6509 | rwhv->GetViewBounds().size() == device_emulation_size_) { |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6510 | rwhv->SetSize(view_size_before_emulation_); |
Dmitry Gozman | c6370718 | 2018-03-06 00:09:39 | [diff] [blame] | 6511 | } |
Jianzhou Feng | d8720c7 | 2018-01-18 03:06:30 | [diff] [blame] | 6512 | device_emulation_size_ = gfx::Size(); |
| 6513 | view_size_before_emulation_ = gfx::Size(); |
| 6514 | } |
| 6515 | |
Max Morin | 5bc74f5 | 2018-05-09 07:00:21 | [diff] [blame] | 6516 | ForwardingAudioStreamFactory* WebContentsImpl::GetAudioStreamFactory() { |
| 6517 | if (!audio_stream_factory_) { |
| 6518 | audio_stream_factory_.emplace( |
| 6519 | this, |
| 6520 | content::ServiceManagerConnection::GetForProcess() |
| 6521 | ->GetConnector() |
| 6522 | ->Clone(), |
| 6523 | AudioStreamBrokerFactory::CreateImpl()); |
| 6524 | } |
| 6525 | |
| 6526 | return &*audio_stream_factory_; |
| 6527 | } |
| 6528 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 6529 | void WebContentsImpl::MediaStartedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6530 | const WebContentsObserver::MediaPlayerInfo& media_info, |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 6531 | const WebContentsObserver::MediaPlayerId& id) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6532 | if (media_info.has_video) |
| 6533 | currently_playing_video_count_++; |
| 6534 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 6535 | for (auto& observer : observers_) |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6536 | observer.MediaStartedPlaying(media_info, id); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 6537 | } |
| 6538 | |
| 6539 | void WebContentsImpl::MediaStoppedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6540 | const WebContentsObserver::MediaPlayerInfo& media_info, |
Becca Hughes | 220bfc10 | 2017-11-14 18:24:07 | [diff] [blame] | 6541 | const WebContentsObserver::MediaPlayerId& id, |
| 6542 | WebContentsObserver::MediaStoppedReason reason) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6543 | if (media_info.has_video) |
| 6544 | currently_playing_video_count_--; |
| 6545 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 6546 | for (auto& observer : observers_) |
Becca Hughes | 220bfc10 | 2017-11-14 18:24:07 | [diff] [blame] | 6547 | observer.MediaStoppedPlaying(media_info, id, reason); |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6548 | } |
| 6549 | |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 6550 | void WebContentsImpl::MediaResized( |
| 6551 | const gfx::Size& size, |
| 6552 | const WebContentsObserver::MediaPlayerId& id) { |
| 6553 | cached_video_sizes_[id] = size; |
| 6554 | |
| 6555 | for (auto& observer : observers_) |
| 6556 | observer.MediaResized(size, id); |
| 6557 | } |
| 6558 | |
Peter E Conn | eccb34c2 | 2017-09-08 09:37:58 | [diff] [blame] | 6559 | void WebContentsImpl::MediaEffectivelyFullscreenChanged(bool is_fullscreen) { |
| 6560 | for (auto& observer : observers_) |
| 6561 | observer.MediaEffectivelyFullscreenChanged(is_fullscreen); |
| 6562 | } |
| 6563 | |
Peter Conn | 31c726a | 2017-08-17 11:07:34 | [diff] [blame] | 6564 | base::Optional<gfx::Size> WebContentsImpl::GetFullscreenVideoSize() { |
| 6565 | base::Optional<WebContentsObserver::MediaPlayerId> id = |
| 6566 | media_web_contents_observer_->GetFullscreenVideoMediaPlayerId(); |
| 6567 | if (id && cached_video_sizes_.count(id.value())) |
| 6568 | return base::Optional<gfx::Size>(cached_video_sizes_[id.value()]); |
| 6569 | return base::Optional<gfx::Size>(); |
peconn | 25795152 | 2017-06-09 18:24:59 | [diff] [blame] | 6570 | } |
| 6571 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 6572 | int WebContentsImpl::GetCurrentlyPlayingVideoCount() { |
| 6573 | return currently_playing_video_count_; |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 6574 | } |
| 6575 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6576 | void WebContentsImpl::UpdateWebContentsVisibility(Visibility visibility) { |
Francois Doray | 3f2afbd | 2018-04-06 19:18:18 | [diff] [blame] | 6577 | // Occlusion is disabled when |features::kWebContentsOcclusion| is disabled |
| 6578 | // (for power and speed impact assessment) or when |
| 6579 | // |switches::kDisableBackgroundingOccludedWindowsForTesting| is specified on |
| 6580 | // the command line (to avoid flakiness in browser tests). |
| 6581 | const bool occlusion_is_disabled = |
| 6582 | !base::FeatureList::IsEnabled(features::kWebContentsOcclusion) || |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6583 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 6584 | switches::kDisableBackgroundingOccludedWindowsForTesting); |
| 6585 | if (occlusion_is_disabled && visibility == Visibility::OCCLUDED) |
| 6586 | visibility = Visibility::VISIBLE; |
| 6587 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6588 | if (!did_first_set_visible_) { |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6589 | if (visibility == Visibility::VISIBLE) { |
| 6590 | // A WebContents created with CreateParams::initially_hidden = false |
| 6591 | // starts with GetVisibility() == Visibility::VISIBLE even though it is |
| 6592 | // not really visible. Call WasShown() when it becomes visible for real as |
| 6593 | // the page load mechanism and some WebContentsObserver rely on that. |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6594 | WasShown(); |
Francois Doray | fe4a177 | 2018-02-17 04:17:09 | [diff] [blame] | 6595 | did_first_set_visible_ = true; |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6596 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6597 | |
| 6598 | // Trust the initial visibility of the WebContents and do not switch it to |
| 6599 | // HIDDEN or OCCLUDED before it becomes VISIBLE for real. Doing so would |
| 6600 | // result in destroying resources that would immediately be recreated (e.g. |
| 6601 | // UpdateWebContents(HIDDEN) can be called when a WebContents is added to a |
| 6602 | // hidden window that is about to be shown). |
| 6603 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6604 | return; |
| 6605 | } |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6606 | |
| 6607 | if (visibility == visibility_) |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6608 | return; |
| 6609 | |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6610 | if (visibility == Visibility::VISIBLE) |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6611 | WasShown(); |
Francois Doray | e616115 | 2018-03-27 22:05:37 | [diff] [blame] | 6612 | else if (visibility == Visibility::OCCLUDED) |
| 6613 | WasOccluded(); |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 6614 | else |
| 6615 | WasHidden(); |
| 6616 | } |
| 6617 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 6618 | void WebContentsImpl::UpdateOverridingUserAgent() { |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 6619 | NotifyPreferencesChanged(); |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 6620 | } |
| 6621 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 6622 | void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 6623 | JavaScriptDialogManager* dialog_manager) { |
| 6624 | dialog_manager_ = dialog_manager; |
| 6625 | } |
| 6626 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 6627 | void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { |
| 6628 | auto it = binding_sets_.find(interface_name); |
| 6629 | if (it != binding_sets_.end()) |
| 6630 | binding_sets_.erase(it); |
| 6631 | } |
| 6632 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 6633 | bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) { |
nzolghadr | bbffc6c | 2017-05-25 17:56:39 | [diff] [blame] | 6634 | // Here we associate this metric to the main frame URL regardless of what |
| 6635 | // caused it. |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 6636 | sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL( |
| 6637 | GetLastCommittedURL())); |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 6638 | return true; |
| 6639 | } |
| 6640 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6641 | void WebContentsImpl::FocusedNodeTouched(bool editable) { |
| 6642 | #if defined(OS_WIN) |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6643 | RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 6644 | if (!view) |
| 6645 | return; |
Dave Tapuska | 2315d8f | 2018-03-06 17:52:55 | [diff] [blame] | 6646 | view->FocusedNodeTouched(editable); |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 6647 | #endif |
| 6648 | } |
| 6649 | |
samans | 90fb816 | 2017-04-04 22:30:45 | [diff] [blame] | 6650 | void WebContentsImpl::DidReceiveCompositorFrame() { |
| 6651 | for (auto& observer : observers_) |
| 6652 | observer.DidReceiveCompositorFrame(); |
| 6653 | } |
| 6654 | |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 6655 | void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() { |
| 6656 | bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 6657 | switches::kAllowInsecureLocalhost); |
| 6658 | if (!allow_localhost) |
| 6659 | return; |
| 6660 | |
| 6661 | content::NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
Rob Wu | f79b3ba | 2018-01-14 01:54:31 | [diff] [blame] | 6662 | if (!entry || !net::IsLocalhost(entry->GetURL())) |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 6663 | return; |
| 6664 | |
| 6665 | content::SSLStatus ssl_status = entry->GetSSL(); |
| 6666 | bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) && |
| 6667 | !net::IsCertStatusMinorError(ssl_status.cert_status); |
| 6668 | if (!is_cert_error) |
| 6669 | return; |
| 6670 | |
| 6671 | GetMainFrame()->AddMessageToConsole( |
| 6672 | content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 6673 | base::StringPrintf("This site does not have a valid SSL " |
| 6674 | "certificate! Without SSL, your site's and " |
| 6675 | "visitors' data is vulnerable to theft and " |
| 6676 | "tampering. Get a valid SSL certificate before" |
| 6677 | " releasing your website to the public.")); |
| 6678 | } |
| 6679 | |
ekaramad | f6750aa | 2017-06-06 18:29:42 | [diff] [blame] | 6680 | bool WebContentsImpl::IsShowingContextMenuOnPage() const { |
| 6681 | return showing_context_menu_; |
| 6682 | } |
| 6683 | |
Min Qin | a904f330 | 2018-02-13 23:33:34 | [diff] [blame] | 6684 | download::DownloadUrlParameters::RequestHeadersType |
| 6685 | WebContentsImpl::ParseDownloadHeaders(const std::string& headers) { |
| 6686 | download::DownloadUrlParameters::RequestHeadersType request_headers; |
Megan Jablonski | 2f6a4c5 | 2017-07-10 23:01:25 | [diff] [blame] | 6687 | for (const base::StringPiece& key_value : base::SplitStringPiece( |
| 6688 | headers, "\r\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY)) { |
| 6689 | std::vector<std::string> pair = base::SplitString( |
| 6690 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 6691 | if (2ul == pair.size()) |
| 6692 | request_headers.push_back(make_pair(pair[0], pair[1])); |
| 6693 | } |
| 6694 | return request_headers; |
| 6695 | } |
| 6696 | |
lukasza | 6f8ac62 | 2017-06-06 03:10:20 | [diff] [blame] | 6697 | void WebContentsImpl::SetOpenerForNewContents(FrameTreeNode* opener, |
| 6698 | bool opener_suppressed) { |
| 6699 | if (opener) { |
| 6700 | FrameTreeNode* new_root = GetFrameTree()->root(); |
| 6701 | |
| 6702 | // For the "original opener", track the opener's main frame instead, because |
| 6703 | // if the opener is a subframe, the opener tracking could be easily bypassed |
| 6704 | // by spawning from a subframe and deleting the subframe. |
| 6705 | // https://crbug.com/705316 |
| 6706 | new_root->SetOriginalOpener(opener->frame_tree()->root()); |
| 6707 | |
| 6708 | if (!opener_suppressed) { |
| 6709 | new_root->SetOpener(opener); |
| 6710 | created_with_opener_ = true; |
| 6711 | } |
| 6712 | } |
| 6713 | } |
| 6714 | |
Becca Hughes | 9f6fd4b8 | 2017-06-15 10:01:40 | [diff] [blame] | 6715 | void WebContentsImpl::MediaMutedStatusChanged( |
| 6716 | const WebContentsObserver::MediaPlayerId& id, |
| 6717 | bool muted) { |
| 6718 | for (auto& observer : observers_) |
| 6719 | observer.MediaMutedStatusChanged(id, muted); |
| 6720 | } |
| 6721 | |
EhsanK | 2075c7e | 2017-08-21 02:42:39 | [diff] [blame] | 6722 | void WebContentsImpl::SetVisibilityForChildViews(bool visible) { |
| 6723 | GetMainFrame()->SetVisibilityForChildViews(visible); |
| 6724 | } |
| 6725 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 6726 | } // namespace content |