[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] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 5 | #include "content/browser/tab_contents/tab_contents.h" |
[email protected] | 3952656 | 2011-02-05 03:41:51 | [diff] [blame] | 6 | |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 7 | #include <cmath> |
| 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] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 13 | #include "base/string_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 14 | #include "base/time.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 15 | #include "base/utf_string_conversions.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 16 | #include "content/browser/child_process_security_policy.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 17 | #include "content/browser/debugger/devtools_manager_impl.h" |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 18 | #include "content/browser/download/download_stats.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 19 | #include "content/browser/download/save_package.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 20 | #include "content/browser/host_zoom_map.h" |
| 21 | #include "content/browser/in_process_webkit/session_storage_namespace.h" |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 22 | #include "content/browser/intents/web_intents_dispatcher_impl.h" |
[email protected] | 37a72af | 2011-06-13 05:42:01 | [diff] [blame] | 23 | #include "content/browser/load_from_memory_cache_details.h" |
[email protected] | 35e251d | 2011-05-24 21:01:04 | [diff] [blame] | 24 | #include "content/browser/load_notification_details.h" |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 25 | #include "content/browser/renderer_host/render_process_host_impl.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 26 | #include "content/browser/renderer_host/render_view_host.h" |
| 27 | #include "content/browser/renderer_host/render_widget_host_view.h" |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 28 | #include "content/browser/renderer_host/resource_dispatcher_host.h" |
[email protected] | 567812d | 2011-02-24 17:40:50 | [diff] [blame] | 29 | #include "content/browser/renderer_host/resource_request_details.h" |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 30 | #include "content/browser/site_instance_impl.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 31 | #include "content/browser/tab_contents/interstitial_page.h" |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 32 | #include "content/browser/tab_contents/navigation_entry_impl.h" |
[email protected] | 0dd3a0ab | 2011-02-18 08:17:44 | [diff] [blame] | 33 | #include "content/browser/tab_contents/provisional_load_details.h" |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 34 | #include "content/browser/tab_contents/title_updated_details.h" |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 35 | #include "content/browser/webui/web_ui_impl.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 36 | #include "content/common/intents_messages.h" |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 37 | #include "content/common/view_messages.h" |
[email protected] | ccb79730 | 2011-12-15 16:55:11 | [diff] [blame] | 38 | #include "content/public/browser/browser_context.h" |
[email protected] | 87f3c08 | 2011-10-19 18:07:44 | [diff] [blame] | 39 | #include "content/public/browser/content_browser_client.h" |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 40 | #include "content/public/browser/devtools_agent_host_registry.h" |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 41 | #include "content/public/browser/download_manager.h" |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 42 | #include "content/public/browser/invalidate_type.h" |
[email protected] | 5b96836f | 2011-12-22 07:39:00 | [diff] [blame] | 43 | #include "content/public/browser/navigation_details.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 44 | #include "content/public/browser/notification_service.h" |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 45 | #include "content/public/browser/user_metrics.h" |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 46 | #include "content/public/browser/web_contents_delegate.h" |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 47 | #include "content/public/browser/web_contents_observer.h" |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 48 | #include "content/public/browser/web_contents_view.h" |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 49 | #include "content/public/browser/web_ui_controller_factory.h" |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 50 | #include "content/public/common/bindings_policy.h" |
[email protected] | 54087fe | 2011-10-28 22:02:48 | [diff] [blame] | 51 | #include "content/public/common/content_constants.h" |
[email protected] | 4573fbd | 2011-10-31 20:25:18 | [diff] [blame] | 52 | #include "content/public/common/content_restriction.h" |
[email protected] | a1d2916 | 2011-10-14 17:14:03 | [diff] [blame] | 53 | #include "content/public/common/url_constants.h" |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 54 | #include "net/base/mime_util.h" |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 55 | #include "net/base/net_util.h" |
[email protected] | abe2c03 | 2011-03-31 18:49:34 | [diff] [blame] | 56 | #include "net/url_request/url_request_context_getter.h" |
[email protected] | 8bd0fe6 | 2011-01-17 06:44:37 | [diff] [blame] | 57 | #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" |
[email protected] | 08397d5 | 2011-02-05 01:53:38 | [diff] [blame] | 58 | #include "ui/gfx/codec/png_codec.h" |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 59 | #include "webkit/glue/web_intent_data.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 60 | #include "webkit/glue/webpreferences.h" |
| 61 | |
| 62 | #if defined(OS_MACOSX) |
[email protected] | b9b751f2 | 2011-03-25 14:04:12 | [diff] [blame] | 63 | #include "ui/gfx/surface/io_surface_support_mac.h" |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 64 | #endif // defined(OS_MACOSX) |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 65 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 66 | // Cross-Site Navigations |
| 67 | // |
| 68 | // If a TabContents is told to navigate to a different web site (as determined |
| 69 | // by SiteInstance), it will replace its current RenderViewHost with a new |
| 70 | // RenderViewHost dedicated to the new SiteInstance. This works as follows: |
| 71 | // |
| 72 | // - Navigate determines whether the destination is cross-site, and if so, |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 73 | // it creates a pending_render_view_host_. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 74 | // - The pending RVH is "suspended," so that no navigation messages are sent to |
| 75 | // its renderer until the onbeforeunload JavaScript handler has a chance to |
| 76 | // run in the current RVH. |
| 77 | // - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton) |
| 78 | // that it has a pending cross-site request. ResourceDispatcherHost will |
| 79 | // check for this when the response arrives. |
| 80 | // - The current RVH runs its onbeforeunload handler. If it returns false, we |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 81 | // cancel all the pending logic. Otherwise we allow the pending RVH to send |
| 82 | // the navigation request to its renderer. |
| 83 | // - ResourceDispatcherHost receives a ResourceRequest on the IO thread for the |
| 84 | // main resource load on the pending RVH. It checks CrossSiteRequestManager |
| 85 | // to see that it is a cross-site request, and installs a |
| 86 | // CrossSiteResourceHandler. |
| 87 | // - When RDH receives a response, the BufferedResourceHandler determines |
| 88 | // whether it is a download. If so, it sends a message to the new renderer |
| 89 | // causing it to cancel the request, and the download proceeds. For now, the |
| 90 | // pending RVH remains until the next DidNavigate event for this TabContents. |
| 91 | // This isn't ideal, but it doesn't affect any functionality. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 92 | // - After RDH receives a response and determines that it is safe and not a |
| 93 | // download, it pauses the response to first run the old page's onunload |
| 94 | // handler. It does this by asynchronously calling the OnCrossSiteResponse |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 95 | // method of TabContents on the UI thread, which sends a SwapOut message |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 96 | // to the current RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 97 | // - Once the onunload handler is finished, a SwapOut_ACK message is sent to |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 98 | // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 99 | // to the pending RVH. |
| 100 | // - The pending renderer sends a FrameNavigate message that invokes the |
| 101 | // DidNavigate method. This replaces the current RVH with the |
[email protected] | a275008 | 2011-09-01 12:29:46 | [diff] [blame] | 102 | // pending RVH. |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 103 | // - The previous renderer is kept swapped out in RenderViewHostManager in case |
| 104 | // the user goes back. The process only stays live if another tab is using |
| 105 | // it, but if so, the existing frame relationships will be maintained. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 106 | |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 107 | using content::DevToolsAgentHost; |
| 108 | using content::DevToolsAgentHostRegistry; |
| 109 | using content::DevToolsManagerImpl; |
[email protected] | e582fdd | 2011-12-20 16:48:17 | [diff] [blame] | 110 | using content::DownloadItem; |
| 111 | using content::DownloadManager; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 112 | using content::GlobalRequestID; |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 113 | using content::NavigationController; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 114 | using content::NavigationEntry; |
| 115 | using content::NavigationEntryImpl; |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 116 | using content::OpenURLParams; |
[email protected] | b0b67cf | 2012-01-18 21:59:57 | [diff] [blame] | 117 | using content::RenderViewHostDelegate; |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 118 | using content::SiteInstance; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 119 | using content::SSLStatus; |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 120 | using content::UserMetricsAction; |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 121 | using content::WebContents; |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 122 | using content::WebContentsObserver; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 123 | using content::WebUI; |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 124 | using content::WebUIController; |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 125 | using content::WebUIControllerFactory; |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 126 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 127 | namespace { |
| 128 | |
| 129 | // Amount of time we wait between when a key event is received and the renderer |
| 130 | // is queried for its state and pushed to the NavigationEntry. |
| 131 | const int kQueryStateDelay = 5000; |
| 132 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 133 | const int kSyncWaitDelay = 40; |
| 134 | |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 135 | static const char kDotGoogleDotCom[] = ".google.com"; |
| 136 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 137 | #if defined(OS_WIN) |
| 138 | |
| 139 | BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 140 | // Note: erase is required to properly paint some widgets borders. This can |
| 141 | // be seen with textfields. |
| 142 | InvalidateRect(hwnd, NULL, TRUE); |
| 143 | return TRUE; |
| 144 | } |
| 145 | #endif |
| 146 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 147 | ViewMsg_Navigate_Type::Value GetNavigationType( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 148 | content::BrowserContext* browser_context, const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 149 | NavigationController::ReloadType reload_type) { |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 150 | switch (reload_type) { |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 151 | case NavigationControllerImpl::RELOAD: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 152 | return ViewMsg_Navigate_Type::RELOAD; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 153 | case NavigationControllerImpl::RELOAD_IGNORING_CACHE: |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 154 | return ViewMsg_Navigate_Type::RELOAD_IGNORING_CACHE; |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 155 | case NavigationControllerImpl::NO_RELOAD: |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 156 | break; // Fall through to rest of function. |
| 157 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 158 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 159 | if (entry.restore_type() == NavigationEntryImpl::RESTORE_LAST_SESSION && |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 160 | browser_context->DidLastSessionExitCleanly()) |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 161 | return ViewMsg_Navigate_Type::RESTORE; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 162 | |
[email protected] | 2c556966 | 2011-03-22 20:45:02 | [diff] [blame] | 163 | return ViewMsg_Navigate_Type::NORMAL; |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 164 | } |
| 165 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 166 | void MakeNavigateParams(const NavigationEntryImpl& entry, |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 167 | const NavigationControllerImpl& controller, |
[email protected] | 674bc59 | 2011-12-20 23:00:42 | [diff] [blame] | 168 | content::WebContentsDelegate* delegate, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 169 | NavigationController::ReloadType reload_type, |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 170 | ViewMsg_Navigate_Params* params) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 171 | params->page_id = entry.GetPageID(); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 172 | params->pending_history_list_offset = controller.GetIndexOfEntry(&entry); |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 173 | params->current_history_list_offset = controller.GetLastCommittedEntryIndex(); |
| 174 | params->current_history_list_length = controller.GetEntryCount(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 175 | params->url = entry.GetURL(); |
| 176 | params->referrer = entry.GetReferrer(); |
| 177 | params->transition = entry.GetTransitionType(); |
| 178 | params->state = entry.GetContentState(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 179 | params->navigation_type = |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 180 | GetNavigationType(controller.GetBrowserContext(), entry, reload_type); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 181 | params->request_time = base::Time::Now(); |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 182 | params->extra_headers = entry.extra_headers(); |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 183 | params->transferred_request_child_id = |
| 184 | entry.transferred_global_request_id().child_id; |
| 185 | params->transferred_request_request_id = |
| 186 | entry.transferred_global_request_id().request_id; |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 187 | |
| 188 | if (delegate) |
| 189 | delegate->AddNavigationHeaders(params->url, ¶ms->extra_headers); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 190 | } |
| 191 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 192 | } // namespace |
| 193 | |
[email protected] | a81343d23 | 2011-12-27 07:39:20 | [diff] [blame] | 194 | namespace content { |
| 195 | |
| 196 | WebContents* WebContents::Create( |
| 197 | BrowserContext* browser_context, |
| 198 | SiteInstance* site_instance, |
| 199 | int routing_id, |
| 200 | const WebContents* base_tab_contents, |
| 201 | SessionStorageNamespace* session_storage_namespace) { |
| 202 | return new TabContents(browser_context, |
| 203 | site_instance, |
| 204 | routing_id, |
| 205 | static_cast<const TabContents*>(base_tab_contents), |
| 206 | session_storage_namespace); |
| 207 | } |
| 208 | } |
[email protected] | f4f50ef | 2011-01-21 19:01:19 | [diff] [blame] | 209 | |
| 210 | // TabContents ---------------------------------------------------------------- |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 211 | |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 212 | TabContents::TabContents(content::BrowserContext* browser_context, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 213 | SiteInstance* site_instance, |
| 214 | int routing_id, |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 215 | const TabContents* base_tab_contents, |
| 216 | SessionStorageNamespace* session_storage_namespace) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 217 | : delegate_(NULL), |
[email protected] | 6ee12c4 | 2010-09-14 09:36:07 | [diff] [blame] | 218 | ALLOW_THIS_IN_INITIALIZER_LIST(controller_( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 219 | this, browser_context, session_storage_namespace)), |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 220 | ALLOW_THIS_IN_INITIALIZER_LIST(view_( |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 221 | content::GetContentClient()->browser()->CreateWebContentsView(this))), |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 222 | ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 223 | is_loading_(false), |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 224 | crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING), |
| 225 | crashed_error_code_(0), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 226 | waiting_for_response_(false), |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 227 | load_state_(net::LOAD_STATE_IDLE, string16()), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 228 | upload_size_(0), |
| 229 | upload_position_(0), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 230 | displayed_insecure_content_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 231 | capturing_contents_(false), |
| 232 | is_being_destroyed_(false), |
| 233 | notify_disconnection_(false), |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 234 | dialog_creator_(NULL), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 235 | #if defined(OS_WIN) |
| 236 | message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 237 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 238 | is_showing_before_unload_dialog_(false), |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 239 | opener_web_ui_type_(WebUI::kNoWebUI), |
[email protected] | ebf40a7 | 2010-07-22 01:46:38 | [diff] [blame] | 240 | closed_by_user_gesture_(false), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 241 | minimum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 242 | static_cast<int>(content::kMinimumZoomFactor * 100)), |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 243 | maximum_zoom_percent_( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 244 | static_cast<int>(content::kMaximumZoomFactor * 100)), |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 245 | temporary_zoom_settings_(false), |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 246 | content_restrictions_(0), |
| 247 | view_type_(content::VIEW_TYPE_TAB_CONTENTS) { |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 248 | render_manager_.Init(browser_context, site_instance, routing_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 249 | |
[email protected] | 34ac7050 | 2009-09-25 17:07:23 | [diff] [blame] | 250 | // We have the initial size of the view be based on the size of the passed in |
| 251 | // tab contents (normally a tab from the same window). |
| 252 | view_->CreateView(base_tab_contents ? |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 253 | base_tab_contents->GetView()->GetContainerSize() : gfx::Size()); |
[email protected] | 483623eb | 2011-10-25 09:30:00 | [diff] [blame] | 254 | |
| 255 | #if defined(ENABLE_JAVA_BRIDGE) |
| 256 | java_bridge_dispatcher_host_manager_.reset( |
| 257 | new JavaBridgeDispatcherHostManager(this)); |
| 258 | #endif |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 259 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 260 | |
| 261 | TabContents::~TabContents() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 262 | is_being_destroyed_ = true; |
| 263 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 264 | // Clear out any JavaScript state. |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 265 | if (dialog_creator_) |
| 266 | dialog_creator_->ResetJavaScriptState(this); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 267 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 268 | NotifyDisconnected(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 269 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 270 | // Notify any observer that have a reference on this tab contents. |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 271 | content::NotificationService::current()->Notify( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 272 | content::NOTIFICATION_WEB_CONTENTS_DESTROYED, |
| 273 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 274 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 275 | |
| 276 | // TODO(brettw) this should be moved to the view. |
[email protected] | 010882f | 2011-11-14 22:32:07 | [diff] [blame] | 277 | #if defined(OS_WIN) && !defined(USE_AURA) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 278 | // If we still have a window handle, destroy it. GetNativeView can return |
| 279 | // NULL if this contents was part of a window that closed. |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 280 | if (GetNativeView()) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 281 | RenderViewHost* host = GetRenderViewHost(); |
[email protected] | b9a1fb4 | 2011-04-12 23:16:44 | [diff] [blame] | 282 | if (host && host->view()) |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 283 | host->view()->WillWmDestroy(); |
[email protected] | 50bd645 | 2010-11-27 19:39:42 | [diff] [blame] | 284 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 285 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 286 | |
| 287 | // OnCloseStarted isn't called in unit tests. |
| 288 | if (!tab_close_start_time_.is_null()) { |
| 289 | UMA_HISTOGRAM_TIMES("Tab.Close", |
| 290 | base::TimeTicks::Now() - tab_close_start_time_); |
| 291 | } |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 292 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 293 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, TabContentsDestroyed()); |
[email protected] | 232a581 | 2011-03-04 22:42:08 | [diff] [blame] | 294 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 295 | SetDelegate(NULL); |
[email protected] | b5a1d11c | 2011-02-17 03:09:42 | [diff] [blame] | 296 | } |
| 297 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 298 | NavigationControllerImpl& TabContents::GetControllerImpl() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 299 | return controller_; |
| 300 | } |
| 301 | |
[email protected] | 76518718 | 2012-01-11 23:59:28 | [diff] [blame] | 302 | RenderViewHostManager* TabContents::GetRenderManagerForTesting() { |
| 303 | return &render_manager_; |
| 304 | } |
| 305 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 306 | bool TabContents::OnMessageReceived(const IPC::Message& message) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 307 | if (GetWebUI() && |
| 308 | static_cast<WebUIImpl*>(GetWebUI())->OnMessageReceived(message)) { |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 309 | return true; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 310 | } |
[email protected] | f82d57b5 | 2011-04-27 19:13:17 | [diff] [blame] | 311 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 312 | ObserverListBase<WebContentsObserver>::Iterator it(observers_); |
| 313 | WebContentsObserver* observer; |
[email protected] | 0f180ee | 2011-01-21 18:23:10 | [diff] [blame] | 314 | while ((observer = it.GetNext()) != NULL) |
| 315 | if (observer->OnMessageReceived(message)) |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 316 | return true; |
[email protected] | 403415a | 2011-01-10 18:57:53 | [diff] [blame] | 317 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 318 | bool handled = true; |
| 319 | bool message_is_ok = true; |
| 320 | IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok) |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 321 | IPC_MESSAGE_HANDLER(IntentsHostMsg_RegisterIntentService, |
| 322 | OnRegisterIntentService) |
[email protected] | ce975194 | 2011-09-21 01:57:24 | [diff] [blame] | 323 | IPC_MESSAGE_HANDLER(IntentsHostMsg_WebIntentDispatch, |
| 324 | OnWebIntentDispatch) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 325 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame, |
| 326 | OnDidStartProvisionalLoadForFrame) |
| 327 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad, |
| 328 | OnDidRedirectProvisionalLoad) |
| 329 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError, |
| 330 | OnDidFailProvisionalLoadWithError) |
| 331 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache, |
| 332 | OnDidLoadResourceFromMemoryCache) |
| 333 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent, |
| 334 | OnDidDisplayInsecureContent) |
| 335 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent, |
| 336 | OnDidRunInsecureContent) |
| 337 | IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame, |
| 338 | OnDocumentLoadedInFrame) |
| 339 | IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad) |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 340 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions, |
| 341 | OnUpdateContentRestrictions) |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 342 | IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset) |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 343 | IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateZoomLimits, OnUpdateZoomLimits) |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 344 | IPC_MESSAGE_HANDLER(ViewHostMsg_SaveURLAs, OnSaveURL) |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 345 | IPC_MESSAGE_HANDLER(ViewHostMsg_EnumerateDirectory, OnEnumerateDirectory) |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 346 | IPC_MESSAGE_HANDLER(ViewHostMsg_JSOutOfMemory, OnJSOutOfMemory) |
| 347 | IPC_MESSAGE_HANDLER(ViewHostMsg_RegisterProtocolHandler, |
| 348 | OnRegisterProtocolHandler) |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 349 | IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply) |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 350 | IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin) |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 351 | IPC_MESSAGE_HANDLER(ViewHostMsg_AppCacheAccessed, OnAppCacheAccessed) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 352 | IPC_MESSAGE_UNHANDLED(handled = false) |
| 353 | IPC_END_MESSAGE_MAP_EX() |
| 354 | |
| 355 | if (!message_is_ok) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 356 | content::RecordAction(UserMetricsAction("BadMessageTerminate_RVD")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 357 | GetRenderProcessHost()->ReceivedBadMessage(); |
| 358 | } |
| 359 | |
| 360 | return handled; |
| 361 | } |
| 362 | |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 363 | void TabContents::RunFileChooser( |
| 364 | RenderViewHost* render_view_host, |
[email protected] | 8caadeb | 2011-11-22 02:45:23 | [diff] [blame] | 365 | const content::FileChooserParams& params) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 366 | delegate_->RunFileChooser(this, params); |
[email protected] | 6c2e472f | 2011-08-24 23:26:18 | [diff] [blame] | 367 | } |
| 368 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 369 | NavigationController& TabContents::GetController() { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 370 | return controller_; |
| 371 | } |
| 372 | |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 373 | const NavigationController& TabContents::GetController() const { |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 374 | return controller_; |
| 375 | } |
| 376 | |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 377 | content::BrowserContext* TabContents::GetBrowserContext() const { |
[email protected] | a2602382 | 2011-12-29 00:23:55 | [diff] [blame] | 378 | return controller_.GetBrowserContext(); |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | f5fa20e | 2011-12-21 22:35:56 | [diff] [blame] | 381 | void TabContents::SetViewType(content::ViewType type) { |
| 382 | view_type_ = type; |
| 383 | } |
| 384 | |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 385 | content::ViewType TabContents::GetViewType() const { |
| 386 | return view_type_; |
| 387 | } |
| 388 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 389 | const GURL& TabContents::GetURL() const { |
| 390 | // We may not have a navigation entry yet |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 391 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 392 | return entry ? entry->GetVirtualURL() : GURL::EmptyGURL(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | |
| 396 | const base::PropertyBag* TabContents::GetPropertyBag() const { |
| 397 | return &property_bag_; |
| 398 | } |
| 399 | |
| 400 | base::PropertyBag* TabContents::GetPropertyBag() { |
| 401 | return &property_bag_; |
| 402 | } |
| 403 | |
| 404 | content::WebContentsDelegate* TabContents::GetDelegate() { |
| 405 | return delegate_; |
| 406 | } |
| 407 | |
| 408 | void TabContents::SetDelegate(content::WebContentsDelegate* delegate) { |
| 409 | // TODO(cbentzel): remove this debugging code? |
| 410 | if (delegate == delegate_) |
| 411 | return; |
| 412 | if (delegate_) |
| 413 | delegate_->Detach(this); |
| 414 | delegate_ = delegate; |
| 415 | if (delegate_) |
| 416 | delegate_->Attach(this); |
| 417 | } |
| 418 | |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 419 | content::RenderProcessHost* TabContents::GetRenderProcessHost() const { |
[email protected] | 4d0df26 | 2011-10-03 20:05:03 | [diff] [blame] | 420 | if (render_manager_.current_host()) |
| 421 | return render_manager_.current_host()->process(); |
| 422 | else |
| 423 | return NULL; |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 426 | RenderViewHost* TabContents::GetRenderViewHost() const { |
| 427 | return render_manager_.current_host(); |
| 428 | } |
| 429 | |
| 430 | RenderWidgetHostView* TabContents::GetRenderWidgetHostView() const { |
| 431 | return render_manager_.GetRenderWidgetHostView(); |
| 432 | } |
| 433 | |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 434 | content::WebContentsView* TabContents::GetView() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 435 | return view_.get(); |
| 436 | } |
| 437 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 438 | content::WebUI* TabContents::CreateWebUI(const GURL& url) { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 439 | WebUIControllerFactory* factory = |
| 440 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 441 | if (!factory) |
| 442 | return NULL; |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 443 | WebUIImpl* web_ui = new WebUIImpl(this); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 444 | WebUIController* controller = |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 445 | factory->CreateWebUIControllerForURL(web_ui, url); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 446 | if (controller) { |
| 447 | web_ui->SetController(controller); |
| 448 | return web_ui; |
| 449 | } |
| 450 | |
| 451 | delete web_ui; |
| 452 | return NULL; |
| 453 | } |
| 454 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 455 | content::WebUI* TabContents::GetWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 456 | return render_manager_.web_ui() ? render_manager_.web_ui() |
| 457 | : render_manager_.pending_web_ui(); |
| 458 | } |
| 459 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 460 | content::WebUI* TabContents::GetCommittedWebUI() const { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 461 | return render_manager_.web_ui(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 462 | } |
| 463 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 464 | const string16& TabContents::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 465 | // Transient entries take precedence. They are used for interstitial pages |
| 466 | // that are shown on top of existing pages. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 467 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 468 | std::string accept_languages = |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 469 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 470 | GetBrowserContext()); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 471 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 472 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 473 | } |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 474 | WebUI* our_web_ui = render_manager_.pending_web_ui() ? |
| 475 | render_manager_.pending_web_ui() : render_manager_.web_ui(); |
| 476 | if (our_web_ui) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 477 | // Don't override the title in view source mode. |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 478 | entry = controller_.GetActiveEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 479 | if (!(entry && entry->IsViewSourceMode())) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 480 | // Give the Web UI the chance to override our title. |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 481 | const string16& title = our_web_ui->GetOverriddenTitle(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 482 | if (!title.empty()) |
| 483 | return title; |
| 484 | } |
| 485 | } |
| 486 | |
| 487 | // We use the title for the last committed entry rather than a pending |
| 488 | // navigation entry. For example, when the user types in a URL, we want to |
| 489 | // keep the old page's title until the new load has committed and we get a new |
| 490 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 491 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 492 | if (entry) { |
[email protected] | b5cca98 | 2011-05-26 04:42:08 | [diff] [blame] | 493 | return entry->GetTitleForDisplay(accept_languages); |
[email protected] | 45d0ef7f | 2011-01-05 13:46:23 | [diff] [blame] | 494 | } |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 495 | |
| 496 | // |page_title_when_no_navigation_entry_| is finally used |
| 497 | // if no title cannot be retrieved. |
| 498 | return page_title_when_no_navigation_entry_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 499 | } |
| 500 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 501 | int32 TabContents::GetMaxPageID() { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 502 | return GetMaxPageIDForSiteInstance(GetSiteInstance()); |
| 503 | } |
| 504 | |
| 505 | int32 TabContents::GetMaxPageIDForSiteInstance(SiteInstance* site_instance) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 506 | if (max_page_ids_.find(site_instance->GetId()) == max_page_ids_.end()) |
| 507 | max_page_ids_[site_instance->GetId()] = -1; |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 508 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 509 | return max_page_ids_[site_instance->GetId()]; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | void TabContents::UpdateMaxPageID(int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 513 | UpdateMaxPageIDForSiteInstance(GetSiteInstance(), page_id); |
| 514 | } |
| 515 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 516 | void TabContents::UpdateMaxPageIDForSiteInstance( |
| 517 | SiteInstance* site_instance, int32 page_id) { |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 518 | if (GetMaxPageIDForSiteInstance(site_instance) < page_id) |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 519 | max_page_ids_[site_instance->GetId()] = page_id; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 520 | } |
| 521 | |
[email protected] | 91854cd | 2012-01-10 19:43:57 | [diff] [blame] | 522 | void TabContents::CopyMaxPageIDsFrom(TabContents* tab_contents) { |
| 523 | max_page_ids_ = tab_contents->max_page_ids_; |
| 524 | } |
| 525 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 526 | SiteInstance* TabContents::GetSiteInstance() const { |
| 527 | return render_manager_.current_host()->site_instance(); |
| 528 | } |
| 529 | |
[email protected] | 77362eb | 2011-08-01 17:18:38 | [diff] [blame] | 530 | SiteInstance* TabContents::GetPendingSiteInstance() const { |
| 531 | RenderViewHost* dest_rvh = render_manager_.pending_render_view_host() ? |
| 532 | render_manager_.pending_render_view_host() : |
| 533 | render_manager_.current_host(); |
| 534 | return dest_rvh->site_instance(); |
| 535 | } |
| 536 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 537 | bool TabContents::IsLoading() const { |
| 538 | return is_loading_; |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 539 | } |
| 540 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 541 | bool TabContents::IsWaitingForResponse() const { |
| 542 | return waiting_for_response_; |
| 543 | } |
| 544 | |
| 545 | const net::LoadStateWithParam& TabContents::GetLoadState() const { |
| 546 | return load_state_; |
| 547 | } |
| 548 | |
| 549 | const string16& TabContents::GetLoadStateHost() const { |
| 550 | return load_state_host_; |
| 551 | } |
| 552 | |
| 553 | uint64 TabContents::GetUploadSize() const { |
| 554 | return upload_size_; |
| 555 | } |
| 556 | |
| 557 | uint64 TabContents::GetUploadPosition() const { |
| 558 | return upload_position_; |
| 559 | } |
| 560 | |
| 561 | const std::string& TabContents::GetEncoding() const { |
| 562 | return encoding_; |
| 563 | } |
| 564 | |
| 565 | bool TabContents::DisplayedInsecureContent() const { |
| 566 | return displayed_insecure_content_; |
| 567 | } |
| 568 | |
| 569 | void TabContents::SetCapturingContents(bool cap) { |
| 570 | capturing_contents_ = cap; |
| 571 | } |
| 572 | |
| 573 | bool TabContents::IsCrashed() const { |
| 574 | return (crashed_status_ == base::TERMINATION_STATUS_PROCESS_CRASHED || |
| 575 | crashed_status_ == base::TERMINATION_STATUS_ABNORMAL_TERMINATION || |
| 576 | crashed_status_ == base::TERMINATION_STATUS_PROCESS_WAS_KILLED); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 577 | } |
| 578 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 579 | void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) { |
| 580 | if (status == crashed_status_) |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 581 | return; |
| 582 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 583 | crashed_status_ = status; |
| 584 | crashed_error_code_ = error_code; |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 585 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 586 | } |
| 587 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 588 | base::TerminationStatus TabContents::GetCrashedStatus() const { |
| 589 | return crashed_status_; |
| 590 | } |
| 591 | |
| 592 | bool TabContents::IsBeingDestroyed() const { |
| 593 | return is_being_destroyed_; |
| 594 | } |
| 595 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 596 | void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { |
| 597 | if (delegate_) |
| 598 | delegate_->NavigationStateChanged(this, changed_flags); |
| 599 | } |
| 600 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 601 | void TabContents::DidBecomeSelected() { |
| 602 | controller_.SetActive(true); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 603 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 604 | if (rwhv) { |
| 605 | rwhv->DidBecomeSelected(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 606 | #if defined(OS_MACOSX) |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 607 | rwhv->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 608 | #endif |
| 609 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 610 | |
[email protected] | 5ac2016 | 2010-11-24 23:33:11 | [diff] [blame] | 611 | last_selected_time_ = base::TimeTicks::Now(); |
[email protected] | 3e69bc8 | 2011-05-26 23:22:38 | [diff] [blame] | 612 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 613 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidBecomeSelected()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 614 | } |
| 615 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 616 | |
| 617 | base::TimeTicks TabContents::GetLastSelectedTime() const { |
| 618 | return last_selected_time_; |
| 619 | } |
| 620 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 621 | void TabContents::WasHidden() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 622 | if (!capturing_contents_) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 623 | // |GetRenderViewHost()| can be NULL if the user middle clicks a link to |
| 624 | // open a tab in then background, then closes the tab before selecting it. |
| 625 | // This is because closing the tab calls TabContents::Destroy(), which |
| 626 | // removes the |GetRenderViewHost()|; then when we actually destroy the |
| 627 | // window, OnWindowPosChanged() notices and calls HideContents() (which |
| 628 | // calls us). |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 629 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 630 | if (rwhv) |
| 631 | rwhv->WasHidden(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 632 | } |
| 633 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 634 | content::NotificationService::current()->Notify( |
[email protected] | ea049a0 | 2011-12-25 21:37:09 | [diff] [blame] | 635 | content::NOTIFICATION_WEB_CONTENTS_HIDDEN, |
| 636 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 637 | content::NotificationService::NoDetails()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 640 | void TabContents::ShowContents() { |
| 641 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 642 | if (rwhv) |
| 643 | rwhv->DidBecomeSelected(); |
| 644 | } |
| 645 | |
| 646 | void TabContents::HideContents() { |
| 647 | // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 648 | // our superclass HideContents(), because some callers want to be very picky |
| 649 | // about the order in which these get called. In addition to making the code |
| 650 | // here practically impossible to understand, this also means we end up |
| 651 | // calling TabContents::WasHidden() twice if callers call both versions of |
| 652 | // HideContents() on a TabContents. |
| 653 | WasHidden(); |
| 654 | } |
| 655 | |
| 656 | bool TabContents::NeedToFireBeforeUnload() { |
| 657 | // TODO(creis): Should we fire even for interstitial pages? |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 658 | return WillNotifyDisconnection() && |
| 659 | !ShowingInterstitialPage() && |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 660 | !GetRenderViewHost()->SuddenTerminationAllowed(); |
| 661 | } |
| 662 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 663 | void TabContents::Stop() { |
| 664 | render_manager_.Stop(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 665 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, StopNavigation()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 666 | } |
| 667 | |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 668 | WebContents* TabContents::Clone() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 669 | // We create a new SiteInstance so that the new tab won't share processes |
| 670 | // with the old one. This can be changed in the future if we need it to share |
| 671 | // processes for some reason. |
| 672 | TabContents* tc = new TabContents( |
| 673 | GetBrowserContext(), |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 674 | SiteInstance::Create(GetBrowserContext()), |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 675 | MSG_ROUTING_NONE, this, NULL); |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 676 | tc->GetControllerImpl().CopyStateFrom(controller_); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 677 | return tc; |
| 678 | } |
| 679 | |
| 680 | void TabContents::ShowPageInfo(const GURL& url, |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 681 | const SSLStatus& ssl, |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 682 | bool show_history) { |
| 683 | if (!delegate_) |
| 684 | return; |
| 685 | |
| 686 | delegate_->ShowPageInfo(GetBrowserContext(), url, ssl, show_history); |
| 687 | } |
| 688 | |
[email protected] | 2a6bc3e | 2011-12-28 23:51:33 | [diff] [blame] | 689 | void TabContents::AddNewContents(WebContents* new_contents, |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 690 | WindowOpenDisposition disposition, |
| 691 | const gfx::Rect& initial_pos, |
| 692 | bool user_gesture) { |
| 693 | if (!delegate_) |
| 694 | return; |
| 695 | |
| 696 | delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 697 | user_gesture); |
| 698 | } |
| 699 | |
| 700 | gfx::NativeView TabContents::GetContentNativeView() const { |
| 701 | return view_->GetContentNativeView(); |
| 702 | } |
| 703 | |
| 704 | gfx::NativeView TabContents::GetNativeView() const { |
| 705 | return view_->GetNativeView(); |
| 706 | } |
| 707 | |
| 708 | void TabContents::GetContainerBounds(gfx::Rect* out) const { |
| 709 | view_->GetContainerBounds(out); |
| 710 | } |
| 711 | |
| 712 | void TabContents::Focus() { |
| 713 | view_->Focus(); |
| 714 | } |
| 715 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 716 | void TabContents::AddObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 717 | observers_.AddObserver(observer); |
| 718 | } |
| 719 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 720 | void TabContents::RemoveObserver(WebContentsObserver* observer) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 721 | observers_.RemoveObserver(observer); |
| 722 | } |
| 723 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 724 | void TabContents::Activate() { |
| 725 | if (delegate_) |
| 726 | delegate_->ActivateContents(this); |
| 727 | } |
| 728 | |
[email protected] | ea42e778 | 2010-08-23 23:58:12 | [diff] [blame] | 729 | void TabContents::Deactivate() { |
| 730 | if (delegate_) |
| 731 | delegate_->DeactivateContents(this); |
| 732 | } |
| 733 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 734 | void TabContents::LostCapture() { |
| 735 | if (delegate_) |
| 736 | delegate_->LostCapture(); |
| 737 | } |
| 738 | |
| 739 | bool TabContents::PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event, |
| 740 | bool* is_keyboard_shortcut) { |
| 741 | return delegate_ && |
| 742 | delegate_->PreHandleKeyboardEvent(event, is_keyboard_shortcut); |
| 743 | } |
| 744 | |
| 745 | void TabContents::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
| 746 | if (delegate_) |
| 747 | delegate_->HandleKeyboardEvent(event); |
| 748 | } |
| 749 | |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 750 | void TabContents::HandleMouseDown() { |
| 751 | if (delegate_) |
| 752 | delegate_->HandleMouseDown(); |
| 753 | } |
| 754 | |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 755 | void TabContents::HandleMouseUp() { |
| 756 | if (delegate_) |
| 757 | delegate_->HandleMouseUp(); |
| 758 | } |
| 759 | |
| 760 | void TabContents::HandleMouseActivate() { |
| 761 | if (delegate_) |
| 762 | delegate_->HandleMouseActivate(); |
| 763 | } |
| 764 | |
[email protected] | 8a5e0ca | 2011-08-25 06:30:47 | [diff] [blame] | 765 | void TabContents::ToggleFullscreenMode(bool enter_fullscreen) { |
| 766 | if (delegate_) |
| 767 | delegate_->ToggleFullscreenModeForTab(this, enter_fullscreen); |
| 768 | } |
| 769 | |
[email protected] | 5d5f7af | 2011-10-01 01:38:12 | [diff] [blame] | 770 | bool TabContents::IsFullscreenForCurrentTab() const { |
| 771 | return delegate_ ? delegate_->IsFullscreenForTab(this) : false; |
| 772 | } |
| 773 | |
[email protected] | e962111 | 2011-10-17 05:38:37 | [diff] [blame] | 774 | void TabContents::RequestToLockMouse() { |
| 775 | if (delegate_) { |
| 776 | delegate_->RequestToLockMouse(this); |
| 777 | } else { |
| 778 | GotResponseToLockMouseRequest(false); |
| 779 | } |
| 780 | } |
| 781 | |
| 782 | void TabContents::LostMouseLock() { |
| 783 | if (delegate_) |
| 784 | delegate_->LostMouseLock(); |
| 785 | } |
| 786 | |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 787 | void TabContents::UpdatePreferredSize(const gfx::Size& pref_size) { |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 788 | preferred_size_ = pref_size; |
[email protected] | 0548c535 | 2011-09-07 00:33:33 | [diff] [blame] | 789 | if (delegate_) |
| 790 | delegate_->UpdatePreferredSize(this, pref_size); |
| 791 | } |
| 792 | |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 793 | void TabContents::WebUISend(RenderViewHost* render_view_host, |
| 794 | const GURL& source_url, |
| 795 | const std::string& name, |
| 796 | const base::ListValue& args) { |
| 797 | if (delegate_) |
| 798 | delegate_->WebUISend(this, source_url, name, args); |
| 799 | } |
| 800 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 801 | WebContents* TabContents::OpenURL(const OpenURLParams& params) { |
| 802 | if (!delegate_) |
| 803 | return NULL; |
[email protected] | 00c37fc | 2011-08-02 00:22:50 | [diff] [blame] | 804 | |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 805 | WebContents* new_contents = delegate_->OpenURLFromTab(this, params); |
| 806 | // Notify observers. |
| 807 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
| 808 | DidOpenURL(params.url, params.referrer, |
| 809 | params.disposition, params.transition)); |
| 810 | return new_contents; |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 813 | bool TabContents::NavigateToPendingEntry( |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 814 | NavigationController::ReloadType reload_type) { |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 815 | return NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 816 | *NavigationEntryImpl::FromNavigationEntry(controller_.GetPendingEntry()), |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 817 | reload_type); |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 818 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 819 | |
[email protected] | 876bc83 | 2010-09-07 16:29:54 | [diff] [blame] | 820 | bool TabContents::NavigateToEntry( |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 821 | const NavigationEntryImpl& entry, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 822 | NavigationController::ReloadType reload_type) { |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 823 | // The renderer will reject IPC messages with URLs longer than |
| 824 | // this limit, so don't attempt to navigate with a longer URL. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 825 | if (entry.GetURL().spec().size() > content::kMaxURLChars) |
[email protected] | 19e8114 | 2011-10-03 16:19:40 | [diff] [blame] | 826 | return false; |
| 827 | |
[email protected] | dd11de5 | 2011-11-03 22:54:27 | [diff] [blame] | 828 | RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); |
[email protected] | ffc906f | 2011-10-04 22:55:40 | [diff] [blame] | 829 | if (!dest_render_view_host) |
| 830 | return false; // Unable to create the desired render view host. |
| 831 | |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 832 | // 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] | 833 | // Double check that here. |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 834 | int enabled_bindings = dest_render_view_host->enabled_bindings(); |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 835 | WebUIControllerFactory* factory = |
| 836 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 837 | bool is_allowed_in_web_ui_renderer = |
| 838 | factory && |
| 839 | factory->IsURLAcceptableForWebUI(GetBrowserContext(), entry.GetURL()); |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 840 | #if defined(OS_CHROMEOS) |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 841 | is_allowed_in_web_ui_renderer |= entry.GetURL().SchemeIs(chrome::kDataScheme); |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 842 | #endif |
[email protected] | e091df8 | 2011-10-11 18:13:21 | [diff] [blame] | 843 | CHECK(!(enabled_bindings & content::BINDINGS_POLICY_WEB_UI) || |
[email protected] | c09163a | 2011-02-15 00:05:55 | [diff] [blame] | 844 | is_allowed_in_web_ui_renderer); |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 845 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 846 | // Tell DevTools agent that it is attached prior to the navigation. |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 847 | DevToolsManagerImpl::GetInstance()->OnNavigatingToPendingEntry( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 848 | GetRenderViewHost(), |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 849 | dest_render_view_host, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 850 | entry.GetURL()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 851 | |
| 852 | // Used for page load time metrics. |
| 853 | current_load_start_ = base::TimeTicks::Now(); |
| 854 | |
| 855 | // Navigate in the desired RenderViewHost. |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 856 | ViewMsg_Navigate_Params navigate_params; |
[email protected] | dd11de5 | 2011-11-03 22:54:27 | [diff] [blame] | 857 | MakeNavigateParams(entry, controller_, delegate_, reload_type, |
[email protected] | 6c6b02d | 2011-09-02 03:36:47 | [diff] [blame] | 858 | &navigate_params); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 859 | dest_render_view_host->Navigate(navigate_params); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 860 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 861 | if (entry.GetPageID() == -1) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 862 | // HACK!! This code suppresses javascript: URLs from being added to |
| 863 | // session history, which is what we want to do for javascript: URLs that |
| 864 | // do not generate content. What we really need is a message from the |
| 865 | // renderer telling us that a new page was not created. The same message |
| 866 | // could be used for mailto: URLs and the like. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 867 | if (entry.GetURL().SchemeIs(chrome::kJavaScriptScheme)) |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 868 | return false; |
| 869 | } |
| 870 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 871 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 872 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | b375c5d | 2011-05-03 21:15:04 | [diff] [blame] | 873 | observers_, |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 874 | NavigateToPendingEntry(entry.GetURL(), reload_type)); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 875 | |
[email protected] | 09b2934 | 2011-06-24 19:18:48 | [diff] [blame] | 876 | if (delegate_) |
| 877 | delegate_->DidNavigateToPendingEntry(this); |
| 878 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 879 | return true; |
| 880 | } |
| 881 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 882 | void TabContents::SetHistoryLengthAndPrune( |
| 883 | const SiteInstance* site_instance, |
| 884 | int history_length, |
| 885 | int32 minimum_page_id) { |
[email protected] | 5229253b | 2011-08-16 14:36:41 | [diff] [blame] | 886 | // SetHistoryLengthAndPrune doesn't work when there are pending cross-site |
| 887 | // navigations. Callers should ensure that this is the case. |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 888 | if (render_manager_.pending_render_view_host()) { |
| 889 | NOTREACHED(); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 890 | return; |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 891 | } |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 892 | RenderViewHost* rvh = GetRenderViewHost(); |
[email protected] | 9e1ad4b | 2011-08-14 16:49:19 | [diff] [blame] | 893 | if (!rvh) { |
| 894 | NOTREACHED(); |
| 895 | return; |
| 896 | } |
| 897 | if (site_instance && rvh->site_instance() != site_instance) { |
| 898 | NOTREACHED(); |
| 899 | return; |
| 900 | } |
| 901 | rvh->Send(new ViewMsg_SetHistoryLengthAndPrune(rvh->routing_id(), |
| 902 | history_length, |
| 903 | minimum_page_id)); |
[email protected] | 796931a9 | 2011-08-10 01:32:14 | [diff] [blame] | 904 | } |
| 905 | |
[email protected] | 90daadb4 | 2009-06-08 21:27:28 | [diff] [blame] | 906 | void TabContents::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 907 | if (ShowingInterstitialPage()) { |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 908 | render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); |
| 909 | return; |
| 910 | } |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 911 | GetRenderViewHost()->SetInitialFocus(reverse); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 912 | } |
| 913 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 914 | bool TabContents::ShowingInterstitialPage() const { |
| 915 | return render_manager_.interstitial_page() != NULL; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 916 | } |
| 917 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 918 | InterstitialPage* TabContents::GetInterstitialPage() const { |
| 919 | return render_manager_.interstitial_page(); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 920 | } |
| 921 | |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 922 | bool TabContents::IsSavable() { |
| 923 | // WebKit creates Document object when MIME type is application/xhtml+xml, |
| 924 | // so we also support this MIME type. |
| 925 | return contents_mime_type_ == "text/html" || |
| 926 | contents_mime_type_ == "text/xml" || |
| 927 | contents_mime_type_ == "application/xhtml+xml" || |
| 928 | contents_mime_type_ == "text/plain" || |
| 929 | contents_mime_type_ == "text/css" || |
| 930 | net::IsSupportedJavascriptMimeType(contents_mime_type_.c_str()); |
| 931 | } |
| 932 | |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 933 | void TabContents::OnSavePage() { |
| 934 | // If we can not save the page, try to download it. |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 935 | if (!IsSavable()) { |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 936 | DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 937 | const GURL& current_page_url = GetURL(); |
| 938 | if (dlm && current_page_url.is_valid()) { |
| 939 | dlm->DownloadUrl(current_page_url, GURL(), "", this); |
[email protected] | 8bd9e56 | 2011-08-16 23:55:46 | [diff] [blame] | 940 | download_stats::RecordDownloadCount( |
| 941 | download_stats::INITIATED_BY_SAVE_PACKAGE_FAILURE_COUNT); |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 942 | return; |
| 943 | } |
| 944 | } |
| 945 | |
| 946 | Stop(); |
| 947 | |
| 948 | // Create the save package and possibly prompt the user for the name to save |
| 949 | // the page as. The user prompt is an asynchronous operation that runs on |
| 950 | // another thread. |
| 951 | save_package_ = new SavePackage(this); |
| 952 | save_package_->GetSaveInfo(); |
| 953 | } |
| 954 | |
| 955 | // Used in automated testing to bypass prompting the user for file names. |
| 956 | // Instead, the names and paths are hard coded rather than running them through |
| 957 | // file name sanitation and extension / mime checking. |
| 958 | bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
[email protected] | a53209b | 2012-01-20 16:48:16 | [diff] [blame] | 959 | content::SavePageType save_type) { |
[email protected] | c7dd2f6 | 2011-07-18 15:57:59 | [diff] [blame] | 960 | // Stop the page from navigating. |
| 961 | Stop(); |
| 962 | |
| 963 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
| 964 | return save_package_->Init(); |
| 965 | } |
| 966 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 967 | bool TabContents::IsActiveEntry(int32 page_id) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 968 | NavigationEntryImpl* active_entry = |
| 969 | NavigationEntryImpl::FromNavigationEntry(controller_.GetActiveEntry()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 970 | return (active_entry != NULL && |
| 971 | active_entry->site_instance() == GetSiteInstance() && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 972 | active_entry->GetPageID() == page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 973 | } |
| 974 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 975 | const std::string& TabContents::GetContentsMimeType() const { |
| 976 | return contents_mime_type_; |
| 977 | } |
| 978 | |
| 979 | bool TabContents::WillNotifyDisconnection() const { |
| 980 | return notify_disconnection_; |
| 981 | } |
| 982 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 983 | void TabContents::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 984 | SetEncoding(encoding); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 985 | GetRenderViewHost()->Send(new ViewMsg_SetPageEncoding( |
| 986 | GetRenderViewHost()->routing_id(), encoding)); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 987 | } |
| 988 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 989 | void TabContents::ResetOverrideEncoding() { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 990 | encoding_.clear(); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 991 | GetRenderViewHost()->Send(new ViewMsg_ResetPageEncodingToDefault( |
| 992 | GetRenderViewHost()->routing_id())); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 993 | } |
| 994 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 995 | content::RendererPreferences* TabContents::GetMutableRendererPrefs() { |
| 996 | return &renderer_preferences_; |
| 997 | } |
| 998 | |
| 999 | void TabContents::SetNewTabStartTime(const base::TimeTicks& time) { |
| 1000 | new_tab_start_time_ = time; |
| 1001 | } |
| 1002 | |
| 1003 | base::TimeTicks TabContents::GetNewTabStartTime() const { |
| 1004 | return new_tab_start_time_; |
| 1005 | } |
| 1006 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1007 | void TabContents::OnCloseStarted() { |
| 1008 | if (tab_close_start_time_.is_null()) |
| 1009 | tab_close_start_time_ = base::TimeTicks::Now(); |
| 1010 | } |
| 1011 | |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1012 | bool TabContents::ShouldAcceptDragAndDrop() const { |
| 1013 | #if defined(OS_CHROMEOS) |
| 1014 | // ChromeOS panels (pop-ups) do not take drag-n-drop. |
| 1015 | // See http://crosbug.com/2413 |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1016 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
[email protected] | b83af49 | 2010-10-09 03:21:20 | [diff] [blame] | 1017 | return false; |
| 1018 | return true; |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1019 | #else |
| 1020 | return true; |
| 1021 | #endif |
| 1022 | } |
| 1023 | |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 1024 | void TabContents::SystemDragEnded() { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1025 | if (GetRenderViewHost()) |
| 1026 | GetRenderViewHost()->DragSourceSystemDragEnded(); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1027 | if (delegate_) |
| 1028 | delegate_->DragEnded(); |
[email protected] | 7813bd7 | 2011-02-05 02:19:34 | [diff] [blame] | 1029 | } |
| 1030 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1031 | void TabContents::SetClosedByUserGesture(bool value) { |
| 1032 | closed_by_user_gesture_ = value; |
| 1033 | } |
| 1034 | |
| 1035 | bool TabContents::GetClosedByUserGesture() const { |
| 1036 | return closed_by_user_gesture_; |
| 1037 | } |
| 1038 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1039 | double TabContents::GetZoomLevel() const { |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 1040 | HostZoomMap* zoom_map = GetBrowserContext()->GetHostZoomMap(); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1041 | if (!zoom_map) |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1042 | return 0; |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1043 | |
| 1044 | double zoom_level; |
| 1045 | if (temporary_zoom_settings_) { |
| 1046 | zoom_level = zoom_map->GetTemporaryZoomLevel( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1047 | GetRenderProcessHost()->GetID(), GetRenderViewHost()->routing_id()); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1048 | } else { |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1049 | GURL url; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1050 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1051 | // Since zoom map is updated using rewritten URL, use rewritten URL |
| 1052 | // to get the zoom level. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1053 | url = active_entry ? active_entry->GetURL() : GURL::EmptyGURL(); |
[email protected] | 2ae88d1 | 2011-10-14 09:11:19 | [diff] [blame] | 1054 | zoom_level = zoom_map->GetZoomLevel(net::GetHostOrSpecFromURL(url)); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1055 | } |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1056 | return zoom_level; |
| 1057 | } |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1058 | |
[email protected] | d0b8d09 | 2010-10-25 04:05:17 | [diff] [blame] | 1059 | int TabContents::GetZoomPercent(bool* enable_increment, |
| 1060 | bool* enable_decrement) { |
| 1061 | *enable_decrement = *enable_increment = false; |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1062 | // Calculate the zoom percent from the factor. Round up to the nearest whole |
| 1063 | // number. |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1064 | int percent = static_cast<int>( |
[email protected] | 0f08340 | 2011-11-22 02:59:01 | [diff] [blame] | 1065 | WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100 + 0.5); |
[email protected] | b75b829 | 2010-10-01 07:28:25 | [diff] [blame] | 1066 | *enable_decrement = percent > minimum_zoom_percent_; |
| 1067 | *enable_increment = percent < maximum_zoom_percent_; |
| 1068 | return percent; |
| 1069 | } |
| 1070 | |
[email protected] | 3c733bde | 2010-12-21 19:56:31 | [diff] [blame] | 1071 | void TabContents::ViewSource() { |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1072 | if (!delegate_) |
| 1073 | return; |
| 1074 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1075 | NavigationEntry* active_entry = GetController().GetActiveEntry(); |
[email protected] | 1788e77 | 2010-12-15 16:40:50 | [diff] [blame] | 1076 | if (!active_entry) |
| 1077 | return; |
| 1078 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1079 | delegate_->ViewSourceForTab(this, active_entry->GetURL()); |
[email protected] | 77d8d62 | 2010-12-15 10:30:12 | [diff] [blame] | 1080 | } |
| 1081 | |
[email protected] | 932b7a1 | 2011-03-09 12:50:27 | [diff] [blame] | 1082 | void TabContents::ViewFrameSource(const GURL& url, |
| 1083 | const std::string& content_state) { |
| 1084 | if (!delegate_) |
| 1085 | return; |
| 1086 | |
| 1087 | delegate_->ViewSourceForFrame(this, url, content_state); |
| 1088 | } |
| 1089 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1090 | int TabContents::GetMinimumZoomPercent() const { |
| 1091 | return minimum_zoom_percent_; |
| 1092 | } |
| 1093 | |
| 1094 | int TabContents::GetMaximumZoomPercent() const { |
| 1095 | return maximum_zoom_percent_; |
| 1096 | } |
| 1097 | |
[email protected] | bcd281560 | 2012-01-14 18:17:23 | [diff] [blame] | 1098 | gfx::Size TabContents::GetPreferredSize() const { |
| 1099 | return preferred_size_; |
| 1100 | } |
| 1101 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1102 | int TabContents::GetContentRestrictions() const { |
| 1103 | return content_restrictions_; |
| 1104 | } |
| 1105 | |
| 1106 | WebUI::TypeID TabContents::GetWebUITypeForCurrentState() { |
[email protected] | 863f70a | 2012-01-27 02:05:50 | [diff] [blame^] | 1107 | WebUIControllerFactory* factory = |
| 1108 | content::GetContentClient()->browser()->GetWebUIControllerFactory(); |
| 1109 | if (!factory) |
| 1110 | return WebUI::kNoWebUI; |
| 1111 | return factory->GetWebUIType(GetBrowserContext(), GetURL()); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1112 | } |
| 1113 | |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 1114 | content::WebUI* TabContents::GetWebUIForCurrentState() { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1115 | // When there is a pending navigation entry, we want to use the pending WebUI |
| 1116 | // that goes along with it to control the basic flags. For example, we want to |
| 1117 | // show the pending URL in the URL bar, so we want the display_url flag to |
| 1118 | // be from the pending entry. |
| 1119 | // |
| 1120 | // The confusion comes because there are multiple possibilities for the |
| 1121 | // initial load in a tab as a side effect of the way the RenderViewHostManager |
| 1122 | // works. |
| 1123 | // |
| 1124 | // - For the very first tab the load looks "normal". The new tab Web UI is |
| 1125 | // the pending one, and we want it to apply here. |
| 1126 | // |
| 1127 | // - For subsequent new tabs, they'll get a new SiteInstance which will then |
| 1128 | // get switched to the one previously associated with the new tab pages. |
| 1129 | // This switching will cause the manager to commit the RVH/WebUI. So we'll |
| 1130 | // have a committed Web UI in this case. |
| 1131 | // |
| 1132 | // This condition handles all of these cases: |
| 1133 | // |
| 1134 | // - First load in first tab: no committed nav entry + pending nav entry + |
| 1135 | // pending dom ui: |
| 1136 | // -> Use pending Web UI if any. |
| 1137 | // |
| 1138 | // - First load in second tab: no committed nav entry + pending nav entry + |
| 1139 | // no pending Web UI: |
| 1140 | // -> Use the committed Web UI if any. |
| 1141 | // |
| 1142 | // - Second navigation in any tab: committed nav entry + pending nav entry: |
| 1143 | // -> Use pending Web UI if any. |
| 1144 | // |
| 1145 | // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1146 | // -> Use committed Web UI. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1147 | if (controller_.GetPendingEntry() && |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1148 | (controller_.GetLastCommittedEntry() || |
| 1149 | render_manager_.pending_web_ui())) |
| 1150 | return render_manager_.pending_web_ui(); |
| 1151 | return render_manager_.web_ui(); |
| 1152 | } |
| 1153 | |
| 1154 | bool TabContents::GotResponseToLockMouseRequest(bool allowed) { |
| 1155 | return GetRenderViewHost() ? |
| 1156 | GetRenderViewHost()->GotResponseToLockMouseRequest(allowed) : false; |
| 1157 | } |
| 1158 | |
| 1159 | bool TabContents::FocusLocationBarByDefault() { |
[email protected] | 01ec4ec | 2012-01-18 04:13:47 | [diff] [blame] | 1160 | content::WebUI* web_ui = GetWebUIForCurrentState(); |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1161 | if (web_ui) |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1162 | return web_ui->ShouldFocusLocationBarByDefault(); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1163 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1164 | if (entry && entry->GetURL() == GURL(chrome::kAboutBlankURL)) |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1165 | return true; |
| 1166 | return false; |
| 1167 | } |
| 1168 | |
| 1169 | void TabContents::SetFocusToLocationBar(bool select_all) { |
| 1170 | if (delegate_) |
| 1171 | delegate_->SetFocusToLocationBar(select_all); |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 1172 | } |
| 1173 | |
[email protected] | 8b5af49 | 2011-11-28 21:50:58 | [diff] [blame] | 1174 | void TabContents::OnRegisterIntentService(const string16& action, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1175 | const string16& type, |
| 1176 | const string16& href, |
| 1177 | const string16& title, |
| 1178 | const string16& disposition) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1179 | delegate_->RegisterIntentHandler( |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1180 | this, action, type, href, title, disposition); |
| 1181 | } |
| 1182 | |
[email protected] | 67810501 | 2011-12-09 04:01:21 | [diff] [blame] | 1183 | void TabContents::OnWebIntentDispatch(const webkit_glue::WebIntentData& intent, |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1184 | int intent_id) { |
[email protected] | 0d9989d | 2011-12-21 20:26:00 | [diff] [blame] | 1185 | WebIntentsDispatcherImpl* intents_dispatcher = |
| 1186 | new WebIntentsDispatcherImpl(this, intent, intent_id); |
| 1187 | delegate_->WebIntentDispatch(this, intents_dispatcher); |
[email protected] | 63c23932 | 2011-10-31 23:56:30 | [diff] [blame] | 1188 | } |
| 1189 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1190 | void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id, |
| 1191 | bool is_main_frame, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 1192 | const GURL& opener_url, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1193 | const GURL& url) { |
| 1194 | bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL); |
| 1195 | GURL validated_url(url); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1196 | GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1197 | GetRenderProcessHost()->GetID(), &validated_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1198 | |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1199 | RenderViewHost* rvh = |
| 1200 | render_manager_.pending_render_view_host() ? |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1201 | render_manager_.pending_render_view_host() : GetRenderViewHost(); |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1202 | // Notify observers about the start of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1203 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1204 | DidStartProvisionalLoadForFrame(frame_id, is_main_frame, |
[email protected] | 8093a54 | 2011-05-13 07:29:32 | [diff] [blame] | 1205 | validated_url, is_error_page, rvh)); |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1206 | |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1207 | if (is_main_frame) { |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 1208 | // Notify observers about the provisional change in the main frame URL. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1209 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 1210 | ProvisionalChangeToMainFrameUrl(url, opener_url)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1211 | } |
| 1212 | } |
| 1213 | |
| 1214 | void TabContents::OnDidRedirectProvisionalLoad(int32 page_id, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 1215 | const GURL& opener_url, |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1216 | const GURL& source_url, |
| 1217 | const GURL& target_url) { |
[email protected] | 18ba2b1 | 2011-04-06 16:35:49 | [diff] [blame] | 1218 | // TODO(creis): Remove this method and have the pre-rendering code listen to |
| 1219 | // the ResourceDispatcherHost's RESOURCE_RECEIVED_REDIRECT notification |
| 1220 | // instead. See http://crbug.com/78512. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1221 | NavigationEntry* entry; |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1222 | if (page_id == -1) |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1223 | entry = controller_.GetPendingEntry(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1224 | else |
| 1225 | entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id); |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1226 | if (!entry || entry->GetURL() != source_url) |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1227 | return; |
[email protected] | e7d5089 | 2011-01-19 21:47:38 | [diff] [blame] | 1228 | |
[email protected] | 4850a7f | 2011-03-08 23:36:59 | [diff] [blame] | 1229 | // Notify observers about the provisional change in the main frame URL. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1230 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | eacb080b | 2011-05-22 19:40:26 | [diff] [blame] | 1231 | ProvisionalChangeToMainFrameUrl(target_url, |
[email protected] | 57b9396c | 2011-10-07 19:11:59 | [diff] [blame] | 1232 | opener_url)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | void TabContents::OnDidFailProvisionalLoadWithError( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1236 | const ViewHostMsg_DidFailProvisionalLoadWithError_Params& params) { |
| 1237 | VLOG(1) << "Failed Provisional Load: " << params.url.possibly_invalid_spec() |
| 1238 | << ", error_code: " << params.error_code |
| 1239 | << ", error_description: " << params.error_description |
| 1240 | << ", is_main_frame: " << params.is_main_frame |
| 1241 | << ", showing_repost_interstitial: " << |
| 1242 | params.showing_repost_interstitial |
| 1243 | << ", frame_id: " << params.frame_id; |
| 1244 | GURL validated_url(params.url); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1245 | GetRenderViewHost()->FilterURL(ChildProcessSecurityPolicy::GetInstance(), |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1246 | GetRenderProcessHost()->GetID(), &validated_url); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1247 | |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1248 | if (net::ERR_ABORTED == params.error_code) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1249 | // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
| 1250 | // This means that the interstitial won't be torn down properly, which is |
| 1251 | // bad. But if we have an interstitial, go back to another tab type, and |
| 1252 | // then load the same interstitial again, we could end up getting the first |
| 1253 | // interstitial's "failed" message (as a result of the cancel) when we're on |
| 1254 | // the second one. |
| 1255 | // |
| 1256 | // We can't tell this apart, so we think we're tearing down the current page |
| 1257 | // which will cause a crash later one. There is also some code in |
| 1258 | // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented |
| 1259 | // out because of this problem. |
| 1260 | // |
| 1261 | // http://code.google.com/p/chromium/issues/detail?id=2855 |
| 1262 | // Because this will not tear down the interstitial properly, if "back" is |
| 1263 | // back to another tab type, the interstitial will still be somewhat alive |
| 1264 | // in the previous tab type. If you navigate somewhere that activates the |
| 1265 | // tab with the interstitial again, you'll see a flash before the new load |
| 1266 | // commits of the interstitial page. |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1267 | if (ShowingInterstitialPage()) { |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1268 | LOG(WARNING) << "Discarding message during interstitial."; |
| 1269 | return; |
| 1270 | } |
| 1271 | |
[email protected] | 02102f8 | 2011-06-13 20:37:02 | [diff] [blame] | 1272 | // Discard our pending entry if the load canceled (e.g. if we decided to |
| 1273 | // download the file instead of load it). We do not verify that the URL |
| 1274 | // being canceled matches the pending entry's URL because they will not |
| 1275 | // match if a redirect occurred (in which case we do not want to leave a |
| 1276 | // stale redirect URL showing). This means that we also cancel the pending |
| 1277 | // entry if the user started a new navigation. As a result, the navigation |
| 1278 | // controller may not remember that a load is in progress, but the |
| 1279 | // navigation will still commit even if there is no pending entry. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1280 | if (controller_.GetPendingEntry()) |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 1281 | DidCancelLoading(); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1282 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1283 | render_manager_.RendererAbortedProvisionalLoad(GetRenderViewHost()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1284 | } |
| 1285 | |
| 1286 | // Send out a notification that we failed a provisional load with an error. |
| 1287 | ProvisionalLoadDetails details( |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1288 | params.is_main_frame, |
| 1289 | controller_.IsURLInPageNavigation(validated_url), |
| 1290 | validated_url, |
| 1291 | std::string(), |
| 1292 | false, |
| 1293 | params.frame_id); |
| 1294 | details.set_error_code(params.error_code); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1295 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1296 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1297 | content::NOTIFICATION_FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1298 | content::Source<NavigationController>(&controller_), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1299 | content::Details<ProvisionalLoadDetails>(&details)); |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1300 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1301 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | d7b175e | 2011-10-11 15:31:58 | [diff] [blame] | 1302 | observers_, |
| 1303 | DidFailProvisionalLoad(params.frame_id, |
| 1304 | params.is_main_frame, |
| 1305 | validated_url, |
| 1306 | params.error_code, |
| 1307 | params.error_description)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | void TabContents::OnDidLoadResourceFromMemoryCache( |
| 1311 | const GURL& url, |
[email protected] | 7043596 | 2011-08-02 20:13:28 | [diff] [blame] | 1312 | const std::string& security_info, |
| 1313 | const std::string& http_method, |
| 1314 | ResourceType::Type resource_type) { |
[email protected] | 2862086 | 2011-03-22 23:07:19 | [diff] [blame] | 1315 | base::StatsCounter cache("WebKit.CacheHit"); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1316 | cache.Increment(); |
| 1317 | |
| 1318 | // Send out a notification that we loaded a resource from our memory cache. |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 1319 | int cert_id = 0; |
| 1320 | net::CertStatus cert_status = 0; |
| 1321 | int security_bits = -1; |
| 1322 | int connection_status = 0; |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1323 | SSLManager::DeserializeSecurityInfo(security_info, |
| 1324 | &cert_id, &cert_status, |
| 1325 | &security_bits, |
| 1326 | &connection_status); |
[email protected] | f3b1a08 | 2011-11-18 00:34:30 | [diff] [blame] | 1327 | LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->GetID(), |
[email protected] | 7a8c55e | 2011-02-15 08:21:16 | [diff] [blame] | 1328 | cert_id, cert_status); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1329 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1330 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1331 | content::NOTIFICATION_LOAD_FROM_MEMORY_CACHE, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1332 | content::Source<NavigationController>(&controller_), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1333 | content::Details<LoadFromMemoryCacheDetails>(&details)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | void TabContents::OnDidDisplayInsecureContent() { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1337 | content::RecordAction(UserMetricsAction("SSL.DisplayedInsecureContent")); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1338 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1339 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1340 | } |
| 1341 | |
| 1342 | void TabContents::OnDidRunInsecureContent( |
[email protected] | 9277111 | 2011-01-20 00:13:02 | [diff] [blame] | 1343 | const std::string& security_origin, const GURL& target_url) { |
[email protected] | 9941cf5 | 2011-02-08 16:17:23 | [diff] [blame] | 1344 | LOG(INFO) << security_origin << " ran insecure content from " |
| 1345 | << target_url.possibly_invalid_spec(); |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1346 | content::RecordAction(UserMetricsAction("SSL.RanInsecureContent")); |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 1347 | if (EndsWith(security_origin, kDotGoogleDotCom, false)) { |
[email protected] | 7f6f44c | 2011-12-14 13:23:38 | [diff] [blame] | 1348 | content::RecordAction( |
[email protected] | ca40603 | 2011-07-19 21:53:05 | [diff] [blame] | 1349 | UserMetricsAction("SSL.RanInsecureContentGoogle")); |
| 1350 | } |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 1351 | controller_.GetSSLManager()->DidRunInsecureContent(security_origin); |
[email protected] | f2b58c4d | 2011-06-01 23:29:41 | [diff] [blame] | 1352 | displayed_insecure_content_ = true; |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 1353 | SSLManager::NotifySSLInternalStateChanged(&GetControllerImpl()); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1354 | } |
| 1355 | |
| 1356 | void TabContents::OnDocumentLoadedInFrame(int64 frame_id) { |
| 1357 | controller_.DocumentLoadedInFrame(); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1358 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1359 | DocumentLoadedInFrame(frame_id)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1360 | } |
| 1361 | |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1362 | void TabContents::OnDidFinishLoad( |
| 1363 | int64 frame_id, |
| 1364 | const GURL& validated_url, |
| 1365 | bool is_main_frame) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1366 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1367 | DidFinishLoad(frame_id, validated_url, is_main_frame)); |
| 1368 | } |
| 1369 | |
| 1370 | void TabContents::OnDidFailLoadWithError(int64 frame_id, |
| 1371 | const GURL& validated_url, |
| 1372 | bool is_main_frame, |
| 1373 | int error_code, |
| 1374 | const string16& error_description) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1375 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 1a55c5be | 2011-11-29 11:36:31 | [diff] [blame] | 1376 | DidFailLoad(frame_id, validated_url, is_main_frame, |
| 1377 | error_code, error_description)); |
[email protected] | 724159a | 2010-12-30 01:11:18 | [diff] [blame] | 1378 | } |
| 1379 | |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 1380 | void TabContents::OnUpdateContentRestrictions(int restrictions) { |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1381 | content_restrictions_ = restrictions; |
| 1382 | delegate_->ContentRestrictionsChanged(this); |
[email protected] | c8f73ab | 2011-01-22 00:05:17 | [diff] [blame] | 1383 | } |
| 1384 | |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1385 | void TabContents::OnGoToEntryAtOffset(int offset) { |
| 1386 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1387 | NavigationEntryImpl* entry = NavigationEntryImpl::FromNavigationEntry( |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1388 | controller_.GetEntryAtOffset(offset)); |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1389 | if (!entry) |
| 1390 | return; |
| 1391 | // Note that we don't call NavigationController::GotToOffset() as we don't |
| 1392 | // want to create a pending navigation entry (it might end up lingering |
| 1393 | // http://crbug.com/51680). |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 1394 | entry->SetTransitionType( |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1395 | content::PageTransitionFromInt( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1396 | entry->GetTransitionType() | |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1397 | content::PAGE_TRANSITION_FORWARD_BACK)); |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 1398 | NavigateToEntry(*entry, NavigationControllerImpl::NO_RELOAD); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1399 | |
| 1400 | // If the entry is being restored and doesn't have a SiteInstance yet, fill |
| 1401 | // it in now that we know. This allows us to find the entry when it commits. |
| 1402 | if (!entry->site_instance() && |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1403 | entry->restore_type() != NavigationEntryImpl::RESTORE_NONE) { |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1404 | entry->set_site_instance( |
| 1405 | static_cast<SiteInstanceImpl*>(GetPendingSiteInstance())); |
[email protected] | a13cc36 | 2011-07-28 21:29:57 | [diff] [blame] | 1406 | } |
[email protected] | 21681395 | 2011-05-19 22:21:26 | [diff] [blame] | 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | void TabContents::OnUpdateZoomLimits(int minimum_percent, |
| 1411 | int maximum_percent, |
| 1412 | bool remember) { |
| 1413 | minimum_zoom_percent_ = minimum_percent; |
| 1414 | maximum_zoom_percent_ = maximum_percent; |
| 1415 | temporary_zoom_settings_ = !remember; |
| 1416 | } |
| 1417 | |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 1418 | void TabContents::OnSaveURL(const GURL& url) { |
| 1419 | DownloadManager* dlm = GetBrowserContext()->GetDownloadManager(); |
| 1420 | dlm->DownloadUrl(url, GetURL(), "", this); |
| 1421 | } |
| 1422 | |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1423 | void TabContents::OnEnumerateDirectory(int request_id, |
| 1424 | const FilePath& path) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1425 | delegate_->EnumerateDirectory(this, request_id, path); |
[email protected] | 3a29a6e | 2011-08-24 18:26:21 | [diff] [blame] | 1426 | } |
| 1427 | |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1428 | void TabContents::OnJSOutOfMemory() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1429 | delegate_->JSOutOfMemory(this); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | void TabContents::OnRegisterProtocolHandler(const std::string& protocol, |
| 1433 | const GURL& url, |
| 1434 | const string16& title) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1435 | delegate_->RegisterProtocolHandler(this, protocol, url, title); |
[email protected] | 7d18902 | 2011-08-25 22:54:20 | [diff] [blame] | 1436 | } |
| 1437 | |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1438 | void TabContents::OnFindReply(int request_id, |
| 1439 | int number_of_matches, |
| 1440 | const gfx::Rect& selection_rect, |
| 1441 | int active_match_ordinal, |
| 1442 | bool final_update) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1443 | delegate_->FindReply(this, request_id, number_of_matches, selection_rect, |
| 1444 | active_match_ordinal, final_update); |
[email protected] | 4e6239c | 2011-09-23 00:11:00 | [diff] [blame] | 1445 | // Send a notification to the renderer that we are ready to receive more |
| 1446 | // results from the scoping effort of the Find operation. The FindInPage |
| 1447 | // scoping is asynchronous and periodically sends results back up to the |
| 1448 | // browser using IPC. In an effort to not spam the browser we have the |
| 1449 | // browser send an ACK for each FindReply message and have the renderer |
| 1450 | // queue up the latest status message while waiting for this ACK. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1451 | GetRenderViewHost()->Send( |
| 1452 | new ViewMsg_FindReplyACK(GetRenderViewHost()->routing_id())); |
[email protected] | b888919c | 2011-09-02 00:32:16 | [diff] [blame] | 1453 | } |
| 1454 | |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1455 | void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1456 | delegate_->CrashedPlugin(this, plugin_path); |
[email protected] | d952a05 | 2011-09-06 18:42:45 | [diff] [blame] | 1457 | } |
| 1458 | |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 1459 | void TabContents::OnAppCacheAccessed(const GURL& manifest_url, |
| 1460 | bool blocked_by_policy) { |
| 1461 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1462 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 7fc4bbb | 2011-09-08 21:23:10 | [diff] [blame] | 1463 | AppCacheAccessed(manifest_url, blocked_by_policy)); |
| 1464 | } |
| 1465 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1466 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 1467 | // loading, or done loading and calls the base implementation. |
| 1468 | void TabContents::SetIsLoading(bool is_loading, |
| 1469 | LoadNotificationDetails* details) { |
| 1470 | if (is_loading == is_loading_) |
| 1471 | return; |
| 1472 | |
| 1473 | if (!is_loading) { |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 1474 | load_state_ = net::LoadStateWithParam(net::LOAD_STATE_IDLE, string16()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1475 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 1476 | upload_size_ = 0; |
| 1477 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1478 | } |
| 1479 | |
| 1480 | render_manager_.SetIsLoading(is_loading); |
| 1481 | |
| 1482 | is_loading_ = is_loading; |
| 1483 | waiting_for_response_ = is_loading; |
| 1484 | |
[email protected] | 6ebdc9b | 2010-09-27 16:55:57 | [diff] [blame] | 1485 | if (delegate_) |
| 1486 | delegate_->LoadingStateChanged(this); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1487 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1488 | |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1489 | int type = is_loading ? content::NOTIFICATION_LOAD_START : |
| 1490 | content::NOTIFICATION_LOAD_STOP; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1491 | content::NotificationDetails det = content::NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1492 | if (details) |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1493 | det = content::Details<LoadNotificationDetails>(details); |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1494 | content::NotificationService::current()->Notify(type, |
[email protected] | c5eed49 | 2012-01-04 17:07:50 | [diff] [blame] | 1495 | content::Source<NavigationController>(&controller_), |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1496 | det); |
| 1497 | } |
| 1498 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1499 | void TabContents::DidNavigateMainFramePostCommit( |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 1500 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1501 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1502 | if (opener_web_ui_type_ != WebUI::kNoWebUI) { |
[email protected] | 80a8fad | 2011-01-29 04:02:38 | [diff] [blame] | 1503 | // 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] | 1504 | // that opened the window, as long as both renderers have the same |
| 1505 | // privileges. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1506 | if (delegate_ && opener_web_ui_type_ == GetWebUITypeForCurrentState()) { |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 1507 | WebUIImpl* web_ui = static_cast<WebUIImpl*>(CreateWebUI(GetURL())); |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1508 | // web_ui might be NULL if the URL refers to a non-existent extension. |
| 1509 | if (web_ui) { |
[email protected] | d098079 | 2011-02-13 19:41:40 | [diff] [blame] | 1510 | render_manager_.SetWebUIPostCommit(web_ui); |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1511 | web_ui->RenderViewCreated(GetRenderViewHost()); |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1512 | } |
| 1513 | } |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1514 | opener_web_ui_type_ = WebUI::kNoWebUI; |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1515 | } |
| 1516 | |
[email protected] | 4e697b04 | 2011-07-08 06:44:56 | [diff] [blame] | 1517 | if (details.is_navigation_to_different_page()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1518 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1519 | // doesn't let us know that the cursor left an element during a |
| 1520 | // transition (this is also why the mouse cursor remains as a hand after |
| 1521 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1522 | // clear the bubble when a user navigates to a named anchor in the same |
| 1523 | // page. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1524 | UpdateTargetURL(details.entry->GetPageID(), GURL()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1525 | } |
| 1526 | |
[email protected] | a6e82fc | 2010-02-24 22:28:14 | [diff] [blame] | 1527 | if (!details.is_in_page) { |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 1528 | // Once the main frame is navigated, we're no longer considered to have |
| 1529 | // displayed insecure content. |
| 1530 | displayed_insecure_content_ = false; |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1531 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1532 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1533 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1534 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 1535 | DidNavigateMainFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1536 | } |
| 1537 | |
| 1538 | void TabContents::DidNavigateAnyFramePostCommit( |
| 1539 | RenderViewHost* render_view_host, |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 1540 | const content::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1541 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | e550f5e | 2012-01-11 07:22:06 | [diff] [blame] | 1542 | // If we navigate off the page, reset JavaScript state. This does nothing |
| 1543 | // to prevent a malicious script from spamming messages, since the script |
| 1544 | // could just reload the page to stop blocking. |
| 1545 | if (dialog_creator_ && !details.is_in_page) { |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 1546 | dialog_creator_->ResetJavaScriptState(this); |
| 1547 | dialog_creator_ = NULL; |
| 1548 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1549 | |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1550 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1551 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | a6e16aec | 2011-11-11 18:53:04 | [diff] [blame] | 1552 | DidNavigateAnyFrame(details, params)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1553 | } |
| 1554 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1555 | void TabContents::UpdateMaxPageIDIfNecessary(RenderViewHost* rvh) { |
| 1556 | // If we are creating a RVH for a restored controller, then we need to make |
| 1557 | // sure the RenderView starts with a next_page_id_ larger than the number |
| 1558 | // of restored entries. This must be called before the RenderView starts |
| 1559 | // navigating (to avoid a race between the browser updating max_page_id and |
| 1560 | // the renderer updating next_page_id_). Because of this, we only call this |
| 1561 | // from CreateRenderView and allow that to notify the RenderView for us. |
[email protected] | 71fde35 | 2011-12-29 03:29:56 | [diff] [blame] | 1562 | int max_restored_page_id = controller_.GetMaxRestoredPageID(); |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 1563 | if (max_restored_page_id > GetMaxPageIDForSiteInstance(rvh->site_instance())) |
| 1564 | UpdateMaxPageIDForSiteInstance(rvh->site_instance(), max_restored_page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1565 | } |
| 1566 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1567 | bool TabContents::UpdateTitleForEntry(NavigationEntryImpl* entry, |
[email protected] | acafd27 | 2011-07-26 17:35:57 | [diff] [blame] | 1568 | const string16& title) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1569 | // For file URLs without a title, use the pathname instead. In the case of a |
| 1570 | // synthesized title, we don't want the update to count toward the "one set |
| 1571 | // per page of the title to history." |
[email protected] | 6b2f7a8 | 2011-04-25 19:30:51 | [diff] [blame] | 1572 | string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1573 | bool explicit_set; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1574 | if (entry && entry->GetURL().SchemeIsFile() && title.empty()) { |
| 1575 | final_title = UTF8ToUTF16(entry->GetURL().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1576 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1577 | } else { |
[email protected] | acafd27 | 2011-07-26 17:35:57 | [diff] [blame] | 1578 | TrimWhitespace(title, TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1579 | explicit_set = true; |
| 1580 | } |
| 1581 | |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1582 | // If a page is created via window.open and never navigated, |
| 1583 | // there will be no navigation entry. In this situation, |
| 1584 | // |page_title_when_no_navigaiton_entry_| will be used for page title. |
| 1585 | if (entry) { |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1586 | if (final_title == entry->GetTitle()) |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1587 | return false; // Nothing changed, don't bother. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1588 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1589 | entry->SetTitle(final_title); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1590 | } else { |
| 1591 | if (page_title_when_no_navigation_entry_ == final_title) |
| 1592 | return false; // Nothing changed, don't bother. |
| 1593 | |
| 1594 | page_title_when_no_navigation_entry_ = final_title; |
| 1595 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1596 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1597 | // Lastly, set the title for the view. |
[email protected] | 790e2fd | 2011-09-21 20:28:23 | [diff] [blame] | 1598 | view_->SetPageTitle(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1599 | |
[email protected] | 105bb0f | 2011-05-24 17:12:14 | [diff] [blame] | 1600 | TitleUpdatedDetails details(entry, explicit_set); |
| 1601 | |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1602 | content::NotificationService::current()->Notify( |
[email protected] | bb81f38 | 2012-01-03 22:45:44 | [diff] [blame] | 1603 | content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, |
| 1604 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1605 | content::Details<TitleUpdatedDetails>(&details)); |
[email protected] | cbc0e1b | 2010-04-12 18:33:04 | [diff] [blame] | 1606 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1607 | return true; |
| 1608 | } |
| 1609 | |
| 1610 | void TabContents::NotifySwapped() { |
| 1611 | // After sending out a swap notification, we need to send a disconnect |
| 1612 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 1613 | // pointer. See Bug 1230284. |
| 1614 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1615 | content::NotificationService::current()->Notify( |
[email protected] | 4ca1530 | 2012-01-03 05:53:20 | [diff] [blame] | 1616 | content::NOTIFICATION_WEB_CONTENTS_SWAPPED, |
| 1617 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1618 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1619 | } |
| 1620 | |
| 1621 | void TabContents::NotifyConnected() { |
| 1622 | notify_disconnection_ = true; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1623 | content::NotificationService::current()->Notify( |
[email protected] | ef9572e | 2012-01-04 22:14:12 | [diff] [blame] | 1624 | content::NOTIFICATION_WEB_CONTENTS_CONNECTED, |
| 1625 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1626 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1627 | } |
| 1628 | |
| 1629 | void TabContents::NotifyDisconnected() { |
| 1630 | if (!notify_disconnection_) |
| 1631 | return; |
| 1632 | |
| 1633 | notify_disconnection_ = false; |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1634 | content::NotificationService::current()->Notify( |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1635 | content::NOTIFICATION_WEB_CONTENTS_DISCONNECTED, |
| 1636 | content::Source<WebContents>(this), |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1637 | content::NotificationService::NoDetails()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1638 | } |
| 1639 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 1640 | RenderViewHostDelegate::View* TabContents::GetViewDelegate() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1641 | return view_.get(); |
| 1642 | } |
| 1643 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 1644 | RenderViewHostDelegate::RendererManagement* |
| 1645 | TabContents::GetRendererManagementDelegate() { |
| 1646 | return &render_manager_; |
| 1647 | } |
| 1648 | |
[email protected] | daf82f8 | 2011-10-31 22:35:31 | [diff] [blame] | 1649 | content::RendererPreferences TabContents::GetRendererPrefs( |
[email protected] | 3d7474ff | 2011-07-27 17:47:37 | [diff] [blame] | 1650 | content::BrowserContext* browser_context) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 1651 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 1652 | } |
| 1653 | |
[email protected] | 768c547 | 2011-12-26 19:06:17 | [diff] [blame] | 1654 | WebContents* TabContents::GetAsWebContents() { |
| 1655 | return this; |
| 1656 | } |
| 1657 | |
[email protected] | da4dfc4 | 2011-10-12 15:53:56 | [diff] [blame] | 1658 | content::ViewType TabContents::GetRenderViewType() const { |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 1659 | return view_type_; |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 1660 | } |
| 1661 | |
[email protected] | b7a756d4 | 2012-01-23 18:08:17 | [diff] [blame] | 1662 | gfx::Rect TabContents::GetRootWindowResizerRect() const { |
| 1663 | if (delegate_) |
| 1664 | return delegate_->GetRootWindowResizerRect(); |
| 1665 | return gfx::Rect(); |
| 1666 | } |
| 1667 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1668 | void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1669 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1670 | content::NOTIFICATION_RENDER_VIEW_HOST_CREATED_FOR_TAB, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1671 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1672 | content::Details<RenderViewHost>(render_view_host)); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1673 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1674 | if (!entry) |
| 1675 | return; |
| 1676 | |
| 1677 | // 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] | 1678 | // use the pending Web UI rather than any possibly existing committed one. |
[email protected] | 1fd1a50 | 2011-03-30 16:55:56 | [diff] [blame] | 1679 | if (render_manager_.pending_web_ui()) |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1680 | render_manager_.pending_web_ui()->RenderViewCreated(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1681 | |
| 1682 | if (entry->IsViewSourceMode()) { |
| 1683 | // Put the renderer in view source mode. |
| 1684 | render_view_host->Send( |
| 1685 | new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 1686 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 1687 | |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1688 | GetView()->RenderViewCreated(render_view_host); |
[email protected] | 11f764bb | 2011-05-25 19:45:26 | [diff] [blame] | 1689 | |
| 1690 | FOR_EACH_OBSERVER( |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1691 | WebContentsObserver, observers_, RenderViewCreated(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1692 | } |
| 1693 | |
| 1694 | void TabContents::RenderViewReady(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1695 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1696 | // Don't notify the world, since this came from a renderer in the |
| 1697 | // background. |
| 1698 | return; |
| 1699 | } |
| 1700 | |
| 1701 | NotifyConnected(); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1702 | bool was_crashed = IsCrashed(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1703 | SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 1704 | |
| 1705 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 1706 | // window). |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 1707 | if (was_crashed && !FocusLocationBarByDefault() && |
| 1708 | (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) { |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 1709 | Focus(); |
[email protected] | 484ae591 | 2010-09-29 19:16:14 | [diff] [blame] | 1710 | } |
[email protected] | 32ded221 | 2011-11-10 18:51:43 | [diff] [blame] | 1711 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1712 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewReady()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1713 | } |
| 1714 | |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1715 | void TabContents::RenderViewGone(RenderViewHost* rvh, |
| 1716 | base::TerminationStatus status, |
| 1717 | int error_code) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1718 | if (rvh != GetRenderViewHost()) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1719 | // The pending page's RenderViewHost is gone. |
| 1720 | return; |
| 1721 | } |
| 1722 | |
| 1723 | SetIsLoading(false, NULL); |
| 1724 | NotifyDisconnected(); |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 1725 | SetIsCrashed(status, error_code); |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1726 | GetView()->OnTabCrashed(GetCrashedStatus(), crashed_error_code_); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1727 | |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1728 | FOR_EACH_OBSERVER(WebContentsObserver, |
[email protected] | 9cddb1a2 | 2011-11-15 15:04:27 | [diff] [blame] | 1729 | observers_, |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1730 | RenderViewGone(GetCrashedStatus())); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1731 | } |
| 1732 | |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 1733 | void TabContents::RenderViewDeleted(RenderViewHost* rvh) { |
[email protected] | fb7b79f7 | 2009-11-06 18:00:48 | [diff] [blame] | 1734 | render_manager_.RenderViewDeleted(rvh); |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1735 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, RenderViewDeleted(rvh)); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 1736 | } |
| 1737 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1738 | void TabContents::DidNavigate(RenderViewHost* rvh, |
| 1739 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1740 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1741 | render_manager_.DidNavigateMainFrame(rvh); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 1742 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1743 | // Update the site of the SiteInstance if it doesn't have one yet. |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 1744 | if (!static_cast<SiteInstanceImpl*>(GetSiteInstance())->HasSite()) |
| 1745 | static_cast<SiteInstanceImpl*>(GetSiteInstance())->SetSite(params.url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1746 | |
| 1747 | // Need to update MIME type here because it's referred to in |
| 1748 | // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 1749 | // determine whether or not to enable the encoding menu. |
| 1750 | // It's updated only for the main frame. For a subframe, |
| 1751 | // RenderView::UpdateURL does not set params.contents_mime_type. |
| 1752 | // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 1753 | // TODO(jungshik): Add a test for the encoding menu to avoid |
| 1754 | // regressing it again. |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1755 | if (content::PageTransitionIsMainFrame(params.transition)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1756 | contents_mime_type_ = params.contents_mime_type; |
| 1757 | |
[email protected] | 8286f51a | 2011-05-31 17:39:13 | [diff] [blame] | 1758 | content::LoadCommittedDetails details; |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1759 | bool did_navigate = controller_.RendererDidNavigate(params, &details); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 1760 | |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 1761 | // Send notification about committed provisional loads. This notification is |
| 1762 | // different from the NAV_ENTRY_COMMITTED notification which doesn't include |
| 1763 | // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations. |
[email protected] | 610cbb8 | 2011-10-18 16:35:08 | [diff] [blame] | 1764 | if (details.type != content::NAVIGATION_TYPE_NAV_IGNORE) { |
[email protected] | dabb0d1 | 2010-10-05 12:50:07 | [diff] [blame] | 1765 | // For AUTO_SUBFRAME navigations, an event for the main frame is generated |
| 1766 | // that is not recorded in the navigation history. For the purpose of |
| 1767 | // tracking navigation events, we treat this event as a sub frame navigation |
| 1768 | // event. |
| 1769 | bool is_main_frame = did_navigate ? details.is_main_frame : false; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1770 | content::PageTransition transition_type = params.transition; |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 1771 | // Whether or not a page transition was triggered by going backward or |
| 1772 | // forward in the history is only stored in the navigation controller's |
| 1773 | // entry list. |
| 1774 | if (did_navigate && |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1775 | (controller_.GetActiveEntry()->GetTransitionType() & |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1776 | content::PAGE_TRANSITION_FORWARD_BACK)) { |
| 1777 | transition_type = content::PageTransitionFromInt( |
| 1778 | params.transition | content::PAGE_TRANSITION_FORWARD_BACK); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 1779 | } |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1780 | // Notify observers about the commit of the provisional load. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1781 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 0d60f019 | 2011-04-14 12:40:10 | [diff] [blame] | 1782 | DidCommitProvisionalLoadForFrame(params.frame_id, |
| 1783 | is_main_frame, params.url, transition_type)); |
[email protected] | a9c0bfe | 2010-09-17 08:35:22 | [diff] [blame] | 1784 | } |
| 1785 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 1786 | if (!did_navigate) |
| 1787 | return; // No navigation happened. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1788 | |
| 1789 | // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 1790 | // for the appropriate notification (best) or you can add it to |
| 1791 | // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 1792 | // necessary, please). |
| 1793 | |
| 1794 | // Run post-commit tasks. |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1795 | if (details.is_main_frame) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1796 | DidNavigateMainFramePostCommit(details, params); |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1797 | if (delegate_) |
| 1798 | delegate_->DidNavigateMainFramePostCommit(this); |
[email protected] | 93f230e0 | 2011-06-01 14:40:00 | [diff] [blame] | 1799 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1800 | DidNavigateAnyFramePostCommit(rvh, details, params); |
| 1801 | } |
| 1802 | |
| 1803 | void TabContents::UpdateState(RenderViewHost* rvh, |
| 1804 | int32 page_id, |
| 1805 | const std::string& state) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1806 | // Ensure that this state update comes from either the active RVH or one of |
| 1807 | // 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] | 1808 | DCHECK(rvh == GetRenderViewHost() || render_manager_.IsSwappedOut(rvh)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1809 | |
| 1810 | // We must be prepared to handle state updates for any page, these occur |
| 1811 | // when the user is scrolling and entering form data, as well as when we're |
| 1812 | // leaving a page, in which case our state may have already been moved to |
| 1813 | // the next page. The navigation controller will look up the appropriate |
| 1814 | // NavigationEntry and update it when it is notified via the delegate. |
| 1815 | |
| 1816 | int entry_index = controller_.GetEntryIndexWithPageID( |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 1817 | rvh->site_instance(), page_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1818 | if (entry_index < 0) |
| 1819 | return; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1820 | NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1821 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1822 | if (state == entry->GetContentState()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1823 | return; // Nothing to update. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1824 | entry->SetContentState(state); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1825 | controller_.NotifyEntryChanged(entry, entry_index); |
| 1826 | } |
| 1827 | |
| 1828 | void TabContents::UpdateTitle(RenderViewHost* rvh, |
[email protected] | acafd27 | 2011-07-26 17:35:57 | [diff] [blame] | 1829 | int32 page_id, |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1830 | const string16& title, |
| 1831 | base::i18n::TextDirection title_direction) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1832 | // If we have a title, that's a pretty good indication that we've started |
| 1833 | // getting useful data. |
| 1834 | SetNotWaitingForResponse(); |
| 1835 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1836 | DCHECK(rvh == GetRenderViewHost()); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1837 | NavigationEntryImpl* entry = controller_.GetEntryWithPageID( |
| 1838 | rvh->site_instance(), page_id); |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1839 | |
[email protected] | a49e10b | 2011-08-01 23:57:46 | [diff] [blame] | 1840 | // TODO(evan): make use of title_direction. |
| 1841 | // http://code.google.com/p/chromium/issues/detail?id=27094 |
[email protected] | 987fc3a | 2011-05-26 14:18:09 | [diff] [blame] | 1842 | if (!UpdateTitleForEntry(entry, title)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1843 | return; |
| 1844 | |
| 1845 | // Broadcast notifications when the UI should be updated. |
| 1846 | if (entry == controller_.GetEntryAtOffset(0)) |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1847 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1848 | } |
| 1849 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1850 | void TabContents::UpdateEncoding(RenderViewHost* render_view_host, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 1851 | const std::string& encoding) { |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 1852 | SetEncoding(encoding); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1856 | if (delegate_) |
| 1857 | delegate_->UpdateTargetURL(this, page_id, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1858 | } |
| 1859 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1860 | void TabContents::Close(RenderViewHost* rvh) { |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 1861 | // The UI may be in an event-tracking loop, such as between the |
| 1862 | // mouse-down and mouse-up in text selection or a button click. |
| 1863 | // Defer the close until after tracking is complete, so that we |
| 1864 | // don't free objects out from under the UI. |
| 1865 | // TODO(shess): This could probably be integrated with the |
| 1866 | // IsDoingDrag() test below. Punting for now because I need more |
| 1867 | // research to understand how this impacts platforms other than Mac. |
| 1868 | // TODO(shess): This could get more fine-grained. For instance, |
| 1869 | // closing a tab in another window while selecting text in the |
| 1870 | // current window's Omnibox should be just fine. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1871 | if (GetView()->IsEventTracking()) { |
| 1872 | GetView()->CloseTabAfterEventTracking(); |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 1873 | return; |
| 1874 | } |
| 1875 | |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 1876 | // If we close the tab while we're in the middle of a drag, we'll crash. |
| 1877 | // Instead, cancel the drag and close it as soon as the drag ends. |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 1878 | if (GetView()->IsDoingDrag()) { |
| 1879 | GetView()->CancelDragAndCloseTab(); |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 1880 | return; |
| 1881 | } |
| 1882 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1883 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1884 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1885 | delegate_->CloseContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1886 | } |
| 1887 | |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 1888 | void TabContents::SwappedOut(RenderViewHost* rvh) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 1889 | if (delegate_ && rvh == GetRenderViewHost()) |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1890 | delegate_->SwappedOut(this); |
[email protected] | cd9ed79d | 2011-11-15 19:22:57 | [diff] [blame] | 1891 | } |
| 1892 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1893 | void TabContents::RequestMove(const gfx::Rect& new_bounds) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1894 | if (delegate_ && delegate_->IsPopupOrPanel(this)) |
| 1895 | delegate_->MoveContents(this, new_bounds); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1896 | } |
| 1897 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1898 | void TabContents::DidStartLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1899 | SetIsLoading(true, NULL); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1900 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1901 | if (delegate_ && content_restrictions_) { |
[email protected] | c40d623 | 2011-03-25 00:16:21 | [diff] [blame] | 1902 | content_restrictions_ = 0; |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1903 | delegate_->ContentRestrictionsChanged(this); |
[email protected] | 9e82366 | 2010-10-13 23:36:00 | [diff] [blame] | 1904 | } |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1905 | |
| 1906 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1907 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStartLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1908 | } |
| 1909 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1910 | void TabContents::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1911 | scoped_ptr<LoadNotificationDetails> details; |
| 1912 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 1913 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1914 | // An entry may not exist for a stop when loading an initial blank page or |
| 1915 | // if an iframe injected by script into a blank page finishes loading. |
| 1916 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1917 | base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; |
| 1918 | |
| 1919 | details.reset(new LoadNotificationDetails( |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 1920 | entry->GetVirtualURL(), |
| 1921 | entry->GetTransitionType(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1922 | elapsed, |
| 1923 | &controller_, |
| 1924 | controller_.GetCurrentEntryIndex())); |
| 1925 | } |
| 1926 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1927 | SetIsLoading(false, details.get()); |
[email protected] | 3c9e187 | 2010-11-18 16:17:49 | [diff] [blame] | 1928 | |
| 1929 | // Notify observers about navigation. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1930 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidStopLoading()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1931 | } |
| 1932 | |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 1933 | void TabContents::DidCancelLoading() { |
| 1934 | controller_.DiscardNonCommittedEntries(); |
| 1935 | |
| 1936 | // Update the URL display. |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 1937 | NotifyNavigationStateChanged(content::INVALIDATE_TYPE_URL); |
[email protected] | c95fa8b | 2011-04-28 20:26:16 | [diff] [blame] | 1938 | } |
| 1939 | |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 1940 | void TabContents::DidChangeLoadProgress(double progress) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 1941 | if (delegate_) |
| 1942 | delegate_->LoadProgressChanged(progress); |
[email protected] | 1a3c3cb | 2010-12-16 21:03:40 | [diff] [blame] | 1943 | } |
| 1944 | |
[email protected] | 952a68e | 2011-11-17 00:36:10 | [diff] [blame] | 1945 | void TabContents::DocumentAvailableInMainFrame( |
| 1946 | RenderViewHost* render_view_host) { |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 1947 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | 952a68e | 2011-11-17 00:36:10 | [diff] [blame] | 1948 | DocumentAvailableInMainFrame()); |
| 1949 | } |
| 1950 | |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 1951 | void TabContents::DocumentOnLoadCompletedInMainFrame( |
| 1952 | RenderViewHost* render_view_host, |
| 1953 | int32 page_id) { |
[email protected] | ad50def5 | 2011-10-19 23:17:07 | [diff] [blame] | 1954 | content::NotificationService::current()->Notify( |
[email protected] | 43211582 | 2011-07-10 15:52:27 | [diff] [blame] | 1955 | content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, |
[email protected] | fbc5e5f9 | 2012-01-02 06:08:32 | [diff] [blame] | 1956 | content::Source<WebContents>(this), |
[email protected] | 6c2381d | 2011-10-19 02:52:53 | [diff] [blame] | 1957 | content::Details<int>(&page_id)); |
[email protected] | 2549749 | 2010-09-11 15:15:08 | [diff] [blame] | 1958 | } |
| 1959 | |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1960 | void TabContents::RequestOpenURL(const GURL& url, |
[email protected] | 445e104 | 2011-12-03 21:03:15 | [diff] [blame] | 1961 | const content::Referrer& referrer, |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1962 | WindowOpenDisposition disposition, |
| 1963 | int64 source_frame_id) { |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1964 | // Delegate to RequestTransferURL because this is just the generic |
| 1965 | // case where |old_request_id| is empty. |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 1966 | RequestTransferURL(url, referrer, disposition, source_frame_id, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1967 | GlobalRequestID()); |
| 1968 | } |
| 1969 | |
| 1970 | void TabContents::RequestTransferURL(const GURL& url, |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 1971 | const content::Referrer& referrer, |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1972 | WindowOpenDisposition disposition, |
| 1973 | int64 source_frame_id, |
| 1974 | const GlobalRequestID& old_request_id) { |
[email protected] | e5d549d | 2011-12-28 01:29:20 | [diff] [blame] | 1975 | WebContents* new_contents = NULL; |
[email protected] | 2905f74 | 2011-10-13 03:51:58 | [diff] [blame] | 1976 | content::PageTransition transition_type = content::PAGE_TRANSITION_LINK; |
[email protected] | 7ade273 | 2011-02-10 00:13:58 | [diff] [blame] | 1977 | if (render_manager_.web_ui()) { |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1978 | // 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] | 1979 | // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 1980 | // generated suggestions). |
| 1981 | // |
[email protected] | e011291 | 2011-02-02 22:54:35 | [diff] [blame] | 1982 | // 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] | 1983 | // want web sites to see a referrer of "chrome://blah" (and some |
| 1984 | // 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] | 1985 | // send to the site), so we send no referrer. |
[email protected] | bce1f1c | 2011-12-05 15:11:58 | [diff] [blame] | 1986 | OpenURLParams params(url, content::Referrer(), disposition, |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1987 | render_manager_.web_ui()->GetLinkTransitionType(), |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1988 | false /* is_renderer_initiated */); |
| 1989 | params.transferred_global_request_id = old_request_id; |
| 1990 | new_contents = OpenURL(params); |
[email protected] | c63cedf2 | 2012-01-17 18:42:22 | [diff] [blame] | 1991 | transition_type = render_manager_.web_ui()->GetLinkTransitionType(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1992 | } else { |
[email protected] | 4ad5d77d | 2011-12-03 02:00:48 | [diff] [blame] | 1993 | OpenURLParams params(url, referrer, disposition, |
| 1994 | content::PAGE_TRANSITION_LINK, true /* is_renderer_initiated */); |
| 1995 | params.transferred_global_request_id = old_request_id; |
| 1996 | new_contents = OpenURL(params); |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 1997 | } |
| 1998 | if (new_contents) { |
| 1999 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2000 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, |
[email protected] | ae5184d6 | 2011-10-06 19:25:58 | [diff] [blame] | 2001 | DidOpenRequestedURL(new_contents, |
| 2002 | url, |
| 2003 | referrer, |
| 2004 | disposition, |
| 2005 | transition_type, |
| 2006 | source_frame_id)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2007 | } |
| 2008 | } |
| 2009 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2010 | void TabContents::RunJavaScriptMessage( |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2011 | const RenderViewHost* rvh, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2012 | const string16& message, |
| 2013 | const string16& default_prompt, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2014 | const GURL& frame_url, |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2015 | ui::JavascriptMessageType javascript_message_type, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2016 | IPC::Message* reply_msg, |
| 2017 | bool* did_suppress_message) { |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2018 | // Suppress JavaScript dialogs when requested. Also suppress messages when |
| 2019 | // showing an interstitial as it's shown over the previous page and we don't |
| 2020 | // want the hidden page's dialogs to interfere with the interstitial. |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2021 | bool suppress_this_message = |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2022 | rvh->is_swapped_out() || |
[email protected] | 0bfbf88 | 2011-12-22 18:19:27 | [diff] [blame] | 2023 | ShowingInterstitialPage() || |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2024 | !delegate_ || |
| 2025 | delegate_->ShouldSuppressDialogs(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2026 | |
| 2027 | if (!suppress_this_message) { |
[email protected] | b627d9a | 2011-06-28 14:06:34 | [diff] [blame] | 2028 | content::JavaScriptDialogCreator::TitleType title_type; |
| 2029 | string16 title; |
| 2030 | |
| 2031 | if (!frame_url.has_host()) { |
| 2032 | title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_NONE; |
| 2033 | } else { |
| 2034 | title_type = content::JavaScriptDialogCreator::DIALOG_TITLE_FORMATTED_URL; |
| 2035 | title = net::FormatUrl( |
| 2036 | frame_url.GetOrigin(), |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2037 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2038 | GetBrowserContext())); |
[email protected] | b627d9a | 2011-06-28 14:06:34 | [diff] [blame] | 2039 | } |
| 2040 | |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2041 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
| 2042 | dialog_creator_->RunJavaScriptDialog(this, |
| 2043 | title_type, |
| 2044 | title, |
[email protected] | 269f86d | 2011-12-07 02:43:47 | [diff] [blame] | 2045 | javascript_message_type, |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2046 | message, |
| 2047 | default_prompt, |
| 2048 | reply_msg, |
| 2049 | &suppress_this_message); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2050 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2051 | |
| 2052 | if (suppress_this_message) { |
| 2053 | // If we are suppressing messages, just reply as if the user immediately |
| 2054 | // pressed "Cancel". |
| 2055 | OnDialogClosed(reply_msg, false, string16()); |
| 2056 | } |
| 2057 | |
| 2058 | *did_suppress_message = suppress_this_message; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2059 | } |
| 2060 | |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2061 | void TabContents::RunBeforeUnloadConfirm(const RenderViewHost* rvh, |
[email protected] | 4f5ce84 | 2011-05-27 19:34:41 | [diff] [blame] | 2062 | const string16& message, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2063 | IPC::Message* reply_msg) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2064 | if (delegate_) |
| 2065 | delegate_->WillRunBeforeUnloadConfirm(); |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2066 | |
| 2067 | bool suppress_this_message = |
| 2068 | rvh->is_swapped_out() || |
| 2069 | !delegate_ || |
| 2070 | delegate_->ShouldSuppressDialogs(); |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2071 | if (suppress_this_message) { |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2072 | GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, true, string16()); |
[email protected] | 8f55e80 | 2010-12-06 18:11:50 | [diff] [blame] | 2073 | return; |
| 2074 | } |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2075 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2076 | is_showing_before_unload_dialog_ = true; |
[email protected] | 2e5b90c | 2011-08-16 21:11:55 | [diff] [blame] | 2077 | dialog_creator_ = delegate_->GetJavaScriptDialogCreator(); |
| 2078 | dialog_creator_->RunBeforeUnloadDialog(this, |
| 2079 | message, |
| 2080 | reply_msg); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2081 | } |
| 2082 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2083 | WebPreferences TabContents::GetWebkitPrefs() { |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2084 | WebPreferences web_prefs = |
[email protected] | 181a95ee | 2011-07-12 19:26:36 | [diff] [blame] | 2085 | content::GetContentClient()->browser()->GetWebkitPrefs( |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2086 | GetRenderViewHost()); |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2087 | |
[email protected] | b8299c1 | 2011-06-03 19:52:28 | [diff] [blame] | 2088 | // Force accelerated compositing and 2d canvas off for chrome:, about: and |
[email protected] | 2ef216b | 2011-08-01 19:25:21 | [diff] [blame] | 2089 | // chrome-devtools: pages (unless it's specifically allowed). |
| 2090 | if ((GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || |
[email protected] | 30b8e0ee | 2011-09-12 14:45:57 | [diff] [blame] | 2091 | // Allow accelerated compositing for keyboard and log in screen. |
[email protected] | b8299c1 | 2011-06-03 19:52:28 | [diff] [blame] | 2092 | GetURL().SchemeIs(chrome::kChromeUIScheme) || |
[email protected] | cd4a5bd2 | 2011-09-13 06:46:30 | [diff] [blame] | 2093 | (GetURL().SchemeIs(chrome::kAboutScheme) && |
| 2094 | GetURL().spec() != chrome::kAboutBlankURL)) && |
[email protected] | 2ef216b | 2011-08-01 19:25:21 | [diff] [blame] | 2095 | !web_prefs.allow_webui_compositing) { |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2096 | web_prefs.accelerated_compositing_enabled = false; |
[email protected] | 9beff75 | 2010-09-22 19:35:43 | [diff] [blame] | 2097 | web_prefs.accelerated_2d_canvas_enabled = false; |
[email protected] | 447021c | 2010-09-08 21:29:08 | [diff] [blame] | 2098 | } |
| 2099 | |
| 2100 | return web_prefs; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2101 | } |
| 2102 | |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2103 | void TabContents::OnUserGesture() { |
[email protected] | ddb8505 | 2011-05-18 14:40:27 | [diff] [blame] | 2104 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2105 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetUserGesture()); |
[email protected] | 68649314 | 2011-07-15 21:47:22 | [diff] [blame] | 2106 | |
[email protected] | 9990736 | 2012-01-11 05:41:40 | [diff] [blame] | 2107 | ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get(); |
[email protected] | b39e7a88b | 2012-01-10 21:43:17 | [diff] [blame] | 2108 | if (rdh) // NULL in unittests. |
| 2109 | rdh->OnUserGesture(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2110 | } |
| 2111 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2112 | void TabContents::OnIgnoredUIEvent() { |
[email protected] | 3114509 | 2011-09-30 01:49:44 | [diff] [blame] | 2113 | // Notify observers. |
[email protected] | d8c66043 | 2011-12-22 20:51:25 | [diff] [blame] | 2114 | FOR_EACH_OBSERVER(WebContentsObserver, observers_, DidGetIgnoredUIEvent()); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2115 | } |
| 2116 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2117 | void TabContents::RendererUnresponsive(RenderViewHost* rvh, |
| 2118 | bool is_during_unload) { |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2119 | // Don't show hung renderer dialog for a swapped out RVH. |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2120 | if (rvh != GetRenderViewHost()) |
[email protected] | 992db4c | 2011-05-12 15:37:15 | [diff] [blame] | 2121 | return; |
| 2122 | |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2123 | // Ignore renderer unresponsive event if debugger is attached to the tab |
| 2124 | // since the event may be a result of the renderer sitting on a breakpoint. |
| 2125 | // See http://crbug.com/65458 |
[email protected] | 0e12d7d | 2011-12-01 16:21:44 | [diff] [blame] | 2126 | DevToolsAgentHost* agent = |
| 2127 | content::DevToolsAgentHostRegistry::GetDevToolsAgentHost(rvh); |
| 2128 | if (agent && |
| 2129 | DevToolsManagerImpl::GetInstance()->GetDevToolsClientHostFor(agent)) |
[email protected] | e5fc163 | 2011-08-08 07:51:53 | [diff] [blame] | 2130 | return; |
| 2131 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2132 | if (is_during_unload) { |
| 2133 | // Hang occurred while firing the beforeunload/unload handler. |
| 2134 | // Pretend the handler fired so tab closing continues as if it had. |
[email protected] | 829e761 | 2009-04-25 01:15:11 | [diff] [blame] | 2135 | rvh->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2136 | |
| 2137 | if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2138 | return; |
| 2139 | |
| 2140 | // If the tab hangs in the beforeunload/unload handler there's really |
| 2141 | // nothing we can do to recover. Pretend the unload listeners have |
| 2142 | // all fired and close the tab. If the hang is in the beforeunload handler |
| 2143 | // then the user will not have the option of cancelling the close. |
| 2144 | Close(rvh); |
| 2145 | return; |
| 2146 | } |
| 2147 | |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2148 | if (!GetRenderViewHost() || !GetRenderViewHost()->IsRenderViewLive()) |
[email protected] | 5545290 | 2011-06-01 21:57:47 | [diff] [blame] | 2149 | return; |
| 2150 | |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2151 | if (delegate_) |
| 2152 | delegate_->RendererUnresponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2153 | } |
| 2154 | |
| 2155 | void TabContents::RendererResponsive(RenderViewHost* render_view_host) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2156 | if (delegate_) |
| 2157 | delegate_->RendererResponsive(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2158 | } |
| 2159 | |
| 2160 | void TabContents::LoadStateChanged(const GURL& url, |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 2161 | const net::LoadStateWithParam& load_state, |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2162 | uint64 upload_position, |
| 2163 | uint64 upload_size) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2164 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2165 | upload_position_ = upload_position; |
| 2166 | upload_size_ = upload_size; |
[email protected] | 04866c4 | 2011-05-03 20:03:50 | [diff] [blame] | 2167 | load_state_host_ = net::IDNToUnicode(url.host(), |
[email protected] | 597a867b | 2011-11-18 18:31:20 | [diff] [blame] | 2168 | content::GetContentClient()->browser()->GetAcceptLangs( |
[email protected] | 627e051 | 2011-12-21 22:55:30 | [diff] [blame] | 2169 | GetBrowserContext())); |
[email protected] | 9c235f04 | 2011-08-10 22:28:21 | [diff] [blame] | 2170 | if (load_state_.state == net::LOAD_STATE_READING_RESPONSE) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2171 | SetNotWaitingForResponse(); |
[email protected] | d908348 | 2012-01-06 00:38:46 | [diff] [blame] | 2172 | if (IsLoading()) { |
| 2173 | NotifyNavigationStateChanged( |
| 2174 | content::INVALIDATE_TYPE_LOAD | content::INVALIDATE_TYPE_TAB); |
| 2175 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2176 | } |
| 2177 | |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2178 | void TabContents::WorkerCrashed() { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2179 | if (delegate_) |
| 2180 | delegate_->WorkerCrashed(this); |
[email protected] | 7d47247 | 2011-01-22 01:30:25 | [diff] [blame] | 2181 | } |
| 2182 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2183 | void TabContents::BeforeUnloadFiredFromRenderManager( |
| 2184 | bool proceed, |
| 2185 | bool* proceed_to_fire_unload) { |
[email protected] | 6934a70 | 2011-12-20 00:04:51 | [diff] [blame] | 2186 | if (delegate_) |
| 2187 | delegate_->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2188 | } |
| 2189 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2190 | void TabContents::DidStartLoadingFromRenderManager( |
| 2191 | RenderViewHost* render_view_host) { |
| 2192 | DidStartLoading(); |
| 2193 | } |
| 2194 | |
| 2195 | void TabContents::RenderViewGoneFromRenderManager( |
| 2196 | RenderViewHost* render_view_host) { |
[email protected] | 443b80e | 2010-12-14 00:42:23 | [diff] [blame] | 2197 | DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING); |
| 2198 | RenderViewGone(render_view_host, crashed_status_, crashed_error_code_); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2199 | } |
| 2200 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2201 | void TabContents::UpdateRenderViewSizeForRenderManager() { |
[email protected] | 8643e6d | 2012-01-18 20:26:10 | [diff] [blame] | 2202 | // TODO(brettw) this is a hack. See WebContentsView::SizeContents. |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 2203 | gfx::Size size = view_->GetContainerSize(); |
| 2204 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 2205 | // here during container initialization and normal window size will be set |
| 2206 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 2207 | // normal size later so just ignore it. |
| 2208 | if (!size.IsEmpty()) |
| 2209 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2210 | } |
| 2211 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2212 | void TabContents::NotifySwappedFromRenderManager() { |
| 2213 | NotifySwapped(); |
| 2214 | } |
| 2215 | |
[email protected] | d202a7c | 2012-01-04 07:53:47 | [diff] [blame] | 2216 | NavigationControllerImpl& TabContents::GetControllerForRenderManager() { |
[email protected] | cdcb1dee | 2012-01-04 00:46:20 | [diff] [blame] | 2217 | return GetControllerImpl(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2218 | } |
| 2219 | |
[email protected] | d235345 | 2012-01-19 19:53:56 | [diff] [blame] | 2220 | WebUIImpl* TabContents::CreateWebUIForRenderManager(const GURL& url) { |
| 2221 | return static_cast<WebUIImpl*>(CreateWebUI(url)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2222 | } |
| 2223 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2224 | NavigationEntry* |
| 2225 | TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2226 | return controller_.GetLastCommittedEntry(); |
| 2227 | } |
| 2228 | |
| 2229 | bool TabContents::CreateRenderViewForRenderManager( |
| 2230 | RenderViewHost* render_view_host) { |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2231 | // Can be NULL during tests. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2232 | RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 2233 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2234 | // 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] | 2235 | if (rwh_view) |
| 2236 | rwh_view->SetSize(view_->GetContainerSize()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2237 | |
[email protected] | 74ce1ad | 2011-12-16 21:51:46 | [diff] [blame] | 2238 | // Make sure we use the correct starting page_id in the new RenderView. |
| 2239 | UpdateMaxPageIDIfNecessary(render_view_host); |
| 2240 | int32 max_page_id = |
| 2241 | GetMaxPageIDForSiteInstance(render_view_host->site_instance()); |
| 2242 | |
| 2243 | if (!render_view_host->CreateRenderView(string16(), max_page_id)) |
[email protected] | a412772 | 2011-04-27 23:13:52 | [diff] [blame] | 2244 | return false; |
| 2245 | |
[email protected] | e60c023 | 2011-11-11 19:56:35 | [diff] [blame] | 2246 | #if defined(OS_LINUX) || defined(OS_OPENBSD) |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2247 | // Force a ViewMsg_Resize to be sent, needed to make plugins show up on |
| 2248 | // linux. See crbug.com/83941. |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2249 | if (rwh_view) { |
| 2250 | if (RenderWidgetHost* render_widget_host = rwh_view->GetRenderWidgetHost()) |
| 2251 | render_widget_host->WasResized(); |
| 2252 | } |
[email protected] | f8233cc | 2011-05-31 20:24:50 | [diff] [blame] | 2253 | #endif |
| 2254 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2255 | return true; |
| 2256 | } |
| 2257 | |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2258 | void TabContents::OnDialogClosed(IPC::Message* reply_msg, |
| 2259 | bool success, |
| 2260 | const string16& user_input) { |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2261 | if (is_showing_before_unload_dialog_ && !success) { |
| 2262 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 2263 | // spinning, since we forced it to start spinning in Navigate. |
| 2264 | DidStopLoading(); |
| 2265 | |
| 2266 | tab_close_start_time_ = base::TimeTicks(); |
| 2267 | } |
| 2268 | is_showing_before_unload_dialog_ = false; |
[email protected] | 151a63d | 2011-12-20 22:32:52 | [diff] [blame] | 2269 | GetRenderViewHost()->JavaScriptDialogClosed(reply_msg, success, user_input); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2270 | } |
| 2271 | |
[email protected] | 0b08add | 2011-11-29 03:27:06 | [diff] [blame] | 2272 | gfx::NativeWindow TabContents::GetDialogRootWindow() const { |
[email protected] | 3ab9cb8 | 2011-06-03 18:02:07 | [diff] [blame] | 2273 | return view_->GetTopLevelNativeWindow(); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2274 | } |
| 2275 | |
[email protected] | a1e97f0 | 2011-06-30 14:04:34 | [diff] [blame] | 2276 | void TabContents::OnDialogShown() { |
| 2277 | Activate(); |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2278 | } |
| 2279 | |
[email protected] | be1f56ab | 2011-12-22 06:55:31 | [diff] [blame] | 2280 | void TabContents::SetEncoding(const std::string& encoding) { |
[email protected] | 763ec4ca | 2011-04-29 15:48:12 | [diff] [blame] | 2281 | encoding_ = content::GetContentClient()->browser()-> |
| 2282 | GetCanonicalEncodingNameByAliasName(encoding); |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 2283 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 2284 | |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 2285 | void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) { |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2286 | RenderWidgetHostView* rwh_view = GetView()->CreateViewForWidget(rvh); |
[email protected] | 245f7d5 | 2011-11-28 15:36:44 | [diff] [blame] | 2287 | // Can be NULL during tests. |
| 2288 | if (rwh_view) |
[email protected] | d487beefe | 2011-12-21 05:41:21 | [diff] [blame] | 2289 | rwh_view->SetSize(GetView()->GetContainerSize()); |
[email protected] | 33f7497 | 2010-12-08 16:40:36 | [diff] [blame] | 2290 | } |