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