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