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