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