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