[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] | 835d7c8 | 2010-10-14 04:38:38 | [diff] [blame] | 10 | #include "base/metrics/histogram.h" |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 11 | #include "base/metrics/stats_counters.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 12 | #include "base/string16.h" |
[email protected] | 43d9d78 | 2012-03-01 15:40:09 | [diff] [blame] | 13 | #include "base/string_number_conversions.h" |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 14 | #include "base/string_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 15 | #include "base/time.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 16 | #include "base/utf_string_conversions.h" |
[email protected] | 172cf71 | 2012-05-23 15:07:39 | [diff] [blame] | 17 | #include "content/browser/browser_plugin/browser_plugin_host.h" |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 18 | #include "content/browser/child_process_security_policy_impl.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 19 | #include "content/browser/debugger/devtools_manager_impl.h" |
[email protected] | 1ea3c79 | 2012-04-17 01:25:04 | [diff] [blame] | 20 | #include "content/browser/dom_storage/session_storage_namespace_impl.h" |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 21 | #include "content/browser/download/download_stats.h" |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 22 | #include "content/browser/download/mhtml_generation_manager.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 23 | #include "content/browser/download/save_package.h" |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 24 | #include "content/browser/gpu/gpu_data_manager_impl.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 25 | #include "content/browser/gpu/gpu_process_host.h" |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 26 | #include "content/browser/host_zoom_map_impl.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 27 | #include "content/browser/intents/web_intents_dispatcher_impl.h" |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 28 | #include "content/browser/load_from_memory_cache_details.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 29 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | b3c41c0b | 2012-03-06 15:48:32 | [diff] [blame] | 30 | #include "content/browser/renderer_host/render_view_host_impl.h" |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 31 | #include "content/browser/renderer_host/render_widget_host_impl.h" |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 32 | #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 33 | #include "content/browser/site_instance_impl.h" |
[email protected] | f9e4dae | 2012-04-10 21:26:37 | [diff] [blame] | 34 | #include "content/browser/web_contents/interstitial_page_impl.h" |
| 35 | #include "content/browser/web_contents/navigation_entry_impl.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 36 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 37 | #include "content/common/intents_messages.h" |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 38 | #include "content/common/ssl_status_serialization.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 39 | #include "content/common/view_messages.h" |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 40 | #include "content/port/browser/render_view_host_delegate_view.h" |
[email protected] | 5626b089 | 2012-02-20 14:46:58 | [diff] [blame] | 41 | #include "content/port/browser/render_widget_host_view_port.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 42 | #include "content/public/browser/browser_context.h" |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 43 | #include "content/public/browser/color_chooser.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 44 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 45 | #include "content/public/browser/devtools_agent_host_registry.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 46 | #include "content/public/browser/download_manager.h" |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 47 | #include "content/public/browser/download_url_parameters.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 48 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 32f497b | 2012-01-30 20:33:15 | [diff] [blame] | 49 | #include "content/public/browser/javascript_dialogs.h" |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 50 | #include "content/public/browser/load_notification_details.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 51 | #include "content/public/browser/navigation_details.h" |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 52 | #include "content/public/browser/notification_details.h" |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 53 | #include "content/public/browser/notification_service.h" |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 54 | #include "content/public/browser/resource_request_details.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 55 | #include "content/public/browser/user_metrics.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 56 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 57 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 58 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 59 | #include "content/public/browser/web_ui_controller_factory.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 60 | #include "content/public/common/bindings_policy.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 61 | #include "content/public/common/content_constants.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 62 | #include "content/public/common/content_restriction.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 63 | #include "content/public/common/content_switches.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 64 | #include "content/public/common/url_constants.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 65 | #include "net/base/mime_util.h" |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 66 | #include "net/base/net_util.h" |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 67 | #include "net/base/network_change_notifier.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 68 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 302fe42 | 2012-06-11 14:49:11 | [diff] [blame] | 69 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositor.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 70 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 71 | #include "ui/base/layout.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 72 | #include "ui/base/ui_base_switches.h" |
[email protected] | 7da9c4c | 2012-06-12 14:43:01 | [diff] [blame] | 73 | #include "ui/gfx/display.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 74 | #include "ui/gfx/screen.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 75 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 76 | #include "webkit/glue/web_intent_service_data.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 77 | #include "webkit/glue/webpreferences.h" |
| 78 | |
[email protected] | f66df82 | 2012-05-18 16:52:17 | [diff] [blame] | 79 | #if defined(OS_MACOSX) |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 80 | #include "base/mac/foundation_util.h" |
[email protected] | d353541f | 2012-05-03 22:45:41 | [diff] [blame] | 81 | #include "ui/surface/io_surface_support_mac.h" |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 82 | #endif |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 83 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 84 | // Cross-Site Navigations |
| 85 | // |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 86 | // If a WebContentsImpl is told to navigate to a different web site (as |
| 87 | // determined by SiteInstance), it will replace its current RenderViewHost with |
| 88 | // a new RenderViewHost dedicated to the new SiteInstance. This works as |
| 89 | // follows: |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 90 | // |
| 91 | // - Navigate determines whether the destination is cross-site, and if so, |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 92 | // it creates a pending_render_view_host_. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 93 | // - The pending RVH is "suspended," so that no navigation messages are sent to |
| 94 | // its renderer until the onbeforeunload JavaScript handler has a chance to |
| 95 | // run in the current RVH. |
| 96 | // - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton) |
| 97 | // that it has a pending cross-site request. ResourceDispatcherHost will |
| 98 | // check for this when the response arrives. |
| 99 | // - The current RVH runs its onbeforeunload handler. If it returns false, we |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 100 | // cancel all the pending logic. Otherwise we allow the pending RVH to send |
| 101 | // the navigation request to its renderer. |
| 102 | // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the |
| 103 | // main resource load on the pending RVH. It checks CrossSiteRequestManager |
| 104 | // to see that it is a cross-site request, and installs a |
| 105 | // CrossSiteResourceHandler. |
| 106 | // - When RDH receives a response, the BufferedResourceHandler determines |
| 107 | // whether it is a download. If so, it sends a message to the new renderer |
| 108 | // causing it to cancel the request, and the download proceeds. For now, the |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 109 | // pending RVH remains until the next DidNavigate event for this |
| 110 | // WebContentsImpl. This isn't ideal, but it doesn't affect any functionality. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 111 | // - After RDH receives a response and determines that it is safe and not a |
| 112 | // download, it pauses the response to first run the old page's onunload |
| 113 | // handler. It does this by asynchronously calling the OnCrossSiteResponse |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 114 | // method of WebContentsImpl on the UI thread, which sends a SwapOut message |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 115 | // to the current RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 116 | // - Once the onunload handler is finished, a SwapOut_ACK message is sent to |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 117 | // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 118 | // to the pending RVH. |
| 119 | // - The pending renderer sends a FrameNavigate message that invokes the |
| 120 | // DidNavigate method. This replaces the current RVH with the |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 121 | // pending RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 122 | // - The previous renderer is kept swapped out in RenderViewHostManager in case |
| 123 | // the user goes back. The process only stays live if another tab is using |
| 124 | // it, but if so, the existing frame relationships will be maintained. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 125 | |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 126 | using content::BrowserContext; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 127 | using content::DevToolsAgentHost; |
| 128 | using content::DevToolsAgentHostRegistry; |
| 129 | using content::DevToolsManagerImpl; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 130 | using content::DownloadItem; |
| 131 | using content::DownloadManager; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 132 | using content::DownloadUrlParameters; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 133 | using content::GlobalRequestID; |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 134 | using content::HostZoomMap; |
[email protected] | cadaec5 | 2012-02-08 21:53:13 | [diff] [blame] | 135 | using content::InterstitialPage; |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 136 | using content::LoadNotificationDetails; |
[email protected] | b87ee52 | 2012-05-18 15:16:54 | [diff] [blame] | 137 | using content::NativeWebKeyboardEvent; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 138 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 139 | using content::NavigationEntry; |
| 140 | using content::NavigationEntryImpl; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 141 | using content::OpenURLParams; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 142 | using content::RenderViewHost; |
[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 143 | using content::RenderViewHostDelegate; |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 144 | using content::RenderViewHostDelegateView; |
[email protected] | 09d31d5 | 2012-03-11 22:30:27 | [diff] [blame] | 145 | using content::RenderViewHostImpl; |
[email protected] | eaabba2 | 2012-03-07 15:02:11 | [diff] [blame] | 146 | using content::RenderWidgetHost; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 147 | using content::RenderWidgetHostImpl; |
[email protected] | 5626b089 | 2012-02-20 14:46:58 | [diff] [blame] | 148 | using content::RenderWidgetHostView; |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 149 | using content::RenderWidgetHostViewPort; |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 150 | using content::ResourceDispatcherHostImpl; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 151 | using content::SSLStatus; |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 152 | using content::SessionStorageNamespace; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 153 | using content::SiteInstance; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 154 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 155 | using content::WebContents; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 156 | using content::WebContentsObserver; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 157 | using content::WebUI; |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 158 | using content::WebUIController; |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 159 | using content::WebUIControllerFactory; |
[email protected] | 6717bf27 | 2012-05-11 23:31:25 | [diff] [blame] | 160 | using webkit_glue::WebPreferences; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 161 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 162 | namespace { |
| 163 | |
| 164 | // Amount of time we wait between when a key event is received and the renderer |
| 165 | // is queried for its state and pushed to the NavigationEntry. |
| 166 | const int kQueryStateDelay = 5000; |
| 167 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 168 | const int kSyncWaitDelay = 40; |
| 169 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 170 | const char kDotGoogleDotCom[] = ".google.com"; |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 171 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 172 | #if defined(OS_WIN) |
| 173 | |
| 174 | BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 175 | // Note: erase is required to properly paint some widgets borders. This can |
| 176 | // be seen with textfields. |
| 177 | InvalidateRect(hwnd, NULL, TRUE); |
| 178 | return TRUE; |
| 179 | } |
| 180 | #endif |
| 181 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 182 | ViewMsg_Navigate_Type::Value GetNavigationType( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 183 | content::BrowserContext* browser_context, const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 184 | NavigationController::ReloadType reload_type) { |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 185 | switch (reload_type) { |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 186 | case NavigationControllerImpl::RELOAD: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 187 | return ViewMsg_Navigate_Type::RELOAD; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 188 | case NavigationControllerImpl::RELOAD_IGNORING_CACHE: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 189 | return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 190 | case NavigationControllerImpl::NO_RELOAD: |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 191 | break; // Fall through to rest of function. |
| 192 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 193 | |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 194 | // |RenderViewImpl::PopulateStateFromPendingNavigationParams| differentiates |
| 195 | // between |RESTORE_WITH_POST| and |RESTORE|. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 196 | if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION && |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 197 | browser_context->DidLastSessionExitCleanly()) { |
| 198 | if (entry.GetHasPostData()) |
| 199 | return ViewMsg_Navigate_Type::RESTORE_WITH_POST; |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 200 | return ViewMsg_Navigate_Type::RESTORE; |
[email protected] | 59246c57 | 2012-02-10 13:32:13 | [diff] [blame] | 201 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 202 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 203 | return ViewMsg_Navigate_Type::NORMAL; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 204 | } |
| 205 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 206 | void MakeNavigateParams(const NavigationEntryImpl& entry, |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 207 | const NavigationControllerImpl& controller, |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 208 | content::WebContentsDelegate* delegate, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 209 | NavigationController::ReloadType reload_type, |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 210 | const std::string& embedder_channel_name, |
| 211 | int embedder_container_id, |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 212 | ViewMsg_Navigate_Params* params) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 213 | params->page_id = entry.GetPageID(); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 214 | params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 215 | params->current_history_list_offset = controller.GetLastCommittedEntryIndex(); |
| 216 | params->current_history_list_length = controller.GetEntryCount(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 217 | params->url = entry.GetURL(); |
| 218 | params->referrer = entry.GetReferrer(); |
| 219 | params->transition = entry.GetTransitionType(); |
| 220 | params->state = entry.GetContentState(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 221 | params->navigation_type = |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 222 | GetNavigationType(controller.GetBrowserContext(), entry, reload_type); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 223 | params->request_time = base::Time::Now(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 224 | params->extra_headers = entry.extra_headers(); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 225 | params->transferred_request_child_id = |
| 226 | entry.transferred_global_request_id().child_id; |
| 227 | params->transferred_request_request_id = |
| 228 | entry.transferred_global_request_id().request_id; |
[email protected] | 8074478 | 2012-05-04 01:47:00 | [diff] [blame] | 229 | // Avoid downloading when in view-source mode. |
| 230 | params->allow_download = !entry.IsViewSourceMode(); |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 231 | params->embedder_channel_name = embedder_channel_name; |
| 232 | params->embedder_container_id = embedder_container_id; |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 233 | |
| 234 | if (delegate) |
| 235 | delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 236 | } |
| 237 | |
[email protected] | f98f509 | 2012-05-19 00:08:14 | [diff] [blame] | 238 | int GetSwitchValueAsInt( |
| 239 | const CommandLine& command_line, |
| 240 | const std::string& switch_string, |
| 241 | int min_value) { |
| 242 | std::string string_value = command_line.GetSwitchValueASCII(switch_string); |
| 243 | int int_value; |
| 244 | if (base::StringToInt(string_value, &int_value)) |
| 245 | return std::max(min_value, int_value); |
| 246 | else |
| 247 | return min_value; |
| 248 | } |
| 249 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 250 | } // namespace |
| 251 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 252 | namespace content { |
| 253 | |
| 254 | WebContents* WebContents::Create( |
| 255 | BrowserContext* browser_context, |
| 256 | SiteInstance* site_instance, |
| 257 | int routing_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 258 | const WebContents* base_web_contents, |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 259 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 260 | return new WebContentsImpl( |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 261 | browser_context, |
| 262 | site_instance, |
| 263 | routing_id, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 264 | static_cast<const WebContentsImpl*>(base_web_contents), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 265 | NULL, |
[email protected] | adbfb8df | 2012-02-24 01:19:43 | [diff] [blame] | 266 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace)); |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 267 | } |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 268 | |
[email protected] | 299d7f1 | 2012-05-23 05:31:15 | [diff] [blame] | 269 | WebContents* WebContents::FromRenderViewHost(const RenderViewHost* rvh) { |
[email protected] | 746d305 | 2012-05-22 15:15:47 | [diff] [blame] | 270 | return rvh->GetDelegate()->GetAsWebContents(); |
| 271 | } |
| 272 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 273 | } |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 274 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 275 | // WebContentsImpl ------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 276 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 277 | WebContentsImpl::WebContentsImpl( |
| 278 | content::BrowserContext* browser_context, |
| 279 | SiteInstance* site_instance, |
| 280 | int routing_id, |
| 281 | const WebContentsImpl* base_web_contents, |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 282 | WebContentsImpl* opener, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 283 | SessionStorageNamespaceImpl* session_storage_namespace) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 284 | : delegate_(NULL), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 285 | ALLOW_THIS_IN_INITIALIZER_LIST(controller_( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 286 | this, browser_context, session_storage_namespace)), |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 287 | render_view_host_delegate_view_(NULL), |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 288 | opener_(opener), |
[email protected] | 4ca76c0 | 2012-05-16 16:19:05 | [diff] [blame] | 289 | ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this, this)), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 290 | is_loading_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 291 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 292 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 293 | waiting_for_response_(false), |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 294 | load_state_(net::LOAD_STATE_IDLE, string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 295 | upload_size_(0), |
| 296 | upload_position_(0), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 297 | displayed_insecure_content_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 298 | capturing_contents_(false), |
| 299 | is_being_destroyed_(false), |
| 300 | notify_disconnection_(false), |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 301 | dialog_creator_(NULL), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 302 | #if defined(OS_WIN) |
| 303 | message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 304 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 305 | is_showing_before_unload_dialog_(false), |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 306 | opener_web_ui_type_(WebUI::kNoWebUI), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 307 | closed_by_user_gesture_(false), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 308 | minimum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 309 | static_cast<int>(content::kMinimumZoomFactor * 100)), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 310 | maximum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 311 | static_cast<int>(content::kMaximumZoomFactor * 100)), |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 312 | temporary_zoom_settings_(false), |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 313 | content_restrictions_(0), |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 314 | color_chooser_(NULL) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 315 | render_manager_.Init(browser_context, site_instance, routing_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 316 | |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 317 | view_.reset(content::GetContentClient()->browser()-> |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 318 | OverrideCreateWebContentsView(this, &render_view_host_delegate_view_)); |
| 319 | if (view_.get()) { |
| 320 | CHECK(render_view_host_delegate_view_); |
| 321 | } else { |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 322 | content::WebContentsViewDelegate* delegate = |
| 323 | content::GetContentClient()->browser()->GetWebContentsViewDelegate( |
| 324 | this); |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 325 | view_.reset(CreateWebContentsView( |
| 326 | this, delegate, &render_view_host_delegate_view_)); |
| 327 | CHECK(render_view_host_delegate_view_); |
[email protected] | 38b098f | 2012-03-14 21:11:57 | [diff] [blame] | 328 | } |
| 329 | CHECK(view_.get()); |
| 330 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 331 | // We have the initial size of the view be based on the size of the view of |
| 332 | // the passed in WebContents. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 333 | view_->CreateView(base_web_contents ? |
| 334 | base_web_contents->GetView()->GetContainerSize() : gfx::Size()); |
[email protected] | 483623eb | 2011-10-25 09:30:00 | [diff] [blame] | 335 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 336 | // Listen for whether our opener gets destroyed. |
| 337 | if (opener_) { |
| 338 | registrar_.Add(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 339 | content::Source<WebContents>(opener_)); |
| 340 | } |
| 341 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 342 | registrar_.Add(this, |
| 343 | content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
| 344 | content::NotificationService::AllBrowserContextsAndSources()); |
| 345 | |
[email protected] | 483623eb | 2011-10-25 09:30:00 | [diff] [blame] | 346 | #if defined(ENABLE_JAVA_BRIDGE) |
| 347 | java_bridge_dispatcher_host_manager_.reset( |
| 348 | new JavaBridgeDispatcherHostManager(this)); |
| 349 | #endif |
[email protected] | 172cf71 | 2012-05-23 15:07:39 | [diff] [blame] | 350 | |
| 351 | browser_plugin_host_.reset(new content::BrowserPluginHost(this)); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 352 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 353 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 354 | WebContentsImpl::~WebContentsImpl() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 355 | is_being_destroyed_ = true; |
| 356 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 357 | // Clear out any JavaScript state. |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 358 | if (dialog_creator_) |
| 359 | dialog_creator_->ResetJavaScriptState(this); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 360 | |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 361 | if (color_chooser_) |
| 362 | color_chooser_->End(); |
| 363 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 364 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 365 | |
[email protected] | ca13a44 | 2012-04-17 14:00:12 | [diff] [blame] | 366 | // Notify any observer that have a reference on this WebContents. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 367 | content::NotificationService::current()->Notify( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 368 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 369 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 370 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 371 | |
| 372 | // TODO(brettw) this should be moved to the view. |
[email protected] | 010882f | 2011-11-14 22:32:07 | [diff] [blame] | 373 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 374 | // If we still have a window handle, destroy it. GetNativeView can return |
| 375 | // NULL if this contents was part of a window that closed. |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 376 | if (GetNativeView()) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 377 | RenderViewHost* host = GetRenderViewHost(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 378 | if (host && host->GetView()) |
| 379 | RenderWidgetHostViewPort::FromRWHV(host->GetView())->WillWmDestroy(); |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 380 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 381 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 382 | |
| 383 | // OnCloseStarted isn't called in unit tests. |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 384 | if (!close_start_time_.is_null()) { |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 385 | UMA_HISTOGRAM_TIMES("Tab.Close", |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 386 | base::TimeTicks::Now() - close_start_time_); |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 387 | } |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 388 | |
[email protected] | 2db9bd7 | 2012-04-13 20:20:56 | [diff] [blame] | 389 | FOR_EACH_OBSERVER(WebContentsObserver, |
| 390 | observers_, |
| 391 | WebContentsImplDestroyed()); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 392 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 393 | SetDelegate(NULL); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 394 | } |
| 395 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 396 | WebPreferences WebContentsImpl::GetWebkitPrefs(RenderViewHost* rvh, |
| 397 | const GURL& url) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 398 | WebPreferences prefs; |
| 399 | |
| 400 | const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 401 | |
| 402 | prefs.developer_extras_enabled = true; |
| 403 | prefs.javascript_enabled = |
| 404 | !command_line.HasSwitch(switches::kDisableJavaScript); |
| 405 | prefs.web_security_enabled = |
| 406 | !command_line.HasSwitch(switches::kDisableWebSecurity); |
| 407 | prefs.plugins_enabled = |
| 408 | !command_line.HasSwitch(switches::kDisablePlugins); |
| 409 | prefs.java_enabled = |
| 410 | !command_line.HasSwitch(switches::kDisableJava); |
| 411 | |
| 412 | prefs.uses_page_cache = |
| 413 | command_line.HasSwitch(switches::kEnableFastback); |
| 414 | prefs.remote_fonts_enabled = |
| 415 | !command_line.HasSwitch(switches::kDisableRemoteFonts); |
| 416 | prefs.xss_auditor_enabled = |
| 417 | !command_line.HasSwitch(switches::kDisableXSSAuditor); |
| 418 | prefs.application_cache_enabled = |
| 419 | !command_line.HasSwitch(switches::kDisableApplicationCache); |
| 420 | |
| 421 | prefs.local_storage_enabled = |
| 422 | !command_line.HasSwitch(switches::kDisableLocalStorage); |
| 423 | prefs.databases_enabled = |
| 424 | !command_line.HasSwitch(switches::kDisableDatabases); |
| 425 | prefs.webaudio_enabled = |
| 426 | !command_line.HasSwitch(switches::kDisableWebAudio); |
| 427 | |
| 428 | prefs.experimental_webgl_enabled = |
| 429 | GpuProcessHost::gpu_enabled() && |
| 430 | !command_line.HasSwitch(switches::kDisable3DAPIs) && |
| 431 | !command_line.HasSwitch(switches::kDisableExperimentalWebGL); |
| 432 | |
[email protected] | 5a07309 | 2012-06-08 00:42:51 | [diff] [blame] | 433 | prefs.flash_3d_enabled = |
| 434 | GpuProcessHost::gpu_enabled() && |
| 435 | !command_line.HasSwitch(switches::kDisableFlash3d); |
| 436 | prefs.flash_stage3d_enabled = |
| 437 | GpuProcessHost::gpu_enabled() && |
| 438 | !command_line.HasSwitch(switches::kDisableFlashStage3d); |
[email protected] | e0d8c42 | 2012-06-04 22:57:19 | [diff] [blame] | 439 | |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 440 | prefs.gl_multisampling_enabled = |
| 441 | !command_line.HasSwitch(switches::kDisableGLMultisampling); |
| 442 | prefs.privileged_webgl_extensions_enabled = |
| 443 | command_line.HasSwitch(switches::kEnablePrivilegedWebGLExtensions); |
| 444 | prefs.site_specific_quirks_enabled = |
| 445 | !command_line.HasSwitch(switches::kDisableSiteSpecificQuirks); |
| 446 | prefs.allow_file_access_from_file_urls = |
| 447 | command_line.HasSwitch(switches::kAllowFileAccessFromFiles); |
| 448 | prefs.show_composited_layer_borders = |
| 449 | command_line.HasSwitch(switches::kShowCompositedLayerBorders); |
| 450 | prefs.show_composited_layer_tree = |
| 451 | command_line.HasSwitch(switches::kShowCompositedLayerTree); |
| 452 | prefs.show_fps_counter = |
| 453 | command_line.HasSwitch(switches::kShowFPSCounter); |
[email protected] | 8611a85 | 2012-05-23 22:11:19 | [diff] [blame] | 454 | prefs.show_paint_rects = |
| 455 | command_line.HasSwitch(switches::kShowPaintRects); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 456 | prefs.accelerated_compositing_enabled = |
| 457 | GpuProcessHost::gpu_enabled() && |
| 458 | !command_line.HasSwitch(switches::kDisableAcceleratedCompositing); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 459 | prefs.force_compositing_mode = |
| 460 | command_line.HasSwitch(switches::kForceCompositingMode); |
| 461 | prefs.fixed_position_compositing_enabled = |
| 462 | command_line.HasSwitch(switches::kEnableCompositingForFixedPosition); |
| 463 | prefs.accelerated_2d_canvas_enabled = |
| 464 | GpuProcessHost::gpu_enabled() && |
| 465 | !command_line.HasSwitch(switches::kDisableAccelerated2dCanvas); |
[email protected] | e1f6bdd | 2012-02-07 21:52:58 | [diff] [blame] | 466 | prefs.deferred_2d_canvas_enabled = |
[email protected] | 00bbad2 | 2012-05-25 13:24:17 | [diff] [blame] | 467 | !command_line.HasSwitch(switches::kDisableDeferred2dCanvas); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 468 | prefs.accelerated_painting_enabled = |
| 469 | GpuProcessHost::gpu_enabled() && |
| 470 | command_line.HasSwitch(switches::kEnableAcceleratedPainting); |
| 471 | prefs.accelerated_filters_enabled = |
| 472 | GpuProcessHost::gpu_enabled() && |
| 473 | command_line.HasSwitch(switches::kEnableAcceleratedFilters); |
| 474 | prefs.accelerated_layers_enabled = |
| 475 | prefs.accelerated_animation_enabled = |
| 476 | !command_line.HasSwitch(switches::kDisableAcceleratedLayers); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 477 | prefs.accelerated_plugins_enabled = |
| 478 | !command_line.HasSwitch(switches::kDisableAcceleratedPlugins); |
| 479 | prefs.accelerated_video_enabled = |
| 480 | !command_line.HasSwitch(switches::kDisableAcceleratedVideo); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 481 | prefs.interactive_form_validation_enabled = |
| 482 | !command_line.HasSwitch(switches::kDisableInteractiveFormValidation); |
| 483 | prefs.fullscreen_enabled = |
| 484 | !command_line.HasSwitch(switches::kDisableFullScreen); |
[email protected] | 37ac2a8 | 2012-03-01 05:30:16 | [diff] [blame] | 485 | prefs.css_regions_enabled = |
| 486 | command_line.HasSwitch(switches::kEnableCssRegions); |
[email protected] | bc19958 | 2012-03-29 09:02:29 | [diff] [blame] | 487 | prefs.css_shaders_enabled = |
| 488 | command_line.HasSwitch(switches::kEnableCssShaders); |
[email protected] | a08412b6 | 2012-05-29 21:28:56 | [diff] [blame] | 489 | prefs.device_supports_touch = |
| 490 | ui::GetDisplayLayout() == ui::LAYOUT_TOUCH; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 491 | |
| 492 | #if defined(OS_MACOSX) |
| 493 | bool default_enable_scroll_animator = true; |
| 494 | #else |
| 495 | // On CrOS, the launcher always passes in the --enable flag. |
| 496 | bool default_enable_scroll_animator = false; |
| 497 | #endif |
| 498 | prefs.enable_scroll_animator = default_enable_scroll_animator; |
| 499 | if (command_line.HasSwitch(switches::kEnableSmoothScrolling)) |
| 500 | prefs.enable_scroll_animator = true; |
| 501 | if (command_line.HasSwitch(switches::kDisableSmoothScrolling)) |
| 502 | prefs.enable_scroll_animator = false; |
| 503 | |
| 504 | prefs.visual_word_movement_enabled = |
| 505 | command_line.HasSwitch(switches::kEnableVisualWordMovement); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 506 | |
| 507 | { // Certain GPU features might have been blacklisted. |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 508 | GpuDataManagerImpl* gpu_data_manager = GpuDataManagerImpl::GetInstance(); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 509 | DCHECK(gpu_data_manager); |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 510 | uint32 blacklist_type = gpu_data_manager->GetGpuFeatureType(); |
| 511 | if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_COMPOSITING) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 512 | prefs.accelerated_compositing_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 513 | if (blacklist_type & content::GPU_FEATURE_TYPE_WEBGL) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 514 | prefs.experimental_webgl_enabled = false; |
[email protected] | e0d8c42 | 2012-06-04 22:57:19 | [diff] [blame] | 515 | if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH3D) |
| 516 | prefs.flash_3d_enabled = false; |
| 517 | if (blacklist_type & content::GPU_FEATURE_TYPE_FLASH_STAGE3D) |
| 518 | prefs.flash_stage3d_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 519 | if (blacklist_type & content::GPU_FEATURE_TYPE_ACCELERATED_2D_CANVAS) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 520 | prefs.accelerated_2d_canvas_enabled = false; |
[email protected] | d56ecf92 | 2012-02-15 16:03:11 | [diff] [blame] | 521 | if (blacklist_type & content::GPU_FEATURE_TYPE_MULTISAMPLING) |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 522 | prefs.gl_multisampling_enabled = false; |
| 523 | |
| 524 | // Accelerated video and animation are slower than regular when using a |
[email protected] | 2ffd73d | 2012-03-02 17:33:45 | [diff] [blame] | 525 | // software 3d rasterizer. 3D CSS may also be too slow to be worthwhile. |
[email protected] | 79078df | 2012-02-16 01:22:32 | [diff] [blame] | 526 | if (gpu_data_manager->ShouldUseSoftwareRendering()) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 527 | prefs.accelerated_video_enabled = false; |
| 528 | prefs.accelerated_animation_enabled = false; |
[email protected] | 2ffd73d | 2012-03-02 17:33:45 | [diff] [blame] | 529 | prefs.accelerated_layers_enabled = false; |
[email protected] | 428e820 | 2012-05-16 00:08:09 | [diff] [blame] | 530 | prefs.accelerated_plugins_enabled = false; |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 531 | } |
| 532 | } |
| 533 | |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 534 | if (ChildProcessSecurityPolicyImpl::GetInstance()->HasWebUIBindings( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 535 | rvh->GetProcess()->GetID())) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 536 | prefs.loads_images_automatically = true; |
| 537 | prefs.javascript_enabled = true; |
| 538 | } |
| 539 | |
| 540 | prefs.is_online = !net::NetworkChangeNotifier::IsOffline(); |
| 541 | |
| 542 | // Force accelerated compositing and 2d canvas off for chrome:, about: and |
| 543 | // chrome-devtools: pages (unless it's specifically allowed). |
| 544 | if ((url.SchemeIs(chrome::kChromeDevToolsScheme) || |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 545 | url.SchemeIs(chrome::kChromeUIScheme) || |
| 546 | (url.SchemeIs(chrome::kAboutScheme) && |
| 547 | url.spec() != chrome::kAboutBlankURL)) && |
[email protected] | b049fbd4 | 2012-02-08 02:03:25 | [diff] [blame] | 548 | !command_line.HasSwitch(switches::kAllowWebUICompositing)) { |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 549 | prefs.accelerated_compositing_enabled = false; |
| 550 | prefs.accelerated_2d_canvas_enabled = false; |
| 551 | } |
[email protected] | 43d9d78 | 2012-03-01 15:40:09 | [diff] [blame] | 552 | |
[email protected] | 302fe42 | 2012-06-11 14:49:11 | [diff] [blame] | 553 | #if !defined(WEBCOMPOSITOR_OWNS_SETTINGS) |
| 554 | prefs.threaded_animation_enabled = |
| 555 | !command_line.HasSwitch(switches::kDisableThreadedAnimation); |
| 556 | prefs.per_tile_painting_enabled = |
| 557 | command_line.HasSwitch(switches::kEnablePerTilePainting); |
| 558 | prefs.partial_swap_enabled = |
| 559 | command_line.HasSwitch(switches::kEnablePartialSwap); |
| 560 | #endif |
| 561 | |
[email protected] | f98f509 | 2012-05-19 00:08:14 | [diff] [blame] | 562 | if (command_line.HasSwitch(switches::kDefaultTileWidth)) |
| 563 | prefs.default_tile_width = |
| 564 | GetSwitchValueAsInt(command_line, switches::kDefaultTileWidth, 1); |
| 565 | if (command_line.HasSwitch(switches::kDefaultTileHeight)) |
| 566 | prefs.default_tile_height = |
| 567 | GetSwitchValueAsInt(command_line, switches::kDefaultTileHeight, 1); |
| 568 | if (command_line.HasSwitch(switches::kMaxUntiledLayerWidth)) |
| 569 | prefs.max_untiled_layer_width = |
| 570 | GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerWidth, 1); |
| 571 | if (command_line.HasSwitch(switches::kMaxUntiledLayerHeight)) |
| 572 | prefs.max_untiled_layer_height = |
| 573 | GetSwitchValueAsInt(command_line, switches::kMaxUntiledLayerHeight, 1); |
| 574 | |
[email protected] | 2486dce | 2012-05-23 17:18:19 | [diff] [blame] | 575 | if (gfx::Screen::IsDIPEnabled()) { |
| 576 | // Only apply when using DIP coordinate system as this setting interferes |
| 577 | // with fixed layout mode. |
| 578 | prefs.apply_default_device_scale_factor_in_compositor = true; |
| 579 | } |
| 580 | |
[email protected] | 96bcdc10 | 2012-05-24 23:42:10 | [diff] [blame] | 581 | prefs.fixed_position_creates_stacking_context = |
| 582 | command_line.HasSwitch(switches::kFixedPositionCreatesStackingContext); |
| 583 | |
[email protected] | 2e21fe29 | 2012-03-02 22:52:32 | [diff] [blame] | 584 | content::GetContentClient()->browser()->OverrideWebkitPrefs(rvh, url, &prefs); |
[email protected] | 64d69de4 | 2012-02-06 00:19:54 | [diff] [blame] | 585 | |
| 586 | return prefs; |
| 587 | } |
| 588 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 589 | NavigationControllerImpl& WebContentsImpl::GetControllerImpl() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 590 | return controller_; |
| 591 | } |
| 592 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 593 | RenderViewHostManager* WebContentsImpl::GetRenderManagerForTesting() { |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 594 | return &render_manager_; |
| 595 | } |
| 596 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 597 | bool WebContentsImpl::OnMessageReceived(const IPC::Message& message) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 598 | if (GetWebUI() && |
| 599 | static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 600 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 601 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 602 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 603 | ObserverListBase<WebContentsObserver>::Iterator it(observers_); |
| 604 | WebContentsObserver* observer; |
[email protected] | 0f180ee | 2011-01-21 18:23:10 | [diff] [blame] | 605 | while ((observer = it.GetNext()) != NULL) |
| 606 | if (observer->OnMessageReceived(message)) |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 607 | return true; |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 608 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 609 | bool handled = true; |
| 610 | bool message_is_ok = true; |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 611 | IPC_BEGIN_MESSAGE_MAP_EX(WebContentsImpl, message, message_is_ok) |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 612 | IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService, |
| 613 | OnRegisterIntentService) |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 614 | IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch, |
| 615 | OnWebIntentDispatch) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 616 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, |
| 617 | OnDidLoadResourceFromMemoryCache) |
| 618 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, |
| 619 | OnDidDisplayInsecureContent) |
| 620 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, |
| 621 | OnDidRunInsecureContent) |
| 622 | IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame, |
| 623 | OnDocumentLoadedInFrame) |
| 624 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad) |
[email protected] | 9bf6ee9f | 2012-04-11 11:07:26 | [diff] [blame] | 625 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailLoadWithError, |
| 626 | OnDidFailLoadWithError) |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 627 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions, |
| 628 | OnUpdateContentRestrictions) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 629 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 630 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 631 | IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 632 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 633 | IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
| 634 | IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
| 635 | OnRegisterProtocolHandler) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 636 | IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 637 | IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 638 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 639 | IPC_MESSAGE_HANDLER(ViewHostMsg_OpenColorChooser, OnOpenColorChooser) |
| 640 | IPC_MESSAGE_HANDLER(ViewHostMsg_EndColorChooser, OnEndColorChooser) |
| 641 | IPC_MESSAGE_HANDLER(ViewHostMsg_SetSelectedColorInColorChooser, |
| 642 | OnSetSelectedColorInColorChooser) |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 643 | IPC_MESSAGE_HANDLER(ViewHostMsg_PepperPluginHung, OnPepperPluginHung) |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 644 | IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 645 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 646 | IPC_END_MESSAGE_MAP_EX() |
| 647 | |
| 648 | if (!message_is_ok) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 649 | content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 650 | GetRenderProcessHost()->ReceivedBadMessage(); |
| 651 | } |
| 652 | |
| 653 | return handled; |
| 654 | } |
| 655 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 656 | void WebContentsImpl::RunFileChooser( |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 657 | RenderViewHost* render_view_host, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 658 | const content::FileChooserParams& params) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 659 | delegate_->RunFileChooser(this, params); |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 660 | } |
| 661 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 662 | NavigationController& WebContentsImpl::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 663 | return controller_; |
| 664 | } |
| 665 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 666 | const NavigationController& WebContentsImpl::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 667 | return controller_; |
| 668 | } |
| 669 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 670 | content::BrowserContext* WebContentsImpl::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 671 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 674 | const GURL& WebContentsImpl::GetURL() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 675 | // We may not have a navigation entry yet |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 676 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 677 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 681 | const base::PropertyBag* WebContentsImpl::GetPropertyBag() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 682 | return &property_bag_; |
| 683 | } |
| 684 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 685 | base::PropertyBag* WebContentsImpl::GetPropertyBag() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 686 | return &property_bag_; |
| 687 | } |
| 688 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 689 | content::WebContentsDelegate* WebContentsImpl::GetDelegate() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 690 | return delegate_; |
| 691 | } |
| 692 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 693 | void WebContentsImpl::SetDelegate(content::WebContentsDelegate* delegate) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 694 | // TODO(cbentzel): remove this debugging code? |
| 695 | if (delegate == delegate_) |
| 696 | return; |
| 697 | if (delegate_) |
| 698 | delegate_->Detach(this); |
| 699 | delegate_ = delegate; |
| 700 | if (delegate_) |
| 701 | delegate_->Attach(this); |
| 702 | } |
| 703 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 704 | content::RenderProcessHost* WebContentsImpl::GetRenderProcessHost() const { |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 705 | RenderViewHostImpl* host = render_manager_.current_host(); |
| 706 | return host ? host->GetProcess() : NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 707 | } |
| 708 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 709 | RenderViewHost* WebContentsImpl::GetRenderViewHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 710 | return render_manager_.current_host(); |
| 711 | } |
| 712 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 713 | RenderWidgetHostView* WebContentsImpl::GetRenderWidgetHostView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 714 | return render_manager_.GetRenderWidgetHostView(); |
| 715 | } |
| 716 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 717 | content::WebContentsView* WebContentsImpl::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 718 | return view_.get(); |
| 719 | } |
| 720 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 721 | content::WebUI* WebContentsImpl::CreateWebUI(const GURL& url) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 722 | WebUIControllerFactory* factory = |
| 723 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 724 | if (!factory) |
| 725 | return NULL; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 726 | WebUIImpl* web_ui = new WebUIImpl(this); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 727 | WebUIController* controller = |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 728 | factory->CreateWebUIControllerForURL(web_ui, url); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 729 | if (controller) { |
| 730 | web_ui->SetController(controller); |
| 731 | return web_ui; |
| 732 | } |
| 733 | |
| 734 | delete web_ui; |
| 735 | return NULL; |
| 736 | } |
| 737 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 738 | content::WebUI* WebContentsImpl::GetWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 739 | return render_manager_.web_ui() ? render_manager_.web_ui() |
| 740 | : render_manager_.pending_web_ui(); |
| 741 | } |
| 742 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 743 | content::WebUI* WebContentsImpl::GetCommittedWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 744 | return render_manager_.web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 747 | void WebContentsImpl::SetUserAgentOverride(const std::string& override) { |
| 748 | user_agent_override_ = override; |
| 749 | } |
| 750 | |
| 751 | const std::string& WebContentsImpl::GetUserAgentOverride() const { |
| 752 | return user_agent_override_; |
| 753 | } |
| 754 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 755 | const string16& WebContentsImpl::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 756 | // Transient entries take precedence. They are used for interstitial pages |
| 757 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 758 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 759 | std::string accept_languages = |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 760 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 761 | GetBrowserContext()); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 762 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 763 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 764 | } |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 765 | WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
| 766 | render_manager_.pending_web_ui() : render_manager_.web_ui(); |
| 767 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 768 | // Don't override the title in view source mode. |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 769 | entry = controller_.GetActiveEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 770 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 771 | // Give the Web UI the chance to override our title. |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 772 | const string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 773 | if (!title.empty()) |
| 774 | return title; |
| 775 | } |
| 776 | } |
| 777 | |
| 778 | // We use the title for the last committed entry rather than a pending |
| 779 | // navigation entry. For example, when the user types in a URL, we want to |
| 780 | // keep the old page's title until the new load has committed and we get a new |
| 781 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 782 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 783 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 784 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 785 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 786 | |
| 787 | // |page_title_when_no_navigation_entry_| is finally used |
| 788 | // if no title cannot be retrieved. |
| 789 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 790 | } |
| 791 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 792 | int32 WebContentsImpl::GetMaxPageID() { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 793 | return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
| 794 | } |
| 795 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 796 | int32 WebContentsImpl::GetMaxPageIDForSiteInstance( |
| 797 | SiteInstance* site_instance) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 798 | if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
| 799 | max_page_ids_[site_instance->GetId()] = -1; |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 800 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 801 | return max_page_ids_[site_instance->GetId()]; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 802 | } |
| 803 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 804 | void WebContentsImpl::UpdateMaxPageID(int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 805 | UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); |
| 806 | } |
| 807 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 808 | void WebContentsImpl::UpdateMaxPageIDForSiteInstance( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 809 | SiteInstance* site_instance, int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 810 | if (GetMaxPageIDForSiteInstance(site_instance) < page_id) |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 811 | max_page_ids_[site_instance->GetId()] = page_id; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 812 | } |
| 813 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 814 | void WebContentsImpl::CopyMaxPageIDsFrom(WebContentsImpl* web_contents) { |
| 815 | max_page_ids_ = web_contents->max_page_ids_; |
[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 816 | } |
| 817 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 818 | SiteInstance* WebContentsImpl::GetSiteInstance() const { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 819 | return render_manager_.current_host()->GetSiteInstance(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 820 | } |
| 821 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 822 | SiteInstance* WebContentsImpl::GetPendingSiteInstance() const { |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 823 | RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ? |
| 824 | render_manager_.pending_render_view_host() : |
| 825 | render_manager_.current_host(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 826 | return dest_rvh->GetSiteInstance(); |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 827 | } |
| 828 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 829 | bool WebContentsImpl::IsLoading() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 830 | return is_loading_; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 831 | } |
| 832 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 833 | bool WebContentsImpl::IsWaitingForResponse() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 834 | return waiting_for_response_; |
| 835 | } |
| 836 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 837 | const net::LoadStateWithParam& WebContentsImpl::GetLoadState() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 838 | return load_state_; |
| 839 | } |
| 840 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 841 | const string16& WebContentsImpl::GetLoadStateHost() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 842 | return load_state_host_; |
| 843 | } |
| 844 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 845 | uint64 WebContentsImpl::GetUploadSize() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 846 | return upload_size_; |
| 847 | } |
| 848 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 849 | uint64 WebContentsImpl::GetUploadPosition() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 850 | return upload_position_; |
| 851 | } |
| 852 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 853 | const std::string& WebContentsImpl::GetEncoding() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 854 | return encoding_; |
| 855 | } |
| 856 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 857 | bool WebContentsImpl::DisplayedInsecureContent() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 858 | return displayed_insecure_content_; |
| 859 | } |
| 860 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 861 | void WebContentsImpl::SetCapturingContents(bool cap) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 862 | capturing_contents_ = cap; |
| 863 | } |
| 864 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 865 | bool WebContentsImpl::IsCrashed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 866 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 867 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
| 868 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 869 | } |
| 870 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 871 | void WebContentsImpl::SetIsCrashed(base::TerminationStatus status, |
| 872 | int error_code) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 873 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 874 | return; |
| 875 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 876 | crashed_status_ = status; |
| 877 | crashed_error_code_ = error_code; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 878 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 879 | } |
| 880 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 881 | base::TerminationStatus WebContentsImpl::GetCrashedStatus() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 882 | return crashed_status_; |
| 883 | } |
| 884 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 885 | bool WebContentsImpl::IsBeingDestroyed() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 886 | return is_being_destroyed_; |
| 887 | } |
| 888 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 889 | void WebContentsImpl::NotifyNavigationStateChanged(unsigned changed_flags) { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 890 | if (delegate_) |
| 891 | delegate_->NavigationStateChanged(this, changed_flags); |
| 892 | } |
| 893 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 894 | void WebContentsImpl::DidBecomeSelected() { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 895 | controller_.SetActive(true); |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 896 | RenderWidgetHostViewPort* rwhv = |
| 897 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 898 | if (rwhv) { |
| 899 | rwhv->DidBecomeSelected(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 900 | #if defined(OS_MACOSX) |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 901 | rwhv->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 902 | #endif |
| 903 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 904 | |
[email protected] | 5ac2016 | 2010-11-24 23:33:11 | [diff] [blame] | 905 | last_selected_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 906 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 907 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected()); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 908 | |
| 909 | // The resize rect might have changed while this was inactive -- send the new |
| 910 | // one to make sure it's up to date. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 911 | RenderViewHostImpl* rvh = |
| 912 | static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
[email protected] | b9769d8 | 2012-02-10 00:23:59 | [diff] [blame] | 913 | if (rvh) { |
| 914 | rvh->ResizeRectChanged(GetRootWindowResizerRect()); |
| 915 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 916 | } |
| 917 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 918 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 919 | base::TimeTicks WebContentsImpl::GetLastSelectedTime() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 920 | return last_selected_time_; |
| 921 | } |
| 922 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 923 | void WebContentsImpl::WasHidden() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 924 | if (!capturing_contents_) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 925 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 926 | // open a tab in then background, then closes the tab before selecting it. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 927 | // This is because closing the tab calls WebContentsImpl::Destroy(), which |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 928 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 929 | // window, OnWindowPosChanged() notices and calls HideContents() (which |
| 930 | // calls us). |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 931 | RenderWidgetHostViewPort* rwhv = |
| 932 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 933 | if (rwhv) |
| 934 | rwhv->WasHidden(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 935 | } |
| 936 | |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 937 | bool is_visible = false; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 938 | content::NotificationService::current()->Notify( |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 939 | content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 940 | content::Source<WebContents>(this), |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 941 | content::Details<bool>(&is_visible)); |
| 942 | } |
| 943 | |
| 944 | void WebContentsImpl::WasRestored() { |
| 945 | bool is_visible = true; |
| 946 | content::NotificationService::current()->Notify( |
| 947 | content::NOTIFICATION_WEB_CONTENTS_VISIBILITY_CHANGED, |
| 948 | content::Source<WebContents>(this), |
| 949 | content::Details<bool>(&is_visible)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 950 | } |
| 951 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 952 | void WebContentsImpl::ShowContents() { |
[email protected] | c30585c | 2012-02-16 15:02:04 | [diff] [blame] | 953 | RenderWidgetHostViewPort* rwhv = |
| 954 | RenderWidgetHostViewPort::FromRWHV(GetRenderWidgetHostView()); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 955 | if (rwhv) |
| 956 | rwhv->DidBecomeSelected(); |
[email protected] | 375fa1b | 2012-05-22 22:05:37 | [diff] [blame] | 957 | WasRestored(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 958 | } |
| 959 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 960 | void WebContentsImpl::HideContents() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 961 | // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 962 | // our superclass HideContents(), because some callers want to be very picky |
| 963 | // about the order in which these get called. In addition to making the code |
| 964 | // here practically impossible to understand, this also means we end up |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 965 | // calling WebContentsImpl::WasHidden() twice if callers call both versions of |
| 966 | // HideContents() on a WebContentsImpl. |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 967 | WasHidden(); |
| 968 | } |
| 969 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 970 | bool WebContentsImpl::NeedToFireBeforeUnload() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 971 | // TODO(creis): Should we fire even for interstitial pages? |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 972 | return WillNotifyDisconnection() && |
| 973 | !ShowingInterstitialPage() && |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 974 | !static_cast<RenderViewHostImpl*>( |
| 975 | GetRenderViewHost())->SuddenTerminationAllowed(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 976 | } |
| 977 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 978 | void WebContentsImpl::Stop() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 979 | render_manager_.Stop(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 980 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 983 | WebContents* WebContentsImpl::Clone() { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 984 | // We use our current SiteInstance since the cloned entry will use it anyway. |
| 985 | // We pass |this| for the |base_web_contents| to size the view correctly, and |
| 986 | // our own opener so that the cloned page can access it if it was before. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 987 | WebContentsImpl* tc = new WebContentsImpl( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 988 | GetBrowserContext(), GetSiteInstance(), |
| 989 | MSG_ROUTING_NONE, this, opener_, NULL); |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 990 | tc->GetControllerImpl().CopyStateFrom(controller_); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 991 | return tc; |
| 992 | } |
| 993 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 994 | void WebContentsImpl::AddNewContents(WebContents* new_contents, |
| 995 | WindowOpenDisposition disposition, |
| 996 | const gfx::Rect& initial_pos, |
| 997 | bool user_gesture) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 998 | if (!delegate_) |
| 999 | return; |
| 1000 | |
| 1001 | delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 1002 | user_gesture); |
| 1003 | } |
| 1004 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1005 | gfx::NativeView WebContentsImpl::GetContentNativeView() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1006 | return view_->GetContentNativeView(); |
| 1007 | } |
| 1008 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1009 | gfx::NativeView WebContentsImpl::GetNativeView() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1010 | return view_->GetNativeView(); |
| 1011 | } |
| 1012 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1013 | void WebContentsImpl::GetContainerBounds(gfx::Rect* out) const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1014 | view_->GetContainerBounds(out); |
| 1015 | } |
| 1016 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1017 | void WebContentsImpl::Focus() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1018 | view_->Focus(); |
| 1019 | } |
| 1020 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1021 | void WebContentsImpl::Observe(int type, |
| 1022 | const content::NotificationSource& source, |
| 1023 | const content::NotificationDetails& details) { |
| 1024 | switch (type) { |
| 1025 | case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: |
| 1026 | OnWebContentsDestroyed( |
| 1027 | content::Source<content::WebContents>(source).ptr()); |
| 1028 | break; |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1029 | case content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED: { |
| 1030 | RenderWidgetHost* host = content::Source<RenderWidgetHost>(source).ptr(); |
| 1031 | for (PendingWidgetViews::iterator i = pending_widget_views_.begin(); |
| 1032 | i != pending_widget_views_.end(); ++i) { |
| 1033 | if (host->GetView() == i->second) { |
| 1034 | pending_widget_views_.erase(i); |
| 1035 | break; |
| 1036 | } |
| 1037 | } |
| 1038 | break; |
| 1039 | } |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1040 | default: |
| 1041 | NOTREACHED(); |
| 1042 | } |
| 1043 | } |
| 1044 | |
| 1045 | void WebContentsImpl::OnWebContentsDestroyed(WebContents* web_contents) { |
| 1046 | // Clear the opener if it has been closed. |
| 1047 | if (web_contents == opener_) { |
| 1048 | registrar_.Remove(this, content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 1049 | content::Source<WebContents>(opener_)); |
| 1050 | opener_ = NULL; |
| 1051 | } |
| 1052 | } |
| 1053 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1054 | void WebContentsImpl::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1055 | observers_.AddObserver(observer); |
| 1056 | } |
| 1057 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1058 | void WebContentsImpl::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1059 | observers_.RemoveObserver(observer); |
| 1060 | } |
| 1061 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1062 | void WebContentsImpl::Activate() { |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1063 | if (delegate_) |
| 1064 | delegate_->ActivateContents(this); |
| 1065 | } |
| 1066 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1067 | void WebContentsImpl::Deactivate() { |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 1068 | if (delegate_) |
| 1069 | delegate_->DeactivateContents(this); |
| 1070 | } |
| 1071 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1072 | void WebContentsImpl::LostCapture() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1073 | if (delegate_) |
| 1074 | delegate_->LostCapture(); |
| 1075 | } |
| 1076 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1077 | bool WebContentsImpl::PreHandleKeyboardEvent( |
| 1078 | const NativeWebKeyboardEvent& event, |
| 1079 | bool* is_keyboard_shortcut) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1080 | return delegate_ && |
| 1081 | delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 1082 | } |
| 1083 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1084 | void WebContentsImpl::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1085 | if (delegate_) |
| 1086 | delegate_->HandleKeyboardEvent(event); |
| 1087 | } |
| 1088 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1089 | void WebContentsImpl::HandleMouseDown() { |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 1090 | if (delegate_) |
| 1091 | delegate_->HandleMouseDown(); |
| 1092 | } |
| 1093 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1094 | void WebContentsImpl::HandleMouseUp() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1095 | if (delegate_) |
| 1096 | delegate_->HandleMouseUp(); |
| 1097 | } |
| 1098 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1099 | void WebContentsImpl::HandleMouseActivate() { |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 1100 | if (delegate_) |
| 1101 | delegate_->HandleMouseActivate(); |
| 1102 | } |
| 1103 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1104 | void WebContentsImpl::ToggleFullscreenMode(bool enter_fullscreen) { |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 1105 | if (delegate_) |
| 1106 | delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen); |
| 1107 | } |
| 1108 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1109 | bool WebContentsImpl::IsFullscreenForCurrentTab() const { |
[email protected] | 199bba6e | 2012-04-04 16:19:38 | [diff] [blame] | 1110 | return delegate_ ? delegate_->IsFullscreenForTabOrPending(this) : false; |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 1111 | } |
| 1112 | |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1113 | void WebContentsImpl::RequestToLockMouse(bool user_gesture, |
| 1114 | bool last_unlocked_by_target) { |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1115 | if (delegate_) { |
[email protected] | a9c81f0 | 2012-06-01 00:15:44 | [diff] [blame] | 1116 | delegate_->RequestToLockMouse(this, user_gesture, last_unlocked_by_target); |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1117 | } else { |
| 1118 | GotResponseToLockMouseRequest(false); |
| 1119 | } |
| 1120 | } |
| 1121 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1122 | void WebContentsImpl::LostMouseLock() { |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 1123 | if (delegate_) |
| 1124 | delegate_->LostMouseLock(); |
| 1125 | } |
| 1126 | |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1127 | void WebContentsImpl::CreateNewWindow( |
| 1128 | int route_id, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 1129 | const ViewHostMsg_CreateWindow_Params& params, |
| 1130 | SessionStorageNamespace* session_storage_namespace) { |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1131 | if (delegate_ && !delegate_->ShouldCreateWebContents( |
| 1132 | this, route_id, params.window_container_type, params.frame_name, |
| 1133 | params.target_url)) { |
| 1134 | return; |
| 1135 | } |
| 1136 | |
| 1137 | // We usually create the new window in the same BrowsingInstance (group of |
| 1138 | // script-related windows), by passing in the current SiteInstance. However, |
| 1139 | // if the opener is being suppressed, we create a new SiteInstance in its own |
| 1140 | // BrowsingInstance. |
| 1141 | scoped_refptr<SiteInstance> site_instance = |
| 1142 | params.opener_suppressed ? |
| 1143 | SiteInstance::Create(GetBrowserContext()) : |
| 1144 | GetSiteInstance(); |
| 1145 | |
| 1146 | // Create the new web contents. This will automatically create the new |
| 1147 | // WebContentsView. In the future, we may want to create the view separately. |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 1148 | WebContentsImpl* new_contents = new WebContentsImpl( |
| 1149 | GetBrowserContext(), |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 1150 | site_instance, |
| 1151 | route_id, |
| 1152 | this, |
| 1153 | params.opener_suppressed ? NULL : this, |
[email protected] | 97714c8 | 2012-06-06 10:15:13 | [diff] [blame] | 1154 | static_cast<SessionStorageNamespaceImpl*>(session_storage_namespace)); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1155 | new_contents->set_opener_web_ui_type(GetWebUITypeForCurrentState()); |
| 1156 | |
| 1157 | if (!params.opener_suppressed) { |
| 1158 | content::WebContentsView* new_view = new_contents->GetView(); |
| 1159 | |
| 1160 | // TODO(brettw): It seems bogus that we have to call this function on the |
| 1161 | // newly created object and give it one of its own member variables. |
| 1162 | new_view->CreateViewForWidget(new_contents->GetRenderViewHost()); |
| 1163 | |
| 1164 | // Save the created window associated with the route so we can show it |
| 1165 | // later. |
| 1166 | DCHECK_NE(MSG_ROUTING_NONE, route_id); |
| 1167 | pending_contents_[route_id] = new_contents; |
| 1168 | } |
| 1169 | |
| 1170 | if (delegate_) { |
| 1171 | delegate_->WebContentsCreated( |
| 1172 | this, params.opener_frame_id, params.target_url, new_contents); |
| 1173 | } |
| 1174 | |
| 1175 | if (params.opener_suppressed) { |
| 1176 | // When the opener is suppressed, the original renderer cannot access the |
| 1177 | // new window. As a result, we need to show and navigate the window here. |
| 1178 | gfx::Rect initial_pos; |
| 1179 | AddNewContents( |
| 1180 | new_contents, params.disposition, initial_pos, params.user_gesture); |
| 1181 | |
| 1182 | content::OpenURLParams open_params(params.target_url, content::Referrer(), |
| 1183 | CURRENT_TAB, |
| 1184 | content::PAGE_TRANSITION_LINK, |
| 1185 | true /* is_renderer_initiated */); |
| 1186 | new_contents->OpenURL(open_params); |
| 1187 | } |
| 1188 | } |
| 1189 | |
| 1190 | void WebContentsImpl::CreateNewWidget(int route_id, |
| 1191 | WebKit::WebPopupType popup_type) { |
| 1192 | CreateNewWidget(route_id, false, popup_type); |
| 1193 | } |
| 1194 | |
| 1195 | void WebContentsImpl::CreateNewFullscreenWidget(int route_id) { |
| 1196 | CreateNewWidget(route_id, true, WebKit::WebPopupTypeNone); |
| 1197 | } |
| 1198 | |
| 1199 | void WebContentsImpl::CreateNewWidget(int route_id, |
| 1200 | bool is_fullscreen, |
| 1201 | WebKit::WebPopupType popup_type) { |
| 1202 | content::RenderProcessHost* process = GetRenderProcessHost(); |
| 1203 | RenderWidgetHostImpl* widget_host = |
| 1204 | new RenderWidgetHostImpl(this, process, route_id); |
| 1205 | RenderWidgetHostViewPort* widget_view = |
| 1206 | RenderWidgetHostViewPort::CreateViewForWidget(widget_host); |
| 1207 | if (!is_fullscreen) { |
| 1208 | // Popups should not get activated. |
| 1209 | widget_view->SetPopupType(popup_type); |
| 1210 | } |
| 1211 | // Save the created widget associated with the route so we can show it later. |
| 1212 | pending_widget_views_[route_id] = widget_view; |
| 1213 | |
| 1214 | #if defined(OS_MACOSX) |
| 1215 | // A RenderWidgetHostViewMac has lifetime scoped to the view. We'll retain it |
| 1216 | // to allow it to survive the trip without being hosted. |
| 1217 | base::mac::NSObjectRetain(widget_view->GetNativeView()); |
| 1218 | #endif |
| 1219 | } |
| 1220 | |
| 1221 | void WebContentsImpl::ShowCreatedWindow(int route_id, |
| 1222 | WindowOpenDisposition disposition, |
| 1223 | const gfx::Rect& initial_pos, |
| 1224 | bool user_gesture) { |
| 1225 | WebContentsImpl* contents = GetCreatedWindow(route_id); |
| 1226 | if (contents) |
| 1227 | AddNewContents(contents, disposition, initial_pos, user_gesture); |
| 1228 | } |
| 1229 | |
| 1230 | void WebContentsImpl::ShowCreatedWidget(int route_id, |
| 1231 | const gfx::Rect& initial_pos) { |
| 1232 | ShowCreatedWidget(route_id, false, initial_pos); |
| 1233 | } |
| 1234 | |
| 1235 | void WebContentsImpl::ShowCreatedFullscreenWidget(int route_id) { |
| 1236 | ShowCreatedWidget(route_id, true, gfx::Rect()); |
| 1237 | } |
| 1238 | |
| 1239 | void WebContentsImpl::ShowCreatedWidget(int route_id, |
| 1240 | bool is_fullscreen, |
| 1241 | const gfx::Rect& initial_pos) { |
| 1242 | if (delegate_) |
| 1243 | delegate_->RenderWidgetShowing(); |
| 1244 | |
| 1245 | RenderWidgetHostViewPort* widget_host_view = |
| 1246 | RenderWidgetHostViewPort::FromRWHV(GetCreatedWidget(route_id)); |
| 1247 | if (!widget_host_view) |
| 1248 | return; |
| 1249 | if (is_fullscreen) { |
| 1250 | widget_host_view->InitAsFullscreen(GetRenderWidgetHostView()); |
| 1251 | } else { |
| 1252 | widget_host_view->InitAsPopup(GetRenderWidgetHostView(), initial_pos); |
| 1253 | } |
[email protected] | 8905450 | 2012-06-03 10:29:24 | [diff] [blame] | 1254 | |
| 1255 | RenderWidgetHostImpl* render_widget_host_impl = |
| 1256 | RenderWidgetHostImpl::From(widget_host_view->GetRenderWidgetHost()); |
| 1257 | render_widget_host_impl->Init(); |
| 1258 | // Only allow privileged mouse lock for fullscreen render widget, which is |
| 1259 | // used to implement Pepper Flash fullscreen. |
| 1260 | render_widget_host_impl->set_allow_privileged_mouse_lock(is_fullscreen); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1261 | |
| 1262 | #if defined(OS_MACOSX) |
| 1263 | // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's |
| 1264 | // properly embedded (or purposefully ignored) we can release the retain we |
| 1265 | // took in CreateNewWidget(). |
| 1266 | base::mac::NSObjectRelease(widget_host_view->GetNativeView()); |
| 1267 | #endif |
| 1268 | } |
| 1269 | |
| 1270 | WebContentsImpl* WebContentsImpl::GetCreatedWindow(int route_id) { |
| 1271 | PendingContents::iterator iter = pending_contents_.find(route_id); |
| 1272 | |
| 1273 | // Certain systems can block the creation of new windows. If we didn't succeed |
| 1274 | // in creating one, just return NULL. |
| 1275 | if (iter == pending_contents_.end()) { |
| 1276 | return NULL; |
| 1277 | } |
| 1278 | |
| 1279 | WebContentsImpl* new_contents = iter->second; |
| 1280 | pending_contents_.erase(route_id); |
| 1281 | |
| 1282 | if (!new_contents->GetRenderProcessHost()->HasConnection() || |
| 1283 | !new_contents->GetRenderViewHost()->GetView()) |
| 1284 | return NULL; |
| 1285 | |
| 1286 | // TODO(brettw): It seems bogus to reach into here and initialize the host. |
| 1287 | static_cast<RenderViewHostImpl*>(new_contents->GetRenderViewHost())->Init(); |
| 1288 | return new_contents; |
| 1289 | } |
| 1290 | |
| 1291 | RenderWidgetHostView* WebContentsImpl::GetCreatedWidget(int route_id) { |
| 1292 | PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id); |
| 1293 | if (iter == pending_widget_views_.end()) { |
| 1294 | DCHECK(false); |
| 1295 | return NULL; |
| 1296 | } |
| 1297 | |
| 1298 | RenderWidgetHostView* widget_host_view = iter->second; |
| 1299 | pending_widget_views_.erase(route_id); |
| 1300 | |
| 1301 | RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost(); |
| 1302 | if (!widget_host->GetProcess()->HasConnection()) { |
| 1303 | // The view has gone away or the renderer crashed. Nothing to do. |
| 1304 | return NULL; |
| 1305 | } |
| 1306 | |
| 1307 | return widget_host_view; |
| 1308 | } |
| 1309 | |
| 1310 | void WebContentsImpl::ShowContextMenu( |
| 1311 | const content::ContextMenuParams& params) { |
| 1312 | // Allow WebContentsDelegates to handle the context menu operation first. |
| 1313 | if (delegate_ && delegate_->HandleContextMenu(params)) |
| 1314 | return; |
| 1315 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 1316 | render_view_host_delegate_view_->ShowContextMenu(params); |
[email protected] | bafe6cd | 2012-05-23 23:09:50 | [diff] [blame] | 1317 | } |
| 1318 | |
[email protected] | f13b420 | 2012-06-12 23:53:23 | [diff] [blame^] | 1319 | void WebContentsImpl::RequestMediaAccessPermission( |
| 1320 | const content::MediaStreamRequest* request, |
| 1321 | const content::MediaResponseCallback& callback) { |
| 1322 | if (delegate_) |
| 1323 | delegate_->RequestMediaAccessPermission(this, request, callback); |
| 1324 | else |
| 1325 | callback.Run(content::MediaStreamDevices()); |
| 1326 | } |
| 1327 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1328 | void WebContentsImpl::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 1329 | preferred_size_ = pref_size; |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 1330 | if (delegate_) |
| 1331 | delegate_->UpdatePreferredSize(this, pref_size); |
| 1332 | } |
| 1333 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1334 | void WebContentsImpl::ResizeDueToAutoResize(const gfx::Size& new_size) { |
[email protected] | 61e2b3cc | 2012-03-02 16:13:34 | [diff] [blame] | 1335 | if (delegate_) |
| 1336 | delegate_->ResizeDueToAutoResize(this, new_size); |
| 1337 | } |
| 1338 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1339 | WebContents* WebContentsImpl::OpenURL(const OpenURLParams& params) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1340 | if (!delegate_) |
| 1341 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 1342 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1343 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 1344 | // Notify observers. |
| 1345 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1346 | DidOpenURL(params.url, params.referrer, |
| 1347 | params.disposition, params.transition)); |
| 1348 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1349 | } |
| 1350 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1351 | bool WebContentsImpl::NavigateToPendingEntry( |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1352 | NavigationController::ReloadType reload_type) { |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1353 | return NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1354 | *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()), |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1355 | reload_type); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 1356 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1357 | |
[email protected] | ba45bfd | 2012-05-22 21:51:44 | [diff] [blame] | 1358 | void WebContentsImpl::RenderViewForInterstitialPageCreated( |
| 1359 | content::RenderViewHost* render_view_host) { |
| 1360 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 1361 | RenderViewForInterstitialPageCreated(render_view_host)); |
| 1362 | } |
| 1363 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1364 | bool WebContentsImpl::NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1365 | const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1366 | NavigationController::ReloadType reload_type) { |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 1367 | // The renderer will reject IPC messages with URLs longer than |
| 1368 | // this limit, so don't attempt to navigate with a longer URL. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1369 | if (entry.GetURL().spec().size() > content::kMaxURLChars) |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 1370 | return false; |
| 1371 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1372 | RenderViewHostImpl* dest_render_view_host = |
| 1373 | static_cast<RenderViewHostImpl*>(render_manager_.Navigate(entry)); |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 1374 | if (!dest_render_view_host) |
| 1375 | return false; // Unable to create the desired render view host. |
| 1376 | |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1377 | // For security, we should never send non-Web-UI URLs to a Web UI renderer. |
[email protected] | 05fdd49 | 2010-11-15 17:52:07 | [diff] [blame] | 1378 | // Double check that here. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1379 | int enabled_bindings = dest_render_view_host->GetEnabledBindings(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1380 | WebUIControllerFactory* factory = |
| 1381 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1382 | bool data_urls_allowed = delegate_ && delegate_->CanLoadDataURLsInWebUI(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1383 | bool is_allowed_in_web_ui_renderer = |
| 1384 | factory && |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1385 | factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL(), |
| 1386 | data_urls_allowed); |
[email protected] | 1684454a | 2012-03-24 04:12:23 | [diff] [blame] | 1387 | if ((enabled_bindings & content::BINDINGS_POLICY_WEB_UI) && |
| 1388 | !is_allowed_in_web_ui_renderer) { |
[email protected] | 24e1825 | 2012-04-16 21:26:27 | [diff] [blame] | 1389 | // Log the URL to help us diagnose any future failures of this CHECK. |
[email protected] | 1684454a | 2012-03-24 04:12:23 | [diff] [blame] | 1390 | content::GetContentClient()->SetActiveURL(entry.GetURL()); |
| 1391 | CHECK(0); |
| 1392 | } |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 1393 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1394 | // Tell DevTools agent that it is attached prior to the navigation. |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1395 | DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1396 | GetRenderViewHost(), |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 1397 | dest_render_view_host, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1398 | entry.GetURL()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1399 | |
| 1400 | // Used for page load time metrics. |
| 1401 | current_load_start_ = base::TimeTicks::Now(); |
| 1402 | |
| 1403 | // Navigate in the desired RenderViewHost. |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 1404 | std::string embedder_channel_name; |
| 1405 | int embedder_container_id; |
| 1406 | GetBrowserPluginEmbedderInfo(dest_render_view_host, |
| 1407 | &embedder_channel_name, |
| 1408 | &embedder_container_id); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 1409 | ViewMsg_Navigate_Params navigate_params; |
[email protected] | dd11de5 | 2011-11-03 22:54:27 | [diff] [blame] | 1410 | MakeNavigateParams(entry, controller_, delegate_, reload_type, |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 1411 | embedder_channel_name, |
| 1412 | embedder_container_id, |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 1413 | &navigate_params); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 1414 | dest_render_view_host->Navigate(navigate_params); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1415 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1416 | if (entry.GetPageID() == -1) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1417 | // HACK!! This code suppresses javascript: URLs from being added to |
| 1418 | // session history, which is what we want to do for javascript: URLs that |
| 1419 | // do not generate content. What we really need is a message from the |
| 1420 | // renderer telling us that a new page was not created. The same message |
| 1421 | // could be used for mailto: URLs and the like. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1422 | if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme)) |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1423 | return false; |
| 1424 | } |
| 1425 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1426 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1427 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 1428 | observers_, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1429 | NavigateToPendingEntry(entry.GetURL(), reload_type)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1430 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 1431 | if (delegate_) |
| 1432 | delegate_->DidNavigateToPendingEntry(this); |
| 1433 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1434 | return true; |
| 1435 | } |
| 1436 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1437 | void WebContentsImpl::SetHistoryLengthAndPrune( |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1438 | const SiteInstance* site_instance, |
| 1439 | int history_length, |
| 1440 | int32 minimum_page_id) { |
[email protected] | 5229253b | 2011-08-16 14:36:41 | [diff] [blame] | 1441 | // SetHistoryLengthAndPrune doesn't work when there are pending cross-site |
| 1442 | // navigations. Callers should ensure that this is the case. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1443 | if (render_manager_.pending_render_view_host()) { |
| 1444 | NOTREACHED(); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 1445 | return; |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1446 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1447 | RenderViewHostImpl* rvh = GetRenderViewHostImpl(); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1448 | if (!rvh) { |
| 1449 | NOTREACHED(); |
| 1450 | return; |
| 1451 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1452 | if (site_instance && rvh->GetSiteInstance() != site_instance) { |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1453 | NOTREACHED(); |
| 1454 | return; |
| 1455 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1456 | rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->GetRoutingID(), |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 1457 | history_length, |
| 1458 | minimum_page_id)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 1459 | } |
| 1460 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1461 | void WebContentsImpl::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1462 | if (ShowingInterstitialPage()) { |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 1463 | render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); |
| 1464 | return; |
| 1465 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1466 | GetRenderViewHostImpl()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1467 | } |
| 1468 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1469 | bool WebContentsImpl::ShowingInterstitialPage() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1470 | return render_manager_.interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1471 | } |
| 1472 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1473 | InterstitialPage* WebContentsImpl::GetInterstitialPage() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1474 | return render_manager_.interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 1475 | } |
| 1476 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1477 | bool WebContentsImpl::IsSavable() { |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 1478 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 1479 | // so we also support this MIME type. |
| 1480 | return contents_mime_type_ == "text/html" || |
| 1481 | contents_mime_type_ == "text/xml" || |
| 1482 | contents_mime_type_ == "application/xhtml+xml" || |
| 1483 | contents_mime_type_ == "text/plain" || |
| 1484 | contents_mime_type_ == "text/css" || |
| 1485 | net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); |
| 1486 | } |
| 1487 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1488 | void WebContentsImpl::OnSavePage() { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1489 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 1490 | if (!IsSavable()) { |
[email protected] | 731809e | 2012-02-15 21:56:48 | [diff] [blame] | 1491 | download_stats::RecordDownloadSource( |
| 1492 | download_stats::INITIATED_BY_SAVE_PACKAGE_ON_NON_HTML); |
[email protected] | 20b433a | 2012-05-15 21:23:46 | [diff] [blame] | 1493 | SaveURL(GetURL(), content::Referrer(), true); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 1494 | return; |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1495 | } |
| 1496 | |
| 1497 | Stop(); |
| 1498 | |
| 1499 | // Create the save package and possibly prompt the user for the name to save |
| 1500 | // the page as. The user prompt is an asynchronous operation that runs on |
| 1501 | // another thread. |
| 1502 | save_package_ = new SavePackage(this); |
| 1503 | save_package_->GetSaveInfo(); |
| 1504 | } |
| 1505 | |
| 1506 | // Used in automated testing to bypass prompting the user for file names. |
| 1507 | // Instead, the names and paths are hard coded rather than running them through |
| 1508 | // file name sanitation and extension / mime checking. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1509 | bool WebContentsImpl::SavePage(const FilePath& main_file, |
| 1510 | const FilePath& dir_path, |
| 1511 | content::SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1512 | // Stop the page from navigating. |
| 1513 | Stop(); |
| 1514 | |
| 1515 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | 6474b11 | 2012-05-04 19:35:27 | [diff] [blame] | 1516 | return save_package_->Init(content::SavePackageDownloadCreatedCallback()); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 1517 | } |
| 1518 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1519 | void WebContentsImpl::GenerateMHTML( |
[email protected] | aa4f397 | 2012-03-01 18:12:12 | [diff] [blame] | 1520 | const FilePath& file, |
| 1521 | const base::Callback<void(const FilePath&, int64)>& callback) { |
| 1522 | MHTMLGenerationManager::GetInstance()->GenerateMHTML(this, file, callback); |
| 1523 | } |
| 1524 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1525 | bool WebContentsImpl::IsActiveEntry(int32 page_id) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1526 | NavigationEntryImpl* active_entry = |
| 1527 | NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1528 | return (active_entry != NULL && |
| 1529 | active_entry->site_instance() == GetSiteInstance() && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1530 | active_entry->GetPageID() == page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1531 | } |
| 1532 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1533 | const std::string& WebContentsImpl::GetContentsMimeType() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1534 | return contents_mime_type_; |
| 1535 | } |
| 1536 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1537 | bool WebContentsImpl::WillNotifyDisconnection() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1538 | return notify_disconnection_; |
| 1539 | } |
| 1540 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1541 | void WebContentsImpl::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1542 | SetEncoding(encoding); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1543 | GetRenderViewHostImpl()->Send(new ViewMsg_SetPageEncoding( |
| 1544 | GetRenderViewHost()->GetRoutingID(), encoding)); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1545 | } |
| 1546 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1547 | void WebContentsImpl::ResetOverrideEncoding() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1548 | encoding_.clear(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1549 | GetRenderViewHostImpl()->Send(new ViewMsg_ResetPageEncodingToDefault( |
| 1550 | GetRenderViewHost()->GetRoutingID())); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1551 | } |
| 1552 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1553 | content::RendererPreferences* WebContentsImpl::GetMutableRendererPrefs() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1554 | return &renderer_preferences_; |
| 1555 | } |
| 1556 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1557 | void WebContentsImpl::SetNewTabStartTime(const base::TimeTicks& time) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1558 | new_tab_start_time_ = time; |
| 1559 | } |
| 1560 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1561 | base::TimeTicks WebContentsImpl::GetNewTabStartTime() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1562 | return new_tab_start_time_; |
| 1563 | } |
| 1564 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 1565 | void WebContentsImpl::Close() { |
| 1566 | Close(GetRenderViewHost()); |
| 1567 | } |
| 1568 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1569 | void WebContentsImpl::OnCloseStarted() { |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 1570 | if (close_start_time_.is_null()) |
| 1571 | close_start_time_ = base::TimeTicks::Now(); |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1572 | } |
| 1573 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1574 | bool WebContentsImpl::ShouldAcceptDragAndDrop() const { |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1575 | #if defined(OS_CHROMEOS) |
| 1576 | // ChromeOS panels (pop-ups) do not take drag-n-drop. |
| 1577 | // See http://crosbug.com/2413 |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1578 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
[email protected] | b83af49 | 2010-10-09 03:21:20 | [diff] [blame] | 1579 | return false; |
| 1580 | return true; |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1581 | #else |
| 1582 | return true; |
| 1583 | #endif |
| 1584 | } |
| 1585 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1586 | void WebContentsImpl::SystemDragEnded() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1587 | if (GetRenderViewHost()) |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1588 | GetRenderViewHostImpl()->DragSourceSystemDragEnded(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1589 | if (delegate_) |
| 1590 | delegate_->DragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 1591 | } |
| 1592 | |
[email protected] | e35ccd5 | 2012-05-23 16:22:47 | [diff] [blame] | 1593 | void WebContentsImpl::UserGestureDone() { |
| 1594 | OnUserGesture(); |
| 1595 | } |
| 1596 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1597 | void WebContentsImpl::SetClosedByUserGesture(bool value) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1598 | closed_by_user_gesture_ = value; |
| 1599 | } |
| 1600 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1601 | bool WebContentsImpl::GetClosedByUserGesture() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1602 | return closed_by_user_gesture_; |
| 1603 | } |
| 1604 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1605 | double WebContentsImpl::GetZoomLevel() const { |
[email protected] | 5c925087 | 2012-01-30 17:24:05 | [diff] [blame] | 1606 | HostZoomMapImpl* zoom_map = static_cast<HostZoomMapImpl*>( |
[email protected] | 5fe3713a | 2012-02-22 08:31:56 | [diff] [blame] | 1607 | HostZoomMap::GetForBrowserContext(GetBrowserContext())); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1608 | if (!zoom_map) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1609 | return 0; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1610 | |
| 1611 | double zoom_level; |
| 1612 | if (temporary_zoom_settings_) { |
| 1613 | zoom_level = zoom_map->GetTemporaryZoomLevel( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1614 | GetRenderProcessHost()->GetID(), GetRenderViewHost()->GetRoutingID()); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1615 | } else { |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1616 | GURL url; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1617 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1618 | // Since zoom map is updated using rewritten URL, use rewritten URL |
| 1619 | // to get the zoom level. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1620 | url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1621 | zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1622 | } |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1623 | return zoom_level; |
| 1624 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1625 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1626 | int WebContentsImpl::GetZoomPercent(bool* enable_increment, |
| 1627 | bool* enable_decrement) { |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1628 | *enable_decrement = *enable_increment = false; |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1629 | // Calculate the zoom percent from the factor. Round up to the nearest whole |
| 1630 | // number. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1631 | int percent = static_cast<int>( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1632 | WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1633 | *enable_decrement = percent > minimum_zoom_percent_; |
| 1634 | *enable_increment = percent < maximum_zoom_percent_; |
| 1635 | return percent; |
| 1636 | } |
| 1637 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1638 | void WebContentsImpl::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1639 | if (!delegate_) |
| 1640 | return; |
| 1641 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1642 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1643 | if (!active_entry) |
| 1644 | return; |
| 1645 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1646 | delegate_->ViewSourceForTab(this, active_entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1647 | } |
| 1648 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1649 | void WebContentsImpl::ViewFrameSource(const GURL& url, |
| 1650 | const std::string& content_state) { |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1651 | if (!delegate_) |
| 1652 | return; |
| 1653 | |
| 1654 | delegate_->ViewSourceForFrame(this, url, content_state); |
| 1655 | } |
| 1656 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1657 | int WebContentsImpl::GetMinimumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1658 | return minimum_zoom_percent_; |
| 1659 | } |
| 1660 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1661 | int WebContentsImpl::GetMaximumZoomPercent() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1662 | return maximum_zoom_percent_; |
| 1663 | } |
| 1664 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1665 | gfx::Size WebContentsImpl::GetPreferredSize() const { |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 1666 | return preferred_size_; |
| 1667 | } |
| 1668 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1669 | int WebContentsImpl::GetContentRestrictions() const { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1670 | return content_restrictions_; |
| 1671 | } |
| 1672 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1673 | WebUI::TypeID WebContentsImpl::GetWebUITypeForCurrentState() { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame] | 1674 | WebUIControllerFactory* factory = |
| 1675 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 1676 | if (!factory) |
| 1677 | return WebUI::kNoWebUI; |
| 1678 | return factory->GetWebUIType(GetBrowserContext(), GetURL()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1679 | } |
| 1680 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1681 | content::WebUI* WebContentsImpl::GetWebUIForCurrentState() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1682 | // When there is a pending navigation entry, we want to use the pending WebUI |
| 1683 | // that goes along with it to control the basic flags. For example, we want to |
| 1684 | // show the pending URL in the URL bar, so we want the display_url flag to |
| 1685 | // be from the pending entry. |
| 1686 | // |
| 1687 | // The confusion comes because there are multiple possibilities for the |
| 1688 | // initial load in a tab as a side effect of the way the RenderViewHostManager |
| 1689 | // works. |
| 1690 | // |
| 1691 | // - For the very first tab the load looks "normal". The new tab Web UI is |
| 1692 | // the pending one, and we want it to apply here. |
| 1693 | // |
| 1694 | // - For subsequent new tabs, they'll get a new SiteInstance which will then |
| 1695 | // get switched to the one previously associated with the new tab pages. |
| 1696 | // This switching will cause the manager to commit the RVH/WebUI. So we'll |
| 1697 | // have a committed Web UI in this case. |
| 1698 | // |
| 1699 | // This condition handles all of these cases: |
| 1700 | // |
| 1701 | // - First load in first tab: no committed nav entry + pending nav entry + |
| 1702 | // pending dom ui: |
| 1703 | // -> Use pending Web UI if any. |
| 1704 | // |
| 1705 | // - First load in second tab: no committed nav entry + pending nav entry + |
| 1706 | // no pending Web UI: |
| 1707 | // -> Use the committed Web UI if any. |
| 1708 | // |
| 1709 | // - Second navigation in any tab: committed nav entry + pending nav entry: |
| 1710 | // -> Use pending Web UI if any. |
| 1711 | // |
| 1712 | // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1713 | // -> Use committed Web UI. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1714 | if (controller_.GetPendingEntry() && |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1715 | (controller_.GetLastCommittedEntry() || |
| 1716 | render_manager_.pending_web_ui())) |
| 1717 | return render_manager_.pending_web_ui(); |
| 1718 | return render_manager_.web_ui(); |
| 1719 | } |
| 1720 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1721 | bool WebContentsImpl::GotResponseToLockMouseRequest(bool allowed) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1722 | return GetRenderViewHost() ? |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1723 | GetRenderViewHostImpl()->GotResponseToLockMouseRequest(allowed) : false; |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1724 | } |
| 1725 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1726 | bool WebContentsImpl::HasOpener() const { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 1727 | return opener_ != NULL; |
[email protected] | a0358d7 | 2012-03-09 14:06:50 | [diff] [blame] | 1728 | } |
| 1729 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1730 | void WebContentsImpl::DidChooseColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 1731 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1732 | GetRenderViewHost()->Send(new ViewMsg_DidChooseColorResponse( |
| 1733 | GetRenderViewHost()->GetRoutingID(), color_chooser_id, color)); |
| 1734 | } |
| 1735 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1736 | void WebContentsImpl::DidEndColorChooser(int color_chooser_id) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 1737 | GetRenderViewHost()->Send(new ViewMsg_DidEndColorChooser( |
| 1738 | GetRenderViewHost()->GetRoutingID(), color_chooser_id)); |
| 1739 | if (delegate_) |
| 1740 | delegate_->DidEndColorChooser(); |
| 1741 | color_chooser_ = NULL; |
| 1742 | } |
| 1743 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1744 | bool WebContentsImpl::FocusLocationBarByDefault() { |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 1745 | content::WebUI* web_ui = GetWebUIForCurrentState(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1746 | if (web_ui) |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1747 | return web_ui->ShouldFocusLocationBarByDefault(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1748 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1749 | return (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL)); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1750 | } |
| 1751 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1752 | void WebContentsImpl::SetFocusToLocationBar(bool select_all) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1753 | if (delegate_) |
| 1754 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 1755 | } |
| 1756 | |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 1757 | void WebContentsImpl::OnRegisterIntentService( |
| 1758 | const webkit_glue::WebIntentServiceData& data, |
| 1759 | bool user_gesture) { |
| 1760 | delegate_->RegisterIntentHandler(this, data, user_gesture); |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1761 | } |
| 1762 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1763 | void WebContentsImpl::OnWebIntentDispatch( |
| 1764 | const webkit_glue::WebIntentData& intent, |
| 1765 | int intent_id) { |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1766 | WebIntentsDispatcherImpl* intents_dispatcher = |
| 1767 | new WebIntentsDispatcherImpl(this, intent, intent_id); |
| 1768 | delegate_->WebIntentDispatch(this, intents_dispatcher); |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1769 | } |
| 1770 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1771 | void WebContentsImpl::DidStartProvisionalLoadForFrame( |
| 1772 | content::RenderViewHost* render_view_host, |
| 1773 | int64 frame_id, |
| 1774 | bool is_main_frame, |
| 1775 | const GURL& opener_url, |
| 1776 | const GURL& url) { |
[email protected] | 285f4bb8 | 2012-04-17 15:57:28 | [diff] [blame] | 1777 | bool is_error_page = (url.spec() == content::kUnreachableWebDataURL); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1778 | GURL validated_url(url); |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1779 | GURL validated_opener_url(opener_url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1780 | content::RenderProcessHost* render_process_host = |
| 1781 | render_view_host->GetProcess(); |
[email protected] | 97d402f3 | 2012-06-01 02:55:16 | [diff] [blame] | 1782 | RenderViewHostImpl::FilterURL( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1783 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1784 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1785 | false, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1786 | &validated_url); |
[email protected] | 97d402f3 | 2012-06-01 02:55:16 | [diff] [blame] | 1787 | RenderViewHostImpl::FilterURL( |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1788 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1789 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1790 | true, |
| 1791 | &validated_opener_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1792 | |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1793 | // Notify observers about the start of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1794 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1795 | DidStartProvisionalLoadForFrame(frame_id, is_main_frame, |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1796 | validated_url, is_error_page, render_view_host)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1797 | } |
| 1798 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1799 | void WebContentsImpl::DidFailProvisionalLoadWithError( |
| 1800 | content::RenderViewHost* render_view_host, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1801 | const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
| 1802 | VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() |
| 1803 | << ", error_code: " << params.error_code |
| 1804 | << ", error_description: " << params.error_description |
| 1805 | << ", is_main_frame: " << params.is_main_frame |
| 1806 | << ", showing_repost_interstitial: " << |
| 1807 | params.showing_repost_interstitial |
| 1808 | << ", frame_id: " << params.frame_id; |
| 1809 | GURL validated_url(params.url); |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1810 | content::RenderProcessHost* render_process_host = |
| 1811 | render_view_host->GetProcess(); |
[email protected] | 97d402f3 | 2012-06-01 02:55:16 | [diff] [blame] | 1812 | RenderViewHostImpl::FilterURL( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1813 | ChildProcessSecurityPolicyImpl::GetInstance(), |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1814 | render_process_host->GetID(), |
[email protected] | 6b7cd8f | 2012-03-21 21:02:45 | [diff] [blame] | 1815 | false, |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 1816 | &validated_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1817 | |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1818 | if (net::ERR_ABORTED == params.error_code) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1819 | // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
| 1820 | // This means that the interstitial won't be torn down properly, which is |
| 1821 | // bad. But if we have an interstitial, go back to another tab type, and |
| 1822 | // then load the same interstitial again, we could end up getting the first |
| 1823 | // interstitial's "failed" message (as a result of the cancel) when we're on |
| 1824 | // the second one. |
| 1825 | // |
| 1826 | // We can't tell this apart, so we think we're tearing down the current page |
| 1827 | // which will cause a crash later one. There is also some code in |
| 1828 | // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented |
| 1829 | // out because of this problem. |
| 1830 | // |
| 1831 | // http://code.google.com/p/chromium/issues/detail?id=2855 |
| 1832 | // Because this will not tear down the interstitial properly, if "back" is |
| 1833 | // back to another tab type, the interstitial will still be somewhat alive |
| 1834 | // in the previous tab type. If you navigate somewhere that activates the |
| 1835 | // tab with the interstitial again, you'll see a flash before the new load |
| 1836 | // commits of the interstitial page. |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1837 | if (ShowingInterstitialPage()) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1838 | LOG(WARNING) << "Discarding message during interstitial."; |
| 1839 | return; |
| 1840 | } |
| 1841 | |
[email protected] | 02102f8 | 2011-06-13 20:37:02 | [diff] [blame] | 1842 | // Discard our pending entry if the load canceled (e.g. if we decided to |
| 1843 | // download the file instead of load it). We do not verify that the URL |
| 1844 | // being canceled matches the pending entry's URL because they will not |
| 1845 | // match if a redirect occurred (in which case we do not want to leave a |
| 1846 | // stale redirect URL showing). This means that we also cancel the pending |
| 1847 | // entry if the user started a new navigation. As a result, the navigation |
| 1848 | // controller may not remember that a load is in progress, but the |
| 1849 | // navigation will still commit even if there is no pending entry. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1850 | if (controller_.GetPendingEntry()) |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 1851 | DidCancelLoading(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1852 | |
[email protected] | 54047eb5 | 2012-05-08 21:45:57 | [diff] [blame] | 1853 | render_manager_.RendererAbortedProvisionalLoad(render_view_host); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1854 | } |
| 1855 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1856 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1857 | observers_, |
| 1858 | DidFailProvisionalLoad(params.frame_id, |
| 1859 | params.is_main_frame, |
| 1860 | validated_url, |
| 1861 | params.error_code, |
[email protected] | ef16c3e | 2012-05-16 22:13:46 | [diff] [blame] | 1862 | params.error_description, |
| 1863 | render_view_host)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1864 | } |
| 1865 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1866 | void WebContentsImpl::OnDidLoadResourceFromMemoryCache( |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1867 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 1868 | const std::string& security_info, |
| 1869 | const std::string& http_method, |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 1870 | const std::string& mime_type, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 1871 | ResourceType::Type resource_type) { |
[email protected] | 2862086 | 2011-03-22 23:07:19 | [diff] [blame] | 1872 | base::StatsCounter cache("WebKit.CacheHit"); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1873 | cache.Increment(); |
| 1874 | |
| 1875 | // Send out a notification that we loaded a resource from our memory cache. |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 1876 | int cert_id = 0; |
| 1877 | net::CertStatus cert_status = 0; |
| 1878 | int security_bits = -1; |
| 1879 | int connection_status = 0; |
[email protected] | 35be7ec | 2012-02-12 20:42:51 | [diff] [blame] | 1880 | content::DeserializeSecurityInfo(security_info, &cert_id, &cert_status, |
| 1881 | &security_bits, &connection_status); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1882 | LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(), |
[email protected] | 6d6cfb3a | 2012-05-23 22:53:18 | [diff] [blame] | 1883 | cert_id, cert_status, http_method, |
| 1884 | mime_type, resource_type); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1885 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1886 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1887 | content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1888 | content::Source<NavigationController>(&controller_), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1889 | content::Details<LoadFromMemoryCacheDetails>(&details)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1890 | } |
| 1891 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1892 | void WebContentsImpl::OnDidDisplayInsecureContent() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1893 | content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1894 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1895 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1896 | } |
| 1897 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1898 | void WebContentsImpl::OnDidRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 1899 | const std::string& security_origin, const GURL& target_url) { |
[email protected] | 9941cf5 | 2011-02-08 16:17:23 | [diff] [blame] | 1900 | LOG(INFO) << security_origin << " ran insecure content from " |
| 1901 | << target_url.possibly_invalid_spec(); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1902 | content::RecordAction(UserMetricsAction("SSL.RanInsecureContent")); |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 1903 | if (EndsWith(security_origin, kDotGoogleDotCom, false)) |
| 1904 | content::RecordAction(UserMetricsAction("SSL.RanInsecureContentGoogle")); |
[email protected] | 330614de | 2012-02-13 17:07:18 | [diff] [blame] | 1905 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
[email protected] | f2b58c4d | 2011-06-01 23:29:41 | [diff] [blame] | 1906 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1907 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1910 | void WebContentsImpl::OnDocumentLoadedInFrame(int64 frame_id) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1911 | controller_.DocumentLoadedInFrame(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1912 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1913 | DocumentLoadedInFrame(frame_id)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1914 | } |
| 1915 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1916 | void WebContentsImpl::OnDidFinishLoad( |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1917 | int64 frame_id, |
| 1918 | const GURL& validated_url, |
| 1919 | bool is_main_frame) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1920 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1921 | DidFinishLoad(frame_id, validated_url, is_main_frame)); |
| 1922 | } |
| 1923 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1924 | void WebContentsImpl::OnDidFailLoadWithError( |
| 1925 | int64 frame_id, |
| 1926 | const GURL& validated_url, |
| 1927 | bool is_main_frame, |
| 1928 | int error_code, |
| 1929 | const string16& error_description) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1930 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1931 | DidFailLoad(frame_id, validated_url, is_main_frame, |
| 1932 | error_code, error_description)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1933 | } |
| 1934 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1935 | void WebContentsImpl::OnUpdateContentRestrictions(int restrictions) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1936 | content_restrictions_ = restrictions; |
| 1937 | delegate_->ContentRestrictionsChanged(this); |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 1938 | } |
| 1939 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1940 | void WebContentsImpl::OnGoToEntryAtOffset(int offset) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1941 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1942 | NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1943 | controller_.GetEntryAtOffset(offset)); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1944 | if (!entry) |
| 1945 | return; |
| 1946 | // Note that we don't call NavigationController::GotToOffset() as we don't |
| 1947 | // want to create a pending navigation entry (it might end up lingering |
| 1948 | // http://crbug.com/51680). |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1949 | entry->SetTransitionType( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1950 | content::PageTransitionFromInt( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1951 | entry->GetTransitionType() | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1952 | content::PAGE_TRANSITION_FORWARD_BACK)); |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1953 | NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1954 | |
| 1955 | // If the entry is being restored and doesn't have a SiteInstance yet, fill |
| 1956 | // it in now that we know. This allows us to find the entry when it commits. |
| 1957 | if (!entry->site_instance() && |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1958 | entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1959 | entry->set_site_instance( |
| 1960 | static_cast<SiteInstanceImpl*>(GetPendingSiteInstance())); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1961 | } |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1962 | } |
| 1963 | } |
| 1964 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1965 | void WebContentsImpl::OnUpdateZoomLimits(int minimum_percent, |
| 1966 | int maximum_percent, |
| 1967 | bool remember) { |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1968 | minimum_zoom_percent_ = minimum_percent; |
| 1969 | maximum_zoom_percent_ = maximum_percent; |
| 1970 | temporary_zoom_settings_ = !remember; |
| 1971 | } |
| 1972 | |
[email protected] | 20b433a | 2012-05-15 21:23:46 | [diff] [blame] | 1973 | void WebContentsImpl::OnSaveURL(const GURL& url, |
| 1974 | const content::Referrer& referrer) { |
[email protected] | 731809e | 2012-02-15 21:56:48 | [diff] [blame] | 1975 | download_stats::RecordDownloadSource( |
| 1976 | download_stats::INITIATED_BY_PEPPER_SAVE); |
[email protected] | e30d68d | 2012-02-09 00:06:26 | [diff] [blame] | 1977 | // Check if the URL to save matches the URL of the main frame. Since this |
| 1978 | // message originates from Pepper plugins, it may not be the case if the |
| 1979 | // plugin is an embedded element. |
| 1980 | GURL main_frame_url = GetURL(); |
| 1981 | if (!main_frame_url.is_valid()) |
| 1982 | return; |
| 1983 | bool is_main_frame = (url == main_frame_url); |
[email protected] | 20b433a | 2012-05-15 21:23:46 | [diff] [blame] | 1984 | SaveURL(url, referrer, is_main_frame); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1985 | } |
| 1986 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1987 | void WebContentsImpl::OnEnumerateDirectory(int request_id, |
| 1988 | const FilePath& path) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 1989 | ChildProcessSecurityPolicyImpl* policy = |
| 1990 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 1991 | if (policy->CanReadDirectory(GetRenderProcessHost()->GetID(), path)) |
| 1992 | delegate_->EnumerateDirectory(this, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1993 | } |
| 1994 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1995 | void WebContentsImpl::OnJSOutOfMemory() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1996 | delegate_->JSOutOfMemory(this); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1997 | } |
| 1998 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 1999 | void WebContentsImpl::OnRegisterProtocolHandler(const std::string& protocol, |
| 2000 | const GURL& url, |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 2001 | const string16& title, |
| 2002 | bool user_gesture) { |
[email protected] | b953542 | 2012-02-09 01:47:59 | [diff] [blame] | 2003 | ChildProcessSecurityPolicyImpl* policy = |
| 2004 | ChildProcessSecurityPolicyImpl::GetInstance(); |
| 2005 | if (policy->IsPseudoScheme(protocol) || policy->IsDisabledScheme(protocol)) |
| 2006 | return; |
[email protected] | 3a3b75a | 2012-06-01 08:38:36 | [diff] [blame] | 2007 | delegate_->RegisterProtocolHandler(this, protocol, url, title, user_gesture); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 2008 | } |
| 2009 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2010 | void WebContentsImpl::OnFindReply(int request_id, |
| 2011 | int number_of_matches, |
| 2012 | const gfx::Rect& selection_rect, |
| 2013 | int active_match_ordinal, |
| 2014 | bool final_update) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2015 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 2016 | active_match_ordinal, final_update); |
[email protected] | 4e6239c | 2011-09-23 00:11:00 | [diff] [blame] | 2017 | // Send a notification to the renderer that we are ready to receive more |
| 2018 | // results from the scoping effort of the Find operation. The FindInPage |
| 2019 | // scoping is asynchronous and periodically sends results back up to the |
| 2020 | // browser using IPC. In an effort to not spam the browser we have the |
| 2021 | // browser send an ACK for each FindReply message and have the renderer |
| 2022 | // queue up the latest status message while waiting for this ACK. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2023 | GetRenderViewHostImpl()->Send( |
| 2024 | new ViewMsg_FindReplyACK(GetRenderViewHost()->GetRoutingID())); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 2025 | } |
| 2026 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2027 | void WebContentsImpl::OnCrashedPlugin(const FilePath& plugin_path) { |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 2028 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2029 | PluginCrashed(plugin_path)); |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 2030 | } |
| 2031 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2032 | void WebContentsImpl::OnAppCacheAccessed(const GURL& manifest_url, |
| 2033 | bool blocked_by_policy) { |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 2034 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2035 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 2036 | AppCacheAccessed(manifest_url, blocked_by_policy)); |
| 2037 | } |
| 2038 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2039 | void WebContentsImpl::OnOpenColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 2040 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2041 | color_chooser_ = delegate_->OpenColorChooser(this, color_chooser_id, color); |
| 2042 | } |
| 2043 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2044 | void WebContentsImpl::OnEndColorChooser(int color_chooser_id) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2045 | if (color_chooser_ && |
| 2046 | color_chooser_id == color_chooser_->identifier()) |
| 2047 | color_chooser_->End(); |
| 2048 | } |
| 2049 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2050 | void WebContentsImpl::OnSetSelectedColorInColorChooser(int color_chooser_id, |
[email protected] | 55578b0a | 2012-04-18 14:31:32 | [diff] [blame] | 2051 | SkColor color) { |
[email protected] | da854376 | 2012-03-20 08:52:20 | [diff] [blame] | 2052 | if (color_chooser_ && |
| 2053 | color_chooser_id == color_chooser_->identifier()) |
| 2054 | color_chooser_->SetSelectedColor(color); |
| 2055 | } |
| 2056 | |
[email protected] | 9f2a9d7 | 2012-04-16 16:02:22 | [diff] [blame] | 2057 | void WebContentsImpl::OnPepperPluginHung(int plugin_child_id, |
| 2058 | const FilePath& path, |
| 2059 | bool is_hung) { |
[email protected] | 3fc07c5 | 2012-04-20 00:27:44 | [diff] [blame] | 2060 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2061 | PluginHungStatusChanged(plugin_child_id, path, is_hung)); |
[email protected] | 8be4584 | 2012-04-13 19:49:29 | [diff] [blame] | 2062 | } |
| 2063 | |
[email protected] | d0759f49 | 2012-04-19 22:50:50 | [diff] [blame] | 2064 | // This exists for render views that don't have a WebUI, but do have WebUI |
| 2065 | // bindings enabled. |
| 2066 | void WebContentsImpl::OnWebUISend(const GURL& source_url, |
| 2067 | const std::string& name, |
| 2068 | const base::ListValue& args) { |
| 2069 | if (delegate_) |
| 2070 | delegate_->WebUISend(this, source_url, name, args); |
| 2071 | } |
| 2072 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2073 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 2074 | // loading, or done loading and calls the base implementation. |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2075 | void WebContentsImpl::SetIsLoading(bool is_loading, |
| 2076 | LoadNotificationDetails* details) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2077 | if (is_loading == is_loading_) |
| 2078 | return; |
| 2079 | |
| 2080 | if (!is_loading) { |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 2081 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2082 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2083 | upload_size_ = 0; |
| 2084 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2085 | } |
| 2086 | |
| 2087 | render_manager_.SetIsLoading(is_loading); |
| 2088 | |
| 2089 | is_loading_ = is_loading; |
| 2090 | waiting_for_response_ = is_loading; |
| 2091 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 2092 | if (delegate_) |
| 2093 | delegate_->LoadingStateChanged(this); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2094 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2095 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2096 | int type = is_loading ? content::NOTIFICATION_LOAD_START : |
| 2097 | content::NOTIFICATION_LOAD_STOP; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2098 | content::NotificationDetails det = content::NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2099 | if (details) |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2100 | det = content::Details<LoadNotificationDetails>(details); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2101 | content::NotificationService::current()->Notify(type, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 2102 | content::Source<NavigationController>(&controller_), |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 2103 | det); |
| 2104 | } |
| 2105 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2106 | void WebContentsImpl::DidNavigateMainFramePostCommit( |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 2107 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2108 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 2109 | if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 2110 | // If this is a window.open navigation, use the same WebUI as the renderer |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 2111 | // that opened the window, as long as both renderers have the same |
| 2112 | // privileges. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 2113 | if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 2114 | WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL())); |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 2115 | // web_ui might be NULL if the URL refers to a non-existent extension. |
| 2116 | if (web_ui) { |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 2117 | render_manager_.SetWebUIPostCommit(web_ui); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2118 | web_ui->RenderViewCreated(GetRenderViewHost()); |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 2119 | } |
| 2120 | } |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 2121 | opener_web_ui_type_ = WebUI::kNoWebUI; |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 2122 | } |
| 2123 | |
[email protected] | 4e697b04 | 2011-07-08 06:44:56 | [diff] [blame] | 2124 | if (details.is_navigation_to_different_page()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2125 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 2126 | // doesn't let us know that the cursor left an element during a |
| 2127 | // transition (this is also why the mouse cursor remains as a hand after |
| 2128 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 2129 | // clear the bubble when a user navigates to a named anchor in the same |
| 2130 | // page. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2131 | UpdateTargetURL(details.entry->GetPageID(), GURL()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2132 | } |
| 2133 | |
[email protected] | a6e82fc | 2010-02-24 22:28:14 | [diff] [blame] | 2134 | if (!details.is_in_page) { |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 2135 | // Once the main frame is navigated, we're no longer considered to have |
| 2136 | // displayed insecure content. |
| 2137 | displayed_insecure_content_ = false; |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 2138 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 2139 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2140 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2141 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 2142 | DidNavigateMainFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2143 | } |
| 2144 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2145 | void WebContentsImpl::DidNavigateAnyFramePostCommit( |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2146 | RenderViewHost* render_view_host, |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 2147 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2148 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | e550f5e | 2012-01-11 07:22:06 | [diff] [blame] | 2149 | // If we navigate off the page, reset JavaScript state. This does nothing |
| 2150 | // to prevent a malicious script from spamming messages, since the script |
| 2151 | // could just reload the page to stop blocking. |
| 2152 | if (dialog_creator_ && !details.is_in_page) { |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2153 | dialog_creator_->ResetJavaScriptState(this); |
| 2154 | dialog_creator_ = NULL; |
| 2155 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2156 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2157 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2158 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 2159 | DidNavigateAnyFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2160 | } |
| 2161 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2162 | void WebContentsImpl::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2163 | // If we are creating a RVH for a restored controller, then we need to make |
| 2164 | // sure the RenderView starts with a next_page_id_ larger than the number |
| 2165 | // of restored entries. This must be called before the RenderView starts |
| 2166 | // navigating (to avoid a race between the browser updating max_page_id and |
| 2167 | // the renderer updating next_page_id_). Because of this, we only call this |
| 2168 | // from CreateRenderView and allow that to notify the RenderView for us. |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 2169 | int max_restored_page_id = controller_.GetMaxRestoredPageID(); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2170 | if (max_restored_page_id > |
| 2171 | GetMaxPageIDForSiteInstance(rvh->GetSiteInstance())) |
| 2172 | UpdateMaxPageIDForSiteInstance(rvh->GetSiteInstance(), |
| 2173 | max_restored_page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2174 | } |
| 2175 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2176 | bool WebContentsImpl::UpdateTitleForEntry(NavigationEntryImpl* entry, |
| 2177 | const string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2178 | // For file URLs without a title, use the pathname instead. In the case of a |
| 2179 | // synthesized title, we don't want the update to count toward the "one set |
| 2180 | // per page of the title to history." |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 2181 | string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2182 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2183 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
| 2184 | final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2185 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 2186 | } else { |
[email protected] | acafd27 | 2011-07-26 17:35:57 | [diff] [blame] | 2187 | TrimWhitespace(title, TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2188 | explicit_set = true; |
| 2189 | } |
| 2190 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2191 | // If a page is created via window.open and never navigated, |
| 2192 | // there will be no navigation entry. In this situation, |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2193 | // |page_title_when_no_navigation_entry_| will be used for page title. |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2194 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2195 | if (final_title == entry->GetTitle()) |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2196 | return false; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2197 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2198 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2199 | } else { |
| 2200 | if (page_title_when_no_navigation_entry_ == final_title) |
| 2201 | return false; // Nothing changed, don't bother. |
| 2202 | |
| 2203 | page_title_when_no_navigation_entry_ = final_title; |
| 2204 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2205 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2206 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 2207 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2208 | |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 2209 | std::pair<content::NavigationEntry*, bool> details = |
| 2210 | std::make_pair(entry, explicit_set); |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 2211 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2212 | content::NotificationService::current()->Notify( |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 2213 | content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 2214 | content::Source<WebContents>(this), |
[email protected] | 2bb17188 | 2012-03-07 02:09:46 | [diff] [blame] | 2215 | content::Details<std::pair<content::NavigationEntry*, bool> >(&details)); |
[email protected] | cbc0e1b | 2010-04-12 18:33:04 | [diff] [blame] | 2216 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2217 | return true; |
| 2218 | } |
| 2219 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2220 | void WebContentsImpl::NotifySwapped() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2221 | // After sending out a swap notification, we need to send a disconnect |
| 2222 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 2223 | // pointer. See Bug 1230284. |
| 2224 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2225 | content::NotificationService::current()->Notify( |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 2226 | content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 2227 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2228 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2229 | } |
| 2230 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2231 | void WebContentsImpl::NotifyConnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2232 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2233 | content::NotificationService::current()->Notify( |
[email protected] | ef9572e | 2012-01-04 22:14:12 | [diff] [blame] | 2234 | content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 2235 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2236 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2237 | } |
| 2238 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2239 | void WebContentsImpl::NotifyDisconnected() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2240 | if (!notify_disconnection_) |
| 2241 | return; |
| 2242 | |
| 2243 | notify_disconnection_ = false; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2244 | content::NotificationService::current()->Notify( |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2245 | content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 2246 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2247 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2248 | } |
| 2249 | |
[email protected] | 5a3bdf5 | 2012-05-24 15:12:57 | [diff] [blame] | 2250 | RenderViewHostDelegateView* WebContentsImpl::GetDelegateView() { |
| 2251 | return render_view_host_delegate_view_; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2252 | } |
| 2253 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2254 | RenderViewHostDelegate::RendererManagement* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2255 | WebContentsImpl::GetRendererManagementDelegate() { |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2256 | return &render_manager_; |
| 2257 | } |
| 2258 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2259 | content::RendererPreferences WebContentsImpl::GetRendererPrefs( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 2260 | content::BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 2261 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 2262 | } |
| 2263 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2264 | WebContents* WebContentsImpl::GetAsWebContents() { |
[email protected] | 768c547 | 2011-12-26 19:06:17 | [diff] [blame] | 2265 | return this; |
| 2266 | } |
| 2267 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2268 | gfx::Rect WebContentsImpl::GetRootWindowResizerRect() const { |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 2269 | if (delegate_) |
| 2270 | return delegate_->GetRootWindowResizerRect(); |
| 2271 | return gfx::Rect(); |
| 2272 | } |
| 2273 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2274 | void WebContentsImpl::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2275 | // Don't send notifications if we are just creating a swapped-out RVH for |
| 2276 | // the opener chain. These won't be used for view-source or WebUI, so it's |
| 2277 | // ok to return early. |
| 2278 | if (static_cast<RenderViewHostImpl*>(render_view_host)->is_swapped_out()) |
| 2279 | return; |
| 2280 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2281 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2282 | content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2283 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2284 | content::Details<RenderViewHost>(render_view_host)); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2285 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2286 | if (!entry) |
| 2287 | return; |
| 2288 | |
| 2289 | // 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] | 2290 | // use the pending Web UI rather than any possibly existing committed one. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 2291 | if (render_manager_.pending_web_ui()) |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 2292 | render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2293 | |
| 2294 | if (entry->IsViewSourceMode()) { |
| 2295 | // Put the renderer in view source mode. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2296 | static_cast<RenderViewHostImpl*>(render_view_host)->Send( |
| 2297 | new ViewMsg_EnableViewSourceMode(render_view_host->GetRoutingID())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2298 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 2299 | |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2300 | GetView()->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 2301 | |
| 2302 | FOR_EACH_OBSERVER( |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2303 | WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2304 | } |
| 2305 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2306 | void WebContentsImpl::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2307 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2308 | // Don't notify the world, since this came from a renderer in the |
| 2309 | // background. |
| 2310 | return; |
| 2311 | } |
| 2312 | |
| 2313 | NotifyConnected(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2314 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2315 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2316 | |
| 2317 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 2318 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2319 | if (was_crashed && !FocusLocationBarByDefault() && |
| 2320 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2321 | Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 2322 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 2323 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2324 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2325 | } |
| 2326 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2327 | void WebContentsImpl::RenderViewGone(RenderViewHost* rvh, |
| 2328 | base::TerminationStatus status, |
| 2329 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2330 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2331 | // The pending page's RenderViewHost is gone. |
| 2332 | return; |
| 2333 | } |
| 2334 | |
| 2335 | SetIsLoading(false, NULL); |
| 2336 | NotifyDisconnected(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2337 | SetIsCrashed(status, error_code); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2338 | GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2339 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2340 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 2341 | observers_, |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2342 | RenderViewGone(GetCrashedStatus())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2343 | } |
| 2344 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2345 | void WebContentsImpl::RenderViewDeleted(RenderViewHost* rvh) { |
[email protected] | fb7b79f7 | 2009-11-06 18:00:48 | [diff] [blame] | 2346 | render_manager_.RenderViewDeleted(rvh); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2347 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2348 | } |
| 2349 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2350 | void WebContentsImpl::DidNavigate( |
| 2351 | RenderViewHost* rvh, |
| 2352 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2353 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2354 | render_manager_.DidNavigateMainFrame(rvh); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2355 | |
[email protected] | 434f69f | 2012-02-06 21:56:52 | [diff] [blame] | 2356 | // Update the site of the SiteInstance if it doesn't have one yet, unless |
| 2357 | // this is for about:blank. In that case, the SiteInstance can still be |
| 2358 | // considered unused until a navigation to a real page. |
| 2359 | if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite() && |
| 2360 | params.url != GURL(chrome::kAboutBlankURL)) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 2361 | static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); |
[email protected] | 434f69f | 2012-02-06 21:56:52 | [diff] [blame] | 2362 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2363 | |
| 2364 | // Need to update MIME type here because it's referred to in |
| 2365 | // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 2366 | // determine whether or not to enable the encoding menu. |
| 2367 | // It's updated only for the main frame. For a subframe, |
| 2368 | // RenderView::UpdateURL does not set params.contents_mime_type. |
| 2369 | // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 2370 | // TODO(jungshik): Add a test for the encoding menu to avoid |
| 2371 | // regressing it again. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2372 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2373 | contents_mime_type_ = params.contents_mime_type; |
| 2374 | |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 2375 | content::LoadCommittedDetails details; |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2376 | bool did_navigate = controller_.RendererDidNavigate(params, &details); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2377 | |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2378 | // Send notification about committed provisional loads. This notification is |
| 2379 | // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| 2380 | // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 2381 | if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) { |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 2382 | // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 2383 | // that is not recorded in the navigation history. For the purpose of |
| 2384 | // tracking navigation events, we treat this event as a sub frame navigation |
| 2385 | // event. |
| 2386 | bool is_main_frame = did_navigate ? details.is_main_frame : false; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2387 | content::PageTransition transition_type = params.transition; |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2388 | // Whether or not a page transition was triggered by going backward or |
| 2389 | // forward in the history is only stored in the navigation controller's |
| 2390 | // entry list. |
| 2391 | if (did_navigate && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2392 | (controller_.GetActiveEntry()->GetTransitionType() & |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2393 | content::PAGE_TRANSITION_FORWARD_BACK)) { |
| 2394 | transition_type = content::PageTransitionFromInt( |
| 2395 | params.transition | content::PAGE_TRANSITION_FORWARD_BACK); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2396 | } |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 2397 | // Notify observers about the commit of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2398 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 2399 | DidCommitProvisionalLoadForFrame(params.frame_id, |
[email protected] | ef16c3e | 2012-05-16 22:13:46 | [diff] [blame] | 2400 | is_main_frame, params.url, transition_type, rvh)); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 2401 | } |
| 2402 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 2403 | if (!did_navigate) |
| 2404 | return; // No navigation happened. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2405 | |
| 2406 | // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 2407 | // for the appropriate notification (best) or you can add it to |
| 2408 | // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 2409 | // necessary, please). |
| 2410 | |
| 2411 | // Run post-commit tasks. |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2412 | if (details.is_main_frame) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2413 | DidNavigateMainFramePostCommit(details, params); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2414 | if (delegate_) |
| 2415 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 2416 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2417 | DidNavigateAnyFramePostCommit(rvh, details, params); |
| 2418 | } |
| 2419 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2420 | void WebContentsImpl::UpdateState(RenderViewHost* rvh, |
| 2421 | int32 page_id, |
| 2422 | const std::string& state) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2423 | // Ensure that this state update comes from either the active RVH or one of |
| 2424 | // the swapped out RVHs. We don't expect to hear from any other RVHs. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2425 | DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2426 | |
| 2427 | // We must be prepared to handle state updates for any page, these occur |
| 2428 | // when the user is scrolling and entering form data, as well as when we're |
| 2429 | // leaving a page, in which case our state may have already been moved to |
| 2430 | // the next page. The navigation controller will look up the appropriate |
| 2431 | // NavigationEntry and update it when it is notified via the delegate. |
| 2432 | |
| 2433 | int entry_index = controller_.GetEntryIndexWithPageID( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2434 | rvh->GetSiteInstance(), page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2435 | if (entry_index < 0) |
| 2436 | return; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2437 | NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2438 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2439 | if (state == entry->GetContentState()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2440 | return; // Nothing to update. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2441 | entry->SetContentState(state); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2442 | controller_.NotifyEntryChanged(entry, entry_index); |
| 2443 | } |
| 2444 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2445 | void WebContentsImpl::UpdateTitle(RenderViewHost* rvh, |
| 2446 | int32 page_id, |
| 2447 | const string16& title, |
| 2448 | base::i18n::TextDirection title_direction) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2449 | // If we have a title, that's a pretty good indication that we've started |
| 2450 | // getting useful data. |
| 2451 | SetNotWaitingForResponse(); |
| 2452 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2453 | // Try to find the navigation entry, which might not be the current one. |
| 2454 | // For example, it might be from a pending RVH for the pending entry. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2455 | NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2456 | rvh->GetSiteInstance(), page_id); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2457 | |
[email protected] | 73eb260 | 2012-02-09 19:50:55 | [diff] [blame] | 2458 | // We can handle title updates when we don't have an entry in |
| 2459 | // UpdateTitleForEntry, but only if the update is from the current RVH. |
| 2460 | if (!entry && rvh != GetRenderViewHost()) |
| 2461 | return; |
| 2462 | |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 2463 | // TODO(evan): make use of title_direction. |
| 2464 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 2465 | if (!UpdateTitleForEntry(entry, title)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2466 | return; |
| 2467 | |
| 2468 | // Broadcast notifications when the UI should be updated. |
| 2469 | if (entry == controller_.GetEntryAtOffset(0)) |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2470 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2471 | } |
| 2472 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2473 | void WebContentsImpl::UpdateEncoding(RenderViewHost* render_view_host, |
| 2474 | const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2475 | SetEncoding(encoding); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2476 | } |
| 2477 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2478 | void WebContentsImpl::UpdateTargetURL(int32 page_id, const GURL& url) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2479 | if (delegate_) |
| 2480 | delegate_->UpdateTargetURL(this, page_id, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2481 | } |
| 2482 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2483 | void WebContentsImpl::Close(RenderViewHost* rvh) { |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2484 | // The UI may be in an event-tracking loop, such as between the |
| 2485 | // mouse-down and mouse-up in text selection or a button click. |
| 2486 | // Defer the close until after tracking is complete, so that we |
| 2487 | // don't free objects out from under the UI. |
| 2488 | // TODO(shess): This could probably be integrated with the |
| 2489 | // IsDoingDrag() test below. Punting for now because I need more |
| 2490 | // research to understand how this impacts platforms other than Mac. |
| 2491 | // TODO(shess): This could get more fine-grained. For instance, |
| 2492 | // closing a tab in another window while selecting text in the |
| 2493 | // current window's Omnibox should be just fine. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2494 | if (GetView()->IsEventTracking()) { |
| 2495 | GetView()->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2496 | return; |
| 2497 | } |
| 2498 | |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2499 | // If we close the tab while we're in the middle of a drag, we'll crash. |
| 2500 | // Instead, cancel the drag and close it as soon as the drag ends. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2501 | if (GetView()->IsDoingDrag()) { |
| 2502 | GetView()->CancelDragAndCloseTab(); |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2503 | return; |
| 2504 | } |
| 2505 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2506 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2507 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2508 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2509 | } |
| 2510 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2511 | void WebContentsImpl::SwappedOut(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2512 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2513 | delegate_->SwappedOut(this); |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 2514 | } |
| 2515 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2516 | void WebContentsImpl::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2517 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 2518 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2519 | } |
| 2520 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2521 | void WebContentsImpl::DidStartLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2522 | SetIsLoading(true, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2523 | |
[email protected] | 82114f5 | 2012-03-20 22:53:41 | [diff] [blame] | 2524 | if (delegate_ && content_restrictions_) |
| 2525 | OnUpdateContentRestrictions(0); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2526 | |
| 2527 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2528 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2529 | } |
| 2530 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2531 | void WebContentsImpl::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2532 | scoped_ptr<LoadNotificationDetails> details; |
| 2533 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2534 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2535 | // An entry may not exist for a stop when loading an initial blank page or |
| 2536 | // if an iframe injected by script into a blank page finishes loading. |
| 2537 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2538 | base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; |
| 2539 | |
| 2540 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2541 | entry->GetVirtualURL(), |
| 2542 | entry->GetTransitionType(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2543 | elapsed, |
| 2544 | &controller_, |
| 2545 | controller_.GetCurrentEntryIndex())); |
| 2546 | } |
| 2547 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2548 | SetIsLoading(false, details.get()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 2549 | |
| 2550 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2551 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2552 | } |
| 2553 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2554 | void WebContentsImpl::DidCancelLoading() { |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 2555 | controller_.DiscardNonCommittedEntries(); |
| 2556 | |
| 2557 | // Update the URL display. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2558 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 2559 | } |
| 2560 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2561 | void WebContentsImpl::DidChangeLoadProgress(double progress) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2562 | if (delegate_) |
| 2563 | delegate_->LoadProgressChanged(progress); |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 2564 | } |
| 2565 | |
[email protected] | 87717d0e | 2012-04-26 02:58:43 | [diff] [blame] | 2566 | void WebContentsImpl::DocumentAvailableInMainFrame( |
| 2567 | RenderViewHost* render_view_host) { |
| 2568 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 2569 | DocumentAvailableInMainFrame()); |
[email protected] | 952a68e | 2011-11-17 00:36:10 | [diff] [blame] | 2570 | } |
| 2571 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2572 | void WebContentsImpl::DocumentOnLoadCompletedInMainFrame( |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2573 | RenderViewHost* render_view_host, |
| 2574 | int32 page_id) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 2575 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 2576 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 2577 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 2578 | content::Details<int>(&page_id)); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 2579 | } |
| 2580 | |
[email protected] | 196159d | 2012-05-04 17:26:54 | [diff] [blame] | 2581 | void WebContentsImpl::RequestOpenURL(RenderViewHost* rvh, |
| 2582 | const GURL& url, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2583 | const content::Referrer& referrer, |
| 2584 | WindowOpenDisposition disposition, |
| 2585 | int64 source_frame_id) { |
[email protected] | 196159d | 2012-05-04 17:26:54 | [diff] [blame] | 2586 | // If this came from a swapped out RenderViewHost, we only allow the request |
| 2587 | // if we are still in the same BrowsingInstance. |
| 2588 | if (static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() && |
| 2589 | !rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) { |
| 2590 | return; |
| 2591 | } |
| 2592 | |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2593 | // Delegate to RequestTransferURL because this is just the generic |
| 2594 | // case where |old_request_id| is empty. |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 2595 | RequestTransferURL(url, referrer, disposition, source_frame_id, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2596 | GlobalRequestID()); |
| 2597 | } |
| 2598 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2599 | void WebContentsImpl::RequestTransferURL( |
| 2600 | const GURL& url, |
| 2601 | const content::Referrer& referrer, |
| 2602 | WindowOpenDisposition disposition, |
| 2603 | int64 source_frame_id, |
| 2604 | const GlobalRequestID& old_request_id) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 2605 | WebContents* new_contents = NULL; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 2606 | content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 2607 | if (render_manager_.web_ui()) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2608 | // When we're a Web UI, it will provide a page transition type for us (this |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2609 | // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 2610 | // generated suggestions). |
| 2611 | // |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 2612 | // Note also that we hide the referrer for Web UI pages. We don't really |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 2613 | // want web sites to see a referrer of "chrome://blah" (and some |
| 2614 | // chrome: URLs might have search terms or other stuff we don't want to |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2615 | // send to the site), so we send no referrer. |
[email protected] | 6bf6a6b5 | 2012-02-03 15:41:43 | [diff] [blame] | 2616 | OpenURLParams params(url, content::Referrer(), source_frame_id, disposition, |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 2617 | render_manager_.web_ui()->GetLinkTransitionType(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2618 | false /* is_renderer_initiated */); |
| 2619 | params.transferred_global_request_id = old_request_id; |
| 2620 | new_contents = OpenURL(params); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 2621 | transition_type = render_manager_.web_ui()->GetLinkTransitionType(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2622 | } else { |
[email protected] | 6bf6a6b5 | 2012-02-03 15:41:43 | [diff] [blame] | 2623 | OpenURLParams params(url, referrer, source_frame_id, disposition, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 2624 | content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); |
| 2625 | params.transferred_global_request_id = old_request_id; |
| 2626 | new_contents = OpenURL(params); |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2627 | } |
| 2628 | if (new_contents) { |
| 2629 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2630 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2631 | DidOpenRequestedURL(new_contents, |
| 2632 | url, |
| 2633 | referrer, |
| 2634 | disposition, |
| 2635 | transition_type, |
| 2636 | source_frame_id)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2637 | } |
| 2638 | } |
| 2639 | |
[email protected] | e1c3a55 | 2012-05-04 20:51:32 | [diff] [blame] | 2640 | void WebContentsImpl::RouteCloseEvent(RenderViewHost* rvh) { |
| 2641 | // Tell the active RenderViewHost to run unload handlers and close, as long |
| 2642 | // as the request came from a RenderViewHost in the same BrowsingInstance. |
| 2643 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 2644 | // It is possible to receive it from one that has just been swapped in, |
| 2645 | // in which case we might as well deliver the message anyway. |
| 2646 | if (rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
| 2647 | GetRenderViewHost()->ClosePage(); |
| 2648 | } |
| 2649 | |
[email protected] | f546640b | 2012-05-15 00:03:49 | [diff] [blame] | 2650 | void WebContentsImpl::RouteMessageEvent( |
| 2651 | RenderViewHost* rvh, |
| 2652 | const ViewMsg_PostMessage_Params& params) { |
| 2653 | // Only deliver the message to the active RenderViewHost if the request |
| 2654 | // came from a RenderViewHost in the same BrowsingInstance. |
| 2655 | if (!rvh->GetSiteInstance()->IsRelatedSiteInstance(GetSiteInstance())) |
| 2656 | return; |
| 2657 | |
| 2658 | ViewMsg_PostMessage_Params new_params(params); |
| 2659 | |
| 2660 | // If there is a source_routing_id, translate it to the routing ID for |
| 2661 | // the equivalent swapped out RVH in the target process. If we need |
| 2662 | // to create a swapped out RVH for the source tab, we create its opener |
| 2663 | // chain as well, since those will also be accessible to the target page. |
| 2664 | if (new_params.source_routing_id != MSG_ROUTING_NONE) { |
| 2665 | // Try to look up the WebContents for the source page. |
| 2666 | WebContentsImpl* source_contents = NULL; |
| 2667 | RenderViewHostImpl* source_rvh = RenderViewHostImpl::FromID( |
| 2668 | rvh->GetProcess()->GetID(), params.source_routing_id); |
| 2669 | if (source_rvh) { |
| 2670 | source_contents = static_cast<WebContentsImpl*>( |
| 2671 | source_rvh->GetDelegate()->GetAsWebContents()); |
| 2672 | } |
| 2673 | |
| 2674 | if (source_contents) { |
| 2675 | new_params.source_routing_id = |
| 2676 | source_contents->CreateOpenerRenderViews(GetSiteInstance()); |
| 2677 | } else { |
| 2678 | // We couldn't find it, so don't pass a source frame. |
| 2679 | new_params.source_routing_id = MSG_ROUTING_NONE; |
| 2680 | } |
| 2681 | } |
| 2682 | |
| 2683 | // In most cases, we receive this from a swapped out RenderViewHost. |
| 2684 | // It is possible to receive it from one that has just been swapped in, |
| 2685 | // in which case we might as well deliver the message anyway. |
| 2686 | GetRenderViewHost()->Send(new ViewMsg_PostMessageEvent( |
| 2687 | GetRenderViewHost()->GetRoutingID(), new_params)); |
| 2688 | } |
| 2689 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2690 | void WebContentsImpl::RunJavaScriptMessage( |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2691 | RenderViewHost* rvh, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2692 | const string16& message, |
| 2693 | const string16& default_prompt, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2694 | const GURL& frame_url, |
[email protected] | be2510c0 | 2012-05-28 14:52:14 | [diff] [blame] | 2695 | content::JavaScriptMessageType javascript_message_type, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2696 | IPC::Message* reply_msg, |
| 2697 | bool* did_suppress_message) { |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2698 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 2699 | // showing an interstitial as it's shown over the previous page and we don't |
| 2700 | // want the hidden page's dialogs to interfere with the interstitial. |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2701 | bool suppress_this_message = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2702 | static_cast<RenderViewHostImpl*>(rvh)->is_swapped_out() || |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2703 | ShowingInterstitialPage() || |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2704 | !delegate_ || |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2705 | delegate_->ShouldSuppressDialogs() || |
| 2706 | !delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2707 | |
| 2708 | if (!suppress_this_message) { |
[email protected] | 55df909 | 2012-02-29 22:56:43 | [diff] [blame] | 2709 | std::string accept_lang = content::GetContentClient()->browser()-> |
| 2710 | GetAcceptLangs(GetBrowserContext()); |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2711 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2712 | dialog_creator_->RunJavaScriptDialog( |
[email protected] | 55df909 | 2012-02-29 22:56:43 | [diff] [blame] | 2713 | this, |
| 2714 | frame_url.GetOrigin(), |
| 2715 | accept_lang, |
| 2716 | javascript_message_type, |
| 2717 | message, |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2718 | default_prompt, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2719 | base::Bind(&WebContentsImpl::OnDialogClosed, |
| 2720 | base::Unretained(this), |
| 2721 | rvh, |
| 2722 | reply_msg), |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2723 | &suppress_this_message); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2724 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2725 | |
| 2726 | if (suppress_this_message) { |
| 2727 | // If we are suppressing messages, just reply as if the user immediately |
| 2728 | // pressed "Cancel". |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2729 | OnDialogClosed(rvh, reply_msg, false, string16()); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | *did_suppress_message = suppress_this_message; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2733 | } |
| 2734 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2735 | void WebContentsImpl::RunBeforeUnloadConfirm(RenderViewHost* rvh, |
| 2736 | const string16& message, |
| 2737 | bool is_reload, |
| 2738 | IPC::Message* reply_msg) { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2739 | RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2740 | if (delegate_) |
| 2741 | delegate_->WillRunBeforeUnloadConfirm(); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2742 | |
| 2743 | bool suppress_this_message = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2744 | rvhi->is_swapped_out() || |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2745 | !delegate_ || |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2746 | delegate_->ShouldSuppressDialogs() || |
| 2747 | !delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2748 | if (suppress_this_message) { |
[email protected] | fedec01 | 2012-01-28 03:09:34 | [diff] [blame] | 2749 | // The reply must be sent to the RVH that sent the request. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2750 | rvhi->JavaScriptDialogClosed(reply_msg, true, string16()); |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2751 | return; |
| 2752 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2753 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2754 | is_showing_before_unload_dialog_ = true; |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2755 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2756 | dialog_creator_->RunBeforeUnloadDialog( |
[email protected] | 3b3301f6 | 2012-02-29 04:32:32 | [diff] [blame] | 2757 | this, message, is_reload, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2758 | base::Bind(&WebContentsImpl::OnDialogClosed, base::Unretained(this), rvh, |
[email protected] | 51da7e3 | 2012-01-30 19:24:52 | [diff] [blame] | 2759 | reply_msg)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2760 | } |
| 2761 | |
[email protected] | a796f20 | 2012-05-30 14:14:25 | [diff] [blame] | 2762 | bool WebContentsImpl::AddMessageToConsole(int32 level, |
| 2763 | const string16& message, |
| 2764 | int32 line_no, |
| 2765 | const string16& source_id) { |
| 2766 | if (!delegate_) |
| 2767 | return false; |
| 2768 | return delegate_->AddMessageToConsole(this, level, message, line_no, |
| 2769 | source_id); |
| 2770 | } |
| 2771 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2772 | WebPreferences WebContentsImpl::GetWebkitPrefs() { |
[email protected] | f913393 | 2012-03-16 16:37:33 | [diff] [blame] | 2773 | // We want to base the page config off of the real URL, rather than the |
| 2774 | // display URL. |
| 2775 | GURL url = controller_.GetActiveEntry() |
| 2776 | ? controller_.GetActiveEntry()->GetURL() : GURL::EmptyGURL(); |
| 2777 | return GetWebkitPrefs(GetRenderViewHost(), url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2778 | } |
| 2779 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2780 | void WebContentsImpl::OnUserGesture() { |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 2781 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2782 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 2783 | |
[email protected] | ea11472 | 2012-03-12 01:11:25 | [diff] [blame] | 2784 | ResourceDispatcherHostImpl* rdh = ResourceDispatcherHostImpl::Get(); |
[email protected] | b39e7a88b | 2012-01-10 21:43:17 | [diff] [blame] | 2785 | if (rdh) // NULL in unittests. |
| 2786 | rdh->OnUserGesture(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2787 | } |
| 2788 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2789 | void WebContentsImpl::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 2790 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2791 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2792 | } |
| 2793 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2794 | void WebContentsImpl::RendererUnresponsive(RenderViewHost* rvh, |
| 2795 | bool is_during_unload) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2796 | // Don't show hung renderer dialog for a swapped out RVH. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2797 | if (rvh != GetRenderViewHost()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2798 | return; |
| 2799 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2800 | RenderViewHostImpl* rvhi = static_cast<RenderViewHostImpl*>(rvh); |
| 2801 | |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2802 | // Ignore renderer unresponsive event if debugger is attached to the tab |
| 2803 | // since the event may be a result of the renderer sitting on a breakpoint. |
| 2804 | // See http://crbug.com/65458 |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 2805 | DevToolsAgentHost* agent = |
| 2806 | content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); |
| 2807 | if (agent && |
| 2808 | DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent)) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2809 | return; |
| 2810 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2811 | if (is_during_unload) { |
| 2812 | // Hang occurred while firing the beforeunload/unload handler. |
| 2813 | // Pretend the handler fired so tab closing continues as if it had. |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2814 | rvhi->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2815 | |
| 2816 | if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2817 | return; |
| 2818 | |
| 2819 | // If the tab hangs in the beforeunload/unload handler there's really |
| 2820 | // nothing we can do to recover. Pretend the unload listeners have |
| 2821 | // all fired and close the tab. If the hang is in the beforeunload handler |
| 2822 | // then the user will not have the option of cancelling the close. |
| 2823 | Close(rvh); |
| 2824 | return; |
| 2825 | } |
| 2826 | |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2827 | if (!GetRenderViewHostImpl() || !GetRenderViewHostImpl()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 2828 | return; |
| 2829 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2830 | if (delegate_) |
| 2831 | delegate_->RendererUnresponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2832 | } |
| 2833 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2834 | void WebContentsImpl::RendererResponsive(RenderViewHost* render_view_host) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2835 | if (delegate_) |
| 2836 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2837 | } |
| 2838 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2839 | void WebContentsImpl::LoadStateChanged( |
| 2840 | const GURL& url, |
| 2841 | const net::LoadStateWithParam& load_state, |
| 2842 | uint64 upload_position, |
| 2843 | uint64 upload_size) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2844 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2845 | upload_position_ = upload_position; |
| 2846 | upload_size_ = upload_size; |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 2847 | load_state_host_ = net::IDNToUnicode(url.host(), |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2848 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2849 | GetBrowserContext())); |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 2850 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2851 | SetNotWaitingForResponse(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2852 | if (IsLoading()) { |
| 2853 | NotifyNavigationStateChanged( |
| 2854 | content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB); |
| 2855 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2856 | } |
| 2857 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2858 | void WebContentsImpl::WorkerCrashed() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2859 | if (delegate_) |
| 2860 | delegate_->WorkerCrashed(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2861 | } |
| 2862 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2863 | void WebContentsImpl::BeforeUnloadFiredFromRenderManager( |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2864 | bool proceed, |
| 2865 | bool* proceed_to_fire_unload) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2866 | if (delegate_) |
| 2867 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2868 | } |
| 2869 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2870 | void WebContentsImpl::DidStartLoadingFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2871 | RenderViewHost* render_view_host) { |
| 2872 | DidStartLoading(); |
| 2873 | } |
| 2874 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2875 | void WebContentsImpl::RenderViewGoneFromRenderManager( |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2876 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2877 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
| 2878 | RenderViewGone(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2879 | } |
| 2880 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2881 | void WebContentsImpl::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 2882 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 2883 | gfx::Size size = view_->GetContainerSize(); |
| 2884 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 2885 | // here during container initialization and normal window size will be set |
| 2886 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 2887 | // normal size later so just ignore it. |
| 2888 | if (!size.IsEmpty()) |
| 2889 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2890 | } |
| 2891 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2892 | void WebContentsImpl::NotifySwappedFromRenderManager() { |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2893 | NotifySwapped(); |
| 2894 | } |
| 2895 | |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2896 | int WebContentsImpl::CreateOpenerRenderViewsForRenderManager( |
| 2897 | SiteInstance* instance) { |
| 2898 | if (!opener_) |
| 2899 | return MSG_ROUTING_NONE; |
| 2900 | |
| 2901 | // Recursively create RenderViews for anything else in the opener chain. |
| 2902 | return opener_->CreateOpenerRenderViews(instance); |
| 2903 | } |
| 2904 | |
| 2905 | int WebContentsImpl::CreateOpenerRenderViews(SiteInstance* instance) { |
| 2906 | int opener_route_id = MSG_ROUTING_NONE; |
| 2907 | |
| 2908 | // If this tab has an opener, ensure it has a RenderView in the given |
| 2909 | // SiteInstance as well. |
| 2910 | if (opener_) |
| 2911 | opener_route_id = opener_->CreateOpenerRenderViews(instance); |
| 2912 | |
| 2913 | // Create a swapped out RenderView in the given SiteInstance if none exists, |
| 2914 | // setting its opener to the given route_id. Return the new view's route_id. |
| 2915 | return render_manager_.CreateRenderView(instance, opener_route_id, true); |
| 2916 | } |
| 2917 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2918 | NavigationControllerImpl& WebContentsImpl::GetControllerForRenderManager() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 2919 | return GetControllerImpl(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2920 | } |
| 2921 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2922 | WebUIImpl* WebContentsImpl::CreateWebUIForRenderManager(const GURL& url) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 2923 | return static_cast<WebUIImpl*>(CreateWebUI(url)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2924 | } |
| 2925 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2926 | NavigationEntry* |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2927 | WebContentsImpl::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2928 | return controller_.GetLastCommittedEntry(); |
| 2929 | } |
| 2930 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2931 | bool WebContentsImpl::CreateRenderViewForRenderManager( |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2932 | RenderViewHost* render_view_host, int opener_route_id) { |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2933 | // Can be NULL during tests. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2934 | RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 2935 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2936 | // 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] | 2937 | if (rwh_view) |
| 2938 | rwh_view->SetSize(view_->GetContainerSize()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2939 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2940 | // Make sure we use the correct starting page_id in the new RenderView. |
| 2941 | UpdateMaxPageIDIfNecessary(render_view_host); |
| 2942 | int32 max_page_id = |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2943 | GetMaxPageIDForSiteInstance(render_view_host->GetSiteInstance()); |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2944 | |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 2945 | std::string embedder_channel_name; |
| 2946 | int embedder_container_id; |
| 2947 | GetBrowserPluginEmbedderInfo(render_view_host, |
| 2948 | &embedder_channel_name, |
| 2949 | &embedder_container_id); |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2950 | if (!static_cast<RenderViewHostImpl*>( |
[email protected] | 51dbd1c | 2012-05-16 00:36:49 | [diff] [blame] | 2951 | render_view_host)->CreateRenderView(string16(), |
| 2952 | opener_route_id, |
| 2953 | max_page_id, |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 2954 | embedder_channel_name, |
| 2955 | embedder_container_id)) { |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 2956 | return false; |
[email protected] | 14392a5 | 2012-05-02 20:28:44 | [diff] [blame] | 2957 | } |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 2958 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2959 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2960 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 2961 | // linux. See crbug.com/83941. |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2962 | if (rwh_view) { |
| 2963 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 2964 | render_widget_host->WasResized(); |
| 2965 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2966 | #endif |
| 2967 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2968 | return true; |
| 2969 | } |
| 2970 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2971 | void WebContentsImpl::OnDialogClosed(RenderViewHost* rvh, |
| 2972 | IPC::Message* reply_msg, |
| 2973 | bool success, |
| 2974 | const string16& user_input) { |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2975 | if (is_showing_before_unload_dialog_ && !success) { |
| 2976 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 2977 | // spinning, since we forced it to start spinning in Navigate. |
| 2978 | DidStopLoading(); |
| 2979 | |
[email protected] | 3bbacc5b | 2012-04-17 17:46:15 | [diff] [blame] | 2980 | close_start_time_ = base::TimeTicks(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2981 | } |
| 2982 | is_showing_before_unload_dialog_ = false; |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 2983 | static_cast<RenderViewHostImpl*>( |
| 2984 | rvh)->JavaScriptDialogClosed(reply_msg, success, user_input); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2985 | } |
| 2986 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2987 | void WebContentsImpl::SetEncoding(const std::string& encoding) { |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 2988 | encoding_ = content::GetContentClient()->browser()-> |
| 2989 | GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 2990 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 2991 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2992 | void WebContentsImpl::SaveURL(const GURL& url, |
[email protected] | 20b433a | 2012-05-15 21:23:46 | [diff] [blame] | 2993 | const content::Referrer& referrer, |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 2994 | bool is_main_frame) { |
[email protected] | b441a849 | 2012-06-06 14:55:57 | [diff] [blame] | 2995 | DownloadManager* dlm = |
| 2996 | BrowserContext::GetDownloadManager(GetBrowserContext()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 2997 | if (!dlm) |
| 2998 | return; |
| 2999 | int64 post_id = -1; |
[email protected] | e30d68d | 2012-02-09 00:06:26 | [diff] [blame] | 3000 | if (is_main_frame) { |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 3001 | const NavigationEntry* entry = controller_.GetActiveEntry(); |
| 3002 | if (entry) |
| 3003 | post_id = entry->GetPostID(); |
| 3004 | } |
[email protected] | 29a5ffc8 | 2012-03-13 19:35:58 | [diff] [blame] | 3005 | content::DownloadSaveInfo save_info; |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 3006 | save_info.prompt_for_save_location = true; |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 3007 | scoped_ptr<DownloadUrlParameters> params( |
| 3008 | DownloadUrlParameters::FromWebContents(this, url, save_info)); |
[email protected] | f859eba | 2012-05-30 17:22:49 | [diff] [blame] | 3009 | params->set_referrer(referrer); |
[email protected] | c5a5c084 | 2012-05-04 20:05:14 | [diff] [blame] | 3010 | params->set_post_id(post_id); |
| 3011 | params->set_prefer_cache(true); |
| 3012 | if (post_id >= 0) |
| 3013 | params->set_method("POST"); |
| 3014 | dlm->DownloadUrl(params.Pass()); |
[email protected] | 27678b2a | 2012-02-04 22:09:14 | [diff] [blame] | 3015 | } |
| 3016 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3017 | void WebContentsImpl::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 3018 | RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 3019 | // Can be NULL during tests. |
| 3020 | if (rwh_view) |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 3021 | rwh_view->SetSize(GetView()->GetContainerSize()); |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 3022 | } |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 3023 | |
[email protected] | b172aee | 2012-04-10 17:05:26 | [diff] [blame] | 3024 | RenderViewHostImpl* WebContentsImpl::GetRenderViewHostImpl() { |
[email protected] | 9f76c1e | 2012-03-05 15:15:58 | [diff] [blame] | 3025 | return static_cast<RenderViewHostImpl*>(GetRenderViewHost()); |
| 3026 | } |
[email protected] | 7900bfdb | 2012-05-24 19:31:24 | [diff] [blame] | 3027 | |
| 3028 | void WebContentsImpl::GetBrowserPluginEmbedderInfo( |
| 3029 | content::RenderViewHost* render_view_host, |
| 3030 | std::string* embedder_channel_name, |
| 3031 | int* embedder_container_id) { |
| 3032 | content::RenderProcessHost* embedder_render_process_host = |
| 3033 | browser_plugin_host()->embedder_render_process_host(); |
| 3034 | *embedder_container_id = browser_plugin_host()->instance_id(); |
| 3035 | int embedder_process_id = |
| 3036 | embedder_render_process_host ? embedder_render_process_host->GetID() : -1; |
| 3037 | if (embedder_process_id != -1) { |
| 3038 | *embedder_channel_name = |
| 3039 | StringPrintf("%d.r%d", render_view_host->GetProcess()->GetID(), |
| 3040 | embedder_process_id); |
| 3041 | } |
| 3042 | } |