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