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