[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" |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 13 | #include "base/lazy_instance.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 14 | #include "base/location.h" |
[email protected] | 6d636e6 | 2013-07-31 03:15:56 | [diff] [blame] | 15 | #include "base/logging.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 16 | #include "base/macros.h" |
[email protected] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 17 | #include "base/metrics/histogram.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 18 | #include "base/process/process.h" |
erikchen | 35629cc | 2015-03-10 20:43:22 | [diff] [blame] | 19 | #include "base/profiler/scoped_tracker.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 20 | #include "base/single_thread_task_runner.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 21 | #include "base/strings/string16.h" |
| 22 | #include "base/strings/string_number_conversions.h" |
| 23 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 24 | #include "base/strings/utf_string_conversions.h" |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 25 | #include "base/thread_task_runner_handle.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 26 | #include "base/time/time.h" |
ssid | 3e76561 | 2015-01-28 04:03:42 | [diff] [blame] | 27 | #include "base/trace_event/trace_event.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 28 | #include "build/build_config.h" |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 29 | #include "components/mime_util/mime_util.h" |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 30 | #include "components/url_formatter/url_formatter.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 31 | #include "content/browser/accessibility/accessibility_mode_helper.h" |
| 32 | #include "content/browser/accessibility/browser_accessibility_state_impl.h" |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 33 | #include "content/browser/bad_message.h" |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 34 | #include "content/browser/browser_plugin/browser_plugin_embedder.h" |
| 35 | #include "content/browser/browser_plugin/browser_plugin_guest.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 36 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 37 | #include "content/browser/dom_storage/dom_storage_context_wrapper.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 38 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 39 | #include "content/browser/download/download_stats.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 40 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 41 | #include "content/browser/download/save_package.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 42 | #include "content/browser/frame_host/cross_process_frame_connector.h" |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame] | 43 | #include "content/browser/frame_host/interstitial_page_impl.h" |
| 44 | #include "content/browser/frame_host/navigation_entry_impl.h" |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 45 | #include "content/browser/frame_host/navigation_handle_impl.h" |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 46 | #include "content/browser/frame_host/navigator_impl.h" |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 47 | #include "content/browser/frame_host/render_frame_host_impl.h" |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 48 | #include "content/browser/frame_host/render_widget_host_view_child_frame.h" |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 49 | #include "content/browser/geolocation/geolocation_service_context.h" |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 50 | #include "content/browser/host_zoom_map_impl.h" |
[email protected] | 678c036 | 2012-12-05 08:02:44 | [diff] [blame] | 51 | #include "content/browser/loader/resource_dispatcher_host_impl.h" |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 52 | #include "content/browser/manifest/manifest_manager_host.h" |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 53 | #include "content/browser/media/audio_stream_monitor.h" |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 54 | #include "content/browser/media/capture/web_contents_audio_muter.h" |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 55 | #include "content/browser/media/media_web_contents_observer.h" |
[email protected] | 0bc7f354 | 2013-10-21 15:05:53 | [diff] [blame] | 56 | #include "content/browser/message_port_message_filter.h" |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 57 | #include "content/browser/plugin_content_origin_whitelist.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 58 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 2116103 | 2014-05-05 16:56:50 | [diff] [blame] | 59 | #include "content/browser/renderer_host/render_view_host_delegate_view.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 60 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 61 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 62 | #include "content/browser/renderer_host/render_widget_host_input_event_router.h" |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 63 | #include "content/browser/renderer_host/render_widget_host_view_base.h" |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 64 | #include "content/browser/screen_orientation/screen_orientation_dispatcher_host_impl.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 65 | #include "content/browser/site_instance_impl.h" |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 66 | #include "content/browser/wake_lock/wake_lock_service_context.h" |
[email protected] | b5a4084 | 2012-11-28 15:26:11 | [diff] [blame] | 67 | #include "content/browser/web_contents/web_contents_view_guest.h" |
[email protected] | eb2ef21 | 2013-01-29 04:27:58 | [diff] [blame] | 68 | #include "content/browser/webui/generic_handler.h" |
[email protected] | 86a0a6e | 2013-01-28 06:33:03 | [diff] [blame] | 69 | #include "content/browser/webui/web_ui_controller_factory_registry.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 70 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | 8eb0456 | 2013-03-06 03:41:14 | [diff] [blame] | 71 | #include "content/common/browser_plugin/browser_plugin_constants.h" |
[email protected] | 703dd66 | 2013-03-05 07:37:42 | [diff] [blame] | 72 | #include "content/common/browser_plugin/browser_plugin_messages.h" |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 73 | #include "content/common/frame_messages.h" |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 74 | #include "content/common/input_messages.h" |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 75 | #include "content/common/site_isolation_policy.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 76 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 77 | #include "content/common/view_messages.h" |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 78 | #include "content/public/browser/ax_event_notification_details.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 79 | #include "content/public/browser/browser_context.h" |
[email protected] | 139355f | 2014-05-11 14:21:28 | [diff] [blame] | 80 | #include "content/public/browser/browser_plugin_guest_manager.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 81 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 82 | #include "content/public/browser/devtools_agent_host.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 83 | #include "content/public/browser/download_manager.h" |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 84 | #include "content/public/browser/download_url_parameters.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 85 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 86 | #include "content/public/browser/javascript_dialog_manager.h" |
[email protected] | a02cf4c | 2012-06-20 01:02:00 | [diff] [blame] | 87 | #include "content/public/browser/load_from_memory_cache_details.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 88 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 89 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 90 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 91 | #include "content/public/browser/notification_service.h" |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 92 | #include "content/public/browser/render_widget_host_iterator.h" |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 93 | #include "content/public/browser/resource_request_details.h" |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 94 | #include "content/public/browser/screen_orientation_dispatcher_host.h" |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 95 | #include "content/public/browser/security_style_explanations.h" |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 96 | #include "content/public/browser/storage_partition.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 97 | #include "content/public/browser/user_metrics.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 98 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 99 | #include "content/public/common/bindings_policy.h" |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 100 | #include "content/public/common/browser_plugin_guest_mode.h" |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 101 | #include "content/public/common/browser_side_navigation_policy.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 102 | #include "content/public/common/content_constants.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 103 | #include "content/public/common/content_switches.h" |
[email protected] | 7940b8e | 2013-07-25 23:08:49 | [diff] [blame] | 104 | #include "content/public/common/page_zoom.h" |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 105 | #include "content/public/common/result_codes.h" |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 106 | #include "content/public/common/security_style.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 107 | #include "content/public/common/url_constants.h" |
[email protected] | f16cc678 | 2013-12-16 23:42:57 | [diff] [blame] | 108 | #include "content/public/common/url_utils.h" |
[email protected] | b3a97b5 | 2014-07-09 06:25:05 | [diff] [blame] | 109 | #include "content/public/common/web_preferences.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 110 | #include "mojo/common/url_type_converters.h" |
| 111 | #include "mojo/converters/geometry/geometry_type_converters.h" |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 112 | #include "net/http/http_cache.h" |
| 113 | #include "net/http/http_transaction_factory.h" |
| 114 | #include "net/url_request/url_request_context.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 115 | #include "net/url_request/url_request_context_getter.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 116 | #include "skia/public/type_converters.h" |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 117 | #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 118 | #include "third_party/skia/include/core/SkBitmap.h" |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 119 | #include "ui/base/layout.h" |
[email protected] | 7da9c4c | 2012-06-12 14:43:01 | [diff] [blame] | 120 | #include "ui/gfx/display.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 121 | #include "ui/gfx/screen.h" |
[email protected] | 66bd551 | 2012-08-01 02:02:52 | [diff] [blame] | 122 | #include "ui/gl/gl_switches.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 123 | |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 124 | #if defined(OS_ANDROID) |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 125 | #include "content/browser/android/content_video_view.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 126 | #include "content/browser/android/date_time_chooser_android.h" |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 127 | #include "content/browser/media/android/media_session.h" |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 128 | #include "content/browser/media/android/media_web_contents_observer_android.h" |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 129 | #include "content/browser/web_contents/web_contents_android.h" |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 130 | #endif // OS_ANDROID |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 131 | |
[email protected] | f66df82 | 2012-05-18 16:52:17 | [diff] [blame] | 132 | #if defined(OS_MACOSX) |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 133 | #include "base/mac/foundation_util.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 134 | #endif |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 135 | |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 136 | #if defined(MOJO_SHELL_CLIENT) |
| 137 | #include "content/browser/web_contents/web_contents_view_mus.h" |
| 138 | #include "content/public/common/mojo_shell_connection.h" |
fsamuel | 6c6da023 | 2015-11-26 05:13:46 | [diff] [blame] | 139 | #include "ui/aura/mus/mus_util.h" |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 140 | #endif |
| 141 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 142 | namespace content { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 143 | namespace { |
| 144 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 145 | const int kMinimumDelayBetweenLoadingUpdatesMS = 100; |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 146 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 147 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 148 | #if defined(OS_ANDROID) |
| 149 | const char kWebContentsAndroidKey[] = "web_contents_android"; |
| 150 | #endif // OS_ANDROID |
| 151 | |
[email protected] | e4abd3b4 | 2013-11-12 18:28:47 | [diff] [blame] | 152 | base::LazyInstance<std::vector<WebContentsImpl::CreatedCallback> > |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 153 | g_created_callbacks = LAZY_INSTANCE_INITIALIZER; |
| 154 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 155 | static void DidDownloadImage(const WebContents::ImageDownloadCallback& callback, |
| 156 | int id, |
| 157 | const GURL& image_url, |
| 158 | image_downloader::DownloadResultPtr result) { |
| 159 | DCHECK(result); |
| 160 | |
| 161 | const std::vector<SkBitmap> images = |
| 162 | result->images.To<std::vector<SkBitmap>>(); |
| 163 | const std::vector<gfx::Size> original_image_sizes = |
| 164 | result->original_image_sizes.To<std::vector<gfx::Size>>(); |
| 165 | |
| 166 | callback.Run(id, result->http_status_code, image_url, images, |
| 167 | original_image_sizes); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 170 | void NotifyCacheOnIO( |
| 171 | scoped_refptr<net::URLRequestContextGetter> request_context, |
| 172 | const GURL& url, |
| 173 | const std::string& http_method) { |
gunsch | e668855c | 2015-03-05 02:37:58 | [diff] [blame] | 174 | net::HttpCache* cache = request_context->GetURLRequestContext()-> |
| 175 | http_transaction_factory()->GetCache(); |
| 176 | if (cache) |
| 177 | cache->OnExternalCacheHit(url, http_method); |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 178 | } |
| 179 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 180 | bool HasMatchingProcess(FrameTree* tree, int render_process_id) { |
| 181 | for (FrameTreeNode* node : tree->Nodes()) { |
| 182 | if (node->current_frame_host()->GetProcess()->GetID() == render_process_id) |
| 183 | return true; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 184 | } |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 185 | return false; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 186 | } |
| 187 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 188 | void SetAccessibilityModeOnFrame(AccessibilityMode mode, |
| 189 | RenderFrameHost* frame_host) { |
| 190 | static_cast<RenderFrameHostImpl*>(frame_host)->SetAccessibilityMode(mode); |
| 191 | } |
| 192 | |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 193 | void ResetAccessibility(RenderFrameHost* rfh) { |
| 194 | static_cast<RenderFrameHostImpl*>(rfh)->AccessibilityReset(); |
| 195 | } |
| 196 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 197 | } // namespace |
| 198 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 199 | WebContents* WebContents::Create(const WebContents::CreateParams& params) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 200 | FrameTreeNode* opener_node = nullptr; |
| 201 | if (params.opener_render_frame_id != MSG_ROUTING_NONE) { |
| 202 | RenderFrameHostImpl* opener_rfh = RenderFrameHostImpl::FromID( |
| 203 | params.opener_render_process_id, params.opener_render_frame_id); |
| 204 | if (opener_rfh) |
| 205 | opener_node = opener_rfh->frame_tree_node(); |
| 206 | } |
| 207 | return WebContentsImpl::CreateWithOpener(params, opener_node); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | WebContents* WebContents::CreateWithSessionStorage( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 211 | const WebContents::CreateParams& params, |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 212 | const SessionStorageNamespaceMap& session_storage_namespace_map) { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 213 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 214 | |
| 215 | for (SessionStorageNamespaceMap::const_iterator it = |
| 216 | session_storage_namespace_map.begin(); |
| 217 | it != session_storage_namespace_map.end(); |
| 218 | ++it) { |
| 219 | new_contents->GetController() |
| 220 | .SetSessionStorageNamespace(it->first, it->second.get()); |
| 221 | } |
| 222 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 223 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 224 | return new_contents; |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 225 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 226 | |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 227 | void WebContentsImpl::FriendZone::AddCreatedCallbackForTesting( |
| 228 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 229 | g_created_callbacks.Get().push_back(callback); |
| 230 | } |
| 231 | |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 232 | void WebContentsImpl::FriendZone::RemoveCreatedCallbackForTesting( |
| 233 | const CreatedCallback& callback) { |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 234 | for (size_t i = 0; i < g_created_callbacks.Get().size(); ++i) { |
| 235 | if (g_created_callbacks.Get().at(i).Equals(callback)) { |
| 236 | g_created_callbacks.Get().erase(g_created_callbacks.Get().begin() + i); |
| 237 | return; |
| 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 242 | WebContents* WebContents::FromRenderViewHost(RenderViewHost* rvh) { |
| 243 | if (!rvh) |
| 244 | return nullptr; |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 245 | return rvh->GetDelegate()->GetAsWebContents(); |
| 246 | } |
| 247 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 248 | WebContents* WebContents::FromRenderFrameHost(RenderFrameHost* rfh) { |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 249 | if (!rfh) |
| 250 | return nullptr; |
| 251 | return static_cast<RenderFrameHostImpl*>(rfh)->delegate()->GetAsWebContents(); |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 252 | } |
| 253 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 254 | // WebContentsImpl::DestructionObserver ---------------------------------------- |
| 255 | |
| 256 | class WebContentsImpl::DestructionObserver : public WebContentsObserver { |
| 257 | public: |
| 258 | DestructionObserver(WebContentsImpl* owner, WebContents* watched_contents) |
| 259 | : WebContentsObserver(watched_contents), |
| 260 | owner_(owner) { |
| 261 | } |
| 262 | |
| 263 | // WebContentsObserver: |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 264 | void WebContentsDestroyed() override { |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 265 | owner_->OnWebContentsDestroyed( |
| 266 | static_cast<WebContentsImpl*>(web_contents())); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | private: |
| 270 | WebContentsImpl* owner_; |
| 271 | |
| 272 | DISALLOW_COPY_AND_ASSIGN(DestructionObserver); |
| 273 | }; |
| 274 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 275 | WebContentsImpl::ColorChooserInfo::ColorChooserInfo(int render_process_id, |
| 276 | int render_frame_id, |
| 277 | ColorChooser* chooser, |
| 278 | int identifier) |
| 279 | : render_process_id(render_process_id), |
| 280 | render_frame_id(render_frame_id), |
| 281 | chooser(chooser), |
| 282 | identifier(identifier) { |
| 283 | } |
| 284 | |
| 285 | WebContentsImpl::ColorChooserInfo::~ColorChooserInfo() { |
| 286 | } |
| 287 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 288 | // WebContentsImpl::WebContentsTreeNode ---------------------------------------- |
| 289 | WebContentsImpl::WebContentsTreeNode::WebContentsTreeNode() |
| 290 | : outer_web_contents_(nullptr), |
| 291 | outer_contents_frame_tree_node_id_( |
nick | 2482a2d | 2015-12-18 01:39:37 | [diff] [blame] | 292 | FrameTreeNode::kFrameTreeNodeInvalidId) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 293 | } |
| 294 | |
| 295 | WebContentsImpl::WebContentsTreeNode::~WebContentsTreeNode() { |
| 296 | // Remove child pointer from our parent. |
| 297 | if (outer_web_contents_) { |
| 298 | ChildrenSet& child_ptrs_in_parent = |
| 299 | outer_web_contents_->node_->inner_web_contents_tree_nodes_; |
| 300 | ChildrenSet::iterator iter = child_ptrs_in_parent.find(this); |
| 301 | DCHECK(iter != child_ptrs_in_parent.end()); |
| 302 | child_ptrs_in_parent.erase(this); |
| 303 | } |
| 304 | |
| 305 | // Remove parent pointers from our children. |
| 306 | // TODO(lazyboy): We should destroy the children WebContentses too. If the |
| 307 | // children do not manage their own lifetime, then we would leak their |
| 308 | // WebContentses. |
| 309 | for (WebContentsTreeNode* child : inner_web_contents_tree_nodes_) |
| 310 | child->outer_web_contents_ = nullptr; |
| 311 | } |
| 312 | |
| 313 | void WebContentsImpl::WebContentsTreeNode::ConnectToOuterWebContents( |
| 314 | WebContentsImpl* outer_web_contents, |
| 315 | RenderFrameHostImpl* outer_contents_frame) { |
| 316 | outer_web_contents_ = outer_web_contents; |
| 317 | outer_contents_frame_tree_node_id_ = |
| 318 | outer_contents_frame->frame_tree_node()->frame_tree_node_id(); |
| 319 | |
| 320 | if (!outer_web_contents_->node_) |
| 321 | outer_web_contents_->node_.reset(new WebContentsTreeNode()); |
| 322 | |
| 323 | outer_web_contents_->node_->inner_web_contents_tree_nodes_.insert(this); |
| 324 | } |
| 325 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 326 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 327 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 328 | WebContentsImpl::WebContentsImpl(BrowserContext* browser_context) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 329 | : delegate_(NULL), |
[email protected] | 69e797f | 2013-04-30 01:10:22 | [diff] [blame] | 330 | controller_(this, browser_context), |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 331 | render_view_host_delegate_view_(NULL), |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 332 | created_with_opener_(false), |
[email protected] | 2ceee8f | 2014-01-14 18:02:08 | [diff] [blame] | 333 | #if defined(OS_WIN) |
[email protected] | c73a228 | 2013-04-29 21:10:41 | [diff] [blame] | 334 | accessible_parent_(NULL), |
| 335 | #endif |
[email protected] | 6ea6bdf | 2013-12-06 13:35:01 | [diff] [blame] | 336 | frame_tree_(new NavigatorImpl(&controller_, this), |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 337 | this, |
| 338 | this, |
| 339 | this, |
| 340 | this), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 341 | is_loading_(false), |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 342 | is_load_to_different_document_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 343 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 344 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 345 | waiting_for_response_(false), |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 346 | load_state_(net::LOAD_STATE_IDLE, base::string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 347 | upload_size_(0), |
| 348 | upload_position_(0), |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 349 | is_resume_pending_(false), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 350 | displayed_insecure_content_(false), |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 351 | has_accessed_initial_document_(false), |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 352 | theme_color_(SK_ColorTRANSPARENT), |
| 353 | last_sent_theme_color_(SK_ColorTRANSPARENT), |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 354 | did_first_visually_non_empty_paint_(false), |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 355 | capturer_count_(0), |
| 356 | should_normally_be_visible_(true), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 357 | is_being_destroyed_(false), |
| 358 | notify_disconnection_(false), |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 359 | dialog_manager_(NULL), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 360 | is_showing_before_unload_dialog_(false), |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 361 | last_active_time_(base::TimeTicks::Now()), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 362 | closed_by_user_gesture_(false), |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 363 | minimum_zoom_percent_(static_cast<int>(kMinimumZoomFactor * 100)), |
| 364 | maximum_zoom_percent_(static_cast<int>(kMaximumZoomFactor * 100)), |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 365 | zoom_scroll_remainder_(0), |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 366 | render_view_message_source_(NULL), |
mukai | 1db09376 | 2015-01-27 20:06:55 | [diff] [blame] | 367 | render_frame_message_source_(NULL), |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 368 | fullscreen_widget_routing_id_(MSG_ROUTING_NONE), |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 369 | fullscreen_widget_had_focus_at_shutdown_(false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 370 | is_subframe_(false), |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 371 | force_disable_overscroll_content_(false), |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 372 | last_dialog_suppressed_(false), |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 373 | geolocation_service_context_(new GeolocationServiceContext()), |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 374 | accessibility_mode_( |
| 375 | BrowserAccessibilityStateImpl::GetInstance()->accessibility_mode()), |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 376 | audio_stream_monitor_(this), |
mohan.reddy | aae039a | 2014-11-21 17:39:50 | [diff] [blame] | 377 | virtual_keyboard_requested_(false), |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 378 | page_scale_factor_is_one_(true), |
mohan.reddy | 371ad914 | 2014-09-17 08:01:46 | [diff] [blame] | 379 | loading_weak_factory_(this) { |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 380 | frame_tree_.SetFrameRemoveListener( |
| 381 | base::Bind(&WebContentsImpl::OnFrameRemoved, |
| 382 | base::Unretained(this))); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 383 | #if defined(OS_ANDROID) |
| 384 | media_web_contents_observer_.reset(new MediaWebContentsObserverAndroid(this)); |
| 385 | #else |
qinmin | 58567c8 | 2015-01-07 21:00:20 | [diff] [blame] | 386 | media_web_contents_observer_.reset(new MediaWebContentsObserver(this)); |
dalecurtis | c85ed63 | 2016-01-13 00:22:46 | [diff] [blame] | 387 | #endif |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 388 | loader_io_thread_notifier_.reset(new LoaderIOThreadNotifier(this)); |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 389 | wake_lock_service_context_.reset(new WakeLockServiceContext(this)); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 390 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 391 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 392 | WebContentsImpl::~WebContentsImpl() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 393 | is_being_destroyed_ = true; |
| 394 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 395 | rwh_input_event_router_.reset(); |
| 396 | |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 397 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 398 | // Delete all RFHs pending shutdown, which will lead the corresponding RVHs |
| 399 | // to be shutdown and be deleted as well. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 400 | node->render_manager()->ClearRFHsPendingShutdown(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 401 | node->render_manager()->ClearWebUIInstances(); |
dcheng | 72be33c | 2016-01-21 04:11:31 | [diff] [blame] | 402 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 403 | |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 404 | for (RenderWidgetHostImpl* widget : created_widgets_) |
| 405 | widget->DetachDelegate(); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 406 | created_widgets_.clear(); |
| 407 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 408 | // Clear out any JavaScript state. |
[email protected] | 71a88bb | 2013-02-01 22:05:15 | [diff] [blame] | 409 | if (dialog_manager_) |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 410 | dialog_manager_->ResetDialogState(this); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 411 | |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 412 | if (color_chooser_info_.get()) |
| 413 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 414 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 415 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 416 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 417 | // Notify any observer that have a reference on this WebContents. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 418 | NotificationService::current()->Notify( |
| 419 | NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 420 | Source<WebContents>(this), |
| 421 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 422 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 423 | // Destroy all frame tree nodes except for the root; this notifies observers. |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 424 | frame_tree_.root()->ResetForNewProcess(); |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 425 | GetRenderManager()->ResetProxyHosts(); |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 426 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 427 | // Manually call the observer methods for the root frame tree node. It is |
| 428 | // necessary to manually delete all objects tracking navigations |
| 429 | // (NavigationHandle, NavigationRequest) for observers to be properly |
| 430 | // notified of these navigations stopping before the WebContents is |
| 431 | // destroyed. |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 432 | RenderFrameHostManager* root = GetRenderManager(); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 433 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 434 | if (root->pending_frame_host()) { |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 435 | root->pending_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 436 | root->pending_frame_host()->SetNavigationHandle( |
| 437 | scoped_ptr<NavigationHandleImpl>()); |
| 438 | } |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 439 | root->current_frame_host()->SetRenderFrameCreated(false); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 440 | root->current_frame_host()->SetNavigationHandle( |
| 441 | scoped_ptr<NavigationHandleImpl>()); |
| 442 | |
| 443 | // PlzNavigate: clear up state specific to browser-side navigation. |
carlosk | d80262f5 | 2015-12-16 14:40:35 | [diff] [blame] | 444 | if (IsBrowserSideNavigationEnabled()) { |
clamy | 82a2f4d | 2016-02-02 14:20:41 | [diff] [blame] | 445 | // Do not update state as the WebContents is being destroyed. |
| 446 | frame_tree_.root()->ResetNavigationRequest(true); |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 447 | if (root->speculative_frame_host()) { |
| 448 | root->speculative_frame_host()->SetRenderFrameCreated(false); |
| 449 | root->speculative_frame_host()->SetNavigationHandle( |
| 450 | scoped_ptr<NavigationHandleImpl>()); |
| 451 | } |
| 452 | } |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 453 | |
nasko | a83483fb | 2015-02-27 16:57:10 | [diff] [blame] | 454 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 455 | FrameDeleted(root->current_frame_host())); |
| 456 | |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 457 | if (root->pending_render_view_host()) { |
| 458 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 459 | observers_, |
| 460 | RenderViewDeleted(root->pending_render_view_host())); |
| 461 | } |
[email protected] | c06c58c | 2014-03-12 20:31:59 | [diff] [blame] | 462 | |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 463 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 464 | observers_, |
[email protected] | df0c843f | 2014-05-23 20:37:23 | [diff] [blame] | 465 | RenderViewDeleted(root->current_host())); |
[email protected] | f273ee5 | 2013-10-18 16:05:27 | [diff] [blame] | 466 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 467 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 468 | observers_, |
[email protected] | 12a4683 | 2014-05-09 13:35:58 | [diff] [blame] | 469 | WebContentsDestroyed()); |
| 470 | |
| 471 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 472 | observers_, |
| 473 | ResetWebContents()); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 474 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 475 | SetDelegate(NULL); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 476 | |
| 477 | STLDeleteContainerPairSecondPointers(destruction_observers_.begin(), |
| 478 | destruction_observers_.end()); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 481 | WebContentsImpl* WebContentsImpl::CreateWithOpener( |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 482 | const WebContents::CreateParams& params, |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 483 | FrameTreeNode* opener) { |
[email protected] | e11f0e9 | 2013-06-12 15:12:03 | [diff] [blame] | 484 | TRACE_EVENT0("browser", "WebContentsImpl::CreateWithOpener"); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 485 | WebContentsImpl* new_contents = new WebContentsImpl(params.browser_context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 486 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 487 | FrameTreeNode* new_root = new_contents->GetFrameTree()->root(); |
| 488 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 489 | if (!params.opener_suppressed && opener) { |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 490 | new_root->SetOpener(opener); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 491 | new_contents->created_with_opener_ = true; |
| 492 | } |
| 493 | |
alexmos | aedfc6f | 2016-01-21 23:57:38 | [diff] [blame] | 494 | // If the opener is sandboxed, a new popup must inherit the opener's sandbox |
| 495 | // flags, and these flags take effect immediately. An exception is if the |
| 496 | // opener's sandbox flags lack the PropagatesToAuxiliaryBrowsingContexts |
| 497 | // bit (which is controlled by the "allow-popups-to-escape-sandbox" token). |
| 498 | // See https://html.spec.whatwg.org/#attr-iframe-sandbox. |
| 499 | if (opener) { |
| 500 | blink::WebSandboxFlags opener_flags = opener->effective_sandbox_flags(); |
| 501 | const blink::WebSandboxFlags inherit_flag = |
| 502 | blink::WebSandboxFlags::PropagatesToAuxiliaryBrowsingContexts; |
| 503 | if ((opener_flags & inherit_flag) == inherit_flag) { |
| 504 | new_root->SetPendingSandboxFlags(opener_flags); |
| 505 | new_root->CommitPendingSandboxFlags(); |
| 506 | } |
| 507 | } |
| 508 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 509 | // This may be true even when opener is null, such as when opening blocked |
| 510 | // popups. |
alexmos | 090fae8e | 2015-05-28 17:09:28 | [diff] [blame] | 511 | if (params.created_with_opener) |
| 512 | new_contents->created_with_opener_ = true; |
| 513 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 514 | if (params.guest_delegate) { |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 515 | // This makes |new_contents| act as a guest. |
| 516 | // For more info, see comment above class BrowserPluginGuest. |
[email protected] | 2101c4c | 2014-08-22 00:16:16 | [diff] [blame] | 517 | BrowserPluginGuest::Create(new_contents, params.guest_delegate); |
[email protected] | 83100cd | 2014-05-10 11:50:06 | [diff] [blame] | 518 | // We are instantiating a WebContents for browser plugin. Set its subframe |
| 519 | // bit to true. |
| 520 | new_contents->is_subframe_ = true; |
| 521 | } |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 522 | new_contents->Init(params); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 523 | return new_contents; |
| 524 | } |
| 525 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 526 | // static |
| 527 | std::vector<WebContentsImpl*> WebContentsImpl::GetAllWebContents() { |
| 528 | std::vector<WebContentsImpl*> result; |
| 529 | scoped_ptr<RenderWidgetHostIterator> widgets( |
| 530 | RenderWidgetHostImpl::GetRenderWidgetHosts()); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 531 | while (RenderWidgetHost* rwh = widgets->GetNextHost()) { |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 532 | RenderViewHost* rvh = RenderViewHost::From(rwh); |
| 533 | if (!rvh) |
| 534 | continue; |
| 535 | WebContents* web_contents = WebContents::FromRenderViewHost(rvh); |
| 536 | if (!web_contents) |
| 537 | continue; |
avi | df38c95 | 2015-10-27 13:45:13 | [diff] [blame] | 538 | if (web_contents->GetRenderViewHost() != rvh) |
| 539 | continue; |
| 540 | // Because a WebContents can only have one current RVH at a time, there will |
| 541 | // be no duplicate WebContents here. |
| 542 | result.push_back(static_cast<WebContentsImpl*>(web_contents)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 543 | } |
| 544 | return result; |
| 545 | } |
| 546 | |
clamy | a16aa817 | 2015-05-26 13:07:25 | [diff] [blame] | 547 | // static |
| 548 | WebContentsImpl* WebContentsImpl::FromFrameTreeNode( |
| 549 | FrameTreeNode* frame_tree_node) { |
| 550 | return static_cast<WebContentsImpl*>( |
| 551 | WebContents::FromRenderFrameHost(frame_tree_node->current_frame_host())); |
| 552 | } |
| 553 | |
clamy | 0d32d6d | 2015-11-24 11:16:26 | [diff] [blame] | 554 | // static |
| 555 | WebContents* WebContentsImpl::FromRenderFrameHostID(int render_process_host_id, |
| 556 | int render_frame_host_id) { |
| 557 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 558 | RenderFrameHost* render_frame_host = |
| 559 | RenderFrameHost::FromID(render_process_host_id, render_frame_host_id); |
| 560 | if (!render_frame_host) |
| 561 | return nullptr; |
| 562 | |
| 563 | return WebContents::FromRenderFrameHost(render_frame_host); |
| 564 | } |
| 565 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 566 | RenderFrameHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 567 | return GetRenderManager(); |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 568 | } |
| 569 | |
[email protected] | 7bb76189 | 2012-07-20 09:32:47 | [diff] [blame] | 570 | bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
| 571 | const IPC::Message& message) { |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 572 | return OnMessageReceived(render_view_host, NULL, message); |
| 573 | } |
| 574 | |
| 575 | bool WebContentsImpl::OnMessageReceived(RenderViewHost* render_view_host, |
| 576 | RenderFrameHost* render_frame_host, |
| 577 | const IPC::Message& message) { |
| 578 | DCHECK(render_view_host || render_frame_host); |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 579 | if (GetWebUI() && |
| 580 | static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 581 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 582 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 583 | |
brettw | 5a1613dc | 2015-06-02 05:34:43 | [diff] [blame] | 584 | base::ObserverListBase<WebContentsObserver>::Iterator it(&observers_); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 585 | WebContentsObserver* observer; |
[email protected] | 64ffefa | 2014-05-10 12:06:33 | [diff] [blame] | 586 | if (render_frame_host) { |
| 587 | while ((observer = it.GetNext()) != NULL) |
| 588 | if (observer->OnMessageReceived(message, render_frame_host)) |
| 589 | return true; |
| 590 | } else { |
| 591 | while ((observer = it.GetNext()) != NULL) |
| 592 | if (observer->OnMessageReceived(message)) |
| 593 | return true; |
| 594 | } |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 595 | |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 596 | // Message handlers should be aware of which |
| 597 | // RenderViewHost/RenderFrameHost sent the message, which is temporarily |
| 598 | // stored in render_(view|frame)_message_source_. |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 599 | if (render_frame_host) |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 600 | render_frame_message_source_ = render_frame_host; |
[email protected] | b3f957e6 | 2014-08-08 10:09:02 | [diff] [blame] | 601 | else |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 602 | render_view_message_source_ = render_view_host; |
| 603 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 604 | bool handled = true; |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 605 | IPC_BEGIN_MESSAGE_MAP(WebContentsImpl, message) |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 606 | IPC_MESSAGE_HANDLER(FrameHostMsg_DomOperationResponse, |
| 607 | OnDomOperationResponse) |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 608 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidChangeThemeColor, |
| 609 | OnThemeColorChanged) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 610 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishDocumentLoad, |
| 611 | OnDocumentLoadedInFrame) |
| 612 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidFinishLoad, OnDidFinishLoad) |
| 613 | IPC_MESSAGE_HANDLER(FrameHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 614 | IPC_MESSAGE_HANDLER(FrameHostMsg_EndColorChooser, OnEndColorChooser) |
| 615 | IPC_MESSAGE_HANDLER(FrameHostMsg_SetSelectedColorInColorChooser, |
| 616 | OnSetSelectedColorInColorChooser) |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 617 | |
dglazkov | 79c42610 | 2015-08-31 21:22:43 | [diff] [blame] | 618 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFirstVisuallyNonEmptyPaint, |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 619 | OnFirstVisuallyNonEmptyPaint) |
avi | 7830c85 | 2015-08-31 23:46:25 | [diff] [blame] | 620 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidLoadResourceFromMemoryCache, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 621 | OnDidLoadResourceFromMemoryCache) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 622 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 623 | OnDidDisplayInsecureContent) |
avi | 3a333262 | 2015-09-01 01:18:54 | [diff] [blame] | 624 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunInsecureContent, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 625 | OnDidRunInsecureContent) |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 626 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidDisplayContentWithCertificateErrors, |
| 627 | OnDidDisplayContentWithCertificateErrors) |
| 628 | IPC_MESSAGE_HANDLER(FrameHostMsg_DidRunContentWithCertificateErrors, |
| 629 | OnDidRunContentWithCertificateErrors) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 630 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 631 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 632 | IPC_MESSAGE_HANDLER(ViewHostMsg_PageScaleFactorChanged, |
| 633 | OnPageScaleFactorChanged) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 634 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
avi | a23e16b | 2015-07-09 14:18:48 | [diff] [blame] | 635 | IPC_MESSAGE_HANDLER(FrameHostMsg_RegisterProtocolHandler, |
| 636 | OnRegisterProtocolHandler) |
| 637 | IPC_MESSAGE_HANDLER(FrameHostMsg_UnregisterProtocolHandler, |
| 638 | OnUnregisterProtocolHandler) |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(FrameHostMsg_UpdatePageImportanceSignals, |
| 640 | OnUpdatePageImportanceSignals) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 641 | IPC_MESSAGE_HANDLER(FrameHostMsg_Find_Reply, OnFindReply) |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 642 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 643 | IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 644 | #if defined(ENABLE_PLUGINS) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 645 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceCreated, |
| 646 | OnPepperInstanceCreated) |
| 647 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperInstanceDeleted, |
| 648 | OnPepperInstanceDeleted) |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 649 | IPC_MESSAGE_HANDLER(FrameHostMsg_PepperPluginHung, OnPepperPluginHung) |
| 650 | IPC_MESSAGE_HANDLER(FrameHostMsg_PluginCrashed, OnPluginCrashed) |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 651 | IPC_MESSAGE_HANDLER(ViewHostMsg_RequestPpapiBrokerPermission, |
| 652 | OnRequestPpapiBrokerPermission) |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 653 | IPC_MESSAGE_HANDLER_GENERIC(BrowserPluginHostMsg_Attach, |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 654 | OnBrowserPluginMessage(render_frame_host, |
| 655 | message)) |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 656 | #endif |
[email protected] | 41225fe | 2013-03-29 05:32:02 | [diff] [blame] | 657 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateFaviconURL, OnUpdateFaviconURL) |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 658 | IPC_MESSAGE_HANDLER(ViewHostMsg_ShowValidationMessage, |
| 659 | OnShowValidationMessage) |
| 660 | IPC_MESSAGE_HANDLER(ViewHostMsg_HideValidationMessage, |
| 661 | OnHideValidationMessage) |
| 662 | IPC_MESSAGE_HANDLER(ViewHostMsg_MoveValidationMessage, |
| 663 | OnMoveValidationMessage) |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 664 | #if defined(OS_ANDROID) |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 665 | IPC_MESSAGE_HANDLER(FrameHostMsg_FindMatchRects_Reply, |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 666 | OnFindMatchRectsReply) |
| 667 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenDateTimeDialog, |
| 668 | OnOpenDateTimeDialog) |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 669 | #endif |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 670 | IPC_MESSAGE_UNHANDLED(handled = false) |
[email protected] | e44d134 | 2014-05-16 21:29:33 | [diff] [blame] | 671 | IPC_END_MESSAGE_MAP() |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 672 | render_view_message_source_ = NULL; |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 673 | render_frame_message_source_ = NULL; |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 674 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 675 | return handled; |
| 676 | } |
| 677 | |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 678 | bool WebContentsImpl::HasValidFrameSource() { |
| 679 | if (!render_frame_message_source_) { |
| 680 | DCHECK(render_view_message_source_); |
jamescook | da250581 | 2015-03-20 18:01:18 | [diff] [blame] | 681 | bad_message::ReceivedBadMessage(GetRenderProcessHost(), |
| 682 | bad_message::WC_INVALID_FRAME_SOURCE); |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 683 | return false; |
| 684 | } |
| 685 | |
| 686 | return true; |
| 687 | } |
| 688 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 689 | void WebContentsImpl::RunFileChooser( |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 690 | RenderViewHost* render_view_host, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 691 | const FileChooserParams& params) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 692 | if (delegate_) |
| 693 | delegate_->RunFileChooser(this, params); |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 694 | } |
| 695 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 696 | NavigationControllerImpl& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 697 | return controller_; |
| 698 | } |
| 699 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 700 | const NavigationControllerImpl& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 701 | return controller_; |
| 702 | } |
| 703 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 704 | BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 705 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 706 | } |
| 707 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 708 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 709 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 710 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 711 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | a093ce0 | 2013-07-22 20:53:14 | [diff] [blame] | 714 | const GURL& WebContentsImpl::GetVisibleURL() const { |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 715 | // We may not have a navigation entry yet. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 716 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | c854a7e | 2013-05-21 16:42:24 | [diff] [blame] | 717 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 718 | } |
| 719 | |
| 720 | const GURL& WebContentsImpl::GetLastCommittedURL() const { |
| 721 | // We may not have a navigation entry yet. |
| 722 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 723 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
| 724 | } |
| 725 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 726 | WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 727 | return delegate_; |
| 728 | } |
| 729 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 730 | void WebContentsImpl::SetDelegate(WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 731 | // TODO(cbentzel): remove this debugging code? |
| 732 | if (delegate == delegate_) |
| 733 | return; |
| 734 | if (delegate_) |
| 735 | delegate_->Detach(this); |
| 736 | delegate_ = delegate; |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 737 | if (delegate_) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 738 | delegate_->Attach(this); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 739 | // Ensure the visible RVH reflects the new delegate's preferences. |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 740 | if (view_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 741 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 742 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 743 | } |
| 744 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 745 | RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 746 | RenderViewHostImpl* host = GetRenderManager()->current_host(); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 747 | return host ? host->GetProcess() : NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 748 | } |
| 749 | |
clamy | df1975e | 2015-02-05 19:12:24 | [diff] [blame] | 750 | RenderFrameHostImpl* WebContentsImpl::GetMainFrame() { |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 751 | return frame_tree_.root()->current_frame_host(); |
[email protected] | 60eca4eb | 2013-12-06 00:02:16 | [diff] [blame] | 752 | } |
| 753 | |
nick | 53d5cbf | 2015-04-23 22:50:14 | [diff] [blame] | 754 | RenderFrameHostImpl* WebContentsImpl::GetFocusedFrame() { |
| 755 | FrameTreeNode* focused_node = frame_tree_.GetFocusedFrame(); |
| 756 | if (!focused_node) |
| 757 | return nullptr; |
| 758 | return focused_node->current_frame_host(); |
[email protected] | 9c9343b | 2014-03-08 02:56:07 | [diff] [blame] | 759 | } |
| 760 | |
rob | 3e2a073 | 2016-01-06 21:22:09 | [diff] [blame] | 761 | RenderFrameHostImpl* WebContentsImpl::FindFrameByFrameTreeNodeId( |
| 762 | int frame_tree_node_id) { |
| 763 | FrameTreeNode* frame = frame_tree_.FindByID(frame_tree_node_id); |
| 764 | return frame ? frame->current_frame_host() : nullptr; |
| 765 | } |
| 766 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 767 | void WebContentsImpl::ForEachFrame( |
| 768 | const base::Callback<void(RenderFrameHost*)>& on_frame) { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 769 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 770 | on_frame.Run(node->current_frame_host()); |
| 771 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 772 | } |
| 773 | |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 774 | std::vector<RenderFrameHost*> WebContentsImpl::GetAllFrames() { |
| 775 | std::vector<RenderFrameHost*> frame_hosts; |
| 776 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 777 | frame_hosts.push_back(node->current_frame_host()); |
| 778 | return frame_hosts; |
| 779 | } |
| 780 | |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 781 | int WebContentsImpl::SendToAllFrames(IPC::Message* message) { |
| 782 | int number_of_messages = 0; |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 783 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 784 | ++number_of_messages; |
| 785 | IPC::Message* message_copy = new IPC::Message(*message); |
| 786 | message_copy->set_routing_id(rfh->GetRoutingID()); |
| 787 | rfh->Send(message_copy); |
| 788 | } |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 789 | delete message; |
lukasza | cbdf52e | 2016-01-15 21:19:51 | [diff] [blame] | 790 | return number_of_messages; |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 791 | } |
| 792 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 793 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 794 | return GetRenderManager()->current_host(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 795 | } |
| 796 | |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 797 | int WebContentsImpl::GetRoutingID() const { |
| 798 | if (!GetRenderViewHost()) |
| 799 | return MSG_ROUTING_NONE; |
| 800 | |
| 801 | return GetRenderViewHost()->GetRoutingID(); |
| 802 | } |
| 803 | |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 804 | void WebContentsImpl::CancelActiveAndPendingDialogs() { |
| 805 | if (dialog_manager_) |
| 806 | dialog_manager_->CancelActiveAndPendingDialogs(this); |
| 807 | if (browser_plugin_embedder_) |
| 808 | browser_plugin_embedder_->CancelGuestDialogs(); |
| 809 | } |
| 810 | |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 811 | int WebContentsImpl::GetFullscreenWidgetRoutingID() const { |
| 812 | return fullscreen_widget_routing_id_; |
| 813 | } |
| 814 | |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 815 | void WebContentsImpl::ClosePage() { |
| 816 | GetRenderViewHost()->ClosePage(); |
| 817 | } |
| 818 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 819 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 820 | return GetRenderManager()->GetRenderWidgetHostView(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 821 | } |
| 822 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 823 | RenderWidgetHostView* WebContentsImpl::GetFullscreenRenderWidgetHostView() |
| 824 | const { |
| 825 | RenderWidgetHost* const widget_host = |
| 826 | RenderWidgetHostImpl::FromID(GetRenderProcessHost()->GetID(), |
| 827 | GetFullscreenWidgetRoutingID()); |
| 828 | return widget_host ? widget_host->GetView() : NULL; |
| 829 | } |
| 830 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 831 | WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 832 | return view_.get(); |
| 833 | } |
| 834 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 835 | SkColor WebContentsImpl::GetThemeColor() const { |
| 836 | return theme_color_; |
| 837 | } |
| 838 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 839 | void WebContentsImpl::SetAccessibilityMode(AccessibilityMode mode) { |
| 840 | if (mode == accessibility_mode_) |
| 841 | return; |
| 842 | |
| 843 | accessibility_mode_ = mode; |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 844 | |
| 845 | for (FrameTreeNode* node : frame_tree_.Nodes()) { |
| 846 | SetAccessibilityModeOnFrame(mode, node->current_frame_host()); |
| 847 | RenderFrameHost* pending_frame_host = |
| 848 | node->render_manager()->pending_frame_host(); |
| 849 | if (pending_frame_host) |
| 850 | SetAccessibilityModeOnFrame(mode, pending_frame_host); |
| 851 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | void WebContentsImpl::AddAccessibilityMode(AccessibilityMode mode) { |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 855 | SetAccessibilityMode(AddAccessibilityModeTo(accessibility_mode_, mode)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | void WebContentsImpl::RemoveAccessibilityMode(AccessibilityMode mode) { |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 859 | SetAccessibilityMode(RemoveAccessibilityModeFrom(accessibility_mode_, mode)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 860 | } |
| 861 | |
dmazzoni | 83ba5c8 | 2015-04-14 07:11:51 | [diff] [blame] | 862 | void WebContentsImpl::RequestAXTreeSnapshot(AXTreeSnapshotCallback callback) { |
| 863 | // TODO(dmazzoni): http://crbug.com/475608 This only returns the |
| 864 | // accessibility tree from the main frame and everything in the |
| 865 | // same site instance. |
| 866 | GetMainFrame()->RequestAXTreeSnapshot(callback); |
| 867 | } |
| 868 | |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 869 | WebUI* WebContentsImpl::CreateSubframeWebUI(const GURL& url, |
| 870 | const std::string& frame_name) { |
| 871 | DCHECK(!frame_name.empty()); |
| 872 | return CreateWebUI(url, frame_name); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 873 | } |
| 874 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 875 | WebUI* WebContentsImpl::GetWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 876 | WebUI* commited_web_ui = GetCommittedWebUI(); |
| 877 | return commited_web_ui ? commited_web_ui |
| 878 | : GetRenderManager()->GetNavigatingWebUI(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 881 | WebUI* WebContentsImpl::GetCommittedWebUI() const { |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 882 | return frame_tree_.root()->current_frame_host()->web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 883 | } |
| 884 | |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 885 | void WebContentsImpl::SetUserAgentOverride(const std::string& override) { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 886 | if (GetUserAgentOverride() == override) |
| 887 | return; |
| 888 | |
| 889 | renderer_preferences_.user_agent_override = override; |
| 890 | |
| 891 | // Send the new override string to the renderer. |
| 892 | RenderViewHost* host = GetRenderViewHost(); |
| 893 | if (host) |
| 894 | host->SyncRendererPrefs(); |
| 895 | |
| 896 | // Reload the page if a load is currently in progress to avoid having |
| 897 | // different parts of the page loaded using different user agents. |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 898 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 899 | if (is_loading_ && entry != NULL && entry->GetIsOverridingUserAgent()) |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 900 | controller_.ReloadIgnoringCache(true); |
[email protected] | 8d0f331 | 2012-08-18 01:47:53 | [diff] [blame] | 901 | |
| 902 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 903 | UserAgentOverrideSet(override)); |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 904 | } |
| 905 | |
| 906 | const std::string& WebContentsImpl::GetUserAgentOverride() const { |
[email protected] | bf70edce | 2012-06-20 22:32:22 | [diff] [blame] | 907 | return renderer_preferences_.user_agent_override; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 908 | } |
| 909 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 910 | void WebContentsImpl::EnableTreeOnlyAccessibilityMode() { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 911 | if (GetAccessibilityMode() != AccessibilityModeOff) { |
| 912 | for (RenderFrameHost* rfh : GetAllFrames()) |
| 913 | ResetAccessibility(rfh); |
| 914 | } else { |
dtseng | 0dd3fa1 | 2015-07-22 19:00:52 | [diff] [blame] | 915 | AddAccessibilityMode(AccessibilityModeTreeOnly); |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 916 | } |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | bool WebContentsImpl::IsTreeOnlyAccessibilityModeForTesting() const { |
| 920 | return accessibility_mode_ == AccessibilityModeTreeOnly; |
| 921 | } |
| 922 | |
| 923 | bool WebContentsImpl::IsFullAccessibilityModeForTesting() const { |
| 924 | return accessibility_mode_ == AccessibilityModeComplete; |
| 925 | } |
| 926 | |
[email protected] | 2ceee8f | 2014-01-14 18:02:08 | [diff] [blame] | 927 | #if defined(OS_WIN) |
[email protected] | c73a228 | 2013-04-29 21:10:41 | [diff] [blame] | 928 | void WebContentsImpl::SetParentNativeViewAccessible( |
| 929 | gfx::NativeViewAccessible accessible_parent) { |
| 930 | accessible_parent_ = accessible_parent; |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 931 | RenderFrameHostImpl* rfh = GetMainFrame(); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 932 | if (rfh) |
| 933 | rfh->SetParentNativeViewAccessible(accessible_parent); |
[email protected] | c73a228 | 2013-04-29 21:10:41 | [diff] [blame] | 934 | } |
| 935 | #endif |
| 936 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 937 | const PageImportanceSignals& WebContentsImpl::GetPageImportanceSignals() const { |
| 938 | return page_importance_signals_; |
| 939 | } |
| 940 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 941 | const base::string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 942 | // Transient entries take precedence. They are used for interstitial pages |
| 943 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 944 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 945 | std::string accept_languages = |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 946 | GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 947 | GetBrowserContext()); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 948 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 949 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 950 | } |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 951 | |
| 952 | WebUI* navigating_web_ui = GetRenderManager()->GetNavigatingWebUI(); |
| 953 | WebUI* our_web_ui = navigating_web_ui |
| 954 | ? navigating_web_ui |
| 955 | : GetRenderManager()->current_frame_host()->web_ui(); |
| 956 | |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 957 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 958 | // Don't override the title in view source mode. |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 959 | entry = controller_.GetVisibleEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 960 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 961 | // Give the Web UI the chance to override our title. |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 962 | const base::string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 963 | if (!title.empty()) |
| 964 | return title; |
| 965 | } |
| 966 | } |
| 967 | |
| 968 | // We use the title for the last committed entry rather than a pending |
| 969 | // navigation entry. For example, when the user types in a URL, we want to |
| 970 | // keep the old page's title until the new load has committed and we get a new |
| 971 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 972 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 973 | |
creis | 072b61f | 2015-09-28 20:52:24 | [diff] [blame] | 974 | // We make an exception for initial navigations. We only want to use the title |
| 975 | // from the visible entry if: |
| 976 | // 1. The pending entry has been explicitly assigned a title to display. |
| 977 | // 2. The user is doing a history navigation in a new tab (e.g., Ctrl+Back), |
| 978 | // which case there is a pending entry index other than -1. |
| 979 | // |
| 980 | // Otherwise, we want to stick with the last committed entry's title during |
| 981 | // new navigations, which have pending entries at index -1 with no title. |
| 982 | if (controller_.IsInitialNavigation() && |
| 983 | ((controller_.GetVisibleEntry() && |
| 984 | !controller_.GetVisibleEntry()->GetTitle().empty()) || |
| 985 | controller_.GetPendingEntryIndex() != -1)) { |
| 986 | entry = controller_.GetVisibleEntry(); |
[email protected] | 9eeafc01 | 2013-11-25 23:49:47 | [diff] [blame] | 987 | } |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 988 | |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 989 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 990 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 991 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 992 | |
| 993 | // |page_title_when_no_navigation_entry_| is finally used |
| 994 | // if no title cannot be retrieved. |
| 995 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 996 | } |
| 997 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 998 | int32_t WebContentsImpl::GetMaxPageID() { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 999 | return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
| 1000 | } |
| 1001 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1002 | int32_t WebContentsImpl::GetMaxPageIDForSiteInstance( |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1003 | SiteInstance* site_instance) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1004 | if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
| 1005 | max_page_ids_[site_instance->GetId()] = -1; |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1006 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1007 | return max_page_ids_[site_instance->GetId()]; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1008 | } |
| 1009 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1010 | void WebContentsImpl::UpdateMaxPageID(int32_t page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1011 | UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); |
| 1012 | } |
| 1013 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1014 | void WebContentsImpl::UpdateMaxPageIDForSiteInstance( |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1015 | SiteInstance* site_instance, |
| 1016 | int32_t page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1017 | if (GetMaxPageIDForSiteInstance(site_instance) < page_id) |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1018 | max_page_ids_[site_instance->GetId()] = page_id; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1019 | } |
| 1020 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 1021 | void WebContentsImpl::CopyMaxPageIDsFrom(WebContents* web_contents) { |
| 1022 | WebContentsImpl* contents = static_cast<WebContentsImpl*>(web_contents); |
| 1023 | max_page_ids_ = contents->max_page_ids_; |
[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 1024 | } |
| 1025 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1026 | SiteInstanceImpl* WebContentsImpl::GetSiteInstance() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1027 | return GetRenderManager()->current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1028 | } |
| 1029 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 1030 | SiteInstanceImpl* WebContentsImpl::GetPendingSiteInstance() const { |
| 1031 | RenderViewHostImpl* dest_rvh = |
| 1032 | GetRenderManager()->pending_render_view_host() ? |
| 1033 | GetRenderManager()->pending_render_view_host() : |
| 1034 | GetRenderManager()->current_host(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1035 | return dest_rvh->GetSiteInstance(); |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 1036 | } |
| 1037 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1038 | bool WebContentsImpl::IsLoading() const { |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 1039 | return is_loading_; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1040 | } |
| 1041 | |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1042 | bool WebContentsImpl::IsLoadingToDifferentDocument() const { |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 1043 | return is_loading_ && is_load_to_different_document_; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1044 | } |
| 1045 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1046 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 1047 | return waiting_for_response_ && is_load_to_different_document_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1048 | } |
| 1049 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1050 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1051 | return load_state_; |
| 1052 | } |
| 1053 | |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 1054 | const base::string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1055 | return load_state_host_; |
| 1056 | } |
| 1057 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1058 | uint64_t WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1059 | return upload_size_; |
| 1060 | } |
| 1061 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1062 | uint64_t WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1063 | return upload_position_; |
| 1064 | } |
| 1065 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1066 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 1067 | return canonical_encoding_; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1068 | } |
| 1069 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1070 | bool WebContentsImpl::DisplayedInsecureContent() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1071 | return displayed_insecure_content_; |
| 1072 | } |
| 1073 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1074 | void WebContentsImpl::IncrementCapturerCount(const gfx::Size& capture_size) { |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1075 | DCHECK(!is_being_destroyed_); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1076 | ++capturer_count_; |
| 1077 | DVLOG(1) << "There are now " << capturer_count_ |
| 1078 | << " capturing(s) of WebContentsImpl@" << this; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1079 | |
| 1080 | // Note: This provides a hint to upstream code to size the views optimally |
| 1081 | // for quality (e.g., to avoid scaling). |
| 1082 | if (!capture_size.IsEmpty() && preferred_size_for_capture_.IsEmpty()) { |
| 1083 | preferred_size_for_capture_ = capture_size; |
| 1084 | OnPreferredSizeChanged(preferred_size_); |
| 1085 | } |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1086 | |
| 1087 | // Ensure that all views are un-occluded before capture begins. |
| 1088 | WasUnOccluded(); |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1089 | } |
| 1090 | |
| 1091 | void WebContentsImpl::DecrementCapturerCount() { |
| 1092 | --capturer_count_; |
| 1093 | DVLOG(1) << "There are now " << capturer_count_ |
| 1094 | << " capturing(s) of WebContentsImpl@" << this; |
| 1095 | DCHECK_LE(0, capturer_count_); |
| 1096 | |
[email protected] | 5a65223 | 2013-02-12 06:15:25 | [diff] [blame] | 1097 | if (is_being_destroyed_) |
| 1098 | return; |
| 1099 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 1100 | if (capturer_count_ == 0) { |
| 1101 | const gfx::Size old_size = preferred_size_for_capture_; |
| 1102 | preferred_size_for_capture_ = gfx::Size(); |
| 1103 | OnPreferredSizeChanged(old_size); |
| 1104 | } |
| 1105 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 1106 | if (IsHidden()) { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1107 | DVLOG(1) << "Executing delayed WasHidden()."; |
| 1108 | WasHidden(); |
| 1109 | } |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1110 | } |
| 1111 | |
[email protected] | f2bd4081 | 2013-07-20 04:30:44 | [diff] [blame] | 1112 | int WebContentsImpl::GetCapturerCount() const { |
| 1113 | return capturer_count_; |
| 1114 | } |
| 1115 | |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1116 | bool WebContentsImpl::IsAudioMuted() const { |
| 1117 | return audio_muter_.get() && audio_muter_->is_muting(); |
| 1118 | } |
| 1119 | |
| 1120 | void WebContentsImpl::SetAudioMuted(bool mute) { |
| 1121 | DVLOG(1) << "SetAudioMuted(mute=" << mute << "), was " << IsAudioMuted() |
| 1122 | << " for WebContentsImpl@" << this; |
| 1123 | |
| 1124 | if (mute == IsAudioMuted()) |
| 1125 | return; |
| 1126 | |
| 1127 | if (mute) { |
| 1128 | if (!audio_muter_) |
| 1129 | audio_muter_.reset(new WebContentsAudioMuter(this)); |
| 1130 | audio_muter_->StartMuting(); |
| 1131 | } else { |
| 1132 | DCHECK(audio_muter_); |
| 1133 | audio_muter_->StopMuting(); |
| 1134 | } |
| 1135 | |
wjmaclean | 2f797c78 | 2016-01-07 14:52:03 | [diff] [blame] | 1136 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1137 | DidUpdateAudioMutingState(mute)); |
| 1138 | |
miu | 50f9789 | 2014-09-22 22:49:52 | [diff] [blame] | 1139 | // Notification for UI updates in response to the changed muting state. |
| 1140 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
| 1141 | } |
| 1142 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1143 | bool WebContentsImpl::IsCrashed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1144 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 1145 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1146 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1147 | #if defined(OS_CHROMEOS) |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1148 | crashed_status_ == |
| 1149 | base::TERMINATION_STATUS_PROCESS_WAS_KILLED_BY_OOM || |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1150 | #endif |
wfh | 0d9532a | 2015-09-02 23:18:58 | [diff] [blame] | 1151 | crashed_status_ == base::TERMINATION_STATUS_LAUNCH_FAILED |
oshima | 62022572 | 2015-06-04 19:45:27 | [diff] [blame] | 1152 | ); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1153 | } |
| 1154 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1155 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 1156 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1157 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1158 | return; |
| 1159 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1160 | crashed_status_ = status; |
| 1161 | crashed_error_code_ = error_code; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1162 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1163 | } |
| 1164 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1165 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1166 | return crashed_status_; |
| 1167 | } |
| 1168 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1169 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1170 | return is_being_destroyed_; |
| 1171 | } |
| 1172 | |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 1173 | void WebContentsImpl::NotifyNavigationStateChanged( |
| 1174 | InvalidateTypes changed_flags) { |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 1175 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 1176 | // is fixed. |
| 1177 | tracked_objects::ScopedTracker tracking_profile( |
| 1178 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 1179 | "466285 WebContentsImpl::NotifyNavigationStateChanged")); |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 1180 | // Notify the media observer of potential audibility changes. |
| 1181 | if (changed_flags & INVALIDATE_TYPE_TAB) { |
mlamouri | 44e4ef4 | 2016-01-20 18:42:27 | [diff] [blame] | 1182 | media_web_contents_observer_->MaybeUpdateAudibleState(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 1183 | } |
| 1184 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1185 | if (delegate_) |
| 1186 | delegate_->NavigationStateChanged(this, changed_flags); |
| 1187 | } |
| 1188 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1189 | base::TimeTicks WebContentsImpl::GetLastActiveTime() const { |
[email protected] | 9a89045 | 2014-02-13 22:21:02 | [diff] [blame] | 1190 | return last_active_time_; |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1191 | } |
| 1192 | |
georgesak | 5582cbe | 2015-05-22 22:08:07 | [diff] [blame] | 1193 | void WebContentsImpl::SetLastActiveTime(base::TimeTicks last_active_time) { |
| 1194 | last_active_time_ = last_active_time; |
| 1195 | } |
| 1196 | |
[email protected] | 9e2e463 | 2012-07-27 16:38:41 | [diff] [blame] | 1197 | void WebContentsImpl::WasShown() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1198 | controller_.SetActive(true); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1199 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1200 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1201 | if (view) { |
| 1202 | view->Show(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1203 | #if defined(OS_MACOSX) |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1204 | view->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1205 | #endif |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1206 | } |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 1207 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1208 | |
gab | 0dccfef | 2015-05-20 18:43:39 | [diff] [blame] | 1209 | last_active_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 1210 | |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 1211 | // The resize rect might have changed while this was inactive -- send the new |
| 1212 | // one to make sure it's up to date. |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1213 | RenderViewHostImpl* rvh = GetRenderViewHost(); |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1214 | if (rvh) { |
| 1215 | rvh->GetWidget()->ResizeRectChanged( |
| 1216 | GetRootWindowResizerRect(rvh->GetWidget())); |
| 1217 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1218 | |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1219 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasShown()); |
| 1220 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1221 | should_normally_be_visible_ = true; |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1222 | } |
| 1223 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1224 | void WebContentsImpl::WasHidden() { |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1225 | // If there are entities capturing screenshots or video (e.g., mirroring), |
| 1226 | // don't activate the "disable rendering" optimization. |
| 1227 | if (capturer_count_ == 0) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1228 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1229 | // open a tab in the background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1230 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1231 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
[email protected] | 3e32414 | 2012-06-25 18:26:33 | [diff] [blame] | 1232 | // window, OnWindowPosChanged() notices and calls WasHidden() (which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1233 | // calls us). |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1234 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1235 | if (view) |
| 1236 | view->Hide(); |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1237 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1238 | } |
| 1239 | |
[email protected] | c0d9d567 | 2013-10-09 07:38:03 | [diff] [blame] | 1240 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, WasHidden()); |
| 1241 | |
[email protected] | 5459798 | 2013-02-06 01:59:55 | [diff] [blame] | 1242 | should_normally_be_visible_ = false; |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 1243 | } |
| 1244 | |
ccameron | 8807c38f | 2015-01-17 00:29:19 | [diff] [blame] | 1245 | void WebContentsImpl::WasOccluded() { |
| 1246 | if (capturer_count_ > 0) |
| 1247 | return; |
| 1248 | |
| 1249 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1250 | if (view) |
| 1251 | view->WasOccluded(); |
| 1252 | } |
| 1253 | } |
| 1254 | |
| 1255 | void WebContentsImpl::WasUnOccluded() { |
| 1256 | for (RenderWidgetHostView* view : GetRenderWidgetHostViewsInTree()) { |
| 1257 | if (view) |
| 1258 | view->WasUnOccluded(); |
| 1259 | } |
| 1260 | } |
| 1261 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1262 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1263 | // TODO(creis): Should we fire even for interstitial pages? |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1264 | return WillNotifyDisconnection() && !ShowingInterstitialPage() && |
| 1265 | !GetRenderViewHost()->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1266 | } |
| 1267 | |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1268 | void WebContentsImpl::DispatchBeforeUnload(bool for_cross_site_transition) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1269 | GetMainFrame()->DispatchBeforeUnload(for_cross_site_transition); |
[email protected] | 1c3f80bd | 2014-04-08 23:02:06 | [diff] [blame] | 1270 | } |
| 1271 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1272 | void WebContentsImpl::AttachToOuterWebContentsFrame( |
| 1273 | WebContents* outer_web_contents, |
| 1274 | RenderFrameHost* outer_contents_frame) { |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 1275 | CHECK(BrowserPluginGuestMode::UseCrossProcessFramesForGuests()); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1276 | // Create a link to our outer WebContents. |
| 1277 | node_.reset(new WebContentsTreeNode()); |
| 1278 | node_->ConnectToOuterWebContents( |
| 1279 | static_cast<WebContentsImpl*>(outer_web_contents), |
| 1280 | static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1281 | |
| 1282 | DCHECK(outer_contents_frame); |
| 1283 | |
| 1284 | // Create a proxy in top-level RenderFrameHostManager, pointing to the |
| 1285 | // SiteInstance of the outer WebContents. The proxy will be used to send |
| 1286 | // postMessage to the inner WebContents. |
| 1287 | GetRenderManager()->CreateOuterDelegateProxy( |
| 1288 | outer_contents_frame->GetSiteInstance(), |
| 1289 | static_cast<RenderFrameHostImpl*>(outer_contents_frame)); |
| 1290 | |
| 1291 | GetRenderManager()->SetRWHViewForInnerContents( |
| 1292 | GetRenderManager()->GetRenderWidgetHostView()); |
| 1293 | } |
| 1294 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1295 | void WebContentsImpl::Stop() { |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1296 | for (FrameTreeNode* node : frame_tree_.Nodes()) |
| 1297 | node->StopLoading(); |
[email protected] | d16609c | 2013-08-23 06:01:40 | [diff] [blame] | 1298 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, NavigationStopped()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1299 | } |
| 1300 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1301 | WebContents* WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1302 | // We use our current SiteInstance since the cloned entry will use it anyway. |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1303 | // 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] | 1304 | // before. |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1305 | CreateParams create_params(GetBrowserContext(), GetSiteInstance()); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1306 | create_params.initial_size = GetContainerBounds().size(); |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1307 | WebContentsImpl* tc = |
| 1308 | CreateWithOpener(create_params, frame_tree_.root()->opener()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1309 | tc->GetController().CopyStateFrom(controller_); |
[email protected] | 7381d9f | 2012-09-12 20:26:22 | [diff] [blame] | 1310 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 1311 | observers_, |
| 1312 | DidCloneToNewWebContents(this, tc)); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1313 | return tc; |
| 1314 | } |
| 1315 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1316 | void WebContentsImpl::Observe(int type, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1317 | const NotificationSource& source, |
| 1318 | const NotificationDetails& details) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1319 | switch (type) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1320 | case NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1321 | RenderWidgetHost* host = Source<RenderWidgetHost>(source).ptr(); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1322 | RenderWidgetHostView* view = host->GetView(); |
| 1323 | if (view == GetFullscreenRenderWidgetHostView()) { |
| 1324 | // We cannot just call view_->RestoreFocus() here. On some platforms, |
| 1325 | // attempting to focus the currently-invisible WebContentsView will be |
| 1326 | // flat-out ignored. Therefore, this boolean is used to track whether |
| 1327 | // we will request focus after the fullscreen widget has been |
| 1328 | // destroyed. |
| 1329 | fullscreen_widget_had_focus_at_shutdown_ = (view && view->HasFocus()); |
| 1330 | } else { |
| 1331 | for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); |
| 1332 | i != pending_widget_views_.end(); ++i) { |
| 1333 | if (host->GetView() == i->second) { |
| 1334 | pending_widget_views_.erase(i); |
| 1335 | break; |
| 1336 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1337 | } |
| 1338 | } |
| 1339 | break; |
| 1340 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1341 | default: |
| 1342 | NOTREACHED(); |
| 1343 | } |
| 1344 | } |
| 1345 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 1346 | WebContents* WebContentsImpl::GetWebContents() { |
| 1347 | return this; |
| 1348 | } |
| 1349 | |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1350 | void WebContentsImpl::Init(const WebContents::CreateParams& params) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1351 | // This is set before initializing the render manager since |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 1352 | // RenderFrameHostManager::Init calls back into us via its delegate to ask if |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 1353 | // it should be hidden. |
[email protected] | d6fa88f | 2013-10-18 16:00:43 | [diff] [blame] | 1354 | should_normally_be_visible_ = !params.initially_hidden; |
| 1355 | |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1356 | // The routing ids must either all be set or all be unset. |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1357 | DCHECK((params.routing_id == MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1358 | params.main_frame_routing_id == MSG_ROUTING_NONE && |
| 1359 | params.main_frame_widget_routing_id == MSG_ROUTING_NONE) || |
avi | c2c29d78 | 2014-12-12 00:23:54 | [diff] [blame] | 1360 | (params.routing_id != MSG_ROUTING_NONE && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1361 | params.main_frame_routing_id != MSG_ROUTING_NONE && |
| 1362 | params.main_frame_widget_routing_id != MSG_ROUTING_NONE)); |
| 1363 | |
| 1364 | scoped_refptr<SiteInstance> site_instance = params.site_instance; |
| 1365 | if (!site_instance) |
| 1366 | site_instance = SiteInstance::Create(params.browser_context); |
| 1367 | |
| 1368 | // A main RenderFrameHost always has a RenderWidgetHost, since it is always a |
| 1369 | // local root by definition. |
| 1370 | // TODO(avi): Once RenderViewHostImpl has-a RenderWidgetHostImpl, it will no |
| 1371 | // longer be necessary to eagerly grab a routing ID for the view. |
| 1372 | // https://crbug.com/545684 |
| 1373 | int32_t view_routing_id = params.routing_id; |
| 1374 | int32_t main_frame_widget_routing_id = params.main_frame_widget_routing_id; |
| 1375 | if (main_frame_widget_routing_id == MSG_ROUTING_NONE) { |
| 1376 | view_routing_id = main_frame_widget_routing_id = |
| 1377 | site_instance->GetProcess()->GetNextRoutingID(); |
| 1378 | } |
| 1379 | |
| 1380 | GetRenderManager()->Init(site_instance.get(), view_routing_id, |
| 1381 | params.main_frame_routing_id, |
| 1382 | main_frame_widget_routing_id); |
nasko | c9f51dd | 2015-05-13 00:39:28 | [diff] [blame] | 1383 | frame_tree_.root()->SetFrameName(params.main_frame_name); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1384 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1385 | WebContentsViewDelegate* delegate = |
| 1386 | GetContentClient()->browser()->GetWebContentsViewDelegate(this); |
| 1387 | |
fsamuel | adb003360 | 2015-12-09 19:20:41 | [diff] [blame] | 1388 | #if defined(MOJO_SHELL_CLIENT) |
| 1389 | if (MojoShellConnection::Get() && |
| 1390 | base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 1391 | switches::kUseMusInRenderer)) { |
| 1392 | mus::Window* mus_window = aura::GetMusWindow(params.context); |
| 1393 | if (mus_window) { |
| 1394 | view_.reset(new WebContentsViewMus(mus_window, this, delegate, |
| 1395 | &render_view_host_delegate_view_)); |
| 1396 | } |
| 1397 | } |
| 1398 | #endif |
| 1399 | |
| 1400 | if (!view_) { |
| 1401 | view_.reset(CreateWebContentsView(this, delegate, |
| 1402 | &render_view_host_delegate_view_)); |
| 1403 | } |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1404 | |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1405 | if (browser_plugin_guest_ && |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 1406 | !BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1407 | view_.reset(new WebContentsViewGuest(this, browser_plugin_guest_.get(), |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 1408 | std::move(view_), |
fsamuel | 9cf7bdf | 2015-11-20 02:19:32 | [diff] [blame] | 1409 | &render_view_host_delegate_view_)); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1410 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1411 | CHECK(render_view_host_delegate_view_); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1412 | CHECK(view_.get()); |
| 1413 | |
[email protected] | ed245db | 2012-12-18 08:00:45 | [diff] [blame] | 1414 | gfx::Size initial_size = params.initial_size; |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1415 | view_->CreateView(initial_size, params.context); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1416 | |
tommycli | eb25b2a | 2014-11-03 19:45:09 | [diff] [blame] | 1417 | #if defined(ENABLE_PLUGINS) |
| 1418 | plugin_content_origin_whitelist_.reset( |
| 1419 | new PluginContentOriginWhitelist(this)); |
| 1420 | #endif |
| 1421 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1422 | registrar_.Add(this, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1423 | NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 1424 | NotificationService::AllBrowserContextsAndSources()); |
[email protected] | f28ef9a3 | 2014-05-12 16:36:10 | [diff] [blame] | 1425 | |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 1426 | screen_orientation_dispatcher_host_.reset( |
jonross | 7497152 | 2014-09-15 14:16:09 | [diff] [blame] | 1427 | new ScreenOrientationDispatcherHostImpl(this)); |
[email protected] | 01f83f9 | 2014-06-17 14:41:54 | [diff] [blame] | 1428 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 1429 | manifest_manager_host_.reset(new ManifestManagerHost(this)); |
| 1430 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 1431 | #if defined(OS_ANDROID) |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 1432 | date_time_chooser_.reset(new DateTimeChooserAndroid()); |
| 1433 | #endif |
fsamuel | 7310a426 | 2014-12-05 05:06:44 | [diff] [blame] | 1434 | |
| 1435 | // BrowserPluginGuest::Init needs to be called after this WebContents has |
| 1436 | // a RenderWidgetHostViewGuest. That is, |view_->CreateView| above. |
| 1437 | if (browser_plugin_guest_) |
| 1438 | browser_plugin_guest_->Init(); |
nick | f9acfbe | 2014-12-23 19:12:37 | [diff] [blame] | 1439 | |
| 1440 | for (size_t i = 0; i < g_created_callbacks.Get().size(); i++) |
| 1441 | g_created_callbacks.Get().at(i).Run(this); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1442 | |
| 1443 | // If the WebContents creation was renderer-initiated, it means that the |
| 1444 | // corresponding RenderView and main RenderFrame have already been created. |
| 1445 | // Ensure observers are notified about this. |
| 1446 | if (params.renderer_initiated_creation) { |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 1447 | GetRenderViewHost()->GetWidget()->set_renderer_initialized(true); |
nasko | b21fe487 | 2015-02-24 14:15:56 | [diff] [blame] | 1448 | RenderViewCreated(GetRenderViewHost()); |
| 1449 | GetRenderManager()->current_frame_host()->SetRenderFrameCreated(true); |
| 1450 | } |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 1451 | |
| 1452 | // Ensure that observers are notified of the creation of this WebContents's |
| 1453 | // main RenderFrameHost. It must be done here for main frames, since the |
| 1454 | // NotifySwappedFromRenderManager expects view_ to already be created and that |
| 1455 | // happens after RenderFrameHostManager::Init. |
| 1456 | NotifySwappedFromRenderManager( |
| 1457 | nullptr, GetRenderManager()->current_frame_host(), true); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1458 | } |
| 1459 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1460 | void WebContentsImpl::OnWebContentsDestroyed(WebContentsImpl* web_contents) { |
| 1461 | RemoveDestructionObserver(web_contents); |
| 1462 | |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1463 | // Clear a pending contents that has been closed before being shown. |
| 1464 | for (PendingContents::iterator iter = pending_contents_.begin(); |
| 1465 | iter != pending_contents_.end(); |
| 1466 | ++iter) { |
| 1467 | if (iter->second != web_contents) |
| 1468 | continue; |
| 1469 | pending_contents_.erase(iter); |
[email protected] | ceee8cd | 2013-03-08 04:59:51 | [diff] [blame] | 1470 | return; |
| 1471 | } |
| 1472 | NOTREACHED(); |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1473 | } |
| 1474 | |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1475 | void WebContentsImpl::AddDestructionObserver(WebContentsImpl* web_contents) { |
| 1476 | if (!ContainsKey(destruction_observers_, web_contents)) { |
| 1477 | destruction_observers_[web_contents] = |
| 1478 | new DestructionObserver(this, web_contents); |
| 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | void WebContentsImpl::RemoveDestructionObserver(WebContentsImpl* web_contents) { |
| 1483 | DestructionObservers::iterator iter = |
| 1484 | destruction_observers_.find(web_contents); |
| 1485 | if (iter != destruction_observers_.end()) { |
| 1486 | delete destruction_observers_[web_contents]; |
| 1487 | destruction_observers_.erase(iter); |
| 1488 | } |
| 1489 | } |
| 1490 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1491 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1492 | observers_.AddObserver(observer); |
| 1493 | } |
| 1494 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1495 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1496 | observers_.RemoveObserver(observer); |
| 1497 | } |
| 1498 | |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1499 | std::set<RenderWidgetHostView*> |
| 1500 | WebContentsImpl::GetRenderWidgetHostViewsInTree() { |
| 1501 | std::set<RenderWidgetHostView*> set; |
| 1502 | if (ShowingInterstitialPage()) { |
| 1503 | set.insert(GetRenderWidgetHostView()); |
| 1504 | } else { |
dcheng | afb53e2 | 2016-02-04 08:11:08 | [diff] [blame] | 1505 | for (RenderFrameHost* rfh : GetAllFrames()) { |
| 1506 | RenderWidgetHostView* rwhv = static_cast<RenderFrameHostImpl*>(rfh) |
| 1507 | ->frame_tree_node() |
| 1508 | ->render_manager() |
| 1509 | ->GetRenderWidgetHostView(); |
| 1510 | set.insert(rwhv); |
| 1511 | } |
[email protected] | 948481d | 2014-06-11 18:32:22 | [diff] [blame] | 1512 | } |
[email protected] | de3c5d8 | 2014-05-28 22:12:59 | [diff] [blame] | 1513 | return set; |
| 1514 | } |
| 1515 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1516 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1517 | if (delegate_) |
| 1518 | delegate_->ActivateContents(this); |
| 1519 | } |
| 1520 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1521 | void WebContentsImpl::LostCapture(RenderWidgetHostImpl* render_widget_host) { |
| 1522 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1523 | return; |
| 1524 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1525 | if (delegate_) |
| 1526 | delegate_->LostCapture(); |
| 1527 | } |
| 1528 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1529 | void WebContentsImpl::RenderWidgetCreated( |
| 1530 | RenderWidgetHostImpl* render_widget_host) { |
| 1531 | created_widgets_.insert(render_widget_host); |
| 1532 | } |
| 1533 | |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1534 | void WebContentsImpl::RenderWidgetDeleted( |
| 1535 | RenderWidgetHostImpl* render_widget_host) { |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1536 | // Note that |is_being_destroyed_| can be true at this point as |
| 1537 | // ~WebContentsImpl() calls RFHM::ClearRFHsPendingShutdown(), which might lead |
| 1538 | // us here. |
| 1539 | created_widgets_.erase(render_widget_host); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1540 | |
lazyboy | 63f5b31 | 2015-11-23 20:19:52 | [diff] [blame] | 1541 | if (is_being_destroyed_) |
| 1542 | return; |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1543 | |
| 1544 | if (render_widget_host && |
| 1545 | render_widget_host->GetRoutingID() == fullscreen_widget_routing_id_) { |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1546 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1547 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1548 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 1549 | observers_, |
| 1550 | DidDestroyFullscreenWidget( |
| 1551 | fullscreen_widget_routing_id_)); |
| 1552 | fullscreen_widget_routing_id_ = MSG_ROUTING_NONE; |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 1553 | if (fullscreen_widget_had_focus_at_shutdown_) |
| 1554 | view_->RestoreFocus(); |
[email protected] | 44470a2 | 2013-01-24 01:21:54 | [diff] [blame] | 1555 | } |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1556 | } |
| 1557 | |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1558 | void WebContentsImpl::RenderWidgetGotFocus( |
| 1559 | RenderWidgetHostImpl* render_widget_host) { |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 1560 | // Notify the observers if an embedded fullscreen widget was focused. |
| 1561 | if (delegate_ && render_widget_host && delegate_->EmbedsFullscreenWidget() && |
| 1562 | render_widget_host->GetView() == GetFullscreenRenderWidgetHostView()) { |
| 1563 | NotifyWebContentsFocused(); |
| 1564 | } |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 1565 | } |
| 1566 | |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1567 | void WebContentsImpl::RenderWidgetWasResized( |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 1568 | RenderWidgetHostImpl* render_widget_host, |
| 1569 | bool width_changed) { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 1570 | RenderFrameHostImpl* rfh = GetMainFrame(); |
estade | ce344ec | 2015-01-23 00:12:29 | [diff] [blame] | 1571 | if (!rfh || render_widget_host != rfh->GetRenderWidgetHost()) |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1572 | return; |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1573 | |
rouslan | 2f5993f | 2015-01-29 00:18:31 | [diff] [blame] | 1574 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1575 | MainFrameWasResized(width_changed)); |
estade | d0a0c99 | 2015-01-21 14:12:06 | [diff] [blame] | 1576 | } |
| 1577 | |
paulmeyer | 9ef6e446 | 2015-02-24 19:15:10 | [diff] [blame] | 1578 | void WebContentsImpl::ScreenInfoChanged() { |
| 1579 | if (browser_plugin_embedder_) |
| 1580 | browser_plugin_embedder_->ScreenInfoChanged(); |
| 1581 | } |
| 1582 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1583 | bool WebContentsImpl::PreHandleKeyboardEvent( |
| 1584 | const NativeWebKeyboardEvent& event, |
| 1585 | bool* is_keyboard_shortcut) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1586 | return delegate_ && |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1587 | delegate_->PreHandleKeyboardEvent(this, event, is_keyboard_shortcut); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1588 | } |
| 1589 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1590 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 0b09400 | 2014-08-20 18:28:10 | [diff] [blame] | 1591 | if (browser_plugin_embedder_ && |
| 1592 | browser_plugin_embedder_->HandleKeyboardEvent(event)) { |
| 1593 | return; |
| 1594 | } |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1595 | if (delegate_) |
[email protected] | b3996ba | 2012-08-08 00:39:13 | [diff] [blame] | 1596 | delegate_->HandleKeyboardEvent(this, event); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1597 | } |
| 1598 | |
[email protected] | d92026ef | 2014-03-03 21:04:13 | [diff] [blame] | 1599 | bool WebContentsImpl::HandleWheelEvent( |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1600 | const blink::WebMouseWheelEvent& event) { |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1601 | #if !defined(OS_MACOSX) |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1602 | // On platforms other than Mac, control+mousewheel may change zoom. On Mac, |
| 1603 | // this isn't done for two reasons: |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1604 | // -the OS already has a gesture to do this through pinch-zoom |
| 1605 | // -if a user starts an inertial scroll, let's go, and presses control |
| 1606 | // (i.e. control+tab) then the OS's buffered scroll events will come in |
| 1607 | // with control key set which isn't what the user wants |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1608 | if (delegate_ && event.wheelTicksY && |
[email protected] | 5a24f580 | 2014-04-22 22:39:55 | [diff] [blame] | 1609 | (event.modifiers & blink::WebInputEvent::ControlKey) && |
lanwei | a93644f | 2015-01-21 22:00:33 | [diff] [blame] | 1610 | !event.canScroll) { |
w.shackleton | 49bcd39 | 2016-01-06 17:38:22 | [diff] [blame] | 1611 | // Count only integer cumulative scrolls as zoom events; this handles |
| 1612 | // smooth scroll and regular scroll device behavior. |
| 1613 | zoom_scroll_remainder_ += event.wheelTicksY; |
| 1614 | int whole_zoom_scroll_remainder_ = std::lround(zoom_scroll_remainder_); |
| 1615 | zoom_scroll_remainder_ -= whole_zoom_scroll_remainder_; |
| 1616 | if (whole_zoom_scroll_remainder_ != 0) { |
| 1617 | delegate_->ContentsZoomChange(whole_zoom_scroll_remainder_ > 0); |
| 1618 | } |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1619 | return true; |
| 1620 | } |
[email protected] | bccc447 | 2013-04-18 16:37:19 | [diff] [blame] | 1621 | #endif |
[email protected] | fb3f066e | 2013-02-12 19:12:52 | [diff] [blame] | 1622 | return false; |
| 1623 | } |
| 1624 | |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1625 | bool WebContentsImpl::PreHandleGestureEvent( |
| 1626 | const blink::WebGestureEvent& event) { |
[email protected] | 28042d3 | 2014-02-03 14:10:03 | [diff] [blame] | 1627 | return delegate_ && delegate_->PreHandleGestureEvent(this, event); |
[email protected] | 04bce56 | 2014-01-30 05:34:54 | [diff] [blame] | 1628 | } |
| 1629 | |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1630 | RenderWidgetHostInputEventRouter* WebContentsImpl::GetInputEventRouter() { |
wjmaclean | e31234f | 2015-12-14 17:20:45 | [diff] [blame] | 1631 | if (!is_being_destroyed_ && GetOuterWebContents()) |
| 1632 | return GetOuterWebContents()->GetInputEventRouter(); |
| 1633 | |
| 1634 | if (!rwh_input_event_router_.get() && !is_being_destroyed_) |
kenrb | 2a565f8 | 2015-09-02 20:24:59 | [diff] [blame] | 1635 | rwh_input_event_router_.reset(new RenderWidgetHostInputEventRouter); |
| 1636 | return rwh_input_event_router_.get(); |
| 1637 | } |
| 1638 | |
alexmos | 3fcd0ca | 2015-10-23 18:18:33 | [diff] [blame] | 1639 | void WebContentsImpl::ReplicatePageFocus(bool is_focused) { |
| 1640 | // Focus loss may occur while this WebContents is being destroyed. Don't |
| 1641 | // send the message in this case, as the main frame's RenderFrameHost and |
| 1642 | // other state has already been cleared. |
| 1643 | if (is_being_destroyed_) |
| 1644 | return; |
| 1645 | |
| 1646 | frame_tree_.ReplicatePageFocus(is_focused); |
| 1647 | } |
| 1648 | |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1649 | RenderWidgetHostImpl* WebContentsImpl::GetFocusedRenderWidgetHost( |
| 1650 | RenderWidgetHostImpl* receiving_widget) { |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1651 | if (!SiteIsolationPolicy::AreCrossProcessFramesPossible()) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1652 | return receiving_widget; |
| 1653 | |
| 1654 | // Events for widgets other than the main frame (e.g., popup menus) should be |
| 1655 | // forwarded directly to the widget they arrived on. |
| 1656 | if (receiving_widget != GetMainFrame()->GetRenderWidgetHost()) |
| 1657 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1658 | |
| 1659 | FrameTreeNode* focused_frame = frame_tree_.GetFocusedFrame(); |
| 1660 | if (!focused_frame) |
alexmos | c4cbacb | 2015-11-21 01:29:22 | [diff] [blame] | 1661 | return receiving_widget; |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1662 | |
alexmos | 732ca3a | 2015-12-08 02:01:02 | [diff] [blame] | 1663 | // The view may be null if a subframe's renderer process has crashed while |
| 1664 | // the subframe has focus. Drop the event in that case. Do not give |
| 1665 | // it to the main frame, so that the user doesn't unexpectedly type into the |
| 1666 | // wrong frame if a focused subframe renderer crashes while they type. |
| 1667 | RenderWidgetHostView* view = focused_frame->current_frame_host()->GetView(); |
| 1668 | if (!view) |
| 1669 | return nullptr; |
| 1670 | |
| 1671 | return RenderWidgetHostImpl::From(view->GetRenderWidgetHost()); |
alexmos | c4d183e | 2015-11-06 00:46:52 | [diff] [blame] | 1672 | } |
| 1673 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1674 | void WebContentsImpl::EnterFullscreenMode(const GURL& origin) { |
| 1675 | // This method is being called to enter renderer-initiated fullscreen mode. |
| 1676 | // Make sure any existing fullscreen widget is shut down first. |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1677 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 1678 | if (widget_view) { |
| 1679 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1680 | ->ShutdownAndDestroyWidget(true); |
| 1681 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 1682 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1683 | if (delegate_) |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1684 | delegate_->EnterFullscreenModeForTab(this, origin); |
| 1685 | |
| 1686 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1687 | DidToggleFullscreenModeForTab( |
| 1688 | IsFullscreenForCurrentTab( |
| 1689 | GetRenderViewHost()->GetWidget()), |
| 1690 | false)); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1691 | } |
| 1692 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1693 | void WebContentsImpl::ExitFullscreenMode(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1694 | // This method is being called to leave renderer-initiated fullscreen mode. |
| 1695 | // Make sure any existing fullscreen widget is shut down first. |
| 1696 | RenderWidgetHostView* const widget_view = GetFullscreenRenderWidgetHostView(); |
avi | 85a4cef | 2015-12-18 20:13:37 | [diff] [blame] | 1697 | if (widget_view) { |
| 1698 | RenderWidgetHostImpl::From(widget_view->GetRenderWidgetHost()) |
| 1699 | ->ShutdownAndDestroyWidget(true); |
| 1700 | } |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1701 | |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 1702 | #if defined(OS_ANDROID) |
| 1703 | ContentVideoView* video_view = ContentVideoView::GetInstance(); |
| 1704 | if (video_view != NULL) |
watk | 9829229 | 2016-01-19 22:24:08 | [diff] [blame] | 1705 | video_view->ExitFullscreen(); |
hugo.holgersson | 61288e6c | 2015-01-28 17:04:40 | [diff] [blame] | 1706 | #endif |
| 1707 | |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 1708 | if (delegate_) |
| 1709 | delegate_->ExitFullscreenModeForTab(this); |
[email protected] | 657c8e0 | 2014-03-19 19:18:37 | [diff] [blame] | 1710 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1711 | // The fullscreen state is communicated to the renderer through a resize |
| 1712 | // message. If the change in fullscreen state doesn't cause a view resize |
| 1713 | // then we must ensure web contents exit the fullscreen state by explicitly |
| 1714 | // sending a resize message. This is required for the situation of the browser |
| 1715 | // moving the view into a "browser fullscreen" state and then the contents |
| 1716 | // entering "tab fullscreen". Exiting the contents "tab fullscreen" then won't |
| 1717 | // have the side effect of the view resizing, hence the explicit call here is |
| 1718 | // required. |
| 1719 | if (!will_cause_resize) { |
| 1720 | if (RenderWidgetHostView* rwhv = GetRenderWidgetHostView()) { |
| 1721 | if (RenderWidgetHost* render_widget_host = rwhv->GetRenderWidgetHost()) |
| 1722 | render_widget_host->WasResized(); |
| 1723 | } |
scheib | 3dcb6c93 | 2015-02-23 10:55:58 | [diff] [blame] | 1724 | } |
| 1725 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 1726 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 1727 | DidToggleFullscreenModeForTab( |
| 1728 | IsFullscreenForCurrentTab( |
| 1729 | GetRenderViewHost()->GetWidget()), |
| 1730 | will_cause_resize)); |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1731 | } |
| 1732 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 1733 | bool WebContentsImpl::IsFullscreenForCurrentTab( |
| 1734 | RenderWidgetHostImpl* render_widget_host) const { |
| 1735 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1736 | return false; |
| 1737 | |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 1738 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1739 | } |
| 1740 | |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 1741 | blink::WebDisplayMode WebContentsImpl::GetDisplayMode( |
| 1742 | RenderWidgetHostImpl* render_widget_host) const { |
| 1743 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1744 | return blink::WebDisplayModeBrowser; |
| 1745 | |
mikhail.pozdnyakov | c0e251b | 2015-04-15 06:51:12 | [diff] [blame] | 1746 | return delegate_ ? delegate_->GetDisplayMode(this) |
| 1747 | : blink::WebDisplayModeBrowser; |
| 1748 | } |
| 1749 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1750 | void WebContentsImpl::RequestToLockMouse( |
| 1751 | RenderWidgetHostImpl* render_widget_host, |
| 1752 | bool user_gesture, |
| 1753 | bool last_unlocked_by_target) { |
| 1754 | if (render_widget_host != GetRenderViewHost()->GetWidget()) { |
| 1755 | render_widget_host->GotResponseToLockMouseRequest(false); |
| 1756 | return; |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1757 | } |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 1758 | |
| 1759 | if (delegate_) |
| 1760 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
| 1761 | else |
| 1762 | GotResponseToLockMouseRequest(false); |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1763 | } |
| 1764 | |
avi | 3e4b851 | 2015-11-11 01:55:49 | [diff] [blame] | 1765 | void WebContentsImpl::LostMouseLock(RenderWidgetHostImpl* render_widget_host) { |
| 1766 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 1767 | return; |
| 1768 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1769 | if (delegate_) |
| 1770 | delegate_->LostMouseLock(); |
| 1771 | } |
| 1772 | |
dtrainor | 5ef644e | 2015-11-19 00:12:47 | [diff] [blame] | 1773 | void WebContentsImpl::ForwardCompositorProto( |
| 1774 | RenderWidgetHostImpl* render_widget_host, |
| 1775 | const std::vector<uint8_t>& proto) { |
| 1776 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 1777 | return; |
| 1778 | |
| 1779 | if (delegate_) |
| 1780 | delegate_->ForwardCompositorProto(proto); |
| 1781 | } |
| 1782 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1783 | void WebContentsImpl::CreateNewWindow( |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1784 | SiteInstance* source_site_instance, |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1785 | int32_t route_id, |
| 1786 | int32_t main_frame_route_id, |
| 1787 | int32_t main_frame_widget_route_id, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 1788 | const ViewHostMsg_CreateWindow_Params& params, |
| 1789 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1790 | // We usually create the new window in the same BrowsingInstance (group of |
| 1791 | // script-related windows), by passing in the current SiteInstance. However, |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1792 | // if the opener is being suppressed (in a non-guest), we create a new |
| 1793 | // SiteInstance in its own BrowsingInstance. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 1794 | bool is_guest = BrowserPluginGuest::IsGuest(this); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1795 | |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 1796 | if (is_guest && BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 1797 | // TODO(lazyboy): CreateNewWindow doesn't work for OOPIF-based <webview> |
| 1798 | // yet. |
| 1799 | NOTREACHED(); |
| 1800 | } |
| 1801 | |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 1802 | // If the opener is to be suppressed, the new window can be in any process. |
| 1803 | // Since routing ids are process specific, we must not have one passed in |
| 1804 | // as argument here. |
| 1805 | DCHECK(!params.opener_suppressed || route_id == MSG_ROUTING_NONE); |
| 1806 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1807 | scoped_refptr<SiteInstance> site_instance = |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1808 | params.opener_suppressed && !is_guest |
| 1809 | ? SiteInstance::CreateForURL(GetBrowserContext(), params.target_url) |
| 1810 | : source_site_instance; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1811 | |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1812 | // A message to create a new window can only come from a process for a frame |
| 1813 | // in this WebContents' FrameTree. If any other process sends the request, it |
| 1814 | // is invalid and the process must be terminated. |
| 1815 | int render_process_id = source_site_instance->GetProcess()->GetID(); |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1816 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1817 | RenderProcessHost* rph = source_site_instance->GetProcess(); |
jaekyun | 37e572a3 | 2014-12-04 23:33:35 | [diff] [blame] | 1818 | base::ProcessHandle process_handle = rph->GetHandle(); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 1819 | if (process_handle != base::kNullProcessHandle) { |
| 1820 | RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 1821 | base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWindow")); |
jaekyun | 37e572a3 | 2014-12-04 23:33:35 | [diff] [blame] | 1822 | rph->Shutdown(RESULT_CODE_KILLED, false); |
[email protected] | 04cbd3d | 2013-12-04 04:58:20 | [diff] [blame] | 1823 | } |
| 1824 | return; |
| 1825 | } |
| 1826 | |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1827 | // We must assign the SessionStorageNamespace before calling Init(). |
[email protected] | 4c3a2358 | 2012-08-18 08:54:34 | [diff] [blame] | 1828 | // |
| 1829 | // http://crbug.com/142685 |
[email protected] | fdac6ade | 2013-07-20 01:06:30 | [diff] [blame] | 1830 | const std::string& partition_id = |
| 1831 | GetContentClient()->browser()-> |
| 1832 | GetStoragePartitionIdForSite(GetBrowserContext(), |
| 1833 | site_instance->GetSiteURL()); |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1834 | StoragePartition* partition = BrowserContext::GetStoragePartition( |
| 1835 | GetBrowserContext(), site_instance.get()); |
[email protected] | 5f2aa72 | 2013-08-07 16:59:41 | [diff] [blame] | 1836 | DOMStorageContextWrapper* dom_storage_context = |
| 1837 | static_cast<DOMStorageContextWrapper*>(partition->GetDOMStorageContext()); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1838 | SessionStorageNamespaceImpl* session_storage_namespace_impl = |
| 1839 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace); |
| 1840 | CHECK(session_storage_namespace_impl->IsFromContext(dom_storage_context)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 1841 | |
| 1842 | if (delegate_ && |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1843 | !delegate_->ShouldCreateWebContents( |
| 1844 | this, route_id, main_frame_route_id, main_frame_widget_route_id, |
| 1845 | params.window_container_type, params.frame_name, params.target_url, |
| 1846 | partition_id, session_storage_namespace)) { |
[email protected] | f1cd336 | 2014-01-07 20:43:01 | [diff] [blame] | 1847 | if (route_id != MSG_ROUTING_NONE && |
| 1848 | !RenderViewHost::FromID(render_process_id, route_id)) { |
| 1849 | // If the embedder didn't create a WebContents for this route, we need to |
| 1850 | // delete the RenderView that had already been created. |
| 1851 | Send(new ViewMsg_Close(route_id)); |
| 1852 | } |
csharrison | a2280cd | 2016-02-03 23:21:15 | [diff] [blame] | 1853 | // It's safe to only target the frame because the render process will not |
| 1854 | // have a chance to create more frames at this point. |
| 1855 | ResourceDispatcherHostImpl::ResumeBlockedRequestsForRouteFromUI( |
| 1856 | GlobalFrameRoutingId(render_process_id, main_frame_route_id)); |
[email protected] | dd673041 | 2013-08-14 15:03:37 | [diff] [blame] | 1857 | return; |
| 1858 | } |
| 1859 | |
| 1860 | // Create the new web contents. This will automatically create the new |
| 1861 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 1862 | CreateParams create_params(GetBrowserContext(), site_instance.get()); |
[email protected] | 54944cde | 2012-12-09 09:24:59 | [diff] [blame] | 1863 | create_params.routing_id = route_id; |
[email protected] | 227692c5 | 2013-05-31 22:43:04 | [diff] [blame] | 1864 | create_params.main_frame_routing_id = main_frame_route_id; |
dcheng | 3ce04b6 | 2015-10-26 23:30:55 | [diff] [blame] | 1865 | create_params.main_frame_widget_routing_id = main_frame_widget_route_id; |
nasko | 48321ca3 | 2015-07-02 20:44:12 | [diff] [blame] | 1866 | create_params.main_frame_name = params.frame_name; |
alexmos | 4cf2aa3 | 2015-07-15 23:40:43 | [diff] [blame] | 1867 | create_params.opener_render_process_id = render_process_id; |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 1868 | create_params.opener_render_frame_id = params.opener_render_frame_id; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 1869 | create_params.opener_suppressed = params.opener_suppressed; |
| 1870 | if (params.disposition == NEW_BACKGROUND_TAB) |
| 1871 | create_params.initially_hidden = true; |
lfg | 269b702f | 2015-06-08 19:28:19 | [diff] [blame] | 1872 | create_params.renderer_initiated_creation = |
| 1873 | main_frame_route_id != MSG_ROUTING_NONE; |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 1874 | |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 1875 | WebContentsImpl* new_contents = NULL; |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1876 | if (!is_guest) { |
| 1877 | create_params.context = view_->GetNativeView(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1878 | create_params.initial_size = GetContainerBounds().size(); |
[email protected] | 4858e43 | 2014-06-23 18:14:17 | [diff] [blame] | 1879 | new_contents = static_cast<WebContentsImpl*>( |
| 1880 | WebContents::Create(create_params)); |
| 1881 | } else { |
| 1882 | new_contents = GetBrowserPluginGuest()->CreateNewGuestWindow(create_params); |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1883 | } |
[email protected] | 50d326e | 2014-05-20 17:59:06 | [diff] [blame] | 1884 | new_contents->GetController().SetSessionStorageNamespace( |
| 1885 | partition_id, |
| 1886 | session_storage_namespace); |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 1887 | |
alexmos | 646fec0 | 2015-07-25 00:11:49 | [diff] [blame] | 1888 | // If the new frame has a name, make sure any SiteInstances that can find |
| 1889 | // this named frame have proxies for it. Must be called after |
| 1890 | // SetSessionStorageNamespace, since this calls CreateRenderView, which uses |
| 1891 | // GetSessionStorageNamespace. |
| 1892 | if (!params.frame_name.empty()) |
| 1893 | new_contents->GetRenderManager()->CreateProxiesForNewNamedFrame(); |
| 1894 | |
[email protected] | c453807 | 2013-03-18 02:17:55 | [diff] [blame] | 1895 | // 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] | 1896 | // will be shown immediately). |
| 1897 | if (!params.opener_suppressed) { |
| 1898 | if (!is_guest) { |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 1899 | WebContentsView* new_view = new_contents->view_.get(); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1900 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 1901 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 1902 | // newly created object and give it one of its own member variables. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 1903 | new_view->CreateViewForWidget( |
| 1904 | new_contents->GetRenderViewHost()->GetWidget(), false); |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 1905 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1906 | // Save the created window associated with the route so we can show it |
| 1907 | // later. |
| 1908 | DCHECK_NE(MSG_ROUTING_NONE, route_id); |
| 1909 | pending_contents_[route_id] = new_contents; |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 1910 | AddDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1911 | } |
| 1912 | |
| 1913 | if (delegate_) { |
| 1914 | delegate_->WebContentsCreated( |
[email protected] | a7531d77 | 2014-03-25 16:15:07 | [diff] [blame] | 1915 | this, params.opener_render_frame_id, params.frame_name, |
[email protected] | 50de322 | 2013-03-20 15:36:13 | [diff] [blame] | 1916 | params.target_url, new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1917 | } |
| 1918 | |
| 1919 | if (params.opener_suppressed) { |
| 1920 | // When the opener is suppressed, the original renderer cannot access the |
| 1921 | // 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] | 1922 | bool was_blocked = false; |
| 1923 | if (delegate_) { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 1924 | gfx::Rect initial_rect; |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1925 | delegate_->AddNewContents( |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 1926 | this, new_contents, params.disposition, initial_rect, |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1927 | params.user_gesture, &was_blocked); |
| 1928 | } |
| 1929 | if (!was_blocked) { |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1930 | OpenURLParams open_params(params.target_url, |
| 1931 | Referrer(), |
| 1932 | CURRENT_TAB, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 1933 | ui::PAGE_TRANSITION_LINK, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 1934 | true /* is_renderer_initiated */); |
[email protected] | e7f2e7c | 2013-07-15 09:41:30 | [diff] [blame] | 1935 | open_params.user_gesture = params.user_gesture; |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 1936 | |
| 1937 | if (delegate_ && !is_guest && |
| 1938 | !delegate_->ShouldResumeRequestsForCreatedWindow()) { |
| 1939 | // We are in asynchronous add new contents path, delay opening url |
| 1940 | new_contents->delayed_open_url_params_.reset( |
| 1941 | new OpenURLParams(open_params)); |
| 1942 | } else { |
| 1943 | new_contents->OpenURL(open_params); |
| 1944 | } |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 1945 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1946 | } |
| 1947 | } |
| 1948 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1949 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 1950 | int32_t route_id, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1951 | blink::WebPopupType popup_type) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 1952 | CreateNewWidget(render_process_id, route_id, false, popup_type); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1953 | } |
| 1954 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1955 | void WebContentsImpl::CreateNewFullscreenWidget(int32_t render_process_id, |
| 1956 | int32_t route_id) { |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 1957 | CreateNewWidget(render_process_id, route_id, true, blink::WebPopupTypeNone); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1958 | } |
| 1959 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 1960 | void WebContentsImpl::CreateNewWidget(int32_t render_process_id, |
| 1961 | int32_t route_id, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1962 | bool is_fullscreen, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 1963 | blink::WebPopupType popup_type) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame^] | 1964 | RenderProcessHost* process = RenderProcessHost::FromID(render_process_id); |
kenrb | b46f86a | 2015-12-07 07:53:23 | [diff] [blame] | 1965 | // 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] | 1966 | // this WebContentsImpl instance. If any other process sends the request, |
| 1967 | // it is invalid and the process must be terminated. |
dcheng | 57e39e2 | 2016-01-21 00:25:38 | [diff] [blame] | 1968 | if (!HasMatchingProcess(&frame_tree_, render_process_id)) { |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame^] | 1969 | base::ProcessHandle process_handle = process->GetHandle(); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 1970 | if (process_handle != base::kNullProcessHandle) { |
| 1971 | RecordAction( |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 1972 | base::UserMetricsAction("Terminate_ProcessMismatch_CreateNewWidget")); |
kenrb | a26d1509 | 2016-02-10 22:00:25 | [diff] [blame^] | 1973 | process->Shutdown(RESULT_CODE_KILLED, false); |
[email protected] | a850402 | 2013-12-04 20:23:51 | [diff] [blame] | 1974 | } |
| 1975 | return; |
| 1976 | } |
| 1977 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1978 | RenderWidgetHostImpl* widget_host = |
piman | 5d36dae | 2015-09-24 22:47:05 | [diff] [blame] | 1979 | new RenderWidgetHostImpl(this, process, route_id, IsHidden()); |
[email protected] | b24b68a | 2012-09-24 21:57:26 | [diff] [blame] | 1980 | |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 1981 | RenderWidgetHostViewBase* widget_view = |
| 1982 | static_cast<RenderWidgetHostViewBase*>( |
| 1983 | view_->CreateViewForPopupWidget(widget_host)); |
[email protected] | 83918ec | 2013-01-10 15:37:19 | [diff] [blame] | 1984 | if (!widget_view) |
| 1985 | return; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1986 | if (!is_fullscreen) { |
| 1987 | // Popups should not get activated. |
| 1988 | widget_view->SetPopupType(popup_type); |
| 1989 | } |
| 1990 | // Save the created widget associated with the route so we can show it later. |
| 1991 | pending_widget_views_[route_id] = widget_view; |
| 1992 | |
| 1993 | #if defined(OS_MACOSX) |
| 1994 | // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it |
| 1995 | // to allow it to survive the trip without being hosted. |
| 1996 | base::mac::NSObjectRetain(widget_view->GetNativeView()); |
| 1997 | #endif |
| 1998 | } |
| 1999 | |
| 2000 | void WebContentsImpl::ShowCreatedWindow(int route_id, |
| 2001 | WindowOpenDisposition disposition, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2002 | const gfx::Rect& initial_rect, |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2003 | bool user_gesture) { |
| 2004 | WebContentsImpl* contents = GetCreatedWindow(route_id); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2005 | if (contents) { |
| 2006 | WebContentsDelegate* delegate = GetDelegate(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 2007 | contents->is_resume_pending_ = true; |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2008 | if (!delegate || delegate->ShouldResumeRequestsForCreatedWindow()) |
| 2009 | contents->ResumeLoadingCreatedWebContents(); |
| 2010 | |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2011 | if (delegate) { |
| 2012 | delegate->AddNewContents( |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2013 | this, contents, disposition, initial_rect, user_gesture, NULL); |
[email protected] | eda238a1 | 2012-09-07 23:44:00 | [diff] [blame] | 2014 | } |
| 2015 | } |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | void WebContentsImpl::ShowCreatedWidget(int route_id, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2019 | const gfx::Rect& initial_rect) { |
| 2020 | ShowCreatedWidget(route_id, false, initial_rect); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) { |
| 2024 | ShowCreatedWidget(route_id, true, gfx::Rect()); |
| 2025 | } |
| 2026 | |
| 2027 | void WebContentsImpl::ShowCreatedWidget(int route_id, |
| 2028 | bool is_fullscreen, |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2029 | const gfx::Rect& initial_rect) { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2030 | RenderWidgetHostViewBase* widget_host_view = |
| 2031 | static_cast<RenderWidgetHostViewBase*>(GetCreatedWidget(route_id)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2032 | if (!widget_host_view) |
| 2033 | return; |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2034 | |
| 2035 | RenderWidgetHostView* view = NULL; |
| 2036 | BrowserPluginGuest* guest = GetBrowserPluginGuest(); |
| 2037 | if (guest && guest->embedder_web_contents()) { |
| 2038 | view = guest->embedder_web_contents()->GetRenderWidgetHostView(); |
| 2039 | } else { |
| 2040 | view = GetRenderWidgetHostView(); |
| 2041 | } |
| 2042 | |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2043 | if (is_fullscreen) { |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2044 | DCHECK_EQ(MSG_ROUTING_NONE, fullscreen_widget_routing_id_); |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2045 | view_->StoreFocus(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2046 | fullscreen_widget_routing_id_ = route_id; |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2047 | if (delegate_ && delegate_->EmbedsFullscreenWidget()) { |
| 2048 | widget_host_view->InitAsChild(GetRenderWidgetHostView()->GetNativeView()); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2049 | delegate_->EnterFullscreenModeForTab(this, GURL()); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2050 | } else { |
[email protected] | cfd80b0 | 2014-05-01 17:46:48 | [diff] [blame] | 2051 | widget_host_view->InitAsFullscreen(view); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2052 | } |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2053 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 2054 | observers_, |
| 2055 | DidShowFullscreenWidget(route_id)); |
| 2056 | if (!widget_host_view->HasFocus()) |
| 2057 | widget_host_view->Focus(); |
| 2058 | } else { |
bokan | 107a47f | 2015-02-03 23:23:39 | [diff] [blame] | 2059 | widget_host_view->InitAsPopup(view, initial_rect); |
[email protected] | 4aebbca | 2013-09-17 22:26:49 | [diff] [blame] | 2060 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 2061 | |
| 2062 | RenderWidgetHostImpl* render_widget_host_impl = |
| 2063 | RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost()); |
| 2064 | render_widget_host_impl->Init(); |
[email protected] | d7f80ba | 2013-10-12 07:42:31 | [diff] [blame] | 2065 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 2066 | // used to implement Pepper Flash fullscreen. |
| 2067 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2068 | |
| 2069 | #if defined(OS_MACOSX) |
| 2070 | // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's |
| 2071 | // properly embedded (or purposefully ignored) we can release the retain we |
| 2072 | // took in CreateNewWidget(). |
| 2073 | base::mac::NSObjectRelease(widget_host_view->GetNativeView()); |
| 2074 | #endif |
| 2075 | } |
| 2076 | |
| 2077 | WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) { |
| 2078 | PendingContents::iterator iter = pending_contents_.find(route_id); |
| 2079 | |
| 2080 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 2081 | // in creating one, just return NULL. |
| 2082 | if (iter == pending_contents_.end()) { |
| 2083 | return NULL; |
| 2084 | } |
| 2085 | |
| 2086 | WebContentsImpl* new_contents = iter->second; |
| 2087 | pending_contents_.erase(route_id); |
[email protected] | 7fff43e | 2013-05-21 20:21:10 | [diff] [blame] | 2088 | RemoveDestructionObserver(new_contents); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2089 | |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2090 | // Don't initialize the guest WebContents immediately. |
[email protected] | a24efc2 | 2014-05-26 15:50:25 | [diff] [blame] | 2091 | if (BrowserPluginGuest::IsGuest(new_contents)) |
[email protected] | d70bea9 | 2013-04-05 04:23:34 | [diff] [blame] | 2092 | return new_contents; |
| 2093 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2094 | if (!new_contents->GetRenderProcessHost()->HasConnection() || |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2095 | !new_contents->GetRenderViewHost()->GetWidget()->GetView()) |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2096 | return NULL; |
| 2097 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 2098 | return new_contents; |
| 2099 | } |
| 2100 | |
| 2101 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { |
| 2102 | PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); |
| 2103 | if (iter == pending_widget_views_.end()) { |
| 2104 | DCHECK(false); |
| 2105 | return NULL; |
| 2106 | } |
| 2107 | |
| 2108 | RenderWidgetHostView* widget_host_view = iter->second; |
| 2109 | pending_widget_views_.erase(route_id); |
| 2110 | |
| 2111 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
| 2112 | if (!widget_host->GetProcess()->HasConnection()) { |
| 2113 | // The view has gone away or the renderer crashed. Nothing to do. |
| 2114 | return NULL; |
| 2115 | } |
| 2116 | |
| 2117 | return widget_host_view; |
| 2118 | } |
| 2119 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2120 | void WebContentsImpl::RequestMediaAccessPermission( |
[email protected] | 33662e5 | 2013-01-07 21:31:09 | [diff] [blame] | 2121 | const MediaStreamRequest& request, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2122 | const MediaResponseCallback& callback) { |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2123 | if (delegate_) { |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2124 | delegate_->RequestMediaAccessPermission(this, request, callback); |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2125 | } else { |
| 2126 | callback.Run(MediaStreamDevices(), |
grunell | e544e13 | 2014-09-25 22:30:04 | [diff] [blame] | 2127 | MEDIA_DEVICE_FAILED_DUE_TO_SHUTDOWN, |
[email protected] | d19b84b | 2014-03-14 11:52:37 | [diff] [blame] | 2128 | scoped_ptr<MediaStreamUI>()); |
| 2129 | } |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame] | 2130 | } |
| 2131 | |
grunell | 657d4d8 | 2014-09-18 00:09:43 | [diff] [blame] | 2132 | bool WebContentsImpl::CheckMediaAccessPermission(const GURL& security_origin, |
| 2133 | MediaStreamType type) { |
| 2134 | DCHECK(type == MEDIA_DEVICE_AUDIO_CAPTURE || |
| 2135 | type == MEDIA_DEVICE_VIDEO_CAPTURE); |
| 2136 | return delegate_ && |
| 2137 | delegate_->CheckMediaAccessPermission(this, security_origin, type); |
| 2138 | } |
| 2139 | |
[email protected] | cc920043 | 2013-07-23 23:02:40 | [diff] [blame] | 2140 | SessionStorageNamespace* WebContentsImpl::GetSessionStorageNamespace( |
| 2141 | SiteInstance* instance) { |
| 2142 | return controller_.GetSessionStorageNamespace(instance); |
| 2143 | } |
| 2144 | |
[email protected] | 6de7fc48 | 2014-06-06 10:46:44 | [diff] [blame] | 2145 | SessionStorageNamespaceMap WebContentsImpl::GetSessionStorageNamespaceMap() { |
| 2146 | return controller_.GetSessionStorageNamespaceMap(); |
| 2147 | } |
| 2148 | |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 2149 | FrameTree* WebContentsImpl::GetFrameTree() { |
| 2150 | return &frame_tree_; |
| 2151 | } |
| 2152 | |
luken | dc35e7f | 2014-11-10 19:06:14 | [diff] [blame] | 2153 | void WebContentsImpl::SetIsVirtualKeyboardRequested(bool requested) { |
| 2154 | virtual_keyboard_requested_ = requested; |
| 2155 | } |
| 2156 | |
| 2157 | bool WebContentsImpl::IsVirtualKeyboardRequested() { |
| 2158 | return virtual_keyboard_requested_; |
| 2159 | } |
| 2160 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2161 | AccessibilityMode WebContentsImpl::GetAccessibilityMode() const { |
| 2162 | return accessibility_mode_; |
| 2163 | } |
| 2164 | |
[email protected] | 31a71eaf | 2014-03-13 01:47:36 | [diff] [blame] | 2165 | void WebContentsImpl::AccessibilityEventReceived( |
| 2166 | const std::vector<AXEventNotificationDetails>& details) { |
| 2167 | FOR_EACH_OBSERVER( |
| 2168 | WebContentsObserver, observers_, AccessibilityEventReceived(details)); |
| 2169 | } |
| 2170 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2171 | RenderFrameHost* WebContentsImpl::GetGuestByInstanceID( |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 2172 | RenderFrameHost* render_frame_host, |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2173 | int browser_plugin_instance_id) { |
| 2174 | BrowserPluginGuestManager* guest_manager = |
| 2175 | GetBrowserContext()->GetGuestManager(); |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2176 | if (!guest_manager) |
| 2177 | return nullptr; |
| 2178 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2179 | WebContents* guest = guest_manager->GetGuestByInstanceID( |
fsamuel | 2e9413d | 2015-02-25 01:25:44 | [diff] [blame] | 2180 | render_frame_host->GetProcess()->GetID(), browser_plugin_instance_id); |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2181 | if (!guest) |
fsamuel | 9cbc00a | 2015-04-17 20:30:20 | [diff] [blame] | 2182 | return nullptr; |
| 2183 | |
dmazzoni | a656928e | 2014-09-15 20:28:54 | [diff] [blame] | 2184 | return guest->GetMainFrame(); |
| 2185 | } |
| 2186 | |
blundell | c57b93f | 2014-10-29 13:19:57 | [diff] [blame] | 2187 | GeolocationServiceContext* WebContentsImpl::GetGeolocationServiceContext() { |
| 2188 | return geolocation_service_context_.get(); |
| 2189 | } |
| 2190 | |
alogvinov | f50445a | 2015-10-30 13:00:12 | [diff] [blame] | 2191 | WakeLockServiceContext* WebContentsImpl::GetWakeLockServiceContext() { |
| 2192 | return wake_lock_service_context_.get(); |
| 2193 | } |
| 2194 | |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2195 | void WebContentsImpl::OnShowValidationMessage( |
| 2196 | const gfx::Rect& anchor_in_root_view, |
[email protected] | 6ff9c8f | 2013-12-20 09:05:29 | [diff] [blame] | 2197 | const base::string16& main_text, |
| 2198 | const base::string16& sub_text) { |
[email protected] | edc3af8 | 2013-12-12 21:24:07 | [diff] [blame] | 2199 | if (delegate_) |
| 2200 | delegate_->ShowValidationMessage( |
| 2201 | this, anchor_in_root_view, main_text, sub_text); |
| 2202 | } |
| 2203 | |
| 2204 | void WebContentsImpl::OnHideValidationMessage() { |
| 2205 | if (delegate_) |
| 2206 | delegate_->HideValidationMessage(this); |
| 2207 | } |
| 2208 | |
| 2209 | void WebContentsImpl::OnMoveValidationMessage( |
| 2210 | const gfx::Rect& anchor_in_root_view) { |
| 2211 | if (delegate_) |
| 2212 | delegate_->MoveValidationMessage(this, anchor_in_root_view); |
| 2213 | } |
| 2214 | |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 2215 | void WebContentsImpl::DidSendScreenRects(RenderWidgetHostImpl* rwh) { |
| 2216 | if (browser_plugin_embedder_) |
[email protected] | a7568e6 | 2013-06-14 07:50:44 | [diff] [blame] | 2217 | browser_plugin_embedder_->DidSendScreenRects(); |
[email protected] | 32deec6 | 2013-05-15 23:55:04 | [diff] [blame] | 2218 | } |
| 2219 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2220 | BrowserAccessibilityManager* |
| 2221 | WebContentsImpl::GetRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2222 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2223 | return rfh ? rfh->browser_accessibility_manager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | BrowserAccessibilityManager* |
| 2227 | WebContentsImpl::GetOrCreateRootBrowserAccessibilityManager() { |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2228 | RenderFrameHostImpl* rfh = GetMainFrame(); |
| 2229 | return rfh ? rfh->GetOrCreateBrowserAccessibilityManager() : nullptr; |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 2230 | } |
| 2231 | |
mohsen | 7ab1ec16ec | 2015-07-02 18:26:23 | [diff] [blame] | 2232 | void WebContentsImpl::MoveRangeSelectionExtent(const gfx::Point& extent) { |
| 2233 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2234 | if (!focused_frame) |
| 2235 | return; |
| 2236 | |
| 2237 | focused_frame->Send(new InputMsg_MoveRangeSelectionExtent( |
| 2238 | focused_frame->GetRoutingID(), extent)); |
| 2239 | } |
| 2240 | |
| 2241 | void WebContentsImpl::SelectRange(const gfx::Point& base, |
| 2242 | const gfx::Point& extent) { |
| 2243 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2244 | if (!focused_frame) |
| 2245 | return; |
| 2246 | |
| 2247 | focused_frame->Send( |
| 2248 | new InputMsg_SelectRange(focused_frame->GetRoutingID(), base, extent)); |
| 2249 | } |
| 2250 | |
aurimas | ab031902 | 2015-07-10 21:57:38 | [diff] [blame] | 2251 | void WebContentsImpl::AdjustSelectionByCharacterOffset(int start_adjust, |
| 2252 | int end_adjust) { |
| 2253 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2254 | if (!focused_frame) |
| 2255 | return; |
| 2256 | |
| 2257 | focused_frame->Send(new InputMsg_AdjustSelectionByCharacterOffset( |
| 2258 | focused_frame->GetRoutingID(), start_adjust, end_adjust)); |
| 2259 | } |
| 2260 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2261 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2262 | const gfx::Size old_size = GetPreferredSize(); |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 2263 | preferred_size_ = pref_size; |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2264 | OnPreferredSizeChanged(old_size); |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 2265 | } |
| 2266 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2267 | void WebContentsImpl::ResizeDueToAutoResize( |
| 2268 | RenderWidgetHostImpl* render_widget_host, |
| 2269 | const gfx::Size& new_size) { |
| 2270 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 2271 | return; |
| 2272 | |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 2273 | if (delegate_) |
| 2274 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 2275 | } |
| 2276 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2277 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2278 | if (!delegate_) |
| 2279 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 2280 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2281 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2282 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 2283 | } |
| 2284 | |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 2285 | bool WebContentsImpl::Send(IPC::Message* message) { |
| 2286 | if (!GetRenderViewHost()) { |
| 2287 | delete message; |
| 2288 | return false; |
| 2289 | } |
| 2290 | |
| 2291 | return GetRenderViewHost()->Send(message); |
| 2292 | } |
| 2293 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 2294 | void WebContentsImpl::RenderFrameForInterstitialPageCreated( |
| 2295 | RenderFrameHost* render_frame_host) { |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 2296 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 2297 | RenderFrameForInterstitialPageCreated(render_frame_host)); |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 2298 | } |
| 2299 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2300 | void WebContentsImpl::AttachInterstitialPage( |
| 2301 | InterstitialPageImpl* interstitial_page) { |
| 2302 | DCHECK(interstitial_page); |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2303 | GetRenderManager()->set_interstitial_page(interstitial_page); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2304 | |
| 2305 | // Cancel any visible dialogs so that they don't interfere with the |
| 2306 | // interstitial. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 2307 | CancelActiveAndPendingDialogs(); |
[email protected] | 90fb08ed | 2013-09-24 17:43:29 | [diff] [blame] | 2308 | |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2309 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2310 | DidAttachInterstitialPage()); |
| 2311 | } |
| 2312 | |
| 2313 | void WebContentsImpl::DetachInterstitialPage() { |
[email protected] | 6832c8bc | 2014-04-29 07:20:57 | [diff] [blame] | 2314 | if (ShowingInterstitialPage()) |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2315 | GetRenderManager()->remove_interstitial_page(); |
[email protected] | 20ca038 | 2013-02-28 19:50:07 | [diff] [blame] | 2316 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2317 | DidDetachInterstitialPage()); |
| 2318 | } |
| 2319 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 2320 | void WebContentsImpl::SetHistoryOffsetAndLength(int history_offset, |
| 2321 | int history_length) { |
| 2322 | SetHistoryOffsetAndLengthForView( |
| 2323 | GetRenderViewHost(), history_offset, history_length); |
| 2324 | } |
| 2325 | |
| 2326 | void WebContentsImpl::SetHistoryOffsetAndLengthForView( |
| 2327 | RenderViewHost* render_view_host, |
| 2328 | int history_offset, |
| 2329 | int history_length) { |
| 2330 | render_view_host->Send(new ViewMsg_SetHistoryOffsetAndLength( |
| 2331 | render_view_host->GetRoutingID(), history_offset, history_length)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 2332 | } |
| 2333 | |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 2334 | void WebContentsImpl::ReloadFocusedFrame(bool ignore_cache) { |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2335 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2336 | if (!focused_frame) |
| 2337 | return; |
| 2338 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2339 | focused_frame->Send(new FrameMsg_Reload( |
| 2340 | focused_frame->GetRoutingID(), ignore_cache)); |
| 2341 | } |
| 2342 | |
megjablon | 3f594107 | 2016-02-04 23:27:52 | [diff] [blame] | 2343 | void WebContentsImpl::ReloadLoFiImages() { |
| 2344 | SendToAllFrames(new FrameMsg_ReloadLoFiImages(MSG_ROUTING_NONE)); |
| 2345 | } |
| 2346 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2347 | void WebContentsImpl::Undo() { |
| 2348 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2349 | if (!focused_frame) |
| 2350 | return; |
| 2351 | |
| 2352 | focused_frame->Send(new InputMsg_Undo(focused_frame->GetRoutingID())); |
| 2353 | RecordAction(base::UserMetricsAction("Undo")); |
| 2354 | } |
| 2355 | |
| 2356 | void WebContentsImpl::Redo() { |
| 2357 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2358 | if (!focused_frame) |
| 2359 | return; |
| 2360 | focused_frame->Send(new InputMsg_Redo(focused_frame->GetRoutingID())); |
| 2361 | RecordAction(base::UserMetricsAction("Redo")); |
| 2362 | } |
| 2363 | |
| 2364 | void WebContentsImpl::Cut() { |
| 2365 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2366 | if (!focused_frame) |
| 2367 | return; |
| 2368 | |
| 2369 | focused_frame->Send(new InputMsg_Cut(focused_frame->GetRoutingID())); |
| 2370 | RecordAction(base::UserMetricsAction("Cut")); |
| 2371 | } |
| 2372 | |
| 2373 | void WebContentsImpl::Copy() { |
| 2374 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2375 | if (!focused_frame) |
| 2376 | return; |
| 2377 | |
| 2378 | focused_frame->Send(new InputMsg_Copy(focused_frame->GetRoutingID())); |
| 2379 | RecordAction(base::UserMetricsAction("Copy")); |
| 2380 | } |
| 2381 | |
| 2382 | void WebContentsImpl::CopyToFindPboard() { |
| 2383 | #if defined(OS_MACOSX) |
| 2384 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2385 | if (!focused_frame) |
| 2386 | return; |
| 2387 | |
| 2388 | // Windows/Linux don't have the concept of a find pasteboard. |
| 2389 | focused_frame->Send( |
| 2390 | new InputMsg_CopyToFindPboard(focused_frame->GetRoutingID())); |
| 2391 | RecordAction(base::UserMetricsAction("CopyToFindPboard")); |
| 2392 | #endif |
| 2393 | } |
| 2394 | |
| 2395 | void WebContentsImpl::Paste() { |
| 2396 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2397 | if (!focused_frame) |
| 2398 | return; |
| 2399 | |
| 2400 | focused_frame->Send(new InputMsg_Paste(focused_frame->GetRoutingID())); |
| 2401 | RecordAction(base::UserMetricsAction("Paste")); |
| 2402 | } |
| 2403 | |
| 2404 | void WebContentsImpl::PasteAndMatchStyle() { |
| 2405 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2406 | if (!focused_frame) |
| 2407 | return; |
| 2408 | |
| 2409 | focused_frame->Send(new InputMsg_PasteAndMatchStyle( |
| 2410 | focused_frame->GetRoutingID())); |
| 2411 | RecordAction(base::UserMetricsAction("PasteAndMatchStyle")); |
| 2412 | } |
| 2413 | |
| 2414 | void WebContentsImpl::Delete() { |
| 2415 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2416 | if (!focused_frame) |
| 2417 | return; |
| 2418 | |
| 2419 | focused_frame->Send(new InputMsg_Delete(focused_frame->GetRoutingID())); |
| 2420 | RecordAction(base::UserMetricsAction("DeleteSelection")); |
| 2421 | } |
| 2422 | |
| 2423 | void WebContentsImpl::SelectAll() { |
| 2424 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2425 | if (!focused_frame) |
| 2426 | return; |
| 2427 | |
| 2428 | focused_frame->Send(new InputMsg_SelectAll(focused_frame->GetRoutingID())); |
| 2429 | RecordAction(base::UserMetricsAction("SelectAll")); |
| 2430 | } |
| 2431 | |
| 2432 | void WebContentsImpl::Unselect() { |
| 2433 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2434 | if (!focused_frame) |
| 2435 | return; |
| 2436 | |
| 2437 | focused_frame->Send(new InputMsg_Unselect(focused_frame->GetRoutingID())); |
| 2438 | RecordAction(base::UserMetricsAction("Unselect")); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2439 | } |
| 2440 | |
| 2441 | void WebContentsImpl::Replace(const base::string16& word) { |
| 2442 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2443 | if (!focused_frame) |
| 2444 | return; |
| 2445 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2446 | focused_frame->Send(new InputMsg_Replace( |
| 2447 | focused_frame->GetRoutingID(), word)); |
[email protected] | 1f3fc1d | 2014-04-03 14:50:17 | [diff] [blame] | 2448 | } |
| 2449 | |
| 2450 | void WebContentsImpl::ReplaceMisspelling(const base::string16& word) { |
| 2451 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2452 | if (!focused_frame) |
| 2453 | return; |
| 2454 | |
[email protected] | 959be4c | 2014-04-08 15:01:33 | [diff] [blame] | 2455 | focused_frame->Send(new InputMsg_ReplaceMisspelling( |
| 2456 | focused_frame->GetRoutingID(), word)); |
| 2457 | } |
| 2458 | |
| 2459 | void WebContentsImpl::NotifyContextMenuClosed( |
| 2460 | const CustomContextMenuContext& context) { |
| 2461 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2462 | if (!focused_frame) |
| 2463 | return; |
| 2464 | |
| 2465 | focused_frame->Send(new FrameMsg_ContextMenuClosed( |
| 2466 | focused_frame->GetRoutingID(), context)); |
| 2467 | } |
| 2468 | |
| 2469 | void WebContentsImpl::ExecuteCustomContextMenuCommand( |
| 2470 | int action, const CustomContextMenuContext& context) { |
| 2471 | RenderFrameHost* focused_frame = GetFocusedFrame(); |
| 2472 | if (!focused_frame) |
| 2473 | return; |
| 2474 | |
| 2475 | focused_frame->Send(new FrameMsg_CustomContextMenuAction( |
| 2476 | focused_frame->GetRoutingID(), context, action)); |
[email protected] | 4fed370 | 2014-04-01 09:08:00 | [diff] [blame] | 2477 | } |
| 2478 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2479 | gfx::NativeView WebContentsImpl::GetNativeView() { |
| 2480 | return view_->GetNativeView(); |
| 2481 | } |
| 2482 | |
| 2483 | gfx::NativeView WebContentsImpl::GetContentNativeView() { |
| 2484 | return view_->GetContentNativeView(); |
| 2485 | } |
| 2486 | |
| 2487 | gfx::NativeWindow WebContentsImpl::GetTopLevelNativeWindow() { |
| 2488 | return view_->GetTopLevelNativeWindow(); |
| 2489 | } |
| 2490 | |
| 2491 | gfx::Rect WebContentsImpl::GetViewBounds() { |
| 2492 | return view_->GetViewBounds(); |
| 2493 | } |
| 2494 | |
| 2495 | gfx::Rect WebContentsImpl::GetContainerBounds() { |
| 2496 | gfx::Rect rv; |
| 2497 | view_->GetContainerBounds(&rv); |
| 2498 | return rv; |
| 2499 | } |
| 2500 | |
| 2501 | DropData* WebContentsImpl::GetDropData() { |
| 2502 | return view_->GetDropData(); |
| 2503 | } |
| 2504 | |
| 2505 | void WebContentsImpl::Focus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2506 | view_->Focus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2507 | } |
| 2508 | |
| 2509 | void WebContentsImpl::SetInitialFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2510 | view_->SetInitialFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2511 | } |
| 2512 | |
| 2513 | void WebContentsImpl::StoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2514 | view_->StoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2515 | } |
| 2516 | |
| 2517 | void WebContentsImpl::RestoreFocus() { |
miu | 9e14e49 | 2014-10-25 02:39:04 | [diff] [blame] | 2518 | view_->RestoreFocus(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 2519 | } |
| 2520 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2521 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2522 | if (ShowingInterstitialPage()) { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2523 | GetRenderManager()->interstitial_page()->FocusThroughTabTraversal(reverse); |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 2524 | return; |
| 2525 | } |
[email protected] | 0b43199 | 2014-06-24 00:08:03 | [diff] [blame] | 2526 | RenderWidgetHostView* const fullscreen_view = |
| 2527 | GetFullscreenRenderWidgetHostView(); |
| 2528 | if (fullscreen_view) { |
| 2529 | fullscreen_view->Focus(); |
| 2530 | return; |
| 2531 | } |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2532 | GetRenderViewHost()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2533 | } |
| 2534 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2535 | bool WebContentsImpl::ShowingInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2536 | return GetRenderManager()->interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2537 | } |
| 2538 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2539 | InterstitialPage* WebContentsImpl::GetInterstitialPage() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 2540 | return GetRenderManager()->interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 2541 | } |
| 2542 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2543 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2544 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 2545 | // so we also support this MIME type. |
| 2546 | return contents_mime_type_ == "text/html" || |
| 2547 | contents_mime_type_ == "text/xml" || |
| 2548 | contents_mime_type_ == "application/xhtml+xml" || |
| 2549 | contents_mime_type_ == "text/plain" || |
| 2550 | contents_mime_type_ == "text/css" || |
rsleevi | c327b48f8 | 2015-04-30 02:03:25 | [diff] [blame] | 2551 | mime_util::IsSupportedJavascriptMimeType(contents_mime_type_); |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2552 | } |
| 2553 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2554 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2555 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 2556 | if (!IsSavable()) { |
[email protected] | 3586962 | 2012-10-26 23:23:55 | [diff] [blame] | 2557 | RecordDownloadSource(INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML); |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2558 | SaveFrame(GetLastCommittedURL(), Referrer()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2559 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2560 | } |
| 2561 | |
| 2562 | Stop(); |
| 2563 | |
| 2564 | // Create the save package and possibly prompt the user for the name to save |
| 2565 | // the page as. The user prompt is an asynchronous operation that runs on |
| 2566 | // another thread. |
| 2567 | save_package_ = new SavePackage(this); |
| 2568 | save_package_->GetSaveInfo(); |
| 2569 | } |
| 2570 | |
| 2571 | // Used in automated testing to bypass prompting the user for file names. |
| 2572 | // Instead, the names and paths are hard coded rather than running them through |
| 2573 | // file name sanitation and extension / mime checking. |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 2574 | bool WebContentsImpl::SavePage(const base::FilePath& main_file, |
| 2575 | const base::FilePath& dir_path, |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2576 | SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2577 | // Stop the page from navigating. |
| 2578 | Stop(); |
| 2579 | |
| 2580 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2581 | return save_package_->Init(SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 2582 | } |
| 2583 | |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2584 | void WebContentsImpl::SaveFrame(const GURL& url, |
| 2585 | const Referrer& referrer) { |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2586 | SaveFrameWithHeaders(url, referrer, std::string()); |
| 2587 | } |
| 2588 | |
| 2589 | void WebContentsImpl::SaveFrameWithHeaders(const GURL& url, |
| 2590 | const Referrer& referrer, |
| 2591 | const std::string& headers) { |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2592 | if (!GetLastCommittedURL().is_valid()) |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2593 | return; |
sammc | 92af6155 | 2014-11-19 23:27:40 | [diff] [blame] | 2594 | if (delegate_ && delegate_->SaveFrame(url, referrer)) |
| 2595 | return; |
| 2596 | |
nasko | 89ad774 | 2015-03-05 22:14:19 | [diff] [blame] | 2597 | // TODO(nasko): This check for main frame is incorrect and should be fixed |
| 2598 | // by explicitly passing in which frame this method should target. |
| 2599 | bool is_main_frame = (url == GetLastCommittedURL()); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2600 | |
| 2601 | DownloadManager* dlm = |
| 2602 | BrowserContext::GetDownloadManager(GetBrowserContext()); |
| 2603 | if (!dlm) |
| 2604 | return; |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2605 | int64_t post_id = -1; |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2606 | if (is_main_frame) { |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 2607 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2608 | if (entry) |
| 2609 | post_id = entry->GetPostID(); |
| 2610 | } |
| 2611 | scoped_ptr<DownloadUrlParameters> params( |
| 2612 | DownloadUrlParameters::FromWebContents(this, url)); |
| 2613 | params->set_referrer(referrer); |
| 2614 | params->set_post_id(post_id); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2615 | if (post_id >= 0) |
| 2616 | params->set_method("POST"); |
| 2617 | params->set_prompt(true); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2618 | |
| 2619 | if (headers.empty()) { |
| 2620 | params->set_prefer_cache(true); |
| 2621 | } else { |
brettw | 26dab8f0 | 2015-08-08 00:28:47 | [diff] [blame] | 2622 | for (const base::StringPiece& key_value : |
| 2623 | base::SplitStringPiece( |
| 2624 | headers, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 2625 | std::vector<std::string> pair = base::SplitString( |
| 2626 | key_value, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
kundaji | 6c7f969 | 2015-03-09 18:00:37 | [diff] [blame] | 2627 | DCHECK_EQ(2ul, pair.size()); |
| 2628 | params->add_request_header(pair[0], pair[1]); |
| 2629 | } |
| 2630 | } |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 2631 | dlm->DownloadUrl(std::move(params)); |
[email protected] | 3c71576ce | 2013-07-23 02:00:01 | [diff] [blame] | 2632 | } |
| 2633 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2634 | void WebContentsImpl::GenerateMHTML( |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 2635 | const base::FilePath& file, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 2636 | const base::Callback<void(int64_t)>& callback) { |
[email protected] | 18516cf9 | 2013-08-28 18:19:48 | [diff] [blame] | 2637 | MHTMLGenerationManager::GetInstance()->SaveMHTML(this, file, callback); |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 2638 | } |
| 2639 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2640 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2641 | return contents_mime_type_; |
| 2642 | } |
| 2643 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2644 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2645 | return notify_disconnection_; |
| 2646 | } |
| 2647 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2648 | void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2649 | SetEncoding(encoding); |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 2650 | Send(new ViewMsg_SetPageEncoding(GetRoutingID(), encoding)); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 2651 | } |
| 2652 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2653 | void WebContentsImpl::ResetOverrideEncoding() { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 2654 | canonical_encoding_.clear(); |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 2655 | Send(new ViewMsg_ResetPageEncodingToDefault(GetRoutingID())); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 2656 | } |
| 2657 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 2658 | RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2659 | return &renderer_preferences_; |
| 2660 | } |
| 2661 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2662 | void WebContentsImpl::Close() { |
| 2663 | Close(GetRenderViewHost()); |
| 2664 | } |
| 2665 | |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2666 | void WebContentsImpl::DragSourceEndedAt(int client_x, int client_y, |
[email protected] | 180ef24 | 2013-11-07 06:50:46 | [diff] [blame] | 2667 | int screen_x, int screen_y, blink::WebDragOperation operation) { |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2668 | if (browser_plugin_embedder_.get()) |
| 2669 | browser_plugin_embedder_->DragSourceEndedAt(client_x, client_y, |
| 2670 | screen_x, screen_y, operation); |
| 2671 | if (GetRenderViewHost()) |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2672 | GetRenderViewHost()->DragSourceEndedAt(client_x, client_y, screen_x, |
| 2673 | screen_y, operation); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2674 | } |
| 2675 | |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2676 | void WebContentsImpl::DidGetResourceResponseStart( |
| 2677 | const ResourceRequestDetails& details) { |
| 2678 | controller_.ssl_manager()->DidStartResourceResponse(details); |
| 2679 | |
| 2680 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2681 | DidGetResourceResponseStart(details)); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2682 | } |
| 2683 | |
| 2684 | void WebContentsImpl::DidGetRedirectForResourceRequest( |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 2685 | RenderFrameHost* render_frame_host, |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2686 | const ResourceRedirectDetails& details) { |
| 2687 | controller_.ssl_manager()->DidReceiveResourceRedirect(details); |
| 2688 | |
| 2689 | FOR_EACH_OBSERVER( |
| 2690 | WebContentsObserver, |
| 2691 | observers_, |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 2692 | DidGetRedirectForResourceRequest(render_frame_host, details)); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2693 | |
| 2694 | // TODO(avi): Remove. http://crbug.com/170921 |
| 2695 | NotificationService::current()->Notify( |
| 2696 | NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 2697 | Source<WebContents>(this), |
| 2698 | Details<const ResourceRedirectDetails>(&details)); |
[email protected] | d60f370 | 2013-12-26 16:30:24 | [diff] [blame] | 2699 | } |
| 2700 | |
calamity | 7fe55ce | 2015-04-10 03:59:37 | [diff] [blame] | 2701 | void WebContentsImpl::NotifyWebContentsFocused() { |
| 2702 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, OnWebContentsFocused()); |
| 2703 | } |
| 2704 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2705 | void WebContentsImpl::SystemDragEnded() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2706 | if (GetRenderViewHost()) |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2707 | GetRenderViewHost()->DragSourceSystemDragEnded(); |
[email protected] | cf200a56 | 2013-05-03 16:24:29 | [diff] [blame] | 2708 | if (browser_plugin_embedder_.get()) |
| 2709 | browser_plugin_embedder_->SystemDragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 2710 | } |
| 2711 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2712 | void WebContentsImpl::UserGestureDone() { |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 2713 | OnUserGesture(GetRenderViewHost()->GetWidget()); |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 2714 | } |
| 2715 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2716 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2717 | closed_by_user_gesture_ = value; |
| 2718 | } |
| 2719 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2720 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2721 | return closed_by_user_gesture_; |
| 2722 | } |
| 2723 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2724 | void WebContentsImpl::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 2725 | if (!delegate_) |
| 2726 | return; |
| 2727 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 2728 | NavigationEntry* entry = GetController().GetLastCommittedEntry(); |
| 2729 | if (!entry) |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 2730 | return; |
| 2731 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 2732 | delegate_->ViewSourceForTab(this, entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 2733 | } |
| 2734 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2735 | void WebContentsImpl::ViewFrameSource(const GURL& url, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2736 | const PageState& page_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 2737 | if (!delegate_) |
| 2738 | return; |
| 2739 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 2740 | delegate_->ViewSourceForFrame(this, url, page_state); |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 2741 | } |
| 2742 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2743 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2744 | return minimum_zoom_percent_; |
| 2745 | } |
| 2746 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2747 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2748 | return maximum_zoom_percent_; |
| 2749 | } |
| 2750 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 2751 | void WebContentsImpl::SetPageScale(float page_scale_factor) { |
| 2752 | Send(new ViewMsg_SetPageScale(GetRoutingID(), page_scale_factor)); |
ccameron | b7c1d6c | 2015-03-09 17:08:24 | [diff] [blame] | 2753 | } |
| 2754 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2755 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 2756 | return capturer_count_ == 0 ? preferred_size_ : preferred_size_for_capture_; |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 2757 | } |
| 2758 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2759 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
[email protected] | 660f18e | 2014-05-15 20:53:05 | [diff] [blame] | 2760 | if (GetBrowserPluginGuest()) |
| 2761 | return GetBrowserPluginGuest()->LockMouse(allowed); |
| 2762 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2763 | return GetRenderViewHost() |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2764 | ? GetRenderViewHost()->GetWidget()->GotResponseToLockMouseRequest( |
| 2765 | allowed) |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 2766 | : false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2767 | } |
| 2768 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2769 | bool WebContentsImpl::HasOpener() const { |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 2770 | return GetOpener() != NULL; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 2771 | } |
| 2772 | |
alexmos | e201c7cd | 2015-06-10 17:14:21 | [diff] [blame] | 2773 | WebContentsImpl* WebContentsImpl::GetOpener() const { |
| 2774 | FrameTreeNode* opener_ftn = frame_tree_.root()->opener(); |
| 2775 | return opener_ftn ? FromFrameTreeNode(opener_ftn) : nullptr; |
jochen | 55ff350 | 2014-12-18 20:52:57 | [diff] [blame] | 2776 | } |
| 2777 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 2778 | void WebContentsImpl::DidChooseColorInColorChooser(SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 2779 | if (!color_chooser_info_.get()) |
| 2780 | return; |
| 2781 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 2782 | color_chooser_info_->render_process_id, |
| 2783 | color_chooser_info_->render_frame_id); |
| 2784 | if (!rfh) |
| 2785 | return; |
| 2786 | |
| 2787 | rfh->Send(new FrameMsg_DidChooseColorResponse( |
| 2788 | rfh->GetRoutingID(), color_chooser_info_->identifier, color)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2789 | } |
| 2790 | |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 2791 | void WebContentsImpl::DidEndColorChooser() { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 2792 | if (!color_chooser_info_.get()) |
| 2793 | return; |
| 2794 | RenderFrameHost* rfh = RenderFrameHost::FromID( |
| 2795 | color_chooser_info_->render_process_id, |
| 2796 | color_chooser_info_->render_frame_id); |
| 2797 | if (!rfh) |
| 2798 | return; |
| 2799 | |
| 2800 | rfh->Send(new FrameMsg_DidEndColorChooser( |
| 2801 | rfh->GetRoutingID(), color_chooser_info_->identifier)); |
| 2802 | color_chooser_info_.reset(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2803 | } |
| 2804 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 2805 | int WebContentsImpl::DownloadImage( |
| 2806 | const GURL& url, |
| 2807 | bool is_favicon, |
| 2808 | uint32_t max_bitmap_size, |
| 2809 | bool bypass_cache, |
| 2810 | const WebContents::ImageDownloadCallback& callback) { |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 2811 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 2812 | static int next_image_download_id = 0; |
| 2813 | const image_downloader::ImageDownloaderPtr& mojo_image_downloader = |
| 2814 | GetMainFrame()->GetMojoImageDownloader(); |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 2815 | const int download_id = ++next_image_download_id; |
| 2816 | if (!mojo_image_downloader) { |
| 2817 | // If the renderer process is dead (i.e. crash, or memory pressure on |
| 2818 | // Android), the downloader service will be invalid. Pre-Mojo, this would |
| 2819 | // hang the callback indefinetly since the IPC would be dropped. Now, |
| 2820 | // respond with a 400 HTTP error code to indicate that something went wrong. |
| 2821 | BrowserThread::PostTask( |
| 2822 | BrowserThread::UI, FROM_HERE, |
| 2823 | base::Bind(&WebContents::ImageDownloadCallback::Run, |
| 2824 | base::Owned(new ImageDownloadCallback(callback)), |
| 2825 | download_id, 400, url, std::vector<SkBitmap>(), |
| 2826 | std::vector<gfx::Size>())); |
| 2827 | return download_id; |
| 2828 | } |
| 2829 | |
halton.huo | ca2eabd | 2015-07-06 08:17:40 | [diff] [blame] | 2830 | image_downloader::DownloadRequestPtr req = |
| 2831 | image_downloader::DownloadRequest::New(); |
| 2832 | |
| 2833 | req->url = mojo::String::From(url); |
| 2834 | req->is_favicon = is_favicon; |
| 2835 | req->max_bitmap_size = max_bitmap_size; |
| 2836 | req->bypass_cache = bypass_cache; |
| 2837 | |
| 2838 | mojo_image_downloader->DownloadImage( |
dcheng | 36b6aec9 | 2015-12-26 06:16:36 | [diff] [blame] | 2839 | std::move(req), |
amistry | 9f01b77 | 2015-07-29 01:54:55 | [diff] [blame] | 2840 | base::Bind(&DidDownloadImage, callback, download_id, url)); |
| 2841 | return download_id; |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 2842 | } |
| 2843 | |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 2844 | bool WebContentsImpl::IsSubframe() const { |
| 2845 | return is_subframe_; |
| 2846 | } |
| 2847 | |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 2848 | void WebContentsImpl::Find(int request_id, |
| 2849 | const base::string16& search_text, |
| 2850 | const blink::WebFindOptions& options) { |
thestig | 6057a6b2 | 2015-11-12 23:01:33 | [diff] [blame] | 2851 | // Cowardly refuse to search for no text. |
| 2852 | if (search_text.empty()) { |
| 2853 | NOTREACHED(); |
| 2854 | return; |
| 2855 | } |
| 2856 | |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 2857 | // See if a top level browser plugin handles the find request first. |
paulmeyer | 95703b9 | 2015-08-10 17:38:47 | [diff] [blame] | 2858 | if (browser_plugin_embedder_ && |
| 2859 | browser_plugin_embedder_->Find(request_id, search_text, options)) { |
| 2860 | return; |
raymes | 0fa0be5 | 2014-10-13 20:38:09 | [diff] [blame] | 2861 | } |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 2862 | GetMainFrame()->Send(new FrameMsg_Find(GetMainFrame()->GetRoutingID(), |
| 2863 | request_id, search_text, options)); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | void WebContentsImpl::StopFinding(StopFindAction action) { |
raymes | 2bc6418 | 2015-02-06 01:23:01 | [diff] [blame] | 2867 | // See if a top level browser plugin handles the stop finding request first. |
paulmeyer | 95703b9 | 2015-08-10 17:38:47 | [diff] [blame] | 2868 | if (browser_plugin_embedder_ && |
| 2869 | browser_plugin_embedder_->StopFinding(action)) { |
| 2870 | return; |
raymes | 2bc6418 | 2015-02-06 01:23:01 | [diff] [blame] | 2871 | } |
paulmeyer | 5d0a5f0 | 2016-01-21 20:15:52 | [diff] [blame] | 2872 | GetMainFrame()->Send( |
| 2873 | new FrameMsg_StopFinding(GetMainFrame()->GetRoutingID(), action)); |
[email protected] | 36ec24f | 2014-01-09 00:32:08 | [diff] [blame] | 2874 | } |
| 2875 | |
[email protected] | 4fe53add | 2014-04-08 19:53:36 | [diff] [blame] | 2876 | void WebContentsImpl::InsertCSS(const std::string& css) { |
| 2877 | GetMainFrame()->Send(new FrameMsg_CSSInsertRequest( |
| 2878 | GetMainFrame()->GetRoutingID(), css)); |
| 2879 | } |
| 2880 | |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 2881 | bool WebContentsImpl::WasRecentlyAudible() { |
avayvod | cc85bbd | 2015-08-28 19:11:15 | [diff] [blame] | 2882 | return audio_stream_monitor_.WasRecentlyAudible(); |
dalecurtis | bc6572e1 | 2014-09-12 19:22:30 | [diff] [blame] | 2883 | } |
| 2884 | |
mlamouri | efdca9d | 2014-09-16 16:55:40 | [diff] [blame] | 2885 | void WebContentsImpl::GetManifest(const GetManifestCallback& callback) { |
| 2886 | manifest_manager_host_->GetManifest(GetMainFrame(), callback); |
| 2887 | } |
| 2888 | |
dominickn | 6919ce3 | 2015-10-15 01:52:28 | [diff] [blame] | 2889 | void WebContentsImpl::HasManifest(const HasManifestCallback& callback) { |
| 2890 | manifest_manager_host_->HasManifest(GetMainFrame(), callback); |
| 2891 | } |
| 2892 | |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2893 | void WebContentsImpl::ExitFullscreen(bool will_cause_resize) { |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2894 | // Clean up related state and initiate the fullscreen exit. |
avi | 3627ecac | 2015-10-16 17:40:43 | [diff] [blame] | 2895 | GetRenderViewHost()->GetWidget()->RejectMouseLockOrUnlockIfNecessary(); |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 2896 | ExitFullscreenMode(will_cause_resize); |
mlamouri | 7a78d6fd | 2015-01-17 13:23:53 | [diff] [blame] | 2897 | } |
| 2898 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2899 | void WebContentsImpl::ResumeLoadingCreatedWebContents() { |
mariakhomenko | a4971c1 | 2015-07-21 19:04:37 | [diff] [blame] | 2900 | if (delayed_open_url_params_.get()) { |
| 2901 | OpenURL(*delayed_open_url_params_.get()); |
| 2902 | delayed_open_url_params_.reset(nullptr); |
| 2903 | return; |
| 2904 | } |
| 2905 | |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2906 | // Resume blocked requests for both the RenderViewHost and RenderFrameHost. |
| 2907 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 2908 | if (is_resume_pending_) { |
| 2909 | is_resume_pending_ = false; |
avi | 0f1bbc971 | 2015-11-17 02:58:13 | [diff] [blame] | 2910 | GetRenderViewHost()->GetWidget()->Init(); |
dfalcantara | e6b7b4675 | 2015-07-10 18:14:16 | [diff] [blame] | 2911 | GetMainFrame()->Init(); |
| 2912 | } |
mariakhomenko | 44bdc473 | 2015-04-29 01:55:38 | [diff] [blame] | 2913 | } |
| 2914 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2915 | bool WebContentsImpl::FocusLocationBarByDefault() { |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 2916 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
[email protected] | 8e09c7af | 2014-06-10 11:46:17 | [diff] [blame] | 2917 | if (entry && entry->GetURL() == GURL(url::kAboutBlankURL)) |
[email protected] | 0c940663 | 2013-02-08 01:13:33 | [diff] [blame] | 2918 | return true; |
| 2919 | return delegate_ && delegate_->ShouldFocusLocationBarByDefault(this); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2920 | } |
| 2921 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2922 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2923 | if (delegate_) |
| 2924 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 2925 | } |
| 2926 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 2927 | void WebContentsImpl::DidStartNavigation(NavigationHandle* navigation_handle) { |
| 2928 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2929 | DidStartNavigation(navigation_handle)); |
| 2930 | } |
| 2931 | |
| 2932 | void WebContentsImpl::DidRedirectNavigation( |
| 2933 | NavigationHandle* navigation_handle) { |
| 2934 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2935 | DidRedirectNavigation(navigation_handle)); |
| 2936 | } |
| 2937 | |
clamy | efca29e | 2015-09-17 00:22:11 | [diff] [blame] | 2938 | void WebContentsImpl::ReadyToCommitNavigation( |
| 2939 | NavigationHandle* navigation_handle) { |
| 2940 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2941 | ReadyToCommitNavigation(navigation_handle)); |
| 2942 | } |
| 2943 | |
clamy | 0e11988 | 2015-07-31 16:12:33 | [diff] [blame] | 2944 | void WebContentsImpl::DidFinishNavigation(NavigationHandle* navigation_handle) { |
| 2945 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2946 | DidFinishNavigation(navigation_handle)); |
| 2947 | } |
| 2948 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 2949 | void WebContentsImpl::DidStartProvisionalLoad( |
| 2950 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 2951 | const GURL& validated_url, |
| 2952 | bool is_error_page, |
| 2953 | bool is_iframe_srcdoc) { |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 2954 | // Notify observers about the start of the provisional load. |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 2955 | FOR_EACH_OBSERVER( |
| 2956 | WebContentsObserver, |
| 2957 | observers_, |
| 2958 | DidStartProvisionalLoadForFrame( |
| 2959 | render_frame_host, validated_url, is_error_page, is_iframe_srcdoc)); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 2960 | |
| 2961 | // Notify accessibility if this is a reload. |
| 2962 | NavigationEntry* entry = controller_.GetVisibleEntry(); |
| 2963 | if (entry && ui::PageTransitionCoreTypeIs( |
| 2964 | entry->GetTransitionType(), ui::PAGE_TRANSITION_RELOAD)) { |
| 2965 | FrameTreeNode* ftn = render_frame_host->frame_tree_node(); |
| 2966 | BrowserAccessibilityManager* manager = |
| 2967 | ftn->current_frame_host()->browser_accessibility_manager(); |
| 2968 | if (manager) |
| 2969 | manager->UserIsReloading(); |
| 2970 | } |
[email protected] | 400992b | 2012-06-14 00:03:54 | [diff] [blame] | 2971 | } |
| 2972 | |
[email protected] | 3109fbb7 | 2014-01-06 23:57:15 | [diff] [blame] | 2973 | void WebContentsImpl::DidFailProvisionalLoadWithError( |
| 2974 | RenderFrameHostImpl* render_frame_host, |
| 2975 | const FrameHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
| 2976 | GURL validated_url(params.url); |
[email protected] | 860234a | 2014-07-01 00:35:31 | [diff] [blame] | 2977 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 2978 | observers_, |
| 2979 | DidFailProvisionalLoad(render_frame_host, |
[email protected] | 860234a | 2014-07-01 00:35:31 | [diff] [blame] | 2980 | validated_url, |
| 2981 | params.error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 2982 | params.error_description, |
| 2983 | params.was_ignored_by_handler)); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 2984 | |
| 2985 | FrameTreeNode* ftn = render_frame_host->frame_tree_node(); |
| 2986 | BrowserAccessibilityManager* manager = |
| 2987 | ftn->current_frame_host()->browser_accessibility_manager(); |
| 2988 | if (manager) |
| 2989 | manager->NavigationFailed(); |
[email protected] | 3109fbb7 | 2014-01-06 23:57:15 | [diff] [blame] | 2990 | } |
| 2991 | |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 2992 | void WebContentsImpl::DidFailLoadWithError( |
| 2993 | RenderFrameHostImpl* render_frame_host, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 2994 | const GURL& url, |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 2995 | int error_code, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 2996 | const base::string16& error_description, |
| 2997 | bool was_ignored_by_handler) { |
[email protected] | 3619ca8 | 2014-07-09 15:45:14 | [diff] [blame] | 2998 | FOR_EACH_OBSERVER( |
| 2999 | WebContentsObserver, |
| 3000 | observers_, |
gsennton | 6fbb3869 | 2015-06-24 19:23:55 | [diff] [blame] | 3001 | DidFailLoad(render_frame_host, url, error_code, error_description, |
| 3002 | was_ignored_by_handler)); |
[email protected] | b80624c | 2014-02-09 02:46:55 | [diff] [blame] | 3003 | } |
| 3004 | |
[email protected] | 5291380 | 2013-12-10 05:52:18 | [diff] [blame] | 3005 | void WebContentsImpl::NotifyChangedNavigationState( |
| 3006 | InvalidateTypes changed_flags) { |
| 3007 | NotifyNavigationStateChanged(changed_flags); |
| 3008 | } |
| 3009 | |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3010 | void WebContentsImpl::DidStartNavigationToPendingEntry( |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 3011 | const GURL& url, |
| 3012 | NavigationController::ReloadType reload_type) { |
| 3013 | // Notify observers about navigation. |
| 3014 | FOR_EACH_OBSERVER( |
| 3015 | WebContentsObserver, |
| 3016 | observers_, |
| 3017 | DidStartNavigationToPendingEntry(url, reload_type)); |
| 3018 | } |
| 3019 | |
[email protected] | 8cb834e | 2014-03-06 14:23:23 | [diff] [blame] | 3020 | void WebContentsImpl::RequestOpenURL(RenderFrameHostImpl* render_frame_host, |
| 3021 | const OpenURLParams& params) { |
dcheng | b907f733 | 2015-01-07 20:35:50 | [diff] [blame] | 3022 | // OpenURL can blow away the source RFH. Use the process/frame routing ID as a |
| 3023 | // weak pointer of sorts. |
| 3024 | const int32_t process_id = render_frame_host->GetProcess()->GetID(); |
| 3025 | const int32_t frame_id = render_frame_host->GetRoutingID(); |
| 3026 | |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3027 | WebContents* new_contents = OpenURL(params); |
| 3028 | |
dcheng | b907f733 | 2015-01-07 20:35:50 | [diff] [blame] | 3029 | if (new_contents && RenderFrameHost::FromID(process_id, frame_id)) { |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3030 | // Notify observers. |
| 3031 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3032 | DidOpenRequestedURL(new_contents, |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 3033 | render_frame_host, |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3034 | params.url, |
| 3035 | params.referrer, |
| 3036 | params.disposition, |
creis | 114ca1b | 2014-11-13 23:51:46 | [diff] [blame] | 3037 | params.transition)); |
[email protected] | 65920f33 | 2014-03-04 21:14:18 | [diff] [blame] | 3038 | } |
| 3039 | } |
| 3040 | |
creis | 2946027 | 2015-12-16 04:38:22 | [diff] [blame] | 3041 | bool WebContentsImpl::ShouldTransferNavigation() { |
| 3042 | if (!delegate_) |
| 3043 | return true; |
| 3044 | return delegate_->ShouldTransferNavigation(); |
| 3045 | } |
| 3046 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3047 | bool WebContentsImpl::ShouldPreserveAbortedURLs() { |
| 3048 | if (!delegate_) |
| 3049 | return false; |
| 3050 | return delegate_->ShouldPreserveAbortedURLs(this); |
| 3051 | } |
| 3052 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3053 | void WebContentsImpl::DidCommitProvisionalLoad( |
[email protected] | 27dd82fd | 2014-03-03 22:11:43 | [diff] [blame] | 3054 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3055 | const GURL& url, |
Sylvain Defresne | c6ccc77d | 2014-09-19 10:19:35 | [diff] [blame] | 3056 | ui::PageTransition transition_type) { |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3057 | // Notify observers about the commit of the provisional load. |
[email protected] | e2d2d420 | 2014-07-03 12:17:48 | [diff] [blame] | 3058 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 3059 | observers_, |
| 3060 | DidCommitProvisionalLoadForFrame( |
| 3061 | render_frame_host, url, transition_type)); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 3062 | |
| 3063 | BrowserAccessibilityManager* manager = |
| 3064 | render_frame_host->browser_accessibility_manager(); |
| 3065 | if (manager) |
| 3066 | manager->NavigationSucceeded(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3067 | } |
| 3068 | |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3069 | void WebContentsImpl::DidNavigateMainFramePreCommit( |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3070 | bool navigation_is_within_page) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3071 | // Ensure fullscreen mode is exited before committing the navigation to a |
| 3072 | // different page. The next page will not start out assuming it is in |
| 3073 | // fullscreen mode. |
[email protected] | 5cfbddc | 2014-06-23 23:52:23 | [diff] [blame] | 3074 | if (navigation_is_within_page) { |
[email protected] | dfc39cb | 2014-04-09 22:58:19 | [diff] [blame] | 3075 | // No page change? Then, the renderer and browser can remain in fullscreen. |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3076 | return; |
| 3077 | } |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 3078 | if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3079 | ExitFullscreen(false); |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 3080 | DCHECK(!IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())); |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 3081 | } |
| 3082 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3083 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3084 | RenderFrameHostImpl* render_frame_host, |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3085 | const LoadCommittedDetails& details, |
| 3086 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
| 3087 | if (details.is_navigation_to_different_page()) { |
| 3088 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 3089 | // doesn't let us know that the cursor left an element during a |
| 3090 | // transition (this is also why the mouse cursor remains as a hand after |
| 3091 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 3092 | // clear the bubble when a user navigates to a named anchor in the same |
| 3093 | // page. |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 3094 | UpdateTargetURL(render_frame_host->GetRenderViewHost(), GURL()); |
lanwei | 9d343ad2 | 2015-02-11 01:46:00 | [diff] [blame] | 3095 | |
| 3096 | RenderWidgetHostViewBase* rwhvb = |
| 3097 | static_cast<RenderWidgetHostViewBase*>(GetRenderWidgetHostView()); |
| 3098 | if (rwhvb) |
| 3099 | rwhvb->OnDidNavigateMainFrameToNewPage(); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3100 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3101 | did_first_visually_non_empty_paint_ = false; |
| 3102 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3103 | // Reset theme color on navigation to new page. |
| 3104 | theme_color_ = SK_ColorTRANSPARENT; |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3105 | } |
| 3106 | |
| 3107 | if (!details.is_in_page) { |
| 3108 | // Once the main frame is navigated, we're no longer considered to have |
| 3109 | // displayed insecure content. |
| 3110 | displayed_insecure_content_ = false; |
| 3111 | SSLManager::NotifySSLInternalStateChanged( |
| 3112 | GetController().GetBrowserContext()); |
| 3113 | } |
| 3114 | |
| 3115 | // Notify observers about navigation. |
| 3116 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3117 | DidNavigateMainFrame(details, params)); |
| 3118 | |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3119 | if (delegate_) |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3120 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3121 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3122 | } |
| 3123 | |
| 3124 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
| 3125 | RenderFrameHostImpl* render_frame_host, |
| 3126 | const LoadCommittedDetails& details, |
| 3127 | const FrameHostMsg_DidCommitProvisionalLoad_Params& params) { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 3128 | // Now that something has committed, we don't need to track whether the |
| 3129 | // initial page has been accessed. |
| 3130 | has_accessed_initial_document_ = false; |
| 3131 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3132 | // If we navigate off the page, close all JavaScript dialogs. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 3133 | if (!details.is_in_page) |
| 3134 | CancelActiveAndPendingDialogs(); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3135 | |
| 3136 | // Notify observers about navigation. |
| 3137 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
mlamouri | 2d2fd2f | 2014-10-08 16:00:09 | [diff] [blame] | 3138 | DidNavigateAnyFrame(render_frame_host, details, params)); |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3139 | } |
| 3140 | |
| 3141 | void WebContentsImpl::SetMainFrameMimeType(const std::string& mime_type) { |
| 3142 | contents_mime_type_ = mime_type; |
| 3143 | } |
| 3144 | |
[email protected] | 277857a | 2014-06-03 10:38:01 | [diff] [blame] | 3145 | bool WebContentsImpl::CanOverscrollContent() const { |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3146 | // Disable overscroll when touch emulation is on. See crbug.com/369938. |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 3147 | if (force_disable_overscroll_content_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3148 | return false; |
| 3149 | |
[email protected] | 37567b43 | 2014-02-12 01:12:22 | [diff] [blame] | 3150 | if (delegate_) |
| 3151 | return delegate_->CanOverscrollContent(); |
| 3152 | |
| 3153 | return false; |
| 3154 | } |
| 3155 | |
[email protected] | 37b64c5 | 2014-07-11 21:14:05 | [diff] [blame] | 3156 | void WebContentsImpl::OnThemeColorChanged(SkColor theme_color) { |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3157 | // Update the theme color. This is to be published to observers after the |
| 3158 | // first visually non-empty paint. |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3159 | theme_color_ = theme_color; |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3160 | |
| 3161 | if (did_first_visually_non_empty_paint_ && |
| 3162 | last_sent_theme_color_ != theme_color_) { |
| 3163 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3164 | DidChangeThemeColor(theme_color_)); |
| 3165 | last_sent_theme_color_ = theme_color_; |
| 3166 | } |
[email protected] | e710476 | 2014-06-20 19:17:25 | [diff] [blame] | 3167 | } |
| 3168 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3169 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3170 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 3171 | const std::string& security_info, |
| 3172 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 3173 | const std::string& mime_type, |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 3174 | ResourceType resource_type) { |
estark | a5635c4 | 2015-07-14 00:06:53 | [diff] [blame] | 3175 | SSLStatus status; |
| 3176 | if (!DeserializeSecurityInfo(security_info, &status)) { |
| 3177 | bad_message::ReceivedBadMessage( |
| 3178 | GetRenderProcessHost(), |
| 3179 | bad_message::WC_MEMORY_CACHE_RESOURCE_BAD_SECURITY_INFO); |
| 3180 | return; |
| 3181 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3182 | |
| 3183 | // Send out a notification that we loaded a resource from our memory cache. |
avi | e0d9018 | 2015-07-08 19:33:59 | [diff] [blame] | 3184 | // TODO(alcutter,eranm): Pass signed_certificate_timestamp_ids into details. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3185 | LoadFromMemoryCacheDetails details( |
rob | 1ca070f | 2016-01-12 01:06:26 | [diff] [blame] | 3186 | url, status.cert_id, status.cert_status, http_method, mime_type, |
| 3187 | resource_type); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3188 | |
[email protected] | b0f724c | 2013-09-05 04:21:13 | [diff] [blame] | 3189 | controller_.ssl_manager()->DidLoadFromMemoryCache(details); |
| 3190 | |
| 3191 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3192 | DidLoadResourceFromMemoryCache(details)); |
| 3193 | |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3194 | if (url.is_valid() && url.SchemeIsHTTPOrHTTPS()) { |
| 3195 | scoped_refptr<net::URLRequestContextGetter> request_context( |
[email protected] | 6c1e0521 | 2014-07-31 00:59:40 | [diff] [blame] | 3196 | resource_type == RESOURCE_TYPE_MEDIA ? |
[email protected] | 8bfc827 | 2013-09-09 20:10:53 | [diff] [blame] | 3197 | GetBrowserContext()->GetMediaRequestContextForRenderProcess( |
| 3198 | GetRenderProcessHost()->GetID()) : |
| 3199 | GetBrowserContext()->GetRequestContextForRenderProcess( |
| 3200 | GetRenderProcessHost()->GetID())); |
| 3201 | BrowserThread::PostTask( |
| 3202 | BrowserThread::IO, |
| 3203 | FROM_HERE, |
| 3204 | base::Bind(&NotifyCacheOnIO, request_context, url, http_method)); |
| 3205 | } |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3206 | } |
| 3207 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3208 | void WebContentsImpl::OnDidDisplayInsecureContent() { |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3209 | RecordAction(base::UserMetricsAction("SSL.DisplayedInsecureContent")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3210 | displayed_insecure_content_ = true; |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3211 | SSLManager::NotifySSLInternalStateChanged( |
| 3212 | GetController().GetBrowserContext()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3213 | } |
| 3214 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3215 | void WebContentsImpl::OnDidRunInsecureContent(const GURL& security_origin, |
| 3216 | const GURL& target_url) { |
[email protected] | 9450c46 | 2013-11-23 01:22:58 | [diff] [blame] | 3217 | LOG(WARNING) << security_origin << " ran insecure content from " |
| 3218 | << target_url.possibly_invalid_spec(); |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3219 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContent")); |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3220 | if (base::EndsWith(security_origin.spec(), kDotGoogleDotCom, |
brettw | a7ff1b29 | 2015-07-16 17:49:29 | [diff] [blame] | 3221 | base::CompareCase::INSENSITIVE_ASCII)) |
[email protected] | e6e30ac | 2014-01-13 21:24:39 | [diff] [blame] | 3222 | RecordAction(base::UserMetricsAction("SSL.RanInsecureContentGoogle")); |
[email protected] | 330614de | 2012-02-13 17:07:18 | [diff] [blame] | 3223 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3224 | SSLManager::NotifySSLInternalStateChanged( |
| 3225 | GetController().GetBrowserContext()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3226 | } |
| 3227 | |
estark | 910b457 | 2015-12-09 20:55:41 | [diff] [blame] | 3228 | void WebContentsImpl::OnDidDisplayContentWithCertificateErrors( |
| 3229 | const GURL& url, |
| 3230 | const std::string& security_info) { |
| 3231 | SSLStatus ssl; |
| 3232 | if (!DeserializeSecurityInfo(security_info, &ssl)) { |
| 3233 | bad_message::ReceivedBadMessage( |
| 3234 | GetRenderProcessHost(), |
| 3235 | bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO); |
| 3236 | return; |
| 3237 | } |
| 3238 | |
| 3239 | displayed_insecure_content_ = true; |
| 3240 | SSLManager::NotifySSLInternalStateChanged( |
| 3241 | GetController().GetBrowserContext()); |
| 3242 | } |
| 3243 | |
| 3244 | void WebContentsImpl::OnDidRunContentWithCertificateErrors( |
| 3245 | const GURL& security_origin, |
| 3246 | const GURL& url, |
| 3247 | const std::string& security_info) { |
| 3248 | SSLStatus ssl; |
| 3249 | if (!DeserializeSecurityInfo(security_info, &ssl)) { |
| 3250 | bad_message::ReceivedBadMessage( |
| 3251 | GetRenderProcessHost(), |
| 3252 | bad_message::WC_CONTENT_WITH_CERT_ERRORS_BAD_SECURITY_INFO); |
| 3253 | return; |
| 3254 | } |
| 3255 | |
| 3256 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
| 3257 | SSLManager::NotifySSLInternalStateChanged( |
| 3258 | GetController().GetBrowserContext()); |
| 3259 | } |
| 3260 | |
[email protected] | 501052ff | 2014-02-21 22:19:07 | [diff] [blame] | 3261 | void WebContentsImpl::OnDocumentLoadedInFrame() { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3262 | if (!HasValidFrameSource()) |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3263 | return; |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3264 | |
[email protected] | 1d62cf7 | 2014-02-07 21:31:57 | [diff] [blame] | 3265 | RenderFrameHostImpl* rfh = |
| 3266 | static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
[email protected] | 3619ca8 | 2014-07-09 15:45:14 | [diff] [blame] | 3267 | FOR_EACH_OBSERVER( |
| 3268 | WebContentsObserver, observers_, DocumentLoadedInFrame(rfh)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 3269 | } |
| 3270 | |
nasko | fbd03339 | 2015-01-27 02:34:47 | [diff] [blame] | 3271 | void WebContentsImpl::OnDidFinishLoad(const GURL& url) { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3272 | if (!HasValidFrameSource()) |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 3273 | return; |
[email protected] | a1b9926 | 2013-12-27 21:56:22 | [diff] [blame] | 3274 | |
[email protected] | 8b3af1e | 2014-01-24 13:29:12 | [diff] [blame] | 3275 | GURL validated_url(url); |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 3276 | RenderProcessHost* render_process_host = |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 3277 | render_frame_message_source_->GetProcess(); |
[email protected] | 5dcaf8e | 2013-12-28 01:31:42 | [diff] [blame] | 3278 | render_process_host->FilterURL(false, &validated_url); |
[email protected] | 028053d4 | 2014-03-05 22:20:37 | [diff] [blame] | 3279 | |
[email protected] | 61ac9e24 | 2014-03-21 20:55:26 | [diff] [blame] | 3280 | RenderFrameHostImpl* rfh = |
| 3281 | static_cast<RenderFrameHostImpl*>(render_frame_message_source_); |
[email protected] | 3619ca8 | 2014-07-09 15:45:14 | [diff] [blame] | 3282 | FOR_EACH_OBSERVER( |
| 3283 | WebContentsObserver, observers_, DidFinishLoad(rfh, validated_url)); |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 3284 | } |
| 3285 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3286 | void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
avi | 6ddfcae | 2015-06-30 15:50:57 | [diff] [blame] | 3287 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
| 3288 | controller_.GoToOffset(offset); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3289 | } |
| 3290 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3291 | void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
[email protected] | fce82322 | 2014-05-30 16:24:30 | [diff] [blame] | 3292 | int maximum_percent) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3293 | minimum_zoom_percent_ = minimum_percent; |
| 3294 | maximum_zoom_percent_ = maximum_percent; |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 3295 | } |
| 3296 | |
mcnee | 432e47d | 2015-11-09 19:37:46 | [diff] [blame] | 3297 | void WebContentsImpl::OnPageScaleFactorChanged(float page_scale_factor) { |
| 3298 | bool is_one = page_scale_factor == 1.f; |
| 3299 | if (is_one != page_scale_factor_is_one_) { |
| 3300 | page_scale_factor_is_one_ = is_one; |
| 3301 | |
| 3302 | HostZoomMapImpl* host_zoom_map = |
| 3303 | static_cast<HostZoomMapImpl*>(HostZoomMap::GetForWebContents(this)); |
| 3304 | |
| 3305 | if (host_zoom_map && GetRenderProcessHost()) { |
| 3306 | host_zoom_map->SetPageScaleFactorIsOneForView( |
| 3307 | GetRenderProcessHost()->GetID(), GetRoutingID(), |
| 3308 | page_scale_factor_is_one_); |
| 3309 | } |
| 3310 | } |
| 3311 | |
| 3312 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 3313 | observers_, |
| 3314 | OnPageScaleFactorChanged(page_scale_factor)); |
| 3315 | } |
| 3316 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3317 | void WebContentsImpl::OnEnumerateDirectory(int request_id, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3318 | const base::FilePath& path) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3319 | if (!delegate_) |
| 3320 | return; |
| 3321 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3322 | ChildProcessSecurityPolicyImpl* policy = |
| 3323 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 45d5c60 | 2013-10-07 18:33:22 | [diff] [blame] | 3324 | if (policy->CanReadFile(GetRenderProcessHost()->GetID(), path)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3325 | delegate_->EnumerateDirectory(this, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 3326 | } |
| 3327 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3328 | void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol, |
| 3329 | const GURL& url, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3330 | const base::string16& title, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 3331 | bool user_gesture) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3332 | if (!delegate_) |
| 3333 | return; |
| 3334 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3335 | ChildProcessSecurityPolicyImpl* policy = |
| 3336 | ChildProcessSecurityPolicyImpl::GetInstance(); |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3337 | if (policy->IsPseudoScheme(protocol)) |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 3338 | return; |
[email protected] | 8f81063 | 2013-06-06 22:33:32 | [diff] [blame] | 3339 | |
[email protected] | c125e53 | 2014-05-10 20:39:06 | [diff] [blame] | 3340 | delegate_->RegisterProtocolHandler(this, protocol, url, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 3341 | } |
| 3342 | |
[email protected] | f5273e5 | 2014-07-14 16:30:20 | [diff] [blame] | 3343 | void WebContentsImpl::OnUnregisterProtocolHandler(const std::string& protocol, |
| 3344 | const GURL& url, |
| 3345 | bool user_gesture) { |
| 3346 | if (!delegate_) |
| 3347 | return; |
| 3348 | |
| 3349 | ChildProcessSecurityPolicyImpl* policy = |
| 3350 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 3351 | if (policy->IsPseudoScheme(protocol)) |
| 3352 | return; |
| 3353 | |
| 3354 | delegate_->UnregisterProtocolHandler(this, protocol, url, user_gesture); |
| 3355 | } |
| 3356 | |
kouhei | 40f03cb | 2015-09-24 07:47:01 | [diff] [blame] | 3357 | void WebContentsImpl::OnUpdatePageImportanceSignals( |
| 3358 | const PageImportanceSignals& signals) { |
| 3359 | page_importance_signals_ = signals; |
| 3360 | } |
| 3361 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3362 | void WebContentsImpl::OnFindReply(int request_id, |
| 3363 | int number_of_matches, |
| 3364 | const gfx::Rect& selection_rect, |
| 3365 | int active_match_ordinal, |
| 3366 | bool final_update) { |
[email protected] | e5f2de0 | 2012-07-20 22:15:43 | [diff] [blame] | 3367 | if (delegate_) { |
| 3368 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 3369 | active_match_ordinal, final_update); |
| 3370 | } |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 3371 | } |
| 3372 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 3373 | #if defined(OS_ANDROID) |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3374 | void WebContentsImpl::OnFindMatchRectsReply( |
| 3375 | int version, |
| 3376 | const std::vector<gfx::RectF>& rects, |
| 3377 | const gfx::RectF& active_rect) { |
| 3378 | if (delegate_) |
| 3379 | delegate_->FindMatchRectsReply(this, version, rects, active_rect); |
| 3380 | } |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3381 | |
[email protected] | 1ff42797 | 2013-02-07 21:14:07 | [diff] [blame] | 3382 | void WebContentsImpl::OnOpenDateTimeDialog( |
| 3383 | const ViewHostMsg_DateTimeDialogValue_Params& value) { |
ajith.v | 9e47ab5 | 2014-10-30 20:24:17 | [diff] [blame] | 3384 | date_time_chooser_->ShowDialog(GetTopLevelNativeWindow(), |
[email protected] | ee59cbec | 2013-08-16 14:59:09 | [diff] [blame] | 3385 | GetRenderViewHost(), |
| 3386 | value.dialog_type, |
[email protected] | e807256 | 2013-12-04 06:04:13 | [diff] [blame] | 3387 | value.dialog_value, |
[email protected] | ee59cbec | 2013-08-16 14:59:09 | [diff] [blame] | 3388 | value.minimum, |
| 3389 | value.maximum, |
[email protected] | 6e08bfb | 2013-12-07 02:56:17 | [diff] [blame] | 3390 | value.step, |
| 3391 | value.suggestions); |
[email protected] | 583418cc | 2013-01-17 14:01:10 | [diff] [blame] | 3392 | } |
[email protected] | 59363fc9 | 2012-09-05 03:46:31 | [diff] [blame] | 3393 | #endif |
| 3394 | |
avi | 60bd490 | 2015-09-23 20:39:24 | [diff] [blame] | 3395 | void WebContentsImpl::OnDomOperationResponse(const std::string& json_string) { |
| 3396 | std::string json = json_string; |
| 3397 | NotificationService::current()->Notify(NOTIFICATION_DOM_OPERATION_RESPONSE, |
| 3398 | Source<WebContents>(this), |
| 3399 | Details<std::string>(&json)); |
[email protected] | cfa856d6 | 2014-02-22 07:58:40 | [diff] [blame] | 3400 | } |
| 3401 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3402 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
| 3403 | bool blocked_by_policy) { |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3404 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 3405 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 3406 | AppCacheAccessed(manifest_url, blocked_by_policy)); |
| 3407 | } |
| 3408 | |
[email protected] | 8bc5ff0 | 2013-11-29 06:34:03 | [diff] [blame] | 3409 | void WebContentsImpl::OnOpenColorChooser( |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3410 | int color_chooser_id, |
| 3411 | SkColor color, |
| 3412 | const std::vector<ColorSuggestion>& suggestions) { |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3413 | if (!HasValidFrameSource()) |
mukai | 38b1e4f | 2015-01-23 00:24:00 | [diff] [blame] | 3414 | return; |
nasko | 907fcb6 | 2015-01-28 04:24:11 | [diff] [blame] | 3415 | |
[email protected] | aa62afd | 2014-04-22 19:22:46 | [diff] [blame] | 3416 | ColorChooser* new_color_chooser = delegate_ ? |
| 3417 | delegate_->OpenColorChooser(this, color, suggestions) : |
| 3418 | NULL; |
[email protected] | 820957a | 2014-01-14 14:56:30 | [diff] [blame] | 3419 | if (!new_color_chooser) |
[email protected] | cb80545 | 2013-05-22 15:16:21 | [diff] [blame] | 3420 | return; |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3421 | if (color_chooser_info_.get()) |
| 3422 | color_chooser_info_->chooser->End(); |
| 3423 | |
| 3424 | color_chooser_info_.reset(new ColorChooserInfo( |
| 3425 | render_frame_message_source_->GetProcess()->GetID(), |
| 3426 | render_frame_message_source_->GetRoutingID(), |
| 3427 | new_color_chooser, |
| 3428 | color_chooser_id)); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3429 | } |
| 3430 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3431 | void WebContentsImpl::OnEndColorChooser(int color_chooser_id) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3432 | if (color_chooser_info_ && |
| 3433 | color_chooser_id == color_chooser_info_->identifier) |
| 3434 | color_chooser_info_->chooser->End(); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3435 | } |
| 3436 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3437 | void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 3438 | SkColor color) { |
[email protected] | 8ed1647 | 2014-04-11 19:02:48 | [diff] [blame] | 3439 | if (color_chooser_info_ && |
| 3440 | color_chooser_id == color_chooser_info_->identifier) |
| 3441 | color_chooser_info_->chooser->SetSelectedColor(color); |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 3442 | } |
| 3443 | |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 3444 | // This exists for render views that don't have a WebUI, but do have WebUI |
| 3445 | // bindings enabled. |
| 3446 | void WebContentsImpl::OnWebUISend(const GURL& source_url, |
| 3447 | const std::string& name, |
| 3448 | const base::ListValue& args) { |
| 3449 | if (delegate_) |
| 3450 | delegate_->WebUISend(this, source_url, name, args); |
| 3451 | } |
| 3452 | |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 3453 | #if defined(ENABLE_PLUGINS) |
emaxx | e70f5e1 | 2015-05-29 11:26:00 | [diff] [blame] | 3454 | void WebContentsImpl::OnPepperInstanceCreated() { |
| 3455 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceCreated()); |
| 3456 | } |
| 3457 | |
| 3458 | void WebContentsImpl::OnPepperInstanceDeleted() { |
| 3459 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, PepperInstanceDeleted()); |
| 3460 | } |
| 3461 | |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3462 | void WebContentsImpl::OnPepperPluginHung(int plugin_child_id, |
| 3463 | const base::FilePath& path, |
| 3464 | bool is_hung) { |
| 3465 | UMA_HISTOGRAM_COUNTS("Pepper.PluginHung", 1); |
| 3466 | |
| 3467 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3468 | PluginHungStatusChanged(plugin_child_id, path, is_hung)); |
| 3469 | } |
| 3470 | |
| 3471 | void WebContentsImpl::OnPluginCrashed(const base::FilePath& plugin_path, |
| 3472 | base::ProcessId plugin_pid) { |
| 3473 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3474 | PluginCrashed(plugin_path, plugin_pid)); |
| 3475 | } |
| 3476 | |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3477 | void WebContentsImpl::OnRequestPpapiBrokerPermission( |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3478 | int routing_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3479 | const GURL& url, |
[email protected] | 2dec8ec | 2013-02-07 19:20:34 | [diff] [blame] | 3480 | const base::FilePath& plugin_path) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3481 | if (!delegate_) { |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3482 | OnPpapiBrokerPermissionResult(routing_id, false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3483 | return; |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3484 | } |
| 3485 | |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3486 | if (!delegate_->RequestPpapiBrokerPermission( |
| 3487 | this, url, plugin_path, |
| 3488 | base::Bind(&WebContentsImpl::OnPpapiBrokerPermissionResult, |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3489 | base::Unretained(this), routing_id))) { |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3490 | NOTIMPLEMENTED(); |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3491 | OnPpapiBrokerPermissionResult(routing_id, false); |
[email protected] | 8c8fc29 | 2012-11-23 18:57:16 | [diff] [blame] | 3492 | } |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3493 | } |
| 3494 | |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3495 | void WebContentsImpl::OnPpapiBrokerPermissionResult(int routing_id, |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3496 | bool result) { |
[email protected] | ea0309c | 2013-08-06 19:35:44 | [diff] [blame] | 3497 | Send(new ViewMsg_PpapiBrokerPermissionResult(routing_id, result)); |
[email protected] | d8415ad9 | 2012-08-23 14:40:50 | [diff] [blame] | 3498 | } |
| 3499 | |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3500 | void WebContentsImpl::OnBrowserPluginMessage(RenderFrameHost* render_frame_host, |
| 3501 | const IPC::Message& message) { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3502 | CHECK(!browser_plugin_embedder_.get()); |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 3503 | CreateBrowserPluginEmbedderIfNecessary(); |
fsamuel | 833ee7c | 2015-02-13 23:40:40 | [diff] [blame] | 3504 | browser_plugin_embedder_->OnMessageReceived(message, render_frame_host); |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 3505 | } |
tommycli | e6633ca7 | 2014-10-31 00:40:42 | [diff] [blame] | 3506 | #endif // defined(ENABLE_PLUGINS) |
[email protected] | 19be7a6 | 2012-10-01 23:03:37 | [diff] [blame] | 3507 | |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3508 | void WebContentsImpl::OnUpdateFaviconURL( |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3509 | const std::vector<FaviconURL>& candidates) { |
pkotwicz | f9bc2059 | 2015-04-21 18:57:06 | [diff] [blame] | 3510 | // We get updated favicon URLs after the page stops loading. If a cross-site |
| 3511 | // navigation occurs while a page is still loading, the initial page |
| 3512 | // may stop loading and send us updated favicon URLs after the navigation |
| 3513 | // for the new page has committed. |
| 3514 | RenderViewHostImpl* rvhi = |
| 3515 | static_cast<RenderViewHostImpl*>(render_view_message_source_); |
| 3516 | if (!rvhi->is_active()) |
| 3517 | return; |
| 3518 | |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3519 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 3520 | DidUpdateFaviconURL(candidates)); |
[email protected] | 795c2897 | 2012-12-06 06:13:39 | [diff] [blame] | 3521 | } |
| 3522 | |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3523 | #if defined(OS_ANDROID) |
| 3524 | |
| 3525 | void WebContentsImpl::OnMediaSessionStateChanged() { |
| 3526 | MediaSession* session = MediaSession::Get(this); |
| 3527 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3528 | MediaSessionStateChanged(session->IsControllable(), |
| 3529 | session->IsSuspended())); |
| 3530 | } |
| 3531 | |
| 3532 | void WebContentsImpl::ResumeMediaSession() { |
| 3533 | MediaSession::Get(this)->Resume(); |
| 3534 | } |
| 3535 | |
| 3536 | void WebContentsImpl::SuspendMediaSession() { |
| 3537 | MediaSession::Get(this)->Suspend(); |
| 3538 | } |
| 3539 | |
mlamouri | 4c4fbed | 2015-08-17 15:51:01 | [diff] [blame] | 3540 | void WebContentsImpl::StopMediaSession() { |
| 3541 | MediaSession::Get(this)->Stop(); |
| 3542 | } |
| 3543 | |
avayvod | 41634b1 | 2015-07-08 17:07:05 | [diff] [blame] | 3544 | #endif // defined(OS_ANDROID) |
| 3545 | |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 3546 | void WebContentsImpl::OnFirstVisuallyNonEmptyPaint() { |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 3547 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 3548 | DidFirstVisuallyNonEmptyPaint()); |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3549 | |
peter | 90afaba | 2015-06-01 12:05:29 | [diff] [blame] | 3550 | did_first_visually_non_empty_paint_ = true; |
| 3551 | |
yusufo | d41c5f9 | 2015-03-06 00:14:28 | [diff] [blame] | 3552 | if (theme_color_ != last_sent_theme_color_) { |
| 3553 | // Theme color should have updated by now if there was one. |
| 3554 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3555 | DidChangeThemeColor(theme_color_)); |
| 3556 | last_sent_theme_color_ = theme_color_; |
| 3557 | } |
[email protected] | 9f26807 | 2013-11-07 00:02:15 | [diff] [blame] | 3558 | } |
[email protected] | d9030b8 | 2013-07-19 08:26:06 | [diff] [blame] | 3559 | |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3560 | void WebContentsImpl::DidChangeVisibleSSLState() { |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3561 | if (delegate_) { |
[email protected] | 25af6ec | 2014-06-06 19:35:07 | [diff] [blame] | 3562 | delegate_->VisibleSSLStateChanged(this); |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3563 | |
estark | 5ea80e5 | 2015-06-19 18:43:12 | [diff] [blame] | 3564 | SecurityStyleExplanations security_style_explanations; |
| 3565 | SecurityStyle security_style = |
| 3566 | delegate_->GetSecurityStyle(this, &security_style_explanations); |
| 3567 | FOR_EACH_OBSERVER( |
| 3568 | WebContentsObserver, observers_, |
| 3569 | SecurityStyleChanged(security_style, security_style_explanations)); |
lgarron | 662dd52 | 2015-06-08 23:20:01 | [diff] [blame] | 3570 | } |
[email protected] | e67ebf3 | 2013-02-13 11:07:19 | [diff] [blame] | 3571 | } |
| 3572 | |
[email protected] | 17e286e | 2013-03-01 23:29:39 | [diff] [blame] | 3573 | void WebContentsImpl::NotifyBeforeFormRepostWarningShow() { |
| 3574 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 3575 | BeforeFormRepostWarningShow()); |
| 3576 | } |
| 3577 | |
[email protected] | ec6c05f | 2013-10-23 18:41:57 | [diff] [blame] | 3578 | void WebContentsImpl::ActivateAndShowRepostFormWarningDialog() { |
| 3579 | Activate(); |
| 3580 | if (delegate_) |
| 3581 | delegate_->ShowRepostFormWarningDialog(this); |
| 3582 | } |
| 3583 | |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 3584 | bool WebContentsImpl::HasAccessedInitialDocument() { |
| 3585 | return has_accessed_initial_document_; |
| 3586 | } |
| 3587 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3588 | // Notifies the RenderWidgetHost instance about the fact that the page is |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 3589 | // loading, or done loading. |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 3590 | void WebContentsImpl::SetIsLoading(bool is_loading, |
| 3591 | bool to_different_document, |
| 3592 | LoadNotificationDetails* details) { |
| 3593 | if (is_loading == is_loading_) |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3594 | return; |
| 3595 | |
| 3596 | if (!is_loading) { |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3597 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, |
| 3598 | base::string16()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3599 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 3600 | upload_size_ = 0; |
| 3601 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3602 | } |
| 3603 | |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 3604 | GetRenderManager()->SetIsLoading(is_loading); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3605 | |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 3606 | is_loading_ = is_loading; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3607 | waiting_for_response_ = is_loading; |
[email protected] | 6dfed69 | 2014-05-22 04:18:03 | [diff] [blame] | 3608 | is_load_to_different_document_ = to_different_document; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3609 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 3610 | if (delegate_) |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 3611 | delegate_->LoadingStateChanged(this, to_different_document); |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3612 | NotifyNavigationStateChanged(INVALIDATE_TYPE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3613 | |
[email protected] | eab6144 | 2013-11-14 18:35:48 | [diff] [blame] | 3614 | std::string url = (details ? details->url.possibly_invalid_spec() : "NULL"); |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 3615 | if (is_loading) { |
carlosk | c13951a | 2015-12-30 16:51:54 | [diff] [blame] | 3616 | TRACE_EVENT_ASYNC_BEGIN2("browser,navigation", "WebContentsImpl Loading", |
| 3617 | this, "URL", url, "Main FrameTreeNode id", |
| 3618 | GetFrameTree()->root()->frame_tree_node_id()); |
fdegans | 6ce28f5 | 2015-03-19 12:52:22 | [diff] [blame] | 3619 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading()); |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 3620 | } else { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 3621 | TRACE_EVENT_ASYNC_END1("browser,navigation", "WebContentsImpl Loading", |
| 3622 | this, "URL", url); |
fdegans | 6ce28f5 | 2015-03-19 12:52:22 | [diff] [blame] | 3623 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading()); |
[email protected] | 9162187 | 2013-10-08 04:04:59 | [diff] [blame] | 3624 | } |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 3625 | |
| 3626 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3627 | int type = is_loading ? NOTIFICATION_LOAD_START : NOTIFICATION_LOAD_STOP; |
| 3628 | NotificationDetails det = NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3629 | if (details) |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3630 | det = Details<LoadNotificationDetails>(details); |
| 3631 | NotificationService::current()->Notify( |
| 3632 | type, Source<NavigationController>(&controller_), det); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 3633 | } |
| 3634 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3635 | void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 3636 | // If we are creating a RVH for a restored controller, then we need to make |
| 3637 | // sure the RenderView starts with a next_page_id_ larger than the number |
| 3638 | // of restored entries. This must be called before the RenderView starts |
| 3639 | // navigating (to avoid a race between the browser updating max_page_id and |
| 3640 | // the renderer updating next_page_id_). Because of this, we only call this |
| 3641 | // from CreateRenderView and allow that to notify the RenderView for us. |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 3642 | int max_restored_page_id = controller_.GetMaxRestoredPageID(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 3643 | if (max_restored_page_id > |
| 3644 | GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) |
| 3645 | UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), |
| 3646 | max_restored_page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3647 | } |
| 3648 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3649 | bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3650 | const base::string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3651 | // For file URLs without a title, use the pathname instead. In the case of a |
| 3652 | // synthesized title, we don't want the update to count toward the "one set |
| 3653 | // per page of the title to history." |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 3654 | base::string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3655 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3656 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
[email protected] | 3295612 | 2013-12-25 07:29:24 | [diff] [blame] | 3657 | final_title = base::UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3658 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 3659 | } else { |
[email protected] | 8af69c6c | 2014-03-03 19:05:31 | [diff] [blame] | 3660 | base::TrimWhitespace(title, base::TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3661 | explicit_set = true; |
| 3662 | } |
| 3663 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3664 | // If a page is created via window.open and never navigated, |
| 3665 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 3666 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3667 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3668 | if (final_title == entry->GetTitle()) |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3669 | return false; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3670 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 3671 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 3672 | } else { |
| 3673 | if (page_title_when_no_navigation_entry_ == final_title) |
| 3674 | return false; // Nothing changed, don't bother. |
| 3675 | |
| 3676 | page_title_when_no_navigation_entry_ = final_title; |
| 3677 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3678 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3679 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 3680 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3681 | |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 3682 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1ef02d24 | 2013-10-07 16:18:53 | [diff] [blame] | 3683 | TitleWasSet(entry, explicit_set)); |
[email protected] | 6679890 | 2013-10-01 18:40:16 | [diff] [blame] | 3684 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3685 | return true; |
| 3686 | } |
| 3687 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 3688 | void WebContentsImpl::SendChangeLoadProgress() { |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3689 | loading_last_progress_update_ = base::TimeTicks::Now(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3690 | if (delegate_) |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 3691 | delegate_->LoadProgressChanged(this, frame_tree_.load_progress()); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3692 | } |
| 3693 | |
| 3694 | void WebContentsImpl::ResetLoadProgressState() { |
fdegans | 1d1635516 | 2015-03-26 11:58:34 | [diff] [blame] | 3695 | frame_tree_.ResetLoadProgress(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3696 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 3697 | loading_last_progress_update_ = base::TimeTicks(); |
| 3698 | } |
| 3699 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 3700 | void WebContentsImpl::NotifyViewSwapped(RenderViewHost* old_host, |
| 3701 | RenderViewHost* new_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3702 | // After sending out a swap notification, we need to send a disconnect |
| 3703 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 3704 | // pointer. See Bug 1230284. |
| 3705 | notify_disconnection_ = true; |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 3706 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 7b712ee2 | 2013-10-03 00:57:28 | [diff] [blame] | 3707 | RenderViewHostChanged(old_host, new_host)); |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 3708 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3709 | // Ensure that the associated embedder gets cleared after a RenderViewHost |
| 3710 | // gets swapped, so we don't reuse the same embedder next time a |
| 3711 | // RenderViewHost is attached to this WebContents. |
| 3712 | RemoveBrowserPluginEmbedder(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3713 | } |
| 3714 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 3715 | void WebContentsImpl::NotifyFrameSwapped(RenderFrameHost* old_host, |
| 3716 | RenderFrameHost* new_host) { |
| 3717 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 3718 | observers_, |
| 3719 | RenderFrameHostChanged(old_host, new_host)); |
| 3720 | } |
| 3721 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 3722 | // TODO(avi): Remove this entire function because this notification is already |
| 3723 | // covered by two observer functions. http://crbug.com/170921 |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3724 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3725 | if (!notify_disconnection_) |
| 3726 | return; |
| 3727 | |
| 3728 | notify_disconnection_ = false; |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3729 | NotificationService::current()->Notify( |
| 3730 | NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 3731 | Source<WebContents>(this), |
| 3732 | NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3733 | } |
| 3734 | |
[email protected] | cbb1ef59 | 2013-06-05 19:49:46 | [diff] [blame] | 3735 | void WebContentsImpl::NotifyNavigationEntryCommitted( |
| 3736 | const LoadCommittedDetails& load_details) { |
| 3737 | FOR_EACH_OBSERVER( |
| 3738 | WebContentsObserver, observers_, NavigationEntryCommitted(load_details)); |
| 3739 | } |
| 3740 | |
[email protected] | f114fa4 | 2013-12-06 17:06:44 | [diff] [blame] | 3741 | bool WebContentsImpl::OnMessageReceived(RenderFrameHost* render_frame_host, |
| 3742 | const IPC::Message& message) { |
| 3743 | return OnMessageReceived(NULL, render_frame_host, message); |
[email protected] | 271ff579 | 2013-12-04 22:29:31 | [diff] [blame] | 3744 | } |
| 3745 | |
[email protected] | c31a8480 | 2014-04-03 15:55:49 | [diff] [blame] | 3746 | const GURL& WebContentsImpl::GetMainFrameLastCommittedURL() const { |
| 3747 | return GetLastCommittedURL(); |
| 3748 | } |
| 3749 | |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 3750 | void WebContentsImpl::RenderFrameCreated(RenderFrameHost* render_frame_host) { |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 3751 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 3752 | observers_, |
| 3753 | RenderFrameCreated(render_frame_host)); |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3754 | SetAccessibilityModeOnFrame(accessibility_mode_, render_frame_host); |
[email protected] | b849847b | 2013-12-10 21:57:58 | [diff] [blame] | 3755 | } |
| 3756 | |
| 3757 | void WebContentsImpl::RenderFrameDeleted(RenderFrameHost* render_frame_host) { |
| 3758 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 3759 | observers_, |
| 3760 | RenderFrameDeleted(render_frame_host)); |
| 3761 | } |
| 3762 | |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 3763 | void WebContentsImpl::ShowContextMenu(RenderFrameHost* render_frame_host, |
| 3764 | const ContextMenuParams& params) { |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 3765 | ContextMenuParams context_menu_params(params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 3766 | // Allow WebContentsDelegates to handle the context menu operation first. |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 3767 | if (delegate_ && delegate_->HandleContextMenu(context_menu_params)) |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 3768 | return; |
| 3769 | |
[email protected] | 077e704b | 2014-05-23 19:24:10 | [diff] [blame] | 3770 | render_view_host_delegate_view_->ShowContextMenu(render_frame_host, |
| 3771 | context_menu_params); |
[email protected] | a09d53ce | 2014-01-31 00:46:42 | [diff] [blame] | 3772 | } |
| 3773 | |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3774 | void WebContentsImpl::RunJavaScriptMessage( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3775 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3776 | const base::string16& message, |
| 3777 | const base::string16& default_prompt, |
| 3778 | const GURL& frame_url, |
| 3779 | JavaScriptMessageType javascript_message_type, |
| 3780 | IPC::Message* reply_msg) { |
| 3781 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 3782 | // showing an interstitial as it's shown over the previous page and we don't |
| 3783 | // want the hidden page's dialogs to interfere with the interstitial. |
| 3784 | bool suppress_this_message = |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 3785 | static_cast<RenderFrameHostImpl*>(render_frame_host)->is_swapped_out() || |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 3786 | ShowingInterstitialPage() || !delegate_ || |
| 3787 | delegate_->ShouldSuppressDialogs(this) || |
| 3788 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3789 | |
| 3790 | if (!suppress_this_message) { |
| 3791 | std::string accept_lang = GetContentClient()->browser()-> |
| 3792 | GetAcceptLangs(GetBrowserContext()); |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 3793 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3794 | dialog_manager_->RunJavaScriptDialog( |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 3795 | this, frame_url, accept_lang, javascript_message_type, message, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3796 | default_prompt, |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 3797 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3798 | render_frame_host->GetProcess()->GetID(), |
palmer | 4e0ae10d | 2015-09-03 23:38:41 | [diff] [blame] | 3799 | render_frame_host->GetRoutingID(), reply_msg, false), |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3800 | &suppress_this_message); |
| 3801 | } |
| 3802 | |
| 3803 | if (suppress_this_message) { |
| 3804 | // If we are suppressing messages, just reply as if the user immediately |
| 3805 | // pressed "Cancel", passing true to |dialog_was_suppressed|. |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3806 | OnDialogClosed(render_frame_host->GetProcess()->GetID(), |
| 3807 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 3808 | true, false, base::string16()); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3809 | } |
| 3810 | |
| 3811 | // OnDialogClosed (two lines up) may have caused deletion of this object (see |
| 3812 | // http://crbug.com/288961 ). The only safe thing to do here is return. |
| 3813 | } |
| 3814 | |
| 3815 | void WebContentsImpl::RunBeforeUnloadConfirm( |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3816 | RenderFrameHost* render_frame_host, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3817 | const base::string16& message, |
| 3818 | bool is_reload, |
| 3819 | IPC::Message* reply_msg) { |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3820 | RenderFrameHostImpl* rfhi = |
| 3821 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3822 | if (delegate_) |
| 3823 | delegate_->WillRunBeforeUnloadConfirm(); |
| 3824 | |
| 3825 | bool suppress_this_message = |
creis | 36e228b | 2015-06-08 18:48:02 | [diff] [blame] | 3826 | rfhi->rfh_state() != RenderFrameHostImpl::STATE_DEFAULT || |
| 3827 | ShowingInterstitialPage() || !delegate_ || |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 3828 | delegate_->ShouldSuppressDialogs(this) || |
| 3829 | !delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3830 | if (suppress_this_message) { |
| 3831 | rfhi->JavaScriptDialogClosed(reply_msg, true, base::string16(), true); |
| 3832 | return; |
| 3833 | } |
| 3834 | |
| 3835 | is_showing_before_unload_dialog_ = true; |
mathiash | 72a5e46 | 2014-11-19 08:18:50 | [diff] [blame] | 3836 | dialog_manager_ = delegate_->GetJavaScriptDialogManager(this); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3837 | dialog_manager_->RunBeforeUnloadDialog( |
| 3838 | this, message, is_reload, |
| 3839 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 3840 | render_frame_host->GetProcess()->GetID(), |
| 3841 | render_frame_host->GetRoutingID(), reply_msg, |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 3842 | false)); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 3843 | } |
| 3844 | |
[email protected] | a86c0e96 | 2013-12-17 17:10:39 | [diff] [blame] | 3845 | WebContents* WebContentsImpl::GetAsWebContents() { |
| 3846 | return this; |
| 3847 | } |
| 3848 | |
[email protected] | 7912e82 | 2014-04-16 02:37:03 | [diff] [blame] | 3849 | bool WebContentsImpl::IsNeverVisible() { |
| 3850 | if (!delegate_) |
| 3851 | return false; |
| 3852 | return delegate_->IsNeverVisible(this); |
| 3853 | } |
| 3854 | |
[email protected] | 9564021 | 2014-07-26 18:14:30 | [diff] [blame] | 3855 | #if defined(OS_WIN) |
| 3856 | gfx::NativeViewAccessible WebContentsImpl::GetParentNativeViewAccessible() { |
| 3857 | return accessible_parent_; |
| 3858 | } |
| 3859 | #endif |
| 3860 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 3861 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 3862 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3863 | } |
| 3864 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3865 | RendererPreferences WebContentsImpl::GetRendererPrefs( |
| 3866 | BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 3867 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 3868 | } |
| 3869 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 3870 | gfx::Rect WebContentsImpl::GetRootWindowResizerRect( |
| 3871 | RenderWidgetHostImpl* render_widget_host) const { |
| 3872 | if (!RenderViewHostImpl::From(render_widget_host)) |
| 3873 | return gfx::Rect(); |
| 3874 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 3875 | if (delegate_) |
| 3876 | return delegate_->GetRootWindowResizerRect(); |
| 3877 | return gfx::Rect(); |
| 3878 | } |
| 3879 | |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3880 | void WebContentsImpl::RemoveBrowserPluginEmbedder() { |
[email protected] | 59383c78 | 2013-04-17 16:43:27 | [diff] [blame] | 3881 | if (browser_plugin_embedder_) |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 3882 | browser_plugin_embedder_.reset(); |
| 3883 | } |
| 3884 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3885 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3886 | // Don't send notifications if we are just creating a swapped-out RVH for |
| 3887 | // the opener chain. These won't be used for view-source or WebUI, so it's |
| 3888 | // ok to return early. |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 3889 | if (!static_cast<RenderViewHostImpl*>(render_view_host)->is_active()) |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 3890 | return; |
| 3891 | |
[email protected] | 86f98a2 | 2013-03-20 14:35:00 | [diff] [blame] | 3892 | if (delegate_) |
[email protected] | e85165c64 | 2014-06-10 14:34:31 | [diff] [blame] | 3893 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 3894 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 3895 | NotificationService::current()->Notify( |
| 3896 | NOTIFICATION_WEB_CONTENTS_RENDER_VIEW_HOST_CREATED, |
| 3897 | Source<WebContents>(this), |
| 3898 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3899 | |
[email protected] | 6286a37 | 2013-10-09 04:03:27 | [diff] [blame] | 3900 | NavigationEntry* entry = controller_.GetPendingEntry(); |
[email protected] | e770b1e9 | 2013-08-29 14:26:33 | [diff] [blame] | 3901 | if (entry && entry->IsViewSourceMode()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3902 | // Put the renderer in view source mode. |
[email protected] | 6b618e6 | 2012-08-16 12:59:18 | [diff] [blame] | 3903 | render_view_host->Send( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 3904 | new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3905 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 3906 | |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 3907 | view_->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 3908 | |
| 3909 | FOR_EACH_OBSERVER( |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 3910 | WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3911 | } |
| 3912 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3913 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3914 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3915 | // Don't notify the world, since this came from a renderer in the |
| 3916 | // background. |
| 3917 | return; |
| 3918 | } |
| 3919 | |
[email protected] | da7a718 | 2013-09-06 08:11:11 | [diff] [blame] | 3920 | notify_disconnection_ = true; |
| 3921 | // TODO(avi): Remove. http://crbug.com/170921 |
| 3922 | NotificationService::current()->Notify( |
| 3923 | NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 3924 | Source<WebContents>(this), |
| 3925 | NotificationService::NoDetails()); |
| 3926 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 3927 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 3928 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 3929 | |
| 3930 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 3931 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 3932 | if (was_crashed && !FocusLocationBarByDefault() && |
| 3933 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | f3615f0 | 2013-02-26 06:09:06 | [diff] [blame] | 3934 | view_->Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 3935 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 3936 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 3937 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3938 | } |
| 3939 | |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 3940 | void WebContentsImpl::RenderViewTerminated(RenderViewHost* rvh, |
| 3941 | base::TerminationStatus status, |
| 3942 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 3943 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3944 | // The pending page's RenderViewHost is gone. |
| 3945 | return; |
| 3946 | } |
| 3947 | |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 3948 | // Ensure fullscreen mode is exited in the |delegate_| since a crashed |
| 3949 | // renderer may not have made a clean exit. |
avi | bf58fa0c | 2015-11-11 01:45:52 | [diff] [blame] | 3950 | if (IsFullscreenForCurrentTab(GetRenderViewHost()->GetWidget())) |
bokan | ece34a8 | 2016-01-28 19:49:46 | [diff] [blame] | 3951 | ExitFullscreenMode(false); |
[email protected] | 2fcdcc3 | 2014-03-05 02:14:07 | [diff] [blame] | 3952 | |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 3953 | // Cancel any visible dialogs so they are not left dangling over the sad tab. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 3954 | CancelActiveAndPendingDialogs(); |
[email protected] | 698191dc | 2014-02-25 01:06:13 | [diff] [blame] | 3955 | |
[email protected] | f738bdcb | 2014-07-11 20:40:44 | [diff] [blame] | 3956 | if (delegate_) |
| 3957 | delegate_->HideValidationMessage(this); |
| 3958 | |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 3959 | SetIsLoading(false, true, nullptr); |
| 3960 | NotifyDisconnected(); |
| 3961 | SetIsCrashed(status, error_code); |
| 3962 | |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3963 | // Reset the loading progress. TODO(avi): What does it mean to have a |
| 3964 | // "renderer crash" when there is more than one renderer process serving a |
| 3965 | // webpage? Once this function is called at a more granular frame level, we |
| 3966 | // probably will need to more granularly reset the state here. |
| 3967 | ResetLoadProgressState(); |
[email protected] | 960b037 | 2014-05-19 18:01:00 | [diff] [blame] | 3968 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 3969 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 3970 | observers_, |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 3971 | RenderProcessGone(GetCrashedStatus())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3972 | } |
| 3973 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3974 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 3975 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 3976 | } |
| 3977 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3978 | void WebContentsImpl::UpdateState(RenderViewHost* rvh, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 3979 | int32_t page_id, |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 3980 | const PageState& page_state) { |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 3981 | DCHECK(!SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 3982 | |
creis | e1d3e5b | 2014-12-01 18:21:57 | [diff] [blame] | 3983 | // Ensure that this state update comes from a RenderViewHost that belongs to |
| 3984 | // this WebContents. |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 3985 | // TODO(nasko): This should go through RenderFrameHost. |
creis | e1d3e5b | 2014-12-01 18:21:57 | [diff] [blame] | 3986 | if (rvh->GetDelegate()->GetAsWebContents() != this) |
[email protected] | 94d0cc1 | 2013-12-18 00:07:41 | [diff] [blame] | 3987 | return; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3988 | |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 3989 | // We must be prepared to handle state updates for any page. They occur |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3990 | // when the user is scrolling and entering form data, as well as when we're |
| 3991 | // leaving a page, in which case our state may have already been moved to |
| 3992 | // the next page. The navigation controller will look up the appropriate |
| 3993 | // NavigationEntry and update it when it is notified via the delegate. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 3994 | RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
avi | 4717933 | 2015-05-20 21:01:11 | [diff] [blame] | 3995 | NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 3996 | rvhi->GetSiteInstance(), page_id); |
avi | 4717933 | 2015-05-20 21:01:11 | [diff] [blame] | 3997 | if (!entry) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3998 | return; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3999 | |
nasko | 34696991 | 2015-12-16 22:36:47 | [diff] [blame] | 4000 | // Sanity check that ensures nav_entry_id and page_id point to the same |
| 4001 | // navigation entry. |
| 4002 | if (rvhi->GetMainFrame()) { |
| 4003 | NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID( |
| 4004 | static_cast<RenderFrameHostImpl*>(rvhi->GetMainFrame()) |
| 4005 | ->nav_entry_id()); |
creis | d63f6c4a | 2015-11-06 19:05:53 | [diff] [blame] | 4006 | |
nasko | 34696991 | 2015-12-16 22:36:47 | [diff] [blame] | 4007 | DCHECK_EQ(entry, new_entry); |
| 4008 | } |
creis | d63f6c4a | 2015-11-06 19:05:53 | [diff] [blame] | 4009 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 4010 | if (page_state == entry->GetPageState()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4011 | return; // Nothing to update. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 4012 | entry->SetPageState(page_state); |
avi | 4717933 | 2015-05-20 21:01:11 | [diff] [blame] | 4013 | controller_.NotifyEntryChanged(entry); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4014 | } |
| 4015 | |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4016 | void WebContentsImpl::UpdateTargetURL(RenderViewHost* render_view_host, |
| 4017 | const GURL& url) { |
| 4018 | if (fullscreen_widget_routing_id_ != MSG_ROUTING_NONE) { |
| 4019 | // If we're fullscreen only update the url if it's from the fullscreen |
| 4020 | // renderer. |
| 4021 | RenderWidgetHostView* fs = GetFullscreenRenderWidgetHostView(); |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4022 | if (fs && fs->GetRenderWidgetHost() != render_view_host->GetWidget()) |
sky | 8b00392d | 2015-01-10 00:30:28 | [diff] [blame] | 4023 | return; |
| 4024 | } |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4025 | if (delegate_) |
avi | 450ce00e | 2014-09-24 01:58:52 | [diff] [blame] | 4026 | delegate_->UpdateTargetURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4027 | } |
| 4028 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4029 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4030 | #if defined(OS_MACOSX) |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4031 | // The UI may be in an event-tracking loop, such as between the |
| 4032 | // mouse-down and mouse-up in text selection or a button click. |
| 4033 | // Defer the close until after tracking is complete, so that we |
| 4034 | // don't free objects out from under the UI. |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4035 | // TODO(shess): This could get more fine-grained. For instance, |
| 4036 | // closing a tab in another window while selecting text in the |
| 4037 | // current window's Omnibox should be just fine. |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4038 | if (view_->IsEventTracking()) { |
| 4039 | view_->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4040 | return; |
| 4041 | } |
[email protected] | 60780f41 | 2013-02-25 16:34:10 | [diff] [blame] | 4042 | #endif |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 4043 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4044 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 4045 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4046 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4047 | } |
| 4048 | |
[email protected] | 66bbadaf | 2014-03-28 16:25:54 | [diff] [blame] | 4049 | void WebContentsImpl::SwappedOut(RenderFrameHost* rfh) { |
[email protected] | 0d0f4c49 | 2014-04-02 06:42:57 | [diff] [blame] | 4050 | if (delegate_ && rfh->GetRenderViewHost() == GetRenderViewHost()) |
| 4051 | delegate_->SwappedOut(this); |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 4052 | } |
| 4053 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4054 | void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4055 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 4056 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4057 | } |
| 4058 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4059 | void WebContentsImpl::DidStartLoading(FrameTreeNode* frame_tree_node, |
[email protected] | e3b10d1 | 2014-03-28 16:06:09 | [diff] [blame] | 4060 | bool to_different_document) { |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 4061 | SetIsLoading(true, to_different_document, nullptr); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4062 | |
| 4063 | // Notify accessibility that the user is navigating away from the |
| 4064 | // current document. |
| 4065 | // |
| 4066 | // TODO(dmazzoni): do this using a WebContentsObserver. |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4067 | BrowserAccessibilityManager* manager = |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4068 | frame_tree_node->current_frame_host()->browser_accessibility_manager(); |
dmazzoni | bf8cec4 | 2015-02-08 08:28:08 | [diff] [blame] | 4069 | if (manager) |
| 4070 | manager->UserIsNavigatingAway(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4071 | } |
| 4072 | |
fdegans | c73eec2 | 2015-03-19 14:47:54 | [diff] [blame] | 4073 | void WebContentsImpl::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4074 | scoped_ptr<LoadNotificationDetails> details; |
| 4075 | |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4076 | // Use the last committed entry rather than the active one, in case a |
| 4077 | // pending entry has been created. |
| 4078 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4079 | Navigator* navigator = frame_tree_.root()->navigator(); |
[email protected] | 9595fd8 | 2013-04-19 21:28:49 | [diff] [blame] | 4080 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4081 | // An entry may not exist for a stop when loading an initial blank page or |
| 4082 | // if an iframe injected by script into a blank page finishes loading. |
| 4083 | if (entry) { |
[email protected] | 3691e5cf | 2014-01-22 10:16:20 | [diff] [blame] | 4084 | base::TimeDelta elapsed = |
| 4085 | base::TimeTicks::Now() - navigator->GetCurrentLoadStart(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4086 | |
| 4087 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 4088 | entry->GetVirtualURL(), |
| 4089 | entry->GetTransitionType(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4090 | elapsed, |
| 4091 | &controller_, |
| 4092 | controller_.GetCurrentEntryIndex())); |
| 4093 | } |
| 4094 | |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 4095 | SetIsLoading(false, true, details.get()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4096 | } |
| 4097 | |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4098 | void WebContentsImpl::DidChangeLoadProgress() { |
| 4099 | double load_progress = frame_tree_.load_progress(); |
| 4100 | |
| 4101 | // The delegate is notified immediately for the first and last updates. Also, |
| 4102 | // since the message loop may be pretty busy when a page is loaded, it might |
| 4103 | // not execute a posted task in a timely manner so the progress report is sent |
| 4104 | // immediately if enough time has passed. |
| 4105 | base::TimeDelta min_delay = |
| 4106 | base::TimeDelta::FromMilliseconds(kMinimumDelayBetweenLoadingUpdatesMS); |
| 4107 | bool delay_elapsed = loading_last_progress_update_.is_null() || |
| 4108 | base::TimeTicks::Now() - loading_last_progress_update_ > min_delay; |
| 4109 | |
| 4110 | if (load_progress == 0.0 || load_progress == 1.0 || delay_elapsed) { |
| 4111 | // If there is a pending task to send progress, it is now obsolete. |
| 4112 | loading_weak_factory_.InvalidateWeakPtrs(); |
| 4113 | |
| 4114 | // Notify the load progress change. |
| 4115 | SendChangeLoadProgress(); |
| 4116 | |
| 4117 | // Clean-up the states if needed. |
| 4118 | if (load_progress == 1.0) |
| 4119 | ResetLoadProgressState(); |
| 4120 | return; |
| 4121 | } |
| 4122 | |
| 4123 | if (loading_weak_factory_.HasWeakPtrs()) |
| 4124 | return; |
| 4125 | |
skyostil | 95082a6 | 2015-06-05 19:53:07 | [diff] [blame] | 4126 | base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 4127 | FROM_HERE, base::Bind(&WebContentsImpl::SendChangeLoadProgress, |
| 4128 | loading_weak_factory_.GetWeakPtr()), |
fdegans | a696e511 | 2015-04-17 01:57:59 | [diff] [blame] | 4129 | min_delay); |
| 4130 | } |
| 4131 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4132 | void WebContentsImpl::DidCancelLoading() { |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4133 | controller_.DiscardNonCommittedEntries(); |
| 4134 | |
| 4135 | // Update the URL display. |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4136 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 4137 | } |
| 4138 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4139 | void WebContentsImpl::DidAccessInitialDocument() { |
[email protected] | b4c8401 | 2014-04-28 19:51:10 | [diff] [blame] | 4140 | has_accessed_initial_document_ = true; |
| 4141 | |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4142 | // We may have left a failed browser-initiated navigation in the address bar |
| 4143 | // to let the user edit it and try again. Clear it now that content might |
| 4144 | // show up underneath it. |
| 4145 | if (!IsLoading() && controller_.GetPendingEntry()) |
avi | 45a7253 | 2015-04-07 21:01:45 | [diff] [blame] | 4146 | controller_.DiscardPendingEntry(false); |
[email protected] | d1371bf8e | 2014-04-19 03:26:24 | [diff] [blame] | 4147 | |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4148 | // Update the URL display. |
thestig | c4cac8f | 2014-09-04 21:17:50 | [diff] [blame] | 4149 | NotifyNavigationStateChanged(INVALIDATE_TYPE_URL); |
[email protected] | 59167c2 | 2013-06-03 18:07:32 | [diff] [blame] | 4150 | } |
| 4151 | |
alexmos | be2f4c3 | 2015-03-10 02:30:23 | [diff] [blame] | 4152 | void WebContentsImpl::DidChangeName(RenderFrameHost* render_frame_host, |
| 4153 | const std::string& name) { |
| 4154 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4155 | FrameNameChanged(render_frame_host, name)); |
| 4156 | } |
| 4157 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4158 | void WebContentsImpl::DocumentOnLoadCompleted( |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4159 | RenderFrameHost* render_frame_host) { |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 4160 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4161 | DocumentOnLoadCompletedInMainFrame()); |
[email protected] | 6578fef | 2013-10-14 02:35:09 | [diff] [blame] | 4162 | |
| 4163 | // TODO(avi): Remove. http://crbug.com/170921 |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4164 | NotificationService::current()->Notify( |
| 4165 | NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
| 4166 | Source<WebContents>(this), |
[email protected] | 5027949 | 2014-05-05 23:24:29 | [diff] [blame] | 4167 | NotificationService::NoDetails()); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 4168 | } |
| 4169 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4170 | void WebContentsImpl::UpdateStateForFrame(RenderFrameHost* render_frame_host, |
| 4171 | const PageState& page_state) { |
| 4172 | DCHECK(SiteIsolationPolicy::UseSubframeNavigationEntries()); |
| 4173 | |
| 4174 | // The state update affects the last NavigationEntry associated with the given |
| 4175 | // |render_frame_host|. This may not be the last committed NavigationEntry (as |
| 4176 | // in the case of an UpdateState from a frame being swapped out). We track |
| 4177 | // which entry this is in the RenderFrameHost's nav_entry_id. |
| 4178 | RenderFrameHostImpl* rfhi = |
| 4179 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
| 4180 | NavigationEntryImpl* entry = |
| 4181 | controller_.GetEntryWithUniqueID(rfhi->nav_entry_id()); |
| 4182 | if (!entry) |
| 4183 | return; |
| 4184 | |
| 4185 | FrameNavigationEntry* frame_entry = |
| 4186 | entry->GetFrameEntry(rfhi->frame_tree_node()); |
| 4187 | if (!frame_entry) |
| 4188 | return; |
| 4189 | |
creis | d06a942 | 2015-11-11 03:08:45 | [diff] [blame] | 4190 | // The SiteInstance might not match if we do a cross-process navigation with |
| 4191 | // replacement (e.g., auto-subframe), in which case the swap out of the old |
| 4192 | // RenderFrameHost runs in the background after the old FrameNavigationEntry |
| 4193 | // has already been replaced and destroyed. |
| 4194 | if (frame_entry->site_instance() != rfhi->GetSiteInstance()) |
| 4195 | return; |
| 4196 | |
creis | 8eb8ef2 | 2015-11-04 22:51:38 | [diff] [blame] | 4197 | if (page_state == frame_entry->page_state()) |
| 4198 | return; // Nothing to update. |
| 4199 | |
| 4200 | frame_entry->set_page_state(page_state); |
| 4201 | controller_.NotifyEntryChanged(entry); |
| 4202 | } |
| 4203 | |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4204 | void WebContentsImpl::UpdateTitle(RenderFrameHost* render_frame_host, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4205 | int32_t page_id, |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4206 | const base::string16& title, |
| 4207 | base::i18n::TextDirection title_direction) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4208 | // If we have a title, that's a pretty good indication that we've started |
| 4209 | // getting useful data. |
| 4210 | SetNotWaitingForResponse(); |
| 4211 | |
| 4212 | // Try to find the navigation entry, which might not be the current one. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4213 | // For example, it might be from a recently swapped out RFH. |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4214 | NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4215 | render_frame_host->GetSiteInstance(), page_id); |
| 4216 | |
creis | d63f6c4a | 2015-11-06 19:05:53 | [diff] [blame] | 4217 | NavigationEntryImpl* new_entry = controller_.GetEntryWithUniqueID( |
| 4218 | static_cast<RenderFrameHostImpl*>(render_frame_host)->nav_entry_id()); |
| 4219 | DCHECK_EQ(entry, new_entry); |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4220 | |
| 4221 | // We can handle title updates when we don't have an entry in |
| 4222 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 4223 | // TODO(avi): Change to make decisions based on the RenderFrameHost. |
avi | 286019ce | 2015-07-29 01:26:58 | [diff] [blame] | 4224 | if (!entry && render_frame_host != GetMainFrame()) |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4225 | return; |
| 4226 | |
| 4227 | // TODO(evan): make use of title_direction. |
| 4228 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
| 4229 | if (!UpdateTitleForEntry(entry, title)) |
| 4230 | return; |
| 4231 | |
| 4232 | // Broadcast notifications when the UI should be updated. |
| 4233 | if (entry == controller_.GetEntryAtOffset(0)) |
| 4234 | NotifyNavigationStateChanged(INVALIDATE_TYPE_TITLE); |
| 4235 | } |
| 4236 | |
| 4237 | void WebContentsImpl::UpdateEncoding(RenderFrameHost* render_frame_host, |
| 4238 | const std::string& encoding) { |
| 4239 | SetEncoding(encoding); |
| 4240 | } |
| 4241 | |
[email protected] | 39f2f925 | 2014-05-03 00:54:01 | [diff] [blame] | 4242 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 4243 | RenderViewHost* render_view_host) { |
| 4244 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4245 | DocumentAvailableInMainFrame()); |
| 4246 | } |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4247 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4248 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 4249 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 4250 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 4251 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 4252 | // It is possible to receive it from one that has just been swapped in, |
| 4253 | // in which case we might as well deliver the message anyway. |
| 4254 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
nasko | c0fceff | 2015-04-30 15:53:52 | [diff] [blame] | 4255 | ClosePage(); |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 4256 | } |
| 4257 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4258 | bool WebContentsImpl::ShouldRouteMessageEvent( |
| 4259 | RenderFrameHost* target_rfh, |
| 4260 | SiteInstance* source_site_instance) const { |
| 4261 | // Allow the message if this WebContents is dedicated to a browser plugin |
| 4262 | // guest. |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 4263 | // Note: This check means that an embedder could theoretically receive a |
| 4264 | // postMessage from anyone (not just its own guests). However, this is |
| 4265 | // probably not a risk for apps since other pages won't have references |
| 4266 | // to App windows. |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4267 | return GetBrowserPluginGuest() || GetBrowserPluginEmbedder(); |
| 4268 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4269 | |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4270 | void WebContentsImpl::EnsureOpenerProxiesExist(RenderFrameHost* source_rfh) { |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4271 | WebContentsImpl* source_web_contents = static_cast<WebContentsImpl*>( |
| 4272 | WebContents::FromRenderFrameHost(source_rfh)); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4273 | |
alexmos | e7da5a1 | 2015-04-09 02:22:16 | [diff] [blame] | 4274 | if (source_web_contents) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4275 | // If this message is going to outer WebContents from inner WebContents, |
| 4276 | // then we should not create a RenderView. AttachToOuterWebContentsFrame() |
| 4277 | // already created a RenderFrameProxyHost for that purpose. |
| 4278 | if (GetBrowserPluginEmbedder() && |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 4279 | BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4280 | return; |
| 4281 | } |
| 4282 | |
lfg | 812874d | 2016-02-09 22:26:13 | [diff] [blame] | 4283 | if (this != source_web_contents && GetBrowserPluginGuest()) { |
nasko | 5fb985b | 2015-08-20 17:28:16 | [diff] [blame] | 4284 | // We create a swapped out RenderView or RenderFrameProxyHost for the |
| 4285 | // embedder in the guest's render process but we intentionally do not |
| 4286 | // expose the embedder's opener chain to it. |
| 4287 | if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
| 4288 | source_web_contents->GetRenderManager()->CreateRenderFrameProxy( |
| 4289 | GetSiteInstance()); |
| 4290 | } else { |
| 4291 | source_web_contents->CreateSwappedOutRenderView(GetSiteInstance()); |
| 4292 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4293 | } else { |
alexmos | 5872904 | 2015-06-18 23:20:00 | [diff] [blame] | 4294 | RenderFrameHostImpl* source_rfhi = |
| 4295 | static_cast<RenderFrameHostImpl*>(source_rfh); |
| 4296 | source_rfhi->frame_tree_node()->render_manager()->CreateOpenerProxies( |
alexmos | 90325cf | 2015-09-02 17:18:39 | [diff] [blame] | 4297 | GetSiteInstance(), nullptr); |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4298 | } |
| 4299 | } |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 4300 | } |
| 4301 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4302 | bool WebContentsImpl::AddMessageToConsole(int32_t level, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4303 | const base::string16& message, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4304 | int32_t line_no, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4305 | const base::string16& source_id) { |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 4306 | if (!delegate_) |
| 4307 | return false; |
| 4308 | return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 4309 | source_id); |
| 4310 | } |
| 4311 | |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 4312 | int WebContentsImpl::CreateSwappedOutRenderView( |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4313 | SiteInstance* instance) { |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 4314 | int render_view_routing_id = MSG_ROUTING_NONE; |
nick | ac60e7547 | 2015-07-31 00:44:35 | [diff] [blame] | 4315 | if (SiteIsolationPolicy::IsSwappedOutStateForbidden()) { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 4316 | GetRenderManager()->CreateRenderFrameProxy(instance); |
| 4317 | } else { |
| 4318 | GetRenderManager()->CreateRenderFrame( |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 4319 | instance, CREATE_RF_SWAPPED_OUT | CREATE_RF_HIDDEN, |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 4320 | &render_view_routing_id); |
| 4321 | } |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 4322 | return render_view_routing_id; |
[email protected] | 0eba810b | 2012-10-18 03:19:36 | [diff] [blame] | 4323 | } |
| 4324 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4325 | void WebContentsImpl::OnUserGesture(RenderWidgetHostImpl* render_widget_host) { |
| 4326 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4327 | return; |
| 4328 | |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 4329 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 4330 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 4331 | |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 4332 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
[email protected] | b39e7a88b | 2012-01-10 21:43:17 | [diff] [blame] | 4333 | if (rdh) // NULL in unittests. |
| 4334 | rdh->OnUserGesture(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 4335 | } |
| 4336 | |
dominickn | 2dd142dd | 2015-10-29 05:30:50 | [diff] [blame] | 4337 | void WebContentsImpl::OnUserInteraction(const blink::WebInputEvent::Type type) { |
| 4338 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4339 | DidGetUserInteraction(type)); |
| 4340 | } |
| 4341 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4342 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 4343 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 4344 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 4345 | } |
| 4346 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4347 | void WebContentsImpl::RendererUnresponsive( |
| 4348 | RenderWidgetHostImpl* render_widget_host) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4349 | // Don't show hung renderer dialog for a swapped out RVH. |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4350 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 4351 | return; |
| 4352 | |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 4353 | RenderFrameHostImpl* rfhi = |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4354 | static_cast<RenderFrameHostImpl*>(GetRenderViewHost()->GetMainFrame()); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 4355 | |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 4356 | // Ignore renderer unresponsive event if debugger is attached to the tab |
| 4357 | // since the event may be a result of the renderer sitting on a breakpoint. |
| 4358 | // See http://crbug.com/65458 |
[email protected] | 98f6611 | 2012-12-25 12:59:36 | [diff] [blame] | 4359 | if (DevToolsAgentHost::IsDebuggerAttached(this)) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 4360 | return; |
| 4361 | |
clamy | 226727e | 2015-06-29 10:28:47 | [diff] [blame] | 4362 | if (rfhi->is_waiting_for_beforeunload_ack() || |
creis | cce56cd | 2014-09-29 22:45:22 | [diff] [blame] | 4363 | rfhi->IsWaitingForUnloadACK()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4364 | // Hang occurred while firing the beforeunload/unload handler. |
| 4365 | // Pretend the handler fired so tab closing continues as if it had. |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4366 | GetRenderViewHost()->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4367 | |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 4368 | if (!GetRenderManager()->ShouldCloseTabOnUnresponsiveRenderer()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4369 | return; |
| 4370 | |
| 4371 | // If the tab hangs in the beforeunload/unload handler there's really |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 4372 | // nothing we can do to recover. If the hang is in the beforeunload handler, |
| 4373 | // pretend the beforeunload listeners have all fired and allow the delegate |
| 4374 | // to continue closing; the user will not have the option of cancelling the |
| 4375 | // close. Otherwise, pretend the unload listeners have all fired and close |
| 4376 | // the tab. |
| 4377 | bool close = true; |
clamy | 226727e | 2015-06-29 10:28:47 | [diff] [blame] | 4378 | if (rfhi->is_waiting_for_beforeunload_ack() && delegate_) { |
[email protected] | 2e9d79f | 2013-08-16 05:45:56 | [diff] [blame] | 4379 | delegate_->BeforeUnloadFired(this, true, &close); |
| 4380 | } |
| 4381 | if (close) |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4382 | Close(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4383 | return; |
| 4384 | } |
| 4385 | |
creis | c014b40 | 2015-04-23 16:41:45 | [diff] [blame] | 4386 | if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 4387 | return; |
| 4388 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4389 | if (delegate_) |
| 4390 | delegate_->RendererUnresponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4391 | } |
| 4392 | |
avi | c3aa842 | 2015-11-09 20:57:22 | [diff] [blame] | 4393 | void WebContentsImpl::RendererResponsive( |
| 4394 | RenderWidgetHostImpl* render_widget_host) { |
| 4395 | if (render_widget_host != GetRenderViewHost()->GetWidget()) |
| 4396 | return; |
| 4397 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4398 | if (delegate_) |
| 4399 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4400 | } |
| 4401 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4402 | void WebContentsImpl::LoadStateChanged( |
| 4403 | const GURL& url, |
| 4404 | const net::LoadStateWithParam& load_state, |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4405 | uint64_t upload_position, |
| 4406 | uint64_t upload_size) { |
erikchen | 174b78c6 | 2015-03-11 22:02:54 | [diff] [blame] | 4407 | // TODO(erikchen): Remove ScopedTracker below once http://crbug.com/466285 |
| 4408 | // is fixed. |
| 4409 | tracked_objects::ScopedTracker tracking_profile1( |
| 4410 | FROM_HERE_WITH_EXPLICIT_FUNCTION( |
| 4411 | "466285 WebContentsImpl::LoadStateChanged::Start")); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4412 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 4413 | upload_position_ = upload_position; |
| 4414 | upload_size_ = upload_size; |
rsleevi | 24f64dc2 | 2015-08-07 21:39:21 | [diff] [blame] | 4415 | load_state_host_ = url_formatter::IDNToUnicode( |
| 4416 | url.host(), |
| 4417 | GetContentClient()->browser()->GetAcceptLangs(GetBrowserContext())); |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 4418 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4419 | SetNotWaitingForResponse(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4420 | if (IsLoading()) { |
[email protected] | 7f92483 | 2014-08-09 05:57:22 | [diff] [blame] | 4421 | NotifyNavigationStateChanged(static_cast<InvalidateTypes>( |
| 4422 | INVALIDATE_TYPE_LOAD | INVALIDATE_TYPE_TAB)); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 4423 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4424 | } |
| 4425 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4426 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | feaded0 | 2012-09-25 19:12:55 | [diff] [blame] | 4427 | bool proceed, const base::TimeTicks& proceed_time, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4428 | bool* proceed_to_fire_unload) { |
[email protected] | 6d65a46 | 2013-06-21 21:29:12 | [diff] [blame] | 4429 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4430 | BeforeUnloadFired(proceed_time)); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 4431 | if (delegate_) |
| 4432 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | e80af49 | 2013-06-24 21:52:09 | [diff] [blame] | 4433 | // Note: |this| might be deleted at this point. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4434 | } |
| 4435 | |
[email protected] | 58d5cfe | 2013-07-10 02:40:52 | [diff] [blame] | 4436 | void WebContentsImpl::RenderProcessGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4437 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 4438 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
[email protected] | ec6a7eb | 2013-04-22 17:34:22 | [diff] [blame] | 4439 | RenderViewTerminated(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4440 | } |
| 4441 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4442 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 4443 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4444 | gfx::Size size = GetSizeForNewRenderView(); |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 4445 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 4446 | // here during container initialization and normal window size will be set |
| 4447 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 4448 | // normal size later so just ignore it. |
| 4449 | if (!size.IsEmpty()) |
| 4450 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4451 | } |
| 4452 | |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 4453 | void WebContentsImpl::CancelModalDialogsForRenderManager() { |
| 4454 | // We need to cancel modal dialogs when doing a process swap, since the load |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 4455 | // deferrer would prevent us from swapping out. We also clear the state |
| 4456 | // because this is a cross-process navigation, which means that it's a new |
| 4457 | // site that should not have to pay for the sins of its predecessor. |
creis | 89a0f78 | 2015-05-27 16:13:17 | [diff] [blame] | 4458 | // |
| 4459 | // Note that we don't bother telling browser_plugin_embedder_ because the |
| 4460 | // cross-process navigation will either destroy the browser plugins or not |
| 4461 | // require their dialogs to close. |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 4462 | if (dialog_manager_) |
avi | 2460c76 | 2015-04-17 15:21:54 | [diff] [blame] | 4463 | dialog_manager_->ResetDialogState(this); |
[email protected] | af90590 | 2013-10-01 21:38:51 | [diff] [blame] | 4464 | } |
| 4465 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4466 | void WebContentsImpl::NotifySwappedFromRenderManager(RenderFrameHost* old_host, |
| 4467 | RenderFrameHost* new_host, |
| 4468 | bool is_main_frame) { |
| 4469 | if (is_main_frame) { |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 4470 | NotifyViewSwapped(old_host ? old_host->GetRenderViewHost() : nullptr, |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4471 | new_host->GetRenderViewHost()); |
[email protected] | a6b73c6 | 2013-02-11 23:05:08 | [diff] [blame] | 4472 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4473 | // Make sure the visible RVH reflects the new delegate's preferences. |
| 4474 | if (delegate_) |
| 4475 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
[email protected] | d56a49e | 2013-02-23 00:47:39 | [diff] [blame] | 4476 | |
[email protected] | 02d7b6e | 2014-06-24 21:01:50 | [diff] [blame] | 4477 | view_->RenderViewSwappedIn(new_host->GetRenderViewHost()); |
| 4478 | } |
| 4479 | |
| 4480 | NotifyFrameSwapped(old_host, new_host); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4481 | } |
| 4482 | |
nasko | f5940b9f | 2015-03-02 23:04:05 | [diff] [blame] | 4483 | void WebContentsImpl::NotifyMainFrameSwappedFromRenderManager( |
| 4484 | RenderViewHost* old_host, |
| 4485 | RenderViewHost* new_host) { |
| 4486 | NotifyViewSwapped(old_host, new_host); |
| 4487 | } |
| 4488 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4489 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | d1198fd | 2012-08-13 22:50:19 | [diff] [blame] | 4490 | return GetController(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 4491 | } |
| 4492 | |
carlosk | 35f35af | 2015-12-01 10:55:40 | [diff] [blame] | 4493 | scoped_ptr<WebUIImpl> WebContentsImpl::CreateWebUIForRenderFrameHost( |
carlosk | 37f79379 | 2014-11-27 15:08:29 | [diff] [blame] | 4494 | const GURL& url) { |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 4495 | return scoped_ptr<WebUIImpl>(static_cast<WebUIImpl*>(CreateWebUI( |
| 4496 | url, std::string()))); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4497 | } |
| 4498 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 4499 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4500 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4501 | return controller_.GetLastCommittedEntry(); |
| 4502 | } |
| 4503 | |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4504 | void WebContentsImpl::CreateRenderWidgetHostViewForRenderManager( |
| 4505 | RenderViewHost* render_view_host) { |
| 4506 | RenderWidgetHostViewBase* rwh_view = nullptr; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4507 | bool is_guest_in_site_per_process = |
| 4508 | !!browser_plugin_guest_.get() && |
nick | d30fd96 | 2015-07-27 21:51:08 | [diff] [blame] | 4509 | BrowserPluginGuestMode::UseCrossProcessFramesForGuests(); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4510 | if (is_guest_in_site_per_process) { |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 4511 | RenderWidgetHostViewChildFrame* rwh_view_child = |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4512 | new RenderWidgetHostViewChildFrame(render_view_host->GetWidget()); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 4513 | rwh_view = rwh_view_child; |
| 4514 | } else { |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4515 | rwh_view = view_->CreateViewForWidget(render_view_host->GetWidget(), false); |
[email protected] | bffc830 | 2014-01-23 20:52:16 | [diff] [blame] | 4516 | } |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 4517 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4518 | // 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] | 4519 | if (rwh_view) |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4520 | rwh_view->SetSize(GetSizeForNewRenderView()); |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4521 | } |
| 4522 | |
| 4523 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
| 4524 | RenderViewHost* render_view_host, |
| 4525 | int opener_frame_routing_id, |
| 4526 | int proxy_routing_id, |
| 4527 | const FrameReplicationState& replicated_frame_state) { |
| 4528 | TRACE_EVENT0("browser,navigation", |
| 4529 | "WebContentsImpl::CreateRenderViewForRenderManager"); |
| 4530 | |
| 4531 | if (proxy_routing_id == MSG_ROUTING_NONE) |
| 4532 | CreateRenderWidgetHostViewForRenderManager(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4533 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 4534 | // Make sure we use the correct starting page_id in the new RenderView. |
| 4535 | UpdateMaxPageIDIfNecessary(render_view_host); |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 4536 | int32_t max_page_id = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 4537 | GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance()); |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 4538 | |
alexmos | 5ac402d | 2015-07-09 07:51:10 | [diff] [blame] | 4539 | if (!static_cast<RenderViewHostImpl*>(render_view_host) |
| 4540 | ->CreateRenderView(opener_frame_routing_id, proxy_routing_id, |
| 4541 | max_page_id, replicated_frame_state, |
| 4542 | created_with_opener_)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 4543 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 4544 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 4545 | |
avi | 2b17759 | 2014-12-10 02:08:02 | [diff] [blame] | 4546 | SetHistoryOffsetAndLengthForView(render_view_host, |
| 4547 | controller_.GetLastCommittedEntryIndex(), |
| 4548 | controller_.GetEntryCount()); |
| 4549 | |
[email protected] | a220b593 | 2013-09-21 03:47:44 | [diff] [blame] | 4550 | #if defined(OS_POSIX) && !defined(OS_MACOSX) && !defined(OS_ANDROID) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 4551 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 4552 | // linux. See crbug.com/83941. |
avi | f9ab5d94 | 2015-10-15 14:05:44 | [diff] [blame] | 4553 | RenderWidgetHostView* rwh_view = render_view_host->GetWidget()->GetView(); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 4554 | if (rwh_view) { |
| 4555 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 4556 | render_widget_host->WasResized(); |
| 4557 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 4558 | #endif |
| 4559 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 4560 | return true; |
| 4561 | } |
| 4562 | |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4563 | bool WebContentsImpl::CreateRenderFrameForRenderManager( |
| 4564 | RenderFrameHost* render_frame_host, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4565 | int proxy_routing_id, |
| 4566 | int opener_routing_id, |
japhet | e6adf14 | 2014-10-31 00:01:49 | [diff] [blame] | 4567 | int parent_routing_id, |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4568 | int previous_sibling_routing_id) { |
nasko | b8744d2 | 2014-08-28 17:07:43 | [diff] [blame] | 4569 | TRACE_EVENT0("browser,navigation", |
| 4570 | "WebContentsImpl::CreateRenderFrameForRenderManager"); |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4571 | |
| 4572 | RenderFrameHostImpl* rfh = |
| 4573 | static_cast<RenderFrameHostImpl*>(render_frame_host); |
alexmos | a181efc | 2015-09-03 00:39:04 | [diff] [blame] | 4574 | if (!rfh->CreateRenderFrame(proxy_routing_id, opener_routing_id, |
| 4575 | parent_routing_id, previous_sibling_routing_id)) |
[email protected] | 82307f6b | 2014-08-07 03:30:12 | [diff] [blame] | 4576 | return false; |
| 4577 | |
| 4578 | // TODO(nasko): When RenderWidgetHost is owned by RenderFrameHost, the passed |
| 4579 | // RenderFrameHost will have to be associated with the appropriate |
| 4580 | // RenderWidgetHostView or a new one should be created here. |
| 4581 | |
| 4582 | return true; |
| 4583 | } |
| 4584 | |
mfomitchev | 2b8b066a | 2016-01-28 19:23:15 | [diff] [blame] | 4585 | #if defined(OS_ANDROID) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4586 | |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4587 | base::android::ScopedJavaLocalRef<jobject> |
| 4588 | WebContentsImpl::GetJavaWebContents() { |
mostynb | 042582e | 2015-03-16 22:13:40 | [diff] [blame] | 4589 | DCHECK_CURRENTLY_ON(BrowserThread::UI); |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4590 | return GetWebContentsAndroid()->GetJavaObject(); |
| 4591 | } |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4592 | |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4593 | WebContentsAndroid* WebContentsImpl::GetWebContentsAndroid() { |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4594 | WebContentsAndroid* web_contents_android = |
| 4595 | static_cast<WebContentsAndroid*>(GetUserData(kWebContentsAndroidKey)); |
| 4596 | if (!web_contents_android) { |
| 4597 | web_contents_android = new WebContentsAndroid(this); |
| 4598 | SetUserData(kWebContentsAndroidKey, web_contents_android); |
| 4599 | } |
[email protected] | 0e813a5 | 2014-08-13 10:34:56 | [diff] [blame] | 4600 | return web_contents_android; |
[email protected] | 155c7f2 | 2013-12-09 17:07:18 | [diff] [blame] | 4601 | } |
| 4602 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4603 | bool WebContentsImpl::CreateRenderViewForInitialEmptyDocument() { |
nasko | 4c0feb6 | 2015-06-05 18:37:06 | [diff] [blame] | 4604 | return CreateRenderViewForRenderManager( |
| 4605 | GetRenderViewHost(), MSG_ROUTING_NONE, MSG_ROUTING_NONE, |
lfg | bede639 | 2015-09-11 21:54:06 | [diff] [blame] | 4606 | frame_tree_.root()->current_replication_state()); |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4607 | } |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4608 | |
| 4609 | #elif defined(OS_MACOSX) |
| 4610 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 4611 | void WebContentsImpl::SetAllowOtherViews(bool allow) { |
| 4612 | view_->SetAllowOtherViews(allow); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4613 | } |
| 4614 | |
[email protected] | 75f4df7 | 2014-07-16 22:39:42 | [diff] [blame] | 4615 | bool WebContentsImpl::GetAllowOtherViews() { |
| 4616 | return view_->GetAllowOtherViews(); |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4617 | } |
| 4618 | |
[email protected] | 7d244f1 | 2013-08-22 21:41:51 | [diff] [blame] | 4619 | #endif |
| 4620 | |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4621 | void WebContentsImpl::OnDialogClosed(int render_process_id, |
| 4622 | int render_frame_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4623 | IPC::Message* reply_msg, |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4624 | bool dialog_was_suppressed, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4625 | bool success, |
[email protected] | fcf75d4 | 2013-12-03 20:11:26 | [diff] [blame] | 4626 | const base::string16& user_input) { |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4627 | RenderFrameHostImpl* rfh = RenderFrameHostImpl::FromID(render_process_id, |
| 4628 | render_frame_id); |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4629 | last_dialog_suppressed_ = dialog_was_suppressed; |
| 4630 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4631 | if (is_showing_before_unload_dialog_ && !success) { |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 4632 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 4633 | // spinning, since we forced it to start spinning in Navigate. |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4634 | if (rfh) |
waffles | 1c12bf40 | 2016-02-10 17:45:48 | [diff] [blame] | 4635 | DidStopLoading(); |
[email protected] | 15d160c0 | 2012-07-04 10:52:35 | [diff] [blame] | 4636 | controller_.DiscardNonCommittedEntries(); |
[email protected] | ec8e8b0 | 2013-06-19 04:57:10 | [diff] [blame] | 4637 | |
[email protected] | 6d65a46 | 2013-06-21 21:29:12 | [diff] [blame] | 4638 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 4639 | BeforeUnloadDialogCancelled()); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4640 | } |
[email protected] | 87de04b0 | 2014-04-08 22:14:49 | [diff] [blame] | 4641 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4642 | is_showing_before_unload_dialog_ = false; |
[email protected] | 6fba26d | 2014-04-29 09:38:28 | [diff] [blame] | 4643 | if (rfh) { |
| 4644 | rfh->JavaScriptDialogClosed(reply_msg, success, user_input, |
| 4645 | dialog_was_suppressed); |
| 4646 | } else { |
| 4647 | // Don't leak the sync IPC reply if the RFH or process is gone. |
| 4648 | delete reply_msg; |
| 4649 | } |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 4650 | } |
| 4651 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 4652 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | ef3adfc | 2014-05-11 00:04:54 | [diff] [blame] | 4653 | if (encoding == last_reported_encoding_) |
| 4654 | return; |
| 4655 | last_reported_encoding_ = encoding; |
| 4656 | |
| 4657 | canonical_encoding_ = GetContentClient()->browser()-> |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 4658 | GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 4659 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 4660 | |
[email protected] | 1ac10dca | 2013-08-20 20:47:04 | [diff] [blame] | 4661 | bool WebContentsImpl::IsHidden() { |
| 4662 | return capturer_count_ == 0 && !should_normally_be_visible_; |
| 4663 | } |
| 4664 | |
rob | 9725074 | 2015-12-10 17:45:15 | [diff] [blame] | 4665 | int WebContentsImpl::GetOuterDelegateFrameTreeNodeId() { |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4666 | if (node_ && node_->outer_web_contents()) |
| 4667 | return node_->outer_contents_frame_tree_node_id(); |
| 4668 | |
nick | 2482a2d | 2015-12-18 01:39:37 | [diff] [blame] | 4669 | return FrameTreeNode::kFrameTreeNodeInvalidId; |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4670 | } |
| 4671 | |
[email protected] | b0936d2 | 2013-11-28 06:47:36 | [diff] [blame] | 4672 | RenderFrameHostManager* WebContentsImpl::GetRenderManager() const { |
[email protected] | fa944cb8 | 2013-11-15 17:51:21 | [diff] [blame] | 4673 | return frame_tree_.root()->render_manager(); |
| 4674 | } |
| 4675 | |
lazyboy | 8e16ddfd | 2015-09-28 03:41:56 | [diff] [blame] | 4676 | WebContentsImpl* WebContentsImpl::GetOuterWebContents() { |
| 4677 | if (BrowserPluginGuestMode::UseCrossProcessFramesForGuests()) { |
| 4678 | if (node_) |
| 4679 | return node_->outer_web_contents(); |
| 4680 | } else { |
| 4681 | if (GetBrowserPluginGuest()) |
| 4682 | return GetBrowserPluginGuest()->embedder_web_contents(); |
| 4683 | } |
| 4684 | return nullptr; |
| 4685 | } |
| 4686 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 4687 | BrowserPluginGuest* WebContentsImpl::GetBrowserPluginGuest() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4688 | return browser_plugin_guest_.get(); |
| 4689 | } |
| 4690 | |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 4691 | void WebContentsImpl::SetBrowserPluginGuest(BrowserPluginGuest* guest) { |
| 4692 | CHECK(!browser_plugin_guest_); |
lazyboy | 6ec48b2a | 2015-06-29 15:18:14 | [diff] [blame] | 4693 | CHECK(guest); |
[email protected] | 738f57a | 2013-06-29 21:06:54 | [diff] [blame] | 4694 | browser_plugin_guest_.reset(guest); |
| 4695 | } |
| 4696 | |
[email protected] | f849734 | 2013-02-05 22:15:02 | [diff] [blame] | 4697 | BrowserPluginEmbedder* WebContentsImpl::GetBrowserPluginEmbedder() const { |
[email protected] | 7a846df | 2012-09-20 19:17:39 | [diff] [blame] | 4698 | return browser_plugin_embedder_.get(); |
| 4699 | } |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4700 | |
fsamuel | 60b4228 | 2015-03-10 03:29:14 | [diff] [blame] | 4701 | void WebContentsImpl::CreateBrowserPluginEmbedderIfNecessary() { |
| 4702 | if (browser_plugin_embedder_) |
| 4703 | return; |
| 4704 | browser_plugin_embedder_.reset(BrowserPluginEmbedder::Create(this)); |
| 4705 | } |
| 4706 | |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4707 | gfx::Size WebContentsImpl::GetSizeForNewRenderView() { |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4708 | gfx::Size size; |
| 4709 | if (delegate_) |
| 4710 | size = delegate_->GetSizeForNewRenderView(this); |
| 4711 | if (size.IsEmpty()) |
[email protected] | fc2b46b | 2014-05-03 16:33:45 | [diff] [blame] | 4712 | size = GetContainerBounds().size(); |
[email protected] | dc0fd43 | 2013-08-27 15:29:21 | [diff] [blame] | 4713 | return size; |
| 4714 | } |
| 4715 | |
[email protected] | ae7eeda | 2014-07-04 01:53:26 | [diff] [blame] | 4716 | void WebContentsImpl::OnFrameRemoved(RenderFrameHost* render_frame_host) { |
| 4717 | FOR_EACH_OBSERVER( |
nasko | 00528252 | 2015-01-22 02:30:02 | [diff] [blame] | 4718 | WebContentsObserver, observers_, FrameDeleted(render_frame_host)); |
[email protected] | 9b159a5 | 2013-10-03 17:24:55 | [diff] [blame] | 4719 | } |
| 4720 | |
[email protected] | 222f582 | 2014-02-05 23:40:49 | [diff] [blame] | 4721 | void WebContentsImpl::OnPreferredSizeChanged(const gfx::Size& old_size) { |
| 4722 | if (!delegate_) |
| 4723 | return; |
| 4724 | const gfx::Size new_size = GetPreferredSize(); |
| 4725 | if (new_size != old_size) |
| 4726 | delegate_->UpdatePreferredSize(this, new_size); |
| 4727 | } |
| 4728 | |
dbeam | a1b926a | 2015-08-31 23:17:51 | [diff] [blame] | 4729 | WebUI* WebContentsImpl::CreateWebUI(const GURL& url, |
| 4730 | const std::string& frame_name) { |
| 4731 | WebUIImpl* web_ui = new WebUIImpl(this, frame_name); |
| 4732 | WebUIController* controller = WebUIControllerFactoryRegistry::GetInstance()-> |
| 4733 | CreateWebUIControllerForURL(web_ui, url); |
| 4734 | if (controller) { |
| 4735 | web_ui->AddMessageHandler(new GenericHandler()); |
| 4736 | web_ui->SetController(controller); |
| 4737 | return web_ui; |
| 4738 | } |
| 4739 | |
| 4740 | delete web_ui; |
| 4741 | return NULL; |
| 4742 | } |
| 4743 | |
[email protected] | 34ff1cfc | 2014-08-20 06:16:05 | [diff] [blame] | 4744 | void WebContentsImpl::SetForceDisableOverscrollContent(bool force_disable) { |
| 4745 | force_disable_overscroll_content_ = force_disable; |
| 4746 | if (view_) |
| 4747 | view_->SetOverscrollControllerEnabled(CanOverscrollContent()); |
| 4748 | } |
| 4749 | |
dalecurtis | 88c24007 | 2015-12-09 02:11:18 | [diff] [blame] | 4750 | void WebContentsImpl::MediaStartedPlaying( |
| 4751 | const WebContentsObserver::MediaPlayerId& id) { |
| 4752 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStartedPlaying(id)); |
| 4753 | } |
| 4754 | |
| 4755 | void WebContentsImpl::MediaStoppedPlaying( |
| 4756 | const WebContentsObserver::MediaPlayerId& id) { |
| 4757 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, MediaStoppedPlaying(id)); |
| 4758 | } |
| 4759 | |
[email protected] | 8ff00d7 | 2012-10-23 19:12:21 | [diff] [blame] | 4760 | } // namespace content |