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