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