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