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