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