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