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