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