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