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