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