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