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