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