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