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