[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> |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 11 | |
[email protected] | 36fb2c7c | 2011-04-04 15:49:08 | [diff] [blame] | 12 | #include "base/command_line.h" |
creis | fafed88 | 2016-07-29 00:03:09 | [diff] [blame] | 13 | #include "base/debug/dump_without_crashing.h" |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 14 | #include "base/feature_list.h" |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 15 | #include "base/lazy_instance.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 16 | #include "base/location.h" |
[email protected] | 6d636e6 | 2013-07-31 03:15:56 | [diff] [blame] | 17 | #include "base/logging.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 18 | #include "base/macros.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 19 | #include "base/memory/ref_counted.h" |
asvitkine | 8d51e9d | 2016-09-02 23:55:43 | [diff] [blame] | 20 | #include "base/metrics/histogram_macros.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 21 | #include "base/process/process.h" |
erikchen | 35629cc | 2015-03-10 20:43:22 | [diff] [blame] | 22 | #include "base/profiler/scoped_tracker.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 23 | #include "base/single_thread_task_runner.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 24 | #include "base/strings/string16.h" |
| 25 | #include "base/strings/string_number_conversions.h" |
| 26 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 27 | #include "base/strings/utf_string_conversions.h" |
gab | 30f26df | 2016-05-11 19:37:55 | [diff] [blame] | 28 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 29 | #include "base/time/time.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 30 | #include "base/trace_event/trace_event.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 31 | #include "build/build_config.h" |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 32 | #include "components/mime_util/mime_util.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 33 | #include "components/url_formatter/url_formatter.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 34 | #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 35 | #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 36 | #include "content/browser/bad_message.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 37 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 38 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 39 | #include "content/browser/child_process_security_policy_impl.h" |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 40 | #include "content/browser/devtools/render_frame_devtools_agent_host.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 41 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 42 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 43 | #include "content/browser/download/download_stats.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 44 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 45 | #include "content/browser/download/save_package.h" |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 46 | #include "content/browser/find_request_manager.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 47 | #include "content/browser/frame_host/cross_process_frame_connector.h" |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 48 | #include "content/browser/frame_host/frame_tree_node.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 49 | #include "content/browser/frame_host/interstitial_page_impl.h" |
| 50 | #include "content/browser/frame_host/navigation_entry_impl.h" |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 51 | #include "content/browser/frame_host/navigation_handle_impl.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 52 | #include "content/browser/frame_host/navigator_impl.h" |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 53 | #include "content/browser/frame_host/render_frame_host_impl.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 54 | #include "content/browser/frame_host/render_frame_proxy_host.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 55 | #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 56 | #include "content/browser/host_zoom_map_impl.h" |
csharrison | 2e8c98e | 2016-08-01 23:56:25 | [diff] [blame] | 57 | #include "content/browser/loader/loader_io_thread_notifier.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 58 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 59 | #include "content/browser/manifest/manifest_manager_host.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 60 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 61 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 62 | #include "content/browser/media/media_web_contents_observer.h" |
mlamouri | 91873409 | 2016-03-12 04:47:52 | [diff] [blame] | 63 | #include "content/browser/media/session/media_session.h" |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 64 | #include "content/browser/message_port_message_filter.h" |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 65 | #include "content/browser/plugin_content_origin_whitelist.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 66 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 67 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 68 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 69 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 70 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 71 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 72 | #include "content/browser/renderer_host/text_input_manager.h" |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 73 | #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 74 | #include "content/browser/site_instance_impl.h" |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 75 | #include "content/browser/web_contents/web_contents_view_child_frame.h" |
[email protected] | b5a4084 | 2012-11-28 15:26:11 | [diff] [blame] | 76 | #include "content/browser/web_contents/web_contents_view_guest.h" |
[email protected] | eb2ef21 | 2013-01-29 04:27:58 | [diff] [blame] | 77 | #include "content/browser/webui/generic_handler.h" |
[email protected] | 86a0a6e | 2013-01-28 06:33:03 | [diff] [blame] | 78 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 79 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 80 | #include "content/common/browser_plugin/browser_plugin_constants.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 81 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 82 | #include "content/common/frame_messages.h" |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 83 | #include "content/common/input_messages.h" |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 84 | #include "content/common/page_messages.h" |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 85 | #include "content/common/page_state_serialization.h" |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 86 | #include "content/common/render_message_filter.mojom.h" |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 87 | #include "content/common/site_isolation_policy.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 88 | #include "content/common/view_messages.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 89 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 90 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 91 | #include "content/public/browser/browser_plugin_guest_manager.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 92 | #include "content/public/browser/content_browser_client.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 93 | #include "content/public/browser/download_manager.h" |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 94 | #include "content/public/browser/download_url_parameters.h" |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 95 | #include "content/public/browser/guest_mode.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 96 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 97 | #include "content/public/browser/javascript_dialog_manager.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 98 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 99 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 100 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 101 | #include "content/public/browser/notification_service.h" |
scottmg | 011d96e3 | 2016-06-29 19:15:08 | [diff] [blame] | 102 | #include "content/public/browser/notification_types.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 103 | #include "content/public/browser/render_widget_host_iterator.h" |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 104 | #include "content/public/browser/resource_request_details.h" |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 105 | #include "content/public/browser/screen_orientation_dispatcher_host.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 106 | #include "content/public/browser/security_style_explanations.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 107 | #include "content/public/browser/storage_partition.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 108 | #include "content/public/browser/user_metrics.h" |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 109 | #include "content/public/browser/web_contents_binding_set.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 110 | #include "content/public/browser/web_contents_delegate.h" |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 111 | #include "content/public/browser/web_contents_unresponsive_state.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 112 | #include "content/public/common/bindings_policy.h" |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 113 | #include "content/public/common/browser_side_navigation_policy.h" |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 114 | #include "content/public/common/child_process_host.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 115 | #include "content/public/common/content_constants.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 116 | #include "content/public/common/content_switches.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 117 | #include "content/public/common/page_zoom.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 118 | #include "content/public/common/result_codes.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 119 | #include "content/public/common/url_constants.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 120 | #include "content/public/common/url_utils.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 121 | #include "content/public/common/web_preferences.h" |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 122 | #include "device/geolocation/geolocation_service_context.h" |
sammc | 5a139ba | 2016-09-29 01:49:14 | [diff] [blame] | 123 | #include "device/nfc/nfc.mojom.h" |
blundell | d46e883 | 2016-10-07 10:34:27 | [diff] [blame] | 124 | #include "device/wake_lock/wake_lock_service_context.h" |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 125 | #include "net/base/url_util.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 126 | #include "net/http/http_cache.h" |
| 127 | #include "net/http/http_transaction_factory.h" |
| 128 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 129 | #include "net/url_request/url_request_context_getter.h" |
rockot | 734fb66 | 2016-10-15 16:41:30 | [diff] [blame] | 130 | #include "services/service_manager/public/cpp/interface_provider.h" |
estark | 47ba9c7d | 2016-10-11 15:40:11 | [diff] [blame] | 131 | #include "third_party/WebKit/public/platform/WebSecurityStyle.h" |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 132 | #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 133 | #include "third_party/skia/include/core/SkBitmap.h" |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 134 | #include "ui/accessibility/ax_tree_combiner.h" |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 135 | #include "ui/base/layout.h" |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 136 | #include "ui/events/blink/web_input_event_traits.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 137 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 138 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 139 | #if defined(OS_ANDROID) |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 140 | #include "content/browser/android/content_video_view.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 141 | #include "content/browser/android/date_time_chooser_android.h" |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 142 | #include "content/browser/android/java_interfaces_impl.h" |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 143 | #include "content/browser/media/android/media_web_contents_observer_android.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 144 | #include "content/browser/web_contents/web_contents_android.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 145 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 146 | |
[email protected] | f66df82 | 2012-05-18 16:52:17 | [diff] [blame] | 147 | #if defined(OS_MACOSX) |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 148 | #include "base/mac/foundation_util.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 149 | #endif |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 150 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 151 | #if defined(USE_AURA) |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 152 | #include "content/browser/web_contents/web_contents_view_mus.h" |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 153 | #include "content/public/common/service_manager_connection.h" |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 154 | #include "ui/aura/mus/mus_util.h" |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 155 | #endif |
| 156 | |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 157 | #if defined(ENABLE_PLUGINS) |
| 158 | #include "content/browser/media/session/pepper_playback_observer.h" |
| 159 | #endif // ENABLE_PLUGINS |
| 160 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 161 | namespace content { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 162 | namespace { |
| 163 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 164 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 165 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 166 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 167 | #if defined(OS_ANDROID) |
| 168 | const char kWebContentsAndroidKey[] = "web_contents_android"; |
| 169 | #endif // OS_ANDROID |
| 170 | |
[email protected] | e4abd3b4 | 2013-11-12 18:28:47 | [diff] [blame] | 171 | base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 172 | g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| 173 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 174 | void NotifyCacheOnIO( |
| 175 | scoped_refptr<net::URLRequestContextGetter> request_context, |
| 176 | const GURL& url, |
| 177 | const std::string& http_method) { |
gunsch | e668855c | 2015-03-05 02:37:58 | [diff] [blame] | 178 | net::HttpCache* cache = request_context->GetURLRequestContext()-> |
| 179 | http_transaction_factory()->GetCache(); |
| 180 | if (cache) |
| 181 | cache->OnExternalCacheHit(url, http_method); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 182 | } |
| 183 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 184 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 185 | for (FrameTreeNode* node : tree->Nodes()) { |
| 186 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 187 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 188 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 189 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 190 | } |
| 191 | |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 192 | bool HasMatchingWidgetHost(FrameTree* tree, RenderWidgetHost* host) { |
| 193 | // This method scans the frame tree rather than checking whether |
| 194 | // host->delegate() == this, which allows it to return false when the host |
| 195 | // for a frame that is pending or pending deletion. |
| 196 | if (!host) |
| 197 | return false; |
| 198 | |
| 199 | for (FrameTreeNode* node : tree->Nodes()) { |
| 200 | if (node->current_frame_host()->GetRenderWidgetHost() == host) |
| 201 | return true; |
| 202 | } |
| 203 | return false; |
| 204 | } |
| 205 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 206 | void SetAccessibilityModeOnFrame(AccessibilityMode mode, |
| 207 | RenderFrameHost* frame_host) { |
| 208 | static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); |
| 209 | } |
| 210 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 211 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 212 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 213 | } |
| 214 | |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 215 | using AXTreeSnapshotCallback = |
| 216 | base::Callback<void(const ui::AXTreeUpdate&)>; |
| 217 | |
| 218 | // Helper class used by WebContentsImpl::RequestAXTreeSnapshot. |
| 219 | // Handles the callbacks from parallel snapshot requests to each frame, |
| 220 | // and feeds the results to an AXTreeCombiner, which converts them into a |
| 221 | // single combined accessibility tree. |
| 222 | class AXTreeSnapshotCombiner : public base::RefCounted<AXTreeSnapshotCombiner> { |
| 223 | public: |
| 224 | explicit AXTreeSnapshotCombiner(AXTreeSnapshotCallback callback) |
| 225 | : callback_(callback) { |
| 226 | } |
| 227 | |
| 228 | AXTreeSnapshotCallback AddFrame(bool is_root) { |
| 229 | // Adds a reference to |this|. |
| 230 | return base::Bind(&AXTreeSnapshotCombiner::ReceiveSnapshot, |
| 231 | this, |
| 232 | is_root); |
| 233 | } |
| 234 | |
| 235 | void ReceiveSnapshot(bool is_root, const ui::AXTreeUpdate& snapshot) { |
| 236 | combiner_.AddTree(snapshot, is_root); |
| 237 | } |
| 238 | |
| 239 | private: |
| 240 | friend class base::RefCounted<AXTreeSnapshotCombiner>; |
| 241 | |
| 242 | // This is called automatically after the last call to ReceiveSnapshot |
| 243 | // when there are no more references to this object. |
| 244 | ~AXTreeSnapshotCombiner() { |
| 245 | combiner_.Combine(); |
| 246 | callback_.Run(combiner_.combined()); |
| 247 | } |
| 248 | |
| 249 | ui::AXTreeCombiner combiner_; |
| 250 | AXTreeSnapshotCallback callback_; |
| 251 | }; |
| 252 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 253 | } // namespace |
| 254 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 255 | WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 256 | FrameTreeNode* opener_node = nullptr; |
| 257 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
| 258 | RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( |
| 259 | params.opener_render_process_id, params.opener_render_frame_id); |
| 260 | if (opener_rfh) |
| 261 | opener_node = opener_rfh->frame_tree_node(); |
| 262 | } |
| 263 | return WebContentsImpl::CreateWithOpener(params, opener_node); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 264 | } |
| 265 | |
| 266 | WebContents* WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 267 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 268 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 269 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 270 | |
| 271 | for (SessionStorageNamespaceMap::const_iterator it = |
| 272 | session_storage_namespace_map.begin(); |
| 273 | it != session_storage_namespace_map.end(); |
| 274 | ++it) { |
| 275 | new_contents->GetController() |
| 276 | .SetSessionStorageNamespace(it->first, it->second.get()); |
| 277 | } |
| 278 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 279 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 280 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 281 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 282 | |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 283 | void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting( |
| 284 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 285 | g_created_callbacks.Get().push_back(callback); |
| 286 | } |
| 287 | |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 288 | void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
| 289 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 290 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
| 291 | if (g_created_callbacks.Get().at(i).Equals(callback)) { |
| 292 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 293 | return; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 298 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
| 299 | if (!rvh) |
| 300 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 301 | return rvh->GetDelegate()->GetAsWebContents(); |
| 302 | } |
| 303 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 304 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 305 | if (!rfh) |
| 306 | return nullptr; |
| 307 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 308 | } |
| 309 | |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 310 | WebContents* WebContents::FromFrameTreeNodeId(int frame_tree_node_id) { |
| 311 | FrameTreeNode* frame_tree_node = |
| 312 | FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
ananta | b8cfa3b | 2016-10-14 22:43:19 | [diff] [blame] | 313 | if (!frame_tree_node) |
| 314 | return nullptr; |
ananta | 4b7467a5 | 2016-09-23 01:42:38 | [diff] [blame] | 315 | return FromRenderFrameHost(frame_tree_node->current_frame_host()); |
| 316 | } |
| 317 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 318 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 319 | |
| 320 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 321 | public: |
| 322 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
| 323 | : WebContentsObserver(watched_contents), |
| 324 | owner_(owner) { |
| 325 | } |
| 326 | |
| 327 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 328 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 329 | owner_->OnWebContentsDestroyed( |
| 330 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | private: |
| 334 | WebContentsImpl* owner_; |
| 335 | |
| 336 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 337 | }; |
| 338 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 339 | WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id, |
| 340 | int render_frame_id, |
| 341 | ColorChooser* chooser, |
| 342 | int identifier) |
| 343 | : render_process_id(render_process_id), |
| 344 | render_frame_id(render_frame_id), |
| 345 | chooser(chooser), |
| 346 | identifier(identifier) { |
| 347 | } |
| 348 | |
| 349 | WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { |
| 350 | } |
| 351 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 352 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
| 353 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() |
| 354 | : outer_web_contents_(nullptr), |
| 355 | outer_contents_frame_tree_node_id_( |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 356 | FrameTreeNode::kFrameTreeNodeInvalidId), |
| 357 | focused_web_contents_(nullptr) {} |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 358 | |
| 359 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
| 360 | // Remove child pointer from our parent. |
| 361 | if (outer_web_contents_) { |
| 362 | ChildrenSet& child_ptrs_in_parent = |
| 363 | outer_web_contents_->node_->inner_web_contents_tree_nodes_; |
| 364 | ChildrenSet::iterator iter = child_ptrs_in_parent.find(this); |
| 365 | DCHECK(iter != child_ptrs_in_parent.end()); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 366 | child_ptrs_in_parent.erase(iter); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | // Remove parent pointers from our children. |
| 370 | // TODO(lazyboy): We should destroy the children WebContentses too. If the |
| 371 | // children do not manage their own lifetime, then we would leak their |
| 372 | // WebContentses. |
| 373 | for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_) |
| 374 | child->outer_web_contents_ = nullptr; |
| 375 | } |
| 376 | |
| 377 | void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 378 | WebContentsImpl* outer_web_contents, |
| 379 | RenderFrameHostImpl* outer_contents_frame) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 380 | DCHECK(!focused_web_contents_) << "Should not attach a root node."; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 381 | outer_web_contents_ = outer_web_contents; |
| 382 | outer_contents_frame_tree_node_id_ = |
| 383 | outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 384 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 385 | if (!outer_web_contents_->node_) { |
| 386 | // This will only be reached when creating a new WebContents tree. |
| 387 | // Initialize the root of this tree and set it as focused. |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 388 | outer_web_contents_->node_.reset(new WebContentsTreeNode()); |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 389 | outer_web_contents_->node_->SetFocusedWebContents(outer_web_contents_); |
| 390 | } |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 391 | |
| 392 | outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this); |
| 393 | } |
| 394 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 395 | void WebContentsImpl::WebContentsTreeNode::SetFocusedWebContents( |
| 396 | WebContentsImpl* web_contents) { |
| 397 | DCHECK(!outer_web_contents()) |
| 398 | << "Only the outermost WebContents tracks focus."; |
| 399 | focused_web_contents_ = web_contents; |
| 400 | } |
| 401 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 402 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 403 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 404 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 405 | : delegate_(NULL), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 406 | controller_(this, browser_context), |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 407 | render_view_host_delegate_view_(NULL), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 408 | created_with_opener_(false), |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 409 | frame_tree_(new NavigatorImpl(&controller_, this), |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 410 | this, |
| 411 | this, |
| 412 | this, |
| 413 | this), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 414 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 415 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 416 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 417 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 418 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 419 | upload_size_(0), |
| 420 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 421 | is_resume_pending_(false), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 422 | has_accessed_initial_document_(false), |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 423 | theme_color_(SK_ColorTRANSPARENT), |
| 424 | last_sent_theme_color_(SK_ColorTRANSPARENT), |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 425 | did_first_visually_non_empty_paint_(false), |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 426 | capturer_count_(0), |
| 427 | should_normally_be_visible_(true), |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 428 | did_first_set_visible_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 429 | is_being_destroyed_(false), |
| 430 | notify_disconnection_(false), |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 431 | dialog_manager_(NULL), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 432 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 433 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 434 | closed_by_user_gesture_(false), |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 435 | minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 436 | maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 437 | zoom_scroll_remainder_(0), |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 438 | render_view_message_source_(NULL), |
mukai | 1db09376 | 2015-01-27 20:06:55 | [diff] [blame] | 439 | render_frame_message_source_(NULL), |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 440 | fullscreen_widget_process_id_(ChildProcessHost::kInvalidUniqueID), |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 441 | fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 442 | fullscreen_widget_had_focus_at_shutdown_(false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 443 | is_subframe_(false), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 444 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 445 | last_dialog_suppressed_(false), |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 446 | geolocation_service_context_(new device::GeolocationServiceContext()), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 447 | accessibility_mode_( |
| 448 | BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 449 | audio_stream_monitor_(this), |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 450 | bluetooth_connected_device_count_(0), |
mohan.reddy | aae039a | 2014-11-21 17:39:50 | [diff] [blame] | 451 | virtual_keyboard_requested_(false), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 452 | page_scale_factor_is_one_(true), |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 453 | mouse_lock_widget_(nullptr), |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 454 | is_overlay_content_(false), |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 455 | loading_weak_factory_(this), |
| 456 | weak_factory_(this) { |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 457 | frame_tree_.SetFrameRemoveListener( |
| 458 | base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 459 | base::Unretained(this))); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 460 | #if defined(OS_ANDROID) |
| 461 | media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); |
| 462 | #else |
qinmin | 58567c8 | 2015-01-07 21:00:20 | [diff] [blame] | 463 | media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 464 | #endif |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 465 | #if defined (ENABLE_PLUGINS) |
| 466 | pepper_playback_observer_.reset(new PepperPlaybackObserver(this)); |
| 467 | #endif |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 468 | loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
blundell | d46e883 | 2016-10-07 10:34:27 | [diff] [blame] | 469 | wake_lock_service_context_.reset(new device::WakeLockServiceContext( |
blundell | ebd7517 | 2016-10-03 10:41:43 | [diff] [blame] | 470 | BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE), |
| 471 | base::Bind(&WebContentsImpl::GetNativeView, base::Unretained(this)))); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 472 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 473 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 474 | WebContentsImpl::~WebContentsImpl() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 475 | is_being_destroyed_ = true; |
| 476 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 477 | rwh_input_event_router_.reset(); |
| 478 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 479 | for (auto& entry : binding_sets_) |
| 480 | entry.second->CloseAllBindings(); |
| 481 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 482 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 483 | if (GetFocusedWebContents() == this && this != outermost) { |
| 484 | // If the current WebContents is in focus, unset it. |
| 485 | outermost->node_->SetFocusedWebContents(outermost); |
| 486 | } |
| 487 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 488 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 489 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 490 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 491 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 492 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 493 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 494 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 495 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 496 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 497 | created_widgets_.clear(); |
| 498 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 499 | // Clear out any JavaScript state. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 500 | if (dialog_manager_) { |
| 501 | // This object is being destructed, so make sure that no callbacks happen. |
| 502 | dialog_manager_->CancelDialogs(this, |
| 503 | true, // suppress_callbacks, |
| 504 | true); // reset_state |
| 505 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 506 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 507 | if (color_chooser_info_.get()) |
| 508 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 509 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 510 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 511 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 512 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 513 | NotificationService::current()->Notify( |
| 514 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 515 | Source<WebContents>(this), |
| 516 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 517 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 518 | // Destroy all frame tree nodes except for the root; this notifies observers. |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 519 | frame_tree_.root()->ResetForNewProcess(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 520 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 521 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 522 | // Manually call the observer methods for the root frame tree node. It is |
| 523 | // necessary to manually delete all objects tracking navigations |
| 524 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 525 | // notified of these navigations stopping before the WebContents is |
| 526 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 527 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 528 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 529 | if (root->pending_frame_host()) { |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 530 | root->pending_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 531 | root->pending_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 532 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 533 | } |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 534 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 535 | root->current_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 536 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 537 | |
| 538 | // PlzNavigate: clear up state specific to browser-side navigation. |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 539 | if (IsBrowserSideNavigationEnabled()) { |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 540 | // Do not update state as the WebContents is being destroyed. |
| 541 | frame_tree_.root()->ResetNavigationRequest(true); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 542 | if (root->speculative_frame_host()) { |
| 543 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
| 544 | root->speculative_frame_host()->SetNavigationHandle( |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 545 | std::unique_ptr<NavigationHandleImpl>()); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 546 | } |
| 547 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 548 | |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 549 | #if defined(ENABLE_PLUGINS) |
| 550 | // Call this before WebContentsDestroyed() is broadcasted since |
| 551 | // AudioFocusManager will be destroyed after that. |
| 552 | pepper_playback_observer_.reset(); |
| 553 | #endif // defined(ENABLED_PLUGINS) |
| 554 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 555 | for (auto& observer : observers_) |
| 556 | observer.FrameDeleted(root->current_frame_host()); |
nasko | a83483fb | 2015-02-27 16:57:10 | [diff] [blame] | 557 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 558 | if (root->pending_render_view_host()) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 559 | for (auto& observer : observers_) |
| 560 | observer.RenderViewDeleted(root->pending_render_view_host()); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 561 | } |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 562 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 563 | for (auto& observer : observers_) |
| 564 | observer.RenderViewDeleted(root->current_host()); |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 565 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 566 | for (auto& observer : observers_) |
| 567 | observer.WebContentsDestroyed(); |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 568 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 569 | for (auto& observer : observers_) |
| 570 | observer.ResetWebContents(); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 571 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 572 | SetDelegate(NULL); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 573 | } |
| 574 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 575 | WebContentsImpl* WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 576 | const WebContents::CreateParams& params, |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 577 | FrameTreeNode* opener) { |
[email protected] | e11f0e9 | 2013-06-12 15:12:03 | [diff] [blame] | 578 | TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 579 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 580 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 581 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
| 582 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 583 | if (!params.opener_suppressed && opener) { |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 584 | new_root->SetOpener(opener); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 585 | new_contents->created_with_opener_ = true; |
| 586 | } |
| 587 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 588 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 589 | // flags, and these flags take effect immediately. An exception is if the |
| 590 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 591 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 592 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
| 593 | if (opener) { |
| 594 | blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags(); |
| 595 | const blink::WebSandboxFlags inherit_flag = |
| 596 | blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; |
| 597 | if ((opener_flags & inherit_flag) == inherit_flag) { |
| 598 | new_root->SetPendingSandboxFlags(opener_flags); |
| 599 | new_root->CommitPendingSandboxFlags(); |
| 600 | } |
| 601 | } |
| 602 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 603 | // This may be true even when opener is null, such as when opening blocked |
| 604 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 605 | if (params.created_with_opener) |
| 606 | new_contents->created_with_opener_ = true; |
| 607 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 608 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 609 | // This makes |new_contents| act as a guest. |
| 610 | // For more info, see comment above class BrowserPluginGuest. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 611 | BrowserPluginGuest::Create(new_contents, params.guest_delegate); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 612 | // We are instantiating a WebContents for browser plugin. Set its subframe |
| 613 | // bit to true. |
| 614 | new_contents->is_subframe_ = true; |
| 615 | } |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 616 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 617 | return new_contents; |
| 618 | } |
| 619 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 620 | // static |
| 621 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
| 622 | std::vector<WebContentsImpl*> result; |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 623 | std::unique_ptr<RenderWidgetHostIterator> widgets( |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 624 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 625 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 626 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 627 | if (!rvh) |
| 628 | continue; |
| 629 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 630 | if (!web_contents) |
| 631 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 632 | if (web_contents->GetRenderViewHost() != rvh) |
| 633 | continue; |
| 634 | // Because a WebContents can only have one current RVH at a time, there will |
| 635 | // be no duplicate WebContents here. |
| 636 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 637 | } |
| 638 | return result; |
| 639 | } |
| 640 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 641 | // static |
| 642 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
| 643 | FrameTreeNode* frame_tree_node) { |
| 644 | return static_cast<WebContentsImpl*>( |
| 645 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 646 | } |
| 647 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 648 | // static |
| 649 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 650 | int render_frame_host_id) { |
| 651 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 652 | RenderFrameHost* render_frame_host = |
| 653 | RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); |
| 654 | if (!render_frame_host) |
| 655 | return nullptr; |
| 656 | |
| 657 | return WebContents::FromRenderFrameHost(render_frame_host); |
| 658 | } |
| 659 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 660 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 661 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 662 | } |
| 663 | |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 664 | bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
| 665 | const IPC::Message& message) { |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 666 | return OnMessageReceived(render_view_host, NULL, message); |
| 667 | } |
| 668 | |
| 669 | bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
| 670 | RenderFrameHost* render_frame_host, |
| 671 | const IPC::Message& message) { |
| 672 | DCHECK(render_view_host || render_frame_host); |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 673 | if (GetWebUI() && |
| 674 | static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 675 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 676 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 677 | |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 678 | if (render_frame_host) { |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 679 | for (auto& observer : observers_) { |
| 680 | if (observer.OnMessageReceived(message, render_frame_host)) |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 681 | return true; |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 682 | } |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 683 | } else { |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 684 | for (auto& observer : observers_) { |
| 685 | if (observer.OnMessageReceived(message)) |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 686 | return true; |
dcheng | a2d442c2 | 2016-10-13 15:39:21 | [diff] [blame] | 687 | } |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 688 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 689 | |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 690 | // Message handlers should be aware of which |
| 691 | // RenderViewHost/RenderFrameHost sent the message, which is temporarily |
| 692 | // stored in render_(view|frame)_message_source_. |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 693 | if (render_frame_host) |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 694 | render_frame_message_source_ = render_frame_host; |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 695 | else |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 696 | render_view_message_source_ = render_view_host; |
| 697 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 698 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 699 | IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message) |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 700 | IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, |
| 701 | OnDomOperationResponse) |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 702 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 703 | OnThemeColorChanged) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 704 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 705 | OnDocumentLoadedInFrame) |
| 706 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
| 707 | IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 708 | IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
| 709 | IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
| 710 | OnSetSelectedColorInColorChooser) |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 711 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 712 | OnFirstVisuallyNonEmptyPaint) |
avi | 7830c85 | 2015-08-31 23:46:25 | [diff] [blame] | 713 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 714 | OnDidLoadResourceFromMemoryCache) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 715 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 716 | OnDidDisplayInsecureContent) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 717 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 718 | OnDidRunInsecureContent) |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 719 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, |
| 720 | OnDidDisplayContentWithCertificateErrors) |
| 721 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors, |
| 722 | OnDidRunContentWithCertificateErrors) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 723 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 724 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 725 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged, |
| 726 | OnPageScaleFactorChanged) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 727 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
avi | a23e16b | 2015-07-09 14:18:48 | [diff] [blame] | 728 | IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler, |
| 729 | OnRegisterProtocolHandler) |
| 730 | IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler, |
| 731 | OnUnregisterProtocolHandler) |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 732 | IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals, |
| 733 | OnUpdatePageImportanceSignals) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 734 | IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply) |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 735 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 736 | IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 737 | #if defined(ENABLE_PLUGINS) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 738 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 739 | OnPepperInstanceCreated) |
| 740 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 741 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 742 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 743 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStartsPlayback, |
| 744 | OnPepperStartsPlayback) |
| 745 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperStopsPlayback, |
| 746 | OnPepperStopsPlayback) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 747 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 748 | IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 749 | OnRequestPpapiBrokerPermission) |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 750 | IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 751 | OnBrowserPluginMessage(render_frame_host, |
| 752 | message)) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 753 | #endif |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 754 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 755 | IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, |
| 756 | OnShowValidationMessage) |
| 757 | IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, |
| 758 | OnHideValidationMessage) |
| 759 | IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, |
| 760 | OnMoveValidationMessage) |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 761 | #if defined(OS_ANDROID) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 762 | IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 763 | OnFindMatchRectsReply) |
paulmeyer | c8cb7cb | 2016-06-07 01:14:19 | [diff] [blame] | 764 | IPC_MESSAGE_HANDLER(FrameHostMsg_GetNearestFindResult_Reply, |
| 765 | OnGetNearestFindResultReply) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 766 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, |
| 767 | OnOpenDateTimeDialog) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 768 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 769 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 770 | IPC_END_MESSAGE_MAP() |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 771 | render_view_message_source_ = NULL; |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 772 | render_frame_message_source_ = NULL; |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 773 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 774 | return handled; |
| 775 | } |
| 776 | |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 777 | bool WebContentsImpl::HasValidFrameSource() { |
| 778 | if (!render_frame_message_source_) { |
| 779 | DCHECK(render_view_message_source_); |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 780 | bad_message::ReceivedBadMessage(GetRenderProcessHost(), |
| 781 | bad_message::WC_INVALID_FRAME_SOURCE); |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 782 | return false; |
| 783 | } |
| 784 | |
| 785 | return true; |
| 786 | } |
| 787 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 788 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 789 | return controller_; |
| 790 | } |
| 791 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 792 | const NavigationControllerImpl& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 793 | return controller_; |
| 794 | } |
| 795 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 796 | BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 797 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 798 | } |
| 799 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 800 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 801 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 802 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 803 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 804 | } |
| 805 | |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 806 | const GURL& WebContentsImpl::GetVisibleURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 807 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 808 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 809 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 810 | } |
| 811 | |
| 812 | const GURL& WebContentsImpl::GetLastCommittedURL() const { |
| 813 | // We may not have a navigation entry yet. |
| 814 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 815 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 816 | } |
| 817 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 818 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 819 | return delegate_; |
| 820 | } |
| 821 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 822 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 823 | // TODO(cbentzel): remove this debugging code? |
| 824 | if (delegate == delegate_) |
| 825 | return; |
| 826 | if (delegate_) |
| 827 | delegate_->Detach(this); |
| 828 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 829 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 830 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 831 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 832 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 833 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 834 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 837 | RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 838 | RenderViewHostImpl* host = GetRenderManager()->current_host(); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 839 | return host ? host->GetProcess() : NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 840 | } |
| 841 | |
clamy | df1975e | 2015-02-05 19:12:24 | [diff] [blame] | 842 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 843 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 844 | } |
| 845 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 846 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 847 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 848 | if (!focused_node) |
| 849 | return nullptr; |
| 850 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 851 | } |
| 852 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 853 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
| 854 | int frame_tree_node_id) { |
| 855 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 856 | return frame ? frame->current_frame_host() : nullptr; |
| 857 | } |
| 858 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 859 | void WebContentsImpl::ForEachFrame( |
| 860 | const base::Callback<void(RenderFrameHost*)>& on_frame) { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 861 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 862 | on_frame.Run(node->current_frame_host()); |
| 863 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 864 | } |
| 865 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 866 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
| 867 | std::vector<RenderFrameHost*> frame_hosts; |
| 868 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 869 | frame_hosts.push_back(node->current_frame_host()); |
| 870 | return frame_hosts; |
| 871 | } |
| 872 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 873 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 874 | int number_of_messages = 0; |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 875 | for (RenderFrameHost* rfh : GetAllFrames()) { |
lukasza | 1a9ab242 | 2016-03-02 18:47:25 | [diff] [blame] | 876 | if (!rfh->IsRenderFrameLive()) |
| 877 | continue; |
| 878 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 879 | ++number_of_messages; |
| 880 | IPC::Message* message_copy = new IPC::Message(*message); |
| 881 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 882 | rfh->Send(message_copy); |
| 883 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 884 | delete message; |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 885 | return number_of_messages; |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 886 | } |
| 887 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 888 | void WebContentsImpl::SendPageMessage(IPC::Message* msg) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 889 | frame_tree_.root()->render_manager()->SendPageMessage(msg, nullptr); |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 890 | } |
| 891 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 892 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 893 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 894 | } |
| 895 | |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 896 | int WebContentsImpl::GetRoutingID() const { |
| 897 | if (!GetRenderViewHost()) |
| 898 | return MSG_ROUTING_NONE; |
| 899 | |
| 900 | return GetRenderViewHost()->GetRoutingID(); |
| 901 | } |
| 902 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 903 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 904 | if (dialog_manager_) { |
| 905 | dialog_manager_->CancelDialogs(this, |
| 906 | false, // suppress_callbacks, |
| 907 | false); // reset_state |
| 908 | } |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 909 | if (browser_plugin_embedder_) |
| 910 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 911 | } |
| 912 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 913 | void WebContentsImpl::ClosePage() { |
| 914 | GetRenderViewHost()->ClosePage(); |
| 915 | } |
| 916 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 917 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 918 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 919 | } |
| 920 | |
lfg | 265a267 | 2016-04-23 03:11:02 | [diff] [blame] | 921 | RenderWidgetHostView* WebContentsImpl::GetTopLevelRenderWidgetHostView() { |
| 922 | if (GetOuterWebContents()) |
| 923 | return GetOuterWebContents()->GetTopLevelRenderWidgetHostView(); |
| 924 | return GetRenderManager()->GetRenderWidgetHostView(); |
| 925 | } |
| 926 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 927 | RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() |
| 928 | const { |
| 929 | RenderWidgetHost* const widget_host = |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 930 | RenderWidgetHostImpl::FromID(fullscreen_widget_process_id_, |
| 931 | fullscreen_widget_routing_id_); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 932 | return widget_host ? widget_host->GetView() : NULL; |
| 933 | } |
| 934 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 935 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 936 | return view_.get(); |
| 937 | } |
| 938 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 939 | SkColor WebContentsImpl::GetThemeColor() const { |
| 940 | return theme_color_; |
| 941 | } |
| 942 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 943 | void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) { |
| 944 | if (mode == accessibility_mode_) |
| 945 | return; |
| 946 | |
| 947 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 948 | |
| 949 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 950 | SetAccessibilityModeOnFrame(mode, node->current_frame_host()); |
| 951 | RenderFrameHost* pending_frame_host = |
| 952 | node->render_manager()->pending_frame_host(); |
| 953 | if (pending_frame_host) |
| 954 | SetAccessibilityModeOnFrame(mode, pending_frame_host); |
| 955 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 956 | } |
| 957 | |
| 958 | void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) { |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 959 | SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) { |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 963 | SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 964 | } |
| 965 | |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 966 | void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) { |
dmazzoni | d95ae84 | 2016-04-12 21:17:39 | [diff] [blame] | 967 | // Send a request to each of the frames in parallel. Each one will return |
| 968 | // an accessibility tree snapshot, and AXTreeSnapshotCombiner will combine |
| 969 | // them into a single tree and call |callback| with that result, then |
| 970 | // delete |combiner|. |
| 971 | AXTreeSnapshotCombiner* combiner = new AXTreeSnapshotCombiner(callback); |
| 972 | for (FrameTreeNode* frame_tree_node : frame_tree_.Nodes()) { |
| 973 | bool is_root = frame_tree_node->parent() == nullptr; |
| 974 | frame_tree_node->current_frame_host()->RequestAXTreeSnapshot( |
| 975 | combiner->AddFrame(is_root)); |
| 976 | } |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 977 | } |
| 978 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 979 | void WebContentsImpl::SetTemporaryZoomLevel(double level, |
| 980 | bool temporary_zoom_enabled) { |
| 981 | SendPageMessage(new PageMsg_SetZoomLevel( |
| 982 | MSG_ROUTING_NONE, |
| 983 | temporary_zoom_enabled ? PageMsg_SetZoomLevel_Command::SET_TEMPORARY |
| 984 | : PageMsg_SetZoomLevel_Command::CLEAR_TEMPORARY, |
| 985 | level)); |
| 986 | } |
| 987 | |
| 988 | void WebContentsImpl::UpdateZoom(double level) { |
| 989 | // Individual frames may still ignore the new zoom level if their RenderView |
| 990 | // contains a plugin document or if it uses a temporary zoom level. |
| 991 | SendPageMessage(new PageMsg_SetZoomLevel( |
| 992 | MSG_ROUTING_NONE, |
| 993 | PageMsg_SetZoomLevel_Command::USE_CURRENT_TEMPORARY_MODE, level)); |
| 994 | } |
| 995 | |
| 996 | void WebContentsImpl::UpdateZoomIfNecessary(const std::string& scheme, |
| 997 | const std::string& host, |
| 998 | double level) { |
| 999 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 1000 | if (!entry) |
| 1001 | return; |
| 1002 | |
| 1003 | GURL url = HostZoomMap::GetURLFromEntry(entry); |
| 1004 | if (host != net::GetHostOrSpecFromURL(url) || |
| 1005 | (!scheme.empty() && !url.SchemeIs(scheme))) { |
| 1006 | return; |
| 1007 | } |
| 1008 | |
| 1009 | UpdateZoom(level); |
| 1010 | } |
| 1011 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 1012 | base::Closure WebContentsImpl::AddBindingSet( |
| 1013 | const std::string& interface_name, |
| 1014 | WebContentsBindingSet* binding_set) { |
| 1015 | auto result = |
| 1016 | binding_sets_.insert(std::make_pair(interface_name, binding_set)); |
| 1017 | DCHECK(result.second); |
| 1018 | return base::Bind(&WebContentsImpl::RemoveBindingSet, |
| 1019 | weak_factory_.GetWeakPtr(), interface_name); |
| 1020 | } |
| 1021 | |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1022 | void WebContentsImpl::UpdateDeviceScaleFactor(double device_scale_factor) { |
| 1023 | SendPageMessage( |
| 1024 | new PageMsg_SetDeviceScaleFactor(MSG_ROUTING_NONE, device_scale_factor)); |
| 1025 | } |
| 1026 | |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 1027 | void WebContentsImpl::GetScreenInfo(ScreenInfo* screen_info) { |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1028 | if (GetView()) |
ccameron | 2f45153 | 2016-09-07 21:49:27 | [diff] [blame] | 1029 | GetView()->GetScreenInfo(screen_info); |
wjmaclean | 8a795f3 | 2016-08-11 23:49:58 | [diff] [blame] | 1030 | } |
| 1031 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame^] | 1032 | std::unique_ptr<WebUI> WebContentsImpl::CreateSubframeWebUI( |
| 1033 | const GURL& url, |
| 1034 | const std::string& frame_name) { |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 1035 | DCHECK(!frame_name.empty()); |
| 1036 | return CreateWebUI(url, frame_name); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1037 | } |
| 1038 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1039 | WebUI* WebContentsImpl::GetWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1040 | WebUI* commited_web_ui = GetCommittedWebUI(); |
| 1041 | return commited_web_ui ? commited_web_ui |
| 1042 | : GetRenderManager()->GetNavigatingWebUI(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1043 | } |
| 1044 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1045 | WebUI* WebContentsImpl::GetCommittedWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1046 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1047 | } |
| 1048 | |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1049 | void WebContentsImpl::SetUserAgentOverride(const std::string& override) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1050 | if (GetUserAgentOverride() == override) |
| 1051 | return; |
| 1052 | |
| 1053 | renderer_preferences_.user_agent_override = override; |
| 1054 | |
| 1055 | // Send the new override string to the renderer. |
| 1056 | RenderViewHost* host = GetRenderViewHost(); |
| 1057 | if (host) |
| 1058 | host->SyncRendererPrefs(); |
| 1059 | |
| 1060 | // Reload the page if a load is currently in progress to avoid having |
| 1061 | // different parts of the page loaded using different user agents. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 1062 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1063 | if (IsLoading() && entry != NULL && entry->GetIsOverridingUserAgent()) |
toyoshim | 7dad4b118 | 2016-04-01 14:28:05 | [diff] [blame] | 1064 | controller_.ReloadBypassingCache(true); |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 1065 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1066 | for (auto& observer : observers_) |
| 1067 | observer.UserAgentOverrideSet(override); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | const std::string& WebContentsImpl::GetUserAgentOverride() const { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 1071 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 1072 | } |
| 1073 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1074 | void WebContentsImpl::EnableTreeOnlyAccessibilityMode() { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1075 | if (GetAccessibilityMode() != AccessibilityModeOff) { |
| 1076 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 1077 | ResetAccessibility(rfh); |
| 1078 | } else { |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 1079 | AddAccessibilityMode(AccessibilityModeTreeOnly); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1080 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 1081 | } |
| 1082 | |
| 1083 | bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const { |
| 1084 | return accessibility_mode_ == AccessibilityModeTreeOnly; |
| 1085 | } |
| 1086 | |
| 1087 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
| 1088 | return accessibility_mode_ == AccessibilityModeComplete; |
| 1089 | } |
| 1090 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 1091 | const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const { |
| 1092 | return page_importance_signals_; |
| 1093 | } |
| 1094 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1095 | const base::string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 1096 | // Transient entries take precedence. They are used for interstitial pages |
| 1097 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1098 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1099 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1100 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1101 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 1102 | |
| 1103 | WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI(); |
| 1104 | WebUI* our_web_ui = navigating_web_ui |
| 1105 | ? navigating_web_ui |
| 1106 | : GetRenderManager()->current_frame_host()->web_ui(); |
| 1107 | |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1108 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1109 | // Don't override the title in view source mode. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1110 | entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1111 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1112 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1113 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1114 | if (!title.empty()) |
| 1115 | return title; |
| 1116 | } |
| 1117 | } |
| 1118 | |
| 1119 | // We use the title for the last committed entry rather than a pending |
| 1120 | // navigation entry. For example, when the user types in a URL, we want to |
| 1121 | // keep the old page's title until the new load has committed and we get a new |
| 1122 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1123 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1124 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 1125 | // We make an exception for initial navigations. We only want to use the title |
| 1126 | // from the visible entry if: |
| 1127 | // 1. The pending entry has been explicitly assigned a title to display. |
| 1128 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 1129 | // which case there is a pending entry index other than -1. |
| 1130 | // |
| 1131 | // Otherwise, we want to stick with the last committed entry's title during |
| 1132 | // new navigations, which have pending entries at index -1 with no title. |
| 1133 | if (controller_.IsInitialNavigation() && |
| 1134 | ((controller_.GetVisibleEntry() && |
| 1135 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 1136 | controller_.GetPendingEntryIndex() != -1)) { |
| 1137 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 1138 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 1139 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1140 | if (entry) { |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 1141 | return entry->GetTitleForDisplay(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 1142 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1143 | |
| 1144 | // |page_title_when_no_navigation_entry_| is finally used |
| 1145 | // if no title cannot be retrieved. |
| 1146 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1147 | } |
| 1148 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1149 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1150 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1151 | } |
| 1152 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1153 | SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const { |
| 1154 | RenderViewHostImpl* dest_rvh = |
| 1155 | GetRenderManager()->pending_render_view_host() ? |
| 1156 | GetRenderManager()->pending_render_view_host() : |
| 1157 | GetRenderManager()->current_host(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1158 | return dest_rvh->GetSiteInstance(); |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 1159 | } |
| 1160 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1161 | bool WebContentsImpl::IsLoading() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1162 | return frame_tree_.IsLoading() && |
| 1163 | !(ShowingInterstitialPage() && |
| 1164 | GetRenderManager()->interstitial_page()->pause_throbber()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1165 | } |
| 1166 | |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1167 | bool WebContentsImpl::IsLoadingToDifferentDocument() const { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 1168 | return IsLoading() && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1169 | } |
| 1170 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1171 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1172 | return waiting_for_response_ && is_load_to_different_document_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1173 | } |
| 1174 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1175 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1176 | return load_state_; |
| 1177 | } |
| 1178 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1179 | const base::string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1180 | return load_state_host_; |
| 1181 | } |
| 1182 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1183 | uint64_t WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1184 | return upload_size_; |
| 1185 | } |
| 1186 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1187 | uint64_t WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1188 | return upload_position_; |
| 1189 | } |
| 1190 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1191 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 1192 | return canonical_encoding_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1193 | } |
| 1194 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1195 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1196 | DCHECK(!is_being_destroyed_); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1197 | ++capturer_count_; |
| 1198 | DVLOG(1) << "There are now " << capturer_count_ |
| 1199 | << " capturing(s) of WebContentsImpl@" << this; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1200 | |
| 1201 | // Note: This provides a hint to upstream code to size the views optimally |
| 1202 | // for quality (e.g., to avoid scaling). |
| 1203 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1204 | preferred_size_for_capture_ = capture_size; |
| 1205 | OnPreferredSizeChanged(preferred_size_); |
| 1206 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1207 | |
| 1208 | // Ensure that all views are un-occluded before capture begins. |
| 1209 | WasUnOccluded(); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | void WebContentsImpl::DecrementCapturerCount() { |
| 1213 | --capturer_count_; |
| 1214 | DVLOG(1) << "There are now " << capturer_count_ |
| 1215 | << " capturing(s) of WebContentsImpl@" << this; |
| 1216 | DCHECK_LE(0, capturer_count_); |
| 1217 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1218 | if (is_being_destroyed_) |
| 1219 | return; |
| 1220 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1221 | if (capturer_count_ == 0) { |
| 1222 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1223 | preferred_size_for_capture_ = gfx::Size(); |
| 1224 | OnPreferredSizeChanged(old_size); |
| 1225 | } |
| 1226 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1227 | if (IsHidden()) { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1228 | DVLOG(1) << "Executing delayed WasHidden()."; |
| 1229 | WasHidden(); |
| 1230 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1231 | } |
| 1232 | |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1233 | int WebContentsImpl::GetCapturerCount() const { |
| 1234 | return capturer_count_; |
| 1235 | } |
| 1236 | |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1237 | bool WebContentsImpl::IsAudioMuted() const { |
| 1238 | return audio_muter_.get() && audio_muter_->is_muting(); |
| 1239 | } |
| 1240 | |
| 1241 | void WebContentsImpl::SetAudioMuted(bool mute) { |
| 1242 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1243 | << " for WebContentsImpl@" << this; |
| 1244 | |
| 1245 | if (mute == IsAudioMuted()) |
| 1246 | return; |
| 1247 | |
| 1248 | if (mute) { |
| 1249 | if (!audio_muter_) |
| 1250 | audio_muter_.reset(new WebContentsAudioMuter(this)); |
| 1251 | audio_muter_->StartMuting(); |
| 1252 | } else { |
| 1253 | DCHECK(audio_muter_); |
| 1254 | audio_muter_->StopMuting(); |
| 1255 | } |
| 1256 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1257 | for (auto& observer : observers_) |
| 1258 | observer.DidUpdateAudioMutingState(mute); |
wjmaclean | 2f797c78 | 2016-01-07 14:52:03 | [diff] [blame] | 1259 | |
erikchen | ab94f97 | 2016-10-11 01:34:58 | [diff] [blame] | 1260 | // Notification for UI updates in response to the changed muting state. |
| 1261 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1262 | } |
| 1263 | |
ortuno | df4d798 | 2016-04-08 02:33:35 | [diff] [blame] | 1264 | bool WebContentsImpl::IsConnectedToBluetoothDevice() const { |
| 1265 | return bluetooth_connected_device_count_ > 0; |
ortuno | 32e7db3c | 2016-03-29 16:14:20 | [diff] [blame] | 1266 | } |
| 1267 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1268 | bool WebContentsImpl::IsCrashed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1269 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 1270 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1271 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1272 | #if defined(OS_CHROMEOS) |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1273 | crashed_status_ == |
| 1274 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1275 | #endif |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1276 | crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1277 | ); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1278 | } |
| 1279 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1280 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1281 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1282 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1283 | return; |
| 1284 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1285 | crashed_status_ = status; |
| 1286 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1287 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1288 | } |
| 1289 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1290 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1291 | return crashed_status_; |
| 1292 | } |
| 1293 | |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 1294 | int WebContentsImpl::GetCrashedErrorCode() const { |
| 1295 | return crashed_error_code_; |
| 1296 | } |
| 1297 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1298 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1299 | return is_being_destroyed_; |
| 1300 | } |
| 1301 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1302 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1303 | InvalidateTypes changed_flags) { |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 1304 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1305 | // is fixed. |
| 1306 | tracked_objects::ScopedTracker tracking_profile( |
| 1307 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1308 | "466285 WebContentsImpl::NotifyNavigationStateChanged")); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1309 | // Notify the media observer of potential audibility changes. |
| 1310 | if (changed_flags & INVALIDATE_TYPE_TAB) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1311 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1312 | } |
| 1313 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1314 | if (delegate_) |
| 1315 | delegate_->NavigationStateChanged(this, changed_flags); |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 1316 | |
| 1317 | if (GetOuterWebContents()) |
| 1318 | GetOuterWebContents()->NotifyNavigationStateChanged(changed_flags); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1319 | } |
| 1320 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1321 | base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 1322 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1323 | } |
| 1324 | |
georgesak | 5582cbe | 2015-05-22 22:08:07 | [diff] [blame] | 1325 | void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) { |
| 1326 | last_active_time_ = last_active_time; |
| 1327 | } |
| 1328 | |
hajimehoshi | c4f226a | 2016-10-21 09:01:57 | [diff] [blame] | 1329 | base::TimeTicks WebContentsImpl::GetLastHiddenTime() const { |
| 1330 | return last_hidden_time_; |
| 1331 | } |
| 1332 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 1333 | void WebContentsImpl::WasShown() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1334 | controller_.SetActive(true); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1335 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1336 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1337 | if (view) { |
| 1338 | view->Show(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1339 | #if defined(OS_MACOSX) |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1340 | view->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1341 | #endif |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1342 | } |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1343 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1344 | |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1345 | SendPageMessage(new PageMsg_WasShown(MSG_ROUTING_NONE)); |
| 1346 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1347 | last_active_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 1348 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1349 | for (auto& observer : observers_) |
| 1350 | observer.WasShown(); |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1351 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1352 | should_normally_be_visible_ = true; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1353 | } |
| 1354 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1355 | void WebContentsImpl::WasHidden() { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1356 | // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1357 | // don't activate the "disable rendering" optimization. |
| 1358 | if (capturer_count_ == 0) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1359 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1360 | // open a tab in the background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1361 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1362 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1363 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1364 | // calls us). |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1365 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1366 | if (view) |
| 1367 | view->Hide(); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1368 | } |
lfg | 71715407 | 2016-06-30 15:04:16 | [diff] [blame] | 1369 | |
| 1370 | SendPageMessage(new PageMsg_WasHidden(MSG_ROUTING_NONE)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1371 | } |
| 1372 | |
hajimehoshi | c4f226a | 2016-10-21 09:01:57 | [diff] [blame] | 1373 | last_hidden_time_ = base::TimeTicks::Now(); |
| 1374 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1375 | for (auto& observer : observers_) |
| 1376 | observer.WasHidden(); |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1377 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1378 | should_normally_be_visible_ = false; |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 1379 | } |
| 1380 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1381 | void WebContentsImpl::WasOccluded() { |
| 1382 | if (capturer_count_ > 0) |
| 1383 | return; |
| 1384 | |
| 1385 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1386 | if (view) |
| 1387 | view->WasOccluded(); |
| 1388 | } |
| 1389 | } |
| 1390 | |
| 1391 | void WebContentsImpl::WasUnOccluded() { |
| 1392 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1393 | if (view) |
| 1394 | view->WasUnOccluded(); |
| 1395 | } |
| 1396 | } |
| 1397 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1398 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1399 | // TODO(creis): Should we fire even for interstitial pages? |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1400 | return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
| 1401 | !GetRenderViewHost()->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1402 | } |
| 1403 | |
nasko | 148bb0b9 | 2016-05-10 21:03:19 | [diff] [blame] | 1404 | void WebContentsImpl::DispatchBeforeUnload() { |
| 1405 | bool for_cross_site_transition = false; |
clamy | bfd6a81 | 2016-05-30 16:25:17 | [diff] [blame] | 1406 | GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition, false); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1407 | } |
| 1408 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1409 | void WebContentsImpl::AttachToOuterWebContentsFrame( |
| 1410 | WebContents* outer_web_contents, |
| 1411 | RenderFrameHost* outer_contents_frame) { |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 1412 | CHECK(GuestMode::IsCrossProcessFrameGuest(this)); |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1413 | RenderFrameHostManager* render_manager = GetRenderManager(); |
| 1414 | |
| 1415 | // When the WebContents being initialized has an opener, the browser side |
| 1416 | // Render{View,Frame}Host must be initialized and the RenderWidgetHostView |
| 1417 | // created. This is needed because the usual initialization happens during |
| 1418 | // the first navigation, but when attaching a new window we don't navigate |
| 1419 | // before attaching. If the browser side is already initialized, the calls |
| 1420 | // below will just early return. |
| 1421 | render_manager->InitRenderView(GetRenderViewHost(), nullptr); |
| 1422 | GetMainFrame()->Init(); |
| 1423 | if (!render_manager->GetRenderWidgetHostView()) |
| 1424 | CreateRenderWidgetHostViewForRenderManager(GetRenderViewHost()); |
| 1425 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1426 | // Create a link to our outer WebContents. |
| 1427 | node_.reset(new WebContentsTreeNode()); |
| 1428 | node_->ConnectToOuterWebContents( |
| 1429 | static_cast<WebContentsImpl*>(outer_web_contents), |
| 1430 | static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1431 | |
| 1432 | DCHECK(outer_contents_frame); |
| 1433 | |
| 1434 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 1435 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 1436 | // postMessage to the inner WebContents. |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1437 | render_manager->CreateOuterDelegateProxy( |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1438 | outer_contents_frame->GetSiteInstance(), |
| 1439 | static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1440 | |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1441 | render_manager->SetRWHViewForInnerContents( |
| 1442 | render_manager->GetRenderWidgetHostView()); |
wjmaclean | fab616a | 2016-03-02 18:40:39 | [diff] [blame] | 1443 | |
| 1444 | static_cast<RenderWidgetHostViewChildFrame*>( |
lfg | 91a79e1 | 2016-04-01 23:52:19 | [diff] [blame] | 1445 | render_manager->GetRenderWidgetHostView()) |
fsamuel | b6acafa | 2016-10-04 03:21:52 | [diff] [blame] | 1446 | ->RegisterFrameSinkId(); |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 1447 | |
| 1448 | // At this point, we should destroy the TextInputManager which will notify all |
| 1449 | // the RWHV in this WebContents. The RWHV in this WebContents should use the |
| 1450 | // TextInputManager owned by the outer WebContents. |
| 1451 | // TODO(ekaramad): Is it possible to have TextInputState before attaching to |
| 1452 | // outer WebContents? In such a case, is this still the right way to hand off |
| 1453 | // state tracking from inner WebContents's TextInputManager to that of the |
| 1454 | // outer WebContent (crbug.com/609846)? |
| 1455 | text_input_manager_.reset(nullptr); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1456 | } |
| 1457 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1458 | void WebContentsImpl::Stop() { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1459 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 1460 | node->StopLoading(); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1461 | for (auto& observer : observers_) |
| 1462 | observer.NavigationStopped(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1463 | } |
| 1464 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1465 | WebContents* WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1466 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1467 | // 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] | 1468 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1469 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1470 | create_params.initial_size = GetContainerBounds().size(); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1471 | WebContentsImpl* tc = |
| 1472 | CreateWithOpener(create_params, frame_tree_.root()->opener()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1473 | tc->GetController().CopyStateFrom(controller_); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1474 | for (auto& observer : observers_) |
| 1475 | observer.DidCloneToNewWebContents(this, tc); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1476 | return tc; |
| 1477 | } |
| 1478 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1479 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1480 | const NotificationSource& source, |
| 1481 | const NotificationDetails& details) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1482 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1483 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1484 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1485 | RenderWidgetHostView* view = host->GetView(); |
| 1486 | if (view == GetFullscreenRenderWidgetHostView()) { |
| 1487 | // We cannot just call view_->RestoreFocus() here. On some platforms, |
| 1488 | // attempting to focus the currently-invisible WebContentsView will be |
| 1489 | // flat-out ignored. Therefore, this boolean is used to track whether |
| 1490 | // we will request focus after the fullscreen widget has been |
| 1491 | // destroyed. |
| 1492 | fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
| 1493 | } else { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 1494 | for (auto i = pending_widget_views_.begin(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1495 | i != pending_widget_views_.end(); ++i) { |
| 1496 | if (host->GetView() == i->second) { |
| 1497 | pending_widget_views_.erase(i); |
| 1498 | break; |
| 1499 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1500 | } |
| 1501 | } |
| 1502 | break; |
| 1503 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1504 | default: |
| 1505 | NOTREACHED(); |
| 1506 | } |
| 1507 | } |
| 1508 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 1509 | WebContents* WebContentsImpl::GetWebContents() { |
| 1510 | return this; |
| 1511 | } |
| 1512 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1513 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1514 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1515 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1516 | // it should be hidden. |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1517 | should_normally_be_visible_ = !params.initially_hidden; |
| 1518 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1519 | // The routing ids must either all be set or all be unset. |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1520 | DCHECK((params.routing_id == MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1521 | params.main_frame_routing_id == MSG_ROUTING_NONE && |
| 1522 | params.main_frame_widget_routing_id == MSG_ROUTING_NONE) || |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1523 | (params.routing_id != MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1524 | params.main_frame_routing_id != MSG_ROUTING_NONE && |
| 1525 | params.main_frame_widget_routing_id != MSG_ROUTING_NONE)); |
| 1526 | |
| 1527 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 1528 | if (!site_instance) |
| 1529 | site_instance = SiteInstance::Create(params.browser_context); |
| 1530 | |
| 1531 | // A main RenderFrameHost always has a RenderWidgetHost, since it is always a |
| 1532 | // local root by definition. |
| 1533 | // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no |
| 1534 | // longer be necessary to eagerly grab a routing ID for the view. |
| 1535 | // https://crbug.com/545684 |
| 1536 | int32_t view_routing_id = params.routing_id; |
| 1537 | int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id; |
| 1538 | if (main_frame_widget_routing_id == MSG_ROUTING_NONE) { |
| 1539 | view_routing_id = main_frame_widget_routing_id = |
| 1540 | site_instance->GetProcess()->GetNextRoutingID(); |
| 1541 | } |
| 1542 | |
| 1543 | GetRenderManager()->Init(site_instance.get(), view_routing_id, |
| 1544 | params.main_frame_routing_id, |
| 1545 | main_frame_widget_routing_id); |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 1546 | |
lukasza | 5140a41 | 2016-09-15 21:12:30 | [diff] [blame] | 1547 | // blink::FrameTree::setName always keeps |unique_name| empty in case of a |
| 1548 | // main frame - let's do the same thing here. |
| 1549 | std::string unique_name; |
lukasza | 464d869 | 2016-02-22 19:26:32 | [diff] [blame] | 1550 | frame_tree_.root()->SetFrameName(params.main_frame_name, unique_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1551 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1552 | WebContentsViewDelegate* delegate = |
| 1553 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 1554 | |
sadrul | 943e3b3 | 2016-08-04 18:22:59 | [diff] [blame] | 1555 | #if defined(USE_AURA) |
ben | d32292b | 2016-10-07 00:21:58 | [diff] [blame] | 1556 | if (ServiceManagerConnection::GetForProcess() && |
fsamuel | adb003360 | 2015-12-09 19:20:41 | [diff] [blame] | 1557 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1558 | switches::kUseMusInRenderer)) { |
ben | 3a06a27 | 2016-07-04 05:00:10 | [diff] [blame] | 1559 | ui::Window* mus_window = aura::GetMusWindow(params.context); |
fsamuel | adb003360 | 2015-12-09 19:20:41 | [diff] [blame] | 1560 | if (mus_window) { |
| 1561 | view_.reset(new WebContentsViewMus(mus_window, this, delegate, |
| 1562 | &render_view_host_delegate_view_)); |
| 1563 | } |
| 1564 | } |
| 1565 | #endif |
| 1566 | |
| 1567 | if (!view_) { |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 1568 | if (GuestMode::IsCrossProcessFrameGuest(this)) { |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 1569 | view_.reset(new WebContentsViewChildFrame( |
| 1570 | this, delegate, &render_view_host_delegate_view_)); |
| 1571 | } else { |
| 1572 | view_.reset(CreateWebContentsView(this, delegate, |
| 1573 | &render_view_host_delegate_view_)); |
| 1574 | } |
fsamuel | adb003360 | 2015-12-09 19:20:41 | [diff] [blame] | 1575 | } |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1576 | |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 1577 | if (browser_plugin_guest_ && !GuestMode::IsCrossProcessFrameGuest(this)) { |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1578 | view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(), |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 1579 | std::move(view_), |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1580 | &render_view_host_delegate_view_)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1581 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1582 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1583 | CHECK(view_.get()); |
| 1584 | |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 1585 | gfx::Size initial_size = params.initial_size; |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1586 | view_->CreateView(initial_size, params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1587 | |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 1588 | #if defined(ENABLE_PLUGINS) |
| 1589 | plugin_content_origin_whitelist_.reset( |
| 1590 | new PluginContentOriginWhitelist(this)); |
| 1591 | #endif |
| 1592 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1593 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1594 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1595 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 1596 | |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 1597 | screen_orientation_dispatcher_host_.reset( |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 1598 | new ScreenOrientationDispatcherHostImpl(this)); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 1599 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 1600 | manifest_manager_host_.reset(new ManifestManagerHost(this)); |
| 1601 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 1602 | #if defined(OS_ANDROID) |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 1603 | date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 1604 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 1605 | |
| 1606 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
| 1607 | // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
| 1608 | if (browser_plugin_guest_) |
| 1609 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 1610 | |
| 1611 | for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 1612 | g_created_callbacks.Get().at(i).Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1613 | |
| 1614 | // If the WebContents creation was renderer-initiated, it means that the |
| 1615 | // corresponding RenderView and main RenderFrame have already been created. |
| 1616 | // Ensure observers are notified about this. |
| 1617 | if (params.renderer_initiated_creation) { |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 1618 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1619 | RenderViewCreated(GetRenderViewHost()); |
| 1620 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 1621 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 1622 | |
lof84 | 501da08 | 2016-05-23 21:22:54 | [diff] [blame] | 1623 | // Create the renderer process in advance if requested. |
| 1624 | if (params.initialize_renderer) { |
| 1625 | if (!GetRenderManager()->current_frame_host()->IsRenderFrameLive()) { |
| 1626 | GetRenderManager()->InitRenderView(GetRenderViewHost(), nullptr); |
| 1627 | } |
| 1628 | } |
| 1629 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 1630 | // Ensure that observers are notified of the creation of this WebContents's |
| 1631 | // main RenderFrameHost. It must be done here for main frames, since the |
| 1632 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 1633 | // happens after RenderFrameHostManager::Init. |
| 1634 | NotifySwappedFromRenderManager( |
| 1635 | nullptr, GetRenderManager()->current_frame_host(), true); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1636 | } |
| 1637 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1638 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 1639 | RemoveDestructionObserver(web_contents); |
| 1640 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1641 | // Clear a pending contents that has been closed before being shown. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 1642 | for (auto iter = pending_contents_.begin(); iter != pending_contents_.end(); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1643 | ++iter) { |
| 1644 | if (iter->second != web_contents) |
| 1645 | continue; |
| 1646 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1647 | return; |
| 1648 | } |
| 1649 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1650 | } |
| 1651 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1652 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
| 1653 | if (!ContainsKey(destruction_observers_, web_contents)) { |
| 1654 | destruction_observers_[web_contents] = |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 1655 | base::MakeUnique<DestructionObserver>(this, web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1656 | } |
| 1657 | } |
| 1658 | |
| 1659 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
avi | a8cf8198 | 2016-08-12 20:28:46 | [diff] [blame] | 1660 | destruction_observers_.erase(web_contents); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1661 | } |
| 1662 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1663 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1664 | observers_.AddObserver(observer); |
| 1665 | } |
| 1666 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1667 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1668 | observers_.RemoveObserver(observer); |
| 1669 | } |
| 1670 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1671 | std::set<RenderWidgetHostView*> |
| 1672 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 1673 | std::set<RenderWidgetHostView*> set; |
| 1674 | if (ShowingInterstitialPage()) { |
| 1675 | set.insert(GetRenderWidgetHostView()); |
| 1676 | } else { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1677 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 1678 | RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 1679 | ->frame_tree_node() |
| 1680 | ->render_manager() |
| 1681 | ->GetRenderWidgetHostView(); |
| 1682 | set.insert(rwhv); |
| 1683 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1684 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1685 | return set; |
| 1686 | } |
| 1687 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1688 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1689 | if (delegate_) |
| 1690 | delegate_->ActivateContents(this); |
| 1691 | } |
| 1692 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1693 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
| 1694 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1695 | return; |
| 1696 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1697 | if (delegate_) |
| 1698 | delegate_->LostCapture(); |
| 1699 | } |
| 1700 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1701 | void WebContentsImpl::RenderWidgetCreated( |
| 1702 | RenderWidgetHostImpl* render_widget_host) { |
| 1703 | created_widgets_.insert(render_widget_host); |
| 1704 | } |
| 1705 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1706 | void WebContentsImpl::RenderWidgetDeleted( |
| 1707 | RenderWidgetHostImpl* render_widget_host) { |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1708 | // Note that |is_being_destroyed_| can be true at this point as |
| 1709 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 1710 | // us here. |
| 1711 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1712 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1713 | if (is_being_destroyed_) |
| 1714 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1715 | |
| 1716 | if (render_widget_host && |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 1717 | render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_ && |
| 1718 | render_widget_host->GetProcess()->GetID() == |
| 1719 | fullscreen_widget_process_id_) { |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1720 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1721 | delegate_->ExitFullscreenModeForTab(this); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1722 | for (auto& observer : observers_) |
| 1723 | observer.DidDestroyFullscreenWidget(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 1724 | fullscreen_widget_process_id_ = ChildProcessHost::kInvalidUniqueID; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1725 | fullscreen_widget_routing_id_ = MSG_ROUTING_NONE; |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1726 | if (fullscreen_widget_had_focus_at_shutdown_) |
| 1727 | view_->RestoreFocus(); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1728 | } |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1729 | |
lfg | ff8dfc8d | 2016-10-21 17:42:32 | [diff] [blame] | 1730 | if (mouse_lock_widget_) |
| 1731 | LostMouseLock(mouse_lock_widget_); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1732 | } |
| 1733 | |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1734 | void WebContentsImpl::RenderWidgetGotFocus( |
| 1735 | RenderWidgetHostImpl* render_widget_host) { |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 1736 | // Notify the observers if an embedded fullscreen widget was focused. |
| 1737 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 1738 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
| 1739 | NotifyWebContentsFocused(); |
| 1740 | } |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1741 | } |
| 1742 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1743 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 1744 | RenderWidgetHostImpl* render_widget_host, |
| 1745 | bool width_changed) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1746 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 1747 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1748 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1749 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1750 | for (auto& observer : observers_) |
| 1751 | observer.MainFrameWasResized(width_changed); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1752 | } |
| 1753 | |
paulmeyer | 9ef6e446 | 2015-02-24 19:15:10 | [diff] [blame] | 1754 | void WebContentsImpl::ScreenInfoChanged() { |
| 1755 | if (browser_plugin_embedder_) |
| 1756 | browser_plugin_embedder_->ScreenInfoChanged(); |
| 1757 | } |
| 1758 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1759 | bool WebContentsImpl::PreHandleKeyboardEvent( |
| 1760 | const NativeWebKeyboardEvent& event, |
| 1761 | bool* is_keyboard_shortcut) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1762 | return delegate_ && |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1763 | delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1764 | } |
| 1765 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1766 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 1767 | if (browser_plugin_embedder_ && |
| 1768 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
| 1769 | return; |
| 1770 | } |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1771 | if (delegate_) |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1772 | delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1773 | } |
| 1774 | |
[email protected] | d92026ef | 2014-03-03 21:04:13 | [diff] [blame] | 1775 | bool WebContentsImpl::HandleWheelEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1776 | const blink::WebMouseWheelEvent& event) { |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1777 | #if !defined(OS_MACOSX) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1778 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 1779 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1780 | // -the OS already has a gesture to do this through pinch-zoom |
| 1781 | // -if a user starts an inertial scroll, let's go, and presses control |
| 1782 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 1783 | // with control key set which isn't what the user wants |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1784 | if (delegate_ && event.wheelTicksY && |
chongz | 4a975194 | 2016-08-17 17:49:39 | [diff] [blame] | 1785 | !ui::WebInputEventTraits::CanCauseScroll(event)) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 1786 | // Count only integer cumulative scrolls as zoom events; this handles |
| 1787 | // smooth scroll and regular scroll device behavior. |
| 1788 | zoom_scroll_remainder_ += event.wheelTicksY; |
| 1789 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 1790 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 1791 | if (whole_zoom_scroll_remainder_ != 0) { |
| 1792 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 1793 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1794 | return true; |
| 1795 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1796 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1797 | return false; |
| 1798 | } |
| 1799 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1800 | bool WebContentsImpl::PreHandleGestureEvent( |
| 1801 | const blink::WebGestureEvent& event) { |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 1802 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1803 | } |
| 1804 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1805 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 1806 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 1807 | return GetOuterWebContents()->GetInputEventRouter(); |
| 1808 | |
| 1809 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1810 | rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter); |
| 1811 | return rwh_input_event_router_.get(); |
| 1812 | } |
| 1813 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 1814 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
| 1815 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 1816 | // send the message in this case, as the main frame's RenderFrameHost and |
| 1817 | // other state has already been cleared. |
| 1818 | if (is_being_destroyed_) |
| 1819 | return; |
| 1820 | |
| 1821 | frame_tree_.ReplicatePageFocus(is_focused); |
| 1822 | } |
| 1823 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1824 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 1825 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1826 | if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1827 | return receiving_widget; |
| 1828 | |
| 1829 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 1830 | // forwarded directly to the widget they arrived on. |
| 1831 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 1832 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1833 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 1834 | FrameTreeNode* focused_frame = |
| 1835 | GetFocusedWebContents()->frame_tree_.GetFocusedFrame(); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1836 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1837 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1838 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 1839 | // The view may be null if a subframe's renderer process has crashed while |
| 1840 | // the subframe has focus. Drop the event in that case. Do not give |
| 1841 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1842 | // wrong frame if a focused subframe renderer crashes while they type. |
| 1843 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1844 | if (!view) |
| 1845 | return nullptr; |
| 1846 | |
| 1847 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1848 | } |
| 1849 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1850 | void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 1851 | // This method is being called to enter renderer-initiated fullscreen mode. |
| 1852 | // Make sure any existing fullscreen widget is shut down first. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1853 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 1854 | if (widget_view) { |
| 1855 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1856 | ->ShutdownAndDestroyWidget(true); |
| 1857 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1858 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1859 | if (delegate_) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1860 | delegate_->EnterFullscreenModeForTab(this, origin); |
| 1861 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1862 | for (auto& observer : observers_) |
| 1863 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), false); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1864 | } |
| 1865 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1866 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1867 | // This method is being called to leave renderer-initiated fullscreen mode. |
| 1868 | // Make sure any existing fullscreen widget is shut down first. |
| 1869 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 1870 | if (widget_view) { |
| 1871 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1872 | ->ShutdownAndDestroyWidget(true); |
| 1873 | } |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1874 | |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 1875 | #if defined(OS_ANDROID) |
| 1876 | ContentVideoView* video_view = ContentVideoView::GetInstance(); |
| 1877 | if (video_view != NULL) |
watk | 9829229 | 2016-01-19 22:24:08 | [diff] [blame] | 1878 | video_view->ExitFullscreen(); |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 1879 | #endif |
| 1880 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1881 | if (delegate_) |
| 1882 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 1883 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1884 | // The fullscreen state is communicated to the renderer through a resize |
| 1885 | // message. If the change in fullscreen state doesn't cause a view resize |
| 1886 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 1887 | // sending a resize message. This is required for the situation of the browser |
| 1888 | // moving the view into a "browser fullscreen" state and then the contents |
| 1889 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 1890 | // have the side effect of the view resizing, hence the explicit call here is |
| 1891 | // required. |
| 1892 | if (!will_cause_resize) { |
| 1893 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 1894 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
| 1895 | render_widget_host->WasResized(); |
| 1896 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 1897 | } |
| 1898 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 1899 | for (auto& observer : observers_) { |
| 1900 | observer.DidToggleFullscreenModeForTab(IsFullscreenForCurrentTab(), |
| 1901 | will_cause_resize); |
| 1902 | } |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1903 | } |
| 1904 | |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 1905 | bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 1906 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1907 | } |
| 1908 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 1909 | blink::WebDisplayMode WebContentsImpl::GetDisplayMode( |
| 1910 | RenderWidgetHostImpl* render_widget_host) const { |
| 1911 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1912 | return blink::WebDisplayModeBrowser; |
| 1913 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 1914 | return delegate_ ? delegate_->GetDisplayMode(this) |
| 1915 | : blink::WebDisplayModeBrowser; |
| 1916 | } |
| 1917 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1918 | void WebContentsImpl::RequestToLockMouse( |
| 1919 | RenderWidgetHostImpl* render_widget_host, |
| 1920 | bool user_gesture, |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 1921 | bool last_unlocked_by_target, |
| 1922 | bool privileged) { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1923 | if (mouse_lock_widget_) { |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1924 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 1925 | return; |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1926 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1927 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 1928 | if (privileged) { |
| 1929 | mouse_lock_widget_ = render_widget_host; |
| 1930 | render_widget_host->GotResponseToLockMouseRequest(true); |
| 1931 | return; |
| 1932 | } |
| 1933 | |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1934 | bool widget_in_frame_tree = false; |
| 1935 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 1936 | if (node->current_frame_host()->GetRenderWidgetHost() == |
| 1937 | render_widget_host) { |
| 1938 | widget_in_frame_tree = true; |
| 1939 | break; |
| 1940 | } |
| 1941 | } |
| 1942 | |
| 1943 | if (widget_in_frame_tree && delegate_) { |
| 1944 | mouse_lock_widget_ = render_widget_host; |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1945 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1946 | } else { |
| 1947 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 1948 | } |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1949 | } |
| 1950 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1951 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 1952 | CHECK(mouse_lock_widget_); |
| 1953 | mouse_lock_widget_->SendMouseLockLost(); |
| 1954 | mouse_lock_widget_ = nullptr; |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1955 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1956 | if (delegate_) |
| 1957 | delegate_->LostMouseLock(); |
| 1958 | } |
| 1959 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 1960 | bool WebContentsImpl::HasMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 1961 | // To verify if the mouse is locked, the mouse_lock_widget_ needs to be |
| 1962 | // assigned to the widget that requested the mouse lock, and the top-level |
| 1963 | // platform RenderWidgetHostView needs to hold the mouse lock from the OS. |
| 1964 | return mouse_lock_widget_ == render_widget_host && |
| 1965 | GetTopLevelRenderWidgetHostView()->IsMouseLocked(); |
| 1966 | } |
| 1967 | |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 1968 | void WebContentsImpl::ForwardCompositorProto( |
| 1969 | RenderWidgetHostImpl* render_widget_host, |
| 1970 | const std::vector<uint8_t>& proto) { |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 1971 | if (delegate_) |
khushalsagar | 6b649b90 | 2016-02-23 00:23:29 | [diff] [blame] | 1972 | delegate_->ForwardCompositorProto(render_widget_host, proto); |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 1973 | } |
| 1974 | |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 1975 | void WebContentsImpl::OnRenderFrameProxyVisibilityChanged(bool visible) { |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 1976 | if (visible && !GetOuterWebContents()->IsHidden()) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 1977 | WasShown(); |
lfg | 9462cef | 2016-07-18 23:51:06 | [diff] [blame] | 1978 | else if (!visible) |
ekaramad | a4f4269 | 2016-02-11 19:48:37 | [diff] [blame] | 1979 | WasHidden(); |
| 1980 | } |
| 1981 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1982 | void WebContentsImpl::CreateNewWindow( |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1983 | SiteInstance* source_site_instance, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1984 | int32_t route_id, |
| 1985 | int32_t main_frame_route_id, |
| 1986 | int32_t main_frame_widget_route_id, |
rockot | 5c478a7 | 2016-09-28 23:14:18 | [diff] [blame] | 1987 | const mojom::CreateNewWindowParams& params, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 1988 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1989 | // We usually create the new window in the same BrowsingInstance (group of |
| 1990 | // script-related windows), by passing in the current SiteInstance. However, |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1991 | // if the opener is being suppressed (in a non-guest), we create a new |
| 1992 | // SiteInstance in its own BrowsingInstance. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 1993 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1994 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 1995 | // If the opener is to be suppressed, the new window can be in any process. |
| 1996 | // Since routing ids are process specific, we must not have one passed in |
| 1997 | // as argument here. |
| 1998 | DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
| 1999 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2000 | scoped_refptr<SiteInstance> site_instance = |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2001 | params.opener_suppressed && !is_guest |
| 2002 | ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) |
| 2003 | : source_site_instance; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2004 | |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2005 | // A message to create a new window can only come from a process for a frame |
| 2006 | // in this WebContents' FrameTree. If any other process sends the request, it |
| 2007 | // is invalid and the process must be terminated. |
| 2008 | int render_process_id = source_site_instance->GetProcess()->GetID(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2009 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2010 | RenderProcessHost* rph = source_site_instance->GetProcess(); |
jaekyun | 37e572a3 | 2014-12-04 23:33:35 | [diff] [blame] | 2011 | base::ProcessHandle process_handle = rph->GetHandle(); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2012 | if (process_handle != base::kNullProcessHandle) { |
| 2013 | RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 2014 | base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); |
jaekyun | 37e572a3 | 2014-12-04 23:33:35 | [diff] [blame] | 2015 | rph->Shutdown(RESULT_CODE_KILLED, false); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 2016 | } |
| 2017 | return; |
| 2018 | } |
| 2019 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2020 | // We must assign the SessionStorageNamespace before calling Init(). |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 2021 | // |
| 2022 | // http://crbug.com/142685 |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 2023 | const std::string& partition_id = |
| 2024 | GetContentClient()->browser()-> |
| 2025 | GetStoragePartitionIdForSite(GetBrowserContext(), |
| 2026 | site_instance->GetSiteURL()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2027 | StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 2028 | GetBrowserContext(), site_instance.get()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 2029 | DOMStorageContextWrapper* dom_storage_context = |
| 2030 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2031 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 2032 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 2033 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2034 | |
| 2035 | if (delegate_ && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2036 | !delegate_->ShouldCreateWebContents( |
| 2037 | this, route_id, main_frame_route_id, main_frame_widget_route_id, |
| 2038 | params.window_container_type, params.frame_name, params.target_url, |
| 2039 | partition_id, session_storage_namespace)) { |
[email protected] | f1cd336 | 2014-01-07 20:43:01 | [diff] [blame] | 2040 | if (route_id != MSG_ROUTING_NONE && |
| 2041 | !RenderViewHost::FromID(render_process_id, route_id)) { |
| 2042 | // If the embedder didn't create a WebContents for this route, we need to |
| 2043 | // delete the RenderView that had already been created. |
| 2044 | Send(new ViewMsg_Close(route_id)); |
| 2045 | } |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 2046 | // It's safe to only target the frame because the render process will not |
| 2047 | // have a chance to create more frames at this point. |
| 2048 | ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
| 2049 | GlobalFrameRoutingId(render_process_id, main_frame_route_id)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 2050 | return; |
| 2051 | } |
| 2052 | |
| 2053 | // Create the new web contents. This will automatically create the new |
| 2054 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 2055 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 2056 | create_params.routing_id = route_id; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 2057 | create_params.main_frame_routing_id = main_frame_route_id; |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 2058 | create_params.main_frame_widget_routing_id = main_frame_widget_route_id; |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 2059 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 2060 | create_params.opener_render_process_id = render_process_id; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 2061 | create_params.opener_render_frame_id = params.opener_render_frame_id; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2062 | create_params.opener_suppressed = params.opener_suppressed; |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2063 | if (params.disposition == WindowOpenDisposition::NEW_BACKGROUND_TAB) |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2064 | create_params.initially_hidden = true; |
lfg | 269b702f | 2015-06-08 19:28:19 | [diff] [blame] | 2065 | create_params.renderer_initiated_creation = |
| 2066 | main_frame_route_id != MSG_ROUTING_NONE; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2067 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 2068 | WebContentsImpl* new_contents = NULL; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2069 | if (!is_guest) { |
| 2070 | create_params.context = view_->GetNativeView(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2071 | create_params.initial_size = GetContainerBounds().size(); |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 2072 | new_contents = static_cast<WebContentsImpl*>( |
| 2073 | WebContents::Create(create_params)); |
| 2074 | } else { |
| 2075 | new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2076 | } |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 2077 | new_contents->GetController().SetSessionStorageNamespace( |
| 2078 | partition_id, |
| 2079 | session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 2080 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 2081 | // If the new frame has a name, make sure any SiteInstances that can find |
| 2082 | // this named frame have proxies for it. Must be called after |
| 2083 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 2084 | // GetSessionStorageNamespace. |
| 2085 | if (!params.frame_name.empty()) |
| 2086 | new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
| 2087 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 2088 | // 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] | 2089 | // will be shown immediately). |
| 2090 | if (!params.opener_suppressed) { |
| 2091 | if (!is_guest) { |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2092 | WebContentsView* new_view = new_contents->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2093 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2094 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 2095 | // newly created object and give it one of its own member variables. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2096 | new_view->CreateViewForWidget( |
| 2097 | new_contents->GetRenderViewHost()->GetWidget(), false); |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2098 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2099 | // Save the created window associated with the route so we can show it |
| 2100 | // later. |
| 2101 | DCHECK_NE(MSG_ROUTING_NONE, route_id); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2102 | pending_contents_[std::make_pair(render_process_id, route_id)] = |
| 2103 | new_contents; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2104 | AddDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2105 | } |
| 2106 | |
| 2107 | if (delegate_) { |
| 2108 | delegate_->WebContentsCreated( |
nasko | e2df1d7 | 2016-10-04 00:20:17 | [diff] [blame] | 2109 | this, render_process_id, params.opener_render_frame_id, |
| 2110 | params.frame_name, params.target_url, new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | if (params.opener_suppressed) { |
| 2114 | // When the opener is suppressed, the original renderer cannot access the |
| 2115 | // 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] | 2116 | bool was_blocked = false; |
| 2117 | if (delegate_) { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2118 | gfx::Rect initial_rect; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2119 | delegate_->AddNewContents( |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2120 | this, new_contents, params.disposition, initial_rect, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2121 | params.user_gesture, &was_blocked); |
| 2122 | } |
| 2123 | if (!was_blocked) { |
nick | 3b04f32 | 2016-08-31 19:29:19 | [diff] [blame] | 2124 | OpenURLParams open_params(params.target_url, params.referrer, |
| 2125 | WindowOpenDisposition::CURRENT_TAB, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 2126 | ui::PAGE_TRANSITION_LINK, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2127 | true /* is_renderer_initiated */); |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 2128 | open_params.user_gesture = params.user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2129 | |
| 2130 | if (delegate_ && !is_guest && |
| 2131 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
| 2132 | // We are in asynchronous add new contents path, delay opening url |
| 2133 | new_contents->delayed_open_url_params_.reset( |
| 2134 | new OpenURLParams(open_params)); |
| 2135 | } else { |
| 2136 | new_contents->OpenURL(open_params); |
| 2137 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2138 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2139 | } |
| 2140 | } |
| 2141 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2142 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2143 | int32_t route_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2144 | blink::WebPopupType popup_type) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 2145 | CreateNewWidget(render_process_id, route_id, false, popup_type); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2146 | } |
| 2147 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2148 | void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id, |
| 2149 | int32_t route_id) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 2150 | CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2151 | } |
| 2152 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2153 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 2154 | int32_t route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2155 | bool is_fullscreen, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2156 | blink::WebPopupType popup_type) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2157 | RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 2158 | // 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] | 2159 | // this WebContentsImpl instance. If any other process sends the request, |
| 2160 | // it is invalid and the process must be terminated. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 2161 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2162 | base::ProcessHandle process_handle = process->GetHandle(); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2163 | if (process_handle != base::kNullProcessHandle) { |
| 2164 | RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 2165 | base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget")); |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame] | 2166 | process->Shutdown(RESULT_CODE_KILLED, false); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 2167 | } |
| 2168 | return; |
| 2169 | } |
| 2170 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2171 | RenderWidgetHostImpl* widget_host = |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 2172 | new RenderWidgetHostImpl(this, process, route_id, IsHidden()); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 2173 | |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2174 | RenderWidgetHostViewBase* widget_view = |
| 2175 | static_cast<RenderWidgetHostViewBase*>( |
| 2176 | view_->CreateViewForPopupWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 2177 | if (!widget_view) |
| 2178 | return; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2179 | if (!is_fullscreen) { |
| 2180 | // Popups should not get activated. |
| 2181 | widget_view->SetPopupType(popup_type); |
| 2182 | } |
| 2183 | // Save the created widget associated with the route so we can show it later. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2184 | pending_widget_views_[std::make_pair(render_process_id, route_id)] = |
| 2185 | widget_view; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2186 | |
| 2187 | #if defined(OS_MACOSX) |
| 2188 | // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it |
| 2189 | // to allow it to survive the trip without being hosted. |
| 2190 | base::mac::NSObjectRetain(widget_view->GetNativeView()); |
| 2191 | #endif |
| 2192 | } |
| 2193 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2194 | void WebContentsImpl::ShowCreatedWindow(int process_id, |
| 2195 | int route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2196 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2197 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2198 | bool user_gesture) { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2199 | WebContentsImpl* contents = GetCreatedWindow(process_id, route_id); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2200 | if (contents) { |
| 2201 | WebContentsDelegate* delegate = GetDelegate(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 2202 | contents->is_resume_pending_ = true; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2203 | if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) |
| 2204 | contents->ResumeLoadingCreatedWebContents(); |
| 2205 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2206 | if (delegate) { |
| 2207 | delegate->AddNewContents( |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2208 | this, contents, disposition, initial_rect, user_gesture, NULL); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2209 | } |
| 2210 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2211 | } |
| 2212 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2213 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2214 | int route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2215 | const gfx::Rect& initial_rect) { |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2216 | ShowCreatedWidget(process_id, route_id, false, initial_rect); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2217 | } |
| 2218 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2219 | void WebContentsImpl::ShowCreatedFullscreenWidget(int process_id, |
| 2220 | int route_id) { |
| 2221 | ShowCreatedWidget(process_id, route_id, true, gfx::Rect()); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2222 | } |
| 2223 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2224 | void WebContentsImpl::ShowCreatedWidget(int process_id, |
| 2225 | int route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2226 | bool is_fullscreen, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2227 | const gfx::Rect& initial_rect) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2228 | RenderWidgetHostViewBase* widget_host_view = |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2229 | static_cast<RenderWidgetHostViewBase*>( |
| 2230 | GetCreatedWidget(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2231 | if (!widget_host_view) |
| 2232 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2233 | |
| 2234 | RenderWidgetHostView* view = NULL; |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 2235 | if (GetOuterWebContents()) { |
| 2236 | view = GetOuterWebContents()->GetRenderWidgetHostView(); |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2237 | } else { |
| 2238 | view = GetRenderWidgetHostView(); |
| 2239 | } |
| 2240 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2241 | if (is_fullscreen) { |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2242 | DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2243 | view_->StoreFocus(); |
alexmos | c9e76ec | 2016-05-16 22:59:37 | [diff] [blame] | 2244 | fullscreen_widget_process_id_ = |
| 2245 | widget_host_view->GetRenderWidgetHost()->GetProcess()->GetID(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2246 | fullscreen_widget_routing_id_ = route_id; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2247 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| 2248 | widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView()); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2249 | delegate_->EnterFullscreenModeForTab(this, GURL()); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2250 | } else { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2251 | widget_host_view->InitAsFullscreen(view); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2252 | } |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2253 | for (auto& observer : observers_) |
| 2254 | observer.DidShowFullscreenWidget(); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2255 | if (!widget_host_view->HasFocus()) |
| 2256 | widget_host_view->Focus(); |
| 2257 | } else { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2258 | widget_host_view->InitAsPopup(view, initial_rect); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2259 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 2260 | |
| 2261 | RenderWidgetHostImpl* render_widget_host_impl = |
| 2262 | RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost()); |
| 2263 | render_widget_host_impl->Init(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2264 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 2265 | // used to implement Pepper Flash fullscreen. |
| 2266 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2267 | |
| 2268 | #if defined(OS_MACOSX) |
| 2269 | // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's |
| 2270 | // properly embedded (or purposefully ignored) we can release the retain we |
| 2271 | // took in CreateNewWidget(). |
| 2272 | base::mac::NSObjectRelease(widget_host_view->GetNativeView()); |
| 2273 | #endif |
| 2274 | } |
| 2275 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2276 | WebContentsImpl* WebContentsImpl::GetCreatedWindow(int process_id, |
| 2277 | int route_id) { |
| 2278 | auto iter = pending_contents_.find(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2279 | |
| 2280 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 2281 | // in creating one, just return NULL. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2282 | if (iter == pending_contents_.end()) |
| 2283 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2284 | |
| 2285 | WebContentsImpl* new_contents = iter->second; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2286 | pending_contents_.erase(std::make_pair(process_id, route_id)); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2287 | RemoveDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2288 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2289 | // Don't initialize the guest WebContents immediately. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 2290 | if (BrowserPluginGuest::IsGuest(new_contents)) |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2291 | return new_contents; |
| 2292 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2293 | if (!new_contents->GetRenderProcessHost()->HasConnection() || |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2294 | !new_contents->GetRenderViewHost()->GetWidget()->GetView()) |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2295 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2296 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2297 | return new_contents; |
| 2298 | } |
| 2299 | |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2300 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int process_id, |
| 2301 | int route_id) { |
| 2302 | auto iter = pending_widget_views_.find(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2303 | if (iter == pending_widget_views_.end()) { |
| 2304 | DCHECK(false); |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2305 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2306 | } |
| 2307 | |
| 2308 | RenderWidgetHostView* widget_host_view = iter->second; |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2309 | pending_widget_views_.erase(std::make_pair(process_id, route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2310 | |
| 2311 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
| 2312 | if (!widget_host->GetProcess()->HasConnection()) { |
| 2313 | // The view has gone away or the renderer crashed. Nothing to do. |
alexmos | c2a8cec | 2016-05-23 22:19:53 | [diff] [blame] | 2314 | return nullptr; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | return widget_host_view; |
| 2318 | } |
| 2319 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2320 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 2321 | const MediaStreamRequest& request, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2322 | const MediaResponseCallback& callback) { |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2323 | if (delegate_) { |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2324 | delegate_->RequestMediaAccessPermission(this, request, callback); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2325 | } else { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 2326 | callback.Run(MediaStreamDevices(), MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
| 2327 | std::unique_ptr<MediaStreamUI>()); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2328 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2329 | } |
| 2330 | |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 2331 | bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin, |
| 2332 | MediaStreamType type) { |
| 2333 | DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 2334 | type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 2335 | return delegate_ && |
| 2336 | delegate_->CheckMediaAccessPermission(this, security_origin, type); |
| 2337 | } |
| 2338 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 2339 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 2340 | SiteInstance* instance) { |
| 2341 | return controller_.GetSessionStorageNamespace(instance); |
| 2342 | } |
| 2343 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 2344 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 2345 | return controller_.GetSessionStorageNamespaceMap(); |
| 2346 | } |
| 2347 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 2348 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 2349 | return &frame_tree_; |
| 2350 | } |
| 2351 | |
luken | dc35e7f | 2014-11-10 19:06:14 | [diff] [blame] | 2352 | void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) { |
| 2353 | virtual_keyboard_requested_ = requested; |
| 2354 | } |
| 2355 | |
| 2356 | bool WebContentsImpl::IsVirtualKeyboardRequested() { |
| 2357 | return virtual_keyboard_requested_; |
| 2358 | } |
| 2359 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 2360 | bool WebContentsImpl::IsOverridingUserAgent() { |
| 2361 | return GetController().GetVisibleEntry() && |
| 2362 | GetController().GetVisibleEntry()->GetIsOverridingUserAgent(); |
| 2363 | } |
| 2364 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 2365 | bool WebContentsImpl::IsJavaScriptDialogShowing() const { |
| 2366 | return is_showing_javascript_dialog_; |
| 2367 | } |
| 2368 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2369 | AccessibilityMode WebContentsImpl::GetAccessibilityMode() const { |
| 2370 | return accessibility_mode_; |
| 2371 | } |
| 2372 | |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 2373 | void WebContentsImpl::AccessibilityEventReceived( |
| 2374 | const std::vector<AXEventNotificationDetails>& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2375 | for (auto& observer : observers_) |
| 2376 | observer.AccessibilityEventReceived(details); |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 2377 | } |
| 2378 | |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 2379 | void WebContentsImpl::AccessibilityLocationChangesReceived( |
| 2380 | const std::vector<AXLocationChangeNotificationDetails>& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2381 | for (auto& observer : observers_) |
| 2382 | observer.AccessibilityLocationChangesReceived(details); |
dmazzoni | 2400c46 | 2016-08-23 15:07:13 | [diff] [blame] | 2383 | } |
| 2384 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2385 | RenderFrameHost* WebContentsImpl::GetGuestByInstanceID( |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 2386 | RenderFrameHost* render_frame_host, |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2387 | int browser_plugin_instance_id) { |
| 2388 | BrowserPluginGuestManager* guest_manager = |
| 2389 | GetBrowserContext()->GetGuestManager(); |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2390 | if (!guest_manager) |
| 2391 | return nullptr; |
| 2392 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2393 | WebContents* guest = guest_manager->GetGuestByInstanceID( |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 2394 | render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id); |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2395 | if (!guest) |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2396 | return nullptr; |
| 2397 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2398 | return guest->GetMainFrame(); |
| 2399 | } |
| 2400 | |
mcasas | 4e216e7 | 2016-07-28 21:28:38 | [diff] [blame] | 2401 | device::GeolocationServiceContext* |
| 2402 | WebContentsImpl::GetGeolocationServiceContext() { |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 2403 | return geolocation_service_context_.get(); |
| 2404 | } |
| 2405 | |
blundell | d46e883 | 2016-10-07 10:34:27 | [diff] [blame] | 2406 | device::WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() { |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 2407 | return wake_lock_service_context_.get(); |
| 2408 | } |
| 2409 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2410 | void WebContentsImpl::OnShowValidationMessage( |
| 2411 | const gfx::Rect& anchor_in_root_view, |
[email protected] | 6ff9c8f | 2013-12-20 09:05:29 | [diff] [blame] | 2412 | const base::string16& main_text, |
| 2413 | const base::string16& sub_text) { |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2414 | if (delegate_) |
| 2415 | delegate_->ShowValidationMessage( |
| 2416 | this, anchor_in_root_view, main_text, sub_text); |
| 2417 | } |
| 2418 | |
| 2419 | void WebContentsImpl::OnHideValidationMessage() { |
| 2420 | if (delegate_) |
| 2421 | delegate_->HideValidationMessage(this); |
| 2422 | } |
| 2423 | |
| 2424 | void WebContentsImpl::OnMoveValidationMessage( |
| 2425 | const gfx::Rect& anchor_in_root_view) { |
| 2426 | if (delegate_) |
| 2427 | delegate_->MoveValidationMessage(this, anchor_in_root_view); |
| 2428 | } |
| 2429 | |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 2430 | void WebContentsImpl::SendScreenRects() { |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 2431 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
kenrb | 0e8dc20 | 2016-05-30 19:51:40 | [diff] [blame] | 2432 | if (node->current_frame_host()->is_local_root()) |
kenrb | c52e1b4e | 2016-03-20 01:03:37 | [diff] [blame] | 2433 | node->current_frame_host()->GetRenderWidgetHost()->SendScreenRects(); |
| 2434 | } |
lfg | bb9c28a | 2016-03-01 03:19:49 | [diff] [blame] | 2435 | |
lfg | db5c4ed | 2016-03-04 23:09:07 | [diff] [blame] | 2436 | RenderWidgetHostViewBase* rwhv = |
| 2437 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 2438 | if (rwhv) { |
| 2439 | SendPageMessage(new PageMsg_UpdateWindowScreenRect( |
| 2440 | MSG_ROUTING_NONE, rwhv->GetBoundsInRootWindow())); |
| 2441 | } |
| 2442 | |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 2443 | if (browser_plugin_embedder_) |
[email protected] | a7568e6 | 2013-06-14 07:50:44 | [diff] [blame] | 2444 | browser_plugin_embedder_->DidSendScreenRects(); |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 2445 | } |
| 2446 | |
khushalsagar | f3b62b6 | 2016-05-26 21:54:23 | [diff] [blame] | 2447 | void WebContentsImpl::OnFirstPaintAfterLoad( |
| 2448 | RenderWidgetHostImpl* render_widget_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2449 | for (auto& observer : observers_) |
| 2450 | observer.DidFirstPaintAfterLoad(render_widget_host); |
khushalsagar | f3b62b6 | 2016-05-26 21:54:23 | [diff] [blame] | 2451 | } |
| 2452 | |
ekaramad | add88229 | 2016-06-08 15:22:56 | [diff] [blame] | 2453 | TextInputManager* WebContentsImpl::GetTextInputManager() { |
| 2454 | if (GetOuterWebContents()) |
| 2455 | return GetOuterWebContents()->GetTextInputManager(); |
| 2456 | |
| 2457 | if (!text_input_manager_) |
| 2458 | text_input_manager_.reset(new TextInputManager()); |
| 2459 | |
| 2460 | return text_input_manager_.get(); |
| 2461 | } |
| 2462 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2463 | BrowserAccessibilityManager* |
| 2464 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2465 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2466 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2467 | } |
| 2468 | |
| 2469 | BrowserAccessibilityManager* |
| 2470 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2471 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2472 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2473 | } |
| 2474 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 2475 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
| 2476 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2477 | if (!focused_frame) |
| 2478 | return; |
| 2479 | |
| 2480 | focused_frame->Send(new InputMsg_MoveRangeSelectionExtent( |
| 2481 | focused_frame->GetRoutingID(), extent)); |
| 2482 | } |
| 2483 | |
| 2484 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 2485 | const gfx::Point& extent) { |
| 2486 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2487 | if (!focused_frame) |
| 2488 | return; |
| 2489 | |
| 2490 | focused_frame->Send( |
| 2491 | new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent)); |
| 2492 | } |
| 2493 | |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 2494 | void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust, |
| 2495 | int end_adjust) { |
| 2496 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2497 | if (!focused_frame) |
| 2498 | return; |
| 2499 | |
| 2500 | focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( |
| 2501 | focused_frame->GetRoutingID(), start_adjust, end_adjust)); |
| 2502 | } |
| 2503 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2504 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2505 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 2506 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2507 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 2508 | } |
| 2509 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2510 | void WebContentsImpl::ResizeDueToAutoResize( |
| 2511 | RenderWidgetHostImpl* render_widget_host, |
| 2512 | const gfx::Size& new_size) { |
| 2513 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 2514 | return; |
| 2515 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 2516 | if (delegate_) |
| 2517 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 2518 | } |
| 2519 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2520 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2521 | if (!delegate_) |
| 2522 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 2523 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2524 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2525 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2526 | } |
| 2527 | |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 2528 | bool WebContentsImpl::Send(IPC::Message* message) { |
| 2529 | if (!GetRenderViewHost()) { |
| 2530 | delete message; |
| 2531 | return false; |
| 2532 | } |
| 2533 | |
| 2534 | return GetRenderViewHost()->Send(message); |
| 2535 | } |
| 2536 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 2537 | void WebContentsImpl::RenderFrameForInterstitialPageCreated( |
| 2538 | RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2539 | for (auto& observer : observers_) |
| 2540 | observer.RenderFrameForInterstitialPageCreated(render_frame_host); |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 2541 | } |
| 2542 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2543 | void WebContentsImpl::AttachInterstitialPage( |
| 2544 | InterstitialPageImpl* interstitial_page) { |
| 2545 | DCHECK(interstitial_page); |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2546 | GetRenderManager()->set_interstitial_page(interstitial_page); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2547 | |
| 2548 | // Cancel any visible dialogs so that they don't interfere with the |
| 2549 | // interstitial. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 2550 | CancelActiveAndPendingDialogs(); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2551 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2552 | for (auto& observer : observers_) |
| 2553 | observer.DidAttachInterstitialPage(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2554 | |
| 2555 | // Stop the throbber if needed while the interstitial page is shown. |
| 2556 | if (frame_tree_.IsLoading()) |
| 2557 | LoadingStateChanged(true, true, nullptr); |
| 2558 | } |
| 2559 | |
| 2560 | void WebContentsImpl::DidProceedOnInterstitial() { |
| 2561 | // The interstitial page should no longer be pausing the throbber. |
| 2562 | DCHECK(!(ShowingInterstitialPage() && |
| 2563 | GetRenderManager()->interstitial_page()->pause_throbber())); |
| 2564 | |
| 2565 | // Restart the throbber now that the interstitial page no longer pauses it. |
| 2566 | if (ShowingInterstitialPage() && frame_tree_.IsLoading()) |
| 2567 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | void WebContentsImpl::DetachInterstitialPage() { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2571 | bool interstitial_pausing_throbber = |
| 2572 | ShowingInterstitialPage() && |
| 2573 | GetRenderManager()->interstitial_page()->pause_throbber(); |
[email protected] | 6832c8bc | 2014-04-29 07:20:57 | [diff] [blame] | 2574 | if (ShowingInterstitialPage()) |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2575 | GetRenderManager()->remove_interstitial_page(); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2576 | for (auto& observer : observers_) |
| 2577 | observer.DidDetachInterstitialPage(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 2578 | |
| 2579 | // Restart the throbber if needed now that the interstitial page is going |
| 2580 | // away. |
| 2581 | if (interstitial_pausing_throbber && frame_tree_.IsLoading()) |
| 2582 | LoadingStateChanged(true, true, nullptr); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2583 | } |
| 2584 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2585 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 2586 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 2587 | SendPageMessage(new PageMsg_SetHistoryOffsetAndLength( |
| 2588 | MSG_ROUTING_NONE, history_offset, history_length)); |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2589 | } |
| 2590 | |
| 2591 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 2592 | RenderViewHost* render_view_host, |
| 2593 | int history_offset, |
| 2594 | int history_length) { |
alexmos | 136fd6e6 | 2016-08-15 20:58:41 | [diff] [blame] | 2595 | render_view_host->Send(new PageMsg_SetHistoryOffsetAndLength( |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2596 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 2597 | } |
| 2598 | |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 2599 | void WebContentsImpl::ReloadFocusedFrame(bool bypass_cache) { |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2600 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2601 | if (!focused_frame) |
| 2602 | return; |
| 2603 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2604 | focused_frame->Send(new FrameMsg_Reload( |
toyoshim | 24a4c7ab | 2016-04-05 09:24:14 | [diff] [blame] | 2605 | focused_frame->GetRoutingID(), bypass_cache)); |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2606 | } |
| 2607 | |
megjablon | 3f594107 | 2016-02-04 23:27:52 | [diff] [blame] | 2608 | void WebContentsImpl::ReloadLoFiImages() { |
| 2609 | SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE)); |
| 2610 | } |
| 2611 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2612 | void WebContentsImpl::Undo() { |
| 2613 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2614 | if (!focused_frame) |
| 2615 | return; |
| 2616 | |
| 2617 | focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID())); |
| 2618 | RecordAction(base::UserMetricsAction("Undo")); |
| 2619 | } |
| 2620 | |
| 2621 | void WebContentsImpl::Redo() { |
| 2622 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2623 | if (!focused_frame) |
| 2624 | return; |
| 2625 | focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID())); |
| 2626 | RecordAction(base::UserMetricsAction("Redo")); |
| 2627 | } |
| 2628 | |
| 2629 | void WebContentsImpl::Cut() { |
| 2630 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2631 | if (!focused_frame) |
| 2632 | return; |
| 2633 | |
| 2634 | focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID())); |
| 2635 | RecordAction(base::UserMetricsAction("Cut")); |
| 2636 | } |
| 2637 | |
| 2638 | void WebContentsImpl::Copy() { |
| 2639 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2640 | if (!focused_frame) |
| 2641 | return; |
| 2642 | |
| 2643 | focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID())); |
| 2644 | RecordAction(base::UserMetricsAction("Copy")); |
| 2645 | } |
| 2646 | |
| 2647 | void WebContentsImpl::CopyToFindPboard() { |
| 2648 | #if defined(OS_MACOSX) |
| 2649 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2650 | if (!focused_frame) |
| 2651 | return; |
| 2652 | |
| 2653 | // Windows/Linux don't have the concept of a find pasteboard. |
| 2654 | focused_frame->Send( |
| 2655 | new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID())); |
| 2656 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 2657 | #endif |
| 2658 | } |
| 2659 | |
| 2660 | void WebContentsImpl::Paste() { |
| 2661 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2662 | if (!focused_frame) |
| 2663 | return; |
| 2664 | |
| 2665 | focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID())); |
| 2666 | RecordAction(base::UserMetricsAction("Paste")); |
| 2667 | } |
| 2668 | |
| 2669 | void WebContentsImpl::PasteAndMatchStyle() { |
| 2670 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2671 | if (!focused_frame) |
| 2672 | return; |
| 2673 | |
| 2674 | focused_frame->Send(new InputMsg_PasteAndMatchStyle( |
| 2675 | focused_frame->GetRoutingID())); |
| 2676 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 2677 | } |
| 2678 | |
| 2679 | void WebContentsImpl::Delete() { |
| 2680 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2681 | if (!focused_frame) |
| 2682 | return; |
| 2683 | |
| 2684 | focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID())); |
| 2685 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 2686 | } |
| 2687 | |
| 2688 | void WebContentsImpl::SelectAll() { |
| 2689 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2690 | if (!focused_frame) |
| 2691 | return; |
| 2692 | |
| 2693 | focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID())); |
| 2694 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 2695 | } |
| 2696 | |
| 2697 | void WebContentsImpl::Unselect() { |
| 2698 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2699 | if (!focused_frame) |
| 2700 | return; |
| 2701 | |
| 2702 | focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID())); |
| 2703 | RecordAction(base::UserMetricsAction("Unselect")); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2704 | } |
| 2705 | |
| 2706 | void WebContentsImpl::Replace(const base::string16& word) { |
| 2707 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2708 | if (!focused_frame) |
| 2709 | return; |
| 2710 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2711 | focused_frame->Send(new InputMsg_Replace( |
| 2712 | focused_frame->GetRoutingID(), word)); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2713 | } |
| 2714 | |
| 2715 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
| 2716 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2717 | if (!focused_frame) |
| 2718 | return; |
| 2719 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2720 | focused_frame->Send(new InputMsg_ReplaceMisspelling( |
| 2721 | focused_frame->GetRoutingID(), word)); |
| 2722 | } |
| 2723 | |
| 2724 | void WebContentsImpl::NotifyContextMenuClosed( |
| 2725 | const CustomContextMenuContext& context) { |
| 2726 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2727 | if (!focused_frame) |
| 2728 | return; |
| 2729 | |
| 2730 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 2731 | focused_frame->GetRoutingID(), context)); |
| 2732 | } |
| 2733 | |
| 2734 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 2735 | int action, const CustomContextMenuContext& context) { |
| 2736 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2737 | if (!focused_frame) |
| 2738 | return; |
| 2739 | |
| 2740 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 2741 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 2742 | } |
| 2743 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2744 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 2745 | return view_->GetNativeView(); |
| 2746 | } |
| 2747 | |
| 2748 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 2749 | return view_->GetContentNativeView(); |
| 2750 | } |
| 2751 | |
| 2752 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 2753 | return view_->GetTopLevelNativeWindow(); |
| 2754 | } |
| 2755 | |
| 2756 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 2757 | return view_->GetViewBounds(); |
| 2758 | } |
| 2759 | |
| 2760 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
| 2761 | gfx::Rect rv; |
| 2762 | view_->GetContainerBounds(&rv); |
| 2763 | return rv; |
| 2764 | } |
| 2765 | |
| 2766 | DropData* WebContentsImpl::GetDropData() { |
| 2767 | return view_->GetDropData(); |
| 2768 | } |
| 2769 | |
| 2770 | void WebContentsImpl::Focus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2771 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2772 | } |
| 2773 | |
| 2774 | void WebContentsImpl::SetInitialFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2775 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2776 | } |
| 2777 | |
| 2778 | void WebContentsImpl::StoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2779 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2780 | } |
| 2781 | |
| 2782 | void WebContentsImpl::RestoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2783 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2784 | } |
| 2785 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2786 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2787 | if (ShowingInterstitialPage()) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2788 | GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 2789 | return; |
| 2790 | } |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2791 | RenderWidgetHostView* const fullscreen_view = |
| 2792 | GetFullscreenRenderWidgetHostView(); |
| 2793 | if (fullscreen_view) { |
| 2794 | fullscreen_view->Focus(); |
| 2795 | return; |
| 2796 | } |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2797 | GetRenderViewHost()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2798 | } |
| 2799 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2800 | bool WebContentsImpl::ShowingInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2801 | return GetRenderManager()->interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2802 | } |
| 2803 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2804 | InterstitialPage* WebContentsImpl::GetInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2805 | return GetRenderManager()->interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 2806 | } |
| 2807 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2808 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2809 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 2810 | // so we also support this MIME type. |
| 2811 | return contents_mime_type_ == "text/html" || |
| 2812 | contents_mime_type_ == "text/xml" || |
| 2813 | contents_mime_type_ == "application/xhtml+xml" || |
| 2814 | contents_mime_type_ == "text/plain" || |
| 2815 | contents_mime_type_ == "text/css" || |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 2816 | mime_util::IsSupportedJavascriptMimeType(contents_mime_type_); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2817 | } |
| 2818 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2819 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2820 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2821 | if (!IsSavable()) { |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 2822 | RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2823 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2824 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2825 | } |
| 2826 | |
| 2827 | Stop(); |
| 2828 | |
| 2829 | // Create the save package and possibly prompt the user for the name to save |
| 2830 | // the page as. The user prompt is an asynchronous operation that runs on |
| 2831 | // another thread. |
| 2832 | save_package_ = new SavePackage(this); |
| 2833 | save_package_->GetSaveInfo(); |
| 2834 | } |
| 2835 | |
| 2836 | // Used in automated testing to bypass prompting the user for file names. |
| 2837 | // Instead, the names and paths are hard coded rather than running them through |
| 2838 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 2839 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 2840 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2841 | SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2842 | // Stop the page from navigating. |
| 2843 | Stop(); |
| 2844 | |
| 2845 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2846 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2847 | } |
| 2848 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2849 | void WebContentsImpl::SaveFrame(const GURL& url, |
| 2850 | const Referrer& referrer) { |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2851 | SaveFrameWithHeaders(url, referrer, std::string()); |
| 2852 | } |
| 2853 | |
| 2854 | void WebContentsImpl::SaveFrameWithHeaders(const GURL& url, |
| 2855 | const Referrer& referrer, |
| 2856 | const std::string& headers) { |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2857 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2858 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 2859 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 2860 | return; |
| 2861 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2862 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 2863 | // by explicitly passing in which frame this method should target. This would |
| 2864 | // indicate whether it's the main frame, and also tell us the frame pointer |
| 2865 | // to use for routing. |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2866 | bool is_main_frame = (url == GetLastCommittedURL()); |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 2867 | RenderFrameHost* frame_host = GetMainFrame(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2868 | |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 2869 | StoragePartition* storage_partition = BrowserContext::GetStoragePartition( |
| 2870 | GetBrowserContext(), frame_host->GetSiteInstance()); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2871 | DownloadManager* dlm = |
| 2872 | BrowserContext::GetDownloadManager(GetBrowserContext()); |
| 2873 | if (!dlm) |
| 2874 | return; |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2875 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2876 | if (is_main_frame) { |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 2877 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2878 | if (entry) |
| 2879 | post_id = entry->GetPostID(); |
| 2880 | } |
brettw | 760f744 | 2016-05-23 21:19:22 | [diff] [blame] | 2881 | std::unique_ptr<DownloadUrlParameters> params(new DownloadUrlParameters( |
| 2882 | url, frame_host->GetProcess()->GetID(), |
| 2883 | frame_host->GetRenderViewHost()->GetRoutingID(), |
| 2884 | frame_host->GetRoutingID(), storage_partition->GetURLRequestContext())); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2885 | params->set_referrer(referrer); |
| 2886 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2887 | if (post_id >= 0) |
| 2888 | params->set_method("POST"); |
| 2889 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2890 | |
| 2891 | if (headers.empty()) { |
| 2892 | params->set_prefer_cache(true); |
| 2893 | } else { |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 2894 | for (const base::StringPiece& key_value : |
| 2895 | base::SplitStringPiece( |
| 2896 | headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 2897 | std::vector<std::string> pair = base::SplitString( |
| 2898 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2899 | DCHECK_EQ(2ul, pair.size()); |
| 2900 | params->add_request_header(pair[0], pair[1]); |
| 2901 | } |
| 2902 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 2903 | dlm->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2904 | } |
| 2905 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2906 | void WebContentsImpl::GenerateMHTML( |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 2907 | const MHTMLGenerationParams& params, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2908 | const base::Callback<void(int64_t)>& callback) { |
dewittj | 6dc5747a | 2016-05-17 01:48:47 | [diff] [blame] | 2909 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, params, callback); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 2910 | } |
| 2911 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2912 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2913 | return contents_mime_type_; |
| 2914 | } |
| 2915 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2916 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2917 | return notify_disconnection_; |
| 2918 | } |
| 2919 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2920 | RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2921 | return &renderer_preferences_; |
| 2922 | } |
| 2923 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2924 | void WebContentsImpl::Close() { |
| 2925 | Close(GetRenderViewHost()); |
| 2926 | } |
| 2927 | |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2928 | void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2929 | int screen_x, int screen_y, blink::WebDragOperation operation) { |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2930 | if (browser_plugin_embedder_.get()) |
| 2931 | browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y, |
| 2932 | screen_x, screen_y, operation); |
| 2933 | if (GetRenderViewHost()) |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2934 | GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x, |
| 2935 | screen_y, operation); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2936 | } |
| 2937 | |
jam | 73f89264 | 2016-09-11 06:04:06 | [diff] [blame] | 2938 | void WebContentsImpl::LoadStateChanged( |
| 2939 | const GURL& url, |
| 2940 | const net::LoadStateWithParam& load_state, |
| 2941 | uint64_t upload_position, |
| 2942 | uint64_t upload_size) { |
| 2943 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 2944 | // is fixed. |
| 2945 | tracked_objects::ScopedTracker tracking_profile1( |
| 2946 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 2947 | "466285 WebContentsImpl::LoadStateChanged::Start")); |
| 2948 | load_state_ = load_state; |
| 2949 | upload_position_ = upload_position; |
| 2950 | upload_size_ = upload_size; |
| 2951 | load_state_host_ = url_formatter::IDNToUnicode(url.host()); |
| 2952 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
| 2953 | SetNotWaitingForResponse(); |
| 2954 | if (IsLoading()) { |
| 2955 | NotifyNavigationStateChanged(static_cast<InvalidateTypes>( |
| 2956 | INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB)); |
| 2957 | } |
| 2958 | } |
| 2959 | |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2960 | void WebContentsImpl::DidGetResourceResponseStart( |
| 2961 | const ResourceRequestDetails& details) { |
estark | f83ac12 | 2016-10-05 19:06:06 | [diff] [blame] | 2962 | controller_.ssl_manager()->DidStartResourceResponse( |
| 2963 | details.url, details.has_certificate, details.ssl_cert_status); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2964 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2965 | for (auto& observer : observers_) |
| 2966 | observer.DidGetResourceResponseStart(details); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | void WebContentsImpl::DidGetRedirectForResourceRequest( |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2970 | const ResourceRedirectDetails& details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2971 | for (auto& observer : observers_) |
| 2972 | observer.DidGetRedirectForResourceRequest(details); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2973 | |
| 2974 | // TODO(avi): Remove. http://crbug.com/170921 |
| 2975 | NotificationService::current()->Notify( |
| 2976 | NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 2977 | Source<WebContents>(this), |
| 2978 | Details<const ResourceRedirectDetails>(&details)); |
| 2979 | } |
| 2980 | |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2981 | void WebContentsImpl::NotifyWebContentsFocused() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 2982 | for (auto& observer : observers_) |
| 2983 | observer.OnWebContentsFocused(); |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2984 | } |
| 2985 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2986 | void WebContentsImpl::SystemDragEnded() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2987 | if (GetRenderViewHost()) |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2988 | GetRenderViewHost()->DragSourceSystemDragEnded(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2989 | if (browser_plugin_embedder_.get()) |
| 2990 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 2991 | } |
| 2992 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2993 | void WebContentsImpl::UserGestureDone() { |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 2994 | OnUserInteraction(GetRenderViewHost()->GetWidget(), |
| 2995 | blink::WebInputEvent::Undefined); |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2996 | } |
| 2997 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2998 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2999 | closed_by_user_gesture_ = value; |
| 3000 | } |
| 3001 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3002 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3003 | return closed_by_user_gesture_; |
| 3004 | } |
| 3005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3006 | void WebContentsImpl::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3007 | if (!delegate_) |
| 3008 | return; |
| 3009 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3010 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 3011 | if (!entry) |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 3012 | return; |
| 3013 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3014 | delegate_->ViewSourceForTab(this, entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 3015 | } |
| 3016 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3017 | void WebContentsImpl::ViewFrameSource(const GURL& url, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3018 | const PageState& page_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3019 | if (!delegate_) |
| 3020 | return; |
| 3021 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3022 | delegate_->ViewSourceForFrame(this, url, page_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 3023 | } |
| 3024 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3025 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3026 | return minimum_zoom_percent_; |
| 3027 | } |
| 3028 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3029 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3030 | return maximum_zoom_percent_; |
| 3031 | } |
| 3032 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3033 | void WebContentsImpl::SetPageScale(float page_scale_factor) { |
| 3034 | Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor)); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 3035 | } |
| 3036 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3037 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 3038 | return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 3039 | } |
| 3040 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3041 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 3042 | if (GetBrowserPluginGuest()) |
| 3043 | return GetBrowserPluginGuest()->LockMouse(allowed); |
| 3044 | |
lfg | ad824435 | 2016-07-13 16:55:51 | [diff] [blame] | 3045 | if (mouse_lock_widget_ && |
| 3046 | mouse_lock_widget_->GotResponseToLockMouseRequest(allowed)) |
| 3047 | return true; |
| 3048 | |
| 3049 | mouse_lock_widget_ = nullptr; |
lfg | bee1e0a | 2016-06-08 21:24:21 | [diff] [blame] | 3050 | return false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3051 | } |
| 3052 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3053 | bool WebContentsImpl::HasOpener() const { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 3054 | return GetOpener() != NULL; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 3055 | } |
| 3056 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 3057 | WebContentsImpl* WebContentsImpl::GetOpener() const { |
| 3058 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
| 3059 | return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 3060 | } |
| 3061 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3062 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3063 | if (!color_chooser_info_.get()) |
| 3064 | return; |
| 3065 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 3066 | color_chooser_info_->render_process_id, |
| 3067 | color_chooser_info_->render_frame_id); |
| 3068 | if (!rfh) |
| 3069 | return; |
| 3070 | |
| 3071 | rfh->Send(new FrameMsg_DidChooseColorResponse( |
| 3072 | rfh->GetRoutingID(), color_chooser_info_->identifier, color)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3073 | } |
| 3074 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3075 | void WebContentsImpl::DidEndColorChooser() { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3076 | if (!color_chooser_info_.get()) |
| 3077 | return; |
| 3078 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 3079 | color_chooser_info_->render_process_id, |
| 3080 | color_chooser_info_->render_frame_id); |
| 3081 | if (!rfh) |
| 3082 | return; |
| 3083 | |
| 3084 | rfh->Send(new FrameMsg_DidEndColorChooser( |
| 3085 | rfh->GetRoutingID(), color_chooser_info_->identifier)); |
| 3086 | color_chooser_info_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3087 | } |
| 3088 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3089 | int WebContentsImpl::DownloadImage( |
| 3090 | const GURL& url, |
| 3091 | bool is_favicon, |
| 3092 | uint32_t max_bitmap_size, |
| 3093 | bool bypass_cache, |
| 3094 | const WebContents::ImageDownloadCallback& callback) { |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3095 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3096 | static int next_image_download_id = 0; |
leon.han | 6e9dee2 | 2016-02-25 03:44:06 | [diff] [blame] | 3097 | const content::mojom::ImageDownloaderPtr& mojo_image_downloader = |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3098 | GetMainFrame()->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3099 | const int download_id = ++next_image_download_id; |
| 3100 | if (!mojo_image_downloader) { |
| 3101 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 3102 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
| 3103 | // hang the callback indefinetly since the IPC would be dropped. Now, |
| 3104 | // respond with a 400 HTTP error code to indicate that something went wrong. |
| 3105 | BrowserThread::PostTask( |
| 3106 | BrowserThread::UI, FROM_HERE, |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 3107 | base::Bind(&WebContentsImpl::OnDidDownloadImage, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 3108 | weak_factory_.GetWeakPtr(), callback, download_id, url, 400, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 3109 | std::vector<SkBitmap>(), std::vector<gfx::Size>())); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3110 | return download_id; |
| 3111 | } |
| 3112 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 3113 | mojo_image_downloader->DownloadImage( |
sammc | f6f4fcf | 2016-06-21 05:39:39 | [diff] [blame] | 3114 | url, is_favicon, max_bitmap_size, bypass_cache, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 3115 | base::Bind(&WebContentsImpl::OnDidDownloadImage, |
| 3116 | weak_factory_.GetWeakPtr(), callback, download_id, url)); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 3117 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3118 | } |
| 3119 | |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 3120 | bool WebContentsImpl::IsSubframe() const { |
| 3121 | return is_subframe_; |
| 3122 | } |
| 3123 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3124 | void WebContentsImpl::Find(int request_id, |
| 3125 | const base::string16& search_text, |
| 3126 | const blink::WebFindOptions& options) { |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 3127 | // Cowardly refuse to search for no text. |
| 3128 | if (search_text.empty()) { |
| 3129 | NOTREACHED(); |
| 3130 | return; |
| 3131 | } |
| 3132 | |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 3133 | // See if a top level browser plugin handles the find request first. |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3134 | // TODO(paulmeyer): Remove this after find-in-page works across GuestViews. |
paulmeyer | 95703b9 | 2015-08-10 17:38:47 | [diff] [blame] | 3135 | if (browser_plugin_embedder_ && |
| 3136 | browser_plugin_embedder_->Find(request_id, search_text, options)) { |
| 3137 | return; |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 3138 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3139 | |
| 3140 | GetOrCreateFindRequestManager()->Find(request_id, search_text, options); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3141 | } |
| 3142 | |
| 3143 | void WebContentsImpl::StopFinding(StopFindAction action) { |
raymes | 2bc6418 | 2015-02-06 01:23:01 | [diff] [blame] | 3144 | // See if a top level browser plugin handles the stop finding request first. |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3145 | // TODO(paulmeyer): Remove this after find-in-page works across GuestViews. |
paulmeyer | 95703b9 | 2015-08-10 17:38:47 | [diff] [blame] | 3146 | if (browser_plugin_embedder_ && |
| 3147 | browser_plugin_embedder_->StopFinding(action)) { |
| 3148 | return; |
raymes | 2bc6418 | 2015-02-06 01:23:01 | [diff] [blame] | 3149 | } |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3150 | |
| 3151 | GetOrCreateFindRequestManager()->StopFinding(action); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 3152 | } |
| 3153 | |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 3154 | bool WebContentsImpl::WasRecentlyAudible() { |
wjmaclean | 1dabf3e3 | 2016-05-13 23:34:44 | [diff] [blame] | 3155 | return audio_stream_monitor_.WasRecentlyAudible() || |
| 3156 | (browser_plugin_embedder_ && |
| 3157 | browser_plugin_embedder_->WereAnyGuestsRecentlyAudible()); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 3158 | } |
| 3159 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 3160 | void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { |
| 3161 | manifest_manager_host_->GetManifest(GetMainFrame(), callback); |
| 3162 | } |
| 3163 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3164 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3165 | // Clean up related state and initiate the fullscreen exit. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 3166 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3167 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 3168 | } |
| 3169 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3170 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 3171 | if (delayed_open_url_params_.get()) { |
| 3172 | OpenURL(*delayed_open_url_params_.get()); |
| 3173 | delayed_open_url_params_.reset(nullptr); |
| 3174 | return; |
| 3175 | } |
| 3176 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3177 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 3178 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 3179 | if (is_resume_pending_) { |
| 3180 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 3181 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 3182 | GetMainFrame()->Init(); |
| 3183 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 3184 | } |
| 3185 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3186 | bool WebContentsImpl::FocusLocationBarByDefault() { |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 3187 | // When the browser is started with about:blank as the startup URL, focus |
| 3188 | // the location bar (which will also select its contents) so people can |
| 3189 | // simply begin typing to navigate elsewhere. |
| 3190 | // |
| 3191 | // We need to be careful not to trigger this for anything other than the |
| 3192 | // startup navigation. In particular, if we allow an attacker to open a |
| 3193 | // popup to about:blank, then navigate, focusing the Omnibox will cause the |
| 3194 | // end of the new URL to be scrolled into view instead of the start, |
| 3195 | // allowing the attacker to spoof other URLs. The conditions checked here |
| 3196 | // are all aimed at ensuring no such attacker-controlled navigation can |
| 3197 | // trigger this. |
| 3198 | // |
| 3199 | // Note that we check the pending entry instead of the visible one; for the |
| 3200 | // startup URL case these are the same, but for the attacker-controlled |
| 3201 | // navigation case the visible entry is the committed "about:blank" URL and |
| 3202 | // the pending entry is the problematic navigation elsewhere. |
| 3203 | NavigationEntryImpl* entry = controller_.GetPendingEntry(); |
| 3204 | if (controller_.IsInitialNavigation() && entry && |
| 3205 | !entry->is_renderer_initiated() && |
csharrison | a3bd0b3 | 2016-10-19 18:40:48 | [diff] [blame] | 3206 | entry->GetURL() == url::kAboutBlankURL) { |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 3207 | return true; |
palmer | c70cb1f | 2016-03-04 23:41:26 | [diff] [blame] | 3208 | } |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 3209 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3210 | } |
| 3211 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3212 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 3213 | if (delegate_) |
| 3214 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 3215 | } |
| 3216 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3217 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3218 | for (auto& observer : observers_) |
| 3219 | observer.DidStartNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3220 | } |
| 3221 | |
| 3222 | void WebContentsImpl::DidRedirectNavigation( |
| 3223 | NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3224 | for (auto& observer : observers_) |
| 3225 | observer.DidRedirectNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3226 | } |
| 3227 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 3228 | void WebContentsImpl::ReadyToCommitNavigation( |
| 3229 | NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3230 | for (auto& observer : observers_) |
| 3231 | observer.ReadyToCommitNavigation(navigation_handle); |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 3232 | } |
| 3233 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3234 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3235 | for (auto& observer : observers_) |
| 3236 | observer.DidFinishNavigation(navigation_handle); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 3237 | } |
| 3238 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 3239 | void WebContentsImpl::DidStartProvisionalLoad( |
| 3240 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 3241 | const GURL& validated_url, |
| 3242 | bool is_error_page, |
| 3243 | bool is_iframe_srcdoc) { |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 3244 | // Notify observers about the start of the provisional load. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3245 | for (auto& observer : observers_) { |
| 3246 | observer.DidStartProvisionalLoadForFrame(render_frame_host, validated_url, |
| 3247 | is_error_page, is_iframe_srcdoc); |
| 3248 | } |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3249 | |
| 3250 | // Notify accessibility if this is a reload. |
| 3251 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 3252 | if (entry && ui::PageTransitionCoreTypeIs( |
| 3253 | entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) { |
| 3254 | FrameTreeNode* ftn = render_frame_host->frame_tree_node(); |
| 3255 | BrowserAccessibilityManager* manager = |
| 3256 | ftn->current_frame_host()->browser_accessibility_manager(); |
| 3257 | if (manager) |
| 3258 | manager->UserIsReloading(); |
| 3259 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 3260 | } |
| 3261 | |
[email protected] | 3109fbb7 | 2014-01-06 23:57:15 | [diff] [blame] | 3262 | void WebContentsImpl::DidFailProvisionalLoadWithError( |
| 3263 | RenderFrameHostImpl* render_frame_host, |
lazyboy | 552a938 | 2016-07-14 20:38:37 | [diff] [blame] | 3264 | const GURL& validated_url, |
| 3265 | int error_code, |
| 3266 | const base::string16& error_description, |
| 3267 | bool was_ignored_by_handler) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3268 | for (auto& observer : observers_) { |
| 3269 | observer.DidFailProvisionalLoad(render_frame_host, validated_url, |
| 3270 | error_code, error_description, |
| 3271 | was_ignored_by_handler); |
| 3272 | } |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3273 | |
| 3274 | FrameTreeNode* ftn = render_frame_host->frame_tree_node(); |
| 3275 | BrowserAccessibilityManager* manager = |
| 3276 | ftn->current_frame_host()->browser_accessibility_manager(); |
| 3277 | if (manager) |
| 3278 | manager->NavigationFailed(); |
[email protected] | 3109fbb7 | 2014-01-06 23:57:15 | [diff] [blame] | 3279 | } |
| 3280 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3281 | void WebContentsImpl::DidFailLoadWithError( |
| 3282 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3283 | const GURL& url, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3284 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 3285 | const base::string16& error_description, |
| 3286 | bool was_ignored_by_handler) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3287 | for (auto& observer : observers_) { |
| 3288 | observer.DidFailLoad(render_frame_host, url, error_code, error_description, |
| 3289 | was_ignored_by_handler); |
| 3290 | } |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3291 | } |
| 3292 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 3293 | void WebContentsImpl::NotifyChangedNavigationState( |
| 3294 | InvalidateTypes changed_flags) { |
| 3295 | NotifyNavigationStateChanged(changed_flags); |
| 3296 | } |
| 3297 | |
toyoshim | 0df1d3a | 2016-09-09 09:52:48 | [diff] [blame] | 3298 | void WebContentsImpl::DidStartNavigationToPendingEntry(const GURL& url, |
| 3299 | ReloadType reload_type) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3300 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3301 | for (auto& observer : observers_) |
| 3302 | observer.DidStartNavigationToPendingEntry(url, reload_type); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3303 | } |
| 3304 | |
[email protected] | 8cb834e | 2014-03-06 14:23:23 | [diff] [blame] | 3305 | void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host, |
| 3306 | const OpenURLParams& params) { |
dcheng | b907f733 | 2015-01-07 20:35:50 | [diff] [blame] | 3307 | // OpenURL can blow away the source RFH. Use the process/frame routing ID as a |
| 3308 | // weak pointer of sorts. |
| 3309 | const int32_t process_id = render_frame_host->GetProcess()->GetID(); |
| 3310 | const int32_t frame_id = render_frame_host->GetRoutingID(); |
| 3311 | |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3312 | WebContents* new_contents = OpenURL(params); |
| 3313 | |
dcheng | b907f733 | 2015-01-07 20:35:50 | [diff] [blame] | 3314 | if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) { |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3315 | // Notify observers. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3316 | for (auto& observer : observers_) { |
| 3317 | observer.DidOpenRequestedURL(new_contents, render_frame_host, params.url, |
| 3318 | params.referrer, params.disposition, |
| 3319 | params.transition); |
| 3320 | } |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3321 | } |
| 3322 | } |
| 3323 | |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 3324 | bool WebContentsImpl::ShouldTransferNavigation(bool is_main_frame_navigation) { |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 3325 | if (!delegate_) |
| 3326 | return true; |
lukasza | 1d02573 | 2016-09-28 21:36:08 | [diff] [blame] | 3327 | return delegate_->ShouldTransferNavigation(is_main_frame_navigation); |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 3328 | } |
| 3329 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3330 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
| 3331 | if (!delegate_) |
| 3332 | return false; |
| 3333 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 3334 | } |
| 3335 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3336 | void WebContentsImpl::DidCommitProvisionalLoad( |
[email protected] | 27dd82fd | 2014-03-03 22:11:43 | [diff] [blame] | 3337 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3338 | const GURL& url, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 3339 | ui::PageTransition transition_type) { |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3340 | // Notify observers about the commit of the provisional load. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3341 | for (auto& observer : observers_) { |
| 3342 | observer.DidCommitProvisionalLoadForFrame(render_frame_host, url, |
| 3343 | transition_type); |
| 3344 | } |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3345 | |
| 3346 | BrowserAccessibilityManager* manager = |
| 3347 | render_frame_host->browser_accessibility_manager(); |
| 3348 | if (manager) |
| 3349 | manager->NavigationSucceeded(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3350 | } |
| 3351 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3352 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3353 | bool navigation_is_within_page) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3354 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 3355 | // different page. The next page will not start out assuming it is in |
| 3356 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3357 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 3358 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3359 | return; |
| 3360 | } |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 3361 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3362 | ExitFullscreen(false); |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 3363 | DCHECK(!IsFullscreenForCurrentTab()); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3364 | } |
| 3365 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3366 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3367 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3368 | const LoadCommittedDetails& details, |
| 3369 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 3370 | if (details.is_navigation_to_different_page()) { |
| 3371 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 3372 | // doesn't let us know that the cursor left an element during a |
| 3373 | // transition (this is also why the mouse cursor remains as a hand after |
| 3374 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 3375 | // clear the bubble when a user navigates to a named anchor in the same |
| 3376 | // page. |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3377 | UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL()); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 3378 | |
| 3379 | RenderWidgetHostViewBase* rwhvb = |
| 3380 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3381 | if (rwhvb) |
| 3382 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3383 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3384 | did_first_visually_non_empty_paint_ = false; |
| 3385 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3386 | // Reset theme color on navigation to new page. |
| 3387 | theme_color_ = SK_ColorTRANSPARENT; |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3388 | } |
| 3389 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3390 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3391 | for (auto& observer : observers_) |
| 3392 | observer.DidNavigateMainFrame(details, params); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3393 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3394 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3395 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3396 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 3400 | RenderFrameHostImpl* render_frame_host, |
| 3401 | const LoadCommittedDetails& details, |
| 3402 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 3403 | // Now that something has committed, we don't need to track whether the |
| 3404 | // initial page has been accessed. |
| 3405 | has_accessed_initial_document_ = false; |
| 3406 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3407 | // If we navigate off the page, close all JavaScript dialogs. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 3408 | if (!details.is_in_page) |
| 3409 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3410 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 3411 | // If this is a user-initiated navigation, start allowing JavaScript dialogs |
| 3412 | // again. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 3413 | if (params.gesture == NavigationGestureUser && dialog_manager_) { |
| 3414 | dialog_manager_->CancelDialogs(this, |
| 3415 | false, // suppress_callbacks, |
| 3416 | true); // reset_state |
| 3417 | } |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 3418 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3419 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3420 | for (auto& observer : observers_) |
| 3421 | observer.DidNavigateAnyFrame(render_frame_host, details, params); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3422 | } |
| 3423 | |
| 3424 | void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { |
| 3425 | contents_mime_type_ = mime_type; |
| 3426 | } |
| 3427 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 3428 | bool WebContentsImpl::CanOverscrollContent() const { |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3429 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 3430 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3431 | return false; |
| 3432 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3433 | if (delegate_) |
| 3434 | return delegate_->CanOverscrollContent(); |
| 3435 | |
| 3436 | return false; |
| 3437 | } |
| 3438 | |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 3439 | void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) { |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3440 | // Update the theme color. This is to be published to observers after the |
| 3441 | // first visually non-empty paint. |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3442 | theme_color_ = theme_color; |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3443 | |
| 3444 | if (did_first_visually_non_empty_paint_ && |
| 3445 | last_sent_theme_color_ != theme_color_) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3446 | for (auto& observer : observers_) |
| 3447 | observer.DidChangeThemeColor(theme_color_); |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3448 | last_sent_theme_color_ = theme_color_; |
| 3449 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 3450 | } |
| 3451 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3452 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3453 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3454 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 3455 | const std::string& mime_type, |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 3456 | ResourceType resource_type) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3457 | for (auto& observer : observers_) |
| 3458 | observer.DidLoadResourceFromMemoryCache(url, mime_type, resource_type); |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 3459 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3460 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
| 3461 | scoped_refptr<net::URLRequestContextGetter> request_context( |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 3462 | resource_type == RESOURCE_TYPE_MEDIA ? |
jam | 2503f93 | 2016-04-15 20:08:30 | [diff] [blame] | 3463 | GetRenderProcessHost()->GetStoragePartition()-> |
| 3464 | GetMediaURLRequestContext() : |
jam | 608f299 | 2016-03-31 16:35:34 | [diff] [blame] | 3465 | GetRenderProcessHost()->GetStoragePartition()-> |
| 3466 | GetURLRequestContext()); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3467 | BrowserThread::PostTask( |
| 3468 | BrowserThread::IO, |
| 3469 | FROM_HERE, |
| 3470 | base::Bind(&NotifyCacheOnIO, request_context, url, http_method)); |
| 3471 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3472 | } |
| 3473 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3474 | void WebContentsImpl::OnDidDisplayInsecureContent() { |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3475 | RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3476 | controller_.ssl_manager()->DidDisplayMixedContent(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3477 | } |
| 3478 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3479 | void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin, |
| 3480 | const GURL& target_url) { |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 3481 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 3482 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3483 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3484 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 3485 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3486 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3487 | controller_.ssl_manager()->DidRunMixedContent(security_origin); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3488 | } |
| 3489 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3490 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors( |
jam | a385e11 | 2016-07-22 00:07:58 | [diff] [blame] | 3491 | const GURL& url) { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3492 | controller_.ssl_manager()->DidDisplayContentWithCertErrors(); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3493 | } |
| 3494 | |
| 3495 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
jam | a385e11 | 2016-07-22 00:07:58 | [diff] [blame] | 3496 | const GURL& url) { |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 3497 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 3498 | if (!entry) |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 3499 | return; |
| 3500 | |
estark | aeda142 | 2016-05-10 02:31:12 | [diff] [blame] | 3501 | // TODO(estark): check that this does something reasonable for |
| 3502 | // about:blank and sandboxed origins. https://crbug.com/609527 |
estark | cd2e30c | 2016-08-12 06:51:15 | [diff] [blame] | 3503 | controller_.ssl_manager()->DidRunContentWithCertErrors( |
| 3504 | entry->GetURL().GetOrigin()); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3505 | } |
| 3506 | |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 3507 | void WebContentsImpl::OnDocumentLoadedInFrame() { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3508 | if (!HasValidFrameSource()) |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3509 | return; |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3510 | |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 3511 | RenderFrameHostImpl* rfh = |
| 3512 | static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3513 | for (auto& observer : observers_) |
| 3514 | observer.DocumentLoadedInFrame(rfh); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3515 | } |
| 3516 | |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3517 | void WebContentsImpl::OnDidFinishLoad(const GURL& url) { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3518 | if (!HasValidFrameSource()) |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 3519 | return; |
[email protected] | a1b9926 | 2013-12-27 21:56:22 | [diff] [blame] | 3520 | |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 3521 | GURL validated_url(url); |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 3522 | RenderProcessHost* render_process_host = |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 3523 | render_frame_message_source_->GetProcess(); |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 3524 | render_process_host->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 3525 | |
[email protected] | 61ac9e24 | 2014-03-21 20:55:26 | [diff] [blame] | 3526 | RenderFrameHostImpl* rfh = |
| 3527 | static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3528 | for (auto& observer : observers_) |
| 3529 | observer.DidFinishLoad(rfh, validated_url); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3530 | } |
| 3531 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3532 | void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
avi | 6ddfcae | 2015-06-30 15:50:57 | [diff] [blame] | 3533 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
| 3534 | controller_.GoToOffset(offset); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3535 | } |
| 3536 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3537 | void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 3538 | int maximum_percent) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3539 | minimum_zoom_percent_ = minimum_percent; |
| 3540 | maximum_zoom_percent_ = maximum_percent; |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3541 | } |
| 3542 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3543 | void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) { |
| 3544 | bool is_one = page_scale_factor == 1.f; |
| 3545 | if (is_one != page_scale_factor_is_one_) { |
| 3546 | page_scale_factor_is_one_ = is_one; |
| 3547 | |
| 3548 | HostZoomMapImpl* host_zoom_map = |
| 3549 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 3550 | |
| 3551 | if (host_zoom_map && GetRenderProcessHost()) { |
| 3552 | host_zoom_map->SetPageScaleFactorIsOneForView( |
| 3553 | GetRenderProcessHost()->GetID(), GetRoutingID(), |
| 3554 | page_scale_factor_is_one_); |
| 3555 | } |
| 3556 | } |
| 3557 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3558 | for (auto& observer : observers_) |
| 3559 | observer.OnPageScaleFactorChanged(page_scale_factor); |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3560 | } |
| 3561 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3562 | void WebContentsImpl::OnEnumerateDirectory(int request_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3563 | const base::FilePath& path) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3564 | if (!delegate_) |
| 3565 | return; |
| 3566 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3567 | ChildProcessSecurityPolicyImpl* policy = |
| 3568 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 45d5c60 | 2013-10-07 18:33:22 | [diff] [blame] | 3569 | if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3570 | delegate_->EnumerateDirectory(this, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3571 | } |
| 3572 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3573 | void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol, |
| 3574 | const GURL& url, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3575 | const base::string16& title, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 3576 | bool user_gesture) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3577 | if (!delegate_) |
| 3578 | return; |
| 3579 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3580 | ChildProcessSecurityPolicyImpl* policy = |
| 3581 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3582 | if (policy->IsPseudoScheme(protocol)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3583 | return; |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3584 | |
[email protected] | c125e53 | 2014-05-10 20:39:06 | [diff] [blame] | 3585 | delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3586 | } |
| 3587 | |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 3588 | void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol, |
| 3589 | const GURL& url, |
| 3590 | bool user_gesture) { |
| 3591 | if (!delegate_) |
| 3592 | return; |
| 3593 | |
| 3594 | ChildProcessSecurityPolicyImpl* policy = |
| 3595 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 3596 | if (policy->IsPseudoScheme(protocol)) |
| 3597 | return; |
| 3598 | |
| 3599 | delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture); |
| 3600 | } |
| 3601 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 3602 | void WebContentsImpl::OnUpdatePageImportanceSignals( |
| 3603 | const PageImportanceSignals& signals) { |
| 3604 | page_importance_signals_ = signals; |
| 3605 | } |
| 3606 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3607 | void WebContentsImpl::OnFindReply(int request_id, |
| 3608 | int number_of_matches, |
| 3609 | const gfx::Rect& selection_rect, |
| 3610 | int active_match_ordinal, |
| 3611 | bool final_update) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3612 | // Forward the find reply to the FindRequestManager, along with the |
| 3613 | // RenderFrameHost associated with the frame that the reply came from. |
| 3614 | GetOrCreateFindRequestManager()->OnFindReply(render_frame_message_source_, |
| 3615 | request_id, |
| 3616 | number_of_matches, |
| 3617 | selection_rect, |
| 3618 | active_match_ordinal, |
| 3619 | final_update); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3620 | } |
| 3621 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 3622 | #if defined(OS_ANDROID) |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3623 | void WebContentsImpl::OnFindMatchRectsReply( |
| 3624 | int version, |
| 3625 | const std::vector<gfx::RectF>& rects, |
| 3626 | const gfx::RectF& active_rect) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 3627 | GetOrCreateFindRequestManager()->OnFindMatchRectsReply( |
| 3628 | render_frame_message_source_, version, rects, active_rect); |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3629 | } |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3630 | |
paulmeyer | c8cb7cb | 2016-06-07 01:14:19 | [diff] [blame] | 3631 | void WebContentsImpl::OnGetNearestFindResultReply(int request_id, |
| 3632 | float distance) { |
| 3633 | GetOrCreateFindRequestManager()->OnGetNearestFindResultReply( |
| 3634 | render_frame_message_source_, request_id, distance); |
| 3635 | } |
| 3636 | |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 3637 | void WebContentsImpl::OnOpenDateTimeDialog( |
| 3638 | const ViewHostMsg_DateTimeDialogValue_Params& value) { |
ajith.v | 9e47ab5 | 2014-10-30 20:24:17 | [diff] [blame] | 3639 | date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(), |
[email protected] | ee59cbec | 2013-08-16 14:59:09 | [diff] [blame] | 3640 | GetRenderViewHost(), |
| 3641 | value.dialog_type, |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 3642 | value.dialog_value, |
[email protected] | ee59cbec | 2013-08-16 14:59:09 | [diff] [blame] | 3643 | value.minimum, |
| 3644 | value.maximum, |
[email protected] | 6e08bfb | 2013-12-07 02:56:17 | [diff] [blame] | 3645 | value.step, |
| 3646 | value.suggestions); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3647 | } |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3648 | #endif |
| 3649 | |
avi | 60bd490 | 2015-09-23 20:39:24 | [diff] [blame] | 3650 | void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) { |
| 3651 | std::string json = json_string; |
| 3652 | NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 3653 | Source<WebContents>(this), |
| 3654 | Details<std::string>(&json)); |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 3655 | } |
| 3656 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3657 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
| 3658 | bool blocked_by_policy) { |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3659 | // Notify observers about navigation. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3660 | for (auto& observer : observers_) |
| 3661 | observer.AppCacheAccessed(manifest_url, blocked_by_policy); |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3662 | } |
| 3663 | |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 3664 | void WebContentsImpl::OnOpenColorChooser( |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3665 | int color_chooser_id, |
| 3666 | SkColor color, |
| 3667 | const std::vector<ColorSuggestion>& suggestions) { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3668 | if (!HasValidFrameSource()) |
mukai | 38b1e4f | 2015-01-23 00:24:00 | [diff] [blame] | 3669 | return; |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3670 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3671 | ColorChooser* new_color_chooser = delegate_ ? |
| 3672 | delegate_->OpenColorChooser(this, color, suggestions) : |
| 3673 | NULL; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 3674 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3675 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3676 | if (color_chooser_info_.get()) |
| 3677 | color_chooser_info_->chooser->End(); |
| 3678 | |
| 3679 | color_chooser_info_.reset(new ColorChooserInfo( |
| 3680 | render_frame_message_source_->GetProcess()->GetID(), |
| 3681 | render_frame_message_source_->GetRoutingID(), |
| 3682 | new_color_chooser, |
| 3683 | color_chooser_id)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3684 | } |
| 3685 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3686 | void WebContentsImpl::OnEndColorChooser(int color_chooser_id) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3687 | if (color_chooser_info_ && |
| 3688 | color_chooser_id == color_chooser_info_->identifier) |
| 3689 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3690 | } |
| 3691 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3692 | void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 3693 | SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3694 | if (color_chooser_info_ && |
| 3695 | color_chooser_id == color_chooser_info_->identifier) |
| 3696 | color_chooser_info_->chooser->SetSelectedColor(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3697 | } |
| 3698 | |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 3699 | // This exists for render views that don't have a WebUI, but do have WebUI |
| 3700 | // bindings enabled. |
| 3701 | void WebContentsImpl::OnWebUISend(const GURL& source_url, |
| 3702 | const std::string& name, |
| 3703 | const base::ListValue& args) { |
| 3704 | if (delegate_) |
| 3705 | delegate_->WebUISend(this, source_url, name, args); |
| 3706 | } |
| 3707 | |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 3708 | #if defined(ENABLE_PLUGINS) |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 3709 | void WebContentsImpl::OnPepperInstanceCreated(int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3710 | for (auto& observer : observers_) |
| 3711 | observer.PepperInstanceCreated(); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 3712 | pepper_playback_observer_->PepperInstanceCreated(pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 3713 | } |
| 3714 | |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 3715 | void WebContentsImpl::OnPepperInstanceDeleted(int32_t pp_instance) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3716 | for (auto& observer : observers_) |
| 3717 | observer.PepperInstanceDeleted(); |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 3718 | pepper_playback_observer_->PepperInstanceDeleted(pp_instance); |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 3719 | } |
| 3720 | |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3721 | void WebContentsImpl::OnPepperPluginHung(int plugin_child_id, |
| 3722 | const base::FilePath& path, |
| 3723 | bool is_hung) { |
| 3724 | UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1); |
| 3725 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3726 | for (auto& observer : observers_) |
| 3727 | observer.PluginHungStatusChanged(plugin_child_id, path, is_hung); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3728 | } |
| 3729 | |
zqzhang | 181047e6 | 2016-07-01 13:37:17 | [diff] [blame] | 3730 | void WebContentsImpl::OnPepperStartsPlayback(int32_t pp_instance) { |
| 3731 | pepper_playback_observer_->PepperStartsPlayback(pp_instance); |
| 3732 | } |
| 3733 | |
| 3734 | void WebContentsImpl::OnPepperStopsPlayback(int32_t pp_instance) { |
| 3735 | pepper_playback_observer_->PepperStopsPlayback(pp_instance); |
| 3736 | } |
| 3737 | |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3738 | void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path, |
| 3739 | base::ProcessId plugin_pid) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3740 | for (auto& observer : observers_) |
| 3741 | observer.PluginCrashed(plugin_path, plugin_pid); |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3742 | } |
| 3743 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3744 | void WebContentsImpl::OnRequestPpapiBrokerPermission( |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3745 | int routing_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3746 | const GURL& url, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3747 | const base::FilePath& plugin_path) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3748 | if (!delegate_) { |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3749 | OnPpapiBrokerPermissionResult(routing_id, false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3750 | return; |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3751 | } |
| 3752 | |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3753 | if (!delegate_->RequestPpapiBrokerPermission( |
| 3754 | this, url, plugin_path, |
| 3755 | base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult, |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3756 | base::Unretained(this), routing_id))) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3757 | NOTIMPLEMENTED(); |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3758 | OnPpapiBrokerPermissionResult(routing_id, false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3759 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3760 | } |
| 3761 | |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3762 | void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3763 | bool result) { |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3764 | Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result)); |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3765 | } |
| 3766 | |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3767 | void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host, |
| 3768 | const IPC::Message& message) { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3769 | CHECK(!browser_plugin_embedder_.get()); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 3770 | CreateBrowserPluginEmbedderIfNecessary(); |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3771 | browser_plugin_embedder_->OnMessageReceived(message, render_frame_host); |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 3772 | } |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3773 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 3774 | |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3775 | void WebContentsImpl::OnUpdateFaviconURL( |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3776 | const std::vector<FaviconURL>& candidates) { |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 3777 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 3778 | // navigation occurs while a page is still loading, the initial page |
| 3779 | // may stop loading and send us updated favicon URLs after the navigation |
| 3780 | // for the new page has committed. |
| 3781 | RenderViewHostImpl* rvhi = |
| 3782 | static_cast<RenderViewHostImpl*>(render_view_message_source_); |
| 3783 | if (!rvhi->is_active()) |
| 3784 | return; |
| 3785 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3786 | for (auto& observer : observers_) |
| 3787 | observer.DidUpdateFaviconURL(candidates); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3788 | } |
| 3789 | |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3790 | void WebContentsImpl::OnMediaSessionStateChanged() { |
| 3791 | MediaSession* session = MediaSession::Get(this); |
zqzhang | dea6962 | 2016-10-13 10:26:51 | [diff] [blame] | 3792 | for (auto& observer : observers_) { |
| 3793 | observer.MediaSessionStateChanged(session->IsControllable(), |
| 3794 | session->IsSuspended()); |
| 3795 | } |
| 3796 | } |
| 3797 | |
| 3798 | void WebContentsImpl::OnMediaSessionMetadataChanged() { |
| 3799 | MediaSession* session = MediaSession::Get(this); |
| 3800 | for (auto& observer : observers_) { |
| 3801 | observer.MediaSessionMetadataChanged(session->metadata()); |
| 3802 | } |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3803 | } |
| 3804 | |
| 3805 | void WebContentsImpl::ResumeMediaSession() { |
mlamouri | 91873409 | 2016-03-12 04:47:52 | [diff] [blame] | 3806 | MediaSession::Get(this)->Resume(MediaSession::SuspendType::UI); |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3807 | } |
| 3808 | |
| 3809 | void WebContentsImpl::SuspendMediaSession() { |
mlamouri | 91873409 | 2016-03-12 04:47:52 | [diff] [blame] | 3810 | MediaSession::Get(this)->Suspend(MediaSession::SuspendType::UI); |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3811 | } |
| 3812 | |
mlamouri | 4c4fbed | 2015-08-17 15:51:01 | [diff] [blame] | 3813 | void WebContentsImpl::StopMediaSession() { |
mlamouri | 91873409 | 2016-03-12 04:47:52 | [diff] [blame] | 3814 | MediaSession::Get(this)->Stop(MediaSession::SuspendType::UI); |
mlamouri | 4c4fbed | 2015-08-17 15:51:01 | [diff] [blame] | 3815 | } |
| 3816 | |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 3817 | void WebContentsImpl::OnPasswordInputShownOnHttp() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3818 | controller_.ssl_manager()->DidShowPasswordInputOnHttp(); |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 3819 | } |
| 3820 | |
| 3821 | void WebContentsImpl::OnCreditCardInputShownOnHttp() { |
estark | c227350 | 2016-10-12 22:03:02 | [diff] [blame] | 3822 | controller_.ssl_manager()->DidShowCreditCardInputOnHttp(); |
estark | 703f1b4 | 2016-10-10 21:37:15 | [diff] [blame] | 3823 | } |
| 3824 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 3825 | void WebContentsImpl::SetIsOverlayContent(bool is_overlay_content) { |
| 3826 | is_overlay_content_ = is_overlay_content; |
| 3827 | } |
| 3828 | |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 3829 | void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3830 | for (auto& observer : observers_) |
| 3831 | observer.DidFirstVisuallyNonEmptyPaint(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3832 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3833 | did_first_visually_non_empty_paint_ = true; |
| 3834 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3835 | if (theme_color_ != last_sent_theme_color_) { |
| 3836 | // Theme color should have updated by now if there was one. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3837 | for (auto& observer : observers_) |
| 3838 | observer.DidChangeThemeColor(theme_color_); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3839 | last_sent_theme_color_ = theme_color_; |
| 3840 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 3841 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 3842 | |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3843 | void WebContentsImpl::DidChangeVisibleSSLState() { |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3844 | if (delegate_) { |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 3845 | delegate_->VisibleSSLStateChanged(this); |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3846 | |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 3847 | SecurityStyleExplanations security_style_explanations; |
estark | 47ba9c7d | 2016-10-11 15:40:11 | [diff] [blame] | 3848 | blink::WebSecurityStyle security_style = |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 3849 | delegate_->GetSecurityStyle(this, &security_style_explanations); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3850 | for (auto& observer : observers_) { |
| 3851 | observer.SecurityStyleChanged(security_style, |
| 3852 | security_style_explanations); |
| 3853 | } |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3854 | } |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3855 | } |
| 3856 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 3857 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3858 | for (auto& observer : observers_) |
| 3859 | observer.BeforeFormRepostWarningShow(); |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 3860 | } |
| 3861 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 3862 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
| 3863 | Activate(); |
| 3864 | if (delegate_) |
| 3865 | delegate_->ShowRepostFormWarningDialog(this); |
| 3866 | } |
| 3867 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 3868 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 3869 | return has_accessed_initial_document_; |
| 3870 | } |
| 3871 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 3872 | void WebContentsImpl::UpdateTitleForEntry(NavigationEntry* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3873 | const base::string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3874 | // For file URLs without a title, use the pathname instead. In the case of a |
| 3875 | // synthesized title, we don't want the update to count toward the "one set |
| 3876 | // per page of the title to history." |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3877 | base::string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3878 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3879 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 3880 | final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3881 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 3882 | } else { |
[email protected] | 8af69c6c | 2014-03-03 19:05:31 | [diff] [blame] | 3883 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3884 | explicit_set = true; |
| 3885 | } |
| 3886 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3887 | // If a page is created via window.open and never navigated, |
| 3888 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3889 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3890 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3891 | if (final_title == entry->GetTitle()) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 3892 | return; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3893 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3894 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3895 | } else { |
| 3896 | if (page_title_when_no_navigation_entry_ == final_title) |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 3897 | return; // Nothing changed, don't bother. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3898 | |
| 3899 | page_title_when_no_navigation_entry_ = final_title; |
| 3900 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3901 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3902 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 3903 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3904 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3905 | for (auto& observer : observers_) |
| 3906 | observer.TitleWasSet(entry, explicit_set); |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 3907 | |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 3908 | // Broadcast notifications when the UI should be updated. |
| 3909 | if (entry == controller_.GetEntryAtOffset(0)) |
| 3910 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3911 | } |
| 3912 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 3913 | void WebContentsImpl::SendChangeLoadProgress() { |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3914 | loading_last_progress_update_ = base::TimeTicks::Now(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3915 | if (delegate_) |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 3916 | delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3917 | } |
| 3918 | |
| 3919 | void WebContentsImpl::ResetLoadProgressState() { |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 3920 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3921 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 3922 | loading_last_progress_update_ = base::TimeTicks(); |
| 3923 | } |
| 3924 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3925 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 3926 | // loading, or done loading. |
| 3927 | void WebContentsImpl::LoadingStateChanged(bool to_different_document, |
| 3928 | bool due_to_interstitial, |
| 3929 | LoadNotificationDetails* details) { |
| 3930 | // Do not send notifications about loading changes in the FrameTree while the |
| 3931 | // interstitial page is pausing the throbber. |
| 3932 | if (ShowingInterstitialPage() && |
| 3933 | GetRenderManager()->interstitial_page()->pause_throbber() && |
| 3934 | !due_to_interstitial) { |
| 3935 | return; |
| 3936 | } |
| 3937 | |
| 3938 | bool is_loading = IsLoading(); |
| 3939 | |
| 3940 | if (!is_loading) { |
| 3941 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 3942 | base::string16()); |
| 3943 | load_state_host_.clear(); |
| 3944 | upload_size_ = 0; |
| 3945 | upload_position_ = 0; |
| 3946 | } |
| 3947 | |
| 3948 | GetRenderManager()->SetIsLoading(is_loading); |
| 3949 | |
| 3950 | waiting_for_response_ = is_loading; |
| 3951 | is_load_to_different_document_ = to_different_document; |
| 3952 | |
| 3953 | if (delegate_) |
| 3954 | delegate_->LoadingStateChanged(this, to_different_document); |
| 3955 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
| 3956 | |
| 3957 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
| 3958 | if (is_loading) { |
| 3959 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 3960 | this, "URL", url, "Main FrameTreeNode id", |
| 3961 | GetFrameTree()->root()->frame_tree_node_id()); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3962 | for (auto& observer : observers_) |
| 3963 | observer.DidStartLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3964 | } else { |
| 3965 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 3966 | this, "URL", url); |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3967 | for (auto& observer : observers_) |
| 3968 | observer.DidStopLoading(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 3969 | } |
| 3970 | |
| 3971 | // TODO(avi): Remove. http://crbug.com/170921 |
| 3972 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 3973 | NotificationDetails det = NotificationService::NoDetails(); |
| 3974 | if (details) |
| 3975 | det = Details<LoadNotificationDetails>(details); |
| 3976 | NotificationService::current()->Notify( |
| 3977 | type, Source<NavigationController>(&controller_), det); |
| 3978 | } |
| 3979 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 3980 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host, |
| 3981 | RenderViewHost* new_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3982 | // After sending out a swap notification, we need to send a disconnect |
| 3983 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 3984 | // pointer. See Bug 1230284. |
| 3985 | notify_disconnection_ = true; |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3986 | for (auto& observer : observers_) |
| 3987 | observer.RenderViewHostChanged(old_host, new_host); |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 3988 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3989 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 3990 | // gets swapped, so we don't reuse the same embedder next time a |
| 3991 | // RenderViewHost is attached to this WebContents. |
| 3992 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3993 | } |
| 3994 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 3995 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host, |
| 3996 | RenderFrameHost* new_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 3997 | for (auto& observer : observers_) |
| 3998 | observer.RenderFrameHostChanged(old_host, new_host); |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 3999 | } |
| 4000 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4001 | // TODO(avi): Remove this entire function because this notification is already |
| 4002 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4003 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4004 | if (!notify_disconnection_) |
| 4005 | return; |
| 4006 | |
| 4007 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4008 | NotificationService::current()->Notify( |
| 4009 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 4010 | Source<WebContents>(this), |
| 4011 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4012 | } |
| 4013 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 4014 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 4015 | const LoadCommittedDetails& load_details) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4016 | for (auto& observer : observers_) |
| 4017 | observer.NavigationEntryCommitted(load_details); |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 4018 | } |
| 4019 | |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 4020 | bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, |
| 4021 | const IPC::Message& message) { |
| 4022 | return OnMessageReceived(NULL, render_frame_host, message); |
[email protected] | 271ff579 | 2013-12-04 22:29:31 | [diff] [blame] | 4023 | } |
| 4024 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 4025 | void WebContentsImpl::OnAssociatedInterfaceRequest( |
| 4026 | RenderFrameHost* render_frame_host, |
| 4027 | const std::string& interface_name, |
| 4028 | mojo::ScopedInterfaceEndpointHandle handle) { |
| 4029 | auto it = binding_sets_.find(interface_name); |
| 4030 | if (it != binding_sets_.end()) |
| 4031 | it->second->OnRequestForFrame(render_frame_host, std::move(handle)); |
| 4032 | } |
| 4033 | |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 4034 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
| 4035 | return GetLastCommittedURL(); |
| 4036 | } |
| 4037 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4038 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4039 | for (auto& observer : observers_) |
| 4040 | observer.RenderFrameCreated(render_frame_host); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 4041 | SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); |
clamy | 91b7abf | 2016-03-24 15:17:45 | [diff] [blame] | 4042 | |
| 4043 | if (!render_frame_host->IsRenderFrameLive() || render_frame_host->GetParent()) |
| 4044 | return; |
| 4045 | |
| 4046 | NavigationEntry* entry = controller_.GetPendingEntry(); |
| 4047 | if (entry && entry->IsViewSourceMode()) { |
| 4048 | // Put the renderer in view source mode. |
| 4049 | render_frame_host->Send( |
| 4050 | new FrameMsg_EnableViewSourceMode(render_frame_host->GetRoutingID())); |
| 4051 | } |
sammc | 5a139ba | 2016-09-29 01:49:14 | [diff] [blame] | 4052 | #if defined(OS_ANDROID) |
| 4053 | render_frame_host->GetInterfaceRegistry()->AddInterface( |
| 4054 | GetJavaInterfaces()->CreateInterfaceFactory<device::nfc::mojom::NFC>()); |
| 4055 | #endif |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4056 | } |
| 4057 | |
| 4058 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4059 | for (auto& observer : observers_) |
| 4060 | observer.RenderFrameDeleted(render_frame_host); |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 4061 | } |
| 4062 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4063 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 4064 | const ContextMenuParams& params) { |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4065 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4066 | // Allow WebContentsDelegates to handle the context menu operation first. |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4067 | if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4068 | return; |
| 4069 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 4070 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 4071 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 4072 | } |
| 4073 | |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4074 | void WebContentsImpl::RunJavaScriptMessage( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4075 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4076 | const base::string16& message, |
| 4077 | const base::string16& default_prompt, |
| 4078 | const GURL& frame_url, |
| 4079 | JavaScriptMessageType javascript_message_type, |
| 4080 | IPC::Message* reply_msg) { |
| 4081 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 4082 | // showing an interstitial as it's shown over the previous page and we don't |
| 4083 | // want the hidden page's dialogs to interfere with the interstitial. |
| 4084 | bool suppress_this_message = |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4085 | ShowingInterstitialPage() || !delegate_ || |
| 4086 | delegate_->ShouldSuppressDialogs(this) || |
| 4087 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4088 | |
| 4089 | if (!suppress_this_message) { |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 4090 | is_showing_javascript_dialog_ = true; |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4091 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4092 | dialog_manager_->RunJavaScriptDialog( |
jshin | 1fb7646 | 2016-04-05 22:13:03 | [diff] [blame] | 4093 | this, frame_url, javascript_message_type, message, default_prompt, |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 4094 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4095 | render_frame_host->GetProcess()->GetID(), |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 4096 | render_frame_host->GetRoutingID(), reply_msg, false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4097 | &suppress_this_message); |
| 4098 | } |
| 4099 | |
| 4100 | if (suppress_this_message) { |
| 4101 | // If we are suppressing messages, just reply as if the user immediately |
| 4102 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4103 | OnDialogClosed(render_frame_host->GetProcess()->GetID(), |
| 4104 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4105 | true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4106 | } |
| 4107 | |
| 4108 | // OnDialogClosed (two lines up) may have caused deletion of this object (see |
| 4109 | // http://crbug.com/288961 ). The only safe thing to do here is return. |
| 4110 | } |
| 4111 | |
| 4112 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4113 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4114 | bool is_reload, |
| 4115 | IPC::Message* reply_msg) { |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4116 | RenderFrameHostImpl* rfhi = |
| 4117 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4118 | if (delegate_) |
| 4119 | delegate_->WillRunBeforeUnloadConfirm(); |
| 4120 | |
| 4121 | bool suppress_this_message = |
nasko | 19736cc9f | 2016-04-08 22:38:45 | [diff] [blame] | 4122 | !rfhi->is_active() || |
creis | 36e228b | 2015-06-08 18:48:02 | [diff] [blame] | 4123 | ShowingInterstitialPage() || !delegate_ || |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4124 | delegate_->ShouldSuppressDialogs(this) || |
| 4125 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4126 | if (suppress_this_message) { |
| 4127 | rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); |
| 4128 | return; |
| 4129 | } |
| 4130 | |
| 4131 | is_showing_before_unload_dialog_ = true; |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 4132 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4133 | dialog_manager_->RunBeforeUnloadDialog( |
avi | 141dbc132 | 2016-03-11 22:27:42 | [diff] [blame] | 4134 | this, is_reload, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4135 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4136 | render_frame_host->GetProcess()->GetID(), |
| 4137 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4138 | false)); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4139 | } |
| 4140 | |
nasko | ada75b2 | 2016-06-11 16:09:46 | [diff] [blame] | 4141 | void WebContentsImpl::RunFileChooser(RenderFrameHost* render_frame_host, |
| 4142 | const FileChooserParams& params) { |
| 4143 | if (delegate_) |
| 4144 | delegate_->RunFileChooser(render_frame_host, params); |
| 4145 | } |
| 4146 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 4147 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 4148 | return this; |
| 4149 | } |
| 4150 | |
wjmaclean | 6495190 | 2016-04-29 20:59:12 | [diff] [blame] | 4151 | double WebContentsImpl::GetPendingPageZoomLevel() { |
| 4152 | NavigationEntry* pending_entry = GetController().GetPendingEntry(); |
| 4153 | if (!pending_entry) |
| 4154 | return HostZoomMap::GetZoomLevel(this); |
| 4155 | |
| 4156 | GURL url = pending_entry->GetURL(); |
| 4157 | return HostZoomMap::GetForWebContents(this)->GetZoomLevelForHostAndScheme( |
| 4158 | url.scheme(), net::GetHostOrSpecFromURL(url)); |
| 4159 | } |
| 4160 | |
qinmin | 72e8bd0 | 2016-10-21 19:35:37 | [diff] [blame] | 4161 | bool WebContentsImpl::HideDownloadUI() const { |
| 4162 | return is_overlay_content_; |
| 4163 | } |
| 4164 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 4165 | bool WebContentsImpl::IsNeverVisible() { |
| 4166 | if (!delegate_) |
| 4167 | return false; |
| 4168 | return delegate_->IsNeverVisible(this); |
| 4169 | } |
| 4170 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 4171 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 4172 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4173 | } |
| 4174 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4175 | RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 4176 | BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 4177 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 4178 | } |
| 4179 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4180 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 4181 | if (browser_plugin_embedder_) |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4182 | browser_plugin_embedder_.reset(); |
| 4183 | } |
| 4184 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4185 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4186 | if (GuestMode::IsCrossProcessFrameGuest(this) && node_) |
| 4187 | return node_->outer_web_contents(); |
| 4188 | |
| 4189 | if (browser_plugin_guest_) |
| 4190 | return browser_plugin_guest_->embedder_web_contents(); |
| 4191 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4192 | return nullptr; |
| 4193 | } |
| 4194 | |
| 4195 | WebContentsImpl* WebContentsImpl::GetFocusedWebContents() { |
| 4196 | // There is no inner or outer web contents. |
| 4197 | if (!node_ && !GetBrowserPluginGuest()) |
| 4198 | return this; |
| 4199 | |
| 4200 | // We may need to create a node_ on the outermost contents in the |
| 4201 | // BrowserPlugin case. |
| 4202 | WebContentsImpl* outermost = GetOutermostWebContents(); |
| 4203 | if (!outermost->node_) { |
| 4204 | outermost->node_.reset(new WebContentsTreeNode()); |
| 4205 | outermost->node_->SetFocusedWebContents(outermost); |
| 4206 | } |
| 4207 | return outermost->node_->focused_web_contents(); |
| 4208 | } |
| 4209 | |
| 4210 | WebContentsImpl* WebContentsImpl::GetOutermostWebContents() { |
| 4211 | WebContentsImpl* root = this; |
| 4212 | while (root->GetOuterWebContents()) |
| 4213 | root = root->GetOuterWebContents(); |
| 4214 | return root; |
| 4215 | } |
| 4216 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4217 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4218 | // Don't send notifications if we are just creating a swapped-out RVH for |
| 4219 | // the opener chain. These won't be used for view-source or WebUI, so it's |
| 4220 | // ok to return early. |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 4221 | if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4222 | return; |
| 4223 | |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 4224 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 4225 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 4226 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4227 | NotificationService::current()->Notify( |
| 4228 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 4229 | Source<WebContents>(this), |
| 4230 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4231 | |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4232 | view_->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 4233 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4234 | for (auto& observer : observers_) |
| 4235 | observer.RenderViewCreated(render_view_host); |
dgozman | f00c4f7 | 2016-10-19 17:45:15 | [diff] [blame] | 4236 | RenderFrameDevToolsAgentHost::WebContentsCreated(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4237 | } |
| 4238 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4239 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4240 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4241 | // Don't notify the world, since this came from a renderer in the |
| 4242 | // background. |
| 4243 | return; |
| 4244 | } |
| 4245 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 4246 | notify_disconnection_ = true; |
| 4247 | // TODO(avi): Remove. http://crbug.com/170921 |
| 4248 | NotificationService::current()->Notify( |
| 4249 | NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 4250 | Source<WebContents>(this), |
| 4251 | NotificationService::NoDetails()); |
| 4252 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 4253 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 4254 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 4255 | |
| 4256 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 4257 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 4258 | if (was_crashed && !FocusLocationBarByDefault() && |
| 4259 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 4260 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 4261 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 4262 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4263 | for (auto& observer : observers_) |
| 4264 | observer.RenderViewReady(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4265 | } |
| 4266 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 4267 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 4268 | base::TerminationStatus status, |
| 4269 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4270 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4271 | // The pending page's RenderViewHost is gone. |
| 4272 | return; |
| 4273 | } |
| 4274 | |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 4275 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 4276 | // renderer may not have made a clean exit. |
alexmos | 5dd617d | 2016-06-07 04:21:15 | [diff] [blame] | 4277 | if (IsFullscreenForCurrentTab()) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 4278 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 4279 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 4280 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 4281 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 4282 | |
[email protected] | f738bdcb | 2014-07-11 20:40:44 | [diff] [blame] | 4283 | if (delegate_) |
| 4284 | delegate_->HideValidationMessage(this); |
| 4285 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4286 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 4287 | // "renderer crash" when there is more than one renderer process serving a |
| 4288 | // webpage? Once this function is called at a more granular frame level, we |
| 4289 | // probably will need to more granularly reset the state here. |
| 4290 | ResetLoadProgressState(); |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4291 | NotifyDisconnected(); |
| 4292 | SetIsCrashed(status, error_code); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 4293 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4294 | for (auto& observer : observers_) |
| 4295 | observer.RenderProcessGone(GetCrashedStatus()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4296 | } |
| 4297 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4298 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4299 | for (auto& observer : observers_) |
| 4300 | observer.RenderViewDeleted(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 4301 | } |
| 4302 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4303 | void WebContentsImpl::UpdateState(RenderViewHost* rvh, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 4304 | const PageState& page_state) { |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4305 | DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 4306 | |
creis | e1d3e5b | 2014-12-01 18:21:57 | [diff] [blame] | 4307 | // Ensure that this state update comes from a RenderViewHost that belongs to |
| 4308 | // this WebContents. |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 4309 | // TODO(nasko): This should go through RenderFrameHost. |
creis | e1d3e5b | 2014-12-01 18:21:57 | [diff] [blame] | 4310 | if (rvh->GetDelegate()->GetAsWebContents() != this) |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 4311 | return; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4312 | |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 4313 | if (!rvh->GetMainFrame()) { |
| 4314 | // When UseSubframeNavigationEntries is turned off, state updates only come |
| 4315 | // in on main frames. When UseSubframeNavigationEntries is turned on, |
| 4316 | // UpdateStateForFrame() should have been called rather than this function. |
| 4317 | NOTREACHED(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4318 | return; |
nasko | 34696991 | 2015-12-16 22:36:47 | [diff] [blame] | 4319 | } |
creis | d63f6c4a | 2015-11-06 19:05:53 | [diff] [blame] | 4320 | |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 4321 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
| 4322 | static_cast<RenderFrameHostImpl*>(rvh->GetMainFrame())->nav_entry_id()); |
| 4323 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 4324 | if (page_state == entry->GetPageState()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4325 | return; // Nothing to update. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 4326 | entry->SetPageState(page_state); |
avi | 4717933 | 2015-05-20 21:01:11 | [diff] [blame] | 4327 | controller_.NotifyEntryChanged(entry); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4328 | } |
| 4329 | |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4330 | void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host, |
| 4331 | const GURL& url) { |
| 4332 | if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) { |
| 4333 | // If we're fullscreen only update the url if it's from the fullscreen |
| 4334 | // renderer. |
| 4335 | RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView(); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4336 | if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget()) |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4337 | return; |
| 4338 | } |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4339 | if (delegate_) |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 4340 | delegate_->UpdateTargetURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4341 | } |
| 4342 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4343 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4344 | #if defined(OS_MACOSX) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4345 | // The UI may be in an event-tracking loop, such as between the |
| 4346 | // mouse-down and mouse-up in text selection or a button click. |
| 4347 | // Defer the close until after tracking is complete, so that we |
| 4348 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4349 | // TODO(shess): This could get more fine-grained. For instance, |
| 4350 | // closing a tab in another window while selecting text in the |
| 4351 | // current window's Omnibox should be just fine. |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4352 | if (view_->IsEventTracking()) { |
| 4353 | view_->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4354 | return; |
| 4355 | } |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4356 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4357 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4358 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4359 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4360 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4361 | } |
| 4362 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4363 | void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4364 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 4365 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4366 | } |
| 4367 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4368 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 4369 | bool to_different_document) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4370 | LoadingStateChanged(to_different_document, false, nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4371 | |
| 4372 | // Notify accessibility that the user is navigating away from the |
| 4373 | // current document. |
| 4374 | // |
| 4375 | // TODO(dmazzoni): do this using a WebContentsObserver. |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4376 | BrowserAccessibilityManager* manager = |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4377 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4378 | if (manager) |
| 4379 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4380 | } |
| 4381 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 4382 | void WebContentsImpl::DidStopLoading() { |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 4383 | std::unique_ptr<LoadNotificationDetails> details; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4384 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4385 | // Use the last committed entry rather than the active one, in case a |
| 4386 | // pending entry has been created. |
| 4387 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4388 | Navigator* navigator = frame_tree_.root()->navigator(); |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4389 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4390 | // An entry may not exist for a stop when loading an initial blank page or |
| 4391 | // if an iframe injected by script into a blank page finishes loading. |
| 4392 | if (entry) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4393 | base::TimeDelta elapsed = |
| 4394 | base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4395 | |
| 4396 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4397 | entry->GetVirtualURL(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4398 | elapsed, |
| 4399 | &controller_, |
| 4400 | controller_.GetCurrentEntryIndex())); |
| 4401 | } |
| 4402 | |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4403 | LoadingStateChanged(true, false, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4404 | } |
| 4405 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4406 | void WebContentsImpl::DidChangeLoadProgress() { |
| 4407 | double load_progress = frame_tree_.load_progress(); |
| 4408 | |
| 4409 | // The delegate is notified immediately for the first and last updates. Also, |
| 4410 | // since the message loop may be pretty busy when a page is loaded, it might |
| 4411 | // not execute a posted task in a timely manner so the progress report is sent |
| 4412 | // immediately if enough time has passed. |
| 4413 | base::TimeDelta min_delay = |
| 4414 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 4415 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 4416 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 4417 | |
| 4418 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 4419 | // If there is a pending task to send progress, it is now obsolete. |
| 4420 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 4421 | |
| 4422 | // Notify the load progress change. |
| 4423 | SendChangeLoadProgress(); |
| 4424 | |
| 4425 | // Clean-up the states if needed. |
| 4426 | if (load_progress == 1.0) |
| 4427 | ResetLoadProgressState(); |
| 4428 | return; |
| 4429 | } |
| 4430 | |
| 4431 | if (loading_weak_factory_.HasWeakPtrs()) |
| 4432 | return; |
| 4433 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 4434 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 4435 | FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress, |
| 4436 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4437 | min_delay); |
| 4438 | } |
| 4439 | |
clamy | cbf524d4 | 2016-09-27 12:48:35 | [diff] [blame] | 4440 | ScopedVector<NavigationThrottle> WebContentsImpl::CreateThrottlesForNavigation( |
| 4441 | NavigationHandle* navigation_handle) { |
| 4442 | return GetContentClient()->browser()->CreateThrottlesForNavigation( |
| 4443 | navigation_handle); |
| 4444 | } |
| 4445 | |
clamy | 1e5574e | 2016-09-29 16:48:44 | [diff] [blame] | 4446 | std::unique_ptr<NavigationUIData> WebContentsImpl::GetNavigationUIData( |
| 4447 | NavigationHandle* navigation_handle) { |
| 4448 | DCHECK(IsBrowserSideNavigationEnabled()); |
| 4449 | return GetContentClient()->browser()->GetNavigationUIData(navigation_handle); |
| 4450 | } |
| 4451 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4452 | void WebContentsImpl::DidCancelLoading() { |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4453 | controller_.DiscardNonCommittedEntries(); |
| 4454 | |
| 4455 | // Update the URL display. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4456 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4457 | } |
| 4458 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4459 | void WebContentsImpl::DidAccessInitialDocument() { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4460 | has_accessed_initial_document_ = true; |
| 4461 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4462 | // We may have left a failed browser-initiated navigation in the address bar |
| 4463 | // to let the user edit it and try again. Clear it now that content might |
| 4464 | // show up underneath it. |
| 4465 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 4466 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4467 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4468 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 4469 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4470 | } |
| 4471 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 4472 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 4473 | const std::string& name) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4474 | for (auto& observer : observers_) |
| 4475 | observer.FrameNameChanged(render_frame_host, name); |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 4476 | } |
| 4477 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4478 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4479 | RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4480 | for (auto& observer : observers_) |
| 4481 | observer.DocumentOnLoadCompletedInMainFrame(); |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 4482 | |
| 4483 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4484 | NotificationService::current()->Notify( |
| 4485 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 4486 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4487 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 4488 | } |
| 4489 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4490 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
| 4491 | const PageState& page_state) { |
| 4492 | DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 4493 | |
| 4494 | // The state update affects the last NavigationEntry associated with the given |
| 4495 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 4496 | // in the case of an UpdateState from a frame being swapped out). We track |
| 4497 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 4498 | RenderFrameHostImpl* rfhi = |
| 4499 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 4500 | NavigationEntryImpl* entry = |
| 4501 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 4502 | if (!entry) |
| 4503 | return; |
| 4504 | |
| 4505 | FrameNavigationEntry* frame_entry = |
| 4506 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 4507 | if (!frame_entry) |
| 4508 | return; |
| 4509 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 4510 | // The SiteInstance might not match if we do a cross-process navigation with |
| 4511 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 4512 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 4513 | // has already been replaced and destroyed. |
| 4514 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 4515 | return; |
| 4516 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4517 | if (page_state == frame_entry->page_state()) |
| 4518 | return; // Nothing to update. |
| 4519 | |
creis | fafed88 | 2016-07-29 00:03:09 | [diff] [blame] | 4520 | if (!page_state.IsValid()) { |
| 4521 | // Temporarily generate a minidump to diagnose https://crbug.com/568703. |
| 4522 | base::debug::DumpWithoutCrashing(); |
| 4523 | NOTREACHED() << "Shouldn't set an empty PageState."; |
| 4524 | } |
nasko | 3463467 | 2016-07-29 18:46:06 | [diff] [blame] | 4525 | |
| 4526 | // The document_sequence_number and item_sequence_number recorded in the |
| 4527 | // FrameNavigationEntry should not differ from the one coming with the update, |
| 4528 | // since it must come from the same document. Do not update it if a difference |
| 4529 | // is detected, as this indicates that |frame_entry| is not the correct one. |
| 4530 | ExplodedPageState exploded_state; |
| 4531 | if (!DecodePageState(page_state.ToEncodedData(), &exploded_state)) |
| 4532 | return; |
| 4533 | |
| 4534 | if (exploded_state.top.document_sequence_number != |
| 4535 | frame_entry->document_sequence_number() || |
| 4536 | exploded_state.top.item_sequence_number != |
| 4537 | frame_entry->item_sequence_number()) { |
| 4538 | return; |
| 4539 | } |
| 4540 | |
nasko | 04a322f25a | 2016-09-01 00:00:34 | [diff] [blame] | 4541 | frame_entry->SetPageState(page_state); |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4542 | controller_.NotifyEntryChanged(entry); |
| 4543 | } |
| 4544 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4545 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4546 | const base::string16& title, |
| 4547 | base::i18n::TextDirection title_direction) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4548 | // If we have a title, that's a pretty good indication that we've started |
| 4549 | // getting useful data. |
| 4550 | SetNotWaitingForResponse(); |
| 4551 | |
| 4552 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4553 | // For example, it might be from a recently swapped out RFH. |
avi | 1edc855 | 2016-10-13 21:37:16 | [diff] [blame] | 4554 | NavigationEntryImpl* entry = controller_.GetEntryWithUniqueID( |
creis | ad8c31a | 2016-05-24 17:07:04 | [diff] [blame] | 4555 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4556 | |
| 4557 | // We can handle title updates when we don't have an entry in |
| 4558 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 4559 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4560 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4561 | return; |
| 4562 | |
| 4563 | // TODO(evan): make use of title_direction. |
| 4564 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
afakhry | 6f0c1ec2 | 2016-07-14 13:55:13 | [diff] [blame] | 4565 | UpdateTitleForEntry(entry, title); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4566 | } |
| 4567 | |
| 4568 | void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
| 4569 | const std::string& encoding) { |
| 4570 | SetEncoding(encoding); |
| 4571 | } |
| 4572 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4573 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 4574 | RenderViewHost* render_view_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4575 | for (auto& observer : observers_) |
| 4576 | observer.DocumentAvailableInMainFrame(); |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4577 | } |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4578 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4579 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 4580 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 4581 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 4582 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 4583 | // It is possible to receive it from one that has just been swapped in, |
| 4584 | // in which case we might as well deliver the message anyway. |
| 4585 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4586 | ClosePage(); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4587 | } |
| 4588 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4589 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 4590 | RenderFrameHost* target_rfh, |
| 4591 | SiteInstance* source_site_instance) const { |
| 4592 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 4593 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 4594 | // Note: This check means that an embedder could theoretically receive a |
| 4595 | // postMessage from anyone (not just its own guests). However, this is |
| 4596 | // probably not a risk for apps since other pages won't have references |
| 4597 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4598 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 4599 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4600 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4601 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4602 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 4603 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4604 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4605 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4606 | // If this message is going to outer WebContents from inner WebContents, |
| 4607 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 4608 | // already created a RenderFrameProxyHost for that purpose. |
| 4609 | if (GetBrowserPluginEmbedder() && |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4610 | GuestMode::IsCrossProcessFrameGuest(source_web_contents)) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4611 | return; |
| 4612 | } |
| 4613 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 4614 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | b3041b98a4 | 2016-03-12 04:43:06 | [diff] [blame] | 4615 | // We create a RenderFrameProxyHost for the embedder in the guest's render |
| 4616 | // process but we intentionally do not expose the embedder's opener chain |
| 4617 | // to it. |
| 4618 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 4619 | GetSiteInstance()); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4620 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4621 | RenderFrameHostImpl* source_rfhi = |
| 4622 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4623 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 4624 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4625 | } |
| 4626 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4627 | } |
| 4628 | |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4629 | void WebContentsImpl::SetFocusedFrame(FrameTreeNode* node, |
| 4630 | SiteInstance* source) { |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4631 | if (!GuestMode::IsCrossProcessFrameGuest(this) && browser_plugin_guest_) { |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4632 | frame_tree_.SetFocusedFrame(node, source); |
| 4633 | return; |
| 4634 | } |
| 4635 | |
| 4636 | // 1. Find old focused frame and unfocus it. |
| 4637 | // 2. Focus the new frame in the current FrameTree. |
| 4638 | // 3. Set current WebContents as focused. |
| 4639 | WebContentsImpl* old_focused_contents = GetFocusedWebContents(); |
| 4640 | if (old_focused_contents != this) { |
| 4641 | // Focus is moving between frame trees, unfocus the frame in the old tree. |
| 4642 | old_focused_contents->frame_tree_.SetFocusedFrame(nullptr, source); |
| 4643 | GetOutermostWebContents()->node_->SetFocusedWebContents(this); |
| 4644 | } |
| 4645 | |
| 4646 | frame_tree_.SetFocusedFrame(node, source); |
| 4647 | |
| 4648 | // TODO(avallee): Remove this once page focus is fixed. |
| 4649 | RenderWidgetHostImpl* rwh = node->current_frame_host()->GetRenderWidgetHost(); |
ekaramad | 1beabecc | 2016-09-23 20:18:17 | [diff] [blame] | 4650 | if (rwh && old_focused_contents != this) |
avallee | 0206f78 | 2016-07-28 18:55:33 | [diff] [blame] | 4651 | rwh->Focus(); |
| 4652 | } |
| 4653 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4654 | bool WebContentsImpl::AddMessageToConsole(int32_t level, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4655 | const base::string16& message, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4656 | int32_t line_no, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4657 | const base::string16& source_id) { |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 4658 | if (!delegate_) |
| 4659 | return false; |
| 4660 | return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 4661 | source_id); |
| 4662 | } |
| 4663 | |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 4664 | void WebContentsImpl::OnUserInteraction( |
| 4665 | RenderWidgetHostImpl* render_widget_host, |
| 4666 | const blink::WebInputEvent::Type type) { |
kenrb | 1922185 | 2016-04-29 17:21:40 | [diff] [blame] | 4667 | // Ignore unless the widget is currently in the frame tree. |
| 4668 | if (!HasMatchingWidgetHost(&frame_tree_, render_widget_host)) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4669 | return; |
| 4670 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4671 | for (auto& observer : observers_) |
| 4672 | observer.DidGetUserInteraction(type); |
dominickn | 9c7ceaa3 | 2016-02-27 01:52:53 | [diff] [blame] | 4673 | |
| 4674 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
| 4675 | // Exclude scroll events as user gestures for resource load dispatches. |
| 4676 | // rdh is NULL in unittests. |
| 4677 | if (rdh && type != blink::WebInputEvent::MouseWheel) |
scottmg | e22a5e5 | 2016-06-30 00:36:51 | [diff] [blame] | 4678 | rdh->OnUserGesture(); |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 4679 | } |
| 4680 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4681 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4682 | // Notify observers. |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4683 | for (auto& observer : observers_) |
| 4684 | observer.DidGetIgnoredUIEvent(); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 4685 | } |
| 4686 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4687 | void WebContentsImpl::RendererUnresponsive( |
clamy | 639fdffb | 2016-07-18 18:13:32 | [diff] [blame] | 4688 | RenderWidgetHostImpl* render_widget_host, |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 4689 | RendererUnresponsiveType type) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4690 | for (auto& observer : observers_) |
| 4691 | observer.OnRendererUnresponsive(render_widget_host); |
afakhry | 9824183 | 2016-03-11 19:27:47 | [diff] [blame] | 4692 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4693 | // Don't show hung renderer dialog for a swapped out RVH. |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4694 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4695 | return; |
| 4696 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 4697 | RenderFrameHostImpl* rfhi = |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4698 | static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame()); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 4699 | |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 4700 | // Ignore renderer unresponsive event if debugger is attached to the tab |
| 4701 | // since the event may be a result of the renderer sitting on a breakpoint. |
| 4702 | // See http://crbug.com/65458 |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 4703 | if (DevToolsAgentHost::IsDebuggerAttached(this)) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 4704 | return; |
| 4705 | |
clamy | 639fdffb | 2016-07-18 18:13:32 | [diff] [blame] | 4706 | // Record histograms about the type of renderer hang. |
| 4707 | UMA_HISTOGRAM_ENUMERATION( |
| 4708 | "ChildProcess.HangRendererType", type, |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 4709 | RendererUnresponsiveType::RENDERER_UNRESPONSIVE_MAX); |
clamy | 639fdffb | 2016-07-18 18:13:32 | [diff] [blame] | 4710 | |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 4711 | // We might have been waiting for both beforeunload and unload ACK. |
| 4712 | // Check if tab is to be unloaded first. |
| 4713 | if (rfhi->IsWaitingForUnloadACK()) { |
| 4714 | // Hang occurred while firing the unload handler. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4715 | // Pretend the handler fired so tab closing continues as if it had. |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4716 | GetRenderViewHost()->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4717 | |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 4718 | if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4719 | return; |
| 4720 | |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 4721 | // If the tab hangs in the unload handler there's really nothing we can do |
| 4722 | // to recover. Pretend the unload listeners have all fired and close |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 4723 | // the tab. |
metaflow | 73fc955 | 2016-05-23 18:26:48 | [diff] [blame] | 4724 | Close(); |
| 4725 | return; |
| 4726 | } |
| 4727 | |
| 4728 | if (rfhi->is_waiting_for_beforeunload_ack()) { |
| 4729 | // If the hang is in the beforeunload handler, pretend the beforeunload |
| 4730 | // listeners have all fired and allow the delegate to continue closing; |
| 4731 | // the user will not have the option of cancelling the close. |
| 4732 | rfhi->SimulateBeforeUnloadAck(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4733 | return; |
| 4734 | } |
| 4735 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 4736 | if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4737 | return; |
| 4738 | |
dtapuska | e99ec6e5 | 2016-10-18 00:15:42 | [diff] [blame] | 4739 | if (delegate_) { |
| 4740 | WebContentsUnresponsiveState unresponsive_state; |
| 4741 | unresponsive_state.reason = type; |
| 4742 | unresponsive_state.outstanding_ack_count = |
| 4743 | render_widget_host->in_flight_event_count(); |
| 4744 | unresponsive_state.outstanding_event_type = |
| 4745 | render_widget_host->hang_monitor_event_type(); |
| 4746 | unresponsive_state.last_event_type = render_widget_host->last_event_type(); |
| 4747 | delegate_->RendererUnresponsive(this, unresponsive_state); |
| 4748 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4749 | } |
| 4750 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4751 | void WebContentsImpl::RendererResponsive( |
| 4752 | RenderWidgetHostImpl* render_widget_host) { |
| 4753 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4754 | return; |
| 4755 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4756 | if (delegate_) |
| 4757 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4758 | } |
| 4759 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4760 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 4761 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4762 | bool* proceed_to_fire_unload) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4763 | for (auto& observer : observers_) |
| 4764 | observer.BeforeUnloadFired(proceed_time); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4765 | if (delegate_) |
| 4766 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 4767 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4768 | } |
| 4769 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 4770 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4771 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 4772 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 4773 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4774 | } |
| 4775 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4776 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 4777 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4778 | gfx::Size size = GetSizeForNewRenderView(); |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 4779 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 4780 | // here during container initialization and normal window size will be set |
| 4781 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 4782 | // normal size later so just ignore it. |
| 4783 | if (!size.IsEmpty()) |
| 4784 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4785 | } |
| 4786 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 4787 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
| 4788 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 4789 | // deferrer would prevent us from swapping out. We also clear the state |
| 4790 | // because this is a cross-process navigation, which means that it's a new |
| 4791 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 4792 | // |
| 4793 | // Note that we don't bother telling browser_plugin_embedder_ because the |
| 4794 | // cross-process navigation will either destroy the browser plugins or not |
| 4795 | // require their dialogs to close. |
avi | 5d3b869 | 2016-10-12 22:00:46 | [diff] [blame] | 4796 | if (dialog_manager_) { |
| 4797 | dialog_manager_->CancelDialogs(this, |
| 4798 | false, // suppress_callbacks, |
| 4799 | true); // reset_state |
| 4800 | } |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 4801 | } |
| 4802 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4803 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host, |
| 4804 | RenderFrameHost* new_host, |
| 4805 | bool is_main_frame) { |
| 4806 | if (is_main_frame) { |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 4807 | NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4808 | new_host->GetRenderViewHost()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 4809 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4810 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 4811 | if (delegate_) |
| 4812 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 4813 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4814 | view_->RenderViewSwappedIn(new_host->GetRenderViewHost()); |
| 4815 | } |
| 4816 | |
| 4817 | NotifyFrameSwapped(old_host, new_host); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4818 | } |
| 4819 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 4820 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
| 4821 | RenderViewHost* old_host, |
| 4822 | RenderViewHost* new_host) { |
| 4823 | NotifyViewSwapped(old_host, new_host); |
| 4824 | } |
| 4825 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4826 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 4827 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4828 | } |
| 4829 | |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 4830 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 4831 | const GURL& url) { |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame^] | 4832 | return CreateWebUI(url, std::string()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4833 | } |
| 4834 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 4835 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4836 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4837 | return controller_.GetLastCommittedEntry(); |
| 4838 | } |
| 4839 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4840 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 4841 | RenderViewHost* render_view_host) { |
lfg | c740d4b2 | 2016-04-15 16:45:33 | [diff] [blame] | 4842 | RenderWidgetHostViewBase* rwh_view = |
| 4843 | view_->CreateViewForWidget(render_view_host->GetWidget(), false); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 4844 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4845 | // 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] | 4846 | if (rwh_view) |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4847 | rwh_view->SetSize(GetSizeForNewRenderView()); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 4851 | RenderViewHost* render_view_host, |
| 4852 | int opener_frame_routing_id, |
| 4853 | int proxy_routing_id, |
| 4854 | const FrameReplicationState& replicated_frame_state) { |
| 4855 | TRACE_EVENT0("browser,navigation", |
| 4856 | "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 4857 | |
| 4858 | if (proxy_routing_id == MSG_ROUTING_NONE) |
| 4859 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4860 | |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 4861 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
avi | f9a94c7e | 2016-10-14 15:54:11 | [diff] [blame] | 4862 | ->CreateRenderView(opener_frame_routing_id, |
| 4863 | proxy_routing_id, |
| 4864 | replicated_frame_state, |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 4865 | created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 4866 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4867 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 4868 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4869 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 4870 | controller_.GetLastCommittedEntryIndex(), |
| 4871 | controller_.GetEntryCount()); |
| 4872 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 4873 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 4874 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 4875 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4876 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 4877 | if (rwh_view) { |
| 4878 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 4879 | render_widget_host->WasResized(); |
| 4880 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 4881 | #endif |
| 4882 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4883 | return true; |
| 4884 | } |
| 4885 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4886 | bool WebContentsImpl::CreateRenderFrameForRenderManager( |
| 4887 | RenderFrameHost* render_frame_host, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4888 | int proxy_routing_id, |
| 4889 | int opener_routing_id, |
japhet | e6adf14 | 2014-10-31 00:01:49 | [diff] [blame] | 4890 | int parent_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4891 | int previous_sibling_routing_id) { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 4892 | TRACE_EVENT0("browser,navigation", |
| 4893 | "WebContentsImpl::CreateRenderFrameForRenderManager"); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4894 | |
| 4895 | RenderFrameHostImpl* rfh = |
| 4896 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4897 | if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id, |
| 4898 | parent_routing_id, previous_sibling_routing_id)) |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4899 | return false; |
| 4900 | |
| 4901 | // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed |
| 4902 | // RenderFrameHost will have to be associated with the appropriate |
| 4903 | // RenderWidgetHostView or a new one should be created here. |
| 4904 | |
| 4905 | return true; |
| 4906 | } |
| 4907 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 4908 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4909 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4910 | base::android::ScopedJavaLocalRef<jobject> |
| 4911 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 4912 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4913 | return GetWebContentsAndroid()->GetJavaObject(); |
| 4914 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4915 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4916 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4917 | WebContentsAndroid* web_contents_android = |
| 4918 | static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey)); |
| 4919 | if (!web_contents_android) { |
| 4920 | web_contents_android = new WebContentsAndroid(this); |
| 4921 | SetUserData(kWebContentsAndroidKey, web_contents_android); |
| 4922 | } |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4923 | return web_contents_android; |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4924 | } |
| 4925 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 4926 | void WebContentsImpl::ActivateNearestFindResult(float x, |
| 4927 | float y) { |
| 4928 | GetOrCreateFindRequestManager()->ActivateNearestFindResult(x, y); |
| 4929 | } |
| 4930 | |
| 4931 | void WebContentsImpl::RequestFindMatchRects(int current_version) { |
| 4932 | GetOrCreateFindRequestManager()->RequestFindMatchRects(current_version); |
| 4933 | } |
| 4934 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4935 | bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 4936 | return CreateRenderViewForRenderManager( |
| 4937 | GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4938 | frame_tree_.root()->current_replication_state()); |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4939 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4940 | |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 4941 | service_manager::InterfaceProvider* WebContentsImpl::GetJavaInterfaces() { |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 4942 | if (!java_interfaces_) { |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 4943 | service_manager::mojom::InterfaceProviderPtr provider; |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 4944 | BindInterfaceRegistryForWebContents(mojo::GetProxy(&provider), this); |
rockot | 400ea35b | 2016-10-15 19:15:32 | [diff] [blame] | 4945 | java_interfaces_.reset(new service_manager::InterfaceProvider); |
sammc | f5f1b0f | 2016-09-20 23:05:11 | [diff] [blame] | 4946 | java_interfaces_->Bind(std::move(provider)); |
| 4947 | } |
| 4948 | return java_interfaces_.get(); |
| 4949 | } |
| 4950 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4951 | #elif defined(OS_MACOSX) |
| 4952 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 4953 | void WebContentsImpl::SetAllowOtherViews(bool allow) { |
| 4954 | view_->SetAllowOtherViews(allow); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4955 | } |
| 4956 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 4957 | bool WebContentsImpl::GetAllowOtherViews() { |
| 4958 | return view_->GetAllowOtherViews(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4959 | } |
| 4960 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4961 | #endif |
| 4962 | |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 4963 | void WebContentsImpl::OnDidDownloadImage( |
| 4964 | const ImageDownloadCallback& callback, |
| 4965 | int id, |
| 4966 | const GURL& image_url, |
leon.han | cbc4bc3c | 2016-02-26 07:08:52 | [diff] [blame] | 4967 | int32_t http_status_code, |
leon.han | c222853 | 2016-08-16 05:59:18 | [diff] [blame] | 4968 | const std::vector<SkBitmap>& images, |
| 4969 | const std::vector<gfx::Size>& original_image_sizes) { |
| 4970 | callback.Run(id, http_status_code, image_url, images, original_image_sizes); |
pkotwicz | 75ca8ffd | 2016-02-16 23:10:19 | [diff] [blame] | 4971 | } |
| 4972 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4973 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 4974 | int render_frame_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4975 | IPC::Message* reply_msg, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4976 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4977 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4978 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4979 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 4980 | render_frame_id); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4981 | last_dialog_suppressed_ = dialog_was_suppressed; |
| 4982 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4983 | if (is_showing_before_unload_dialog_ && !success) { |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 4984 | // It is possible for the current RenderFrameHost to have changed in the |
| 4985 | // meantime. Do not reset the navigation state in that case. |
| 4986 | if (rfh && rfh == rfh->frame_tree_node()->current_frame_host()) { |
clamy | 44e84ce | 2016-02-22 15:38:25 | [diff] [blame] | 4987 | rfh->frame_tree_node()->BeforeUnloadCanceled(); |
clamy | bc6f415 | 2016-04-01 20:14:23 | [diff] [blame] | 4988 | controller_.DiscardNonCommittedEntries(); |
| 4989 | } |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 4990 | |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 4991 | for (auto& observer : observers_) |
| 4992 | observer.BeforeUnloadDialogCancelled(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4993 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4994 | |
avi | 85ee836 | 2016-10-08 02:09:08 | [diff] [blame] | 4995 | is_showing_javascript_dialog_ = false; |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4996 | is_showing_before_unload_dialog_ = false; |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4997 | if (rfh) { |
| 4998 | rfh->JavaScriptDialogClosed(reply_msg, success, user_input, |
| 4999 | dialog_was_suppressed); |
| 5000 | } else { |
| 5001 | // Don't leak the sync IPC reply if the RFH or process is gone. |
| 5002 | delete reply_msg; |
| 5003 | } |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 5004 | } |
| 5005 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 5006 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 5007 | if (encoding == last_reported_encoding_) |
| 5008 | return; |
| 5009 | last_reported_encoding_ = encoding; |
| 5010 | |
| 5011 | canonical_encoding_ = GetContentClient()->browser()-> |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 5012 | GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 5013 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 5014 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 5015 | bool WebContentsImpl::IsHidden() { |
| 5016 | return capturer_count_ == 0 && !should_normally_be_visible_; |
| 5017 | } |
| 5018 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 5019 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5020 | if (node_ && node_->outer_web_contents()) |
| 5021 | return node_->outer_contents_frame_tree_node_id(); |
| 5022 | |
nick | 2482a2d | 2015-12-18 01:39:37 | [diff] [blame] | 5023 | return FrameTreeNode::kFrameTreeNodeInvalidId; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5024 | } |
| 5025 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 5026 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 5027 | return frame_tree_.root()->render_manager(); |
| 5028 | } |
| 5029 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 5030 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5031 | return browser_plugin_guest_.get(); |
| 5032 | } |
| 5033 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 5034 | void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 5035 | CHECK(!browser_plugin_guest_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 5036 | CHECK(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 5037 | browser_plugin_guest_.reset(guest); |
| 5038 | } |
| 5039 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 5040 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 5041 | return browser_plugin_embedder_.get(); |
| 5042 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5043 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 5044 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 5045 | if (browser_plugin_embedder_) |
| 5046 | return; |
| 5047 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 5048 | } |
| 5049 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5050 | gfx::Size WebContentsImpl::GetSizeForNewRenderView() { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5051 | gfx::Size size; |
| 5052 | if (delegate_) |
| 5053 | size = delegate_->GetSizeForNewRenderView(this); |
| 5054 | if (size.IsEmpty()) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 5055 | size = GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 5056 | return size; |
| 5057 | } |
| 5058 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 5059 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5060 | for (auto& observer : observers_) |
| 5061 | observer.FrameDeleted(render_frame_host); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 5062 | } |
| 5063 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 5064 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 5065 | if (!delegate_) |
| 5066 | return; |
| 5067 | const gfx::Size new_size = GetPreferredSize(); |
| 5068 | if (new_size != old_size) |
| 5069 | delegate_->UpdatePreferredSize(this, new_size); |
| 5070 | } |
| 5071 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame^] | 5072 | std::unique_ptr<WebUIImpl> WebContentsImpl::CreateWebUI( |
| 5073 | const GURL& url, |
| 5074 | const std::string& frame_name) { |
| 5075 | std::unique_ptr<WebUIImpl> web_ui = |
| 5076 | base::MakeUnique<WebUIImpl>(this, frame_name); |
| 5077 | WebUIController* controller = |
| 5078 | WebUIControllerFactoryRegistry::GetInstance() |
| 5079 | ->CreateWebUIControllerForURL(web_ui.get(), url); |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 5080 | if (controller) { |
| 5081 | web_ui->AddMessageHandler(new GenericHandler()); |
| 5082 | web_ui->SetController(controller); |
| 5083 | return web_ui; |
| 5084 | } |
| 5085 | |
avi | e865b1d | 2016-10-24 19:42:59 | [diff] [blame^] | 5086 | return nullptr; |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 5087 | } |
| 5088 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5089 | FindRequestManager* WebContentsImpl::GetOrCreateFindRequestManager() { |
| 5090 | // TODO(paulmeyer): This method will need to access (or potentially create) |
| 5091 | // the FindRequestManager in the outermost WebContents once find-in-page |
| 5092 | // across GuestViews is implemented. |
| 5093 | if (!find_request_manager_) |
| 5094 | find_request_manager_.reset(new FindRequestManager(this)); |
| 5095 | |
| 5096 | return find_request_manager_.get(); |
| 5097 | } |
| 5098 | |
| 5099 | void WebContentsImpl::NotifyFindReply(int request_id, |
| 5100 | int number_of_matches, |
| 5101 | const gfx::Rect& selection_rect, |
| 5102 | int active_match_ordinal, |
| 5103 | bool final_update) { |
paulmeyer | 60b5d83 | 2016-08-31 18:46:34 | [diff] [blame] | 5104 | if (delegate_ && !is_being_destroyed_) { |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5105 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 5106 | active_match_ordinal, final_update); |
| 5107 | } |
| 5108 | } |
| 5109 | |
ortuno | 467e579 | 2016-06-10 04:32:39 | [diff] [blame] | 5110 | void WebContentsImpl::IncrementBluetoothConnectedDeviceCount() { |
| 5111 | // Trying to invalidate the tab state while being destroyed could result in a |
| 5112 | // use after free. |
| 5113 | if (IsBeingDestroyed()) { |
| 5114 | return; |
| 5115 | } |
| 5116 | // Notify for UI updates if the state changes. |
| 5117 | bluetooth_connected_device_count_++; |
| 5118 | if (bluetooth_connected_device_count_ == 1) { |
| 5119 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 5120 | } |
| 5121 | } |
| 5122 | |
| 5123 | void WebContentsImpl::DecrementBluetoothConnectedDeviceCount() { |
| 5124 | // Trying to invalidate the tab state while being destroyed could result in a |
| 5125 | // use after free. |
| 5126 | if (IsBeingDestroyed()) { |
| 5127 | return; |
| 5128 | } |
| 5129 | // Notify for UI updates if the state changes. |
| 5130 | DCHECK(bluetooth_connected_device_count_ != 0); |
| 5131 | bluetooth_connected_device_count_--; |
| 5132 | if (bluetooth_connected_device_count_ == 0) { |
| 5133 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 5134 | } |
| 5135 | } |
| 5136 | |
paulmeyer | c0b762b | 2016-04-13 11:55:17 | [diff] [blame] | 5137 | #if defined(OS_ANDROID) |
| 5138 | void WebContentsImpl::NotifyFindMatchRectsReply( |
| 5139 | int version, |
| 5140 | const std::vector<gfx::RectF>& rects, |
| 5141 | const gfx::RectF& active_rect) { |
| 5142 | if (delegate_) |
| 5143 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 5144 | } |
| 5145 | #endif |
| 5146 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 5147 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 5148 | force_disable_overscroll_content_ = force_disable; |
| 5149 | if (view_) |
| 5150 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 5151 | } |
| 5152 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5153 | void WebContentsImpl::MediaStartedPlaying( |
| 5154 | const WebContentsObserver::MediaPlayerId& id) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5155 | for (auto& observer : observers_) |
| 5156 | observer.MediaStartedPlaying(id); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | void WebContentsImpl::MediaStoppedPlaying( |
| 5160 | const WebContentsObserver::MediaPlayerId& id) { |
ericwilligers | de38634 | 2016-10-19 02:35:09 | [diff] [blame] | 5161 | for (auto& observer : observers_) |
| 5162 | observer.MediaStoppedPlaying(id); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 5163 | } |
| 5164 | |
tapted | 65ff2ea7 | 2016-03-01 23:39:00 | [diff] [blame] | 5165 | void WebContentsImpl::UpdateWebContentsVisibility(bool visible) { |
| 5166 | if (!did_first_set_visible_) { |
| 5167 | // If this WebContents has not yet been set to be visible for the first |
| 5168 | // time, ignore any requests to make it hidden, since resources would |
| 5169 | // immediately be destroyed and only re-created after content loaded. In |
| 5170 | // this state the window content is undefined and can show garbage. |
| 5171 | // However, the page load mechanism requires an activation call through a |
| 5172 | // visibility call to (re)load. |
| 5173 | if (visible) { |
| 5174 | did_first_set_visible_ = true; |
| 5175 | WasShown(); |
| 5176 | } |
| 5177 | return; |
| 5178 | } |
| 5179 | if (visible == should_normally_be_visible_) |
| 5180 | return; |
| 5181 | |
| 5182 | if (visible) |
| 5183 | WasShown(); |
| 5184 | else |
| 5185 | WasHidden(); |
| 5186 | } |
| 5187 | |
aelias | 5252baa | 2016-04-10 01:18:02 | [diff] [blame] | 5188 | void WebContentsImpl::UpdateOverridingUserAgent() { |
| 5189 | std::set<RenderViewHost*> render_view_host_set; |
| 5190 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 5191 | RenderWidgetHost* render_widget_host = |
| 5192 | node->current_frame_host()->GetRenderWidgetHost(); |
| 5193 | if (!render_widget_host) |
| 5194 | continue; |
| 5195 | RenderViewHost* render_view_host = RenderViewHost::From(render_widget_host); |
| 5196 | if (!render_view_host) |
| 5197 | continue; |
| 5198 | render_view_host_set.insert(render_view_host); |
| 5199 | } |
| 5200 | for (RenderViewHost* render_view_host : render_view_host_set) |
| 5201 | render_view_host->OnWebkitPreferencesChanged(); |
| 5202 | } |
| 5203 | |
avi | d53461d | 2016-02-25 17:15:04 | [diff] [blame] | 5204 | void WebContentsImpl::SetJavaScriptDialogManagerForTesting( |
| 5205 | JavaScriptDialogManager* dialog_manager) { |
| 5206 | dialog_manager_ = dialog_manager; |
| 5207 | } |
| 5208 | |
rockot | f62002a | 2016-09-15 00:08:59 | [diff] [blame] | 5209 | void WebContentsImpl::RemoveBindingSet(const std::string& interface_name) { |
| 5210 | auto it = binding_sets_.find(interface_name); |
| 5211 | if (it != binding_sets_.end()) |
| 5212 | binding_sets_.erase(it); |
| 5213 | } |
| 5214 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 5215 | } // namespace content |