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