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