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