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