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