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