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