[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" |
erikchen | 35629cc | 2015-03-10 20:43:22 | [diff] [blame] | 26 | #include "base/profiler/scoped_tracker.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 27 | #include "base/single_thread_task_runner.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 28 | #include "base/strings/string16.h" |
| 29 | #include "base/strings/string_number_conversions.h" |
| 30 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 31 | #include "base/strings/utf_string_conversions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 32 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 33 | #include "base/time/time.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 34 | #include "base/trace_event/trace_event.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 35 | #include "build/build_config.h" |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 36 | #include "components/mime_util/mime_util.h" |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 37 | #include "components/rappor/public/rappor_utils.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 38 | #include "components/url_formatter/url_formatter.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 39 | #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 40 | #include "content/browser/bad_message.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 41 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 42 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 43 | #include "content/browser/child_process_security_policy_impl.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] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 47 | #include "content/browser/download/download_stats.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 48 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 49 | #include "content/browser/download/save_package.h" |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 50 | #include "content/browser/find_request_manager.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 51 | #include "content/browser/frame_host/cross_process_frame_connector.h" |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 52 | #include "content/browser/frame_host/frame_tree_node.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 53 | #include "content/browser/frame_host/interstitial_page_impl.h" |
| 54 | #include "content/browser/frame_host/navigation_entry_impl.h" |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 55 | #include "content/browser/frame_host/navigation_handle_impl.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" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 59 | #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 60 | #include "content/browser/host_zoom_map_impl.h" |
scottmg | 276753cf | 2016-10-27 18:25:22 | [diff] [blame] | 61 | #include "content/browser/host_zoom_map_observer.h" |
csharrison | 2e8c98e | 2016-08-01 23:56:25 | [diff] [blame] | 62 | #include "content/browser/loader/loader_io_thread_notifier.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 63 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 64 | #include "content/browser/manifest/manifest_manager_host.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 65 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 66 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 67 | #include "content/browser/media/media_web_contents_observer.h" |
zqzhang | 1adf3cb | 2016-11-01 11:26:45 | [diff] [blame] | 68 | #include "content/browser/media/session/media_session_impl.h" |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 69 | #include "content/browser/plugin_content_origin_whitelist.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 70 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 71 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 72 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 73 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 74 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 75 | #include "content/browser/renderer_host/render_widget_host_view_base.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" |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 92 | #include "content/common/site_isolation_policy.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 93 | #include "content/common/view_messages.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 94 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 95 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 96 | #include "content/public/browser/browser_plugin_guest_manager.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" |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 99 | #include "content/public/browser/download_url_parameters.h" |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 100 | #include "content/public/browser/focused_node_details.h" |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 101 | #include "content/public/browser/guest_mode.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 102 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 103 | #include "content/public/browser/javascript_dialog_manager.h" |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 104 | #include "content/public/browser/keyboard_event_processing_result.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 105 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 106 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 107 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 108 | #include "content/public/browser/notification_service.h" |
scottmg | 011d96e3 | 2016-06-29 19:15:08 | [diff] [blame] | 109 | #include "content/public/browser/notification_types.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 110 | #include "content/public/browser/render_widget_host_iterator.h" |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 111 | #include "content/public/browser/resource_request_details.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 112 | #include "content/public/browser/security_style_explanations.h" |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 113 | #include "content/public/browser/ssl_status.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 114 | #include "content/public/browser/storage_partition.h" |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 115 | #include "content/public/browser/web_contents_binding_set.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 116 | #include "content/public/browser/web_contents_delegate.h" |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 117 | #include "content/public/browser/web_contents_unresponsive_state.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 118 | #include "content/public/common/bindings_policy.h" |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 119 | #include "content/public/common/browser_side_navigation_policy.h" |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 120 | #include "content/public/common/child_process_host.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 121 | #include "content/public/common/content_constants.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 122 | #include "content/public/common/content_switches.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 123 | #include "content/public/common/page_zoom.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 124 | #include "content/public/common/result_codes.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 125 | #include "content/public/common/url_utils.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 126 | #include "content/public/common/web_preferences.h" |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 127 | #include "device/geolocation/geolocation_service_context.h" |
sammc | 5a139ba | 2016-09-29 01:49:14 | [diff] [blame] | 128 | #include "device/nfc/nfc.mojom.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" |
| 132 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 133 | #include "net/url_request/url_request_context_getter.h" |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 134 | #include "ppapi/features/features.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 135 | #include "services/service_manager/public/cpp/interface_provider.h" |
estark | 47ba9c7d | 2016-10-11 15:40:11 | [diff] [blame] | 136 | #include "third_party/WebKit/public/platform/WebSecurityStyle.h" |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 137 | #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 138 | #include "third_party/skia/include/core/SkBitmap.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 139 | #include "ui/accessibility/ax_tree_combiner.h" |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 140 | #include "ui/base/layout.h" |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 141 | #include "ui/events/blink/web_input_event_traits.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 142 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 143 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 144 | #if defined(OS_WIN) |
| 145 | #include "content/browser/renderer_host/dip_util.h" |
| 146 | #include "ui/gfx/geometry/dip_util.h" |
| 147 | #endif |
| 148 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 149 | #if defined(OS_ANDROID) |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 150 | #include "content/browser/android/content_video_view.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 151 | #include "content/browser/android/date_time_chooser_android.h" |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 152 | #include "content/browser/android/java_interfaces_impl.h" |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 153 | #include "content/browser/media/android/media_web_contents_observer_android.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 154 | #include "content/browser/web_contents/web_contents_android.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 155 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 156 | |
[email protected] | f66df82 | 2012-05-18 16:52:17 | [diff] [blame] | 157 | #if defined(OS_MACOSX) |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 158 | #include "base/mac/foundation_util.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 159 | #endif |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 160 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 161 | #if defined(USE_AURA) |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 162 | #include "content/public/common/service_manager_connection.h" |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 163 | #endif |
| 164 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 165 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 166 | #include "content/browser/media/session/pepper_playback_observer.h" |
| 167 | #endif // ENABLE_PLUGINS |
| 168 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 169 | namespace content { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 170 | namespace { |
| 171 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 172 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 173 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 174 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 175 | #if defined(OS_ANDROID) |
rob.buis | f06a8bf | 2017-03-10 18:11:32 | [diff] [blame] | 176 | const void* const kWebContentsAndroidKey = &kWebContentsAndroidKey; |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 177 | #endif // OS_ANDROID |
| 178 | |
scottmg | 5e65e3a | 2017-03-08 08:48:46 | [diff] [blame] | 179 | base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback>>:: |
| 180 | DestructorAtExit g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 181 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 182 | void NotifyCacheOnIO( |
| 183 | scoped_refptr<net::URLRequestContextGetter> request_context, |
| 184 | const GURL& url, |
| 185 | const std::string& http_method) { |
gunsch | e668855c | 2015-03-05 02:37:58 | [diff] [blame] | 186 | net::HttpCache* cache = request_context->GetURLRequestContext()-> |
| 187 | http_transaction_factory()->GetCache(); |
| 188 | if (cache) |
| 189 | cache->OnExternalCacheHit(url, http_method); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 190 | } |
| 191 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 192 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 193 | for (FrameTreeNode* node : tree->Nodes()) { |
| 194 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 195 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 196 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 197 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 198 | } |
| 199 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 200 | bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) { |
| 201 | // This method scans the frame tree rather than checking whether |
| 202 | // host->delegate() == this, which allows it to return false when the host |
| 203 | // for a frame that is pending or pending deletion. |
| 204 | if (!host) |
| 205 | return false; |
| 206 | |
| 207 | for (FrameTreeNode* node : tree->Nodes()) { |
| 208 | if (node->current_frame_host()->GetRenderWidgetHost() == host) |
| 209 | return true; |
| 210 | } |
| 211 | return false; |
| 212 | } |
| 213 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 214 | void UpdateAccessibilityModeOnFrame(RenderFrameHost* frame_host) { |
| 215 | static_cast<RenderFrameHostImpl*>(frame_host)->UpdateAccessibilityMode(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 216 | } |
| 217 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 218 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 219 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 220 | } |
| 221 | |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 222 | using AXTreeSnapshotCallback = |
| 223 | base::Callback<void(const ui::AXTreeUpdate&)>; |
| 224 | |
| 225 | // Helper class used by WebContentsImpl::RequestAXTreeSnapshot. |
| 226 | // Handles the callbacks from parallel snapshot requests to each frame, |
| 227 | // and feeds the results to an AXTreeCombiner, which converts them into a |
| 228 | // single combined accessibility tree. |
| 229 | class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> { |
| 230 | public: |
| 231 | explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) |
| 232 | : callback_(callback) { |
| 233 | } |
| 234 | |
| 235 | AXTreeSnapshotCallback AddFrame(bool is_root) { |
| 236 | // Adds a reference to |this|. |
| 237 | return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot, |
| 238 | this, |
| 239 | is_root); |
| 240 | } |
| 241 | |
| 242 | void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { |
| 243 | combiner_.AddTree(snapshot, is_root); |
| 244 | } |
| 245 | |
| 246 | private: |
| 247 | friend class base::RefCounted<AXTreeSnapshotCombiner>; |
| 248 | |
| 249 | // This is called automatically after the last call to ReceiveSnapshot |
| 250 | // when there are no more references to this object. |
| 251 | ~AXTreeSnapshotCombiner() { |
| 252 | combiner_.Combine(); |
| 253 | callback_.Run(combiner_.combined()); |
| 254 | } |
| 255 | |
| 256 | ui::AXTreeCombiner combiner_; |
| 257 | AXTreeSnapshotCallback callback_; |
| 258 | }; |
| 259 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 260 | // Helper for GetInnerWebContents(). |
| 261 | bool GetInnerWebContentsHelper( |
| 262 | std::vector<WebContentsImpl*>* all_guest_contents, |
| 263 | WebContents* guest_contents) { |
| 264 | all_guest_contents->push_back(static_cast<WebContentsImpl*>(guest_contents)); |
| 265 | return false; |
| 266 | } |
| 267 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 268 | } // namespace |
| 269 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 270 | WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 271 | FrameTreeNode* opener_node = nullptr; |
| 272 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
| 273 | RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( |
| 274 | params.opener_render_process_id, params.opener_render_frame_id); |
| 275 | if (opener_rfh) |
| 276 | opener_node = opener_rfh->frame_tree_node(); |
| 277 | } |
| 278 | return WebContentsImpl::CreateWithOpener(params, opener_node); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | WebContents* WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 282 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 283 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 284 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[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 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 294 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 295 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 296 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 297 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 298 | void WebContentsImpl::FriendWrapper::AddCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 299 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 300 | g_created_callbacks.Get().push_back(callback); |
| 301 | } |
| 302 | |
benwells | 5e7260d | 2017-03-20 23:36:33 | [diff] [blame] | 303 | void WebContentsImpl::FriendWrapper::RemoveCreatedCallbackForTesting( |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 304 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 305 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
| 306 | if (g_created_callbacks.Get().at(i).Equals(callback)) { |
| 307 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 308 | return; |
| 309 | } |
| 310 | } |
| 311 | } |
| 312 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 313 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
| 314 | if (!rvh) |
| 315 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 316 | return rvh->GetDelegate()->GetAsWebContents(); |
| 317 | } |
| 318 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 319 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 320 | if (!rfh) |
| 321 | return nullptr; |
| 322 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 323 | } |
| 324 | |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 325 | WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) { |
| 326 | FrameTreeNode* frame_tree_node = |
| 327 | FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
ananta | b8cfa3b | 2016-10-14 22:43:19 | [diff] [blame] | 328 | if (!frame_tree_node) |
| 329 | return nullptr; |
jam | 8c4edd0 | 2017-05-06 18:50:33 | [diff] [blame] | 330 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 331 | } |
| 332 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 333 | void WebContents::SetScreenOrientationDelegate( |
| 334 | ScreenOrientationDelegate* delegate) { |
| 335 | ScreenOrientationProvider::SetDelegate(delegate); |
| 336 | } |
| 337 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 338 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 339 | |
| 340 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 341 | public: |
| 342 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
| 343 | : WebContentsObserver(watched_contents), |
| 344 | owner_(owner) { |
| 345 | } |
| 346 | |
| 347 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 348 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 349 | owner_->OnWebContentsDestroyed( |
| 350 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | private: |
| 354 | WebContentsImpl* owner_; |
| 355 | |
| 356 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 357 | }; |
| 358 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 359 | WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id, |
| 360 | int render_frame_id, |
| 361 | ColorChooser* chooser, |
| 362 | int identifier) |
| 363 | : render_process_id(render_process_id), |
| 364 | render_frame_id(render_frame_id), |
| 365 | chooser(chooser), |
| 366 | identifier(identifier) { |
| 367 | } |
| 368 | |
| 369 | WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { |
| 370 | } |
| 371 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 372 | bool WebContentsImpl::ColorChooserInfo::Matches( |
| 373 | RenderFrameHostImpl* render_frame_host, |
| 374 | int color_chooser_id) { |
| 375 | return this->render_process_id == render_frame_host->GetProcess()->GetID() && |
| 376 | this->render_frame_id == render_frame_host->GetRoutingID() && |
| 377 | this->identifier == color_chooser_id; |
| 378 | } |
| 379 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 380 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 381 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode( |
| 382 | WebContentsImpl* current_web_contents) |
| 383 | : current_web_contents_(current_web_contents), |
| 384 | outer_web_contents_(nullptr), |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 385 | outer_contents_frame_tree_node_id_( |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 386 | FrameTreeNode::kFrameTreeNodeInvalidId), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 387 | focused_web_contents_(current_web_contents) {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 388 | |
| 389 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 390 | if (OuterContentsFrameTreeNode()) |
| 391 | OuterContentsFrameTreeNode()->RemoveObserver(this); |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 392 | |
| 393 | if (outer_web_contents_) |
| 394 | outer_web_contents_->node_.DetachInnerWebContents(current_web_contents_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 398 | WebContentsImpl* outer_web_contents, |
| 399 | RenderFrameHostImpl* outer_contents_frame) { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 400 | focused_web_contents_ = nullptr; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 401 | outer_web_contents_ = outer_web_contents; |
| 402 | outer_contents_frame_tree_node_id_ = |
| 403 | outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 404 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 405 | outer_web_contents_->node_.AttachInnerWebContents(current_web_contents_); |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 406 | outer_contents_frame->frame_tree_node()->AddObserver(this); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 407 | } |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 408 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 409 | void WebContentsImpl::WebContentsTreeNode::AttachInnerWebContents( |
| 410 | WebContentsImpl* inner_web_contents) { |
| 411 | inner_web_contents_.push_back(inner_web_contents); |
| 412 | } |
| 413 | |
| 414 | void WebContentsImpl::WebContentsTreeNode::DetachInnerWebContents( |
| 415 | WebContentsImpl* inner_web_contents) { |
| 416 | DCHECK(std::find(inner_web_contents_.begin(), inner_web_contents_.end(), |
| 417 | inner_web_contents) != inner_web_contents_.end()); |
| 418 | inner_web_contents_.erase( |
| 419 | std::remove(inner_web_contents_.begin(), inner_web_contents_.end(), |
| 420 | inner_web_contents), |
| 421 | inner_web_contents_.end()); |
| 422 | } |
| 423 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 424 | FrameTreeNode* |
| 425 | WebContentsImpl::WebContentsTreeNode::OuterContentsFrameTreeNode() const { |
| 426 | return FrameTreeNode::GloballyFindByID(outer_contents_frame_tree_node_id_); |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 427 | } |
| 428 | |
lfg | a3e2bdc | 2017-03-07 20:44:01 | [diff] [blame] | 429 | void WebContentsImpl::WebContentsTreeNode::OnFrameTreeNodeDestroyed( |
| 430 | FrameTreeNode* node) { |
| 431 | DCHECK_EQ(outer_contents_frame_tree_node_id_, node->frame_tree_node_id()) |
| 432 | << "WebContentsTreeNode should only receive notifications for the " |
| 433 | "FrameTreeNode in its outer WebContents that hosts it."; |
| 434 | delete current_web_contents_; // deletes |this| too. |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 435 | } |
| 436 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 437 | void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
| 438 | WebContentsImpl* web_contents) { |
| 439 | DCHECK(!outer_web_contents()) |
| 440 | << "Only the outermost WebContents tracks focus."; |
| 441 | focused_web_contents_ = web_contents; |
| 442 | } |
| 443 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 444 | WebContentsImpl* |
| 445 | WebContentsImpl::WebContentsTreeNode::GetInnerWebContentsInFrame( |
| 446 | const FrameTreeNode* frame) { |
| 447 | auto ftn_id = frame->frame_tree_node_id(); |
| 448 | for (WebContentsImpl* contents : inner_web_contents_) { |
| 449 | if (contents->node_.outer_contents_frame_tree_node_id() == ftn_id) { |
| 450 | return contents; |
| 451 | } |
| 452 | } |
| 453 | return nullptr; |
| 454 | } |
| 455 | |
| 456 | const std::vector<WebContentsImpl*>& |
| 457 | WebContentsImpl::WebContentsTreeNode::inner_web_contents() const { |
| 458 | return inner_web_contents_; |
| 459 | } |
| 460 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 461 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 462 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 463 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 464 | : delegate_(NULL), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 465 | controller_(this, browser_context), |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 466 | render_view_host_delegate_view_(NULL), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 467 | created_with_opener_(false), |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 468 | frame_tree_(new NavigatorImpl(&controller_, this), |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 469 | this, |
| 470 | this, |
| 471 | this, |
| 472 | this), |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 473 | node_(this), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 474 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 475 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 476 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 477 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 478 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 479 | upload_size_(0), |
| 480 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 481 | is_resume_pending_(false), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 482 | has_accessed_initial_document_(false), |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 483 | theme_color_(SK_ColorTRANSPARENT), |
| 484 | last_sent_theme_color_(SK_ColorTRANSPARENT), |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 485 | did_first_visually_non_empty_paint_(false), |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 486 | capturer_count_(0), |
| 487 | should_normally_be_visible_(true), |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 488 | did_first_set_visible_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 489 | is_being_destroyed_(false), |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 490 | is_notifying_observers_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 491 | notify_disconnection_(false), |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 492 | dialog_manager_(NULL), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 493 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 494 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 495 | closed_by_user_gesture_(false), |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 496 | minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 497 | maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 498 | zoom_scroll_remainder_(0), |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 499 | fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 500 | fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 501 | fullscreen_widget_had_focus_at_shutdown_(false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 502 | is_subframe_(false), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 503 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 504 | last_dialog_suppressed_(false), |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 505 | geolocation_service_context_(new device::GeolocationServiceContext()), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 506 | accessibility_mode_( |
| 507 | BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 508 | audio_stream_monitor_(this), |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 509 | bluetooth_connected_device_count_(0), |
mohan.reddy | aae039a | 2014-11-21 17:39:50 | [diff] [blame] | 510 | virtual_keyboard_requested_(false), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 511 | page_scale_factor_is_one_(true), |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 512 | mouse_lock_widget_(nullptr), |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 513 | is_overlay_content_(false), |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 514 | loading_weak_factory_(this), |
| 515 | weak_factory_(this) { |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 516 | frame_tree_.SetFrameRemoveListener( |
| 517 | base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 518 | base::Unretained(this))); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 519 | #if defined(OS_ANDROID) |
| 520 | media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); |
| 521 | #else |
qinmin | 58567c8 | 2015-01-07 21:00:20 | [diff] [blame] | 522 | media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 523 | #endif |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 524 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 525 | pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
| 526 | #endif |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 527 | |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 528 | loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
scottmg | 276753cf | 2016-10-27 18:25:22 | [diff] [blame] | 529 | host_zoom_map_observer_.reset(new HostZoomMapObserver(this)); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 530 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 531 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 532 | WebContentsImpl::~WebContentsImpl() { |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame^] | 533 | // Imperfect sanity check against double free, given some crashes unexpectedly |
| 534 | // observed in the wild. |
| 535 | CHECK(!is_being_destroyed_); |
| 536 | |
| 537 | // We generally keep track of is_being_destroyed_ to let other features know |
| 538 | // to avoid certain actions during destruction. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 539 | is_being_destroyed_ = true; |
| 540 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 541 | // A WebContents should never be deleted while it is notifying observers, |
creis | ba91ba8 | 2017-05-12 22:56:19 | [diff] [blame^] | 542 | // 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] | 543 | // observers. |
| 544 | CHECK(!is_notifying_observers_); |
| 545 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 546 | rwh_input_event_router_.reset(); |
| 547 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 548 | for (auto& entry : binding_sets_) |
| 549 | entry.second->CloseAllBindings(); |
| 550 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 551 | WebContentsImpl* outermost = GetOutermostWebContents(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 552 | if (this != outermost && ContainsOrIsFocusedWebContents()) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 553 | // If the current WebContents is in focus, unset it. |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 554 | outermost->SetAsFocusedWebContentsIfNecessary(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 555 | } |
| 556 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 557 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 558 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 559 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 560 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 561 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 562 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 563 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 564 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 565 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 566 | created_widgets_.clear(); |
| 567 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 568 | // Clear out any JavaScript state. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 569 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 570 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 571 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 572 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 573 | if (color_chooser_info_.get()) |
| 574 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 575 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 576 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 577 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 578 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 579 | NotificationService::current()->Notify( |
| 580 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 581 | Source<WebContents>(this), |
| 582 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 583 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 584 | // Destroy all frame tree nodes except for the root; this notifies observers. |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 585 | frame_tree_.root()->ResetForNewProcess(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 586 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 587 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 588 | // Manually call the observer methods for the root frame tree node. It is |
| 589 | // necessary to manually delete all objects tracking navigations |
| 590 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 591 | // notified of these navigations stopping before the WebContents is |
| 592 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 593 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 594 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 595 | if (root->pending_frame_host()) { |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 596 | root->pending_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 597 | root->pending_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 598 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 599 | } |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 600 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 601 | root->current_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 602 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 603 | |
| 604 | // PlzNavigate: clear up state specific to browser-side navigation. |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 605 | if (IsBrowserSideNavigationEnabled()) { |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 606 | // Do not update state as the WebContents is being destroyed. |
clamy | a86695b | 2017-03-23 14:45:48 | [diff] [blame] | 607 | frame_tree_.root()->ResetNavigationRequest(true, true); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 608 | if (root->speculative_frame_host()) { |
| 609 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
| 610 | root->speculative_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 611 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 612 | } |
| 613 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 614 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 615 | #if BUILDFLAG(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 616 | // Call this before WebContentsDestroyed() is broadcasted since |
| 617 | // AudioFocusManager will be destroyed after that. |
| 618 | pepper_playback_observer_.reset(); |
| 619 | #endif // defined(ENABLED_PLUGINS) |
| 620 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 621 | for (auto& observer : observers_) |
| 622 | observer.FrameDeleted(root->current_frame_host()); |
nasko | a83483fb | 2015-02-27 16:57:10 | [diff] [blame] | 623 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 624 | if (root->pending_render_view_host()) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 625 | for (auto& observer : observers_) |
| 626 | observer.RenderViewDeleted(root->pending_render_view_host()); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 627 | } |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 628 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 629 | for (auto& observer : observers_) |
| 630 | observer.RenderViewDeleted(root->current_host()); |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 631 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 632 | for (auto& observer : observers_) |
| 633 | observer.WebContentsDestroyed(); |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 634 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 635 | for (auto& observer : observers_) |
| 636 | observer.ResetWebContents(); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 637 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 638 | SetDelegate(NULL); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 639 | } |
| 640 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 641 | WebContentsImpl* WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 642 | const WebContents::CreateParams& params, |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 643 | FrameTreeNode* opener) { |
[email protected] | e11f0e9 | 2013-06-12 15:12:03 | [diff] [blame] | 644 | TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 645 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 646 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 647 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
| 648 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 649 | if (opener) { |
avi | 8d1aa16 | 2017-03-27 18:27:37 | [diff] [blame] | 650 | // For the "original opener", track the opener's main frame instead, because |
| 651 | // if the opener is a subframe, the opener tracking could be easily bypassed |
| 652 | // by spawning from a subframe and deleting the subframe. |
| 653 | // https://crbug.com/705316 |
| 654 | new_root->SetOriginalOpener(opener->frame_tree()->root()); |
| 655 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 656 | if (!params.opener_suppressed) { |
| 657 | new_root->SetOpener(opener); |
| 658 | new_contents->created_with_opener_ = true; |
| 659 | } |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 660 | } |
| 661 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 662 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 663 | // flags, and these flags take effect immediately. An exception is if the |
| 664 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 665 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 666 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
| 667 | if (opener) { |
| 668 | blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags(); |
| 669 | const blink::WebSandboxFlags inherit_flag = |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 670 | blink::WebSandboxFlags::kPropagatesToAuxiliaryBrowsingContexts; |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 671 | if ((opener_flags & inherit_flag) == inherit_flag) { |
| 672 | new_root->SetPendingSandboxFlags(opener_flags); |
iclelland | 92f8c0b | 2017-04-19 12:43:05 | [diff] [blame] | 673 | new_root->CommitPendingFramePolicy(); |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 674 | } |
| 675 | } |
| 676 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 677 | // This may be true even when opener is null, such as when opening blocked |
| 678 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 679 | if (params.created_with_opener) |
| 680 | new_contents->created_with_opener_ = true; |
| 681 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 682 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 683 | // This makes |new_contents| act as a guest. |
| 684 | // For more info, see comment above class BrowserPluginGuest. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 685 | BrowserPluginGuest::Create(new_contents, params.guest_delegate); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 686 | // We are instantiating a WebContents for browser plugin. Set its subframe |
| 687 | // bit to true. |
| 688 | new_contents->is_subframe_ = true; |
| 689 | } |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 690 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 691 | return new_contents; |
| 692 | } |
| 693 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 694 | // static |
| 695 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
| 696 | std::vector<WebContentsImpl*> result; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 697 | std::unique_ptr<RenderWidgetHostIterator> widgets( |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 698 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 699 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 700 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 701 | if (!rvh) |
| 702 | continue; |
| 703 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 704 | if (!web_contents) |
| 705 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 706 | if (web_contents->GetRenderViewHost() != rvh) |
| 707 | continue; |
| 708 | // Because a WebContents can only have one current RVH at a time, there will |
| 709 | // be no duplicate WebContents here. |
| 710 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 711 | } |
| 712 | return result; |
| 713 | } |
| 714 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 715 | // static |
| 716 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 717 | const FrameTreeNode* frame_tree_node) { |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 718 | return static_cast<WebContentsImpl*>( |
| 719 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 720 | } |
| 721 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 722 | // static |
| 723 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 724 | int render_frame_host_id) { |
| 725 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 726 | RenderFrameHost* render_frame_host = |
| 727 | RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); |
| 728 | if (!render_frame_host) |
| 729 | return nullptr; |
| 730 | |
| 731 | return WebContents::FromRenderFrameHost(render_frame_host); |
| 732 | } |
| 733 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 734 | // static |
| 735 | WebContentsImpl* WebContentsImpl::FromOuterFrameTreeNode( |
| 736 | const FrameTreeNode* frame_tree_node) { |
| 737 | return WebContentsImpl::FromFrameTreeNode(frame_tree_node) |
| 738 | ->node_.GetInnerWebContentsInFrame(frame_tree_node); |
| 739 | } |
| 740 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 741 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 742 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 743 | } |
| 744 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 745 | bool WebContentsImpl::OnMessageReceived(RenderViewHostImpl* render_view_host, |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 746 | const IPC::Message& message) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 747 | RenderFrameHost* main_frame = render_view_host->GetMainFrame(); |
| 748 | if (main_frame) { |
| 749 | WebUIImpl* web_ui = static_cast<RenderFrameHostImpl*>(main_frame)->web_ui(); |
| 750 | if (web_ui && web_ui->OnMessageReceived(message)) |
| 751 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 752 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 753 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 754 | for (auto& observer : observers_) { |
| 755 | // TODO(nick, creis): Replace all uses of this variant of OnMessageReceived |
| 756 | // with the version that takes a RenderFrameHost, and delete it. |
| 757 | if (observer.OnMessageReceived(message)) |
| 758 | return true; |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 759 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 760 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 761 | bool handled = true; |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 762 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_view_host) |
| 763 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
| 764 | OnFirstVisuallyNonEmptyPaint) |
| 765 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
| 766 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
| 767 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged, |
| 768 | OnPageScaleFactorChanged) |
| 769 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
| 770 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
| 771 | IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
| 772 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 773 | IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 774 | OnRequestPpapiBrokerPermission) |
| 775 | #endif |
| 776 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
| 777 | IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, |
| 778 | OnShowValidationMessage) |
| 779 | IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, |
| 780 | OnHideValidationMessage) |
| 781 | IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, |
| 782 | OnMoveValidationMessage) |
| 783 | #if defined(OS_ANDROID) |
| 784 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, OnOpenDateTimeDialog) |
| 785 | #endif |
| 786 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 787 | IPC_END_MESSAGE_MAP() |
| 788 | |
| 789 | return handled; |
| 790 | } |
| 791 | |
| 792 | bool WebContentsImpl::OnMessageReceived(RenderFrameHostImpl* render_frame_host, |
| 793 | const IPC::Message& message) { |
| 794 | for (auto& observer : observers_) { |
| 795 | if (observer.OnMessageReceived(message, render_frame_host)) |
| 796 | return true; |
| 797 | } |
| 798 | |
| 799 | bool handled = true; |
| 800 | IPC_BEGIN_MESSAGE_MAP_WITH_PARAM(WebContentsImpl, message, render_frame_host) |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 801 | IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, |
| 802 | OnDomOperationResponse) |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 803 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 804 | OnThemeColorChanged) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 805 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 806 | OnDocumentLoadedInFrame) |
| 807 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
| 808 | IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 809 | IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
| 810 | IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
| 811 | OnSetSelectedColorInColorChooser) |
avi | 7830c85 | 2015-08-31 23:46:25 | [diff] [blame] | 812 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 813 | OnDidLoadResourceFromMemoryCache) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 814 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 815 | OnDidDisplayInsecureContent) |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 816 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidContainInsecureFormAction, |
| 817 | OnDidContainInsecureFormAction) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 818 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 819 | OnDidRunInsecureContent) |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 820 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, |
| 821 | OnDidDisplayContentWithCertificateErrors) |
| 822 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors, |
| 823 | OnDidRunContentWithCertificateErrors) |
avi | a23e16b | 2015-07-09 14:18:48 | [diff] [blame] | 824 | IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler, |
| 825 | OnRegisterProtocolHandler) |
| 826 | IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler, |
| 827 | OnUnregisterProtocolHandler) |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 828 | IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals, |
| 829 | OnUpdatePageImportanceSignals) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 830 | IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply) |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 831 | #if BUILDFLAG(ENABLE_PLUGINS) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 832 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 833 | OnPepperInstanceCreated) |
| 834 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 835 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 836 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 837 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback, |
| 838 | OnPepperStartsPlayback) |
| 839 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback, |
| 840 | OnPepperStopsPlayback) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 841 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 842 | IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 843 | OnBrowserPluginMessage(render_frame_host, |
| 844 | message)) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 845 | #endif |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 846 | #if defined(OS_ANDROID) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 847 | IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 848 | OnFindMatchRectsReply) |
paulmeyer | c8cb7cb | 2016-06-07 01:14:19 | [diff] [blame] | 849 | IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply, |
| 850 | OnGetNearestFindResultReply) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 851 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 852 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 853 | IPC_END_MESSAGE_MAP() |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 854 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 855 | return handled; |
| 856 | } |
| 857 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 858 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 859 | return controller_; |
| 860 | } |
| 861 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 862 | const NavigationControllerImpl& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 863 | return controller_; |
| 864 | } |
| 865 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 866 | BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 867 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 868 | } |
| 869 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 870 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 871 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 872 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 873 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 874 | } |
| 875 | |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 876 | const GURL& WebContentsImpl::GetVisibleURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 877 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 878 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 879 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 880 | } |
| 881 | |
| 882 | const GURL& WebContentsImpl::GetLastCommittedURL() const { |
| 883 | // We may not have a navigation entry yet. |
| 884 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 885 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 886 | } |
| 887 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 888 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 889 | return delegate_; |
| 890 | } |
| 891 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 892 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 893 | // TODO(cbentzel): remove this debugging code? |
| 894 | if (delegate == delegate_) |
| 895 | return; |
| 896 | if (delegate_) |
| 897 | delegate_->Detach(this); |
| 898 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 899 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 900 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 901 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 902 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 903 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 904 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 905 | } |
| 906 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 907 | RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 908 | RenderViewHostImpl* host = GetRenderManager()->current_host(); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 909 | return host ? host->GetProcess() : NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 910 | } |
| 911 | |
clamy | df1975e | 2015-02-05 19:12:24 | [diff] [blame] | 912 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 913 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 914 | } |
| 915 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 916 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 917 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 918 | if (!focused_node) |
| 919 | return nullptr; |
| 920 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 921 | } |
| 922 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 923 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 924 | int frame_tree_node_id, |
| 925 | int process_id) { |
| 926 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 927 | |
| 928 | // Sanity check that this is in the caller's expected process. Otherwise a |
| 929 | // recent cross-process navigation may have led to a privilege change that the |
| 930 | // caller is not expecting. |
| 931 | if (!frame || |
| 932 | frame->current_frame_host()->GetProcess()->GetID() != process_id) |
| 933 | return nullptr; |
| 934 | |
| 935 | return frame->current_frame_host(); |
| 936 | } |
| 937 | |
| 938 | RenderFrameHostImpl* WebContentsImpl::UnsafeFindFrameByFrameTreeNodeId( |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 939 | int frame_tree_node_id) { |
creis | f71a263 | 2017-05-04 19:03:50 | [diff] [blame] | 940 | // Beware using this! The RenderFrameHost may have changed since the caller |
| 941 | // obtained frame_tree_node_id. |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 942 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 943 | return frame ? frame->current_frame_host() : nullptr; |
| 944 | } |
| 945 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 946 | void WebContentsImpl::ForEachFrame( |
| 947 | const base::Callback<void(RenderFrameHost*)>& on_frame) { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 948 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 949 | on_frame.Run(node->current_frame_host()); |
| 950 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 951 | } |
| 952 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 953 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
| 954 | std::vector<RenderFrameHost*> frame_hosts; |
| 955 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 956 | frame_hosts.push_back(node->current_frame_host()); |
| 957 | return frame_hosts; |
| 958 | } |
| 959 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 960 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 961 | int number_of_messages = 0; |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 962 | for (RenderFrameHost* rfh : GetAllFrames()) { |
lukasza | 1a9ab242 | 2016-03-02 18:47:25 | [diff] [blame] | 963 | if (!rfh->IsRenderFrameLive()) |
| 964 | continue; |
| 965 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 966 | ++number_of_messages; |
| 967 | IPC::Message* message_copy = new IPC::Message(*message); |
| 968 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 969 | rfh->Send(message_copy); |
| 970 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 971 | delete message; |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 972 | return number_of_messages; |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 973 | } |
| 974 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 975 | void WebContentsImpl::SendPageMessage(IPC::Message* msg) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 976 | frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr); |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 977 | } |
| 978 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 979 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 980 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 981 | } |
| 982 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 983 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 984 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 985 | dialog_manager_->CancelDialogs(this, /*reset_state=*/false); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 986 | } |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 987 | if (browser_plugin_embedder_) |
| 988 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 989 | } |
| 990 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 991 | void WebContentsImpl::ClosePage() { |
| 992 | GetRenderViewHost()->ClosePage(); |
| 993 | } |
| 994 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 995 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 996 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 997 | } |
| 998 | |
lfg | 265a267 | 2016-04-23 03:11:02 | [diff] [blame] | 999 | RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() { |
| 1000 | if (GetOuterWebContents()) |
| 1001 | return GetOuterWebContents()->GetTopLevelRenderWidgetHostView(); |
| 1002 | return GetRenderManager()->GetRenderWidgetHostView(); |
| 1003 | } |
| 1004 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1005 | RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() |
| 1006 | const { |
vmpstr | 6d9996c8 | 2017-02-23 00:43:25 | [diff] [blame] | 1007 | if (auto* widget_host = GetFullscreenRenderWidgetHost()) |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 1008 | return widget_host->GetView(); |
| 1009 | return nullptr; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1010 | } |
| 1011 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1012 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1013 | return view_.get(); |
| 1014 | } |
| 1015 | |
leon.han | 552e9de | 2017-02-09 14:37:30 | [diff] [blame] | 1016 | void WebContentsImpl::OnScreenOrientationChange() { |
| 1017 | DCHECK(screen_orientation_provider_); |
| 1018 | return screen_orientation_provider_->OnOrientationChange(); |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 1019 | } |
| 1020 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 1021 | SkColor WebContentsImpl::GetThemeColor() const { |
| 1022 | return theme_color_; |
| 1023 | } |
| 1024 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1025 | void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) { |
| 1026 | if (mode == accessibility_mode_) |
| 1027 | return; |
| 1028 | |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1029 | // Don't allow accessibility to be enabled for WebContents that are never |
| 1030 | // visible, like background pages. |
| 1031 | if (IsNeverVisible()) |
| 1032 | return; |
| 1033 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1034 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1035 | |
| 1036 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1037 | UpdateAccessibilityModeOnFrame(node->current_frame_host()); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1038 | RenderFrameHost* pending_frame_host = |
| 1039 | node->render_manager()->pending_frame_host(); |
| 1040 | if (pending_frame_host) |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 1041 | UpdateAccessibilityModeOnFrame(pending_frame_host); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1042 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1043 | } |
| 1044 | |
| 1045 | void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1046 | AccessibilityMode new_mode(accessibility_mode_); |
| 1047 | new_mode |= mode; |
| 1048 | SetAccessibilityMode(new_mode); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1049 | } |
| 1050 | |
muyuanli | c693ba1 | 2017-04-27 19:12:40 | [diff] [blame] | 1051 | void WebContentsImpl::RequestAXTreeSnapshot( |
| 1052 | const AXTreeSnapshotCallback& callback) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 1053 | // Send a request to each of the frames in parallel. Each one will return |
| 1054 | // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine |
| 1055 | // them into a single tree and call |callback| with that result, then |
| 1056 | // delete |combiner|. |
| 1057 | AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback); |
| 1058 | for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { |
| 1059 | bool is_root = frame_tree_node->parent() == nullptr; |
| 1060 | frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( |
| 1061 | combiner->AddFrame(is_root)); |
| 1062 | } |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 1063 | } |
| 1064 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 1065 | void WebContentsImpl::SetTemporaryZoomLevel(double level, |
| 1066 | bool temporary_zoom_enabled) { |
| 1067 | SendPageMessage(new PageMsg_SetZoomLevel( |
| 1068 | MSG_ROUTING_NONE, |
| 1069 | temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY |
| 1070 | : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY, |
| 1071 | level)); |
| 1072 | } |
| 1073 | |
| 1074 | void WebContentsImpl::UpdateZoom(double level) { |
| 1075 | // Individual frames may still ignore the new zoom level if their RenderView |
| 1076 | // contains a plugin document or if it uses a temporary zoom level. |
| 1077 | SendPageMessage(new PageMsg_SetZoomLevel( |
| 1078 | MSG_ROUTING_NONE, |
| 1079 | PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level)); |
| 1080 | } |
| 1081 | |
| 1082 | void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, |
| 1083 | const std::string& host, |
| 1084 | double level) { |
| 1085 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 1086 | if (!entry) |
| 1087 | return; |
| 1088 | |
| 1089 | GURL url = HostZoomMap::GetURLFromEntry(entry); |
| 1090 | if (host != net::GetHostOrSpecFromURL(url) || |
| 1091 | (!scheme.empty() && !url.SchemeIs(scheme))) { |
| 1092 | return; |
| 1093 | } |
| 1094 | |
| 1095 | UpdateZoom(level); |
| 1096 | } |
| 1097 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1098 | base::Closure WebContentsImpl::AddBindingSet( |
| 1099 | const std::string& interface_name, |
| 1100 | WebContentsBindingSet* binding_set) { |
| 1101 | auto result = |
| 1102 | binding_sets_.insert(std::make_pair(interface_name, binding_set)); |
| 1103 | DCHECK(result.second); |
| 1104 | return base::Bind(&WebContentsImpl::RemoveBindingSet, |
| 1105 | weak_factory_.GetWeakPtr(), interface_name); |
| 1106 | } |
| 1107 | |
rockot | 8bbad22 | 2017-03-22 04:34:05 | [diff] [blame] | 1108 | WebContentsBindingSet* WebContentsImpl::GetBindingSet( |
| 1109 | const std::string& interface_name) { |
| 1110 | auto it = binding_sets_.find(interface_name); |
| 1111 | if (it == binding_sets_.end()) |
| 1112 | return nullptr; |
| 1113 | return it->second; |
| 1114 | } |
| 1115 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1116 | std::vector<WebContentsImpl*> WebContentsImpl::GetInnerWebContents() { |
| 1117 | if (browser_plugin_embedder_) { |
| 1118 | std::vector<WebContentsImpl*> inner_contents; |
| 1119 | GetBrowserContext()->GetGuestManager()->ForEachGuest( |
| 1120 | this, base::Bind(&GetInnerWebContentsHelper, &inner_contents)); |
| 1121 | return inner_contents; |
| 1122 | } |
| 1123 | |
| 1124 | return node_.inner_web_contents(); |
| 1125 | } |
| 1126 | |
| 1127 | std::vector<WebContentsImpl*> WebContentsImpl::GetWebContentsAndAllInner() { |
| 1128 | std::vector<WebContentsImpl*> all_contents(1, this); |
| 1129 | |
| 1130 | for (size_t i = 0; i != all_contents.size(); ++i) { |
| 1131 | for (auto* inner_contents : all_contents[i]->GetInnerWebContents()) { |
| 1132 | all_contents.push_back(inner_contents); |
| 1133 | } |
| 1134 | } |
| 1135 | |
| 1136 | return all_contents; |
| 1137 | } |
| 1138 | |
Sam McNally | 145fb17 | 2017-05-10 00:13:23 | [diff] [blame] | 1139 | void WebContentsImpl::NotifyManifestUrlChanged( |
| 1140 | const base::Optional<GURL>& manifest_url) { |
| 1141 | for (auto& observer : observers_) |
| 1142 | observer.DidUpdateWebManifestURL(manifest_url); |
| 1143 | } |
| 1144 | |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1145 | void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) { |
| 1146 | SendPageMessage( |
| 1147 | new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor)); |
| 1148 | } |
| 1149 | |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 1150 | void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) { |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1151 | if (GetView()) |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 1152 | GetView()->GetScreenInfo(screen_info); |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1153 | } |
| 1154 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 1155 | std::unique_ptr<WebUI> WebContentsImpl::CreateSubframeWebUI( |
| 1156 | const GURL& url, |
| 1157 | const std::string& frame_name) { |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 1158 | DCHECK(!frame_name.empty()); |
| 1159 | return CreateWebUI(url, frame_name); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1160 | } |
| 1161 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1162 | WebUI* WebContentsImpl::GetWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1163 | WebUI* commited_web_ui = GetCommittedWebUI(); |
| 1164 | return commited_web_ui ? commited_web_ui |
| 1165 | : GetRenderManager()->GetNavigatingWebUI(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1168 | WebUI* WebContentsImpl::GetCommittedWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1169 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1170 | } |
| 1171 | |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1172 | void WebContentsImpl::SetUserAgentOverride(const std::string& override) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1173 | if (GetUserAgentOverride() == override) |
| 1174 | return; |
| 1175 | |
| 1176 | renderer_preferences_.user_agent_override = override; |
| 1177 | |
| 1178 | // Send the new override string to the renderer. |
| 1179 | RenderViewHost* host = GetRenderViewHost(); |
| 1180 | if (host) |
| 1181 | host->SyncRendererPrefs(); |
| 1182 | |
| 1183 | // Reload the page if a load is currently in progress to avoid having |
| 1184 | // different parts of the page loaded using different user agents. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 1185 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1186 | if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent()) |
toyoshim | 6142d96f | 2016-12-19 09:07:25 | [diff] [blame] | 1187 | controller_.Reload(ReloadType::BYPASSING_CACHE, true); |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 1188 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1189 | for (auto& observer : observers_) |
| 1190 | observer.UserAgentOverrideSet(override); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1191 | } |
| 1192 | |
| 1193 | const std::string& WebContentsImpl::GetUserAgentOverride() const { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1194 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1195 | } |
| 1196 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1197 | void WebContentsImpl::EnableWebContentsOnlyAccessibilityMode() { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1198 | if (!GetAccessibilityMode().is_mode_off()) { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1199 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 1200 | ResetAccessibility(rfh); |
| 1201 | } else { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1202 | AddAccessibilityMode(kAccessibilityModeWebContentsOnly); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1203 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1204 | } |
| 1205 | |
dmazzoni | dd3d51a7 | 2016-12-14 18:41:01 | [diff] [blame] | 1206 | bool WebContentsImpl::IsWebContentsOnlyAccessibilityModeForTesting() const { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1207 | return accessibility_mode_ == kAccessibilityModeWebContentsOnly; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1208 | } |
| 1209 | |
| 1210 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
dougt | cd3dad73 | 2017-03-14 03:26:23 | [diff] [blame] | 1211 | return accessibility_mode_ == kAccessibilityModeComplete; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1212 | } |
| 1213 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 1214 | const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const { |
| 1215 | return page_importance_signals_; |
| 1216 | } |
| 1217 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1218 | const base::string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 1219 | // Transient entries take precedence. They are used for interstitial pages |
| 1220 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1221 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1222 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1223 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1224 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1225 | |
| 1226 | WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI(); |
| 1227 | WebUI* our_web_ui = navigating_web_ui |
| 1228 | ? navigating_web_ui |
| 1229 | : GetRenderManager()->current_frame_host()->web_ui(); |
| 1230 | |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1231 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1232 | // Don't override the title in view source mode. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1233 | entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1234 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1235 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1236 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1237 | if (!title.empty()) |
| 1238 | return title; |
| 1239 | } |
| 1240 | } |
| 1241 | |
| 1242 | // We use the title for the last committed entry rather than a pending |
| 1243 | // navigation entry. For example, when the user types in a URL, we want to |
| 1244 | // keep the old page's title until the new load has committed and we get a new |
| 1245 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1246 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1247 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 1248 | // We make an exception for initial navigations. We only want to use the title |
| 1249 | // from the visible entry if: |
| 1250 | // 1. The pending entry has been explicitly assigned a title to display. |
| 1251 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 1252 | // which case there is a pending entry index other than -1. |
| 1253 | // |
| 1254 | // Otherwise, we want to stick with the last committed entry's title during |
| 1255 | // new navigations, which have pending entries at index -1 with no title. |
| 1256 | if (controller_.IsInitialNavigation() && |
| 1257 | ((controller_.GetVisibleEntry() && |
| 1258 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 1259 | controller_.GetPendingEntryIndex() != -1)) { |
| 1260 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 1261 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1262 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1263 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1264 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1265 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1266 | |
| 1267 | // |page_title_when_no_navigation_entry_| is finally used |
| 1268 | // if no title cannot be retrieved. |
| 1269 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1270 | } |
| 1271 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1272 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1273 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1274 | } |
| 1275 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1276 | SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const { |
| 1277 | RenderViewHostImpl* dest_rvh = |
| 1278 | GetRenderManager()->pending_render_view_host() ? |
| 1279 | GetRenderManager()->pending_render_view_host() : |
| 1280 | GetRenderManager()->current_host(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1281 | return dest_rvh->GetSiteInstance(); |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 1282 | } |
| 1283 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1284 | bool WebContentsImpl::IsLoading() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1285 | return frame_tree_.IsLoading() && |
| 1286 | !(ShowingInterstitialPage() && |
| 1287 | GetRenderManager()->interstitial_page()->pause_throbber()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1290 | bool WebContentsImpl::IsLoadingToDifferentDocument() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1291 | return IsLoading() && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1292 | } |
| 1293 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1294 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1295 | return waiting_for_response_ && is_load_to_different_document_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1296 | } |
| 1297 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1298 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1299 | return load_state_; |
| 1300 | } |
| 1301 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1302 | const base::string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1303 | return load_state_host_; |
| 1304 | } |
| 1305 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1306 | uint64_t WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1307 | return upload_size_; |
| 1308 | } |
| 1309 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1310 | uint64_t WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1311 | return upload_position_; |
| 1312 | } |
| 1313 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1314 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 1315 | return canonical_encoding_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1316 | } |
| 1317 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1318 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1319 | DCHECK(!is_being_destroyed_); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1320 | ++capturer_count_; |
| 1321 | DVLOG(1) << "There are now " << capturer_count_ |
| 1322 | << " capturing(s) of WebContentsImpl@" << this; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1323 | |
| 1324 | // Note: This provides a hint to upstream code to size the views optimally |
| 1325 | // for quality (e.g., to avoid scaling). |
| 1326 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1327 | preferred_size_for_capture_ = capture_size; |
| 1328 | OnPreferredSizeChanged(preferred_size_); |
| 1329 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1330 | |
| 1331 | // Ensure that all views are un-occluded before capture begins. |
| 1332 | WasUnOccluded(); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | void WebContentsImpl::DecrementCapturerCount() { |
| 1336 | --capturer_count_; |
| 1337 | DVLOG(1) << "There are now " << capturer_count_ |
| 1338 | << " capturing(s) of WebContentsImpl@" << this; |
| 1339 | DCHECK_LE(0, capturer_count_); |
| 1340 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1341 | if (is_being_destroyed_) |
| 1342 | return; |
| 1343 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1344 | if (capturer_count_ == 0) { |
| 1345 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1346 | preferred_size_for_capture_ = gfx::Size(); |
| 1347 | OnPreferredSizeChanged(old_size); |
| 1348 | } |
| 1349 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1350 | if (IsHidden()) { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1351 | DVLOG(1) << "Executing delayed WasHidden()."; |
| 1352 | WasHidden(); |
| 1353 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1354 | } |
| 1355 | |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1356 | int WebContentsImpl::GetCapturerCount() const { |
| 1357 | return capturer_count_; |
| 1358 | } |
| 1359 | |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1360 | bool WebContentsImpl::IsAudioMuted() const { |
| 1361 | return audio_muter_.get() && audio_muter_->is_muting(); |
| 1362 | } |
| 1363 | |
| 1364 | void WebContentsImpl::SetAudioMuted(bool mute) { |
| 1365 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1366 | << " for WebContentsImpl@" << this; |
| 1367 | |
| 1368 | if (mute == IsAudioMuted()) |
| 1369 | return; |
| 1370 | |
| 1371 | if (mute) { |
| 1372 | if (!audio_muter_) |
| 1373 | audio_muter_.reset(new WebContentsAudioMuter(this)); |
| 1374 | audio_muter_->StartMuting(); |
| 1375 | } else { |
| 1376 | DCHECK(audio_muter_); |
| 1377 | audio_muter_->StopMuting(); |
| 1378 | } |
| 1379 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1380 | for (auto& observer : observers_) |
| 1381 | observer.DidUpdateAudioMutingState(mute); |
wjmaclean | 2f797c78 | 2016-01-07 14:52:03 | [diff] [blame] | 1382 | |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1383 | OnAudioStateChanged(!mute && audio_stream_monitor_.IsCurrentlyAudible()); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1384 | } |
| 1385 | |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 1386 | bool WebContentsImpl::IsConnectedToBluetoothDevice() const { |
| 1387 | return bluetooth_connected_device_count_ > 0; |
ortuno | 32e7db3c | 2016-03-29 16:14:20 | [diff] [blame] | 1388 | } |
| 1389 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1390 | bool WebContentsImpl::IsCrashed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1391 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 1392 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1393 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1394 | #if defined(OS_CHROMEOS) |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1395 | crashed_status_ == |
| 1396 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1397 | #endif |
rkaplow | e56a5203 | 2017-02-07 00:14:54 | [diff] [blame] | 1398 | crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1399 | } |
| 1400 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1401 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1402 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1403 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1404 | return; |
| 1405 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1406 | crashed_status_ = status; |
| 1407 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1408 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1409 | } |
| 1410 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1411 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1412 | return crashed_status_; |
| 1413 | } |
| 1414 | |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 1415 | int WebContentsImpl::GetCrashedErrorCode() const { |
| 1416 | return crashed_error_code_; |
| 1417 | } |
| 1418 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1419 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1420 | return is_being_destroyed_; |
| 1421 | } |
| 1422 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1423 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1424 | InvalidateTypes changed_flags) { |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 1425 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1426 | // is fixed. |
| 1427 | tracked_objects::ScopedTracker tracking_profile( |
| 1428 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1429 | "466285 WebContentsImpl::NotifyNavigationStateChanged")); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1430 | // Notify the media observer of potential audibility changes. |
| 1431 | if (changed_flags & INVALIDATE_TYPE_TAB) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1432 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1433 | } |
| 1434 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1435 | if (delegate_) |
| 1436 | delegate_->NavigationStateChanged(this, changed_flags); |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 1437 | |
| 1438 | if (GetOuterWebContents()) |
| 1439 | GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1440 | } |
| 1441 | |
altimin | ec87fd1f | 2016-11-17 20:22:49 | [diff] [blame] | 1442 | void WebContentsImpl::OnAudioStateChanged(bool is_audible) { |
| 1443 | SendPageMessage(new PageMsg_AudioStateChanged(MSG_ROUTING_NONE, is_audible)); |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1444 | |
altimin | ec87fd1f | 2016-11-17 20:22:49 | [diff] [blame] | 1445 | // Notification for UI updates in response to the changed audio state. |
altimin | d8bd26c | 2016-11-04 11:44:54 | [diff] [blame] | 1446 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 1447 | } |
| 1448 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1449 | base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 1450 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1451 | } |
| 1452 | |
georgesak | 5582cbe | 2015-05-22 22:08:07 | [diff] [blame] | 1453 | void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) { |
| 1454 | last_active_time_ = last_active_time; |
| 1455 | } |
| 1456 | |
hajimehoshi | c4f226a | 2016-10-21 09:01:57 | [diff] [blame] | 1457 | base::TimeTicks WebContentsImpl::GetLastHiddenTime() const { |
| 1458 | return last_hidden_time_; |
| 1459 | } |
| 1460 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 1461 | void WebContentsImpl::WasShown() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1462 | controller_.SetActive(true); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1463 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1464 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1465 | view->Show(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1466 | #if defined(OS_MACOSX) |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1467 | view->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1468 | #endif |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1469 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1470 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1471 | SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE)); |
| 1472 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1473 | last_active_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 1474 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1475 | for (auto& observer : observers_) |
| 1476 | observer.WasShown(); |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1477 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1478 | should_normally_be_visible_ = true; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1479 | } |
| 1480 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1481 | void WebContentsImpl::WasHidden() { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1482 | // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1483 | // don't activate the "disable rendering" optimization. |
| 1484 | if (capturer_count_ == 0) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1485 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1486 | // open a tab in the background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1487 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1488 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1489 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1490 | // calls us). |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1491 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) |
| 1492 | view->Hide(); |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1493 | |
| 1494 | SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1495 | } |
| 1496 | |
hajimehoshi | c4f226a | 2016-10-21 09:01:57 | [diff] [blame] | 1497 | last_hidden_time_ = base::TimeTicks::Now(); |
| 1498 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1499 | for (auto& observer : observers_) |
| 1500 | observer.WasHidden(); |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1501 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1502 | should_normally_be_visible_ = false; |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 1503 | } |
| 1504 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1505 | void WebContentsImpl::WasOccluded() { |
| 1506 | if (capturer_count_ > 0) |
| 1507 | return; |
| 1508 | |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1509 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) |
| 1510 | view->WasOccluded(); |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1511 | } |
| 1512 | |
| 1513 | void WebContentsImpl::WasUnOccluded() { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1514 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) |
| 1515 | view->WasUnOccluded(); |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1516 | } |
| 1517 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1518 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1519 | // TODO(creis): Should we fire even for interstitial pages? |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1520 | return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
jam | 4044498 | 2017-04-11 03:01:41 | [diff] [blame] | 1521 | !GetRenderViewHost()->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1522 | } |
| 1523 | |
nasko | 148bb0b9 | 2016-05-10 21:03:19 | [diff] [blame] | 1524 | void WebContentsImpl::DispatchBeforeUnload() { |
| 1525 | bool for_cross_site_transition = false; |
clamy | bfd6a81 | 2016-05-30 16:25:17 | [diff] [blame] | 1526 | GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1527 | } |
| 1528 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1529 | void WebContentsImpl::AttachToOuterWebContentsFrame( |
| 1530 | WebContents* outer_web_contents, |
| 1531 | RenderFrameHost* outer_contents_frame) { |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 1532 | CHECK(GuestMode::IsCrossProcessFrameGuest(this)); |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1533 | RenderFrameHostManager* render_manager = GetRenderManager(); |
| 1534 | |
| 1535 | // When the WebContents being initialized has an opener, the browser side |
| 1536 | // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
| 1537 | // created. This is needed because the usual initialization happens during |
| 1538 | // the first navigation, but when attaching a new window we don't navigate |
| 1539 | // before attaching. If the browser side is already initialized, the calls |
| 1540 | // below will just early return. |
| 1541 | render_manager->InitRenderView(GetRenderViewHost(), nullptr); |
| 1542 | GetMainFrame()->Init(); |
| 1543 | if (!render_manager->GetRenderWidgetHostView()) |
| 1544 | CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost()); |
| 1545 | |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1546 | auto* outer_web_contents_impl = |
| 1547 | static_cast<WebContentsImpl*>(outer_web_contents); |
| 1548 | auto* outer_contents_frame_impl = |
| 1549 | static_cast<RenderFrameHostImpl*>(outer_contents_frame); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1550 | // Create a link to our outer WebContents. |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1551 | node_.ConnectToOuterWebContents(outer_web_contents_impl, |
| 1552 | outer_contents_frame_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1553 | |
| 1554 | DCHECK(outer_contents_frame); |
| 1555 | |
| 1556 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 1557 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 1558 | // postMessage to the inner WebContents. |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1559 | render_manager->CreateOuterDelegateProxy( |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1560 | outer_contents_frame->GetSiteInstance(), outer_contents_frame_impl); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1561 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1562 | render_manager->SetRWHViewForInnerContents( |
| 1563 | render_manager->GetRenderWidgetHostView()); |
wjmaclean | fab616a | 2016-03-02 18:40:39 | [diff] [blame] | 1564 | |
| 1565 | static_cast<RenderWidgetHostViewChildFrame*>( |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1566 | render_manager->GetRenderWidgetHostView()) |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 1567 | ->RegisterFrameSinkId(); |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 1568 | |
avallee | 7529b2a | 2017-04-26 11:37:51 | [diff] [blame] | 1569 | if (outer_web_contents_impl->frame_tree_.GetFocusedFrame() == |
| 1570 | outer_contents_frame_impl->frame_tree_node()) { |
| 1571 | SetFocusedFrame(frame_tree_.root(), nullptr); |
| 1572 | } |
| 1573 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 1574 | // At this point, we should destroy the TextInputManager which will notify all |
| 1575 | // the RWHV in this WebContents. The RWHV in this WebContents should use the |
| 1576 | // TextInputManager owned by the outer WebContents. |
| 1577 | // TODO(ekaramad): Is it possible to have TextInputState before attaching to |
| 1578 | // outer WebContents? In such a case, is this still the right way to hand off |
| 1579 | // state tracking from inner WebContents's TextInputManager to that of the |
| 1580 | // outer WebContent (crbug.com/609846)? |
| 1581 | text_input_manager_.reset(nullptr); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1582 | } |
| 1583 | |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 1584 | void WebContentsImpl::DidChangeVisibleSecurityState() { |
| 1585 | if (delegate_) { |
| 1586 | delegate_->VisibleSecurityStateChanged(this); |
cjgrant | 6d1d727a | 2016-12-09 21:16:57 | [diff] [blame] | 1587 | for (auto& observer : observers_) |
| 1588 | observer.DidChangeVisibleSecurityState(); |
dalecurtis | 6c58ed0 | 2016-10-28 23:02:37 | [diff] [blame] | 1589 | } |
| 1590 | } |
| 1591 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1592 | void WebContentsImpl::Stop() { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1593 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 1594 | node->StopLoading(); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1595 | for (auto& observer : observers_) |
| 1596 | observer.NavigationStopped(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1599 | WebContents* WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1600 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1601 | // 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] | 1602 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1603 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1604 | create_params.initial_size = GetContainerBounds().size(); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1605 | WebContentsImpl* tc = |
| 1606 | CreateWithOpener(create_params, frame_tree_.root()->opener()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1607 | tc->GetController().CopyStateFrom(controller_); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1608 | for (auto& observer : observers_) |
| 1609 | observer.DidCloneToNewWebContents(this, tc); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1610 | return tc; |
| 1611 | } |
| 1612 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1613 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1614 | const NotificationSource& source, |
| 1615 | const NotificationDetails& details) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1616 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1617 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1618 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1619 | RenderWidgetHostView* view = host->GetView(); |
| 1620 | if (view == GetFullscreenRenderWidgetHostView()) { |
| 1621 | // We cannot just call view_->RestoreFocus() here. On some platforms, |
| 1622 | // attempting to focus the currently-invisible WebContentsView will be |
| 1623 | // flat-out ignored. Therefore, this boolean is used to track whether |
| 1624 | // we will request focus after the fullscreen widget has been |
| 1625 | // destroyed. |
| 1626 | fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
| 1627 | } else { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 1628 | for (auto i = pending_widget_views_.begin(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1629 | i != pending_widget_views_.end(); ++i) { |
| 1630 | if (host->GetView() == i->second) { |
| 1631 | pending_widget_views_.erase(i); |
| 1632 | break; |
| 1633 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1634 | } |
| 1635 | } |
| 1636 | break; |
| 1637 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1638 | default: |
| 1639 | NOTREACHED(); |
| 1640 | } |
| 1641 | } |
| 1642 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 1643 | WebContents* WebContentsImpl::GetWebContents() { |
| 1644 | return this; |
| 1645 | } |
| 1646 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1647 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1648 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1649 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1650 | // it should be hidden. |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1651 | should_normally_be_visible_ = !params.initially_hidden; |
| 1652 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1653 | // The routing ids must either all be set or all be unset. |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1654 | DCHECK((params.routing_id == MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1655 | params.main_frame_routing_id == MSG_ROUTING_NONE && |
| 1656 | params.main_frame_widget_routing_id == MSG_ROUTING_NONE) || |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1657 | (params.routing_id != MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1658 | params.main_frame_routing_id != MSG_ROUTING_NONE && |
| 1659 | params.main_frame_widget_routing_id != MSG_ROUTING_NONE)); |
| 1660 | |
| 1661 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 1662 | if (!site_instance) |
| 1663 | site_instance = SiteInstance::Create(params.browser_context); |
| 1664 | |
| 1665 | // A main RenderFrameHost always has a RenderWidgetHost, since it is always a |
| 1666 | // local root by definition. |
| 1667 | // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no |
| 1668 | // longer be necessary to eagerly grab a routing ID for the view. |
| 1669 | // https://crbug.com/545684 |
| 1670 | int32_t view_routing_id = params.routing_id; |
| 1671 | int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id; |
| 1672 | if (main_frame_widget_routing_id == MSG_ROUTING_NONE) { |
| 1673 | view_routing_id = main_frame_widget_routing_id = |
| 1674 | site_instance->GetProcess()->GetNextRoutingID(); |
| 1675 | } |
| 1676 | |
| 1677 | GetRenderManager()->Init(site_instance.get(), view_routing_id, |
| 1678 | params.main_frame_routing_id, |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 1679 | main_frame_widget_routing_id, |
| 1680 | params.renderer_initiated_creation); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 1681 | |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 1682 | // blink::FrameTree::setName always keeps |unique_name| empty in case of a |
| 1683 | // main frame - let's do the same thing here. |
| 1684 | std::string unique_name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 1685 | frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1686 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1687 | WebContentsViewDelegate* delegate = |
| 1688 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 1689 | |
sky | 52a39e34 | 2016-12-17 17:23:22 | [diff] [blame] | 1690 | if (GuestMode::IsCrossProcessFrameGuest(this)) { |
| 1691 | view_.reset(new WebContentsViewChildFrame( |
| 1692 | this, delegate, &render_view_host_delegate_view_)); |
| 1693 | } else { |
| 1694 | view_.reset(CreateWebContentsView(this, delegate, |
| 1695 | &render_view_host_delegate_view_)); |
fsamuel | adb003360 | 2015-12-09 19:20:41 | [diff] [blame] | 1696 | } |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1697 | |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 1698 | if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) { |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1699 | view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(), |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 1700 | std::move(view_), |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1701 | &render_view_host_delegate_view_)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1702 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1703 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1704 | CHECK(view_.get()); |
| 1705 | |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 1706 | gfx::Size initial_size = params.initial_size; |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1707 | view_->CreateView(initial_size, params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1708 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 1709 | #if BUILDFLAG(ENABLE_PLUGINS) |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 1710 | plugin_content_origin_whitelist_.reset( |
| 1711 | new PluginContentOriginWhitelist(this)); |
| 1712 | #endif |
| 1713 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1714 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1715 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1716 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 1717 | |
leon.han | e4db177a | 2017-02-07 14:19:16 | [diff] [blame] | 1718 | screen_orientation_provider_.reset(new ScreenOrientationProvider(this)); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 1719 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 1720 | manifest_manager_host_.reset(new ManifestManagerHost(this)); |
| 1721 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 1722 | #if defined(OS_ANDROID) |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 1723 | date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 1724 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 1725 | |
| 1726 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
| 1727 | // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
| 1728 | if (browser_plugin_guest_) |
| 1729 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 1730 | |
| 1731 | for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 1732 | g_created_callbacks.Get().at(i).Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1733 | |
| 1734 | // If the WebContents creation was renderer-initiated, it means that the |
| 1735 | // corresponding RenderView and main RenderFrame have already been created. |
| 1736 | // Ensure observers are notified about this. |
| 1737 | if (params.renderer_initiated_creation) { |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 1738 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1739 | RenderViewCreated(GetRenderViewHost()); |
| 1740 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 1741 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 1742 | |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 1743 | // Create the renderer process in advance if requested. |
| 1744 | if (params.initialize_renderer) { |
| 1745 | if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) { |
| 1746 | GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
| 1747 | } |
| 1748 | } |
| 1749 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 1750 | // Ensure that observers are notified of the creation of this WebContents's |
| 1751 | // main RenderFrameHost. It must be done here for main frames, since the |
| 1752 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 1753 | // happens after RenderFrameHostManager::Init. |
| 1754 | NotifySwappedFromRenderManager( |
| 1755 | nullptr, GetRenderManager()->current_frame_host(), true); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1756 | } |
| 1757 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1758 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 1759 | RemoveDestructionObserver(web_contents); |
| 1760 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1761 | // Clear a pending contents that has been closed before being shown. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 1762 | for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1763 | ++iter) { |
| 1764 | if (iter->second != web_contents) |
| 1765 | continue; |
| 1766 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1767 | return; |
| 1768 | } |
| 1769 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1770 | } |
| 1771 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1772 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
| 1773 | if (!ContainsKey(destruction_observers_, web_contents)) { |
| 1774 | destruction_observers_[web_contents] = |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 1775 | base::MakeUnique<DestructionObserver>(this, web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1776 | } |
| 1777 | } |
| 1778 | |
| 1779 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 1780 | destruction_observers_.erase(web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1781 | } |
| 1782 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1783 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1784 | observers_.AddObserver(observer); |
| 1785 | } |
| 1786 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1787 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1788 | observers_.RemoveObserver(observer); |
| 1789 | } |
| 1790 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1791 | std::set<RenderWidgetHostView*> |
| 1792 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 1793 | std::set<RenderWidgetHostView*> set; |
| 1794 | if (ShowingInterstitialPage()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1795 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) |
| 1796 | set.insert(rwhv); |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1797 | } else { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1798 | for (RenderFrameHost* rfh : GetAllFrames()) { |
lfg | f949e0e | 2017-05-10 22:18:11 | [diff] [blame] | 1799 | if (RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 1800 | ->frame_tree_node() |
| 1801 | ->render_manager() |
| 1802 | ->GetRenderWidgetHostView()) { |
| 1803 | set.insert(rwhv); |
| 1804 | } |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1805 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1806 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1807 | return set; |
| 1808 | } |
| 1809 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1810 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1811 | if (delegate_) |
| 1812 | delegate_->ActivateContents(this); |
| 1813 | } |
| 1814 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1815 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
| 1816 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1817 | return; |
| 1818 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1819 | if (delegate_) |
| 1820 | delegate_->LostCapture(); |
| 1821 | } |
| 1822 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1823 | void WebContentsImpl::RenderWidgetCreated( |
| 1824 | RenderWidgetHostImpl* render_widget_host) { |
| 1825 | created_widgets_.insert(render_widget_host); |
| 1826 | } |
| 1827 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1828 | void WebContentsImpl::RenderWidgetDeleted( |
| 1829 | RenderWidgetHostImpl* render_widget_host) { |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1830 | // Note that |is_being_destroyed_| can be true at this point as |
| 1831 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 1832 | // us here. |
| 1833 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1834 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1835 | if (is_being_destroyed_) |
| 1836 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1837 | |
| 1838 | if (render_widget_host && |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 1839 | render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ && |
| 1840 | render_widget_host->GetProcess()->GetID() == |
| 1841 | fullscreen_widget_process_id_) { |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1842 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1843 | delegate_->ExitFullscreenModeForTab(this); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1844 | for (auto& observer : observers_) |
| 1845 | observer.DidDestroyFullscreenWidget(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 1846 | fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1847 | fullscreen_widget_routing_id_ = MSG_ROUTING_NONE; |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1848 | if (fullscreen_widget_had_focus_at_shutdown_) |
| 1849 | view_->RestoreFocus(); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1850 | } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1851 | |
lfg | 7d4caad | 2017-03-22 09:01:45 | [diff] [blame] | 1852 | if (render_widget_host == mouse_lock_widget_) |
lfg | ff8dfc8d | 2016-10-21 17:42:32 | [diff] [blame] | 1853 | LostMouseLock(mouse_lock_widget_); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1854 | } |
| 1855 | |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1856 | void WebContentsImpl::RenderWidgetGotFocus( |
| 1857 | RenderWidgetHostImpl* render_widget_host) { |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 1858 | // Notify the observers if an embedded fullscreen widget was focused. |
| 1859 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 1860 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
| 1861 | NotifyWebContentsFocused(); |
| 1862 | } |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1863 | } |
| 1864 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1865 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 1866 | RenderWidgetHostImpl* render_widget_host, |
| 1867 | bool width_changed) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1868 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 1869 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1870 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1871 | |
lfg | 8d649cc | 2017-04-28 18:04:30 | [diff] [blame] | 1872 | ScreenInfo screen_info; |
| 1873 | GetScreenInfo(&screen_info); |
| 1874 | SendPageMessage(new PageMsg_UpdateScreenInfo(MSG_ROUTING_NONE, screen_info)); |
| 1875 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1876 | for (auto& observer : observers_) |
| 1877 | observer.MainFrameWasResized(width_changed); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1878 | } |
| 1879 | |
paulmeyer | 9ef6e446 | 2015-02-24 19:15:10 | [diff] [blame] | 1880 | void WebContentsImpl::ScreenInfoChanged() { |
| 1881 | if (browser_plugin_embedder_) |
| 1882 | browser_plugin_embedder_->ScreenInfoChanged(); |
| 1883 | } |
| 1884 | |
sky | f65d9bb | 2017-03-24 02:26:39 | [diff] [blame] | 1885 | KeyboardEventProcessingResult WebContentsImpl::PreHandleKeyboardEvent( |
| 1886 | const NativeWebKeyboardEvent& event) { |
| 1887 | return delegate_ ? delegate_->PreHandleKeyboardEvent(this, event) |
| 1888 | : KeyboardEventProcessingResult::NOT_HANDLED; |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1889 | } |
| 1890 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1891 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 1892 | if (browser_plugin_embedder_ && |
| 1893 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
| 1894 | return; |
| 1895 | } |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1896 | if (delegate_) |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1897 | delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1898 | } |
| 1899 | |
[email protected] | d92026ef | 2014-03-03 21:04:13 | [diff] [blame] | 1900 | bool WebContentsImpl::HandleWheelEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1901 | const blink::WebMouseWheelEvent& event) { |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1902 | #if !defined(OS_MACOSX) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1903 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 1904 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1905 | // -the OS already has a gesture to do this through pinch-zoom |
| 1906 | // -if a user starts an inertial scroll, let's go, and presses control |
| 1907 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 1908 | // with control key set which isn't what the user wants |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1909 | if (delegate_ && event.wheel_ticks_y && |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 1910 | !ui::WebInputEventTraits::CanCauseScroll(event)) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 1911 | // Count only integer cumulative scrolls as zoom events; this handles |
| 1912 | // smooth scroll and regular scroll device behavior. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 1913 | zoom_scroll_remainder_ += event.wheel_ticks_y; |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 1914 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 1915 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 1916 | if (whole_zoom_scroll_remainder_ != 0) { |
| 1917 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 1918 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1919 | return true; |
| 1920 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1921 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1922 | return false; |
| 1923 | } |
| 1924 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1925 | bool WebContentsImpl::PreHandleGestureEvent( |
| 1926 | const blink::WebGestureEvent& event) { |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 1927 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1928 | } |
| 1929 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1930 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 1931 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 1932 | return GetOuterWebContents()->GetInputEventRouter(); |
| 1933 | |
| 1934 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1935 | rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter); |
| 1936 | return rwh_input_event_router_.get(); |
| 1937 | } |
| 1938 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 1939 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
| 1940 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 1941 | // send the message in this case, as the main frame's RenderFrameHost and |
| 1942 | // other state has already been cleared. |
| 1943 | if (is_being_destroyed_) |
| 1944 | return; |
| 1945 | |
| 1946 | frame_tree_.ReplicatePageFocus(is_focused); |
| 1947 | } |
| 1948 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1949 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 1950 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1951 | if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1952 | return receiving_widget; |
| 1953 | |
| 1954 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 1955 | // forwarded directly to the widget they arrived on. |
| 1956 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 1957 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1958 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 1959 | WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 1960 | |
| 1961 | // If the focused WebContents is showing an interstitial, return the |
| 1962 | // interstitial's widget. |
| 1963 | if (focused_contents->ShowingInterstitialPage()) { |
| 1964 | return static_cast<RenderFrameHostImpl*>( |
| 1965 | focused_contents->GetRenderManager() |
| 1966 | ->interstitial_page() |
| 1967 | ->GetMainFrame()) |
| 1968 | ->GetRenderWidgetHost(); |
| 1969 | } |
| 1970 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 1971 | // If the focused WebContents is a guest WebContents, then get the focused |
| 1972 | // frame in the embedder WebContents instead. |
| 1973 | FrameTreeNode* focused_frame = nullptr; |
| 1974 | if (focused_contents->browser_plugin_guest_ && |
| 1975 | !GuestMode::IsCrossProcessFrameGuest(focused_contents)) { |
| 1976 | focused_frame = frame_tree_.GetFocusedFrame(); |
| 1977 | } else { |
| 1978 | focused_frame = GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
| 1979 | } |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 1980 | |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1981 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1982 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1983 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 1984 | // The view may be null if a subframe's renderer process has crashed while |
| 1985 | // the subframe has focus. Drop the event in that case. Do not give |
| 1986 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1987 | // wrong frame if a focused subframe renderer crashes while they type. |
| 1988 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1989 | if (!view) |
| 1990 | return nullptr; |
| 1991 | |
| 1992 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1993 | } |
| 1994 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 1995 | RenderWidgetHostImpl* WebContentsImpl::GetRenderWidgetHostWithPageFocus() { |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 1996 | WebContentsImpl* focused_web_contents = GetFocusedWebContents(); |
| 1997 | |
| 1998 | if (focused_web_contents->ShowingInterstitialPage()) { |
| 1999 | return static_cast<RenderFrameHostImpl*>( |
| 2000 | focused_web_contents->GetRenderManager() |
| 2001 | ->interstitial_page() |
| 2002 | ->GetMainFrame()) |
| 2003 | ->GetRenderWidgetHost(); |
| 2004 | } |
| 2005 | |
| 2006 | return focused_web_contents->GetMainFrame()->GetRenderWidgetHost(); |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 2007 | } |
| 2008 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2009 | void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 2010 | // This method is being called to enter renderer-initiated fullscreen mode. |
| 2011 | // Make sure any existing fullscreen widget is shut down first. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2012 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2013 | if (widget_view) { |
| 2014 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2015 | ->ShutdownAndDestroyWidget(true); |
| 2016 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2017 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 2018 | if (delegate_) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2019 | delegate_->EnterFullscreenModeForTab(this, origin); |
| 2020 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2021 | for (auto& observer : observers_) |
| 2022 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2023 | } |
| 2024 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2025 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2026 | // This method is being called to leave renderer-initiated fullscreen mode. |
| 2027 | // Make sure any existing fullscreen widget is shut down first. |
| 2028 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 2029 | if (widget_view) { |
| 2030 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 2031 | ->ShutdownAndDestroyWidget(true); |
| 2032 | } |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2033 | |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 2034 | #if defined(OS_ANDROID) |
| 2035 | ContentVideoView* video_view = ContentVideoView::GetInstance(); |
| 2036 | if (video_view != NULL) |
watk | 9829229 | 2016-01-19 22:24:08 | [diff] [blame] | 2037 | video_view->ExitFullscreen(); |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 2038 | #endif |
| 2039 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2040 | if (delegate_) |
| 2041 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 2042 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2043 | // The fullscreen state is communicated to the renderer through a resize |
| 2044 | // message. If the change in fullscreen state doesn't cause a view resize |
| 2045 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 2046 | // sending a resize message. This is required for the situation of the browser |
| 2047 | // moving the view into a "browser fullscreen" state and then the contents |
| 2048 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 2049 | // have the side effect of the view resizing, hence the explicit call here is |
| 2050 | // required. |
| 2051 | if (!will_cause_resize) { |
| 2052 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 2053 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
| 2054 | render_widget_host->WasResized(); |
| 2055 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 2056 | } |
| 2057 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2058 | for (auto& observer : observers_) { |
| 2059 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), |
| 2060 | will_cause_resize); |
| 2061 | } |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 2062 | } |
| 2063 | |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 2064 | bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 2065 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 2066 | } |
| 2067 | |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 2068 | bool WebContentsImpl::IsFullscreen() { |
| 2069 | return IsFullscreenForCurrentTab(); |
| 2070 | } |
| 2071 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 2072 | blink::WebDisplayMode WebContentsImpl::GetDisplayMode( |
| 2073 | RenderWidgetHostImpl* render_widget_host) const { |
| 2074 | if (!RenderViewHostImpl::From(render_widget_host)) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2075 | return blink::kWebDisplayModeBrowser; |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 2076 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 2077 | return delegate_ ? delegate_->GetDisplayMode(this) |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2078 | : blink::kWebDisplayModeBrowser; |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 2079 | } |
| 2080 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2081 | void WebContentsImpl::RequestToLockMouse( |
| 2082 | RenderWidgetHostImpl* render_widget_host, |
| 2083 | bool user_gesture, |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2084 | bool last_unlocked_by_target, |
| 2085 | bool privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2086 | for (WebContentsImpl* current = this; current; |
| 2087 | current = current->GetOuterWebContents()) { |
| 2088 | if (current->mouse_lock_widget_) { |
| 2089 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 2090 | return; |
| 2091 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2092 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2093 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2094 | if (privileged) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2095 | DCHECK(!GetOuterWebContents()); |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2096 | mouse_lock_widget_ = render_widget_host; |
| 2097 | render_widget_host->GotResponseToLockMouseRequest(true); |
| 2098 | return; |
| 2099 | } |
| 2100 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2101 | bool widget_in_frame_tree = false; |
| 2102 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 2103 | if (node->current_frame_host()->GetRenderWidgetHost() == |
| 2104 | render_widget_host) { |
| 2105 | widget_in_frame_tree = true; |
| 2106 | break; |
| 2107 | } |
| 2108 | } |
| 2109 | |
| 2110 | if (widget_in_frame_tree && delegate_) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2111 | for (WebContentsImpl* current = this; current; |
| 2112 | current = current->GetOuterWebContents()) { |
| 2113 | current->mouse_lock_widget_ = render_widget_host; |
| 2114 | } |
| 2115 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2116 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2117 | } else { |
| 2118 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 2119 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2120 | } |
| 2121 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2122 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2123 | CHECK(mouse_lock_widget_); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2124 | |
| 2125 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) |
| 2126 | return mouse_lock_widget_->delegate()->LostMouseLock(render_widget_host); |
| 2127 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 2128 | mouse_lock_widget_->SendMouseLockLost(); |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 2129 | for (WebContentsImpl* current = this; current; |
| 2130 | current = current->GetOuterWebContents()) { |
| 2131 | current->mouse_lock_widget_ = nullptr; |
| 2132 | } |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 2133 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 2134 | if (delegate_) |
| 2135 | delegate_->LostMouseLock(); |
| 2136 | } |
| 2137 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 2138 | bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 2139 | // To verify if the mouse is locked, the mouse_lock_widget_ needs to be |
| 2140 | // assigned to the widget that requested the mouse lock, and the top-level |
| 2141 | // platform RenderWidgetHostView needs to hold the mouse lock from the OS. |
| 2142 | return mouse_lock_widget_ == render_widget_host && |
| 2143 | GetTopLevelRenderWidgetHostView()->IsMouseLocked(); |
| 2144 | } |
| 2145 | |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 2146 | RenderWidgetHostImpl* WebContentsImpl::GetMouseLockWidget() { |
lfg | e2176fb | 2017-03-26 00:45:47 | [diff] [blame] | 2147 | if (GetTopLevelRenderWidgetHostView()->IsMouseLocked() || |
| 2148 | (GetFullscreenRenderWidgetHostView() && |
| 2149 | GetFullscreenRenderWidgetHostView()->IsMouseLocked())) |
lfg | 84763c9 | 2017-02-16 18:55:15 | [diff] [blame] | 2150 | return mouse_lock_widget_; |
| 2151 | |
| 2152 | return nullptr; |
| 2153 | } |
| 2154 | |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2155 | void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) { |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 2156 | if (visible && !GetOuterWebContents()->IsHidden()) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2157 | WasShown(); |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 2158 | else if (!visible) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 2159 | WasHidden(); |
| 2160 | } |
| 2161 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2162 | void WebContentsImpl::CreateNewWindow( |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2163 | RenderFrameHost* opener, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2164 | int32_t render_view_route_id, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2165 | int32_t main_frame_route_id, |
| 2166 | int32_t main_frame_widget_route_id, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 2167 | const mojom::CreateNewWindowParams& params, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 2168 | SessionStorageNamespace* session_storage_namespace) { |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2169 | // We should have zero valid routing ids, or three valid routing IDs. |
| 2170 | DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), |
| 2171 | (main_frame_route_id == MSG_ROUTING_NONE)); |
| 2172 | DCHECK_EQ((render_view_route_id == MSG_ROUTING_NONE), |
| 2173 | (main_frame_widget_route_id == MSG_ROUTING_NONE)); |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2174 | DCHECK(opener); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2175 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2176 | int render_process_id = opener->GetProcess()->GetID(); |
| 2177 | SiteInstance* source_site_instance = opener->GetSiteInstance(); |
| 2178 | |
| 2179 | // The route IDs passed into this function can be trusted not to already |
| 2180 | // be in use; they were allocated by the RenderWidgetHelper by the caller. |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2181 | DCHECK(!RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id)); |
| 2182 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2183 | // We usually create the new window in the same BrowsingInstance (group of |
| 2184 | // script-related windows), by passing in the current SiteInstance. However, |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2185 | // if the opener is being suppressed (in a non-guest), we create a new |
| 2186 | // SiteInstance in its own BrowsingInstance. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 2187 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2188 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2189 | // If the opener is to be suppressed, the new window can be in any process. |
| 2190 | // Since routing ids are process specific, we must not have one passed in |
| 2191 | // as argument here. |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2192 | DCHECK(!params.opener_suppressed || render_view_route_id == MSG_ROUTING_NONE); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2193 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2194 | scoped_refptr<SiteInstance> site_instance = |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2195 | params.opener_suppressed && !is_guest |
| 2196 | ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) |
| 2197 | : source_site_instance; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2198 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2199 | // We must assign the SessionStorageNamespace before calling Init(). |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 2200 | // |
| 2201 | // http://crbug.com/142685 |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2202 | const std::string& partition_id = |
| 2203 | GetContentClient()->browser()-> |
| 2204 | GetStoragePartitionIdForSite(GetBrowserContext(), |
| 2205 | site_instance->GetSiteURL()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2206 | StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 2207 | GetBrowserContext(), site_instance.get()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 2208 | DOMStorageContextWrapper* dom_storage_context = |
| 2209 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2210 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 2211 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 2212 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2213 | |
| 2214 | if (delegate_ && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2215 | !delegate_->ShouldCreateWebContents( |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2216 | this, source_site_instance, render_view_route_id, main_frame_route_id, |
nick | f5e618c | 2016-11-28 22:38:37 | [diff] [blame] | 2217 | main_frame_widget_route_id, params.window_container_type, |
nick | b374042 | 2017-04-24 22:27:45 | [diff] [blame] | 2218 | opener->GetLastCommittedURL(), params.frame_name, params.target_url, |
| 2219 | partition_id, session_storage_namespace)) { |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2220 | // Note: even though we're not creating a WebContents here, it could have |
| 2221 | // been created by the embedder so ensure that the RenderFrameHost is |
| 2222 | // properly initialized. |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 2223 | // It's safe to only target the frame because the render process will not |
| 2224 | // have a chance to create more frames at this point. |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2225 | RenderFrameHostImpl* rfh = |
| 2226 | RenderFrameHostImpl::FromID(render_process_id, main_frame_route_id); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2227 | if (rfh) { |
| 2228 | DCHECK(rfh->IsRenderFrameLive()); |
jam | baaab3a | 2016-11-05 00:46:18 | [diff] [blame] | 2229 | rfh->Init(); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2230 | } |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2231 | return; |
| 2232 | } |
| 2233 | |
| 2234 | // Create the new web contents. This will automatically create the new |
| 2235 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2236 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2237 | create_params.routing_id = render_view_route_id; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2238 | create_params.main_frame_routing_id = main_frame_route_id; |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2239 | create_params.main_frame_widget_routing_id = main_frame_widget_route_id; |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 2240 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2241 | create_params.opener_render_process_id = render_process_id; |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2242 | create_params.opener_render_frame_id = opener->GetRoutingID(); |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2243 | create_params.opener_suppressed = params.opener_suppressed; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2244 | if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2245 | create_params.initially_hidden = true; |
lfg | 269b702f | 2015-06-08 19:28:19 | [diff] [blame] | 2246 | create_params.renderer_initiated_creation = |
| 2247 | main_frame_route_id != MSG_ROUTING_NONE; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2248 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 2249 | WebContentsImpl* new_contents = NULL; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2250 | if (!is_guest) { |
| 2251 | create_params.context = view_->GetNativeView(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2252 | create_params.initial_size = GetContainerBounds().size(); |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 2253 | new_contents = static_cast<WebContentsImpl*>( |
| 2254 | WebContents::Create(create_params)); |
| 2255 | } else { |
| 2256 | new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2257 | } |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2258 | new_contents->GetController().SetSessionStorageNamespace( |
| 2259 | partition_id, |
| 2260 | session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2261 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 2262 | // If the new frame has a name, make sure any SiteInstances that can find |
| 2263 | // this named frame have proxies for it. Must be called after |
| 2264 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 2265 | // GetSessionStorageNamespace. |
| 2266 | if (!params.frame_name.empty()) |
| 2267 | new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
| 2268 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2269 | // 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] | 2270 | // will be shown immediately). |
| 2271 | if (!params.opener_suppressed) { |
| 2272 | if (!is_guest) { |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2273 | WebContentsView* new_view = new_contents->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2274 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2275 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 2276 | // newly created object and give it one of its own member variables. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2277 | new_view->CreateViewForWidget( |
| 2278 | new_contents->GetRenderViewHost()->GetWidget(), false); |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2279 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2280 | // Save the created window associated with the route so we can show it |
| 2281 | // later. |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2282 | DCHECK_NE(MSG_ROUTING_NONE, main_frame_widget_route_id); |
| 2283 | pending_contents_[std::make_pair( |
| 2284 | render_process_id, main_frame_widget_route_id)] = new_contents; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2285 | AddDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2286 | } |
| 2287 | |
| 2288 | if (delegate_) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2289 | delegate_->WebContentsCreated(this, render_process_id, |
| 2290 | opener->GetRoutingID(), params.frame_name, |
| 2291 | params.target_url, new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2292 | } |
| 2293 | |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2294 | if (opener) { |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 2295 | for (auto& observer : observers_) { |
csharrison | 95f01e92 | 2017-04-24 18:52:35 | [diff] [blame] | 2296 | observer.DidOpenRequestedURL(new_contents, opener, params.target_url, |
| 2297 | params.referrer, params.disposition, |
| 2298 | ui::PAGE_TRANSITION_LINK, |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 2299 | false, // started_from_context_menu |
| 2300 | true); // renderer_initiated |
| 2301 | } |
| 2302 | } |
| 2303 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2304 | if (params.opener_suppressed) { |
| 2305 | // When the opener is suppressed, the original renderer cannot access the |
| 2306 | // 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] | 2307 | bool was_blocked = false; |
| 2308 | if (delegate_) { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2309 | gfx::Rect initial_rect; |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2310 | base::WeakPtr<WebContentsImpl> weak_new_contents = |
| 2311 | new_contents->weak_factory_.GetWeakPtr(); |
| 2312 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2313 | delegate_->AddNewContents( |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2314 | this, new_contents, params.disposition, initial_rect, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2315 | params.user_gesture, &was_blocked); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2316 | |
| 2317 | if (!weak_new_contents) |
| 2318 | return; // The delegate deleted |new_contents| during AddNewContents(). |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2319 | } |
| 2320 | if (!was_blocked) { |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2321 | OpenURLParams open_params(params.target_url, params.referrer, |
| 2322 | WindowOpenDisposition::CURRENT_TAB, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 2323 | ui::PAGE_TRANSITION_LINK, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2324 | true /* is_renderer_initiated */); |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2325 | open_params.user_gesture = params.user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2326 | |
| 2327 | if (delegate_ && !is_guest && |
| 2328 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
| 2329 | // We are in asynchronous add new contents path, delay opening url |
| 2330 | new_contents->delayed_open_url_params_.reset( |
| 2331 | new OpenURLParams(open_params)); |
| 2332 | } else { |
| 2333 | new_contents->OpenURL(open_params); |
| 2334 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2335 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2339 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2340 | int32_t route_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2341 | blink::WebPopupType popup_type) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 2342 | CreateNewWidget(render_process_id, route_id, false, popup_type); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2343 | } |
| 2344 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2345 | void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id, |
| 2346 | int32_t route_id) { |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 2347 | CreateNewWidget(render_process_id, route_id, true, blink::kWebPopupTypeNone); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2348 | } |
| 2349 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2350 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2351 | int32_t route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2352 | bool is_fullscreen, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2353 | blink::WebPopupType popup_type) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2354 | RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 2355 | // 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] | 2356 | // this WebContentsImpl instance. If any other process sends the request, |
| 2357 | // it is invalid and the process must be terminated. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2358 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2359 | base::ProcessHandle process_handle = process->GetHandle(); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2360 | if (process_handle != base::kNullProcessHandle) { |
| 2361 | RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 2362 | base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget")); |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2363 | process->Shutdown(RESULT_CODE_KILLED, false); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2364 | } |
| 2365 | return; |
| 2366 | } |
| 2367 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2368 | RenderWidgetHostImpl* widget_host = |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 2369 | new RenderWidgetHostImpl(this, process, route_id, IsHidden()); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2370 | |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2371 | RenderWidgetHostViewBase* widget_view = |
| 2372 | static_cast<RenderWidgetHostViewBase*>( |
| 2373 | view_->CreateViewForPopupWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 2374 | if (!widget_view) |
| 2375 | return; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2376 | if (!is_fullscreen) { |
| 2377 | // Popups should not get activated. |
| 2378 | widget_view->SetPopupType(popup_type); |
| 2379 | } |
| 2380 | // Save the created widget associated with the route so we can show it later. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2381 | pending_widget_views_[std::make_pair(render_process_id, route_id)] = |
| 2382 | widget_view; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2383 | |
| 2384 | #if defined(OS_MACOSX) |
| 2385 | // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it |
| 2386 | // to allow it to survive the trip without being hosted. |
| 2387 | base::mac::NSObjectRetain(widget_view->GetNativeView()); |
| 2388 | #endif |
| 2389 | } |
| 2390 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2391 | void WebContentsImpl::ShowCreatedWindow(int process_id, |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2392 | int main_frame_widget_route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2393 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2394 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2395 | bool user_gesture) { |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2396 | WebContentsImpl* popup = |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2397 | GetCreatedWindow(process_id, main_frame_widget_route_id); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2398 | if (popup) { |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2399 | WebContentsDelegate* delegate = GetDelegate(); |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2400 | popup->is_resume_pending_ = true; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2401 | if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2402 | popup->ResumeLoadingCreatedWebContents(); |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2403 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2404 | if (delegate) { |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2405 | base::WeakPtr<WebContentsImpl> weak_popup = |
| 2406 | popup->weak_factory_.GetWeakPtr(); |
| 2407 | delegate->AddNewContents(this, popup, disposition, initial_rect, |
| 2408 | user_gesture, nullptr); |
| 2409 | if (!weak_popup) |
| 2410 | return; // The delegate deleted |popup| during AddNewContents(). |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2411 | } |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2412 | |
nick | 0d55848 | 2017-02-13 22:27:22 | [diff] [blame] | 2413 | RenderWidgetHostImpl* rwh = popup->GetMainFrame()->GetRenderWidgetHost(); |
| 2414 | DCHECK_EQ(main_frame_widget_route_id, rwh->GetRoutingID()); |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2415 | rwh->Send(new ViewMsg_Move_ACK(rwh->GetRoutingID())); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2416 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2417 | } |
| 2418 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2419 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2420 | int route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2421 | const gfx::Rect& initial_rect) { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2422 | ShowCreatedWidget(process_id, route_id, false, initial_rect); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2423 | } |
| 2424 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2425 | void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id, |
| 2426 | int route_id) { |
| 2427 | ShowCreatedWidget(process_id, route_id, true, gfx::Rect()); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2428 | } |
| 2429 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2430 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2431 | int route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2432 | bool is_fullscreen, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2433 | const gfx::Rect& initial_rect) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2434 | RenderWidgetHostViewBase* widget_host_view = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2435 | static_cast<RenderWidgetHostViewBase*>( |
| 2436 | GetCreatedWidget(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2437 | if (!widget_host_view) |
| 2438 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2439 | |
| 2440 | RenderWidgetHostView* view = NULL; |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 2441 | if (GetOuterWebContents()) { |
| 2442 | view = GetOuterWebContents()->GetRenderWidgetHostView(); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2443 | } else { |
| 2444 | view = GetRenderWidgetHostView(); |
| 2445 | } |
| 2446 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2447 | if (is_fullscreen) { |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2448 | DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2449 | view_->StoreFocus(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2450 | fullscreen_widget_process_id_ = |
| 2451 | widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2452 | fullscreen_widget_routing_id_ = route_id; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2453 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| 2454 | widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView()); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2455 | delegate_->EnterFullscreenModeForTab(this, GURL()); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2456 | } else { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2457 | widget_host_view->InitAsFullscreen(view); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2458 | } |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2459 | for (auto& observer : observers_) |
| 2460 | observer.DidShowFullscreenWidget(); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2461 | if (!widget_host_view->HasFocus()) |
| 2462 | widget_host_view->Focus(); |
| 2463 | } else { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2464 | widget_host_view->InitAsPopup(view, initial_rect); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2465 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 2466 | |
| 2467 | RenderWidgetHostImpl* render_widget_host_impl = |
| 2468 | RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost()); |
| 2469 | render_widget_host_impl->Init(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2470 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 2471 | // used to implement Pepper Flash fullscreen. |
| 2472 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2473 | |
| 2474 | #if defined(OS_MACOSX) |
| 2475 | // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's |
| 2476 | // properly embedded (or purposefully ignored) we can release the retain we |
| 2477 | // took in CreateNewWidget(). |
| 2478 | base::mac::NSObjectRelease(widget_host_view->GetNativeView()); |
| 2479 | #endif |
| 2480 | } |
| 2481 | |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2482 | WebContentsImpl* WebContentsImpl::GetCreatedWindow( |
| 2483 | int process_id, |
| 2484 | int main_frame_widget_route_id) { |
| 2485 | auto key = std::make_pair(process_id, main_frame_widget_route_id); |
| 2486 | auto iter = pending_contents_.find(key); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2487 | |
| 2488 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 2489 | // in creating one, just return NULL. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2490 | if (iter == pending_contents_.end()) |
| 2491 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2492 | |
| 2493 | WebContentsImpl* new_contents = iter->second; |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2494 | pending_contents_.erase(key); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2495 | RemoveDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2496 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2497 | // Don't initialize the guest WebContents immediately. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 2498 | if (BrowserPluginGuest::IsGuest(new_contents)) |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2499 | return new_contents; |
| 2500 | |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2501 | if (!new_contents->GetMainFrame()->GetProcess()->HasConnection() || |
| 2502 | !new_contents->GetMainFrame()->GetView()) { |
| 2503 | // TODO(nick): http://crbug.com/674318 -- Who deletes |new_contents|? |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2504 | return nullptr; |
nick | 5ae4d2d | 2017-01-06 01:18:35 | [diff] [blame] | 2505 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2506 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2507 | return new_contents; |
| 2508 | } |
| 2509 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2510 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
| 2511 | int route_id) { |
| 2512 | auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2513 | if (iter == pending_widget_views_.end()) { |
| 2514 | DCHECK(false); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2515 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | RenderWidgetHostView* widget_host_view = iter->second; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2519 | pending_widget_views_.erase(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2520 | |
| 2521 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
| 2522 | if (!widget_host->GetProcess()->HasConnection()) { |
| 2523 | // The view has gone away or the renderer crashed. Nothing to do. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2524 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2525 | } |
| 2526 | |
| 2527 | return widget_host_view; |
| 2528 | } |
| 2529 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2530 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 2531 | const MediaStreamRequest& request, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2532 | const MediaResponseCallback& callback) { |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2533 | if (delegate_) { |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2534 | delegate_->RequestMediaAccessPermission(this, request, callback); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2535 | } else { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 2536 | callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
| 2537 | std::unique_ptr<MediaStreamUI>()); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2538 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2539 | } |
| 2540 | |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 2541 | bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin, |
| 2542 | MediaStreamType type) { |
| 2543 | DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 2544 | type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 2545 | return delegate_ && |
| 2546 | delegate_->CheckMediaAccessPermission(this, security_origin, type); |
| 2547 | } |
| 2548 | |
guidou | 8a440b84 | 2017-01-30 13:58:43 | [diff] [blame] | 2549 | std::string WebContentsImpl::GetDefaultMediaDeviceID(MediaStreamType type) { |
| 2550 | if (!delegate_) |
| 2551 | return std::string(); |
| 2552 | return delegate_->GetDefaultMediaDeviceID(this, type); |
| 2553 | } |
| 2554 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 2555 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 2556 | SiteInstance* instance) { |
| 2557 | return controller_.GetSessionStorageNamespace(instance); |
| 2558 | } |
| 2559 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 2560 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 2561 | return controller_.GetSessionStorageNamespaceMap(); |
| 2562 | } |
| 2563 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 2564 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 2565 | return &frame_tree_; |
| 2566 | } |
| 2567 | |
luken | dc35e7f | 2014-11-10 19:06:14 | [diff] [blame] | 2568 | void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) { |
| 2569 | virtual_keyboard_requested_ = requested; |
| 2570 | } |
| 2571 | |
| 2572 | bool WebContentsImpl::IsVirtualKeyboardRequested() { |
| 2573 | return virtual_keyboard_requested_; |
| 2574 | } |
| 2575 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 2576 | bool WebContentsImpl::IsOverridingUserAgent() { |
| 2577 | return GetController().GetVisibleEntry() && |
| 2578 | GetController().GetVisibleEntry()->GetIsOverridingUserAgent(); |
| 2579 | } |
| 2580 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 2581 | bool WebContentsImpl::IsJavaScriptDialogShowing() const { |
| 2582 | return is_showing_javascript_dialog_; |
| 2583 | } |
| 2584 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 2585 | bool WebContentsImpl::ShouldIgnoreUnresponsiveRenderer() { |
| 2586 | // Ignore unresponsive renderers if the debugger is attached to them since the |
| 2587 | // unresponsiveness might be a result of the renderer sitting on a breakpoint. |
| 2588 | // |
| 2589 | // TODO(pfeldman): Fix this to only return true if the renderer is *actually* |
| 2590 | // sitting on a breakpoint. https://crbug.com/684202 |
| 2591 | return DevToolsAgentHost::IsDebuggerAttached(this); |
| 2592 | } |
| 2593 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2594 | AccessibilityMode WebContentsImpl::GetAccessibilityMode() const { |
| 2595 | return accessibility_mode_; |
| 2596 | } |
| 2597 | |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 2598 | void WebContentsImpl::AccessibilityEventReceived( |
| 2599 | const std::vector<AXEventNotificationDetails>& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2600 | for (auto& observer : observers_) |
| 2601 | observer.AccessibilityEventReceived(details); |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 2602 | } |
| 2603 | |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 2604 | void WebContentsImpl::AccessibilityLocationChangesReceived( |
| 2605 | const std::vector<AXLocationChangeNotificationDetails>& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2606 | for (auto& observer : observers_) |
| 2607 | observer.AccessibilityLocationChangesReceived(details); |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 2608 | } |
| 2609 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2610 | RenderFrameHost* WebContentsImpl::GetGuestByInstanceID( |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 2611 | RenderFrameHost* render_frame_host, |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2612 | int browser_plugin_instance_id) { |
| 2613 | BrowserPluginGuestManager* guest_manager = |
| 2614 | GetBrowserContext()->GetGuestManager(); |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2615 | if (!guest_manager) |
| 2616 | return nullptr; |
| 2617 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2618 | WebContents* guest = guest_manager->GetGuestByInstanceID( |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 2619 | render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id); |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2620 | if (!guest) |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2621 | return nullptr; |
| 2622 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2623 | return guest->GetMainFrame(); |
| 2624 | } |
| 2625 | |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 2626 | device::GeolocationServiceContext* |
| 2627 | WebContentsImpl::GetGeolocationServiceContext() { |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 2628 | return geolocation_service_context_.get(); |
| 2629 | } |
| 2630 | |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 2631 | device::mojom::WakeLockContext* WebContentsImpl::GetWakeLockContext() { |
blundell | d8cd72b | 2017-03-28 07:18:38 | [diff] [blame] | 2632 | if (!wake_lock_context_host_) |
| 2633 | wake_lock_context_host_.reset(new WakeLockContextHost(this)); |
blundell | e75a8f9 | 2017-03-27 08:11:17 | [diff] [blame] | 2634 | return wake_lock_context_host_->GetWakeLockContext(); |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 2635 | } |
| 2636 | |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 2637 | device::mojom::WakeLockService* WebContentsImpl::GetRendererWakeLock() { |
| 2638 | // WebContents creates a long-lived connection to one WakeLockServiceImpl. |
| 2639 | // All the frames' requests will be added into the BindingSet of |
| 2640 | // WakeLockServiceImpl via this connection. |
| 2641 | if (!renderer_wake_lock_) { |
| 2642 | device::mojom::WakeLockContext* wake_lock_context = GetWakeLockContext(); |
| 2643 | if (!wake_lock_context) { |
| 2644 | return nullptr; |
| 2645 | } |
ke.he | f435c1e8 | 2017-05-11 04:09:10 | [diff] [blame] | 2646 | wake_lock_context->GetWakeLock( |
| 2647 | device::mojom::WakeLockType::PreventDisplaySleep, |
| 2648 | device::mojom::WakeLockReason::ReasonOther, "Wake Lock API", |
| 2649 | mojo::MakeRequest(&renderer_wake_lock_)); |
ke.he | 98b761e | 2017-05-09 05:59:17 | [diff] [blame] | 2650 | } |
| 2651 | return renderer_wake_lock_.get(); |
| 2652 | } |
| 2653 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2654 | void WebContentsImpl::OnShowValidationMessage( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 2655 | RenderViewHostImpl* source, |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2656 | const gfx::Rect& anchor_in_root_view, |
[email protected] | 6ff9c8f | 2013-12-20 09:05:29 | [diff] [blame] | 2657 | const base::string16& main_text, |
| 2658 | const base::string16& sub_text) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 2659 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2660 | if (delegate_) |
| 2661 | delegate_->ShowValidationMessage( |
| 2662 | this, anchor_in_root_view, main_text, sub_text); |
| 2663 | } |
| 2664 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 2665 | void WebContentsImpl::OnHideValidationMessage(RenderViewHostImpl* source) { |
| 2666 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2667 | if (delegate_) |
| 2668 | delegate_->HideValidationMessage(this); |
| 2669 | } |
| 2670 | |
| 2671 | void WebContentsImpl::OnMoveValidationMessage( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 2672 | RenderViewHostImpl* source, |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2673 | const gfx::Rect& anchor_in_root_view) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 2674 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2675 | if (delegate_) |
| 2676 | delegate_->MoveValidationMessage(this, anchor_in_root_view); |
| 2677 | } |
| 2678 | |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 2679 | void WebContentsImpl::SendScreenRects() { |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 2680 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
kenrb | 0e8dc20 | 2016-05-30 19:51:40 | [diff] [blame] | 2681 | if (node->current_frame_host()->is_local_root()) |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 2682 | node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects(); |
| 2683 | } |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 2684 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2685 | RenderWidgetHostViewBase* rwhv = |
| 2686 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 2687 | if (rwhv) { |
| 2688 | SendPageMessage(new PageMsg_UpdateWindowScreenRect( |
| 2689 | MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow())); |
| 2690 | } |
| 2691 | |
avallee | 9f43b01 | 2016-11-26 07:02:10 | [diff] [blame] | 2692 | if (browser_plugin_embedder_ && !is_being_destroyed_) |
[email protected] | a7568e6 | 2013-06-14 07:50:44 | [diff] [blame] | 2693 | browser_plugin_embedder_->DidSendScreenRects(); |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 2694 | } |
| 2695 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 2696 | TextInputManager* WebContentsImpl::GetTextInputManager() { |
| 2697 | if (GetOuterWebContents()) |
| 2698 | return GetOuterWebContents()->GetTextInputManager(); |
| 2699 | |
| 2700 | if (!text_input_manager_) |
| 2701 | text_input_manager_.reset(new TextInputManager()); |
| 2702 | |
| 2703 | return text_input_manager_.get(); |
| 2704 | } |
| 2705 | |
paulmeyer | 7f6f1d4f | 2016-11-15 00:00:27 | [diff] [blame] | 2706 | bool WebContentsImpl::OnUpdateDragCursor() { |
| 2707 | if (browser_plugin_embedder_) |
| 2708 | return browser_plugin_embedder_->OnUpdateDragCursor(); |
| 2709 | return false; |
| 2710 | } |
| 2711 | |
kenrb | 11f213a | 2017-03-24 18:12:06 | [diff] [blame] | 2712 | bool WebContentsImpl::IsWidgetForMainFrame( |
| 2713 | RenderWidgetHostImpl* render_widget_host) { |
| 2714 | return render_widget_host == GetMainFrame()->GetRenderWidgetHost(); |
| 2715 | } |
| 2716 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2717 | BrowserAccessibilityManager* |
| 2718 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2719 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2720 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2721 | } |
| 2722 | |
| 2723 | BrowserAccessibilityManager* |
| 2724 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2725 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2726 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2727 | } |
| 2728 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 2729 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
| 2730 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2731 | if (!focused_frame) |
| 2732 | return; |
| 2733 | |
| 2734 | focused_frame->Send(new InputMsg_MoveRangeSelectionExtent( |
| 2735 | focused_frame->GetRoutingID(), extent)); |
| 2736 | } |
| 2737 | |
| 2738 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 2739 | const gfx::Point& extent) { |
| 2740 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2741 | if (!focused_frame) |
| 2742 | return; |
| 2743 | |
| 2744 | focused_frame->Send( |
| 2745 | new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent)); |
| 2746 | } |
| 2747 | |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 2748 | void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust, |
| 2749 | int end_adjust) { |
| 2750 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2751 | if (!focused_frame) |
| 2752 | return; |
| 2753 | |
| 2754 | focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( |
| 2755 | focused_frame->GetRoutingID(), start_adjust, end_adjust)); |
| 2756 | } |
| 2757 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2758 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2759 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 2760 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2761 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 2762 | } |
| 2763 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2764 | void WebContentsImpl::ResizeDueToAutoResize( |
| 2765 | RenderWidgetHostImpl* render_widget_host, |
| 2766 | const gfx::Size& new_size) { |
| 2767 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 2768 | return; |
| 2769 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 2770 | if (delegate_) |
| 2771 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 2772 | } |
| 2773 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2774 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2775 | if (!delegate_) |
| 2776 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 2777 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2778 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 2779 | |
| 2780 | RenderFrameHost* source_render_frame_host = RenderFrameHost::FromID( |
| 2781 | params.source_render_process_id, params.source_render_frame_id); |
| 2782 | |
| 2783 | if (source_render_frame_host && params.source_site_instance) { |
| 2784 | CHECK_EQ(source_render_frame_host->GetSiteInstance(), |
| 2785 | params.source_site_instance.get()); |
| 2786 | } |
| 2787 | |
| 2788 | if (new_contents && source_render_frame_host && new_contents != this) { |
| 2789 | for (auto& observer : observers_) { |
| 2790 | observer.DidOpenRequestedURL(new_contents, source_render_frame_host, |
| 2791 | params.url, params.referrer, |
| 2792 | params.disposition, params.transition, |
pnoland | aae574e | 2017-03-06 21:04:21 | [diff] [blame] | 2793 | params.started_from_context_menu, false); |
pnoland | 48894465 | 2017-02-22 18:58:54 | [diff] [blame] | 2794 | } |
| 2795 | } |
| 2796 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2797 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2798 | } |
| 2799 | |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 2800 | bool WebContentsImpl::Send(IPC::Message* message) { |
| 2801 | if (!GetRenderViewHost()) { |
| 2802 | delete message; |
| 2803 | return false; |
| 2804 | } |
| 2805 | |
| 2806 | return GetRenderViewHost()->Send(message); |
| 2807 | } |
| 2808 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 2809 | void WebContentsImpl::RenderFrameForInterstitialPageCreated( |
| 2810 | RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2811 | for (auto& observer : observers_) |
| 2812 | observer.RenderFrameForInterstitialPageCreated(render_frame_host); |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 2813 | } |
| 2814 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2815 | void WebContentsImpl::AttachInterstitialPage( |
| 2816 | InterstitialPageImpl* interstitial_page) { |
| 2817 | DCHECK(interstitial_page); |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2818 | GetRenderManager()->set_interstitial_page(interstitial_page); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2819 | |
| 2820 | // Cancel any visible dialogs so that they don't interfere with the |
| 2821 | // interstitial. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 2822 | CancelActiveAndPendingDialogs(); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2823 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2824 | for (auto& observer : observers_) |
| 2825 | observer.DidAttachInterstitialPage(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2826 | |
| 2827 | // Stop the throbber if needed while the interstitial page is shown. |
| 2828 | if (frame_tree_.IsLoading()) |
| 2829 | LoadingStateChanged(true, true, nullptr); |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2830 | |
| 2831 | // Connect to outer WebContents if necessary. |
| 2832 | if (node_.OuterContentsFrameTreeNode()) { |
| 2833 | if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 2834 | DCHECK( |
| 2835 | static_cast<RenderWidgetHostViewBase*>(interstitial_page->GetView()) |
| 2836 | ->IsRenderWidgetHostViewChildFrame()); |
| 2837 | RenderWidgetHostViewChildFrame* view = |
| 2838 | static_cast<RenderWidgetHostViewChildFrame*>( |
| 2839 | interstitial_page->GetView()); |
| 2840 | GetRenderManager()->SetRWHViewForInnerContents(view); |
| 2841 | } |
| 2842 | } |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | void WebContentsImpl::DidProceedOnInterstitial() { |
| 2846 | // The interstitial page should no longer be pausing the throbber. |
| 2847 | DCHECK(!(ShowingInterstitialPage() && |
| 2848 | GetRenderManager()->interstitial_page()->pause_throbber())); |
| 2849 | |
| 2850 | // Restart the throbber now that the interstitial page no longer pauses it. |
| 2851 | if (ShowingInterstitialPage() && frame_tree_.IsLoading()) |
| 2852 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2853 | } |
| 2854 | |
| 2855 | void WebContentsImpl::DetachInterstitialPage() { |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 2856 | // Disconnect from outer WebContents if necessary. |
| 2857 | if (node_.OuterContentsFrameTreeNode()) { |
| 2858 | if (GetRenderManager()->GetProxyToOuterDelegate()) { |
| 2859 | DCHECK(static_cast<RenderWidgetHostViewBase*>( |
| 2860 | GetRenderManager()->current_frame_host()->GetView()) |
| 2861 | ->IsRenderWidgetHostViewChildFrame()); |
| 2862 | RenderWidgetHostViewChildFrame* view = |
| 2863 | static_cast<RenderWidgetHostViewChildFrame*>( |
| 2864 | GetRenderManager()->current_frame_host()->GetView()); |
| 2865 | GetRenderManager()->SetRWHViewForInnerContents(view); |
| 2866 | } |
| 2867 | } |
| 2868 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2869 | bool interstitial_pausing_throbber = |
| 2870 | ShowingInterstitialPage() && |
| 2871 | GetRenderManager()->interstitial_page()->pause_throbber(); |
[email protected] | 6832c8bc | 2014-04-29 07:20:57 | [diff] [blame] | 2872 | if (ShowingInterstitialPage()) |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2873 | GetRenderManager()->remove_interstitial_page(); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2874 | for (auto& observer : observers_) |
| 2875 | observer.DidDetachInterstitialPage(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2876 | |
| 2877 | // Restart the throbber if needed now that the interstitial page is going |
| 2878 | // away. |
| 2879 | if (interstitial_pausing_throbber && frame_tree_.IsLoading()) |
| 2880 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2881 | } |
| 2882 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2883 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 2884 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 2885 | SendPageMessage(new PageMsg_SetHistoryOffsetAndLength( |
| 2886 | MSG_ROUTING_NONE, history_offset, history_length)); |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 2890 | RenderViewHost* render_view_host, |
| 2891 | int history_offset, |
| 2892 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 2893 | render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength( |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2894 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 2895 | } |
| 2896 | |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 2897 | void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) { |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2898 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2899 | if (!focused_frame) |
| 2900 | return; |
| 2901 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2902 | focused_frame->Send(new FrameMsg_Reload( |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 2903 | focused_frame->GetRoutingID(), bypass_cache)); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2904 | } |
| 2905 | |
megjablon | 3f594107 | 2016-02-04 23:27:52 | [diff] [blame] | 2906 | void WebContentsImpl::ReloadLoFiImages() { |
| 2907 | SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE)); |
| 2908 | } |
| 2909 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2910 | void WebContentsImpl::Undo() { |
| 2911 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2912 | if (!focused_frame) |
| 2913 | return; |
| 2914 | |
| 2915 | focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID())); |
| 2916 | RecordAction(base::UserMetricsAction("Undo")); |
| 2917 | } |
| 2918 | |
| 2919 | void WebContentsImpl::Redo() { |
| 2920 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2921 | if (!focused_frame) |
| 2922 | return; |
| 2923 | focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID())); |
| 2924 | RecordAction(base::UserMetricsAction("Redo")); |
| 2925 | } |
| 2926 | |
| 2927 | void WebContentsImpl::Cut() { |
| 2928 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2929 | if (!focused_frame) |
| 2930 | return; |
| 2931 | |
| 2932 | focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID())); |
| 2933 | RecordAction(base::UserMetricsAction("Cut")); |
| 2934 | } |
| 2935 | |
| 2936 | void WebContentsImpl::Copy() { |
| 2937 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2938 | if (!focused_frame) |
| 2939 | return; |
| 2940 | |
| 2941 | focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID())); |
| 2942 | RecordAction(base::UserMetricsAction("Copy")); |
| 2943 | } |
| 2944 | |
| 2945 | void WebContentsImpl::CopyToFindPboard() { |
| 2946 | #if defined(OS_MACOSX) |
| 2947 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2948 | if (!focused_frame) |
| 2949 | return; |
| 2950 | |
| 2951 | // Windows/Linux don't have the concept of a find pasteboard. |
| 2952 | focused_frame->Send( |
| 2953 | new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID())); |
| 2954 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 2955 | #endif |
| 2956 | } |
| 2957 | |
| 2958 | void WebContentsImpl::Paste() { |
| 2959 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2960 | if (!focused_frame) |
| 2961 | return; |
| 2962 | |
| 2963 | focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID())); |
| 2964 | RecordAction(base::UserMetricsAction("Paste")); |
| 2965 | } |
| 2966 | |
| 2967 | void WebContentsImpl::PasteAndMatchStyle() { |
| 2968 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2969 | if (!focused_frame) |
| 2970 | return; |
| 2971 | |
| 2972 | focused_frame->Send(new InputMsg_PasteAndMatchStyle( |
| 2973 | focused_frame->GetRoutingID())); |
| 2974 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 2975 | } |
| 2976 | |
| 2977 | void WebContentsImpl::Delete() { |
| 2978 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2979 | if (!focused_frame) |
| 2980 | return; |
| 2981 | |
| 2982 | focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID())); |
| 2983 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 2984 | } |
| 2985 | |
| 2986 | void WebContentsImpl::SelectAll() { |
| 2987 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2988 | if (!focused_frame) |
| 2989 | return; |
| 2990 | |
| 2991 | focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID())); |
| 2992 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 2993 | } |
| 2994 | |
yabinh | 351e7ec | 2017-03-10 02:43:24 | [diff] [blame] | 2995 | void WebContentsImpl::CollapseSelection() { |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2996 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2997 | if (!focused_frame) |
| 2998 | return; |
| 2999 | |
yabinh | 351e7ec | 2017-03-10 02:43:24 | [diff] [blame] | 3000 | focused_frame->Send( |
| 3001 | new InputMsg_CollapseSelection(focused_frame->GetRoutingID())); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | void WebContentsImpl::Replace(const base::string16& word) { |
| 3005 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3006 | if (!focused_frame) |
| 3007 | return; |
| 3008 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3009 | focused_frame->Send(new InputMsg_Replace( |
| 3010 | focused_frame->GetRoutingID(), word)); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
| 3014 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3015 | if (!focused_frame) |
| 3016 | return; |
| 3017 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 3018 | focused_frame->Send(new InputMsg_ReplaceMisspelling( |
| 3019 | focused_frame->GetRoutingID(), word)); |
| 3020 | } |
| 3021 | |
| 3022 | void WebContentsImpl::NotifyContextMenuClosed( |
| 3023 | const CustomContextMenuContext& context) { |
| 3024 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3025 | if (!focused_frame) |
| 3026 | return; |
| 3027 | |
| 3028 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 3029 | focused_frame->GetRoutingID(), context)); |
| 3030 | } |
| 3031 | |
| 3032 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 3033 | int action, const CustomContextMenuContext& context) { |
| 3034 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 3035 | if (!focused_frame) |
| 3036 | return; |
| 3037 | |
| 3038 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 3039 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 3040 | } |
| 3041 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3042 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 3043 | return view_->GetNativeView(); |
| 3044 | } |
| 3045 | |
| 3046 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 3047 | return view_->GetContentNativeView(); |
| 3048 | } |
| 3049 | |
| 3050 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 3051 | return view_->GetTopLevelNativeWindow(); |
| 3052 | } |
| 3053 | |
| 3054 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 3055 | return view_->GetViewBounds(); |
| 3056 | } |
| 3057 | |
| 3058 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
| 3059 | gfx::Rect rv; |
| 3060 | view_->GetContainerBounds(&rv); |
| 3061 | return rv; |
| 3062 | } |
| 3063 | |
| 3064 | DropData* WebContentsImpl::GetDropData() { |
| 3065 | return view_->GetDropData(); |
| 3066 | } |
| 3067 | |
| 3068 | void WebContentsImpl::Focus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3069 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3070 | } |
| 3071 | |
| 3072 | void WebContentsImpl::SetInitialFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3073 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3074 | } |
| 3075 | |
| 3076 | void WebContentsImpl::StoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3077 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3078 | } |
| 3079 | |
| 3080 | void WebContentsImpl::RestoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 3081 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 3082 | } |
| 3083 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3084 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3085 | if (ShowingInterstitialPage()) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 3086 | GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 3087 | return; |
| 3088 | } |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 3089 | RenderWidgetHostView* const fullscreen_view = |
| 3090 | GetFullscreenRenderWidgetHostView(); |
| 3091 | if (fullscreen_view) { |
| 3092 | fullscreen_view->Focus(); |
| 3093 | return; |
| 3094 | } |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 3095 | GetRenderViewHost()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3096 | } |
| 3097 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3098 | bool WebContentsImpl::ShowingInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 3099 | return GetRenderManager()->interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3100 | } |
| 3101 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3102 | InterstitialPage* WebContentsImpl::GetInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 3103 | return GetRenderManager()->interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 3104 | } |
| 3105 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3106 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3107 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 3108 | // so we also support this MIME type. |
| 3109 | return contents_mime_type_ == "text/html" || |
| 3110 | contents_mime_type_ == "text/xml" || |
| 3111 | contents_mime_type_ == "application/xhtml+xml" || |
| 3112 | contents_mime_type_ == "text/plain" || |
| 3113 | contents_mime_type_ == "text/css" || |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 3114 | mime_util::IsSupportedJavascriptMimeType(contents_mime_type_); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3115 | } |
| 3116 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3117 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3118 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 3119 | if (!IsSavable()) { |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 3120 | RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3121 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 3122 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3123 | } |
| 3124 | |
| 3125 | Stop(); |
| 3126 | |
| 3127 | // Create the save package and possibly prompt the user for the name to save |
| 3128 | // the page as. The user prompt is an asynchronous operation that runs on |
| 3129 | // another thread. |
| 3130 | save_package_ = new SavePackage(this); |
| 3131 | save_package_->GetSaveInfo(); |
| 3132 | } |
| 3133 | |
| 3134 | // Used in automated testing to bypass prompting the user for file names. |
| 3135 | // Instead, the names and paths are hard coded rather than running them through |
| 3136 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3137 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 3138 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3139 | SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3140 | // Stop the page from navigating. |
| 3141 | Stop(); |
| 3142 | |
| 3143 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3144 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 3145 | } |
| 3146 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3147 | void WebContentsImpl::SaveFrame(const GURL& url, |
| 3148 | const Referrer& referrer) { |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3149 | SaveFrameWithHeaders(url, referrer, std::string()); |
| 3150 | } |
| 3151 | |
| 3152 | void WebContentsImpl::SaveFrameWithHeaders(const GURL& url, |
| 3153 | const Referrer& referrer, |
| 3154 | const std::string& headers) { |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3155 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3156 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 3157 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 3158 | return; |
| 3159 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3160 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3161 | // by explicitly passing in which frame this method should target. This would |
| 3162 | // indicate whether it's the main frame, and also tell us the frame pointer |
| 3163 | // to use for routing. |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 3164 | bool is_main_frame = (url == GetLastCommittedURL()); |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3165 | RenderFrameHost* frame_host = GetMainFrame(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3166 | |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3167 | StoragePartition* storage_partition = BrowserContext::GetStoragePartition( |
| 3168 | GetBrowserContext(), frame_host->GetSiteInstance()); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3169 | DownloadManager* dlm = |
| 3170 | BrowserContext::GetDownloadManager(GetBrowserContext()); |
| 3171 | if (!dlm) |
| 3172 | return; |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 3173 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3174 | if (is_main_frame) { |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3175 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3176 | if (entry) |
| 3177 | post_id = entry->GetPostID(); |
| 3178 | } |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 3179 | std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters( |
| 3180 | url, frame_host->GetProcess()->GetID(), |
| 3181 | frame_host->GetRenderViewHost()->GetRoutingID(), |
| 3182 | frame_host->GetRoutingID(), storage_partition->GetURLRequestContext())); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3183 | params->set_referrer(referrer); |
| 3184 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3185 | if (post_id >= 0) |
| 3186 | params->set_method("POST"); |
| 3187 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3188 | |
| 3189 | if (headers.empty()) { |
| 3190 | params->set_prefer_cache(true); |
| 3191 | } else { |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 3192 | for (const base::StringPiece& key_value : |
| 3193 | base::SplitStringPiece( |
| 3194 | headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 3195 | std::vector<std::string> pair = base::SplitString( |
| 3196 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 3197 | DCHECK_EQ(2ul, pair.size()); |
| 3198 | params->add_request_header(pair[0], pair[1]); |
| 3199 | } |
| 3200 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 3201 | dlm->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 3202 | } |
| 3203 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3204 | void WebContentsImpl::GenerateMHTML( |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 3205 | const MHTMLGenerationParams& params, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 3206 | const base::Callback<void(int64_t)>& callback) { |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 3207 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 3208 | } |
| 3209 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3210 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3211 | return contents_mime_type_; |
| 3212 | } |
| 3213 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3214 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3215 | return notify_disconnection_; |
| 3216 | } |
| 3217 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3218 | RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3219 | return &renderer_preferences_; |
| 3220 | } |
| 3221 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 3222 | void WebContentsImpl::Close() { |
| 3223 | Close(GetRenderViewHost()); |
| 3224 | } |
| 3225 | |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 3226 | void WebContentsImpl::DragSourceEndedAt(int client_x, |
| 3227 | int client_y, |
| 3228 | int screen_x, |
| 3229 | int screen_y, |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3230 | blink::WebDragOperation operation, |
| 3231 | RenderWidgetHost* source_rwh) { |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3232 | if (browser_plugin_embedder_.get()) |
paulmeyer | 8fc8ea9 | 2016-11-15 05:12:21 | [diff] [blame] | 3233 | browser_plugin_embedder_->DragSourceEndedAt( |
| 3234 | client_x, client_y, screen_x, screen_y, operation); |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3235 | if (source_rwh) { |
| 3236 | source_rwh->DragSourceEndedAt(gfx::Point(client_x, client_y), |
| 3237 | gfx::Point(screen_x, screen_y), |
| 3238 | operation); |
| 3239 | } |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3240 | } |
| 3241 | |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 3242 | void WebContentsImpl::LoadStateChanged( |
| 3243 | const GURL& url, |
| 3244 | const net::LoadStateWithParam& load_state, |
| 3245 | uint64_t upload_position, |
| 3246 | uint64_t upload_size) { |
| 3247 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 3248 | // is fixed. |
| 3249 | tracked_objects::ScopedTracker tracking_profile1( |
| 3250 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 3251 | "466285 WebContentsImpl::LoadStateChanged::Start")); |
| 3252 | load_state_ = load_state; |
| 3253 | upload_position_ = upload_position; |
| 3254 | upload_size_ = upload_size; |
| 3255 | load_state_host_ = url_formatter::IDNToUnicode(url.host()); |
| 3256 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
| 3257 | SetNotWaitingForResponse(); |
| 3258 | if (IsLoading()) { |
| 3259 | NotifyNavigationStateChanged(static_cast<InvalidateTypes>( |
| 3260 | INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB)); |
| 3261 | } |
| 3262 | } |
| 3263 | |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 3264 | void WebContentsImpl::DidGetResourceResponseStart( |
| 3265 | const ResourceRequestDetails& details) { |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 3266 | controller_.ssl_manager()->DidStartResourceResponse( |
| 3267 | details.url, details.has_certificate, details.ssl_cert_status); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 3268 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3269 | for (auto& observer : observers_) |
| 3270 | observer.DidGetResourceResponseStart(details); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 3271 | } |
| 3272 | |
| 3273 | void WebContentsImpl::DidGetRedirectForResourceRequest( |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 3274 | const ResourceRedirectDetails& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3275 | for (auto& observer : observers_) |
| 3276 | observer.DidGetRedirectForResourceRequest(details); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 3277 | |
| 3278 | // TODO(avi): Remove. http://crbug.com/170921 |
| 3279 | NotificationService::current()->Notify( |
| 3280 | NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 3281 | Source<WebContents>(this), |
| 3282 | Details<const ResourceRedirectDetails>(&details)); |
| 3283 | } |
| 3284 | |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 3285 | void WebContentsImpl::NotifyWebContentsFocused() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3286 | for (auto& observer : observers_) |
| 3287 | observer.OnWebContentsFocused(); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 3288 | } |
| 3289 | |
Paul Meyer | 0c58c371 | 2016-11-17 22:59:51 | [diff] [blame] | 3290 | void WebContentsImpl::SystemDragEnded(RenderWidgetHost* source_rwh) { |
| 3291 | if (source_rwh) |
| 3292 | source_rwh->DragSourceSystemDragEnded(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 3293 | if (browser_plugin_embedder_.get()) |
| 3294 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 3295 | } |
| 3296 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 3297 | void WebContentsImpl::UserGestureDone() { |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 3298 | OnUserInteraction(GetRenderViewHost()->GetWidget(), |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 3299 | blink::WebInputEvent::kUndefined); |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 3300 | } |
| 3301 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3302 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3303 | closed_by_user_gesture_ = value; |
| 3304 | } |
| 3305 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3306 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3307 | return closed_by_user_gesture_; |
| 3308 | } |
| 3309 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3310 | void WebContentsImpl::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3311 | if (!delegate_) |
| 3312 | return; |
| 3313 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3314 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 3315 | if (!entry) |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3316 | return; |
| 3317 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3318 | delegate_->ViewSourceForTab(this, entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3319 | } |
| 3320 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3321 | void WebContentsImpl::ViewFrameSource(const GURL& url, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3322 | const PageState& page_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3323 | if (!delegate_) |
| 3324 | return; |
| 3325 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3326 | delegate_->ViewSourceForFrame(this, url, page_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3327 | } |
| 3328 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3329 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3330 | return minimum_zoom_percent_; |
| 3331 | } |
| 3332 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3333 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3334 | return maximum_zoom_percent_; |
| 3335 | } |
| 3336 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3337 | void WebContentsImpl::SetPageScale(float page_scale_factor) { |
davidsac | 996be11 | 2016-11-30 08:56:38 | [diff] [blame] | 3338 | Send(new ViewMsg_SetPageScale(GetRenderViewHost()->GetRoutingID(), |
| 3339 | page_scale_factor)); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 3340 | } |
| 3341 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3342 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3343 | return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 3344 | } |
| 3345 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3346 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3347 | if (!GuestMode::IsCrossProcessFrameGuest(GetWebContents()) && |
| 3348 | GetBrowserPluginGuest()) |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 3349 | return GetBrowserPluginGuest()->LockMouse(allowed); |
| 3350 | |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3351 | if (mouse_lock_widget_) { |
| 3352 | if (mouse_lock_widget_->delegate()->GetAsWebContents() != this) { |
| 3353 | return mouse_lock_widget_->delegate() |
| 3354 | ->GetAsWebContents() |
| 3355 | ->GotResponseToLockMouseRequest(allowed); |
| 3356 | } |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3357 | |
lfg | f0cd46e | 2017-01-04 00:05:23 | [diff] [blame] | 3358 | if (mouse_lock_widget_->GotResponseToLockMouseRequest(allowed)) |
| 3359 | return true; |
| 3360 | } |
| 3361 | |
| 3362 | for (WebContentsImpl* current = this; current; |
| 3363 | current = current->GetOuterWebContents()) { |
| 3364 | current->mouse_lock_widget_ = nullptr; |
| 3365 | } |
| 3366 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3367 | return false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3368 | } |
| 3369 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3370 | bool WebContentsImpl::HasOpener() const { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 3371 | return GetOpener() != NULL; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 3372 | } |
| 3373 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 3374 | WebContentsImpl* WebContentsImpl::GetOpener() const { |
| 3375 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
| 3376 | return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 3377 | } |
| 3378 | |
jochen | 6004a36 | 2017-02-04 00:11:40 | [diff] [blame] | 3379 | bool WebContentsImpl::HasOriginalOpener() const { |
| 3380 | return GetOriginalOpener() != NULL; |
| 3381 | } |
| 3382 | |
| 3383 | WebContents* WebContentsImpl::GetOriginalOpener() const { |
| 3384 | FrameTreeNode* opener_ftn = frame_tree_.root()->original_opener(); |
| 3385 | return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; |
| 3386 | } |
| 3387 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3388 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3389 | if (!color_chooser_info_.get()) |
| 3390 | return; |
| 3391 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 3392 | color_chooser_info_->render_process_id, |
| 3393 | color_chooser_info_->render_frame_id); |
| 3394 | if (!rfh) |
| 3395 | return; |
| 3396 | |
| 3397 | rfh->Send(new FrameMsg_DidChooseColorResponse( |
| 3398 | rfh->GetRoutingID(), color_chooser_info_->identifier, color)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3399 | } |
| 3400 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3401 | void WebContentsImpl::DidEndColorChooser() { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3402 | if (!color_chooser_info_.get()) |
| 3403 | return; |
| 3404 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 3405 | color_chooser_info_->render_process_id, |
| 3406 | color_chooser_info_->render_frame_id); |
| 3407 | if (!rfh) |
| 3408 | return; |
| 3409 | |
| 3410 | rfh->Send(new FrameMsg_DidEndColorChooser( |
| 3411 | rfh->GetRoutingID(), color_chooser_info_->identifier)); |
| 3412 | color_chooser_info_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3413 | } |
| 3414 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3415 | int WebContentsImpl::DownloadImage( |
| 3416 | const GURL& url, |
| 3417 | bool is_favicon, |
| 3418 | uint32_t max_bitmap_size, |
| 3419 | bool bypass_cache, |
| 3420 | const WebContents::ImageDownloadCallback& callback) { |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3421 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3422 | static int next_image_download_id = 0; |
leon.han | 6e9dee2 | 2016-02-25 03:44:06 | [diff] [blame] | 3423 | const content::mojom::ImageDownloaderPtr& mojo_image_downloader = |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3424 | GetMainFrame()->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3425 | const int download_id = ++next_image_download_id; |
| 3426 | if (!mojo_image_downloader) { |
| 3427 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 3428 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
| 3429 | // hang the callback indefinetly since the IPC would be dropped. Now, |
| 3430 | // respond with a 400 HTTP error code to indicate that something went wrong. |
| 3431 | BrowserThread::PostTask( |
| 3432 | BrowserThread::UI, FROM_HERE, |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 3433 | base::Bind(&WebContentsImpl::OnDidDownloadImage, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 3434 | weak_factory_.GetWeakPtr(), callback, download_id, url, 400, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 3435 | std::vector<SkBitmap>(), std::vector<gfx::Size>())); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3436 | return download_id; |
| 3437 | } |
| 3438 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3439 | mojo_image_downloader->DownloadImage( |
sammc | f6f4fcf | 2016-06-21 05:39:39 | [diff] [blame] | 3440 | url, is_favicon, max_bitmap_size, bypass_cache, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 3441 | base::Bind(&WebContentsImpl::OnDidDownloadImage, |
| 3442 | weak_factory_.GetWeakPtr(), callback, download_id, url)); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3443 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3444 | } |
| 3445 | |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 3446 | bool WebContentsImpl::IsSubframe() const { |
| 3447 | return is_subframe_; |
| 3448 | } |
| 3449 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3450 | void WebContentsImpl::Find(int request_id, |
| 3451 | const base::string16& search_text, |
| 3452 | const blink::WebFindOptions& options) { |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 3453 | // Cowardly refuse to search for no text. |
| 3454 | if (search_text.empty()) { |
| 3455 | NOTREACHED(); |
| 3456 | return; |
| 3457 | } |
| 3458 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3459 | GetOrCreateFindRequestManager()->Find(request_id, search_text, options); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3460 | } |
| 3461 | |
| 3462 | void WebContentsImpl::StopFinding(StopFindAction action) { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 3463 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 3464 | manager->StopFinding(action); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3465 | } |
| 3466 | |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 3467 | bool WebContentsImpl::WasRecentlyAudible() { |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 3468 | return audio_stream_monitor_.WasRecentlyAudible() || |
| 3469 | (browser_plugin_embedder_ && |
| 3470 | browser_plugin_embedder_->WereAnyGuestsRecentlyAudible()); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 3471 | } |
| 3472 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 3473 | void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { |
| 3474 | manifest_manager_host_->GetManifest(GetMainFrame(), callback); |
| 3475 | } |
| 3476 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3477 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3478 | // Clean up related state and initiate the fullscreen exit. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 3479 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3480 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3481 | } |
| 3482 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3483 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3484 | if (delayed_open_url_params_.get()) { |
| 3485 | OpenURL(*delayed_open_url_params_.get()); |
| 3486 | delayed_open_url_params_.reset(nullptr); |
| 3487 | return; |
| 3488 | } |
| 3489 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3490 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 3491 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 3492 | if (is_resume_pending_) { |
| 3493 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 3494 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 3495 | GetMainFrame()->Init(); |
| 3496 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3497 | } |
| 3498 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3499 | bool WebContentsImpl::FocusLocationBarByDefault() { |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 3500 | // When the browser is started with about:blank as the startup URL, focus |
| 3501 | // the location bar (which will also select its contents) so people can |
| 3502 | // simply begin typing to navigate elsewhere. |
| 3503 | // |
| 3504 | // We need to be careful not to trigger this for anything other than the |
| 3505 | // startup navigation. In particular, if we allow an attacker to open a |
| 3506 | // popup to about:blank, then navigate, focusing the Omnibox will cause the |
| 3507 | // end of the new URL to be scrolled into view instead of the start, |
| 3508 | // allowing the attacker to spoof other URLs. The conditions checked here |
| 3509 | // are all aimed at ensuring no such attacker-controlled navigation can |
| 3510 | // trigger this. |
| 3511 | // |
| 3512 | // Note that we check the pending entry instead of the visible one; for the |
| 3513 | // startup URL case these are the same, but for the attacker-controlled |
| 3514 | // navigation case the visible entry is the committed "about:blank" URL and |
| 3515 | // the pending entry is the problematic navigation elsewhere. |
| 3516 | NavigationEntryImpl* entry = controller_.GetPendingEntry(); |
| 3517 | if (controller_.IsInitialNavigation() && entry && |
| 3518 | !entry->is_renderer_initiated() && |
csharrison | a3bd0b3 | 2016-10-19 18:40:48 | [diff] [blame] | 3519 | entry->GetURL() == url::kAboutBlankURL) { |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 3520 | return true; |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 3521 | } |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 3522 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3523 | } |
| 3524 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3525 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3526 | if (delegate_) |
| 3527 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 3528 | } |
| 3529 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3530 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3531 | for (auto& observer : observers_) |
| 3532 | observer.DidStartNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3533 | } |
| 3534 | |
| 3535 | void WebContentsImpl::DidRedirectNavigation( |
| 3536 | NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3537 | for (auto& observer : observers_) |
| 3538 | observer.DidRedirectNavigation(navigation_handle); |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 3539 | |
| 3540 | // Notify accessibility if this is a reload. This has to called on the |
| 3541 | // BrowserAccessibilityManager associated with the old RFHI. |
| 3542 | if (navigation_handle->GetReloadType() != ReloadType::NONE) { |
| 3543 | NavigationHandleImpl* nhi = |
| 3544 | static_cast<NavigationHandleImpl*>(navigation_handle); |
| 3545 | BrowserAccessibilityManager* manager = |
| 3546 | nhi->frame_tree_node() |
| 3547 | ->current_frame_host() |
| 3548 | ->browser_accessibility_manager(); |
| 3549 | if (manager) |
| 3550 | manager->UserIsReloading(); |
| 3551 | } |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3552 | } |
| 3553 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 3554 | void WebContentsImpl::ReadyToCommitNavigation( |
| 3555 | NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3556 | for (auto& observer : observers_) |
| 3557 | observer.ReadyToCommitNavigation(navigation_handle); |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 3558 | } |
| 3559 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3560 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3561 | for (auto& observer : observers_) |
| 3562 | observer.DidFinishNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3563 | |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 3564 | if (navigation_handle->HasCommitted()) { |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3565 | BrowserAccessibilityManager* manager = |
jam | 5f358e5 | 2017-02-13 16:37:03 | [diff] [blame] | 3566 | static_cast<RenderFrameHostImpl*>( |
| 3567 | navigation_handle->GetRenderFrameHost()) |
| 3568 | ->browser_accessibility_manager(); |
| 3569 | if (manager) { |
| 3570 | if (navigation_handle->IsErrorPage()) { |
| 3571 | manager->NavigationFailed(); |
| 3572 | } else { |
| 3573 | manager->NavigationSucceeded(); |
| 3574 | } |
| 3575 | } |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3576 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3577 | } |
| 3578 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3579 | void WebContentsImpl::DidFailLoadWithError( |
| 3580 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3581 | const GURL& url, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3582 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 3583 | const base::string16& error_description, |
| 3584 | bool was_ignored_by_handler) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3585 | for (auto& observer : observers_) { |
| 3586 | observer.DidFailLoad(render_frame_host, url, error_code, error_description, |
| 3587 | was_ignored_by_handler); |
| 3588 | } |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3589 | } |
| 3590 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 3591 | void WebContentsImpl::NotifyChangedNavigationState( |
| 3592 | InvalidateTypes changed_flags) { |
| 3593 | NotifyNavigationStateChanged(changed_flags); |
| 3594 | } |
| 3595 | |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 3596 | void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url, |
| 3597 | ReloadType reload_type) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3598 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3599 | for (auto& observer : observers_) |
| 3600 | observer.DidStartNavigationToPendingEntry(url, reload_type); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3601 | } |
| 3602 | |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 3603 | bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) { |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 3604 | if (!delegate_) |
| 3605 | return true; |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 3606 | return delegate_->ShouldTransferNavigation(is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 3607 | } |
| 3608 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3609 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
| 3610 | if (!delegate_) |
| 3611 | return false; |
| 3612 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 3613 | } |
| 3614 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3615 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3616 | bool navigation_is_within_page) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3617 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 3618 | // different page. The next page will not start out assuming it is in |
| 3619 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3620 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 3621 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3622 | return; |
| 3623 | } |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 3624 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3625 | ExitFullscreen(false); |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 3626 | DCHECK(!IsFullscreenForCurrentTab()); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3627 | } |
| 3628 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3629 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3630 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3631 | const LoadCommittedDetails& details, |
| 3632 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 3633 | if (details.is_navigation_to_different_page()) { |
| 3634 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 3635 | // doesn't let us know that the cursor left an element during a |
| 3636 | // transition (this is also why the mouse cursor remains as a hand after |
| 3637 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 3638 | // clear the bubble when a user navigates to a named anchor in the same |
| 3639 | // page. |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3640 | UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL()); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 3641 | |
| 3642 | RenderWidgetHostViewBase* rwhvb = |
| 3643 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3644 | if (rwhvb) |
| 3645 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3646 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3647 | did_first_visually_non_empty_paint_ = false; |
| 3648 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3649 | // Reset theme color on navigation to new page. |
| 3650 | theme_color_ = SK_ColorTRANSPARENT; |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3651 | } |
| 3652 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3653 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3654 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3655 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3656 | } |
| 3657 | |
| 3658 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 3659 | RenderFrameHostImpl* render_frame_host, |
| 3660 | const LoadCommittedDetails& details, |
| 3661 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 3662 | // Now that something has committed, we don't need to track whether the |
| 3663 | // initial page has been accessed. |
| 3664 | has_accessed_initial_document_ = false; |
| 3665 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3666 | // If we navigate off the page, close all JavaScript dialogs. |
eugenebut | ee08663a | 2017-04-27 17:43:12 | [diff] [blame] | 3667 | if (!details.is_same_document) |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 3668 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3669 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 3670 | // If this is a user-initiated navigation, start allowing JavaScript dialogs |
| 3671 | // again. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 3672 | if (params.gesture == NavigationGestureUser && dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 3673 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 3674 | } |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3675 | } |
| 3676 | |
| 3677 | void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { |
| 3678 | contents_mime_type_ = mime_type; |
| 3679 | } |
| 3680 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 3681 | bool WebContentsImpl::CanOverscrollContent() const { |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3682 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 3683 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3684 | return false; |
| 3685 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3686 | if (delegate_) |
| 3687 | return delegate_->CanOverscrollContent(); |
| 3688 | |
| 3689 | return false; |
| 3690 | } |
| 3691 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3692 | void WebContentsImpl::OnThemeColorChanged(RenderFrameHostImpl* source, |
| 3693 | SkColor theme_color) { |
| 3694 | if (source != GetMainFrame()) { |
| 3695 | // Only the main frame may control the theme. |
| 3696 | return; |
| 3697 | } |
| 3698 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3699 | // Update the theme color. This is to be published to observers after the |
| 3700 | // first visually non-empty paint. |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3701 | theme_color_ = theme_color; |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3702 | |
| 3703 | if (did_first_visually_non_empty_paint_ && |
| 3704 | last_sent_theme_color_ != theme_color_) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3705 | for (auto& observer : observers_) |
| 3706 | observer.DidChangeThemeColor(theme_color_); |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3707 | last_sent_theme_color_ = theme_color_; |
| 3708 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 3709 | } |
| 3710 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3711 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3712 | RenderFrameHostImpl* source, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3713 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3714 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 3715 | const std::string& mime_type, |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 3716 | ResourceType resource_type) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3717 | for (auto& observer : observers_) |
| 3718 | observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type); |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 3719 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3720 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3721 | StoragePartition* partition = source->GetProcess()->GetStoragePartition(); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3722 | scoped_refptr<net::URLRequestContextGetter> request_context( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3723 | resource_type == RESOURCE_TYPE_MEDIA |
| 3724 | ? partition->GetMediaURLRequestContext() |
| 3725 | : partition->GetURLRequestContext()); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3726 | BrowserThread::PostTask( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3727 | BrowserThread::IO, FROM_HERE, |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3728 | base::Bind(&NotifyCacheOnIO, request_context, url, http_method)); |
| 3729 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3730 | } |
| 3731 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3732 | void WebContentsImpl::OnDidDisplayInsecureContent(RenderFrameHostImpl* source) { |
| 3733 | // Any frame can trigger display of insecure content, so we don't check |
| 3734 | // |source| here. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 3735 | DidDisplayInsecureContent(); |
| 3736 | } |
| 3737 | |
| 3738 | void WebContentsImpl::DidDisplayInsecureContent() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3739 | controller_.ssl_manager()->DidDisplayMixedContent(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3740 | } |
| 3741 | |
elawrence | b2ac2a23 | 2017-03-27 21:46:25 | [diff] [blame] | 3742 | void WebContentsImpl::OnDidContainInsecureFormAction( |
| 3743 | RenderFrameHostImpl* source) { |
| 3744 | controller_.ssl_manager()->DidContainInsecureFormAction(); |
| 3745 | } |
| 3746 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3747 | void WebContentsImpl::OnDidRunInsecureContent(RenderFrameHostImpl* source, |
| 3748 | const GURL& security_origin, |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3749 | const GURL& target_url) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3750 | // TODO(nick, estark): Should we call FilterURL using |source|'s process on |
| 3751 | // these parameters? |target_url| seems unused, except for a log message. And |
| 3752 | // |security_origin| might be replaceable with the origin of the main frame. |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 3753 | DidRunInsecureContent(security_origin, target_url); |
| 3754 | } |
| 3755 | |
| 3756 | void WebContentsImpl::DidRunInsecureContent(const GURL& security_origin, |
| 3757 | const GURL& target_url) { |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 3758 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 3759 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3760 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3761 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 3762 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3763 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3764 | controller_.ssl_manager()->DidRunMixedContent(security_origin); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3765 | } |
| 3766 | |
carlosk | d9d9794 | 2017-02-16 08:58:09 | [diff] [blame] | 3767 | void WebContentsImpl::PassiveInsecureContentFound(const GURL& resource_url) { |
| 3768 | GetDelegate()->PassiveInsecureContentFound(resource_url); |
| 3769 | } |
| 3770 | |
| 3771 | bool WebContentsImpl::ShouldAllowRunningInsecureContent( |
| 3772 | WebContents* web_contents, |
| 3773 | bool allowed_per_prefs, |
| 3774 | const url::Origin& origin, |
| 3775 | const GURL& resource_url) { |
| 3776 | return GetDelegate()->ShouldAllowRunningInsecureContent( |
| 3777 | web_contents, allowed_per_prefs, origin, resource_url); |
| 3778 | } |
| 3779 | |
rob.buis | 300b087 | 2017-03-10 20:43:58 | [diff] [blame] | 3780 | #if defined(OS_ANDROID) |
| 3781 | base::android::ScopedJavaLocalRef<jobject> |
| 3782 | WebContentsImpl::GetJavaRenderFrameHostDelegate() { |
| 3783 | return GetJavaWebContents(); |
| 3784 | } |
| 3785 | #endif |
| 3786 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3787 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3788 | RenderFrameHostImpl* source, |
jam | a385e11 | 2016-07-22 00:07:58 | [diff] [blame] | 3789 | const GURL& url) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3790 | // TODO(nick): |url| is unused; get rid of it. |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3791 | controller_.ssl_manager()->DidDisplayContentWithCertErrors(); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3792 | } |
| 3793 | |
| 3794 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3795 | RenderFrameHostImpl* source, |
jam | a385e11 | 2016-07-22 00:07:58 | [diff] [blame] | 3796 | const GURL& url) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3797 | // TODO(nick, estark): Do we need to consider |source| here somehow? |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 3798 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 3799 | if (!entry) |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 3800 | return; |
| 3801 | |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 3802 | // TODO(estark): check that this does something reasonable for |
| 3803 | // about:blank and sandboxed origins. https://crbug.com/609527 |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 3804 | controller_.ssl_manager()->DidRunContentWithCertErrors( |
| 3805 | entry->GetURL().GetOrigin()); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3806 | } |
| 3807 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3808 | void WebContentsImpl::OnDocumentLoadedInFrame(RenderFrameHostImpl* source) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3809 | for (auto& observer : observers_) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3810 | observer.DocumentLoadedInFrame(source); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3811 | } |
| 3812 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3813 | void WebContentsImpl::OnDidFinishLoad(RenderFrameHostImpl* source, |
| 3814 | const GURL& url) { |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 3815 | GURL validated_url(url); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3816 | source->GetProcess()->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 3817 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3818 | for (auto& observer : observers_) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3819 | observer.DidFinishLoad(source, validated_url); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3820 | } |
| 3821 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3822 | void WebContentsImpl::OnGoToEntryAtOffset(RenderViewHostImpl* source, |
| 3823 | int offset) { |
| 3824 | // All frames are allowed to navigate the global history. |
avi | 6ddfcae | 2015-06-30 15:50:57 | [diff] [blame] | 3825 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
| 3826 | controller_.GoToOffset(offset); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3827 | } |
| 3828 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3829 | void WebContentsImpl::OnUpdateZoomLimits(RenderViewHostImpl* source, |
| 3830 | int minimum_percent, |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 3831 | int maximum_percent) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3832 | minimum_zoom_percent_ = minimum_percent; |
| 3833 | maximum_zoom_percent_ = maximum_percent; |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3834 | } |
| 3835 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3836 | void WebContentsImpl::OnPageScaleFactorChanged(RenderViewHostImpl* source, |
| 3837 | float page_scale_factor) { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3838 | bool is_one = page_scale_factor == 1.f; |
| 3839 | if (is_one != page_scale_factor_is_one_) { |
| 3840 | page_scale_factor_is_one_ = is_one; |
| 3841 | |
| 3842 | HostZoomMapImpl* host_zoom_map = |
| 3843 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 3844 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3845 | if (host_zoom_map) { |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3846 | host_zoom_map->SetPageScaleFactorIsOneForView( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3847 | source->GetProcess()->GetID(), source->GetRoutingID(), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3848 | page_scale_factor_is_one_); |
| 3849 | } |
| 3850 | } |
| 3851 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3852 | for (auto& observer : observers_) |
| 3853 | observer.OnPageScaleFactorChanged(page_scale_factor); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3854 | } |
| 3855 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3856 | void WebContentsImpl::OnEnumerateDirectory(RenderViewHostImpl* source, |
| 3857 | int request_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3858 | const base::FilePath& path) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3859 | if (!delegate_) |
| 3860 | return; |
| 3861 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3862 | ChildProcessSecurityPolicyImpl* policy = |
| 3863 | ChildProcessSecurityPolicyImpl::GetInstance(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3864 | if (policy->CanReadFile(source->GetProcess()->GetID(), path)) { |
| 3865 | // TODO(nick): |this| param in the call below ought to be a RenderFrameHost. |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3866 | delegate_->EnumerateDirectory(this, request_id, path); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3867 | } |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3868 | } |
| 3869 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3870 | void WebContentsImpl::OnRegisterProtocolHandler(RenderFrameHostImpl* source, |
| 3871 | const std::string& protocol, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3872 | const GURL& url, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3873 | const base::string16& title, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 3874 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3875 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
| 3876 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3877 | if (!delegate_) |
| 3878 | return; |
| 3879 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3880 | ChildProcessSecurityPolicyImpl* policy = |
| 3881 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3882 | if (policy->IsPseudoScheme(protocol)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3883 | return; |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3884 | |
[email protected] | c125e53 | 2014-05-10 20:39:06 | [diff] [blame] | 3885 | delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3886 | } |
| 3887 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3888 | void WebContentsImpl::OnUnregisterProtocolHandler(RenderFrameHostImpl* source, |
| 3889 | const std::string& protocol, |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 3890 | const GURL& url, |
| 3891 | bool user_gesture) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3892 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
| 3893 | // TODO(nick): Do we need to apply FilterURL to |url|? |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 3894 | if (!delegate_) |
| 3895 | return; |
| 3896 | |
| 3897 | ChildProcessSecurityPolicyImpl* policy = |
| 3898 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 3899 | if (policy->IsPseudoScheme(protocol)) |
| 3900 | return; |
| 3901 | |
| 3902 | delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture); |
| 3903 | } |
| 3904 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 3905 | void WebContentsImpl::OnUpdatePageImportanceSignals( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3906 | RenderFrameHostImpl* source, |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 3907 | const PageImportanceSignals& signals) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3908 | // TODO(nick, kouhei): Fix this for oopifs; currently all frames' state gets |
| 3909 | // written to this one field. |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 3910 | page_importance_signals_ = signals; |
| 3911 | } |
| 3912 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3913 | void WebContentsImpl::OnFindReply(RenderFrameHostImpl* source, |
| 3914 | int request_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3915 | int number_of_matches, |
| 3916 | const gfx::Rect& selection_rect, |
| 3917 | int active_match_ordinal, |
| 3918 | bool final_update) { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 3919 | if (active_match_ordinal > 0) |
| 3920 | SetFocusedFrame(source->frame_tree_node(), source->GetSiteInstance()); |
| 3921 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3922 | // Forward the find reply to the FindRequestManager, along with the |
| 3923 | // RenderFrameHost associated with the frame that the reply came from. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3924 | GetOrCreateFindRequestManager()->OnFindReply( |
| 3925 | source, request_id, number_of_matches, selection_rect, |
| 3926 | active_match_ordinal, final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3927 | } |
| 3928 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 3929 | #if defined(OS_ANDROID) |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3930 | void WebContentsImpl::OnFindMatchRectsReply( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3931 | RenderFrameHostImpl* source, |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3932 | int version, |
| 3933 | const std::vector<gfx::RectF>& rects, |
| 3934 | const gfx::RectF& active_rect) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3935 | GetOrCreateFindRequestManager()->OnFindMatchRectsReply(source, version, rects, |
| 3936 | active_rect); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3937 | } |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3938 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3939 | void WebContentsImpl::OnGetNearestFindResultReply(RenderFrameHostImpl* source, |
| 3940 | int request_id, |
paulmeyer | c8cb7cb | 2016-06-07 01:14:19 | [diff] [blame] | 3941 | float distance) { |
| 3942 | GetOrCreateFindRequestManager()->OnGetNearestFindResultReply( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3943 | source, request_id, distance); |
paulmeyer | c8cb7cb | 2016-06-07 01:14:19 | [diff] [blame] | 3944 | } |
| 3945 | |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 3946 | void WebContentsImpl::OnOpenDateTimeDialog( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3947 | RenderViewHostImpl* source, |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 3948 | const ViewHostMsg_DateTimeDialogValue_Params& value) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3949 | date_time_chooser_->ShowDialog( |
| 3950 | GetTopLevelNativeWindow(), source, value.dialog_type, value.dialog_value, |
| 3951 | value.minimum, value.maximum, value.step, value.suggestions); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3952 | } |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3953 | #endif |
| 3954 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3955 | void WebContentsImpl::OnDomOperationResponse(RenderFrameHostImpl* source, |
| 3956 | const std::string& json_string) { |
| 3957 | // TODO(nick, lukasza): The notification below should probably be updated to |
| 3958 | // include |source|. |
avi | 60bd490 | 2015-09-23 20:39:24 | [diff] [blame] | 3959 | std::string json = json_string; |
| 3960 | NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 3961 | Source<WebContents>(this), |
| 3962 | Details<std::string>(&json)); |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 3963 | } |
| 3964 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3965 | void WebContentsImpl::OnAppCacheAccessed(RenderViewHostImpl* source, |
| 3966 | const GURL& manifest_url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3967 | bool blocked_by_policy) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3968 | // TODO(nick): Should we consider |source| here? Should we call FilterURL on |
| 3969 | // |manifest_url|? |
| 3970 | |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3971 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3972 | for (auto& observer : observers_) |
| 3973 | observer.AppCacheAccessed(manifest_url, blocked_by_policy); |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3974 | } |
| 3975 | |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 3976 | void WebContentsImpl::OnOpenColorChooser( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3977 | RenderFrameHostImpl* source, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3978 | int color_chooser_id, |
| 3979 | SkColor color, |
| 3980 | const std::vector<ColorSuggestion>& suggestions) { |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3981 | ColorChooser* new_color_chooser = delegate_ ? |
| 3982 | delegate_->OpenColorChooser(this, color, suggestions) : |
| 3983 | NULL; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 3984 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3985 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3986 | if (color_chooser_info_.get()) |
| 3987 | color_chooser_info_->chooser->End(); |
| 3988 | |
| 3989 | color_chooser_info_.reset(new ColorChooserInfo( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3990 | source->GetProcess()->GetID(), source->GetRoutingID(), new_color_chooser, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3991 | color_chooser_id)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3992 | } |
| 3993 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3994 | void WebContentsImpl::OnEndColorChooser(RenderFrameHostImpl* source, |
| 3995 | int color_chooser_id) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3996 | if (color_chooser_info_ && |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 3997 | color_chooser_info_->Matches(source, color_chooser_id)) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3998 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3999 | } |
| 4000 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4001 | void WebContentsImpl::OnSetSelectedColorInColorChooser( |
| 4002 | RenderFrameHostImpl* source, |
| 4003 | int color_chooser_id, |
| 4004 | SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 4005 | if (color_chooser_info_ && |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4006 | color_chooser_info_->Matches(source, color_chooser_id)) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 4007 | color_chooser_info_->chooser->SetSelectedColor(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 4008 | } |
| 4009 | |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 4010 | // This exists for render views that don't have a WebUI, but do have WebUI |
| 4011 | // bindings enabled. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4012 | void WebContentsImpl::OnWebUISend(RenderViewHostImpl* source, |
| 4013 | const GURL& source_url, |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 4014 | const std::string& name, |
| 4015 | const base::ListValue& args) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4016 | // TODO(nick): Should we consider |source| here or pass it to the delegate? |
| 4017 | // TODO(nick): Should FilterURL be applied to |source_url|? |
| 4018 | // TODO(nick): This IPC should be ported to FrameHostMsg_, and |source_url| |
| 4019 | // should be eliminated (use last_committed_url() on the RFH instead). |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 4020 | if (delegate_) |
| 4021 | delegate_->WebUISend(this, source_url, name, args); |
| 4022 | } |
| 4023 | |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4024 | #if BUILDFLAG(ENABLE_PLUGINS) |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4025 | void WebContentsImpl::OnPepperInstanceCreated(RenderFrameHostImpl* source, |
| 4026 | int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4027 | for (auto& observer : observers_) |
| 4028 | observer.PepperInstanceCreated(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4029 | pepper_playback_observer_->PepperInstanceCreated(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 4030 | } |
| 4031 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4032 | void WebContentsImpl::OnPepperInstanceDeleted(RenderFrameHostImpl* source, |
| 4033 | int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4034 | for (auto& observer : observers_) |
| 4035 | observer.PepperInstanceDeleted(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4036 | pepper_playback_observer_->PepperInstanceDeleted(source, pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 4037 | } |
| 4038 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4039 | void WebContentsImpl::OnPepperPluginHung(RenderFrameHostImpl* source, |
| 4040 | int plugin_child_id, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4041 | const base::FilePath& path, |
| 4042 | bool is_hung) { |
| 4043 | UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1); |
| 4044 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4045 | for (auto& observer : observers_) |
| 4046 | observer.PluginHungStatusChanged(plugin_child_id, path, is_hung); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4047 | } |
| 4048 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4049 | void WebContentsImpl::OnPepperStartsPlayback(RenderFrameHostImpl* source, |
| 4050 | int32_t pp_instance) { |
| 4051 | pepper_playback_observer_->PepperStartsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 4052 | } |
| 4053 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4054 | void WebContentsImpl::OnPepperStopsPlayback(RenderFrameHostImpl* source, |
| 4055 | int32_t pp_instance) { |
| 4056 | pepper_playback_observer_->PepperStopsPlayback(source, pp_instance); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 4057 | } |
| 4058 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4059 | void WebContentsImpl::OnPluginCrashed(RenderFrameHostImpl* source, |
| 4060 | const base::FilePath& plugin_path, |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4061 | base::ProcessId plugin_pid) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4062 | // TODO(nick): Eliminate the |plugin_pid| parameter, which can't be trusted, |
| 4063 | // and is only used by BlinkTestController. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4064 | for (auto& observer : observers_) |
| 4065 | observer.PluginCrashed(plugin_path, plugin_pid); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 4066 | } |
| 4067 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4068 | void WebContentsImpl::OnRequestPpapiBrokerPermission( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4069 | RenderViewHostImpl* source, |
| 4070 | int ppb_broker_route_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4071 | const GURL& url, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 4072 | const base::FilePath& plugin_path) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4073 | base::Callback<void(bool)> permission_result_callback = base::Bind( |
| 4074 | &WebContentsImpl::SendPpapiBrokerPermissionResult, base::Unretained(this), |
| 4075 | source->GetProcess()->GetID(), ppb_broker_route_id); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4076 | if (!delegate_) { |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4077 | permission_result_callback.Run(false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4078 | return; |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4079 | } |
| 4080 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4081 | if (!delegate_->RequestPpapiBrokerPermission(this, url, plugin_path, |
| 4082 | permission_result_callback)) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4083 | NOTIMPLEMENTED(); |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4084 | permission_result_callback.Run(false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 4085 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4086 | } |
| 4087 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4088 | void WebContentsImpl::SendPpapiBrokerPermissionResult(int process_id, |
| 4089 | int ppb_broker_route_id, |
| 4090 | bool result) { |
| 4091 | RenderProcessHost* rph = RenderProcessHost::FromID(process_id); |
| 4092 | if (rph) { |
| 4093 | // TODO(nick): Convert this from ViewMsg_ to a Ppapi msg, since it |
| 4094 | // is not routed to a RenderView. |
| 4095 | rph->Send( |
| 4096 | new ViewMsg_PpapiBrokerPermissionResult(ppb_broker_route_id, result)); |
| 4097 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 4098 | } |
| 4099 | |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 4100 | void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host, |
| 4101 | const IPC::Message& message) { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4102 | CHECK(!browser_plugin_embedder_.get()); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 4103 | CreateBrowserPluginEmbedderIfNecessary(); |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 4104 | browser_plugin_embedder_->OnMessageReceived(message, render_frame_host); |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 4105 | } |
brettw | 4b46108 | 2016-11-19 18:55:16 | [diff] [blame] | 4106 | #endif // BUILDFLAG(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 4107 | |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4108 | void WebContentsImpl::OnUpdateFaviconURL( |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4109 | RenderViewHostImpl* source, |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4110 | const std::vector<FaviconURL>& candidates) { |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 4111 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 4112 | // navigation occurs while a page is still loading, the initial page |
| 4113 | // may stop loading and send us updated favicon URLs after the navigation |
| 4114 | // for the new page has committed. |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4115 | if (!source->is_active()) |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 4116 | return; |
| 4117 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4118 | for (auto& observer : observers_) |
| 4119 | observer.DidUpdateFaviconURL(candidates); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 4120 | } |
| 4121 | |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 4122 | void WebContentsImpl::OnPasswordInputShownOnHttp() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 4123 | controller_.ssl_manager()->DidShowPasswordInputOnHttp(); |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 4124 | } |
| 4125 | |
estark | fae6b587 | 2016-11-04 05:20:31 | [diff] [blame] | 4126 | void WebContentsImpl::OnAllPasswordInputsHiddenOnHttp() { |
| 4127 | controller_.ssl_manager()->DidHideAllPasswordInputsOnHttp(); |
| 4128 | } |
| 4129 | |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 4130 | void WebContentsImpl::OnCreditCardInputShownOnHttp() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 4131 | controller_.ssl_manager()->DidShowCreditCardInputOnHttp(); |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 4132 | } |
| 4133 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 4134 | void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) { |
| 4135 | is_overlay_content_ = is_overlay_content; |
| 4136 | } |
| 4137 | |
nick | a0ac838 | 2016-12-15 23:59:23 | [diff] [blame] | 4138 | void WebContentsImpl::OnFirstVisuallyNonEmptyPaint(RenderViewHostImpl* source) { |
| 4139 | // TODO(nick): When this is ported to FrameHostMsg_, we should only listen if |
| 4140 | // |source| is the main frame. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4141 | for (auto& observer : observers_) |
| 4142 | observer.DidFirstVisuallyNonEmptyPaint(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4143 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 4144 | did_first_visually_non_empty_paint_ = true; |
| 4145 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4146 | if (theme_color_ != last_sent_theme_color_) { |
| 4147 | // Theme color should have updated by now if there was one. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4148 | for (auto& observer : observers_) |
| 4149 | observer.DidChangeThemeColor(theme_color_); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 4150 | last_sent_theme_color_ = theme_color_; |
| 4151 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 4152 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 4153 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 4154 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4155 | for (auto& observer : observers_) |
| 4156 | observer.BeforeFormRepostWarningShow(); |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 4157 | } |
| 4158 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 4159 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
| 4160 | Activate(); |
| 4161 | if (delegate_) |
| 4162 | delegate_->ShowRepostFormWarningDialog(this); |
| 4163 | } |
| 4164 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4165 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 4166 | return has_accessed_initial_document_; |
| 4167 | } |
| 4168 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4169 | void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4170 | const base::string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4171 | // For file URLs without a title, use the pathname instead. In the case of a |
| 4172 | // synthesized title, we don't want the update to count toward the "one set |
| 4173 | // per page of the title to history." |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4174 | base::string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4175 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4176 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 4177 | final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4178 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 4179 | } else { |
[email protected] | 8af69c6c | 2014-03-03 19:05:31 | [diff] [blame] | 4180 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4181 | explicit_set = true; |
| 4182 | } |
| 4183 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4184 | // If a page is created via window.open and never navigated, |
| 4185 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 4186 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4187 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4188 | if (final_title == entry->GetTitle()) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4189 | return; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4190 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4191 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4192 | } else { |
| 4193 | if (page_title_when_no_navigation_entry_ == final_title) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4194 | return; // Nothing changed, don't bother. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 4195 | |
| 4196 | page_title_when_no_navigation_entry_ = final_title; |
| 4197 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4198 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4199 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 4200 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4201 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4202 | for (auto& observer : observers_) |
| 4203 | observer.TitleWasSet(entry, explicit_set); |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 4204 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4205 | // Broadcast notifications when the UI should be updated. |
| 4206 | if (entry == controller_.GetEntryAtOffset(0)) |
| 4207 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4208 | } |
| 4209 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4210 | void WebContentsImpl::SendChangeLoadProgress() { |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4211 | loading_last_progress_update_ = base::TimeTicks::Now(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4212 | if (delegate_) |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4213 | delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4214 | } |
| 4215 | |
| 4216 | void WebContentsImpl::ResetLoadProgressState() { |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 4217 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4218 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 4219 | loading_last_progress_update_ = base::TimeTicks(); |
| 4220 | } |
| 4221 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4222 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 4223 | // loading, or done loading. |
| 4224 | void WebContentsImpl::LoadingStateChanged(bool to_different_document, |
| 4225 | bool due_to_interstitial, |
| 4226 | LoadNotificationDetails* details) { |
| 4227 | // Do not send notifications about loading changes in the FrameTree while the |
| 4228 | // interstitial page is pausing the throbber. |
| 4229 | if (ShowingInterstitialPage() && |
| 4230 | GetRenderManager()->interstitial_page()->pause_throbber() && |
| 4231 | !due_to_interstitial) { |
| 4232 | return; |
| 4233 | } |
| 4234 | |
| 4235 | bool is_loading = IsLoading(); |
| 4236 | |
| 4237 | if (!is_loading) { |
| 4238 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 4239 | base::string16()); |
| 4240 | load_state_host_.clear(); |
| 4241 | upload_size_ = 0; |
| 4242 | upload_position_ = 0; |
| 4243 | } |
| 4244 | |
| 4245 | GetRenderManager()->SetIsLoading(is_loading); |
| 4246 | |
| 4247 | waiting_for_response_ = is_loading; |
| 4248 | is_load_to_different_document_ = to_different_document; |
| 4249 | |
| 4250 | if (delegate_) |
| 4251 | delegate_->LoadingStateChanged(this, to_different_document); |
| 4252 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
| 4253 | |
| 4254 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
| 4255 | if (is_loading) { |
| 4256 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 4257 | this, "URL", url, "Main FrameTreeNode id", |
| 4258 | GetFrameTree()->root()->frame_tree_node_id()); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4259 | for (auto& observer : observers_) |
| 4260 | observer.DidStartLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4261 | } else { |
| 4262 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 4263 | this, "URL", url); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4264 | for (auto& observer : observers_) |
| 4265 | observer.DidStopLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4266 | } |
| 4267 | |
| 4268 | // TODO(avi): Remove. http://crbug.com/170921 |
| 4269 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 4270 | NotificationDetails det = NotificationService::NoDetails(); |
| 4271 | if (details) |
| 4272 | det = Details<LoadNotificationDetails>(details); |
| 4273 | NotificationService::current()->Notify( |
| 4274 | type, Source<NavigationController>(&controller_), det); |
| 4275 | } |
| 4276 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4277 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host, |
| 4278 | RenderViewHost* new_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4279 | // After sending out a swap notification, we need to send a disconnect |
| 4280 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 4281 | // pointer. See Bug 1230284. |
| 4282 | notify_disconnection_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4283 | for (auto& observer : observers_) |
| 4284 | observer.RenderViewHostChanged(old_host, new_host); |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4285 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4286 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 4287 | // gets swapped, so we don't reuse the same embedder next time a |
| 4288 | // RenderViewHost is attached to this WebContents. |
| 4289 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4290 | } |
| 4291 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4292 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host, |
| 4293 | RenderFrameHost* new_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4294 | for (auto& observer : observers_) |
| 4295 | observer.RenderFrameHostChanged(old_host, new_host); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4296 | } |
| 4297 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4298 | // TODO(avi): Remove this entire function because this notification is already |
| 4299 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4300 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4301 | if (!notify_disconnection_) |
| 4302 | return; |
| 4303 | |
| 4304 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4305 | NotificationService::current()->Notify( |
| 4306 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 4307 | Source<WebContents>(this), |
| 4308 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4309 | } |
| 4310 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 4311 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 4312 | const LoadCommittedDetails& load_details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4313 | for (auto& observer : observers_) |
| 4314 | observer.NavigationEntryCommitted(load_details); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 4315 | } |
| 4316 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 4317 | void WebContentsImpl::OnAssociatedInterfaceRequest( |
| 4318 | RenderFrameHost* render_frame_host, |
| 4319 | const std::string& interface_name, |
| 4320 | mojo::ScopedInterfaceEndpointHandle handle) { |
| 4321 | auto it = binding_sets_.find(interface_name); |
| 4322 | if (it != binding_sets_.end()) |
| 4323 | it->second->OnRequestForFrame(render_frame_host, std::move(handle)); |
| 4324 | } |
| 4325 | |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 4326 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
| 4327 | return GetLastCommittedURL(); |
| 4328 | } |
| 4329 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4330 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4331 | for (auto& observer : observers_) |
| 4332 | observer.RenderFrameCreated(render_frame_host); |
dmazzoni | f8a3104 | 2016-12-03 00:52:13 | [diff] [blame] | 4333 | UpdateAccessibilityModeOnFrame(render_frame_host); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 4334 | |
| 4335 | if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent()) |
| 4336 | return; |
| 4337 | |
| 4338 | NavigationEntry* entry = controller_.GetPendingEntry(); |
| 4339 | if (entry && entry->IsViewSourceMode()) { |
| 4340 | // Put the renderer in view source mode. |
| 4341 | render_frame_host->Send( |
| 4342 | new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID())); |
| 4343 | } |
sammc | 5a139ba | 2016-09-29 01:49:14 | [diff] [blame] | 4344 | #if defined(OS_ANDROID) |
| 4345 | render_frame_host->GetInterfaceRegistry()->AddInterface( |
| 4346 | GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>()); |
| 4347 | #endif |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4348 | } |
| 4349 | |
| 4350 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
creis | 363889745 | 2017-05-09 22:07:50 | [diff] [blame] | 4351 | is_notifying_observers_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4352 | for (auto& observer : observers_) |
| 4353 | observer.RenderFrameDeleted(render_frame_host); |
creis | 363889745 | 2017-05-09 22:07:50 | [diff] [blame] | 4354 | is_notifying_observers_ = false; |
zqzhang | 7b6f4f0 | 2016-12-07 22:10:22 | [diff] [blame] | 4355 | #if BUILDFLAG(ENABLE_PLUGINS) |
| 4356 | pepper_playback_observer_->RenderFrameDeleted(render_frame_host); |
| 4357 | #endif |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4358 | } |
| 4359 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4360 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 4361 | const ContextMenuParams& params) { |
avi | e9fd872 | 2017-04-10 16:17:58 | [diff] [blame] | 4362 | // If a renderer fires off a second command to show a context menu before the |
| 4363 | // first context menu is closed, just ignore it. https://crbug.com/707534 |
| 4364 | if (GetRenderWidgetHostView()->IsShowingContextMenu()) |
| 4365 | return; |
| 4366 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4367 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4368 | // Allow WebContentsDelegates to handle the context menu operation first. |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4369 | if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4370 | return; |
| 4371 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4372 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 4373 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4374 | } |
| 4375 | |
avi | 777ff45 | 2017-02-09 19:04:48 | [diff] [blame] | 4376 | void WebContentsImpl::RunJavaScriptDialog(RenderFrameHost* render_frame_host, |
| 4377 | const base::string16& message, |
| 4378 | const base::string16& default_prompt, |
| 4379 | const GURL& frame_url, |
| 4380 | JavaScriptDialogType dialog_type, |
| 4381 | IPC::Message* reply_msg) { |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4382 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 4383 | // showing an interstitial as it's shown over the previous page and we don't |
| 4384 | // want the hidden page's dialogs to interfere with the interstitial. |
| 4385 | bool suppress_this_message = |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4386 | ShowingInterstitialPage() || !delegate_ || |
| 4387 | delegate_->ShouldSuppressDialogs(this) || |
| 4388 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4389 | |
| 4390 | if (!suppress_this_message) { |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 4391 | is_showing_javascript_dialog_ = true; |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4392 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4393 | dialog_manager_->RunJavaScriptDialog( |
avi | 777ff45 | 2017-02-09 19:04:48 | [diff] [blame] | 4394 | this, frame_url, dialog_type, message, default_prompt, |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 4395 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4396 | render_frame_host->GetProcess()->GetID(), |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 4397 | render_frame_host->GetRoutingID(), reply_msg, false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4398 | &suppress_this_message); |
| 4399 | } |
| 4400 | |
| 4401 | if (suppress_this_message) { |
| 4402 | // If we are suppressing messages, just reply as if the user immediately |
| 4403 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4404 | OnDialogClosed(render_frame_host->GetProcess()->GetID(), |
| 4405 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4406 | true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4407 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4408 | } |
| 4409 | |
| 4410 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4411 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4412 | bool is_reload, |
| 4413 | IPC::Message* reply_msg) { |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4414 | RenderFrameHostImpl* rfhi = |
| 4415 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4416 | if (delegate_) |
| 4417 | delegate_->WillRunBeforeUnloadConfirm(); |
| 4418 | |
| 4419 | bool suppress_this_message = |
nasko | 19736cc9f | 2016-04-08 22:38:45 | [diff] [blame] | 4420 | !rfhi->is_active() || |
creis | 36e228b | 2015-06-08 18:48:02 | [diff] [blame] | 4421 | ShowingInterstitialPage() || !delegate_ || |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4422 | delegate_->ShouldSuppressDialogs(this) || |
| 4423 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4424 | if (suppress_this_message) { |
avi | 44acfaa8 | 2017-05-03 22:55:35 | [diff] [blame] | 4425 | rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4426 | return; |
| 4427 | } |
| 4428 | |
| 4429 | is_showing_before_unload_dialog_ = true; |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4430 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4431 | dialog_manager_->RunBeforeUnloadDialog( |
avi | 141dbc132 | 2016-03-11 22:27:42 | [diff] [blame] | 4432 | this, is_reload, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4433 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4434 | render_frame_host->GetProcess()->GetID(), |
| 4435 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4436 | false)); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4437 | } |
| 4438 | |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 4439 | void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host, |
| 4440 | const FileChooserParams& params) { |
| 4441 | if (delegate_) |
| 4442 | delegate_->RunFileChooser(render_frame_host, params); |
| 4443 | } |
| 4444 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 4445 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 4446 | return this; |
| 4447 | } |
| 4448 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 4449 | double WebContentsImpl::GetPendingPageZoomLevel() { |
| 4450 | NavigationEntry* pending_entry = GetController().GetPendingEntry(); |
| 4451 | if (!pending_entry) |
| 4452 | return HostZoomMap::GetZoomLevel(this); |
| 4453 | |
| 4454 | GURL url = pending_entry->GetURL(); |
| 4455 | return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme( |
| 4456 | url.scheme(), net::GetHostOrSpecFromURL(url)); |
| 4457 | } |
| 4458 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 4459 | bool WebContentsImpl::HideDownloadUI() const { |
| 4460 | return is_overlay_content_; |
| 4461 | } |
| 4462 | |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 4463 | bool WebContentsImpl::HasPersistentVideo() const { |
| 4464 | return has_persistent_video_; |
| 4465 | } |
| 4466 | |
mlamouri | e52c1b54 | 2017-02-23 14:57:50 | [diff] [blame] | 4467 | bool WebContentsImpl::HasActiveEffectivelyFullscreenVideo() const { |
| 4468 | return media_web_contents_observer_->HasActiveEffectivelyFullscreenVideo(); |
| 4469 | } |
| 4470 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 4471 | bool WebContentsImpl::IsFocusedElementEditable() { |
| 4472 | RenderFrameHostImpl* frame = GetFocusedFrame(); |
| 4473 | return frame && frame->has_focused_editable_element(); |
| 4474 | } |
| 4475 | |
| 4476 | void WebContentsImpl::ClearFocusedElement() { |
| 4477 | if (auto* frame = GetFocusedFrame()) |
| 4478 | frame->ClearFocusedElement(); |
| 4479 | } |
| 4480 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 4481 | bool WebContentsImpl::IsNeverVisible() { |
| 4482 | if (!delegate_) |
| 4483 | return false; |
| 4484 | return delegate_->IsNeverVisible(this); |
| 4485 | } |
| 4486 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 4487 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 4488 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4489 | } |
| 4490 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4491 | RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 4492 | BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 4493 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4494 | } |
| 4495 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4496 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 4497 | if (browser_plugin_embedder_) |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4498 | browser_plugin_embedder_.reset(); |
| 4499 | } |
| 4500 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4501 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 4502 | if (GuestMode::IsCrossProcessFrameGuest(this)) |
| 4503 | return node_.outer_web_contents(); |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4504 | |
| 4505 | if (browser_plugin_guest_) |
| 4506 | return browser_plugin_guest_->embedder_web_contents(); |
| 4507 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4508 | return nullptr; |
| 4509 | } |
| 4510 | |
| 4511 | WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 4512 | return GetOutermostWebContents()->node_.focused_web_contents(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4513 | } |
| 4514 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 4515 | bool WebContentsImpl::ContainsOrIsFocusedWebContents() { |
| 4516 | for (WebContentsImpl* focused_contents = GetFocusedWebContents(); |
| 4517 | focused_contents; |
| 4518 | focused_contents = focused_contents->GetOuterWebContents()) { |
| 4519 | if (focused_contents == this) |
| 4520 | return true; |
| 4521 | } |
| 4522 | |
| 4523 | return false; |
| 4524 | } |
| 4525 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4526 | WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { |
| 4527 | WebContentsImpl* root = this; |
| 4528 | while (root->GetOuterWebContents()) |
| 4529 | root = root->GetOuterWebContents(); |
| 4530 | return root; |
| 4531 | } |
| 4532 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4533 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4534 | // Don't send notifications if we are just creating a swapped-out RVH for |
| 4535 | // the opener chain. These won't be used for view-source or WebUI, so it's |
| 4536 | // ok to return early. |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 4537 | if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4538 | return; |
| 4539 | |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 4540 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4541 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 4542 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4543 | NotificationService::current()->Notify( |
| 4544 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 4545 | Source<WebContents>(this), |
| 4546 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4547 | |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4548 | view_->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 4549 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4550 | for (auto& observer : observers_) |
| 4551 | observer.RenderViewCreated(render_view_host); |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 4552 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4553 | } |
| 4554 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4555 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4556 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4557 | // Don't notify the world, since this came from a renderer in the |
| 4558 | // background. |
| 4559 | return; |
| 4560 | } |
| 4561 | |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 4562 | RenderWidgetHostViewBase* rwhv = |
| 4563 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 4564 | if (rwhv) |
| 4565 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
| 4566 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4567 | notify_disconnection_ = true; |
| 4568 | // TODO(avi): Remove. http://crbug.com/170921 |
| 4569 | NotificationService::current()->Notify( |
| 4570 | NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 4571 | Source<WebContents>(this), |
| 4572 | NotificationService::NoDetails()); |
| 4573 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 4574 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 4575 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 4576 | |
| 4577 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 4578 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 4579 | if (was_crashed && !FocusLocationBarByDefault() && |
| 4580 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 4581 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 4582 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 4583 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4584 | for (auto& observer : observers_) |
| 4585 | observer.RenderViewReady(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4586 | } |
| 4587 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 4588 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 4589 | base::TerminationStatus status, |
| 4590 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4591 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4592 | // The pending page's RenderViewHost is gone. |
| 4593 | return; |
| 4594 | } |
| 4595 | |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 4596 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 4597 | // renderer may not have made a clean exit. |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 4598 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4599 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 4600 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 4601 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 4602 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 4603 | |
[email protected] | f738bdcb | 2014-07-11 20:40:44 | [diff] [blame] | 4604 | if (delegate_) |
| 4605 | delegate_->HideValidationMessage(this); |
| 4606 | |
dalecurtis | 3d1e130 | 2017-02-20 22:33:25 | [diff] [blame] | 4607 | audio_stream_monitor_.RenderProcessGone(rvh->GetProcess()->GetID()); |
| 4608 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4609 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 4610 | // "renderer crash" when there is more than one renderer process serving a |
| 4611 | // webpage? Once this function is called at a more granular frame level, we |
| 4612 | // probably will need to more granularly reset the state here. |
| 4613 | ResetLoadProgressState(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4614 | NotifyDisconnected(); |
| 4615 | SetIsCrashed(status, error_code); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4616 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4617 | for (auto& observer : observers_) |
| 4618 | observer.RenderProcessGone(GetCrashedStatus()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4619 | } |
| 4620 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4621 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4622 | for (auto& observer : observers_) |
| 4623 | observer.RenderViewDeleted(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 4624 | } |
| 4625 | |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4626 | void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host, |
| 4627 | const GURL& url) { |
| 4628 | if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) { |
| 4629 | // If we're fullscreen only update the url if it's from the fullscreen |
| 4630 | // renderer. |
| 4631 | RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView(); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4632 | if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget()) |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4633 | return; |
| 4634 | } |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4635 | if (delegate_) |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 4636 | delegate_->UpdateTargetURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4637 | } |
| 4638 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4639 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4640 | #if defined(OS_MACOSX) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4641 | // The UI may be in an event-tracking loop, such as between the |
| 4642 | // mouse-down and mouse-up in text selection or a button click. |
| 4643 | // Defer the close until after tracking is complete, so that we |
| 4644 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4645 | // TODO(shess): This could get more fine-grained. For instance, |
| 4646 | // closing a tab in another window while selecting text in the |
| 4647 | // current window's Omnibox should be just fine. |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4648 | if (view_->IsEventTracking()) { |
| 4649 | view_->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4650 | return; |
| 4651 | } |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4652 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4653 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4654 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4655 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4656 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4657 | } |
| 4658 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4659 | void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4660 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 4661 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4662 | } |
| 4663 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4664 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 4665 | bool to_different_document) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4666 | LoadingStateChanged(to_different_document, false, nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4667 | |
| 4668 | // Notify accessibility that the user is navigating away from the |
| 4669 | // current document. |
| 4670 | // |
| 4671 | // TODO(dmazzoni): do this using a WebContentsObserver. |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4672 | BrowserAccessibilityManager* manager = |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4673 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4674 | if (manager) |
| 4675 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4676 | } |
| 4677 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 4678 | void WebContentsImpl::DidStopLoading() { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 4679 | std::unique_ptr<LoadNotificationDetails> details; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4680 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4681 | // Use the last committed entry rather than the active one, in case a |
| 4682 | // pending entry has been created. |
| 4683 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4684 | Navigator* navigator = frame_tree_.root()->navigator(); |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4685 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4686 | // An entry may not exist for a stop when loading an initial blank page or |
| 4687 | // if an iframe injected by script into a blank page finishes loading. |
| 4688 | if (entry) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4689 | base::TimeDelta elapsed = |
| 4690 | base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4691 | |
| 4692 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4693 | entry->GetVirtualURL(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4694 | elapsed, |
| 4695 | &controller_, |
| 4696 | controller_.GetCurrentEntryIndex())); |
| 4697 | } |
| 4698 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4699 | LoadingStateChanged(true, false, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4700 | } |
| 4701 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4702 | void WebContentsImpl::DidChangeLoadProgress() { |
| 4703 | double load_progress = frame_tree_.load_progress(); |
| 4704 | |
| 4705 | // The delegate is notified immediately for the first and last updates. Also, |
| 4706 | // since the message loop may be pretty busy when a page is loaded, it might |
| 4707 | // not execute a posted task in a timely manner so the progress report is sent |
| 4708 | // immediately if enough time has passed. |
| 4709 | base::TimeDelta min_delay = |
| 4710 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 4711 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 4712 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 4713 | |
| 4714 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 4715 | // If there is a pending task to send progress, it is now obsolete. |
| 4716 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 4717 | |
| 4718 | // Notify the load progress change. |
| 4719 | SendChangeLoadProgress(); |
| 4720 | |
| 4721 | // Clean-up the states if needed. |
| 4722 | if (load_progress == 1.0) |
| 4723 | ResetLoadProgressState(); |
| 4724 | return; |
| 4725 | } |
| 4726 | |
| 4727 | if (loading_weak_factory_.HasWeakPtrs()) |
| 4728 | return; |
| 4729 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 4730 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 4731 | FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress, |
| 4732 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4733 | min_delay); |
| 4734 | } |
| 4735 | |
avi | d6d88b91 | 2017-01-13 00:16:00 | [diff] [blame] | 4736 | std::vector<std::unique_ptr<NavigationThrottle>> |
| 4737 | WebContentsImpl::CreateThrottlesForNavigation( |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 4738 | NavigationHandle* navigation_handle) { |
| 4739 | return GetContentClient()->browser()->CreateThrottlesForNavigation( |
| 4740 | navigation_handle); |
| 4741 | } |
| 4742 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4743 | std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData( |
| 4744 | NavigationHandle* navigation_handle) { |
| 4745 | DCHECK(IsBrowserSideNavigationEnabled()); |
| 4746 | return GetContentClient()->browser()->GetNavigationUIData(navigation_handle); |
| 4747 | } |
| 4748 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4749 | void WebContentsImpl::DidCancelLoading() { |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4750 | controller_.DiscardNonCommittedEntries(); |
| 4751 | |
| 4752 | // Update the URL display. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4753 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4754 | } |
| 4755 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4756 | void WebContentsImpl::DidAccessInitialDocument() { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4757 | has_accessed_initial_document_ = true; |
| 4758 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4759 | // We may have left a failed browser-initiated navigation in the address bar |
| 4760 | // to let the user edit it and try again. Clear it now that content might |
| 4761 | // show up underneath it. |
| 4762 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 4763 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4764 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4765 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 4766 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4767 | } |
| 4768 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 4769 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 4770 | const std::string& name) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4771 | for (auto& observer : observers_) |
| 4772 | observer.FrameNameChanged(render_frame_host, name); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 4773 | } |
| 4774 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4775 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4776 | RenderFrameHost* render_frame_host) { |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 4777 | ShowInsecureLocalhostWarningIfNeeded(); |
| 4778 | |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 4779 | is_notifying_observers_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4780 | for (auto& observer : observers_) |
| 4781 | observer.DocumentOnLoadCompletedInMainFrame(); |
creis | 97867aa | 2017-02-17 18:39:45 | [diff] [blame] | 4782 | is_notifying_observers_ = false; |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 4783 | |
| 4784 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4785 | NotificationService::current()->Notify( |
| 4786 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 4787 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4788 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 4789 | } |
| 4790 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4791 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
| 4792 | const PageState& page_state) { |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4793 | // The state update affects the last NavigationEntry associated with the given |
| 4794 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 4795 | // in the case of an UpdateState from a frame being swapped out). We track |
| 4796 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 4797 | RenderFrameHostImpl* rfhi = |
| 4798 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 4799 | NavigationEntryImpl* entry = |
| 4800 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 4801 | if (!entry) |
| 4802 | return; |
| 4803 | |
| 4804 | FrameNavigationEntry* frame_entry = |
| 4805 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 4806 | if (!frame_entry) |
| 4807 | return; |
| 4808 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 4809 | // The SiteInstance might not match if we do a cross-process navigation with |
| 4810 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 4811 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 4812 | // has already been replaced and destroyed. |
| 4813 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 4814 | return; |
| 4815 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4816 | if (page_state == frame_entry->page_state()) |
| 4817 | return; // Nothing to update. |
| 4818 | |
creis | 0cade2e | 2017-02-28 06:37:47 | [diff] [blame] | 4819 | DCHECK(page_state.IsValid()) << "Shouldn't set an empty PageState."; |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 4820 | |
| 4821 | // The document_sequence_number and item_sequence_number recorded in the |
| 4822 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 4823 | // since it must come from the same document. Do not update it if a difference |
| 4824 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 4825 | ExplodedPageState exploded_state; |
| 4826 | if (!DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 4827 | return; |
| 4828 | |
| 4829 | if (exploded_state.top.document_sequence_number != |
| 4830 | frame_entry->document_sequence_number() || |
| 4831 | exploded_state.top.item_sequence_number != |
| 4832 | frame_entry->item_sequence_number()) { |
| 4833 | return; |
| 4834 | } |
| 4835 | |
nasko | 04a322f25a | 2016-09-01 00:00:34 | [diff] [blame] | 4836 | frame_entry->SetPageState(page_state); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4837 | controller_.NotifyEntryChanged(entry); |
| 4838 | } |
| 4839 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4840 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4841 | const base::string16& title, |
| 4842 | base::i18n::TextDirection title_direction) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4843 | // If we have a title, that's a pretty good indication that we've started |
| 4844 | // getting useful data. |
| 4845 | SetNotWaitingForResponse(); |
| 4846 | |
| 4847 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4848 | // For example, it might be from a recently swapped out RFH. |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 4849 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
creis | ad8c31a | 2016-05-24 17:07:04 | [diff] [blame] | 4850 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4851 | |
| 4852 | // We can handle title updates when we don't have an entry in |
| 4853 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 4854 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4855 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4856 | return; |
| 4857 | |
| 4858 | // TODO(evan): make use of title_direction. |
| 4859 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4860 | UpdateTitleForEntry(entry, title); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4861 | } |
| 4862 | |
| 4863 | void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
| 4864 | const std::string& encoding) { |
| 4865 | SetEncoding(encoding); |
| 4866 | } |
| 4867 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4868 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 4869 | RenderViewHost* render_view_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4870 | for (auto& observer : observers_) |
| 4871 | observer.DocumentAvailableInMainFrame(); |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4872 | } |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4873 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4874 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 4875 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 4876 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 4877 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 4878 | // It is possible to receive it from one that has just been swapped in, |
| 4879 | // in which case we might as well deliver the message anyway. |
| 4880 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4881 | ClosePage(); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4882 | } |
| 4883 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4884 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 4885 | RenderFrameHost* target_rfh, |
| 4886 | SiteInstance* source_site_instance) const { |
| 4887 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 4888 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 4889 | // Note: This check means that an embedder could theoretically receive a |
| 4890 | // postMessage from anyone (not just its own guests). However, this is |
| 4891 | // probably not a risk for apps since other pages won't have references |
| 4892 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4893 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 4894 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4895 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4896 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4897 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 4898 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4899 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4900 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4901 | // If this message is going to outer WebContents from inner WebContents, |
| 4902 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 4903 | // already created a RenderFrameProxyHost for that purpose. |
| 4904 | if (GetBrowserPluginEmbedder() && |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4905 | GuestMode::IsCrossProcessFrameGuest(source_web_contents)) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4906 | return; |
| 4907 | } |
| 4908 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 4909 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | b3041b98a4 | 2016-03-12 04:43:06 | [diff] [blame] | 4910 | // We create a RenderFrameProxyHost for the embedder in the guest's render |
| 4911 | // process but we intentionally do not expose the embedder's opener chain |
| 4912 | // to it. |
| 4913 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 4914 | GetSiteInstance()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4915 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4916 | RenderFrameHostImpl* source_rfhi = |
| 4917 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4918 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 4919 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4920 | } |
| 4921 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4922 | } |
| 4923 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 4924 | void WebContentsImpl::SetAsFocusedWebContentsIfNecessary() { |
| 4925 | // Only change focus if we are not currently focused. |
| 4926 | WebContentsImpl* old_contents = GetFocusedWebContents(); |
| 4927 | if (old_contents == this) |
| 4928 | return; |
| 4929 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 4930 | GetOutermostWebContents()->node_.SetFocusedWebContents(this); |
| 4931 | |
| 4932 | if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) |
| 4933 | return; |
| 4934 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 4935 | // Send a page level blur to the old contents so that it displays inactive UI |
| 4936 | // and focus this contents to activate it. |
| 4937 | if (old_contents) |
| 4938 | old_contents->GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(false); |
avallee | c2ff1ef | 2017-01-21 00:12:30 | [diff] [blame] | 4939 | |
| 4940 | // Make sure the outer web contents knows our frame is focused. Otherwise, the |
| 4941 | // outer renderer could have the element before or after the frame element |
| 4942 | // focused which would return early without actually advancing focus. |
| 4943 | if (GetRenderManager()->GetProxyToOuterDelegate()) |
| 4944 | GetRenderManager()->GetProxyToOuterDelegate()->SetFocusedFrame(); |
| 4945 | |
lfg | 1453e41 | 2017-04-11 00:48:50 | [diff] [blame] | 4946 | if (ShowingInterstitialPage()) { |
| 4947 | static_cast<RenderFrameHostImpl*>( |
| 4948 | GetRenderManager()->interstitial_page()->GetMainFrame()) |
| 4949 | ->GetRenderWidgetHost() |
| 4950 | ->SetPageFocus(true); |
| 4951 | } else { |
| 4952 | GetMainFrame()->GetRenderWidgetHost()->SetPageFocus(true); |
| 4953 | } |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 4954 | } |
| 4955 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4956 | void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 4957 | SiteInstance* source) { |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 4958 | SetAsFocusedWebContentsIfNecessary(); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4959 | frame_tree_.SetFocusedFrame(node, source); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4960 | } |
| 4961 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 4962 | void WebContentsImpl::OnFocusedElementChangedInFrame( |
| 4963 | RenderFrameHostImpl* frame, |
| 4964 | const gfx::Rect& bounds_in_root_view) { |
| 4965 | RenderWidgetHostViewBase* root_view = |
| 4966 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 4967 | if (!root_view || !frame->GetView()) |
| 4968 | return; |
| 4969 | |
| 4970 | // Converting to screen coordinates. |
| 4971 | gfx::Point origin = bounds_in_root_view.origin(); |
| 4972 | origin += root_view->GetViewBounds().OffsetFromOrigin(); |
| 4973 | gfx::Rect bounds_in_screen(origin, bounds_in_root_view.size()); |
| 4974 | |
| 4975 | root_view->FocusedNodeChanged(frame->has_focused_editable_element(), |
| 4976 | bounds_in_screen); |
| 4977 | |
| 4978 | FocusedNodeDetails details = {frame->has_focused_editable_element(), |
| 4979 | bounds_in_screen}; |
| 4980 | |
| 4981 | // TODO(ekaramad): We should replace this with an observer notification |
| 4982 | // (https://crbug.com/675975). |
| 4983 | NotificationService::current()->Notify( |
| 4984 | NOTIFICATION_FOCUS_CHANGED_IN_PAGE, |
| 4985 | Source<RenderViewHost>(GetRenderViewHost()), |
| 4986 | Details<FocusedNodeDetails>(&details)); |
| 4987 | } |
| 4988 | |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 4989 | bool WebContentsImpl::DidAddMessageToConsole(int32_t level, |
| 4990 | const base::string16& message, |
| 4991 | int32_t line_no, |
| 4992 | const base::string16& source_id) { |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 4993 | if (!delegate_) |
| 4994 | return false; |
avi | a90ae4e | 2016-11-11 20:49:33 | [diff] [blame] | 4995 | return delegate_->DidAddMessageToConsole(this, level, message, line_no, |
| 4996 | source_id); |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 4997 | } |
| 4998 | |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 4999 | void WebContentsImpl::OnUserInteraction( |
| 5000 | RenderWidgetHostImpl* render_widget_host, |
| 5001 | const blink::WebInputEvent::Type type) { |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 5002 | // Ignore unless the widget is currently in the frame tree. |
| 5003 | if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5004 | return; |
| 5005 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5006 | for (auto& observer : observers_) |
| 5007 | observer.DidGetUserInteraction(type); |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 5008 | |
| 5009 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 5010 | // Exclude scroll events as user gestures for resource load dispatches. |
| 5011 | // rdh is NULL in unittests. |
Blink Reformat | 1c4d759e | 2017-04-09 16:34:54 | [diff] [blame] | 5012 | if (rdh && type != blink::WebInputEvent::kMouseWheel) |
scottmg | e22a5e5 | 2016-06-30 00:36:51 | [diff] [blame] | 5013 | rdh->OnUserGesture(); |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 5014 | } |
| 5015 | |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5016 | void WebContentsImpl::FocusOwningWebContents( |
| 5017 | RenderWidgetHostImpl* render_widget_host) { |
| 5018 | // The PDF plugin still runs as a BrowserPlugin and must go through the |
| 5019 | // input redirection mechanism. It must not become focused direcly. |
| 5020 | if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) |
| 5021 | return; |
| 5022 | |
| 5023 | RenderWidgetHostImpl* focused_widget = |
| 5024 | GetFocusedRenderWidgetHost(render_widget_host); |
| 5025 | |
| 5026 | if (focused_widget != render_widget_host && |
avallee | 8e88159 | 2016-11-19 00:39:30 | [diff] [blame] | 5027 | (!focused_widget || |
| 5028 | focused_widget->delegate() != render_widget_host->delegate())) { |
avallee | 9993fca | 2016-11-17 06:16:50 | [diff] [blame] | 5029 | SetAsFocusedWebContentsIfNecessary(); |
| 5030 | } |
| 5031 | } |
| 5032 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5033 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 5034 | // Notify observers. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5035 | for (auto& observer : observers_) |
| 5036 | observer.DidGetIgnoredUIEvent(); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 5037 | } |
| 5038 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5039 | void WebContentsImpl::RendererUnresponsive( |
avi | ce79930 | 2017-03-09 16:34:59 | [diff] [blame] | 5040 | RenderWidgetHostImpl* render_widget_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5041 | for (auto& observer : observers_) |
| 5042 | observer.OnRendererUnresponsive(render_widget_host); |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 5043 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5044 | // Don't show hung renderer dialog for a swapped out RVH. |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5045 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 5046 | return; |
| 5047 | |
avi | c031d39 | 2017-03-03 03:09:42 | [diff] [blame] | 5048 | if (ShouldIgnoreUnresponsiveRenderer()) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 5049 | return; |
| 5050 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 5051 | if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 5052 | return; |
| 5053 | |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 5054 | if (delegate_) { |
| 5055 | WebContentsUnresponsiveState unresponsive_state; |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 5056 | unresponsive_state.outstanding_ack_count = |
| 5057 | render_widget_host->in_flight_event_count(); |
| 5058 | unresponsive_state.outstanding_event_type = |
| 5059 | render_widget_host->hang_monitor_event_type(); |
| 5060 | unresponsive_state.last_event_type = render_widget_host->last_event_type(); |
| 5061 | delegate_->RendererUnresponsive(this, unresponsive_state); |
| 5062 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5063 | } |
| 5064 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 5065 | void WebContentsImpl::RendererResponsive( |
| 5066 | RenderWidgetHostImpl* render_widget_host) { |
| 5067 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 5068 | return; |
| 5069 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 5070 | if (delegate_) |
| 5071 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5072 | } |
| 5073 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5074 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 5075 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5076 | bool* proceed_to_fire_unload) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5077 | for (auto& observer : observers_) |
| 5078 | observer.BeforeUnloadFired(proceed_time); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 5079 | if (delegate_) |
| 5080 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 5081 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5082 | } |
| 5083 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 5084 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 5085 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 5086 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 5087 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 5088 | } |
| 5089 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5090 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 5091 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5092 | gfx::Size size = GetSizeForNewRenderView(); |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 5093 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 5094 | // here during container initialization and normal window size will be set |
| 5095 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 5096 | // normal size later so just ignore it. |
| 5097 | if (!size.IsEmpty()) |
| 5098 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5099 | } |
| 5100 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 5101 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
| 5102 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 5103 | // deferrer would prevent us from swapping out. We also clear the state |
| 5104 | // because this is a cross-process navigation, which means that it's a new |
| 5105 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 5106 | // |
| 5107 | // Note that we don't bother telling browser_plugin_embedder_ because the |
| 5108 | // cross-process navigation will either destroy the browser plugins or not |
| 5109 | // require their dialogs to close. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5110 | if (dialog_manager_) { |
avi | 6879fcf | 2017-01-21 05:27:53 | [diff] [blame] | 5111 | dialog_manager_->CancelDialogs(this, /*reset_state=*/true); |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 5112 | } |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 5113 | } |
| 5114 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5115 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host, |
| 5116 | RenderFrameHost* new_host, |
| 5117 | bool is_main_frame) { |
| 5118 | if (is_main_frame) { |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 5119 | NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5120 | new_host->GetRenderViewHost()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 5121 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5122 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 5123 | if (delegate_) |
| 5124 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 5125 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5126 | view_->RenderViewSwappedIn(new_host->GetRenderViewHost()); |
dmazzoni | 6211145 | 2017-04-28 23:46:55 | [diff] [blame] | 5127 | |
| 5128 | RenderWidgetHostViewBase* rwhv = |
| 5129 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 5130 | if (rwhv) |
| 5131 | rwhv->SetMainFrameAXTreeID(GetMainFrame()->GetAXTreeID()); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 5132 | } |
| 5133 | |
| 5134 | NotifyFrameSwapped(old_host, new_host); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 5135 | } |
| 5136 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 5137 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
| 5138 | RenderViewHost* old_host, |
| 5139 | RenderViewHost* new_host) { |
| 5140 | NotifyViewSwapped(old_host, new_host); |
| 5141 | } |
| 5142 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5143 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 5144 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 5145 | } |
| 5146 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 5147 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 5148 | const GURL& url) { |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 5149 | return CreateWebUI(url, std::string()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5150 | } |
| 5151 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 5152 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5153 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5154 | return controller_.GetLastCommittedEntry(); |
| 5155 | } |
| 5156 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 5157 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 5158 | RenderViewHost* render_view_host) { |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 5159 | RenderWidgetHostViewBase* rwh_view = |
| 5160 | view_->CreateViewForWidget(render_view_host->GetWidget(), false); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 5161 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5162 | // 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] | 5163 | if (rwh_view) |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5164 | rwh_view->SetSize(GetSizeForNewRenderView()); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 5165 | } |
| 5166 | |
| 5167 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 5168 | RenderViewHost* render_view_host, |
| 5169 | int opener_frame_routing_id, |
| 5170 | int proxy_routing_id, |
| 5171 | const FrameReplicationState& replicated_frame_state) { |
| 5172 | TRACE_EVENT0("browser,navigation", |
| 5173 | "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 5174 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 5175 | if (proxy_routing_id == MSG_ROUTING_NONE) |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 5176 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 5177 | |
piman | 00cf940 | 2017-04-03 17:09:20 | [diff] [blame] | 5178 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
| 5179 | ->CreateRenderView(opener_frame_routing_id, proxy_routing_id, |
lfg | 9431efd | 2016-12-14 14:45:26 | [diff] [blame] | 5180 | replicated_frame_state, created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 5181 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 5182 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 5183 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 5184 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 5185 | controller_.GetLastCommittedEntryIndex(), |
| 5186 | controller_.GetEntryCount()); |
| 5187 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 5188 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 5189 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 5190 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 5191 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 5192 | if (rwh_view) { |
| 5193 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 5194 | render_widget_host->WasResized(); |
| 5195 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 5196 | #endif |
| 5197 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 5198 | return true; |
| 5199 | } |
| 5200 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 5201 | bool WebContentsImpl::CreateRenderFrameForRenderManager( |
| 5202 | RenderFrameHost* render_frame_host, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 5203 | int proxy_routing_id, |
| 5204 | int opener_routing_id, |
japhet | e6adf14 | 2014-10-31 00:01:49 | [diff] [blame] | 5205 | int parent_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 5206 | int previous_sibling_routing_id) { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 5207 | TRACE_EVENT0("browser,navigation", |
| 5208 | "WebContentsImpl::CreateRenderFrameForRenderManager"); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 5209 | |
| 5210 | RenderFrameHostImpl* rfh = |
| 5211 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 5212 | if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id, |
| 5213 | parent_routing_id, previous_sibling_routing_id)) |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 5214 | return false; |
| 5215 | |
| 5216 | // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed |
| 5217 | // RenderFrameHost will have to be associated with the appropriate |
| 5218 | // RenderWidgetHostView or a new one should be created here. |
| 5219 | |
| 5220 | return true; |
| 5221 | } |
| 5222 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 5223 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5224 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 5225 | base::android::ScopedJavaLocalRef<jobject> |
| 5226 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 5227 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 5228 | return GetWebContentsAndroid()->GetJavaObject(); |
| 5229 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 5230 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 5231 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 5232 | WebContentsAndroid* web_contents_android = |
| 5233 | static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey)); |
| 5234 | if (!web_contents_android) { |
| 5235 | web_contents_android = new WebContentsAndroid(this); |
avi | cb129c0 | 2017-05-03 06:49:29 | [diff] [blame] | 5236 | SetUserData(kWebContentsAndroidKey, base::WrapUnique(web_contents_android)); |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 5237 | } |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 5238 | return web_contents_android; |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 5239 | } |
| 5240 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5241 | void WebContentsImpl::ActivateNearestFindResult(float x, |
| 5242 | float y) { |
| 5243 | GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y); |
| 5244 | } |
| 5245 | |
| 5246 | void WebContentsImpl::RequestFindMatchRects(int current_version) { |
| 5247 | GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version); |
| 5248 | } |
| 5249 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 5250 | bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 5251 | return CreateRenderViewForRenderManager( |
| 5252 | GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 5253 | frame_tree_.root()->current_replication_state()); |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 5254 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5255 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 5256 | service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() { |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 5257 | if (!java_interfaces_) { |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 5258 | service_manager::mojom::InterfaceProviderPtr provider; |
blundell | e0a9f158 | 2016-12-20 11:23:32 | [diff] [blame] | 5259 | BindInterfaceRegistryForWebContents(mojo::MakeRequest(&provider), this); |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 5260 | java_interfaces_.reset(new service_manager::InterfaceProvider); |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 5261 | java_interfaces_->Bind(std::move(provider)); |
| 5262 | } |
| 5263 | return java_interfaces_.get(); |
| 5264 | } |
| 5265 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5266 | #elif defined(OS_MACOSX) |
| 5267 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 5268 | void WebContentsImpl::SetAllowOtherViews(bool allow) { |
| 5269 | view_->SetAllowOtherViews(allow); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5270 | } |
| 5271 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 5272 | bool WebContentsImpl::GetAllowOtherViews() { |
| 5273 | return view_->GetAllowOtherViews(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5274 | } |
| 5275 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 5276 | #endif |
| 5277 | |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 5278 | void WebContentsImpl::OnDidDownloadImage( |
| 5279 | const ImageDownloadCallback& callback, |
| 5280 | int id, |
| 5281 | const GURL& image_url, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 5282 | int32_t http_status_code, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 5283 | const std::vector<SkBitmap>& images, |
| 5284 | const std::vector<gfx::Size>& original_image_sizes) { |
| 5285 | callback.Run(id, http_status_code, image_url, images, original_image_sizes); |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 5286 | } |
| 5287 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 5288 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 5289 | int render_frame_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5290 | IPC::Message* reply_msg, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5291 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5292 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 5293 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 5294 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 5295 | render_frame_id); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5296 | last_dialog_suppressed_ = dialog_was_suppressed; |
| 5297 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 5298 | if (is_showing_before_unload_dialog_ && !success) { |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 5299 | // It is possible for the current RenderFrameHost to have changed in the |
| 5300 | // meantime. Do not reset the navigation state in that case. |
| 5301 | if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 5302 | rfh->frame_tree_node()->BeforeUnloadCanceled(); |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 5303 | controller_.DiscardNonCommittedEntries(); |
| 5304 | } |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 5305 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5306 | for (auto& observer : observers_) |
| 5307 | observer.BeforeUnloadDialogCancelled(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 5308 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 5309 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 5310 | if (rfh) { |
avi | 44acfaa8 | 2017-05-03 22:55:35 | [diff] [blame] | 5311 | rfh->JavaScriptDialogClosed(reply_msg, success, user_input); |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 5312 | } else { |
| 5313 | // Don't leak the sync IPC reply if the RFH or process is gone. |
| 5314 | delete reply_msg; |
| 5315 | } |
avi | 1c51fb6 | 2017-02-27 20:43:03 | [diff] [blame] | 5316 | |
| 5317 | is_showing_javascript_dialog_ = false; |
| 5318 | is_showing_before_unload_dialog_ = false; |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 5319 | } |
| 5320 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5321 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5322 | if (encoding == last_reported_encoding_) |
| 5323 | return; |
| 5324 | last_reported_encoding_ = encoding; |
| 5325 | |
jinsukkim | 79df88a | 2017-01-04 06:26:15 | [diff] [blame] | 5326 | canonical_encoding_ = base::GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 5327 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 5328 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 5329 | bool WebContentsImpl::IsHidden() { |
| 5330 | return capturer_count_ == 0 && !should_normally_be_visible_; |
| 5331 | } |
| 5332 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 5333 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lfg | 60123369 | 2017-03-06 22:45:44 | [diff] [blame] | 5334 | return node_.outer_contents_frame_tree_node_id(); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5335 | } |
| 5336 | |
ekaramad | aeb3c5c | 2016-11-09 03:22:35 | [diff] [blame] | 5337 | RenderWidgetHostImpl* WebContentsImpl::GetFullscreenRenderWidgetHost() const { |
| 5338 | return RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_, |
| 5339 | fullscreen_widget_routing_id_); |
| 5340 | } |
| 5341 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 5342 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 5343 | return frame_tree_.root()->render_manager(); |
| 5344 | } |
| 5345 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 5346 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5347 | return browser_plugin_guest_.get(); |
| 5348 | } |
| 5349 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 5350 | void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 5351 | CHECK(!browser_plugin_guest_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5352 | CHECK(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 5353 | browser_plugin_guest_.reset(guest); |
| 5354 | } |
| 5355 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 5356 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5357 | return browser_plugin_embedder_.get(); |
| 5358 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5359 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 5360 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 5361 | if (browser_plugin_embedder_) |
| 5362 | return; |
| 5363 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 5364 | } |
| 5365 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5366 | gfx::Size WebContentsImpl::GetSizeForNewRenderView() { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5367 | gfx::Size size; |
| 5368 | if (delegate_) |
| 5369 | size = delegate_->GetSizeForNewRenderView(this); |
| 5370 | if (size.IsEmpty()) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5371 | size = GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5372 | return size; |
| 5373 | } |
| 5374 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 5375 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5376 | for (auto& observer : observers_) |
| 5377 | observer.FrameDeleted(render_frame_host); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 5378 | } |
| 5379 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 5380 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 5381 | if (!delegate_) |
| 5382 | return; |
| 5383 | const gfx::Size new_size = GetPreferredSize(); |
| 5384 | if (new_size != old_size) |
| 5385 | delegate_->UpdatePreferredSize(this, new_size); |
| 5386 | } |
| 5387 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 5388 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI( |
| 5389 | const GURL& url, |
| 5390 | const std::string& frame_name) { |
| 5391 | std::unique_ptr<WebUIImpl> web_ui = |
| 5392 | base::MakeUnique<WebUIImpl>(this, frame_name); |
| 5393 | WebUIController* controller = |
| 5394 | WebUIControllerFactoryRegistry::GetInstance() |
| 5395 | ->CreateWebUIControllerForURL(web_ui.get(), url); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 5396 | if (controller) { |
weisert | 3dab3b9 | 2017-01-10 10:31:17 | [diff] [blame] | 5397 | web_ui->AddMessageHandler(base::MakeUnique<GenericHandler>()); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 5398 | web_ui->SetController(controller); |
| 5399 | return web_ui; |
| 5400 | } |
| 5401 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame] | 5402 | return nullptr; |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 5403 | } |
| 5404 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 5405 | FindRequestManager* WebContentsImpl::GetFindRequestManager() { |
| 5406 | for (WebContentsImpl* contents = this; contents; |
| 5407 | contents = contents->GetOuterWebContents()) { |
| 5408 | if (contents->find_request_manager_) |
| 5409 | return contents->find_request_manager_.get(); |
| 5410 | } |
| 5411 | |
| 5412 | return nullptr; |
| 5413 | } |
| 5414 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5415 | FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 5416 | if (FindRequestManager* manager = GetFindRequestManager()) |
| 5417 | return manager; |
| 5418 | |
| 5419 | // No existing FindRequestManager found, so one must be created. |
| 5420 | find_request_manager_.reset(new FindRequestManager(this)); |
| 5421 | |
| 5422 | // Concurrent find sessions must not overlap, so destroy any existing |
| 5423 | // FindRequestManagers in any inner WebContentses. |
| 5424 | for (WebContentsImpl* contents : GetWebContentsAndAllInner()) { |
| 5425 | if (contents == this) |
| 5426 | continue; |
| 5427 | if (contents->find_request_manager_) { |
| 5428 | contents->find_request_manager_->StopFinding( |
| 5429 | content::STOP_FIND_ACTION_CLEAR_SELECTION); |
| 5430 | contents->find_request_manager_.release(); |
| 5431 | } |
| 5432 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5433 | |
| 5434 | return find_request_manager_.get(); |
| 5435 | } |
| 5436 | |
| 5437 | void WebContentsImpl::NotifyFindReply(int request_id, |
| 5438 | int number_of_matches, |
| 5439 | const gfx::Rect& selection_rect, |
| 5440 | int active_match_ordinal, |
| 5441 | bool final_update) { |
paulmeyer | 60b5d83 | 2016-08-31 18:46:34 | [diff] [blame] | 5442 | if (delegate_ && !is_being_destroyed_) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5443 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 5444 | active_match_ordinal, final_update); |
| 5445 | } |
| 5446 | } |
| 5447 | |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 5448 | void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() { |
| 5449 | // Trying to invalidate the tab state while being destroyed could result in a |
| 5450 | // use after free. |
| 5451 | if (IsBeingDestroyed()) { |
| 5452 | return; |
| 5453 | } |
| 5454 | // Notify for UI updates if the state changes. |
| 5455 | bluetooth_connected_device_count_++; |
| 5456 | if (bluetooth_connected_device_count_ == 1) { |
| 5457 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 5458 | } |
| 5459 | } |
| 5460 | |
| 5461 | void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() { |
| 5462 | // Trying to invalidate the tab state while being destroyed could result in a |
| 5463 | // use after free. |
| 5464 | if (IsBeingDestroyed()) { |
| 5465 | return; |
| 5466 | } |
| 5467 | // Notify for UI updates if the state changes. |
| 5468 | DCHECK(bluetooth_connected_device_count_ != 0); |
| 5469 | bluetooth_connected_device_count_--; |
| 5470 | if (bluetooth_connected_device_count_ == 0) { |
| 5471 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 5472 | } |
| 5473 | } |
| 5474 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 5475 | void WebContentsImpl::SetHasPersistentVideo(bool has_persistent_video) { |
| 5476 | if (has_persistent_video_ == has_persistent_video) |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5477 | return; |
| 5478 | |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 5479 | has_persistent_video_ = has_persistent_video; |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5480 | NotifyPreferencesChanged(); |
zqzhang | 8ac4900 | 2017-03-16 21:51:35 | [diff] [blame] | 5481 | media_web_contents_observer()->RequestPersistentVideo(has_persistent_video); |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5482 | } |
| 5483 | |
paulmeyer | feafc2d | 2017-04-25 21:46:40 | [diff] [blame] | 5484 | void WebContentsImpl::BrowserPluginGuestWillDetach() { |
| 5485 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 5486 | if (this != outermost && ContainsOrIsFocusedWebContents()) |
| 5487 | outermost->SetAsFocusedWebContentsIfNecessary(); |
| 5488 | } |
| 5489 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5490 | #if defined(OS_ANDROID) |
| 5491 | void WebContentsImpl::NotifyFindMatchRectsReply( |
| 5492 | int version, |
| 5493 | const std::vector<gfx::RectF>& rects, |
| 5494 | const gfx::RectF& active_rect) { |
| 5495 | if (delegate_) |
| 5496 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 5497 | } |
| 5498 | #endif |
| 5499 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 5500 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 5501 | force_disable_overscroll_content_ = force_disable; |
| 5502 | if (view_) |
| 5503 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 5504 | } |
| 5505 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5506 | void WebContentsImpl::MediaStartedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5507 | const WebContentsObserver::MediaPlayerInfo& media_info, |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5508 | const WebContentsObserver::MediaPlayerId& id) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5509 | if (media_info.has_video) |
| 5510 | currently_playing_video_count_++; |
| 5511 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5512 | for (auto& observer : observers_) |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5513 | observer.MediaStartedPlaying(media_info, id); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5514 | } |
| 5515 | |
| 5516 | void WebContentsImpl::MediaStoppedPlaying( |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5517 | const WebContentsObserver::MediaPlayerInfo& media_info, |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5518 | const WebContentsObserver::MediaPlayerId& id) { |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5519 | if (media_info.has_video) |
| 5520 | currently_playing_video_count_--; |
| 5521 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5522 | for (auto& observer : observers_) |
billorr | 21c005d | 2016-11-17 03:57:04 | [diff] [blame] | 5523 | observer.MediaStoppedPlaying(media_info, id); |
| 5524 | } |
| 5525 | |
| 5526 | int WebContentsImpl::GetCurrentlyPlayingVideoCount() { |
| 5527 | return currently_playing_video_count_; |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5528 | } |
| 5529 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 5530 | void WebContentsImpl::UpdateWebContentsVisibility(bool visible) { |
| 5531 | if (!did_first_set_visible_) { |
| 5532 | // If this WebContents has not yet been set to be visible for the first |
| 5533 | // time, ignore any requests to make it hidden, since resources would |
| 5534 | // immediately be destroyed and only re-created after content loaded. In |
| 5535 | // this state the window content is undefined and can show garbage. |
| 5536 | // However, the page load mechanism requires an activation call through a |
| 5537 | // visibility call to (re)load. |
| 5538 | if (visible) { |
| 5539 | did_first_set_visible_ = true; |
| 5540 | WasShown(); |
| 5541 | } |
| 5542 | return; |
| 5543 | } |
| 5544 | if (visible == should_normally_be_visible_) |
| 5545 | return; |
| 5546 | |
| 5547 | if (visible) |
| 5548 | WasShown(); |
| 5549 | else |
| 5550 | WasHidden(); |
| 5551 | } |
| 5552 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 5553 | void WebContentsImpl::UpdateOverridingUserAgent() { |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5554 | NotifyPreferencesChanged(); |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 5555 | } |
| 5556 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 5557 | void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 5558 | JavaScriptDialogManager* dialog_manager) { |
| 5559 | dialog_manager_ = dialog_manager; |
| 5560 | } |
| 5561 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 5562 | void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { |
| 5563 | auto it = binding_sets_.find(interface_name); |
| 5564 | if (it != binding_sets_.end()) |
| 5565 | binding_sets_.erase(it); |
| 5566 | } |
| 5567 | |
nzolghadr | d87a308d | 2016-12-07 15:45:56 | [diff] [blame] | 5568 | bool WebContentsImpl::AddDomainInfoToRapporSample(rappor::Sample* sample) { |
| 5569 | sample->SetStringField("Domain", ::rappor::GetDomainAndRegistrySampleFromGURL( |
| 5570 | GetLastCommittedURL())); |
| 5571 | |
| 5572 | return true; |
| 5573 | } |
| 5574 | |
ekaramad | a110f64 | 2016-12-21 19:47:28 | [diff] [blame] | 5575 | void WebContentsImpl::FocusedNodeTouched(bool editable) { |
| 5576 | #if defined(OS_WIN) |
| 5577 | // We use the cursor position to determine where the touch occurred. |
| 5578 | RenderWidgetHostView* view = GetRenderWidgetHostView(); |
| 5579 | if (!view) |
| 5580 | return; |
| 5581 | POINT cursor_pos = {}; |
| 5582 | ::GetCursorPos(&cursor_pos); |
| 5583 | float scale = GetScaleFactorForView(view); |
| 5584 | gfx::Point location_dips_screen = |
| 5585 | gfx::ConvertPointToDIP(scale, gfx::Point(cursor_pos)); |
| 5586 | view->FocusedNodeTouched(location_dips_screen, editable); |
| 5587 | #endif |
| 5588 | } |
| 5589 | |
samans | 90fb816 | 2017-04-04 22:30:45 | [diff] [blame] | 5590 | void WebContentsImpl::DidReceiveCompositorFrame() { |
| 5591 | for (auto& observer : observers_) |
| 5592 | observer.DidReceiveCompositorFrame(); |
| 5593 | } |
| 5594 | |
falken | 52a56e3 | 2016-12-08 05:02:40 | [diff] [blame] | 5595 | void WebContentsImpl::ShowInsecureLocalhostWarningIfNeeded() { |
| 5596 | bool allow_localhost = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 5597 | switches::kAllowInsecureLocalhost); |
| 5598 | if (!allow_localhost) |
| 5599 | return; |
| 5600 | |
| 5601 | content::NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 5602 | if (!entry || !net::IsLocalhost(entry->GetURL().host())) |
| 5603 | return; |
| 5604 | |
| 5605 | content::SSLStatus ssl_status = entry->GetSSL(); |
| 5606 | bool is_cert_error = net::IsCertStatusError(ssl_status.cert_status) && |
| 5607 | !net::IsCertStatusMinorError(ssl_status.cert_status); |
| 5608 | if (!is_cert_error) |
| 5609 | return; |
| 5610 | |
| 5611 | GetMainFrame()->AddMessageToConsole( |
| 5612 | content::CONSOLE_MESSAGE_LEVEL_WARNING, |
| 5613 | base::StringPrintf("This site does not have a valid SSL " |
| 5614 | "certificate! Without SSL, your site's and " |
| 5615 | "visitors' data is vulnerable to theft and " |
| 5616 | "tampering. Get a valid SSL certificate before" |
| 5617 | " releasing your website to the public.")); |
| 5618 | } |
| 5619 | |
mlamouri | 5cd9ae8 | 2017-02-18 11:05:09 | [diff] [blame] | 5620 | void WebContentsImpl::NotifyPreferencesChanged() { |
| 5621 | std::set<RenderViewHost*> render_view_host_set; |
| 5622 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 5623 | RenderWidgetHost* render_widget_host = |
| 5624 | node->current_frame_host()->GetRenderWidgetHost(); |
| 5625 | if (!render_widget_host) |
| 5626 | continue; |
| 5627 | RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
| 5628 | if (!render_view_host) |
| 5629 | continue; |
| 5630 | render_view_host_set.insert(render_view_host); |
| 5631 | } |
| 5632 | for (RenderViewHost* render_view_host : render_view_host_set) |
| 5633 | render_view_host->OnWebkitPreferencesChanged(); |
| 5634 | } |
| 5635 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5636 | } // namespace content |