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