[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1 | // Copyright (c) 2010 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] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 5 | #include "chrome/browser/tab_contents/tab_contents.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 06821f42d | 2010-05-03 22:34:35 | [diff] [blame] | 7 | #if defined(OS_CHROMEOS) |
| 8 | // For GdkScreen |
| 9 | #include <gdk/gdk.h> |
| 10 | #endif // defined(OS_CHROMEOS) |
| 11 | |
[email protected] | a92b864 | 2009-05-05 23:38:56 | [diff] [blame] | 12 | #include "app/l10n_util.h" |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 13 | #include "app/resource_bundle.h" |
[email protected] | 61451981 | 2010-03-19 08:20:56 | [diff] [blame] | 14 | #include "app/text_elider.h" |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 15 | #include "base/auto_reset.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 16 | #include "base/file_version_info.h" |
[email protected] | 7cf1b6ce | 2010-03-20 06:37:01 | [diff] [blame] | 17 | #include "base/i18n/rtl.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 18 | #include "base/process_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 19 | #include "base/string16.h" |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 20 | #include "base/string_util.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 21 | #include "base/time.h" |
[email protected] | 6db0def9 | 2010-03-02 19:55:45 | [diff] [blame] | 22 | #include "chrome/browser/autocomplete_history_manager.h" |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 23 | #include "chrome/browser/autofill/autofill_manager.h" |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 24 | #include "chrome/browser/blocked_popup_container.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 25 | #include "chrome/browser/bookmarks/bookmark_model.h" |
[email protected] | 28191891 | 2010-05-27 22:05:13 | [diff] [blame] | 26 | #include "chrome/browser/browser.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 27 | #include "chrome/browser/browser_process.h" |
[email protected] | cf68b09 | 2010-01-15 20:05:55 | [diff] [blame] | 28 | #include "chrome/browser/browser_shutdown.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 29 | #include "chrome/browser/cert_store.h" |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 30 | #include "chrome/browser/character_encoding.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 31 | #include "chrome/browser/debugger/devtools_manager.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 32 | #include "chrome/browser/dom_operation_notification_details.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 33 | #include "chrome/browser/dom_ui/dom_ui.h" |
| 34 | #include "chrome/browser/dom_ui/dom_ui_factory.h" |
[email protected] | bcef0dc0 | 2009-02-28 00:35:02 | [diff] [blame] | 35 | #include "chrome/browser/download/download_item_model.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 36 | #include "chrome/browser/download/download_manager.h" |
[email protected] | 4129132 | 2010-07-15 17:09:01 | [diff] [blame] | 37 | #include "chrome/browser/download/download_request_limiter.h" |
[email protected] | e7eaedde | 2009-09-25 20:09:49 | [diff] [blame] | 38 | #include "chrome/browser/external_protocol_handler.h" |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 39 | #include "chrome/browser/extensions/extensions_service.h" |
[email protected] | 523623c | 2010-05-19 16:03:42 | [diff] [blame] | 40 | #include "chrome/browser/history/top_sites.h" |
[email protected] | 0189bc72 | 2009-08-28 21:56:48 | [diff] [blame] | 41 | #include "chrome/browser/favicon_service.h" |
[email protected] | e5d2f713 | 2010-04-09 18:13:53 | [diff] [blame] | 42 | #include "chrome/browser/find_bar_state.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 43 | #include "chrome/browser/google_util.h" |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 44 | #include "chrome/browser/host_content_settings_map.h" |
[email protected] | 8897c38 | 2009-05-06 17:53:26 | [diff] [blame] | 45 | #include "chrome/browser/hung_renderer_dialog.h" |
[email protected] | 12f74a9 | 2010-02-05 22:32:14 | [diff] [blame] | 46 | #include "chrome/browser/message_box_handler.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 47 | #include "chrome/browser/load_from_memory_cache_details.h" |
| 48 | #include "chrome/browser/load_notification_details.h" |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 49 | #include "chrome/browser/metrics/metric_event_duration_details.h" |
[email protected] | ea0e8089 | 2009-08-22 00:36:05 | [diff] [blame] | 50 | #include "chrome/browser/modal_html_dialog_delegate.h" |
[email protected] | c886548 | 2009-07-23 20:40:10 | [diff] [blame] | 51 | #include "chrome/browser/omnibox_search_hint.h" |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 52 | #include "chrome/browser/password_manager/password_manager.h" |
[email protected] | 14a000d | 2010-04-29 21:44:24 | [diff] [blame] | 53 | #include "chrome/browser/platform_util.h" |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 54 | #include "chrome/browser/plugin_installer.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 55 | #include "chrome/browser/pref_service.h" |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 56 | #include "chrome/browser/printing/print_view_manager.h" |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 57 | #include "chrome/browser/profile.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 58 | #include "chrome/browser/renderer_host/render_process_host.h" |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 59 | #include "chrome/browser/renderer_host/render_view_host.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 60 | #include "chrome/browser/renderer_host/render_widget_host_view.h" |
[email protected] | fd69498 | 2009-07-03 17:32:37 | [diff] [blame] | 61 | #include "chrome/browser/renderer_host/resource_request_details.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 62 | #include "chrome/browser/renderer_host/site_instance.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 63 | #include "chrome/browser/renderer_host/web_cache_manager.h" |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 64 | #include "chrome/browser/renderer_preferences_util.h" |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 65 | #include "chrome/browser/search_engines/template_url_fetcher.h" |
| 66 | #include "chrome/browser/search_engines/template_url_model.h" |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 67 | #include "chrome/browser/sessions/session_types.h" |
[email protected] | bd1ad68 | 2009-05-15 22:19:17 | [diff] [blame] | 68 | #include "chrome/browser/tab_contents/infobar_delegate.h" |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 69 | #include "chrome/browser/tab_contents/interstitial_page.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 70 | #include "chrome/browser/tab_contents/navigation_entry.h" |
[email protected] | de34a96 | 2009-06-26 23:22:43 | [diff] [blame] | 71 | #include "chrome/browser/tab_contents/provisional_load_details.h" |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 72 | #include "chrome/browser/tab_contents/tab_contents_delegate.h" |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 73 | #include "chrome/browser/tab_contents/tab_contents_view.h" |
[email protected] | 58dca55 | 2009-06-17 00:35:02 | [diff] [blame] | 74 | #include "chrome/browser/tab_contents/thumbnail_generator.h" |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 75 | #include "chrome/browser/translate/page_translated_details.h" |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 76 | #include "chrome/common/bindings_policy.h" |
[email protected] | 35f7d21 | 2009-04-29 21:19:27 | [diff] [blame] | 77 | #include "chrome/common/chrome_switches.h" |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 78 | #include "chrome/common/extensions/extension.h" |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 79 | #include "chrome/common/extensions/extension_action.h" |
[email protected] | 942690b13 | 2010-05-11 06:42:14 | [diff] [blame] | 80 | #include "chrome/common/extensions/extension_resource.h" |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 81 | #include "chrome/common/extensions/url_pattern.h" |
| 82 | #include "chrome/common/navigation_types.h" |
| 83 | #include "chrome/common/net/url_request_context_getter.h" |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 84 | #include "chrome/common/notification_service.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 85 | #include "chrome/common/pref_names.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 86 | #include "chrome/common/render_messages.h" |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 87 | #include "chrome/common/renderer_preferences.h" |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 88 | #include "chrome/common/url_constants.h" |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 89 | #include "grit/chromium_strings.h" |
[email protected] | 8897c38 | 2009-05-06 17:53:26 | [diff] [blame] | 90 | #include "grit/generated_resources.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 91 | #include "grit/locale_settings.h" |
[email protected] | fd62678 | 2010-01-22 05:26:06 | [diff] [blame] | 92 | #include "grit/platform_locale_settings.h" |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 93 | #include "grit/theme_resources.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 94 | #include "net/base/mime_util.h" |
| 95 | #include "net/base/net_errors.h" |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 96 | #include "net/base/net_util.h" |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 97 | #include "net/base/registry_controlled_domain.h" |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 98 | #include "webkit/glue/webpreferences.h" |
[email protected] | 3e45ba9 | 2009-02-20 21:09:00 | [diff] [blame] | 99 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 100 | // Cross-Site Navigations |
| 101 | // |
| 102 | // If a TabContents is told to navigate to a different web site (as determined |
| 103 | // by SiteInstance), it will replace its current RenderViewHost with a new |
| 104 | // RenderViewHost dedicated to the new SiteInstance. This works as follows: |
| 105 | // |
| 106 | // - Navigate determines whether the destination is cross-site, and if so, |
| 107 | // it creates a pending_render_view_host_ and moves into the PENDING |
| 108 | // RendererState. |
| 109 | // - The pending RVH is "suspended," so that no navigation messages are sent to |
| 110 | // its renderer until the onbeforeunload JavaScript handler has a chance to |
| 111 | // run in the current RVH. |
| 112 | // - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton) |
| 113 | // that it has a pending cross-site request. ResourceDispatcherHost will |
| 114 | // check for this when the response arrives. |
| 115 | // - The current RVH runs its onbeforeunload handler. If it returns false, we |
| 116 | // cancel all the pending logic and go back to NORMAL. Otherwise we allow |
| 117 | // the pending RVH to send the navigation request to its renderer. |
| 118 | // - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It |
| 119 | // checks CrossSiteRequestManager to see that the RVH responsible has a |
| 120 | // pending cross-site request, and then installs a CrossSiteEventHandler. |
| 121 | // - When RDH receives a response, the BufferedEventHandler determines whether |
| 122 | // it is a download. If so, it sends a message to the new renderer causing |
| 123 | // it to cancel the request, and the download proceeds in the download |
| 124 | // 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] | 125 | // the next DidNavigate event for this TabContents. This isn't ideal, but it |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 126 | // doesn't affect any functionality. |
| 127 | // - After RDH receives a response and determines that it is safe and not a |
| 128 | // download, it pauses the response to first run the old page's onunload |
| 129 | // handler. It does this by asynchronously calling the OnCrossSiteResponse |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 130 | // method of TabContents on the UI thread, which sends a ClosePage message |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 131 | // to the current RVH. |
| 132 | // - Once the onunload handler is finished, a ClosePage_ACK message is sent to |
| 133 | // the ResourceDispatcherHost, who unpauses the response. Data is then sent |
| 134 | // to the pending RVH. |
| 135 | // - The pending renderer sends a FrameNavigate message that invokes the |
| 136 | // DidNavigate method. This replaces the current RVH with the |
| 137 | // pending RVH and goes back to the NORMAL RendererState. |
| 138 | |
| 139 | namespace { |
| 140 | |
| 141 | // Amount of time we wait between when a key event is received and the renderer |
| 142 | // is queried for its state and pushed to the NavigationEntry. |
| 143 | const int kQueryStateDelay = 5000; |
| 144 | |
| 145 | const int kSyncWaitDelay = 40; |
| 146 | |
[email protected] | 304f879 | 2009-08-19 21:28:09 | [diff] [blame] | 147 | #if defined(OS_CHROMEOS) |
| 148 | // If a popup window is bigger than this fraction of the screen on chrome os, |
| 149 | // turn it into a tab |
| 150 | const float kMaxWidthFactor = 0.5; |
| 151 | const float kMaxHeightFactor = 0.6; |
| 152 | #endif |
| 153 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 154 | // If another javascript message box is displayed within |
| 155 | // kJavascriptMessageExpectedDelay of a previous javascript message box being |
| 156 | // dismissed, display an option to suppress future message boxes from this |
| 157 | // contents. |
| 158 | const int kJavascriptMessageExpectedDelay = 1000; |
| 159 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 160 | // The list of prefs we want to observe. |
| 161 | const wchar_t* kPrefsToObserve[] = { |
| 162 | prefs::kAlternateErrorPagesEnabled, |
| 163 | prefs::kWebKitJavaEnabled, |
| 164 | prefs::kWebKitJavascriptEnabled, |
| 165 | prefs::kWebKitLoadsImagesAutomatically, |
| 166 | prefs::kWebKitPluginsEnabled, |
| 167 | prefs::kWebKitUsesUniversalDetector, |
| 168 | prefs::kWebKitSerifFontFamily, |
| 169 | prefs::kWebKitSansSerifFontFamily, |
| 170 | prefs::kWebKitFixedFontFamily, |
| 171 | prefs::kWebKitDefaultFontSize, |
| 172 | prefs::kWebKitDefaultFixedFontSize, |
[email protected] | 1661a3c0 | 2010-05-20 16:32:36 | [diff] [blame] | 173 | prefs::kWebkitTabsToLinks, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 174 | prefs::kDefaultCharset |
| 175 | // kWebKitStandardFontIsSerif needs to be added |
| 176 | // if we let users pick which font to use, serif or sans-serif when |
| 177 | // no font is specified or a CSS generic family (serif or sans-serif) |
| 178 | // is not specified. |
| 179 | }; |
| 180 | |
| 181 | const int kPrefsToObserveLength = arraysize(kPrefsToObserve); |
| 182 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 183 | // Returns true if the entry's transition type is FORM_SUBMIT. |
| 184 | bool IsFormSubmit(const NavigationEntry* entry) { |
| 185 | return (PageTransition::StripQualifier(entry->transition_type()) == |
| 186 | PageTransition::FORM_SUBMIT); |
| 187 | } |
| 188 | |
| 189 | #if defined(OS_WIN) |
| 190 | |
| 191 | BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) { |
| 192 | // Note: erase is required to properly paint some widgets borders. This can |
| 193 | // be seen with textfields. |
| 194 | InvalidateRect(hwnd, NULL, TRUE); |
| 195 | return TRUE; |
| 196 | } |
| 197 | #endif |
| 198 | |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 199 | ViewMsg_Navigate_Params::NavigationType GetNavigationType( |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 200 | Profile* profile, const NavigationEntry& entry, |
| 201 | NavigationController::ReloadType reload_type) { |
| 202 | switch (reload_type) { |
| 203 | case NavigationController::RELOAD: |
| 204 | return ViewMsg_Navigate_Params::RELOAD; |
| 205 | case NavigationController::RELOAD_IGNORING_CACHE: |
| 206 | return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE; |
| 207 | case NavigationController::NO_RELOAD: |
| 208 | break; // Fall through to rest of function. |
| 209 | } |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 210 | |
| 211 | if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION && |
| 212 | profile->DidLastSessionExitCleanly()) |
| 213 | return ViewMsg_Navigate_Params::RESTORE; |
| 214 | |
| 215 | return ViewMsg_Navigate_Params::NORMAL; |
| 216 | } |
| 217 | |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 218 | void MakeNavigateParams(const NavigationController& controller, |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 219 | NavigationController::ReloadType reload_type, |
| 220 | ViewMsg_Navigate_Params* params) { |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 221 | const NavigationEntry& entry = *controller.pending_entry(); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 222 | params->page_id = entry.page_id(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 223 | params->pending_history_list_offset = controller.pending_entry_index(); |
| 224 | params->current_history_list_offset = controller.last_committed_entry_index(); |
| 225 | params->current_history_list_length = controller.entry_count(); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 226 | params->url = entry.url(); |
| 227 | params->referrer = entry.referrer(); |
| 228 | params->transition = entry.transition_type(); |
| 229 | params->state = entry.content_state(); |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 230 | params->navigation_type = |
| 231 | GetNavigationType(controller.profile(), entry, reload_type); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 232 | params->request_time = base::Time::Now(); |
| 233 | } |
| 234 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 235 | } // namespace |
| 236 | |
| 237 | // ----------------------------------------------------------------------------- |
| 238 | |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 239 | // static |
| 240 | int TabContents::find_request_id_counter_ = -1; |
| 241 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 242 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 243 | TabContents::TabContents(Profile* profile, |
| 244 | SiteInstance* site_instance, |
| 245 | int routing_id, |
[email protected] | 34ac7050 | 2009-09-25 17:07:23 | [diff] [blame] | 246 | const TabContents* base_tab_contents) |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 247 | : delegate_(NULL), |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 248 | ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)), |
| 249 | ALLOW_THIS_IN_INITIALIZER_LIST(view_( |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 250 | TabContentsView::Create(this))), |
| 251 | ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 252 | property_bag_(), |
| 253 | registrar_(), |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 254 | ALLOW_THIS_IN_INITIALIZER_LIST(printing_( |
| 255 | new printing::PrintViewManager(*this))), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 256 | save_package_(), |
[email protected] | 6db0def9 | 2010-03-02 19:55:45 | [diff] [blame] | 257 | autocomplete_history_manager_(), |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 258 | autofill_manager_(), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 259 | password_manager_(), |
| 260 | plugin_installer_(), |
[email protected] | 6f821dd | 2010-02-23 00:54:06 | [diff] [blame] | 261 | bookmark_drag_(NULL), |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 262 | ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 263 | select_file_dialog_(), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 264 | is_loading_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 265 | is_crashed_(false), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 266 | waiting_for_response_(false), |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 267 | max_page_id_(-1), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 268 | current_load_start_(), |
| 269 | load_state_(net::LOAD_STATE_IDLE), |
| 270 | load_state_host_(), |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 271 | upload_size_(0), |
| 272 | upload_position_(0), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 273 | received_page_title_(false), |
| 274 | is_starred_(false), |
| 275 | contents_mime_type_(), |
| 276 | encoding_(), |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 277 | blocked_popups_(NULL), |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 278 | dont_notify_render_view_(false), |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 279 | displayed_insecure_content_(false), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 280 | infobar_delegates_(), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 281 | find_ui_active_(false), |
| 282 | find_op_aborted_(false), |
| 283 | current_find_request_id_(find_request_id_counter_++), |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 284 | last_search_case_sensitive_(false), |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 285 | last_search_result_(), |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 286 | extension_app_(NULL), |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 287 | capturing_contents_(false), |
| 288 | is_being_destroyed_(false), |
| 289 | notify_disconnection_(false), |
| 290 | history_requests_(), |
| 291 | #if defined(OS_WIN) |
| 292 | message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)), |
| 293 | #endif |
| 294 | last_javascript_message_dismissal_(), |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 295 | suppress_javascript_messages_(false), |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 296 | is_showing_before_unload_dialog_(false), |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 297 | renderer_preferences_(), |
[email protected] | 1a242c3 | 2010-02-02 21:20:54 | [diff] [blame] | 298 | opener_dom_ui_type_(DOMUIFactory::kNoDOMUI), |
[email protected] | 777a7b6 | 2010-05-11 13:28:16 | [diff] [blame] | 299 | language_state_(&controller_), |
[email protected] | 0cce15f | 2010-05-21 16:58:39 | [diff] [blame] | 300 | closed_by_user_gesture_(false) { |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 301 | renderer_preferences_util::UpdateFromSystemSettings( |
| 302 | &renderer_preferences_, profile); |
| 303 | |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 304 | content_settings_delegate_.reset( |
| 305 | new TabSpecificContentSettings(this, profile)); |
| 306 | |
[email protected] | 1677984 | 2009-07-08 23:45:29 | [diff] [blame] | 307 | #if defined(OS_CHROMEOS) |
[email protected] | 58dca55 | 2009-06-17 00:35:02 | [diff] [blame] | 308 | // Make sure the thumbnailer is started before starting the render manager. |
| 309 | // The thumbnailer will want to listen for RVH creations, one of which will |
| 310 | // happen in RVHManager::Init. |
| 311 | ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); |
| 312 | if (generator) |
| 313 | generator->StartThumbnailing(); |
| 314 | #endif |
| 315 | |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 316 | render_manager_.Init(profile, site_instance, routing_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 317 | |
[email protected] | 34ac7050 | 2009-09-25 17:07:23 | [diff] [blame] | 318 | // We have the initial size of the view be based on the size of the passed in |
| 319 | // tab contents (normally a tab from the same window). |
| 320 | view_->CreateView(base_tab_contents ? |
| 321 | base_tab_contents->view()->GetContainerSize() : gfx::Size()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 322 | |
| 323 | // Register for notifications about all interested prefs change. |
| 324 | PrefService* prefs = profile->GetPrefs(); |
| 325 | if (prefs) { |
| 326 | for (int i = 0; i < kPrefsToObserveLength; ++i) |
| 327 | prefs->AddPrefObserver(kPrefsToObserve[i], this); |
| 328 | } |
| 329 | |
| 330 | // Register for notifications about URL starredness changing on any profile. |
| 331 | registrar_.Add(this, NotificationType::URLS_STARRED, |
| 332 | NotificationService::AllSources()); |
| 333 | registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED, |
| 334 | NotificationService::AllSources()); |
| 335 | registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, |
| 336 | NotificationService::AllSources()); |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 337 | #if defined(OS_LINUX) |
| 338 | registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED, |
| 339 | NotificationService::AllSources()); |
| 340 | #endif |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 341 | |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 342 | registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED, |
| 343 | NotificationService::AllSources()); |
| 344 | |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 345 | // Register for notifications about content setting changes. |
| 346 | registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED, |
| 347 | NotificationService::AllSources()); |
| 348 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 349 | // Listen for extension changes so we can update extension_for_current_page_. |
| 350 | registrar_.Add(this, NotificationType::EXTENSION_LOADED, |
| 351 | NotificationService::AllSources()); |
| 352 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, |
| 353 | NotificationService::AllSources()); |
| 354 | registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED, |
| 355 | NotificationService::AllSources()); |
| 356 | |
[email protected] | c886548 | 2009-07-23 20:40:10 | [diff] [blame] | 357 | // Set-up the showing of the omnibox search infobar if applicable. |
| 358 | if (OmniboxSearchHint::IsEnabled(profile)) |
| 359 | omnibox_search_hint_.reset(new OmniboxSearchHint(this)); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 360 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 361 | |
| 362 | TabContents::~TabContents() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 363 | is_being_destroyed_ = true; |
| 364 | |
[email protected] | bfe4c158 | 2009-10-02 18:11:09 | [diff] [blame] | 365 | // We don't want any notifications while we're running our destructor. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 366 | registrar_.RemoveAll(); |
| 367 | |
| 368 | // Unregister the notifications of all observed prefs change. |
| 369 | PrefService* prefs = profile()->GetPrefs(); |
| 370 | if (prefs) { |
| 371 | for (int i = 0; i < kPrefsToObserveLength; ++i) |
| 372 | prefs->RemovePrefObserver(kPrefsToObserve[i], this); |
| 373 | } |
| 374 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 375 | NotifyDisconnected(); |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 376 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 377 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 378 | // First cleanly close all child windows. |
| 379 | // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked |
| 380 | // some of these to close. CloseWindows is async, so it might get called |
| 381 | // twice before it runs. |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 382 | CloseConstrainedWindows(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 383 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 384 | // Close all blocked popups. |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 385 | if (blocked_popups_) |
| 386 | blocked_popups_->Destroy(); |
| 387 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 388 | // Notify any observer that have a reference on this tab contents. |
| 389 | NotificationService::current()->Notify( |
| 390 | NotificationType::TAB_CONTENTS_DESTROYED, |
| 391 | Source<TabContents>(this), |
| 392 | NotificationService::NoDetails()); |
| 393 | |
[email protected] | 1e5e74f | 2009-05-27 20:55:12 | [diff] [blame] | 394 | // Notify any lasting InfobarDelegates that have not yet been removed that |
| 395 | // whatever infobar they were handling in this TabContents has closed, |
| 396 | // because the TabContents is going away entirely. |
| 397 | // This must happen after the TAB_CONTENTS_DESTROYED notification as the |
| 398 | // notification may trigger infobars calls that access their delegate. (and |
| 399 | // some implementations of InfoBarDelegate do delete themselves on |
| 400 | // InfoBarClosed()). |
| 401 | for (int i = 0; i < infobar_delegate_count(); ++i) { |
| 402 | InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); |
| 403 | delegate->InfoBarClosed(); |
| 404 | } |
| 405 | infobar_delegates_.clear(); |
| 406 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 407 | // TODO(brettw) this should be moved to the view. |
| 408 | #if defined(OS_WIN) |
| 409 | // If we still have a window handle, destroy it. GetNativeView can return |
| 410 | // NULL if this contents was part of a window that closed. |
| 411 | if (GetNativeView()) |
| 412 | ::DestroyWindow(GetNativeView()); |
| 413 | #endif |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 414 | |
| 415 | // OnCloseStarted isn't called in unit tests. |
| 416 | if (!tab_close_start_time_.is_null()) { |
| 417 | UMA_HISTOGRAM_TIMES("Tab.Close", |
| 418 | base::TimeTicks::Now() - tab_close_start_time_); |
| 419 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 422 | // static |
| 423 | void TabContents::RegisterUserPrefs(PrefService* prefs) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 424 | prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); |
| 425 | |
| 426 | WebPreferences pref_defaults; |
| 427 | prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled, |
| 428 | pref_defaults.javascript_enabled); |
| 429 | prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, |
| 430 | pref_defaults.web_security_enabled); |
| 431 | prefs->RegisterBooleanPref( |
| 432 | prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true); |
| 433 | prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically, |
| 434 | pref_defaults.loads_images_automatically); |
| 435 | prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled, |
| 436 | pref_defaults.plugins_enabled); |
| 437 | prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled, |
| 438 | pref_defaults.dom_paste_enabled); |
| 439 | prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit, |
| 440 | pref_defaults.shrinks_standalone_images_to_fit); |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 441 | prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 442 | prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable, |
| 443 | pref_defaults.text_areas_are_resizable); |
| 444 | prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled, |
| 445 | pref_defaults.java_enabled); |
[email protected] | 1661a3c0 | 2010-05-20 16:32:36 | [diff] [blame] | 446 | prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks, |
| 447 | pref_defaults.tabs_to_links); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 448 | |
| 449 | prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages, |
| 450 | IDS_ACCEPT_LANGUAGES); |
| 451 | prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset, |
| 452 | IDS_DEFAULT_ENCODING); |
| 453 | prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif, |
| 454 | IDS_STANDARD_FONT_IS_SERIF); |
| 455 | prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily, |
| 456 | IDS_FIXED_FONT_FAMILY); |
| 457 | prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily, |
| 458 | IDS_SERIF_FONT_FAMILY); |
| 459 | prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily, |
| 460 | IDS_SANS_SERIF_FONT_FAMILY); |
| 461 | prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily, |
| 462 | IDS_CURSIVE_FONT_FAMILY); |
| 463 | prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily, |
| 464 | IDS_FANTASY_FONT_FAMILY); |
| 465 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize, |
| 466 | IDS_DEFAULT_FONT_SIZE); |
| 467 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize, |
| 468 | IDS_DEFAULT_FIXED_FONT_SIZE); |
| 469 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize, |
| 470 | IDS_MINIMUM_FONT_SIZE); |
| 471 | prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize, |
| 472 | IDS_MINIMUM_LOGICAL_FONT_SIZE); |
| 473 | prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector, |
| 474 | IDS_USES_UNIVERSAL_DETECTOR); |
| 475 | prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings, |
| 476 | IDS_STATIC_ENCODING_LIST); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 477 | } |
| 478 | |
[email protected] | 13367f7 | 2009-07-08 16:39:02 | [diff] [blame] | 479 | // Returns true if contains content rendered by an extension. |
| 480 | bool TabContents::HostsExtension() const { |
| 481 | return GetURL().SchemeIs(chrome::kExtensionScheme); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 482 | } |
| 483 | |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 484 | AutoFillManager* TabContents::GetAutoFillManager() { |
| 485 | if (autofill_manager_.get() == NULL) |
| 486 | autofill_manager_.reset(new AutoFillManager(this)); |
| 487 | return autofill_manager_.get(); |
| 488 | } |
| 489 | |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 490 | PasswordManager* TabContents::GetPasswordManager() { |
| 491 | if (password_manager_.get() == NULL) |
| 492 | password_manager_.reset(new PasswordManager(this)); |
| 493 | return password_manager_.get(); |
| 494 | } |
| 495 | |
| 496 | PluginInstaller* TabContents::GetPluginInstaller() { |
| 497 | if (plugin_installer_.get() == NULL) |
| 498 | plugin_installer_.reset(new PluginInstaller(this)); |
| 499 | return plugin_installer_.get(); |
| 500 | } |
| 501 | |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 502 | RenderProcessHost* TabContents::GetRenderProcessHost() const { |
| 503 | return render_manager_.current_host()->process(); |
| 504 | } |
| 505 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 506 | void TabContents::SetExtensionApp(Extension* extension) { |
[email protected] | 867a73e1 | 2010-03-19 20:45:46 | [diff] [blame] | 507 | DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 508 | extension_app_ = extension; |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 509 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 510 | UpdateExtensionAppIcon(extension_app_); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 511 | |
[email protected] | fca656c | 2010-02-10 20:30:10 | [diff] [blame] | 512 | NotificationService::current()->Notify( |
| 513 | NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 514 | Source<TabContents>(this), |
| 515 | NotificationService::NoDetails()); |
[email protected] | 3b35564 | 2010-02-05 16:01:49 | [diff] [blame] | 516 | } |
| 517 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 518 | void TabContents::SetExtensionAppById(const std::string& extension_app_id) { |
| 519 | if (extension_app_id.empty()) |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 520 | return; |
| 521 | |
| 522 | ExtensionsService* extension_service = profile()->GetExtensionsService(); |
| 523 | if (extension_service && extension_service->is_ready()) { |
| 524 | Extension* extension = |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 525 | extension_service->GetExtensionById(extension_app_id, false); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 526 | if (extension) |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 527 | SetExtensionApp(extension); |
[email protected] | 911f815 | 2010-03-18 16:46:40 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 531 | SkBitmap* TabContents::GetExtensionAppIcon() { |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 532 | // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because |
| 533 | // for those windows, we already have a big icon in the top-left outside any |
| 534 | // tab. Having big tab icons too looks kinda redonk. |
[email protected] | 06821f42d | 2010-05-03 22:34:35 | [diff] [blame] | 535 | Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL; |
| 536 | if (browser && browser->type() == Browser::TYPE_EXTENSION_APP) |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 537 | return NULL; |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 538 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 539 | if (extension_app_icon_.empty()) |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 540 | return NULL; |
| 541 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 542 | return &extension_app_icon_; |
[email protected] | 8eb043b | 2010-04-30 07:19:51 | [diff] [blame] | 543 | } |
| 544 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 545 | const GURL& TabContents::GetURL() const { |
| 546 | // We may not have a navigation entry yet |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 547 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 548 | return entry ? entry->virtual_url() : GURL::EmptyGURL(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 549 | } |
| 550 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 551 | const string16& TabContents::GetTitle() const { |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 552 | // Transient entries take precedence. They are used for interstitial pages |
| 553 | // that are shown on top of existing pages. |
| 554 | NavigationEntry* entry = controller_.GetTransientEntry(); |
| 555 | if (entry) |
| 556 | return entry->GetTitleForDisplay(&controller_); |
| 557 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 558 | DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ? |
| 559 | render_manager_.pending_dom_ui() : render_manager_.dom_ui(); |
| 560 | if (our_dom_ui) { |
| 561 | // Don't override the title in view source mode. |
[email protected] | 4c6092c5b | 2009-06-06 00:23:55 | [diff] [blame] | 562 | entry = controller_.GetActiveEntry(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 563 | if (!(entry && entry->IsViewSourceMode())) { |
| 564 | // Give the DOM UI the chance to override our title. |
| 565 | const string16& title = our_dom_ui->overridden_title(); |
| 566 | if (!title.empty()) |
| 567 | return title; |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | // We use the title for the last committed entry rather than a pending |
| 572 | // navigation entry. For example, when the user types in a URL, we want to |
| 573 | // keep the old page's title until the new load has committed and we get a new |
| 574 | // title. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 575 | entry = controller_.GetLastCommittedEntry(); |
| 576 | if (entry) |
| 577 | return entry->GetTitleForDisplay(&controller_); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 578 | return EmptyString16(); |
| 579 | } |
| 580 | |
[email protected] | bbbc1ef | 2010-02-12 18:03:41 | [diff] [blame] | 581 | // static |
| 582 | string16 TabContents::GetDefaultTitle() { |
| 583 | return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); |
| 584 | } |
| 585 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 586 | int32 TabContents::GetMaxPageID() { |
| 587 | if (GetSiteInstance()) |
| 588 | return GetSiteInstance()->max_page_id(); |
| 589 | else |
| 590 | return max_page_id_; |
| 591 | } |
| 592 | |
| 593 | void TabContents::UpdateMaxPageID(int32 page_id) { |
| 594 | // Ensure both the SiteInstance and RenderProcessHost update their max page |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 595 | // IDs in sync. Only TabContents will also have site instances, except during |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 596 | // testing. |
| 597 | if (GetSiteInstance()) |
| 598 | GetSiteInstance()->UpdateMaxPageID(page_id); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 599 | GetRenderProcessHost()->UpdateMaxPageID(page_id); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 602 | SiteInstance* TabContents::GetSiteInstance() const { |
| 603 | return render_manager_.current_host()->site_instance(); |
| 604 | } |
| 605 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 606 | bool TabContents::ShouldDisplayURL() { |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 607 | // Don't hide the url in view source mode and with interstitials. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 608 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 609 | if (entry && (entry->IsViewSourceMode() || |
| 610 | entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 611 | return true; |
[email protected] | 8ab24cc | 2009-11-13 20:56:15 | [diff] [blame] | 612 | } |
[email protected] | 83e3895b | 2009-06-11 00:07:16 | [diff] [blame] | 613 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 614 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 615 | if (dom_ui) |
| 616 | return !dom_ui->should_hide_url(); |
| 617 | return true; |
| 618 | } |
| 619 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 620 | SkBitmap TabContents::GetFavIcon() const { |
| 621 | // Like GetTitle(), we also want to use the favicon for the last committed |
| 622 | // entry rather than a pending navigation entry. |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 623 | NavigationEntry* entry = controller_.GetTransientEntry(); |
[email protected] | cbab76d | 2008-10-13 22:42:47 | [diff] [blame] | 624 | if (entry) |
| 625 | return entry->favicon().bitmap(); |
| 626 | |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 627 | entry = controller_.GetLastCommittedEntry(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 628 | if (entry) |
| 629 | return entry->favicon().bitmap(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 630 | return SkBitmap(); |
| 631 | } |
| 632 | |
[email protected] | 0b303cc | 2009-09-28 22:35:15 | [diff] [blame] | 633 | bool TabContents::FavIconIsValid() const { |
| 634 | NavigationEntry* entry = controller_.GetTransientEntry(); |
| 635 | if (entry) |
| 636 | return entry->favicon().is_valid(); |
| 637 | |
| 638 | entry = controller_.GetLastCommittedEntry(); |
| 639 | if (entry) |
| 640 | return entry->favicon().is_valid(); |
| 641 | |
| 642 | return false; |
| 643 | } |
| 644 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 645 | bool TabContents::ShouldDisplayFavIcon() { |
| 646 | // Always display a throbber during pending loads. |
| 647 | if (controller_.GetLastCommittedEntry() && controller_.pending_entry()) |
| 648 | return true; |
| 649 | |
| 650 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 651 | if (dom_ui) |
| 652 | return !dom_ui->hide_favicon(); |
| 653 | return true; |
| 654 | } |
| 655 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 656 | std::wstring TabContents::GetStatusText() const { |
| 657 | if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) |
| 658 | return std::wstring(); |
| 659 | |
| 660 | switch (load_state_) { |
| 661 | case net::LOAD_STATE_WAITING_FOR_CACHE: |
| 662 | return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE); |
[email protected] | 8a1f331 | 2010-05-25 19:25:04 | [diff] [blame] | 663 | case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL: |
| 664 | return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 665 | case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: |
| 666 | return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); |
| 667 | case net::LOAD_STATE_RESOLVING_HOST: |
| 668 | return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST); |
| 669 | case net::LOAD_STATE_CONNECTING: |
| 670 | return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING); |
[email protected] | 375e311 | 2010-05-27 20:32:06 | [diff] [blame] | 671 | case net::LOAD_STATE_SSL_HANDSHAKE: |
| 672 | return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 673 | case net::LOAD_STATE_SENDING_REQUEST: |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 674 | if (upload_size_) |
| 675 | return l10n_util::GetStringF( |
| 676 | IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS, |
| 677 | static_cast<int>((100 * upload_position_) / upload_size_)); |
| 678 | else |
| 679 | return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 680 | case net::LOAD_STATE_WAITING_FOR_RESPONSE: |
| 681 | return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE, |
| 682 | load_state_host_); |
| 683 | // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE |
| 684 | case net::LOAD_STATE_IDLE: |
| 685 | case net::LOAD_STATE_READING_RESPONSE: |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | return std::wstring(); |
| 690 | } |
| 691 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 692 | void TabContents::SetIsCrashed(bool state) { |
| 693 | if (state == is_crashed_) |
| 694 | return; |
| 695 | |
| 696 | is_crashed_ = state; |
[email protected] | c9cd222 | 2009-05-06 05:16:50 | [diff] [blame] | 697 | NotifyNavigationStateChanged(INVALIDATE_TAB); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 698 | } |
| 699 | |
[email protected] | 744ef17 | 2009-10-16 21:53:46 | [diff] [blame] | 700 | void TabContents::PageActionStateChanged() { |
| 701 | NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS); |
[email protected] | d7eaf57 | 2009-07-01 21:57:00 | [diff] [blame] | 702 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 703 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 704 | void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) { |
| 705 | if (delegate_) |
| 706 | delegate_->NavigationStateChanged(this, changed_flags); |
| 707 | } |
| 708 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 709 | void TabContents::DidBecomeSelected() { |
| 710 | controller_.SetActive(true); |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 711 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 712 | if (rwhv) { |
| 713 | rwhv->DidBecomeSelected(); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 714 | #if defined(OS_MACOSX) |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 715 | rwhv->SetActive(true); |
[email protected] | 789e915 | 2009-08-04 21:59:43 | [diff] [blame] | 716 | #endif |
| 717 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 718 | |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 719 | WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 720 | } |
| 721 | |
| 722 | void TabContents::WasHidden() { |
| 723 | if (!capturing_contents()) { |
| 724 | // |render_view_host()| can be NULL if the user middle clicks a link to open |
| 725 | // a tab in then background, then closes the tab before selecting it. This |
| 726 | // is because closing the tab calls TabContents::Destroy(), which removes |
| 727 | // the |render_view_host()|; then when we actually destroy the window, |
| 728 | // OnWindowPosChanged() notices and calls HideContents() (which calls us). |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 729 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 730 | if (rwhv) |
| 731 | rwhv->WasHidden(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 732 | } |
| 733 | |
| 734 | NotificationService::current()->Notify( |
| 735 | NotificationType::TAB_CONTENTS_HIDDEN, |
| 736 | Source<TabContents>(this), |
| 737 | NotificationService::NoDetails()); |
| 738 | } |
| 739 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 740 | void TabContents::Activate() { |
| 741 | if (delegate_) |
| 742 | delegate_->ActivateContents(this); |
| 743 | } |
| 744 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 745 | void TabContents::ShowContents() { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 746 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 747 | if (rwhv) |
| 748 | rwhv->DidBecomeSelected(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | void TabContents::HideContents() { |
| 752 | // TODO(pkasting): http://b/1239839 Right now we purposefully don't call |
| 753 | // our superclass HideContents(), because some callers want to be very picky |
| 754 | // about the order in which these get called. In addition to making the code |
| 755 | // here practically impossible to understand, this also means we end up |
| 756 | // calling TabContents::WasHidden() twice if callers call both versions of |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 757 | // HideContents() on a TabContents. |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 758 | WasHidden(); |
| 759 | } |
| 760 | |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 761 | void TabContents::OpenURL(const GURL& url, const GURL& referrer, |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 762 | WindowOpenDisposition disposition, |
| 763 | PageTransition::Type transition) { |
| 764 | if (delegate_) |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 765 | delegate_->OpenURLFromTab(this, url, referrer, disposition, transition); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 766 | } |
| 767 | |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 768 | bool TabContents::NavigateToPendingEntry( |
| 769 | NavigationController::ReloadType reload_type) { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 770 | const NavigationEntry& entry = *controller_.pending_entry(); |
| 771 | |
| 772 | RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry); |
| 773 | if (!dest_render_view_host) |
| 774 | return false; // Unable to create the desired render view host. |
| 775 | |
[email protected] | 770dd8b | 2010-05-24 18:11:39 | [diff] [blame] | 776 | if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) { |
| 777 | dest_render_view_host->EnablePreferredSizeChangedMode( |
| 778 | kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow); |
| 779 | } |
[email protected] | 9fb325e | 2010-05-06 18:23:24 | [diff] [blame] | 780 | |
[email protected] | 0352e547 | 2010-04-29 00:11:40 | [diff] [blame] | 781 | // For security, we should never send non-DOM-UI URLs (other than about:blank) |
| 782 | // to a DOM UI renderer. Double check that here. |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 783 | int enabled_bindings = dest_render_view_host->enabled_bindings(); |
[email protected] | 0352e547 | 2010-04-29 00:11:40 | [diff] [blame] | 784 | bool is_allowed_in_dom_ui_renderer = |
| 785 | DOMUIFactory::UseDOMUIForURL(entry.url()) || |
| 786 | entry.url() == GURL(chrome::kAboutBlankURL); |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 787 | CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) || |
[email protected] | 0352e547 | 2010-04-29 00:11:40 | [diff] [blame] | 788 | is_allowed_in_dom_ui_renderer); |
[email protected] | 54ec647 | 2010-04-09 19:39:58 | [diff] [blame] | 789 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 790 | // Tell DevTools agent that it is attached prior to the navigation. |
[email protected] | d9f9b79 | 2009-06-24 13:17:12 | [diff] [blame] | 791 | DevToolsManager* devtools_manager = DevToolsManager::GetInstance(); |
[email protected] | 7e8e6b6 | 2009-05-08 11:28:32 | [diff] [blame] | 792 | if (devtools_manager) { // NULL in unit tests. |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 793 | devtools_manager->OnNavigatingToPendingEntry(render_view_host(), |
| 794 | dest_render_view_host, |
| 795 | entry.url()); |
[email protected] | 7e8e6b6 | 2009-05-08 11:28:32 | [diff] [blame] | 796 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 797 | |
| 798 | // Used for page load time metrics. |
| 799 | current_load_start_ = base::TimeTicks::Now(); |
| 800 | |
| 801 | // Navigate in the desired RenderViewHost. |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 802 | ViewMsg_Navigate_Params navigate_params; |
[email protected] | 3cc72b1 | 2010-03-18 23:03:00 | [diff] [blame] | 803 | MakeNavigateParams(controller_, reload_type, &navigate_params); |
[email protected] | 056de2d | 2009-06-26 16:41:34 | [diff] [blame] | 804 | dest_render_view_host->Navigate(navigate_params); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 805 | |
| 806 | if (entry.page_id() == -1) { |
| 807 | // HACK!! This code suppresses javascript: URLs from being added to |
| 808 | // session history, which is what we want to do for javascript: URLs that |
| 809 | // do not generate content. What we really need is a message from the |
| 810 | // renderer telling us that a new page was not created. The same message |
| 811 | // could be used for mailto: URLs and the like. |
| 812 | if (entry.url().SchemeIs(chrome::kJavaScriptScheme)) |
| 813 | return false; |
| 814 | } |
| 815 | |
| 816 | // Clear any provisional password saves - this stops password infobars |
| 817 | // showing up on pages the user navigates to while the right page is |
| 818 | // loading. |
| 819 | GetPasswordManager()->ClearProvisionalSave(); |
| 820 | |
[email protected] | 1ccb3568d | 2010-02-19 10:51:16 | [diff] [blame] | 821 | if (reload_type != NavigationController::NO_RELOAD && |
| 822 | !profile()->IsOffTheRecord()) { |
[email protected] | 0189bc72 | 2009-08-28 21:56:48 | [diff] [blame] | 823 | FaviconService* favicon_service = |
| 824 | profile()->GetFaviconService(Profile::IMPLICIT_ACCESS); |
| 825 | if (favicon_service) |
| 826 | favicon_service->SetFaviconOutOfDateForPage(entry.url()); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 827 | } |
| 828 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 829 | return true; |
| 830 | } |
| 831 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 832 | void TabContents::Stop() { |
| 833 | render_manager_.Stop(); |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 834 | printing_->Stop(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 837 | void TabContents::DisassociateFromPopupCount() { |
| 838 | render_view_host()->DisassociateFromPopupCount(); |
| 839 | } |
| 840 | |
| 841 | TabContents* TabContents::Clone() { |
| 842 | // We create a new SiteInstance so that the new tab won't share processes |
| 843 | // with the old one. This can be changed in the future if we need it to share |
| 844 | // processes for some reason. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 845 | TabContents* tc = new TabContents(profile(), |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 846 | SiteInstance::CreateSiteInstance(profile()), |
[email protected] | 12636df | 2009-09-28 22:32:21 | [diff] [blame] | 847 | MSG_ROUTING_NONE, this); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 848 | tc->controller().CopyStateFrom(controller_); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 849 | tc->extension_app_ = extension_app_; |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 850 | tc->extension_app_icon_ = extension_app_icon_; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 851 | return tc; |
| 852 | } |
| 853 | |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 854 | void TabContents::ShowPageInfo(const GURL& url, |
| 855 | const NavigationEntry::SSLStatus& ssl, |
| 856 | bool show_history) { |
| 857 | if (!delegate_) |
| 858 | return; |
| 859 | |
[email protected] | bb67833 | 2009-07-21 00:15:50 | [diff] [blame] | 860 | delegate_->ShowPageInfo(profile(), url, ssl, show_history); |
[email protected] | 4d67720 | 2009-07-19 07:37:12 | [diff] [blame] | 861 | } |
| 862 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 863 | ConstrainedWindow* TabContents::CreateConstrainedDialog( |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 864 | ConstrainedWindowDelegate* delegate) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 865 | ConstrainedWindow* window = |
[email protected] | e838217 | 2009-06-19 22:16:28 | [diff] [blame] | 866 | ConstrainedWindow::CreateConstrainedDialog(this, delegate); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 867 | child_windows_.push_back(window); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 868 | |
| 869 | if (child_windows_.size() == 1) { |
| 870 | window->ShowConstrainedWindow(); |
| 871 | BlockTabContent(true); |
| 872 | } |
| 873 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 874 | return window; |
| 875 | } |
| 876 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 877 | void TabContents::BlockTabContent(bool blocked) { |
[email protected] | 8dccd7cb | 2010-02-25 05:19:55 | [diff] [blame] | 878 | RenderWidgetHostView* rwhv = GetRenderWidgetHostView(); |
| 879 | if (rwhv) |
| 880 | rwhv->SetVisuallyDeemphasized(blocked); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 881 | render_view_host()->set_ignore_input_events(blocked); |
| 882 | if (delegate_) |
| 883 | delegate_->SetTabContentBlocked(this, blocked); |
| 884 | } |
| 885 | |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 886 | void TabContents::AddNewContents(TabContents* new_contents, |
| 887 | WindowOpenDisposition disposition, |
| 888 | const gfx::Rect& initial_pos, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 889 | bool user_gesture) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 890 | if (!delegate_) |
| 891 | return; |
| 892 | |
[email protected] | 35f7d21 | 2009-04-29 21:19:27 | [diff] [blame] | 893 | if ((disposition == NEW_POPUP) && !user_gesture && |
| 894 | !CommandLine::ForCurrentProcess()->HasSwitch( |
| 895 | switches::kDisablePopupBlocking)) { |
[email protected] | 2c4410d | 2009-05-06 23:46:22 | [diff] [blame] | 896 | // Unrequested popups from normal pages are constrained unless they're in |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 897 | // the whitelist. The popup owner will handle checking this. |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 898 | delegate_->GetConstrainingContents(this)->AddPopup( |
| 899 | new_contents, initial_pos); |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 900 | } else { |
[email protected] | 304f879 | 2009-08-19 21:28:09 | [diff] [blame] | 901 | #if defined(OS_CHROMEOS) |
| 902 | if (disposition == NEW_POPUP) { |
| 903 | // If the popup is bigger than a given factor of the screen, then |
| 904 | // turn it into a foreground tab (on chrome os only) |
[email protected] | 8323b08 | 2010-07-16 16:56:11 | [diff] [blame] | 905 | // Also check for width or height == 0, which would otherwise indicate |
| 906 | // a tab sized popup window. |
[email protected] | 304f879 | 2009-08-19 21:28:09 | [diff] [blame] | 907 | GdkScreen* screen = gdk_screen_get_default(); |
| 908 | int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor; |
| 909 | int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor; |
[email protected] | 8323b08 | 2010-07-16 16:56:11 | [diff] [blame] | 910 | if (initial_pos.width() > max_width || initial_pos.width() == 0 || |
| 911 | initial_pos.height() > max_height || initial_pos.height() == 0) { |
[email protected] | 304f879 | 2009-08-19 21:28:09 | [diff] [blame] | 912 | disposition = NEW_FOREGROUND_TAB; |
| 913 | } |
| 914 | } |
| 915 | #endif |
| 916 | |
[email protected] | 0aa5531 | 2008-10-17 21:53:08 | [diff] [blame] | 917 | new_contents->DisassociateFromPopupCount(); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 918 | delegate_->AddNewContents(this, new_contents, disposition, initial_pos, |
| 919 | user_gesture); |
[email protected] | 7f37dd9 | 2009-09-15 16:35:49 | [diff] [blame] | 920 | NotificationService::current()->Notify( |
| 921 | NotificationType::TAB_ADDED, |
| 922 | Source<TabContentsDelegate>(delegate_), |
| 923 | Details<TabContents>(this)); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 924 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 925 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 926 | // TODO(pkasting): Why is this necessary? |
| 927 | PopupNotificationVisibilityChanged(blocked_popups_ != NULL); |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 928 | } |
| 929 | |
[email protected] | bcd9dc4 | 2010-01-23 16:38:18 | [diff] [blame] | 930 | bool TabContents::ExecuteCode(int request_id, const std::string& extension_id, |
[email protected] | 61f5a7b | 2009-12-22 22:21:20 | [diff] [blame] | 931 | const std::vector<URLPattern>& host_permissions, |
[email protected] | 20ad269 | 2009-11-20 18:27:20 | [diff] [blame] | 932 | bool is_js_code, const std::string& code_string, |
| 933 | bool all_frames) { |
[email protected] | ebd0eae7 | 2010-02-16 23:50:51 | [diff] [blame] | 934 | RenderViewHost* host = render_view_host(); |
| 935 | if (!host) |
| 936 | return false; |
| 937 | |
| 938 | return host->Send(new ViewMsg_ExecuteCode(host->routing_id(), |
| 939 | ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions, |
| 940 | is_js_code, code_string, all_frames))); |
[email protected] | 912256b3 | 2009-09-18 09:47:35 | [diff] [blame] | 941 | } |
| 942 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 943 | void TabContents::PopupNotificationVisibilityChanged(bool visible) { |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 944 | if (is_being_destroyed_) |
| 945 | return; |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 946 | content_settings_delegate_->SetPopupsBlocked(visible); |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 947 | if (!dont_notify_render_view_) |
[email protected] | e834524 | 2010-05-06 03:00:40 | [diff] [blame] | 948 | render_view_host()->AllowScriptToClose(!visible); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 949 | } |
| 950 | |
[email protected] | 5c9e97a | 2009-09-09 23:48:30 | [diff] [blame] | 951 | gfx::NativeView TabContents::GetContentNativeView() const { |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 952 | return view_->GetContentNativeView(); |
| 953 | } |
| 954 | |
| 955 | gfx::NativeView TabContents::GetNativeView() const { |
| 956 | return view_->GetNativeView(); |
| 957 | } |
| 958 | |
| 959 | void TabContents::GetContainerBounds(gfx::Rect *out) const { |
| 960 | view_->GetContainerBounds(out); |
| 961 | } |
| 962 | |
| 963 | void TabContents::Focus() { |
| 964 | view_->Focus(); |
| 965 | } |
| 966 | |
[email protected] | 90daadb4 | 2009-06-08 21:27:28 | [diff] [blame] | 967 | void TabContents::FocusThroughTabTraversal(bool reverse) { |
[email protected] | 7e38369 | 2009-06-12 19:14:54 | [diff] [blame] | 968 | if (showing_interstitial_page()) { |
| 969 | render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse); |
| 970 | return; |
| 971 | } |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 972 | render_view_host()->SetInitialFocus(reverse); |
| 973 | } |
| 974 | |
| 975 | bool TabContents::FocusLocationBarByDefault() { |
| 976 | DOMUI* dom_ui = GetDOMUIForCurrentState(); |
| 977 | if (dom_ui) |
| 978 | return dom_ui->focus_location_bar_by_default(); |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 979 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | e0d48158 | 2009-09-15 21:06:25 | [diff] [blame] | 980 | if (entry && entry->url() == GURL(chrome::kAboutBlankURL)) |
[email protected] | 3e3f0eb | 2009-06-22 18:33:43 | [diff] [blame] | 981 | return true; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 982 | return false; |
| 983 | } |
| 984 | |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 985 | void TabContents::SetFocusToLocationBar(bool select_all) { |
[email protected] | a11aaf2 | 2010-03-30 00:03:38 | [diff] [blame] | 986 | if (delegate()) |
[email protected] | a26dc36 | 2010-04-23 01:48:58 | [diff] [blame] | 987 | delegate()->SetFocusToLocationBar(select_all); |
[email protected] | a11aaf2 | 2010-03-30 00:03:38 | [diff] [blame] | 988 | } |
| 989 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 990 | void TabContents::AddInfoBar(InfoBarDelegate* delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 991 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 992 | delegate->InfoBarClosed(); |
| 993 | return; |
| 994 | } |
| 995 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 996 | // Look through the existing InfoBarDelegates we have for a match. If we've |
| 997 | // already got one that matches, then we don't add the new one. |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 998 | for (int i = 0; i < infobar_delegate_count(); ++i) { |
[email protected] | 6d27a7b | 2009-12-18 23:25:45 | [diff] [blame] | 999 | if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) { |
| 1000 | // Tell the new infobar to close so that it can clean itself up. |
| 1001 | delegate->InfoBarClosed(); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1002 | return; |
[email protected] | 6d27a7b | 2009-12-18 23:25:45 | [diff] [blame] | 1003 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1004 | } |
| 1005 | |
| 1006 | infobar_delegates_.push_back(delegate); |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1007 | NotificationService::current()->Notify( |
| 1008 | NotificationType::TAB_CONTENTS_INFOBAR_ADDED, |
| 1009 | Source<TabContents>(this), |
| 1010 | Details<InfoBarDelegate>(delegate)); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1011 | |
| 1012 | // Add ourselves as an observer for navigations the first time a delegate is |
| 1013 | // added. We use this notification to expire InfoBars that need to expire on |
| 1014 | // page transitions. |
| 1015 | if (infobar_delegates_.size() == 1) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1016 | registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1017 | Source<NavigationController>(&controller_)); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | |
| 1021 | void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 1022 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 1023 | return; |
| 1024 | } |
| 1025 | |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1026 | std::vector<InfoBarDelegate*>::iterator it = |
| 1027 | find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate); |
| 1028 | if (it != infobar_delegates_.end()) { |
| 1029 | InfoBarDelegate* delegate = *it; |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1030 | NotificationService::current()->Notify( |
| 1031 | NotificationType::TAB_CONTENTS_INFOBAR_REMOVED, |
| 1032 | Source<TabContents>(this), |
| 1033 | Details<InfoBarDelegate>(delegate)); |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1034 | infobar_delegates_.erase(it); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1035 | |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 1036 | // Remove ourselves as an observer if we are tracking no more InfoBars. |
| 1037 | if (infobar_delegates_.empty()) { |
[email protected] | bfd04a6 | 2009-02-01 18:16:56 | [diff] [blame] | 1038 | registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, |
[email protected] | ce3fa3c | 2009-04-20 19:55:57 | [diff] [blame] | 1039 | Source<NavigationController>(&controller_)); |
[email protected] | 6a02963e | 2009-01-06 16:58:03 | [diff] [blame] | 1040 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1041 | } |
| 1042 | } |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1043 | |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1044 | void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate, |
| 1045 | InfoBarDelegate* new_delegate) { |
[email protected] | f701930 | 2010-03-26 19:58:32 | [diff] [blame] | 1046 | if (delegate_ && !delegate_->infobars_enabled()) { |
| 1047 | new_delegate->InfoBarClosed(); |
| 1048 | return; |
| 1049 | } |
| 1050 | |
[email protected] | f81821c | 2009-08-07 01:29:47 | [diff] [blame] | 1051 | std::vector<InfoBarDelegate*>::iterator it = |
| 1052 | find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate); |
| 1053 | DCHECK(it != infobar_delegates_.end()); |
| 1054 | |
| 1055 | // Notify the container about the change of plans. |
| 1056 | scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details( |
| 1057 | new std::pair<InfoBarDelegate*, InfoBarDelegate*>( |
| 1058 | old_delegate, new_delegate)); |
| 1059 | NotificationService::current()->Notify( |
| 1060 | NotificationType::TAB_CONTENTS_INFOBAR_REPLACED, |
| 1061 | Source<TabContents>(this), |
| 1062 | Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get())); |
| 1063 | |
| 1064 | // Remove the old one. |
| 1065 | infobar_delegates_.erase(it); |
| 1066 | |
| 1067 | // Add the new one. |
| 1068 | infobar_delegates_.push_back(new_delegate); |
| 1069 | } |
| 1070 | |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 1071 | bool TabContents::ShouldShowBookmarkBar() { |
[email protected] | aa9196f | 2009-10-22 16:20:27 | [diff] [blame] | 1072 | if (showing_interstitial_page()) |
| 1073 | return false; |
| 1074 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1075 | // See GetDOMUIForCurrentState() comment for more info. This case is very |
| 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()) { |
| 1079 | // Not the first load, always use the committed DOM UI. |
| 1080 | if (render_manager_.dom_ui()) |
| 1081 | return render_manager_.dom_ui()->force_bookmark_bar_visible(); |
| 1082 | return false; // Default. |
| 1083 | } |
| 1084 | |
| 1085 | // When it's the first load, we know either the pending one or the committed |
| 1086 | // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one |
| 1087 | // of them will be valid, so we can just check both. |
| 1088 | if (render_manager_.pending_dom_ui()) |
| 1089 | return render_manager_.pending_dom_ui()->force_bookmark_bar_visible(); |
| 1090 | if (render_manager_.dom_ui()) |
| 1091 | return render_manager_.dom_ui()->force_bookmark_bar_visible(); |
| 1092 | return false; // Default. |
| 1093 | } |
| 1094 | |
[email protected] | d8f16ae | 2009-08-30 03:47:26 | [diff] [blame] | 1095 | bool TabContents::IsExtensionShelfAlwaysVisible() { |
| 1096 | // See GetDOMUIForCurrentState() comment for more info. This case is very |
| 1097 | // similar, but for non-first loads, we want to use the committed entry. This |
| 1098 | // is so the bookmarks bar disappears at the same time the page does. |
| 1099 | if (controller_.GetLastCommittedEntry()) { |
| 1100 | // Not the first load, always use the committed DOM UI. |
| 1101 | if (render_manager_.dom_ui()) |
| 1102 | return render_manager_.dom_ui()->force_extension_shelf_visible(); |
| 1103 | return false; // Default. |
| 1104 | } |
| 1105 | |
| 1106 | // When it's the first load, we know either the pending one or the committed |
| 1107 | // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one |
| 1108 | // of them will be valid, so we can just check both. |
| 1109 | if (render_manager_.pending_dom_ui()) |
| 1110 | return render_manager_.pending_dom_ui()->force_extension_shelf_visible(); |
| 1111 | if (render_manager_.dom_ui()) |
| 1112 | return render_manager_.dom_ui()->force_extension_shelf_visible(); |
| 1113 | return false; // Default. |
| 1114 | } |
| 1115 | |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1116 | void TabContents::ToolbarSizeChanged(bool is_animating) { |
| 1117 | TabContentsDelegate* d = delegate(); |
| 1118 | if (d) |
| 1119 | d->ToolbarSizeChanged(this, is_animating); |
| 1120 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1121 | |
[email protected] | fc6fb7fb | 2009-11-07 02:35:04 | [diff] [blame] | 1122 | bool TabContents::CanDownload(int request_id) { |
| 1123 | TabContentsDelegate* d = delegate(); |
| 1124 | if (d) |
| 1125 | return d->CanDownload(request_id); |
| 1126 | return true; |
| 1127 | } |
| 1128 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1129 | void TabContents::OnStartDownload(DownloadItem* download) { |
| 1130 | DCHECK(download); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1131 | |
| 1132 | // Download in a constrained popup is shown in the tab that opened it. |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1133 | TabContents* tab_contents = delegate()->GetConstrainingContents(this); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1134 | |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 1135 | if (tab_contents && tab_contents->delegate()) { |
[email protected] | 59560e0b | 2009-06-04 03:30:22 | [diff] [blame] | 1136 | tab_contents->delegate()->OnStartDownload(download); |
[email protected] | c70f9b8 | 2010-04-21 07:31:11 | [diff] [blame] | 1137 | // If the download occurs in a new tab, close it |
| 1138 | if (controller_.IsInitialNavigation() && (tab_contents == this)) |
| 1139 | delegate()->CloseContents(this); |
| 1140 | } |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1141 | } |
[email protected] | 3edd952 | 2009-03-04 22:19:41 | [diff] [blame] | 1142 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1143 | void TabContents::WillClose(ConstrainedWindow* window) { |
| 1144 | ConstrainedWindowList::iterator it = |
| 1145 | find(child_windows_.begin(), child_windows_.end(), window); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1146 | bool removed_topmost_window = it == child_windows_.begin(); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1147 | if (it != child_windows_.end()) |
| 1148 | child_windows_.erase(it); |
[email protected] | 5509879 | 2010-03-24 18:20:37 | [diff] [blame] | 1149 | if (child_windows_.size() > 0) { |
| 1150 | if (removed_topmost_window) { |
| 1151 | child_windows_[0]->ShowConstrainedWindow(); |
| 1152 | } |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1153 | BlockTabContent(true); |
| 1154 | } else { |
| 1155 | BlockTabContent(false); |
| 1156 | } |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 1157 | } |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1158 | |
[email protected] | 66ba493 | 2009-06-04 19:22:13 | [diff] [blame] | 1159 | void TabContents::WillCloseBlockedPopupContainer( |
| 1160 | BlockedPopupContainer* container) { |
| 1161 | DCHECK(blocked_popups_ == container); |
| 1162 | blocked_popups_ = NULL; |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1163 | PopupNotificationVisibilityChanged(false); |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1164 | } |
| 1165 | |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1166 | void TabContents::DidMoveOrResize(ConstrainedWindow* window) { |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 1167 | #if defined(OS_WIN) |
[email protected] | 92edc47 | 2009-02-10 20:32:06 | [diff] [blame] | 1168 | UpdateWindow(GetNativeView()); |
[email protected] | 332af773 | 2009-03-11 13:21:35 | [diff] [blame] | 1169 | #endif |
[email protected] | d5f942ba | 2008-09-26 19:30:34 | [diff] [blame] | 1170 | } |
| 1171 | |
[email protected] | c1dc9f13 | 2009-11-20 23:13:21 | [diff] [blame] | 1172 | void TabContents::StartFinding(string16 search_string, |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1173 | bool forward_direction, |
| 1174 | bool case_sensitive) { |
[email protected] | c1dc9f13 | 2009-11-20 23:13:21 | [diff] [blame] | 1175 | // If search_string is empty, it means FindNext was pressed with a keyboard |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1176 | // shortcut so unless we have something to search for we return early. |
[email protected] | c1dc9f13 | 2009-11-20 23:13:21 | [diff] [blame] | 1177 | if (search_string.empty() && find_text_.empty()) { |
[email protected] | e5d2f713 | 2010-04-09 18:13:53 | [diff] [blame] | 1178 | string16 last_search_prepopulate_text = |
| 1179 | FindBarState::GetLastPrepopulateText(profile()); |
| 1180 | |
[email protected] | 87fae51 | 2009-12-11 02:20:21 | [diff] [blame] | 1181 | // Try the last thing we searched for on this tab, then the last thing |
| 1182 | // searched for on any tab. |
| 1183 | if (!previous_find_text_.empty()) |
| 1184 | search_string = previous_find_text_; |
[email protected] | e5d2f713 | 2010-04-09 18:13:53 | [diff] [blame] | 1185 | else if (!last_search_prepopulate_text.empty()) |
| 1186 | search_string = last_search_prepopulate_text; |
[email protected] | 87fae51 | 2009-12-11 02:20:21 | [diff] [blame] | 1187 | else |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1188 | return; |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1189 | } |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1190 | |
[email protected] | 101c90e | 2009-10-26 21:14:44 | [diff] [blame] | 1191 | // Keep track of the previous search. |
| 1192 | previous_find_text_ = find_text_; |
| 1193 | |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1194 | // This is a FindNext operation if we are searching for the same text again, |
| 1195 | // or if the passed in search text is empty (FindNext keyboard shortcut). The |
| 1196 | // exception to this is if the Find was aborted (then we don't want FindNext |
| 1197 | // because the highlighting has been cleared and we need it to reappear). We |
| 1198 | // therefore treat FindNext after an aborted Find operation as a full fledged |
| 1199 | // Find. |
[email protected] | c1dc9f13 | 2009-11-20 23:13:21 | [diff] [blame] | 1200 | bool find_next = (find_text_ == search_string || search_string.empty()) && |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1201 | (last_search_case_sensitive_ == case_sensitive) && |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1202 | !find_op_aborted_; |
| 1203 | if (!find_next) |
| 1204 | current_find_request_id_ = find_request_id_counter_++; |
| 1205 | |
[email protected] | c1dc9f13 | 2009-11-20 23:13:21 | [diff] [blame] | 1206 | if (!search_string.empty()) |
| 1207 | find_text_ = search_string; |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1208 | last_search_case_sensitive_ = case_sensitive; |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1209 | |
| 1210 | find_op_aborted_ = false; |
| 1211 | |
| 1212 | // Keep track of what the last search was across the tabs. |
[email protected] | e5d2f713 | 2010-04-09 18:13:53 | [diff] [blame] | 1213 | FindBarState* find_bar_state = profile()->GetFindBarState(); |
| 1214 | find_bar_state->set_last_prepopulate_text(find_text_); |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1215 | render_view_host()->StartFinding(current_find_request_id_, |
| 1216 | find_text_, |
| 1217 | forward_direction, |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1218 | case_sensitive, |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1219 | find_next); |
| 1220 | } |
| 1221 | |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 1222 | void TabContents::StopFinding( |
| 1223 | FindBarController::SelectionAction selection_action) { |
[email protected] | d6e8d33 | 2010-06-04 22:26:01 | [diff] [blame] | 1224 | if (selection_action == FindBarController::kClearSelection) { |
| 1225 | // kClearSelection means the find string has been cleared by the user, but |
| 1226 | // the UI has not been dismissed. In that case we want to clear the |
| 1227 | // previously remembered search (http://crbug.com/42639). |
| 1228 | previous_find_text_ = string16(); |
| 1229 | } else { |
[email protected] | 2d2dffc | 2009-06-09 21:41:00 | [diff] [blame] | 1230 | find_ui_active_ = false; |
[email protected] | d6e8d33 | 2010-06-04 22:26:01 | [diff] [blame] | 1231 | if (!find_text_.empty()) |
| 1232 | previous_find_text_ = find_text_; |
| 1233 | } |
[email protected] | 101c90e | 2009-10-26 21:14:44 | [diff] [blame] | 1234 | find_text_.clear(); |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1235 | find_op_aborted_ = true; |
[email protected] | e491f1c | 2009-05-22 20:28:12 | [diff] [blame] | 1236 | last_search_result_ = FindNotificationDetails(); |
[email protected] | 5bc8fe9 | 2010-03-11 18:19:00 | [diff] [blame] | 1237 | render_view_host()->StopFinding(selection_action); |
[email protected] | 6e95706d | 2009-04-23 22:55:01 | [diff] [blame] | 1238 | } |
| 1239 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1240 | void TabContents::OnSavePage() { |
| 1241 | // If we can not save the page, try to download it. |
| 1242 | if (!SavePackage::IsSavableContents(contents_mime_type())) { |
| 1243 | DownloadManager* dlm = profile()->GetDownloadManager(); |
| 1244 | const GURL& current_page_url = GetURL(); |
| 1245 | if (dlm && current_page_url.is_valid()) |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1246 | dlm->DownloadUrl(current_page_url, GURL(), "", this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1247 | return; |
| 1248 | } |
| 1249 | |
| 1250 | Stop(); |
| 1251 | |
| 1252 | // Create the save package and possibly prompt the user for the name to save |
| 1253 | // the page as. The user prompt is an asynchronous operation that runs on |
| 1254 | // another thread. |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1255 | save_package_ = new SavePackage(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1256 | save_package_->GetSaveInfo(); |
| 1257 | } |
| 1258 | |
| 1259 | // Used in automated testing to bypass prompting the user for file names. |
| 1260 | // Instead, the names and paths are hard coded rather than running them through |
| 1261 | // file name sanitation and extension / mime checking. |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 1262 | bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1263 | SavePackage::SavePackageType save_type) { |
| 1264 | // Stop the page from navigating. |
| 1265 | Stop(); |
| 1266 | |
[email protected] | 828cabe | 2009-09-26 22:47:11 | [diff] [blame] | 1267 | save_package_ = new SavePackage(this, save_type, main_file, dir_path); |
[email protected] | cdf6cc8 | 2009-08-04 21:48:59 | [diff] [blame] | 1268 | return save_package_->Init(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1269 | } |
| 1270 | |
[email protected] | 89d6e6e | 2009-12-03 23:06:51 | [diff] [blame] | 1271 | void TabContents::EmailPageLocation() { |
| 1272 | std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false); |
| 1273 | std::string page_url = EscapeQueryParamValue(GetURL().spec(), false); |
| 1274 | std::string mailto = std::string("mailto:?subject=Fwd:%20") + |
| 1275 | title + "&body=%0A%0A" + page_url; |
| 1276 | platform_util::OpenExternal(GURL(mailto)); |
| 1277 | } |
| 1278 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1279 | void TabContents::PrintPreview() { |
| 1280 | // We don't show the print preview yet, only the print dialog. |
| 1281 | PrintNow(); |
| 1282 | } |
| 1283 | |
| 1284 | bool TabContents::PrintNow() { |
| 1285 | // We can't print interstitial page for now. |
| 1286 | if (showing_interstitial_page()) |
| 1287 | return false; |
| 1288 | |
| 1289 | return render_view_host()->PrintPages(); |
| 1290 | } |
| 1291 | |
[email protected] | 8227045 | 2009-06-19 15:58:01 | [diff] [blame] | 1292 | void TabContents::PrintingDone(int document_cookie, bool success) { |
| 1293 | render_view_host()->PrintingDone(document_cookie, success); |
| 1294 | } |
| 1295 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1296 | bool TabContents::IsActiveEntry(int32 page_id) { |
| 1297 | NavigationEntry* active_entry = controller_.GetActiveEntry(); |
| 1298 | return (active_entry != NULL && |
| 1299 | active_entry->site_instance() == GetSiteInstance() && |
| 1300 | active_entry->page_id() == page_id); |
| 1301 | } |
| 1302 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1303 | void TabContents::SetOverrideEncoding(const std::string& encoding) { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1304 | set_encoding(encoding); |
| 1305 | render_view_host()->SetPageEncoding(encoding); |
| 1306 | } |
| 1307 | |
[email protected] | b2fe07d1 | 2010-02-09 14:38:08 | [diff] [blame] | 1308 | void TabContents::ResetOverrideEncoding() { |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 1309 | reset_encoding(); |
| 1310 | render_view_host()->ResetPageEncodingToDefault(); |
| 1311 | } |
| 1312 | |
| 1313 | void TabContents::WindowMoveOrResizeStarted() { |
| 1314 | render_view_host()->WindowMoveOrResizeStarted(); |
| 1315 | } |
| 1316 | |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1317 | void TabContents::LogNewTabTime(const std::string& event_name) { |
| 1318 | // Not all new tab pages get timed. In those cases, we don't have a |
| 1319 | // new_tab_start_time_. |
| 1320 | if (new_tab_start_time_.is_null()) |
| 1321 | return; |
| 1322 | |
| 1323 | base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_; |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1324 | MetricEventDurationDetails details(event_name, |
| 1325 | static_cast<int>(duration.InMilliseconds())); |
| 1326 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1327 | if (event_name == "Tab.NewTabScriptStart") { |
| 1328 | UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration); |
| 1329 | } else if (event_name == "Tab.NewTabDOMContentLoaded") { |
| 1330 | UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration); |
| 1331 | } else if (event_name == "Tab.NewTabOnload") { |
| 1332 | UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1333 | // The new tab page has finished loading; reset it. |
| 1334 | new_tab_start_time_ = base::TimeTicks(); |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1335 | } else { |
| 1336 | NOTREACHED(); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1337 | } |
[email protected] | 84abba6 | 2009-10-07 17:01:44 | [diff] [blame] | 1338 | NotificationService::current()->Notify( |
| 1339 | NotificationType::METRIC_EVENT_DURATION, |
| 1340 | Source<TabContents>(this), |
| 1341 | Details<MetricEventDurationDetails>(&details)); |
[email protected] | 3f8eb7f | 2009-10-02 23:58:05 | [diff] [blame] | 1342 | } |
| 1343 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 1344 | void TabContents::OnCloseStarted() { |
| 1345 | if (tab_close_start_time_.is_null()) |
| 1346 | tab_close_start_time_ = base::TimeTicks::Now(); |
| 1347 | } |
| 1348 | |
[email protected] | b5558cf2 | 2010-07-12 17:30:06 | [diff] [blame] | 1349 | void TabContents::set_request_context(URLRequestContextGetter* context) { |
| 1350 | request_context_ = context; |
| 1351 | } |
| 1352 | |
[email protected] | 46624bf | 2010-06-09 16:04:19 | [diff] [blame] | 1353 | bool TabContents::ShouldAcceptDragAndDrop() const { |
| 1354 | #if defined(OS_CHROMEOS) |
| 1355 | // ChromeOS panels (pop-ups) do not take drag-n-drop. |
| 1356 | // See http://crosbug.com/2413 |
| 1357 | return delegate() && !delegate()->IsPopup(const_cast<TabContents*>(this)); |
| 1358 | #else |
| 1359 | return true; |
| 1360 | #endif |
| 1361 | } |
| 1362 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1363 | TabContents* TabContents::CloneAndMakePhantom() { |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1364 | TabNavigation tab_nav; |
[email protected] | df72ac7 | 2010-02-06 00:43:16 | [diff] [blame] | 1365 | |
| 1366 | NavigationEntry* entry = controller().GetActiveEntry(); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1367 | if (extension_app_) |
| 1368 | tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL()); |
[email protected] | df72ac7 | 2010-02-06 00:43:16 | [diff] [blame] | 1369 | else if (entry) |
| 1370 | tab_nav.SetFromNavigationEntry(*entry); |
| 1371 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1372 | std::vector<TabNavigation> navigations; |
| 1373 | navigations.push_back(tab_nav); |
| 1374 | |
| 1375 | TabContents* new_contents = |
| 1376 | new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL); |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1377 | new_contents->SetExtensionApp(extension_app_); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1378 | new_contents->controller().RestoreFromState(navigations, 0, false); |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1379 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 1380 | if (!extension_app_ && entry) |
[email protected] | df72ac7 | 2010-02-06 00:43:16 | [diff] [blame] | 1381 | new_contents->controller().GetActiveEntry()->favicon() = entry->favicon(); |
| 1382 | |
[email protected] | c37e3b6 | 2010-01-22 00:15:17 | [diff] [blame] | 1383 | return new_contents; |
| 1384 | } |
| 1385 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1386 | // Notifies the RenderWidgetHost instance about the fact that the page is |
| 1387 | // loading, or done loading and calls the base implementation. |
| 1388 | void TabContents::SetIsLoading(bool is_loading, |
| 1389 | LoadNotificationDetails* details) { |
| 1390 | if (is_loading == is_loading_) |
| 1391 | return; |
| 1392 | |
| 1393 | if (!is_loading) { |
| 1394 | load_state_ = net::LOAD_STATE_IDLE; |
| 1395 | load_state_host_.clear(); |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 1396 | upload_size_ = 0; |
| 1397 | upload_position_ = 0; |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | render_manager_.SetIsLoading(is_loading); |
| 1401 | |
| 1402 | is_loading_ = is_loading; |
| 1403 | waiting_for_response_ = is_loading; |
| 1404 | |
| 1405 | if (delegate_) |
| 1406 | delegate_->LoadingStateChanged(this); |
[email protected] | 329581b | 2009-04-28 06:52:35 | [diff] [blame] | 1407 | NotifyNavigationStateChanged(INVALIDATE_LOAD); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1408 | |
| 1409 | NotificationType type = is_loading ? NotificationType::LOAD_START : |
| 1410 | NotificationType::LOAD_STOP; |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1411 | NotificationDetails det = NotificationService::NoDetails(); |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1412 | if (details) |
| 1413 | det = Details<LoadNotificationDetails>(details); |
| 1414 | NotificationService::current()->Notify(type, |
| 1415 | Source<NavigationController>(&controller_), |
| 1416 | det); |
| 1417 | } |
| 1418 | |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 1419 | void TabContents::AddPopup(TabContents* new_contents, |
[email protected] | 7e7414ae | 2010-01-26 20:19:29 | [diff] [blame] | 1420 | const gfx::Rect& initial_pos) { |
[email protected] | 57eda82a | 2010-05-05 21:28:06 | [diff] [blame] | 1421 | // A page can't spawn popups (or do anything else, either) until its load |
| 1422 | // commits, so when we reach here, the popup was spawned by the |
| 1423 | // NavigationController's last committed entry, not the active entry. For |
| 1424 | // example, if a page opens a popup in an onunload() handler, then the active |
| 1425 | // entry is the page to be loaded as we navigate away from the unloading |
| 1426 | // page. For this reason, we can't use GetURL() to get the opener URL, |
| 1427 | // because it returns the active entry. |
| 1428 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 1429 | GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL(); |
| 1430 | |
| 1431 | if (creator.is_valid() && |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1432 | profile()->GetHostContentSettingsMap()->GetContentSetting( |
[email protected] | 57eda82a | 2010-05-05 21:28:06 | [diff] [blame] | 1433 | creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) { |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1434 | AddNewContents(new_contents, NEW_POPUP, initial_pos, true); |
| 1435 | } else { |
| 1436 | if (!blocked_popups_) |
| 1437 | blocked_popups_ = new BlockedPopupContainer(this); |
| 1438 | blocked_popups_->AddTabContents(new_contents, initial_pos); |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 1439 | content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS); |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1440 | } |
[email protected] | b968131 | 2008-11-07 00:08:26 | [diff] [blame] | 1441 | } |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1442 | |
| 1443 | namespace { |
| 1444 | bool TransitionIsReload(PageTransition::Type transition) { |
| 1445 | return PageTransition::StripQualifier(transition) == PageTransition::RELOAD; |
| 1446 | } |
| 1447 | } |
| 1448 | |
| 1449 | void TabContents::ExpireInfoBars( |
| 1450 | const NavigationController::LoadCommittedDetails& details) { |
| 1451 | // Only hide InfoBars when the user has done something that makes the main |
| 1452 | // frame load. We don't want various automatic or subframe navigations making |
| 1453 | // it disappear. |
| 1454 | if (!details.is_user_initiated_main_frame_load()) |
| 1455 | return; |
| 1456 | |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1457 | for (int i = infobar_delegate_count() - 1; i >= 0; --i) { |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1458 | InfoBarDelegate* delegate = GetInfoBarDelegateAt(i); |
[email protected] | f86a0702 | 2008-11-25 01:06:05 | [diff] [blame] | 1459 | if (delegate->ShouldExpire(details)) |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1460 | RemoveInfoBar(delegate); |
[email protected] | 616ed5a | 2008-11-21 22:27:24 | [diff] [blame] | 1461 | } |
| 1462 | } |
[email protected] | fdd61c6 | 2009-04-22 19:22:57 | [diff] [blame] | 1463 | |
[email protected] | 96d185d | 2009-04-24 03:28:54 | [diff] [blame] | 1464 | DOMUI* TabContents::GetDOMUIForCurrentState() { |
| 1465 | // When there is a pending navigation entry, we want to use the pending DOMUI |
| 1466 | // that goes along with it to control the basic flags. For example, we want to |
| 1467 | // show the pending URL in the URL bar, so we want the display_url flag to |
| 1468 | // be from the pending entry. |
| 1469 | // |
| 1470 | // The confusion comes because there are multiple possibilities for the |
| 1471 | // initial load in a tab as a side effect of the way the RenderViewHostManager |
| 1472 | // works. |
| 1473 | // |
| 1474 | // - For the very first tab the load looks "normal". The new tab DOM UI is |
| 1475 | // the pending one, and we want it to apply here. |
| 1476 | // |
| 1477 | // - For subsequent new tabs, they'll get a new SiteInstance which will then |
| 1478 | // get switched to the one previously associated with the new tab pages. |
| 1479 | // This switching will cause the manager to commit the RVH/DOMUI. So we'll |
| 1480 | // have a committed DOM UI in this case. |
| 1481 | // |
| 1482 | // This condition handles all of these cases: |
| 1483 | // |
| 1484 | // - First load in first tab: no committed nav entry + pending nav entry + |
| 1485 | // pending dom ui: |
| 1486 | // -> Use pending DOM UI if any. |
| 1487 | // |
| 1488 | // - First load in second tab: no committed nav entry + pending nav entry + |
| 1489 | // no pending DOM UI: |
| 1490 | // -> Use the committed DOM UI if any. |
| 1491 | // |
| 1492 | // - Second navigation in any tab: committed nav entry + pending nav entry: |
| 1493 | // -> Use pending DOM UI if any. |
| 1494 | // |
| 1495 | // - Normal state with no load: committed nav entry + no pending nav entry: |
| 1496 | // -> Use committed DOM UI. |
| 1497 | if (controller_.pending_entry() && |
| 1498 | (controller_.GetLastCommittedEntry() || |
| 1499 | render_manager_.pending_dom_ui())) |
| 1500 | return render_manager_.pending_dom_ui(); |
| 1501 | return render_manager_.dom_ui(); |
| 1502 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1503 | |
| 1504 | void TabContents::DidNavigateMainFramePostCommit( |
| 1505 | const NavigationController::LoadCommittedDetails& details, |
| 1506 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 1507 | if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) { |
| 1508 | // If this is a window.open navigation, use the same DOMUI as the renderer |
| 1509 | // that opened the window, as long as both renderers have the same |
| 1510 | // privileges. |
| 1511 | if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) { |
| 1512 | DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL()); |
| 1513 | // dom_ui might be NULL if the URL refers to a non-existent extension. |
| 1514 | if (dom_ui) { |
| 1515 | render_manager_.SetDOMUIPostCommit(dom_ui); |
| 1516 | dom_ui->RenderViewCreated(render_view_host()); |
| 1517 | } |
| 1518 | } |
| 1519 | opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI; |
| 1520 | } |
| 1521 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1522 | if (details.is_user_initiated_main_frame_load()) { |
| 1523 | // Clear the status bubble. This is a workaround for a bug where WebKit |
| 1524 | // doesn't let us know that the cursor left an element during a |
| 1525 | // transition (this is also why the mouse cursor remains as a hand after |
| 1526 | // clicking on a link); see bugs 1184641 and 980803. We don't want to |
| 1527 | // clear the bubble when a user navigates to a named anchor in the same |
| 1528 | // page. |
| 1529 | UpdateTargetURL(details.entry->page_id(), GURL()); |
| 1530 | |
| 1531 | // UpdateHelpersForDidNavigate will handle the case where the password_form |
| 1532 | // origin is valid. |
| 1533 | // TODO(brettw) bug 1343111: Password manager stuff in here needs to be |
| 1534 | // cleaned up and covered by tests. |
| 1535 | if (!params.password_form.origin.is_valid()) |
| 1536 | GetPasswordManager()->DidNavigate(); |
| 1537 | } |
| 1538 | |
| 1539 | // The keyword generator uses the navigation entries, so must be called after |
| 1540 | // the commit. |
| 1541 | GenerateKeywordIfNecessary(params); |
| 1542 | |
| 1543 | // Allow the new page to set the title again. |
| 1544 | received_page_title_ = false; |
| 1545 | |
| 1546 | // Get the favicon, either from history or request it from the net. |
| 1547 | fav_icon_helper_.FetchFavIcon(details.entry->url()); |
| 1548 | |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1549 | // Clear all page actions, blocked content notifications and browser actions |
| 1550 | // for this tab, unless this is an in-page navigation. |
[email protected] | a6e82fc | 2010-02-24 22:28:14 | [diff] [blame] | 1551 | if (!details.is_in_page) { |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1552 | ExtensionsService* service = profile()->GetExtensionsService(); |
| 1553 | if (service) { |
| 1554 | for (size_t i = 0; i < service->extensions()->size(); ++i) { |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1555 | ExtensionAction* browser_action = |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1556 | service->extensions()->at(i)->browser_action(); |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1557 | if (browser_action) { |
| 1558 | browser_action->ClearAllValuesForTab(controller().session_id().id()); |
| 1559 | NotificationService::current()->Notify( |
| 1560 | NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1561 | Source<ExtensionAction>(browser_action), |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1562 | NotificationService::NoDetails()); |
| 1563 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1564 | |
[email protected] | 5d246db2 | 2009-10-27 06:17:57 | [diff] [blame] | 1565 | ExtensionAction* page_action = |
[email protected] | 56ce6e5 | 2009-10-27 00:10:52 | [diff] [blame] | 1566 | service->extensions()->at(i)->page_action(); |
| 1567 | if (page_action) { |
| 1568 | page_action->ClearAllValuesForTab(controller().session_id().id()); |
| 1569 | PageActionStateChanged(); |
| 1570 | } |
[email protected] | 92c6f9b9 | 2009-10-24 04:35:08 | [diff] [blame] | 1571 | } |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1572 | } |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1573 | |
| 1574 | // Close blocked popups. |
| 1575 | if (blocked_popups_) { |
[email protected] | 0fbd7033 | 2010-06-01 19:28:34 | [diff] [blame] | 1576 | AutoReset<bool> auto_reset(&dont_notify_render_view_, true); |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1577 | blocked_popups_->Destroy(); |
[email protected] | da7b526 | 2010-02-25 21:12:46 | [diff] [blame] | 1578 | blocked_popups_ = NULL; |
[email protected] | 0de8016 | 2010-02-03 04:52:35 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | // Clear "blocked" flags. |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 1582 | content_settings_delegate_->ClearBlockedContentSettings(); |
| 1583 | content_settings_delegate_->GeolocationDidNavigate(details); |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 1584 | |
| 1585 | // Once the main frame is navigated, we're no longer considered to have |
| 1586 | // displayed insecure content. |
| 1587 | displayed_insecure_content_ = false; |
[email protected] | aece2c7f | 2009-08-27 20:43:17 | [diff] [blame] | 1588 | } |
[email protected] | ce5c450 | 2009-05-06 16:46:11 | [diff] [blame] | 1589 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1590 | // Close constrained windows if necessary. |
| 1591 | if (!net::RegistryControlledDomainService::SameDomainOrHost( |
| 1592 | details.previous_url, details.entry->url())) |
| 1593 | CloseConstrainedWindows(); |
| 1594 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1595 | // Update the starred state. |
| 1596 | UpdateStarredStateForCurrentURL(); |
[email protected] | c07c975 | 2010-03-12 05:57:53 | [diff] [blame] | 1597 | |
| 1598 | // Clear the cache of forms in AutoFill. |
| 1599 | if (autofill_manager_.get()) |
| 1600 | autofill_manager_->Reset(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1601 | } |
| 1602 | |
| 1603 | void TabContents::DidNavigateAnyFramePostCommit( |
| 1604 | RenderViewHost* render_view_host, |
| 1605 | const NavigationController::LoadCommittedDetails& details, |
| 1606 | const ViewHostMsg_FrameNavigate_Params& params) { |
| 1607 | // If we navigate, start showing messages again. This does nothing to prevent |
| 1608 | // a malicious script from spamming messages, since the script could just |
| 1609 | // reload the page to stop blocking. |
| 1610 | suppress_javascript_messages_ = false; |
| 1611 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1612 | // Notify the password manager of the navigation or form submit. |
| 1613 | // TODO(brettw) bug 1343111: Password manager stuff in here needs to be |
| 1614 | // cleaned up and covered by tests. |
| 1615 | if (params.password_form.origin.is_valid()) |
| 1616 | GetPasswordManager()->ProvisionallySavePassword(params.password_form); |
[email protected] | 3b1c181 | 2010-02-12 21:53:55 | [diff] [blame] | 1617 | |
| 1618 | // Let the LanguageState clear its state. |
[email protected] | 34cec8d8 | 2010-03-05 18:27:01 | [diff] [blame] | 1619 | bool reload = details.entry->transition_type() == PageTransition::RELOAD || |
| 1620 | details.type == NavigationType::SAME_PAGE; |
| 1621 | language_state_.DidNavigate(reload, details.is_in_page); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1622 | } |
| 1623 | |
[email protected] | 8cc8d49 | 2010-02-02 10:40:49 | [diff] [blame] | 1624 | void TabContents::CloseConstrainedWindows() { |
| 1625 | // Clear out any constrained windows since we are leaving this page entirely. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1626 | // We use indices instead of iterators in case CloseWindow does something |
| 1627 | // that may invalidate an iterator. |
| 1628 | int size = static_cast<int>(child_windows_.size()); |
| 1629 | for (int i = size - 1; i >= 0; --i) { |
| 1630 | ConstrainedWindow* window = child_windows_[i]; |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1631 | if (window) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1632 | window->CloseConstrainedWindow(); |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 1633 | BlockTabContent(false); |
| 1634 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1635 | } |
| 1636 | } |
| 1637 | |
| 1638 | void TabContents::UpdateStarredStateForCurrentURL() { |
| 1639 | BookmarkModel* model = profile()->GetBookmarkModel(); |
| 1640 | const bool old_state = is_starred_; |
| 1641 | is_starred_ = (model && model->IsBookmarked(GetURL())); |
| 1642 | |
| 1643 | if (is_starred_ != old_state && delegate()) |
| 1644 | delegate()->URLStarredChanged(this, is_starred_); |
| 1645 | } |
| 1646 | |
| 1647 | void TabContents::UpdateAlternateErrorPageURL() { |
| 1648 | GURL url = GetAlternateErrorPageURL(); |
| 1649 | render_view_host()->SetAlternateErrorPageURL(url); |
| 1650 | } |
| 1651 | |
| 1652 | void TabContents::UpdateWebPreferences() { |
| 1653 | render_view_host()->UpdateWebPreferences(GetWebkitPrefs()); |
| 1654 | } |
| 1655 | |
| 1656 | void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, |
| 1657 | RenderViewHost* rvh) { |
| 1658 | // If we are creating a RVH for a restored controller, then we might |
| 1659 | // have more page IDs than the SiteInstance's current max page ID. We must |
| 1660 | // make sure that the max page ID is larger than any restored page ID. |
| 1661 | // Note that it is ok for conflicting page IDs to exist in another tab |
| 1662 | // (i.e., NavigationController), but if any page ID is larger than the max, |
| 1663 | // the back/forward list will get confused. |
| 1664 | int max_restored_page_id = controller_.max_restored_page_id(); |
| 1665 | if (max_restored_page_id > 0) { |
| 1666 | int curr_max_page_id = site_instance->max_page_id(); |
| 1667 | if (max_restored_page_id > curr_max_page_id) { |
| 1668 | // Need to update the site instance immediately. |
| 1669 | site_instance->UpdateMaxPageID(max_restored_page_id); |
| 1670 | |
| 1671 | // Also tell the renderer to update its internal representation. We |
| 1672 | // need to reserve enough IDs to make all restored page IDs less than |
| 1673 | // the max. |
| 1674 | if (curr_max_page_id < 0) |
| 1675 | curr_max_page_id = 0; |
| 1676 | rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id); |
| 1677 | } |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | void TabContents::UpdateHistoryForNavigation( |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1682 | const GURL& virtual_url, |
[email protected] | befd8d82 | 2009-07-01 04:51:47 | [diff] [blame] | 1683 | const NavigationController::LoadCommittedDetails& details, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1684 | const ViewHostMsg_FrameNavigate_Params& params) { |
| 1685 | if (profile()->IsOffTheRecord()) |
| 1686 | return; |
| 1687 | |
| 1688 | // Add to history service. |
| 1689 | HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1690 | if (hs) { |
| 1691 | if (PageTransition::IsMainFrame(params.transition) && |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1692 | virtual_url != params.url) { |
| 1693 | // Hack on the "virtual" URL so that it will appear in history. For some |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1694 | // types of URLs, we will display a magic URL that is different from where |
| 1695 | // the page is actually navigated. We want the user to see in history |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1696 | // what they saw in the URL bar, so we add the virtual URL as a redirect. |
| 1697 | // This only applies to the main frame, as the virtual URL doesn't apply |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1698 | // to sub-frames. |
| 1699 | std::vector<GURL> redirects = params.redirects; |
| 1700 | if (!redirects.empty()) |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1701 | redirects.back() = virtual_url; |
| 1702 | hs->AddPage(virtual_url, this, params.page_id, params.referrer, |
[email protected] | befd8d82 | 2009-07-01 04:51:47 | [diff] [blame] | 1703 | params.transition, redirects, details.did_replace_entry); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1704 | } else { |
| 1705 | hs->AddPage(params.url, this, params.page_id, params.referrer, |
[email protected] | befd8d82 | 2009-07-01 04:51:47 | [diff] [blame] | 1706 | params.transition, params.redirects, |
| 1707 | details.did_replace_entry); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1708 | } |
| 1709 | } |
| 1710 | } |
| 1711 | |
| 1712 | bool TabContents::UpdateTitleForEntry(NavigationEntry* entry, |
| 1713 | const std::wstring& title) { |
| 1714 | // For file URLs without a title, use the pathname instead. In the case of a |
| 1715 | // synthesized title, we don't want the update to count toward the "one set |
| 1716 | // per page of the title to history." |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1717 | string16 final_title; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1718 | bool explicit_set; |
| 1719 | if (entry->url().SchemeIsFile() && title.empty()) { |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1720 | final_title = UTF8ToUTF16(entry->url().ExtractFileName()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1721 | explicit_set = false; // Don't count synthetic titles toward the set limit. |
| 1722 | } else { |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1723 | TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1724 | explicit_set = true; |
| 1725 | } |
| 1726 | |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1727 | if (final_title == entry->title()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1728 | return false; // Nothing changed, don't bother. |
| 1729 | |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1730 | entry->set_title(final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1731 | |
| 1732 | // Update the history system for this page. |
| 1733 | if (!profile()->IsOffTheRecord() && !received_page_title_) { |
| 1734 | HistoryService* hs = |
| 1735 | profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1736 | if (hs) |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 1737 | hs->SetPageTitle(entry->virtual_url(), final_title); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1738 | |
| 1739 | // Don't allow the title to be saved again for explicitly set ones. |
| 1740 | received_page_title_ = explicit_set; |
| 1741 | } |
| 1742 | |
| 1743 | // Lastly, set the title for the view. |
[email protected] | e5366896 | 2010-06-23 15:35:25 | [diff] [blame] | 1744 | view_->SetPageTitle(UTF16ToWideHack(final_title)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1745 | |
[email protected] | cbc0e1b | 2010-04-12 18:33:04 | [diff] [blame] | 1746 | NotificationService::current()->Notify( |
| 1747 | NotificationType::TAB_CONTENTS_TITLE_UPDATED, |
| 1748 | Source<TabContents>(this), |
| 1749 | NotificationService::NoDetails()); |
| 1750 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1751 | return true; |
| 1752 | } |
| 1753 | |
| 1754 | void TabContents::NotifySwapped() { |
| 1755 | // After sending out a swap notification, we need to send a disconnect |
| 1756 | // notification so that clients that pick up a pointer to |this| can NULL the |
| 1757 | // pointer. See Bug 1230284. |
| 1758 | notify_disconnection_ = true; |
| 1759 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1760 | NotificationType::TAB_CONTENTS_SWAPPED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1761 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1762 | NotificationService::NoDetails()); |
| 1763 | } |
| 1764 | |
| 1765 | void TabContents::NotifyConnected() { |
| 1766 | notify_disconnection_ = true; |
| 1767 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1768 | NotificationType::TAB_CONTENTS_CONNECTED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1769 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1770 | NotificationService::NoDetails()); |
| 1771 | } |
| 1772 | |
| 1773 | void TabContents::NotifyDisconnected() { |
| 1774 | if (!notify_disconnection_) |
| 1775 | return; |
| 1776 | |
| 1777 | notify_disconnection_ = false; |
| 1778 | NotificationService::current()->Notify( |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 1779 | NotificationType::TAB_CONTENTS_DISCONNECTED, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 1780 | Source<TabContents>(this), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1781 | NotificationService::NoDetails()); |
| 1782 | } |
| 1783 | |
| 1784 | void TabContents::GenerateKeywordIfNecessary( |
| 1785 | const ViewHostMsg_FrameNavigate_Params& params) { |
| 1786 | if (!params.searchable_form_url.is_valid()) |
| 1787 | return; |
| 1788 | |
| 1789 | if (profile()->IsOffTheRecord()) |
| 1790 | return; |
| 1791 | |
| 1792 | int last_index = controller_.last_committed_entry_index(); |
| 1793 | // When there was no previous page, the last index will be 0. This is |
| 1794 | // normally due to a form submit that opened in a new tab. |
| 1795 | // TODO(brettw) bug 916126: we should support keywords when form submits |
| 1796 | // happen in new tabs. |
| 1797 | if (last_index <= 0) |
| 1798 | return; |
| 1799 | const NavigationEntry* previous_entry = |
| 1800 | controller_.GetEntryAtIndex(last_index - 1); |
| 1801 | if (IsFormSubmit(previous_entry)) { |
| 1802 | // Only generate a keyword if the previous page wasn't itself a form |
| 1803 | // submit. |
| 1804 | return; |
| 1805 | } |
| 1806 | |
| 1807 | GURL keyword_url = previous_entry->user_typed_url().is_valid() ? |
| 1808 | previous_entry->user_typed_url() : previous_entry->url(); |
| 1809 | std::wstring keyword = |
| 1810 | TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected |
| 1811 | if (keyword.empty()) |
| 1812 | return; |
| 1813 | |
| 1814 | TemplateURLModel* url_model = profile()->GetTemplateURLModel(); |
| 1815 | if (!url_model) |
| 1816 | return; |
| 1817 | |
| 1818 | if (!url_model->loaded()) { |
| 1819 | url_model->Load(); |
| 1820 | return; |
| 1821 | } |
| 1822 | |
| 1823 | const TemplateURL* current_url; |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1824 | GURL url = params.searchable_form_url; |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1825 | if (!url_model->CanReplaceKeyword(keyword, url, ¤t_url)) |
| 1826 | return; |
| 1827 | |
| 1828 | if (current_url) { |
| 1829 | if (current_url->originating_url().is_valid()) { |
| 1830 | // The existing keyword was generated from an OpenSearch description |
| 1831 | // document, don't regenerate. |
| 1832 | return; |
| 1833 | } |
| 1834 | url_model->Remove(current_url); |
| 1835 | } |
| 1836 | TemplateURL* new_url = new TemplateURL(); |
| 1837 | new_url->set_keyword(keyword); |
| 1838 | new_url->set_short_name(keyword); |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 1839 | new_url->SetURL(url.spec(), 0, 0); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 1840 | new_url->add_input_encoding(params.searchable_form_encoding); |
| 1841 | DCHECK(controller_.GetLastCommittedEntry()); |
| 1842 | const GURL& favicon_url = |
| 1843 | controller_.GetLastCommittedEntry()->favicon().url(); |
| 1844 | if (favicon_url.is_valid()) { |
| 1845 | new_url->SetFavIconURL(favicon_url); |
| 1846 | } else { |
| 1847 | // The favicon url isn't valid. This means there really isn't a favicon, |
| 1848 | // or the favicon url wasn't obtained before the load started. This assumes |
| 1849 | // the later. |
| 1850 | // TODO(sky): Need a way to set the favicon that doesn't involve generating |
| 1851 | // its url. |
| 1852 | new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); |
| 1853 | } |
| 1854 | new_url->set_safe_for_autoreplace(true); |
| 1855 | url_model->Add(new_url); |
| 1856 | } |
| 1857 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1858 | void TabContents::OnUserGesture() { |
| 1859 | // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this. |
[email protected] | 4129132 | 2010-07-15 17:09:01 | [diff] [blame] | 1860 | DownloadRequestLimiter* limiter = |
| 1861 | g_browser_process->download_request_limiter(); |
| 1862 | if (limiter) |
| 1863 | limiter->OnUserGesture(this); |
[email protected] | e7eaedde | 2009-09-25 20:09:49 | [diff] [blame] | 1864 | ExternalProtocolHandler::OnUserGesture(); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1865 | controller_.OnUserGesture(); |
| 1866 | } |
| 1867 | |
| 1868 | void TabContents::OnFindReply(int request_id, |
| 1869 | int number_of_matches, |
| 1870 | const gfx::Rect& selection_rect, |
| 1871 | int active_match_ordinal, |
| 1872 | bool final_update) { |
[email protected] | 3ce7ced | 2009-07-24 18:52:42 | [diff] [blame] | 1873 | // Ignore responses for requests that have been aborted. |
| 1874 | if (find_op_aborted_) |
| 1875 | return; |
| 1876 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1877 | // Ignore responses for requests other than the one we have most recently |
| 1878 | // issued. That way we won't act on stale results when the user has |
| 1879 | // already typed in another query. |
| 1880 | if (request_id != current_find_request_id_) |
| 1881 | return; |
| 1882 | |
| 1883 | if (number_of_matches == -1) |
| 1884 | number_of_matches = last_search_result_.number_of_matches(); |
| 1885 | if (active_match_ordinal == -1) |
| 1886 | active_match_ordinal = last_search_result_.active_match_ordinal(); |
| 1887 | |
| 1888 | gfx::Rect selection = selection_rect; |
| 1889 | if (selection.IsEmpty()) |
| 1890 | selection = last_search_result_.selection_rect(); |
| 1891 | |
| 1892 | // Notify the UI, automation and any other observers that a find result was |
| 1893 | // found. |
| 1894 | last_search_result_ = FindNotificationDetails(request_id, number_of_matches, |
| 1895 | selection, active_match_ordinal, |
| 1896 | final_update); |
| 1897 | NotificationService::current()->Notify( |
| 1898 | NotificationType::FIND_RESULT_AVAILABLE, |
| 1899 | Source<TabContents>(this), |
| 1900 | Details<FindNotificationDetails>(&last_search_result_)); |
| 1901 | } |
| 1902 | |
| 1903 | void TabContents::GoToEntryAtOffset(int offset) { |
[email protected] | f9cc4c45 | 2009-10-13 14:56:38 | [diff] [blame] | 1904 | if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) |
| 1905 | controller_.GoToOffset(offset); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1906 | } |
| 1907 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1908 | void TabContents::OnMissingPluginStatus(int status) { |
| 1909 | #if defined(OS_WIN) |
| 1910 | // TODO(PORT): pull in when plug-ins work |
| 1911 | GetPluginInstaller()->OnMissingPluginStatus(status); |
| 1912 | #endif |
| 1913 | } |
| 1914 | |
| 1915 | void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1916 | DCHECK(!plugin_path.value().empty()); |
| 1917 | |
| 1918 | std::wstring plugin_name = plugin_path.ToWStringHack(); |
[email protected] | d32d4618 | 2009-07-23 00:09:35 | [diff] [blame] | 1919 | #if defined(OS_WIN) || defined(OS_MACOSX) |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1920 | scoped_ptr<FileVersionInfo> version_info( |
| 1921 | FileVersionInfo::CreateFileVersionInfo(plugin_path)); |
| 1922 | if (version_info.get()) { |
| 1923 | const std::wstring& product_name = version_info->product_name(); |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 1924 | if (!product_name.empty()) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1925 | plugin_name = product_name; |
[email protected] | 996fd70 | 2009-09-04 19:12:37 | [diff] [blame] | 1926 | #if defined(OS_MACOSX) |
| 1927 | // Many plugins on the Mac have .plugin in the actual name, which looks |
| 1928 | // terrible, so look for that and strip it off if present. |
| 1929 | const std::wstring plugin_extension(L".plugin"); |
| 1930 | if (EndsWith(plugin_name, plugin_extension, true)) |
| 1931 | plugin_name.erase(plugin_name.length() - plugin_extension.length()); |
| 1932 | #endif // OS_MACOSX |
| 1933 | } |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1934 | } |
[email protected] | 4a560ed | 2009-07-13 23:35:26 | [diff] [blame] | 1935 | #else |
| 1936 | NOTIMPLEMENTED() << " convert plugin path to plugin name"; |
| 1937 | #endif |
[email protected] | 2ae8a92 | 2010-06-28 20:27:53 | [diff] [blame] | 1938 | SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 1939 | IDR_INFOBAR_PLUGIN_CRASHED); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1940 | AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1941 | this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name), |
[email protected] | 2ae8a92 | 2010-06-28 20:27:53 | [diff] [blame] | 1942 | crash_icon, true)); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1943 | } |
| 1944 | |
| 1945 | void TabContents::OnCrashedWorker() { |
| 1946 | AddInfoBar(new SimpleAlertInfoBarDelegate( |
| 1947 | this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT), |
[email protected] | 938e1f9 | 2010-04-01 18:09:42 | [diff] [blame] | 1948 | NULL, true)); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1949 | } |
| 1950 | |
| 1951 | void TabContents::OnDidGetApplicationInfo( |
| 1952 | int32 page_id, |
| 1953 | const webkit_glue::WebApplicationInfo& info) { |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 1954 | web_app_info_ = info; |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1955 | |
[email protected] | ed543187 | 2009-11-17 08:39:51 | [diff] [blame] | 1956 | if (delegate()) |
| 1957 | delegate()->OnDidGetApplicationInfo(this, page_id); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 1958 | } |
| 1959 | |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 1960 | void TabContents::OnPageContents(const GURL& url, |
| 1961 | int renderer_process_id, |
| 1962 | int32 page_id, |
[email protected] | e510620 | 2010-06-11 21:12:36 | [diff] [blame] | 1963 | const string16& contents, |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 1964 | const std::string& language, |
| 1965 | bool page_translatable) { |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 1966 | // Don't index any https pages. People generally don't want their bank |
| 1967 | // accounts, etc. indexed on their computer, especially since some of these |
| 1968 | // things are not marked cachable. |
| 1969 | // TODO(brettw) we may want to consider more elaborate heuristics such as |
| 1970 | // the cachability of the page. We may also want to consider subframes (this |
| 1971 | // test will still index subframes if the subframe is SSL). |
[email protected] | ccd40a5 | 2010-05-11 16:15:27 | [diff] [blame] | 1972 | // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable |
| 1973 | // content indexing for chromeos in some future releases. |
| 1974 | #if !defined(OS_CHROMEOS) |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 1975 | if (!url.SchemeIsSecure()) { |
| 1976 | Profile* p = profile(); |
| 1977 | if (p && !p->IsOffTheRecord()) { |
| 1978 | HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS); |
| 1979 | if (hs) |
| 1980 | hs->SetPageContents(url, contents); |
| 1981 | } |
| 1982 | } |
[email protected] | ccd40a5 | 2010-05-11 16:15:27 | [diff] [blame] | 1983 | #endif |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 1984 | |
[email protected] | 1c57b7b | 2010-07-12 17:38:10 | [diff] [blame] | 1985 | language_state_.LanguageDetermined(language, page_translatable); |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 1986 | |
| 1987 | std::string lang = language; |
| 1988 | NotificationService::current()->Notify( |
| 1989 | NotificationType::TAB_LANGUAGE_DETERMINED, |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 1990 | Source<TabContents>(this), |
[email protected] | a8a8129 | 2010-01-21 00:32:45 | [diff] [blame] | 1991 | Details<std::string>(&lang)); |
[email protected] | a2cf65eb | 2010-01-18 08:20:38 | [diff] [blame] | 1992 | } |
| 1993 | |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 1994 | void TabContents::OnPageTranslated(int32 page_id, |
| 1995 | const std::string& original_lang, |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 1996 | const std::string& translated_lang, |
| 1997 | TranslateErrors::Type error_type) { |
[email protected] | 3b1c181 | 2010-02-12 21:53:55 | [diff] [blame] | 1998 | language_state_.set_current_language(translated_lang); |
| 1999 | language_state_.set_translation_pending(false); |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 2000 | PageTranslatedDetails details(original_lang, translated_lang, error_type); |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2001 | NotificationService::current()->Notify( |
| 2002 | NotificationType::PAGE_TRANSLATED, |
| 2003 | Source<TabContents>(this), |
[email protected] | 152b8ba3 | 2010-03-29 19:40:16 | [diff] [blame] | 2004 | Details<PageTranslatedDetails>(&details)); |
[email protected] | 7e0831b | 2010-02-01 08:45:15 | [diff] [blame] | 2005 | } |
| 2006 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2007 | void TabContents::DidStartProvisionalLoadForFrame( |
| 2008 | RenderViewHost* render_view_host, |
| 2009 | bool is_main_frame, |
| 2010 | const GURL& url) { |
| 2011 | ProvisionalLoadDetails details(is_main_frame, |
| 2012 | controller_.IsURLInPageNavigation(url), |
| 2013 | url, std::string(), false); |
| 2014 | NotificationService::current()->Notify( |
| 2015 | NotificationType::FRAME_PROVISIONAL_LOAD_START, |
| 2016 | Source<NavigationController>(&controller_), |
| 2017 | Details<ProvisionalLoadDetails>(&details)); |
| 2018 | } |
| 2019 | |
| 2020 | void TabContents::DidStartReceivingResourceResponse( |
[email protected] | 3dbb80b | 2010-02-09 22:41:20 | [diff] [blame] | 2021 | const ResourceRequestDetails& details) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2022 | NotificationService::current()->Notify( |
| 2023 | NotificationType::RESOURCE_RESPONSE_STARTED, |
| 2024 | Source<NavigationController>(&controller()), |
[email protected] | 3dbb80b | 2010-02-09 22:41:20 | [diff] [blame] | 2025 | Details<const ResourceRequestDetails>(&details)); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2026 | } |
| 2027 | |
[email protected] | 3dbb80b | 2010-02-09 22:41:20 | [diff] [blame] | 2028 | void TabContents::DidRedirectResource( |
| 2029 | const ResourceRedirectDetails& details) { |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2030 | NotificationService::current()->Notify( |
| 2031 | NotificationType::RESOURCE_RECEIVED_REDIRECT, |
| 2032 | Source<NavigationController>(&controller()), |
[email protected] | 3dbb80b | 2010-02-09 22:41:20 | [diff] [blame] | 2033 | Details<const ResourceRequestDetails>(&details)); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | void TabContents::DidLoadResourceFromMemoryCache( |
| 2037 | const GURL& url, |
| 2038 | const std::string& frame_origin, |
| 2039 | const std::string& main_frame_origin, |
| 2040 | const std::string& security_info) { |
| 2041 | // Send out a notification that we loaded a resource from our memory cache. |
[email protected] | fc7de49 | 2010-07-12 14:49:04 | [diff] [blame] | 2042 | int cert_id = 0, cert_status = 0, security_bits = 0, connection_status = 0; |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2043 | SSLManager::DeserializeSecurityInfo(security_info, |
| 2044 | &cert_id, &cert_status, |
[email protected] | fc7de49 | 2010-07-12 14:49:04 | [diff] [blame] | 2045 | &security_bits, |
| 2046 | &connection_status); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2047 | LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin, |
[email protected] | 8cb5d5b | 2010-02-09 11:36:16 | [diff] [blame] | 2048 | GetRenderProcessHost()->id(), cert_id, |
| 2049 | cert_status); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2050 | |
| 2051 | NotificationService::current()->Notify( |
| 2052 | NotificationType::LOAD_FROM_MEMORY_CACHE, |
| 2053 | Source<NavigationController>(&controller_), |
| 2054 | Details<LoadFromMemoryCacheDetails>(&details)); |
| 2055 | } |
| 2056 | |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2057 | void TabContents::DidDisplayInsecureContent() { |
[email protected] | f17a0ee | 2010-05-17 17:38:47 | [diff] [blame] | 2058 | displayed_insecure_content_ = true; |
| 2059 | SSLManager::NotifySSLInternalStateChanged(); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | void TabContents::DidRunInsecureContent(const std::string& security_origin) { |
[email protected] | 09843b5f | 2009-09-26 08:30:59 | [diff] [blame] | 2063 | controller_.ssl_manager()->DidRunInsecureContent(security_origin); |
[email protected] | e3d60e5d | 2009-09-25 21:08:29 | [diff] [blame] | 2064 | } |
| 2065 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2066 | void TabContents::DidFailProvisionalLoadWithError( |
| 2067 | RenderViewHost* render_view_host, |
| 2068 | bool is_main_frame, |
| 2069 | int error_code, |
| 2070 | const GURL& url, |
| 2071 | bool showing_repost_interstitial) { |
| 2072 | if (net::ERR_ABORTED == error_code) { |
| 2073 | // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials. |
| 2074 | // This means that the interstitial won't be torn down properly, which is |
| 2075 | // bad. But if we have an interstitial, go back to another tab type, and |
| 2076 | // then load the same interstitial again, we could end up getting the first |
| 2077 | // interstitial's "failed" message (as a result of the cancel) when we're on |
| 2078 | // the second one. |
| 2079 | // |
| 2080 | // We can't tell this apart, so we think we're tearing down the current page |
| 2081 | // which will cause a crash later one. There is also some code in |
| 2082 | // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented |
| 2083 | // out because of this problem. |
| 2084 | // |
| 2085 | // http://code.google.com/p/chromium/issues/detail?id=2855 |
| 2086 | // Because this will not tear down the interstitial properly, if "back" is |
| 2087 | // back to another tab type, the interstitial will still be somewhat alive |
| 2088 | // in the previous tab type. If you navigate somewhere that activates the |
| 2089 | // tab with the interstitial again, you'll see a flash before the new load |
| 2090 | // commits of the interstitial page. |
| 2091 | if (showing_interstitial_page()) { |
| 2092 | LOG(WARNING) << "Discarding message during interstitial."; |
| 2093 | return; |
| 2094 | } |
| 2095 | |
| 2096 | // This will discard our pending entry if we cancelled the load (e.g., if we |
| 2097 | // decided to download the file instead of load it). Only discard the |
| 2098 | // pending entry if the URLs match, otherwise the user initiated a navigate |
| 2099 | // before the page loaded so that the discard would discard the wrong entry. |
| 2100 | NavigationEntry* pending_entry = controller_.pending_entry(); |
| 2101 | if (pending_entry && pending_entry->url() == url) { |
| 2102 | controller_.DiscardNonCommittedEntries(); |
| 2103 | // Update the URL display. |
| 2104 | NotifyNavigationStateChanged(TabContents::INVALIDATE_URL); |
| 2105 | } |
| 2106 | |
| 2107 | render_manager_.RendererAbortedProvisionalLoad(render_view_host); |
| 2108 | } |
| 2109 | |
| 2110 | // Send out a notification that we failed a provisional load with an error. |
| 2111 | ProvisionalLoadDetails details(is_main_frame, |
| 2112 | controller_.IsURLInPageNavigation(url), |
| 2113 | url, std::string(), false); |
| 2114 | details.set_error_code(error_code); |
| 2115 | |
| 2116 | NotificationService::current()->Notify( |
| 2117 | NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR, |
| 2118 | Source<NavigationController>(&controller_), |
| 2119 | Details<ProvisionalLoadDetails>(&details)); |
| 2120 | } |
| 2121 | |
| 2122 | void TabContents::DocumentLoadedInFrame() { |
| 2123 | controller_.DocumentLoadedInFrame(); |
| 2124 | } |
| 2125 | |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 2126 | void TabContents::OnContentSettingsChange() { |
[email protected] | 614c0e1 | 2010-03-25 10:12:56 | [diff] [blame] | 2127 | if (delegate_) |
[email protected] | 20ad6a9 | 2010-04-21 14:07:24 | [diff] [blame] | 2128 | delegate_->OnContentSettingsChange(this); |
[email protected] | 614c0e1 | 2010-03-25 10:12:56 | [diff] [blame] | 2129 | } |
| 2130 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2131 | RenderViewHostDelegate::View* TabContents::GetViewDelegate() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2132 | return view_.get(); |
| 2133 | } |
| 2134 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2135 | RenderViewHostDelegate::RendererManagement* |
| 2136 | TabContents::GetRendererManagementDelegate() { |
| 2137 | return &render_manager_; |
| 2138 | } |
| 2139 | |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2140 | RenderViewHostDelegate::BrowserIntegration* |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2141 | TabContents::GetBrowserIntegrationDelegate() { |
| 2142 | return this; |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2143 | } |
| 2144 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2145 | RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() { |
| 2146 | return this; |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2147 | } |
| 2148 | |
[email protected] | 46ba908 | 2010-06-22 10:00:58 | [diff] [blame] | 2149 | RenderViewHostDelegate::ContentSettings* |
| 2150 | TabContents::GetContentSettingsDelegate() { |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 2151 | return content_settings_delegate_.get(); |
[email protected] | 46ba908 | 2010-06-22 10:00:58 | [diff] [blame] | 2152 | } |
| 2153 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2154 | RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2155 | return save_package_.get(); // May be NULL, but we can return NULL. |
| 2156 | } |
| 2157 | |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2158 | RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() { |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 2159 | return printing_.get(); |
[email protected] | 8d3347f | 2009-07-09 22:00:21 | [diff] [blame] | 2160 | } |
| 2161 | |
| 2162 | RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() { |
| 2163 | return &fav_icon_helper_; |
| 2164 | } |
| 2165 | |
[email protected] | e8dbd674b | 2010-03-11 18:34:40 | [diff] [blame] | 2166 | RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() { |
[email protected] | 6db0def9 | 2010-03-02 19:55:45 | [diff] [blame] | 2167 | if (autocomplete_history_manager_.get() == NULL) |
| 2168 | autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this)); |
| 2169 | return autocomplete_history_manager_.get(); |
[email protected] | bf5c2ff39 | 2009-07-08 16:24:33 | [diff] [blame] | 2170 | } |
| 2171 | |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 2172 | RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() { |
[email protected] | cf28ec5 | 2010-04-09 22:56:34 | [diff] [blame] | 2173 | return GetAutoFillManager(); |
[email protected] | 21674df | 2009-10-28 19:51:21 | [diff] [blame] | 2174 | } |
| 2175 | |
[email protected] | fd571bb | 2010-03-19 01:23:54 | [diff] [blame] | 2176 | AutomationResourceRoutingDelegate* |
| 2177 | TabContents::GetAutomationResourceRoutingDelegate() { |
| 2178 | return delegate(); |
| 2179 | } |
| 2180 | |
[email protected] | ced90ae1 | 2010-02-20 02:06:16 | [diff] [blame] | 2181 | RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() { |
| 2182 | return bookmark_drag_; |
| 2183 | } |
| 2184 | |
| 2185 | void TabContents::SetBookmarkDragDelegate( |
| 2186 | RenderViewHostDelegate::BookmarkDrag* bookmark_drag) { |
| 2187 | bookmark_drag_ = bookmark_drag; |
| 2188 | } |
| 2189 | |
[email protected] | 9fb83e8 | 2010-07-02 18:24:55 | [diff] [blame] | 2190 | TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const { |
| 2191 | return content_settings_delegate_.get(); |
| 2192 | } |
| 2193 | |
[email protected] | 93623c5d | 2009-12-10 21:40:32 | [diff] [blame] | 2194 | RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const { |
[email protected] | 840b151 | 2009-07-21 16:53:46 | [diff] [blame] | 2195 | return renderer_preferences_; |
[email protected] | 80d96fa | 2009-06-10 22:34:51 | [diff] [blame] | 2196 | } |
| 2197 | |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2198 | TabContents* TabContents::GetAsTabContents() { |
| 2199 | return this; |
| 2200 | } |
| 2201 | |
[email protected] | 7b291f9 | 2009-08-14 05:43:53 | [diff] [blame] | 2202 | ViewType::Type TabContents::GetRenderViewType() const { |
| 2203 | return ViewType::TAB_CONTENTS; |
| 2204 | } |
| 2205 | |
| 2206 | int TabContents::GetBrowserWindowID() const { |
| 2207 | return controller().window_id().id(); |
| 2208 | } |
| 2209 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2210 | void TabContents::RenderViewCreated(RenderViewHost* render_view_host) { |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2211 | NotificationService::current()->Notify( |
| 2212 | NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB, |
| 2213 | Source<TabContents>(this), |
| 2214 | Details<RenderViewHost>(render_view_host)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2215 | NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2216 | if (!entry) |
| 2217 | return; |
| 2218 | |
| 2219 | // When we're creating views, we're still doing initial setup, so we always |
| 2220 | // use the pending DOM UI rather than any possibly existing committed one. |
| 2221 | if (render_manager_.pending_dom_ui()) { |
| 2222 | render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host); |
| 2223 | } |
| 2224 | |
| 2225 | if (entry->IsViewSourceMode()) { |
| 2226 | // Put the renderer in view source mode. |
| 2227 | render_view_host->Send( |
| 2228 | new ViewMsg_EnableViewSourceMode(render_view_host->routing_id())); |
| 2229 | } |
[email protected] | 0666aef | 2009-05-13 19:48:08 | [diff] [blame] | 2230 | |
| 2231 | view()->RenderViewCreated(render_view_host); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | void TabContents::RenderViewReady(RenderViewHost* rvh) { |
| 2235 | if (rvh != render_view_host()) { |
| 2236 | // Don't notify the world, since this came from a renderer in the |
| 2237 | // background. |
| 2238 | return; |
| 2239 | } |
| 2240 | |
| 2241 | NotifyConnected(); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2242 | bool was_crashed = is_crashed(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2243 | SetIsCrashed(false); |
[email protected] | 9d8a464 | 2009-07-29 17:25:30 | [diff] [blame] | 2244 | |
| 2245 | // Restore the focus to the tab (otherwise the focus will be on the top |
| 2246 | // window). |
| 2247 | if (was_crashed && !FocusLocationBarByDefault()) |
| 2248 | Focus(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2249 | } |
| 2250 | |
| 2251 | void TabContents::RenderViewGone(RenderViewHost* rvh) { |
| 2252 | // Ask the print preview if this renderer was valuable. |
[email protected] | 1280270 | 2010-07-09 19:43:09 | [diff] [blame] | 2253 | if (!printing_->OnRenderViewGone(rvh)) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2254 | return; |
| 2255 | if (rvh != render_view_host()) { |
| 2256 | // The pending page's RenderViewHost is gone. |
| 2257 | return; |
| 2258 | } |
| 2259 | |
| 2260 | SetIsLoading(false, NULL); |
| 2261 | NotifyDisconnected(); |
| 2262 | SetIsCrashed(true); |
| 2263 | |
[email protected] | ff9efc6 | 2010-02-18 22:10:54 | [diff] [blame] | 2264 | // Remove all infobars. |
[email protected] | e5430c9 | 2010-02-18 22:39:21 | [diff] [blame] | 2265 | for (int i = infobar_delegate_count() - 1; i >=0 ; --i) |
[email protected] | ff9efc6 | 2010-02-18 22:10:54 | [diff] [blame] | 2266 | RemoveInfoBar(GetInfoBarDelegateAt(i)); |
| 2267 | |
[email protected] | 8e53730 | 2009-06-10 21:19:58 | [diff] [blame] | 2268 | // 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] | 2269 | // Only do this if we're not in browser shutdown, so that TabContents |
| 2270 | // objects that are not in a browser (e.g., HTML dialogs) and thus are |
| 2271 | // visible do not flash a sad tab page. |
| 2272 | if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID) |
| 2273 | view_->OnTabCrashed(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2274 | |
| 2275 | // Hide any visible hung renderer warning for this web contents' process. |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2276 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2277 | } |
| 2278 | |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2279 | void TabContents::RenderViewDeleted(RenderViewHost* rvh) { |
| 2280 | NotificationService::current()->Notify( |
| 2281 | NotificationType::RENDER_VIEW_HOST_DELETED, |
| 2282 | Source<TabContents>(this), |
| 2283 | Details<RenderViewHost>(rvh)); |
[email protected] | fb7b79f7 | 2009-11-06 18:00:48 | [diff] [blame] | 2284 | render_manager_.RenderViewDeleted(rvh); |
[email protected] | 2e4633c | 2009-07-09 16:58:06 | [diff] [blame] | 2285 | } |
| 2286 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2287 | void TabContents::DidNavigate(RenderViewHost* rvh, |
| 2288 | const ViewHostMsg_FrameNavigate_Params& params) { |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2289 | int extra_invalidate_flags = 0; |
| 2290 | |
| 2291 | if (PageTransition::IsMainFrame(params.transition)) { |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 2292 | bool was_bookmark_bar_visible = ShouldShowBookmarkBar(); |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2293 | bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible(); |
| 2294 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2295 | render_manager_.DidNavigateMainFrame(rvh); |
| 2296 | |
[email protected] | 20ede07 | 2009-10-06 00:28:35 | [diff] [blame] | 2297 | if (was_bookmark_bar_visible != ShouldShowBookmarkBar()) |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2298 | extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR; |
| 2299 | if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible()) |
| 2300 | extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF; |
| 2301 | } |
| 2302 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2303 | // Update the site of the SiteInstance if it doesn't have one yet. |
| 2304 | if (!GetSiteInstance()->has_site()) |
| 2305 | GetSiteInstance()->SetSite(params.url); |
| 2306 | |
| 2307 | // Need to update MIME type here because it's referred to in |
| 2308 | // UpdateNavigationCommands() called by RendererDidNavigate() to |
| 2309 | // determine whether or not to enable the encoding menu. |
| 2310 | // It's updated only for the main frame. For a subframe, |
| 2311 | // RenderView::UpdateURL does not set params.contents_mime_type. |
| 2312 | // (see http://code.google.com/p/chromium/issues/detail?id=2929 ) |
| 2313 | // TODO(jungshik): Add a test for the encoding menu to avoid |
| 2314 | // regressing it again. |
| 2315 | if (PageTransition::IsMainFrame(params.transition)) |
| 2316 | contents_mime_type_ = params.contents_mime_type; |
| 2317 | |
| 2318 | NavigationController::LoadCommittedDetails details; |
[email protected] | 8030f01 | 2009-09-25 18:09:37 | [diff] [blame] | 2319 | bool did_navigate = controller_.RendererDidNavigate( |
| 2320 | params, extra_invalidate_flags, &details); |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2321 | |
| 2322 | // Update history. Note that this needs to happen after the entry is complete, |
| 2323 | // which WillNavigate[Main,Sub]Frame will do before this function is called. |
[email protected] | 2e29d92 | 2009-10-22 22:13:35 | [diff] [blame] | 2324 | if (params.should_update_history && |
| 2325 | (!delegate() || delegate()->ShouldAddNavigationsToHistory())) { |
[email protected] | 3e90d4a | 2009-07-03 17:38:39 | [diff] [blame] | 2326 | // Most of the time, the displayURL matches the loaded URL, but for about: |
| 2327 | // URLs, we use a data: URL as the real value. We actually want to save |
| 2328 | // the about: URL to the history db and keep the data: URL hidden. This is |
| 2329 | // what the TabContents' URL getter does. |
| 2330 | UpdateHistoryForNavigation(GetURL(), details, params); |
| 2331 | } |
| 2332 | |
[email protected] | 76543b9 | 2009-08-31 17:27:45 | [diff] [blame] | 2333 | if (!did_navigate) |
| 2334 | return; // No navigation happened. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2335 | |
| 2336 | // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen |
| 2337 | // for the appropriate notification (best) or you can add it to |
| 2338 | // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if |
| 2339 | // necessary, please). |
| 2340 | |
| 2341 | // Run post-commit tasks. |
| 2342 | if (details.is_main_frame) |
| 2343 | DidNavigateMainFramePostCommit(details, params); |
| 2344 | DidNavigateAnyFramePostCommit(rvh, details, params); |
| 2345 | } |
| 2346 | |
| 2347 | void TabContents::UpdateState(RenderViewHost* rvh, |
| 2348 | int32 page_id, |
| 2349 | const std::string& state) { |
| 2350 | DCHECK(rvh == render_view_host()); |
| 2351 | |
| 2352 | // We must be prepared to handle state updates for any page, these occur |
| 2353 | // when the user is scrolling and entering form data, as well as when we're |
| 2354 | // leaving a page, in which case our state may have already been moved to |
| 2355 | // the next page. The navigation controller will look up the appropriate |
| 2356 | // NavigationEntry and update it when it is notified via the delegate. |
| 2357 | |
| 2358 | int entry_index = controller_.GetEntryIndexWithPageID( |
| 2359 | GetSiteInstance(), page_id); |
| 2360 | if (entry_index < 0) |
| 2361 | return; |
| 2362 | NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index); |
| 2363 | |
| 2364 | if (state == entry->content_state()) |
| 2365 | return; // Nothing to update. |
| 2366 | entry->set_content_state(state); |
| 2367 | controller_.NotifyEntryChanged(entry, entry_index); |
| 2368 | } |
| 2369 | |
| 2370 | void TabContents::UpdateTitle(RenderViewHost* rvh, |
| 2371 | int32 page_id, const std::wstring& title) { |
| 2372 | // If we have a title, that's a pretty good indication that we've started |
| 2373 | // getting useful data. |
| 2374 | SetNotWaitingForResponse(); |
| 2375 | |
| 2376 | DCHECK(rvh == render_view_host()); |
| 2377 | NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(), |
| 2378 | page_id); |
| 2379 | if (!entry || !UpdateTitleForEntry(entry, title)) |
| 2380 | return; |
| 2381 | |
| 2382 | // Broadcast notifications when the UI should be updated. |
| 2383 | if (entry == controller_.GetEntryAtOffset(0)) |
[email protected] | f1cd5e8 | 2009-10-23 17:19:03 | [diff] [blame] | 2384 | NotifyNavigationStateChanged(INVALIDATE_TITLE); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2385 | } |
| 2386 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2387 | void TabContents::UpdateEncoding(RenderViewHost* render_view_host, |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 2388 | const std::string& encoding) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2389 | set_encoding(encoding); |
| 2390 | } |
| 2391 | |
| 2392 | void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { |
| 2393 | if (delegate()) |
| 2394 | delegate()->UpdateTargetURL(this, url); |
| 2395 | } |
| 2396 | |
| 2397 | void TabContents::UpdateThumbnail(const GURL& url, |
| 2398 | const SkBitmap& bitmap, |
| 2399 | const ThumbnailScore& score) { |
| 2400 | // Tell History about this thumbnail |
[email protected] | 523623c | 2010-05-19 16:03:42 | [diff] [blame] | 2401 | if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) { |
[email protected] | 72d0fc7 | 2009-07-09 17:30:49 | [diff] [blame] | 2402 | if (!profile()->IsOffTheRecord()) |
[email protected] | 523623c | 2010-05-19 16:03:42 | [diff] [blame] | 2403 | profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score); |
[email protected] | 44947830 | 2009-06-09 20:04:28 | [diff] [blame] | 2404 | } else { |
| 2405 | HistoryService* hs; |
| 2406 | if (!profile()->IsOffTheRecord() && |
| 2407 | (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) { |
| 2408 | hs->SetPageThumbnail(url, bitmap, score); |
| 2409 | } |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2410 | } |
| 2411 | } |
| 2412 | |
[email protected] | c4e9890 | 2010-06-01 10:20:14 | [diff] [blame] | 2413 | void TabContents::UpdateInspectorSetting(const std::string& key, |
| 2414 | const std::string& value) { |
| 2415 | DictionaryValue* inspector_settings = |
| 2416 | profile()->GetPrefs()->GetMutableDictionary( |
| 2417 | prefs::kWebKitInspectorSettings); |
[email protected] | 628cf5a5 | 2010-06-07 14:25:33 | [diff] [blame] | 2418 | inspector_settings->SetWithoutPathExpansion(UTF8ToWide(key), |
| 2419 | Value::CreateStringValue(value)); |
[email protected] | 0df3012 | 2009-06-03 12:13:08 | [diff] [blame] | 2420 | } |
| 2421 | |
[email protected] | 45aafc9 | 2010-06-07 14:18:53 | [diff] [blame] | 2422 | void TabContents::ClearInspectorSettings() { |
| 2423 | DictionaryValue* inspector_settings = |
| 2424 | profile()->GetPrefs()->GetMutableDictionary( |
| 2425 | prefs::kWebKitInspectorSettings); |
| 2426 | inspector_settings->Clear(); |
| 2427 | } |
| 2428 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2429 | void TabContents::Close(RenderViewHost* rvh) { |
[email protected] | 0770730 | 2009-11-06 00:50:29 | [diff] [blame] | 2430 | // The UI may be in an event-tracking loop, such as between the |
| 2431 | // mouse-down and mouse-up in text selection or a button click. |
| 2432 | // Defer the close until after tracking is complete, so that we |
| 2433 | // don't free objects out from under the UI. |
| 2434 | // TODO(shess): This could probably be integrated with the |
| 2435 | // IsDoingDrag() test below. Punting for now because I need more |
| 2436 | // research to understand how this impacts platforms other than Mac. |
| 2437 | // TODO(shess): This could get more fine-grained. For instance, |
| 2438 | // closing a tab in another window while selecting text in the |
| 2439 | // current window's Omnibox should be just fine. |
| 2440 | if (view()->IsEventTracking()) { |
| 2441 | view()->CloseTabAfterEventTracking(); |
| 2442 | return; |
| 2443 | } |
| 2444 | |
[email protected] | 24a4d106 | 2009-07-10 23:10:42 | [diff] [blame] | 2445 | // If we close the tab while we're in the middle of a drag, we'll crash. |
| 2446 | // Instead, cancel the drag and close it as soon as the drag ends. |
| 2447 | if (view()->IsDoingDrag()) { |
| 2448 | view()->CancelDragAndCloseTab(); |
| 2449 | return; |
| 2450 | } |
| 2451 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2452 | // Ignore this if it comes from a RenderViewHost that we aren't showing. |
| 2453 | if (delegate() && rvh == render_view_host()) |
| 2454 | delegate()->CloseContents(this); |
| 2455 | } |
| 2456 | |
| 2457 | void TabContents::RequestMove(const gfx::Rect& new_bounds) { |
| 2458 | if (delegate() && delegate()->IsPopup(this)) |
| 2459 | delegate()->MoveContents(this, new_bounds); |
| 2460 | } |
| 2461 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2462 | void TabContents::DidStartLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2463 | SetIsLoading(true, NULL); |
| 2464 | } |
| 2465 | |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2466 | void TabContents::DidStopLoading() { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2467 | scoped_ptr<LoadNotificationDetails> details; |
| 2468 | |
| 2469 | NavigationEntry* entry = controller_.GetActiveEntry(); |
| 2470 | // An entry may not exist for a stop when loading an initial blank page or |
| 2471 | // if an iframe injected by script into a blank page finishes loading. |
| 2472 | if (entry) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2473 | base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_; |
| 2474 | |
| 2475 | details.reset(new LoadNotificationDetails( |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 2476 | entry->virtual_url(), |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2477 | entry->transition_type(), |
| 2478 | elapsed, |
| 2479 | &controller_, |
| 2480 | controller_.GetCurrentEntryIndex())); |
| 2481 | } |
| 2482 | |
| 2483 | // Tell PasswordManager we've finished a page load, which serves as a |
| 2484 | // green light to save pending passwords and reset itself. |
| 2485 | GetPasswordManager()->DidStopLoading(); |
| 2486 | |
| 2487 | SetIsLoading(false, details.get()); |
| 2488 | } |
| 2489 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2490 | void TabContents::DidRedirectProvisionalLoad(int32 page_id, |
| 2491 | const GURL& source_url, |
| 2492 | const GURL& target_url) { |
| 2493 | NavigationEntry* entry; |
| 2494 | if (page_id == -1) |
| 2495 | entry = controller_.pending_entry(); |
| 2496 | else |
| 2497 | entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id); |
| 2498 | if (!entry || entry->url() != source_url) |
| 2499 | return; |
| 2500 | entry->set_url(target_url); |
| 2501 | } |
| 2502 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2503 | void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer, |
| 2504 | WindowOpenDisposition disposition) { |
| 2505 | if (render_manager_.dom_ui()) { |
| 2506 | // When we're a DOM UI, it will provide a page transition type for us (this |
| 2507 | // is so the new tab page can specify AUTO_BOOKMARK for automatically |
| 2508 | // generated suggestions). |
| 2509 | // |
| 2510 | // Note also that we hide the referrer for DOM UI pages. We don't really |
[email protected] | 60e44898 | 2009-05-06 04:21:16 | [diff] [blame] | 2511 | // want web sites to see a referrer of "chrome://blah" (and some |
| 2512 | // 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] | 2513 | // send to the site), so we send no referrer. |
| 2514 | OpenURL(url, GURL(), disposition, |
| 2515 | render_manager_.dom_ui()->link_transition_type()); |
| 2516 | } else { |
| 2517 | OpenURL(url, referrer, disposition, PageTransition::LINK); |
| 2518 | } |
| 2519 | } |
| 2520 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2521 | void TabContents::DomOperationResponse(const std::string& json_string, |
| 2522 | int automation_id) { |
| 2523 | } |
| 2524 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2525 | void TabContents::ProcessDOMUIMessage(const std::string& message, |
[email protected] | 438c97d | 2010-05-21 23:30:15 | [diff] [blame] | 2526 | const ListValue* content, |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 2527 | const GURL& source_url, |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 2528 | int request_id, |
| 2529 | bool has_callback) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2530 | if (!render_manager_.dom_ui()) { |
[email protected] | c2e74fe8 | 2009-09-03 17:57:44 | [diff] [blame] | 2531 | // This can happen if someone uses window.open() to open an extension URL |
| 2532 | // from a non-extension context. |
| 2533 | render_view_host()->BlockExtensionRequest(request_id); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2534 | return; |
| 2535 | } |
[email protected] | bb64b51 | 2010-04-02 21:01:39 | [diff] [blame] | 2536 | render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url, |
| 2537 | request_id, |
[email protected] | 811bfe3 | 2009-07-01 08:46:25 | [diff] [blame] | 2538 | has_callback); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2539 | } |
| 2540 | |
| 2541 | void TabContents::ProcessExternalHostMessage(const std::string& message, |
| 2542 | const std::string& origin, |
| 2543 | const std::string& target) { |
| 2544 | if (delegate()) |
| 2545 | delegate()->ForwardMessageToExternalHost(message, origin, target); |
| 2546 | } |
| 2547 | |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2548 | void TabContents::RunFileChooser( |
| 2549 | const ViewHostMsg_RunFileChooser_Params ¶ms) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2550 | if (!select_file_dialog_.get()) |
| 2551 | select_file_dialog_ = SelectFileDialog::Create(this); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2552 | |
| 2553 | SelectFileDialog::Type dialog_type; |
| 2554 | switch (params.mode) { |
| 2555 | case ViewHostMsg_RunFileChooser_Params::Open: |
| 2556 | dialog_type = SelectFileDialog::SELECT_OPEN_FILE; |
| 2557 | break; |
| 2558 | case ViewHostMsg_RunFileChooser_Params::OpenMultiple: |
| 2559 | dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE; |
| 2560 | break; |
| 2561 | case ViewHostMsg_RunFileChooser_Params::Save: |
| 2562 | dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE; |
| 2563 | break; |
| 2564 | default: |
[email protected] | bed3195 | 2010-03-30 20:07:59 | [diff] [blame] | 2565 | dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2566 | NOTREACHED(); |
| 2567 | } |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2568 | FilePath default_file_name = params.default_file_name; |
| 2569 | if (default_file_name.empty()) |
| 2570 | default_file_name = profile()->last_selected_directory(); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2571 | select_file_dialog_->SelectFile(dialog_type, params.title, |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2572 | default_file_name, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2573 | NULL, 0, FILE_PATH_LITERAL(""), |
| 2574 | view_->GetTopLevelNativeWindow(), NULL); |
| 2575 | } |
| 2576 | |
| 2577 | void TabContents::RunJavaScriptMessage( |
| 2578 | const std::wstring& message, |
| 2579 | const std::wstring& default_prompt, |
| 2580 | const GURL& frame_url, |
| 2581 | const int flags, |
| 2582 | IPC::Message* reply_msg, |
| 2583 | bool* did_suppress_message) { |
| 2584 | // Suppress javascript messages when requested and when inside a constrained |
| 2585 | // popup window (because that activates them and breaks them out of the |
| 2586 | // constrained window jail). |
[email protected] | 91ed49a | 2009-07-07 21:29:55 | [diff] [blame] | 2587 | // Also suppress messages when showing an interstitial. The interstitial is |
| 2588 | // shown over the previous page, we don't want the hidden page dialogs to |
| 2589 | // interfere with the interstitial. |
| 2590 | bool suppress_this_message = suppress_javascript_messages_ || |
| 2591 | showing_interstitial_page(); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2592 | if (delegate()) |
| 2593 | suppress_this_message |= |
[email protected] | b6c87458 | 2009-05-08 19:38:31 | [diff] [blame] | 2594 | (delegate()->GetConstrainingContents(this) != this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2595 | |
| 2596 | *did_suppress_message = suppress_this_message; |
| 2597 | |
| 2598 | if (!suppress_this_message) { |
| 2599 | base::TimeDelta time_since_last_message( |
| 2600 | base::TimeTicks::Now() - last_javascript_message_dismissal_); |
| 2601 | bool show_suppress_checkbox = false; |
| 2602 | // Show a checkbox offering to suppress further messages if this message is |
| 2603 | // being displayed within kJavascriptMessageExpectedDelay of the last one. |
| 2604 | if (time_since_last_message < |
| 2605 | base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay)) |
| 2606 | show_suppress_checkbox = true; |
| 2607 | |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2608 | RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2609 | show_suppress_checkbox, reply_msg); |
| 2610 | } else { |
| 2611 | // If we are suppressing messages, just reply as is if the user immediately |
| 2612 | // pressed "Cancel". |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 2613 | OnMessageBoxClosed(reply_msg, false, std::wstring()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2614 | } |
| 2615 | } |
| 2616 | |
| 2617 | void TabContents::RunBeforeUnloadConfirm(const std::wstring& message, |
| 2618 | IPC::Message* reply_msg) { |
[email protected] | 7ab1e7d6 | 2009-10-14 23:32:01 | [diff] [blame] | 2619 | is_showing_before_unload_dialog_ = true; |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2620 | RunBeforeUnloadDialog(this, message, reply_msg); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2621 | } |
| 2622 | |
| 2623 | void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height, |
| 2624 | const std::string& json_arguments, |
| 2625 | IPC::Message* reply_msg) { |
| 2626 | if (delegate()) { |
| 2627 | HtmlDialogUIDelegate* dialog_delegate = |
| 2628 | new ModalHtmlDialogDelegate(url, width, height, json_arguments, |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2629 | reply_msg, this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2630 | delegate()->ShowHtmlDialog(dialog_delegate, NULL); |
| 2631 | } |
| 2632 | } |
| 2633 | |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2634 | void TabContents::PasswordFormsFound( |
[email protected] | ed3fb03 | 2009-06-16 19:50:56 | [diff] [blame] | 2635 | const std::vector<webkit_glue::PasswordForm>& forms) { |
[email protected] | 4d44a1c | 2010-04-28 19:20:41 | [diff] [blame] | 2636 | GetPasswordManager()->PasswordFormsFound(forms); |
| 2637 | } |
| 2638 | |
| 2639 | void TabContents::PasswordFormsVisible( |
| 2640 | const std::vector<webkit_glue::PasswordForm>& visible_forms) { |
| 2641 | GetPasswordManager()->PasswordFormsVisible(visible_forms); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2642 | } |
| 2643 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2644 | // Checks to see if we should generate a keyword based on the OSDD, and if |
| 2645 | // necessary uses TemplateURLFetcher to download the OSDD and create a keyword. |
| 2646 | void TabContents::PageHasOSDD(RenderViewHost* render_view_host, |
| 2647 | int32 page_id, const GURL& url, |
| 2648 | bool autodetected) { |
| 2649 | // Make sure page_id is the current page, and the TemplateURLModel is loaded. |
| 2650 | DCHECK(url.is_valid()); |
| 2651 | if (!IsActiveEntry(page_id)) |
| 2652 | return; |
| 2653 | TemplateURLModel* url_model = profile()->GetTemplateURLModel(); |
| 2654 | if (!url_model) |
| 2655 | return; |
| 2656 | if (!url_model->loaded()) { |
| 2657 | url_model->Load(); |
| 2658 | return; |
| 2659 | } |
| 2660 | if (!profile()->GetTemplateURLFetcher()) |
| 2661 | return; |
| 2662 | |
| 2663 | if (profile()->IsOffTheRecord()) |
| 2664 | return; |
| 2665 | |
| 2666 | const NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 2667 | DCHECK(entry); |
| 2668 | |
| 2669 | const NavigationEntry* base_entry = entry; |
| 2670 | if (IsFormSubmit(base_entry)) { |
| 2671 | // If the current page is a form submit, find the last page that was not |
| 2672 | // a form submit and use its url to generate the keyword from. |
| 2673 | int index = controller_.last_committed_entry_index() - 1; |
| 2674 | while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index))) |
| 2675 | index--; |
| 2676 | if (index >= 0) |
| 2677 | base_entry = controller_.GetEntryAtIndex(index); |
| 2678 | else |
| 2679 | base_entry = NULL; |
| 2680 | } |
| 2681 | |
| 2682 | // We want to use the user typed URL if available since that represents what |
| 2683 | // the user typed to get here, and fall back on the regular URL if not. |
| 2684 | if (!base_entry) |
| 2685 | return; |
| 2686 | GURL keyword_url = base_entry->user_typed_url().is_valid() ? |
| 2687 | base_entry->user_typed_url() : base_entry->url(); |
| 2688 | if (!keyword_url.is_valid()) |
| 2689 | return; |
| 2690 | std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url, |
| 2691 | autodetected); |
[email protected] | a88dbdd5 | 2010-01-15 19:25:53 | [diff] [blame] | 2692 | |
| 2693 | // For JS added OSDD empty keyword is OK because we will generate keyword |
| 2694 | // later from OSDD content. |
| 2695 | if (autodetected && keyword.empty()) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2696 | return; |
| 2697 | const TemplateURL* template_url = |
| 2698 | url_model->GetTemplateURLForKeyword(keyword); |
| 2699 | if (template_url && (!template_url->safe_for_autoreplace() || |
| 2700 | template_url->originating_url() == url)) { |
| 2701 | // Either there is a user created TemplateURL for this keyword, or the |
| 2702 | // keyword has the same OSDD url and we've parsed it. |
| 2703 | return; |
| 2704 | } |
| 2705 | |
| 2706 | // Download the OpenSearch description document. If this is successful a |
| 2707 | // new keyword will be created when done. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2708 | profile()->GetTemplateURLFetcher()->ScheduleDownload( |
| 2709 | keyword, |
| 2710 | url, |
| 2711 | base_entry->favicon().url(), |
[email protected] | d0cc9fb5 | 2009-06-23 02:26:16 | [diff] [blame] | 2712 | this, |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2713 | autodetected); |
| 2714 | } |
| 2715 | |
[email protected] | 155f35e | 2010-07-17 00:30:18 | [diff] [blame^] | 2716 | // Indicates if the two inputs have the same security origin. |
| 2717 | // |requested_origin| should only be a security origin (no path, etc.). |
| 2718 | // It is ok if |template_url| is NULL. |
| 2719 | static bool IsSameOrigin(const GURL& requested_origin, |
| 2720 | const TemplateURL* template_url) { |
| 2721 | DCHECK(requested_origin == requested_origin.GetOrigin()); |
| 2722 | return template_url && requested_origin == |
| 2723 | TemplateURLModel::GenerateSearchURL(template_url).GetOrigin(); |
| 2724 | } |
| 2725 | |
| 2726 | ViewHostMsg_GetSearchProviderInstallState_Params |
| 2727 | TabContents::GetSearchProviderInstallState(const GURL& requested_host) { |
| 2728 | // Get the last committed entry since that is the page executing the |
| 2729 | // javascript as opposed to a page being navigated to. We don't want |
| 2730 | // to trust the page to tell us the url to avoid using potentially |
| 2731 | // compromised information. |
| 2732 | NavigationEntry* entry = controller_.GetLastCommittedEntry(); |
| 2733 | GURL page_origin = entry ? entry->virtual_url().GetOrigin() : GURL(); |
| 2734 | GURL requested_origin = requested_host.GetOrigin(); |
| 2735 | // Do the security check before any others to avoid information leaks. |
| 2736 | if (page_origin != requested_origin) |
| 2737 | return ViewHostMsg_GetSearchProviderInstallState_Params::Denied(); |
| 2738 | |
| 2739 | // In incognito mode, no search information is exposed. (This check must be |
| 2740 | // done after the security check or else a web site can detect that the |
| 2741 | // user is in incognito mode just by doing a cross origin request.) |
| 2742 | if (profile()->IsOffTheRecord()) |
| 2743 | return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled(); |
| 2744 | |
| 2745 | TemplateURLModel* url_model = profile()->GetTemplateURLModel(); |
| 2746 | if (!url_model) |
| 2747 | return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled(); |
| 2748 | if (!url_model->loaded()) |
| 2749 | url_model->Load(); |
| 2750 | |
| 2751 | // First check to see if the url is the default search provider. |
| 2752 | if (IsSameOrigin(requested_origin, url_model->GetDefaultSearchProvider())) { |
| 2753 | return ViewHostMsg_GetSearchProviderInstallState_Params:: |
| 2754 | InstalledAsDefault(); |
| 2755 | } |
| 2756 | |
| 2757 | // Is the url any search provider? |
| 2758 | std::vector<const TemplateURL*> urls = url_model->GetTemplateURLs(); |
| 2759 | for (std::vector<const TemplateURL*>::iterator i = urls.begin(); |
| 2760 | i != urls.end(); ++i) { |
| 2761 | const TemplateURL* template_url = (*i); |
| 2762 | if (IsSameOrigin(requested_origin, template_url)) { |
| 2763 | return ViewHostMsg_GetSearchProviderInstallState_Params:: |
| 2764 | InstallButNotDefault(); |
| 2765 | } |
| 2766 | } |
| 2767 | return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled(); |
| 2768 | } |
| 2769 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2770 | GURL TabContents::GetAlternateErrorPageURL() const { |
| 2771 | GURL url; |
| 2772 | // Disable alternate error pages when in OffTheRecord/Incognito mode. |
| 2773 | if (profile()->IsOffTheRecord()) |
| 2774 | return url; |
| 2775 | |
| 2776 | PrefService* prefs = profile()->GetPrefs(); |
| 2777 | DCHECK(prefs); |
| 2778 | if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
[email protected] | a33457b8 | 2009-09-21 23:07:15 | [diff] [blame] | 2779 | url = google_util::AppendGoogleLocaleParam( |
| 2780 | GURL(google_util::kLinkDoctorBaseURL)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2781 | url = google_util::AppendGoogleTLDParam(url); |
| 2782 | } |
| 2783 | return url; |
| 2784 | } |
| 2785 | |
| 2786 | WebPreferences TabContents::GetWebkitPrefs() { |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 2787 | Profile* profile = render_view_host()->process()->profile(); |
[email protected] | 7ccddb8c | 2009-08-04 17:36:55 | [diff] [blame] | 2788 | bool is_dom_ui = false; |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 2789 | return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2790 | } |
| 2791 | |
[email protected] | fa1cf0b8 | 2010-01-15 21:49:44 | [diff] [blame] | 2792 | void TabContents::OnIgnoredUIEvent() { |
| 2793 | if (constrained_window_count()) { |
| 2794 | ConstrainedWindow* window = *constrained_window_begin(); |
| 2795 | window->FocusConstrainedWindow(); |
| 2796 | } |
| 2797 | } |
| 2798 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2799 | void TabContents::OnJSOutOfMemory() { |
| 2800 | AddInfoBar(new SimpleAlertInfoBarDelegate( |
[email protected] | 938e1f9 | 2010-04-01 18:09:42 | [diff] [blame] | 2801 | this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true)); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2802 | } |
| 2803 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2804 | void TabContents::OnCrossSiteResponse(int new_render_process_host_id, |
| 2805 | int new_request_id) { |
[email protected] | 57c6a65 | 2009-05-04 07:58:34 | [diff] [blame] | 2806 | // 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] | 2807 | // delivered to a pending RenderViewHost. We must first run the onunload |
| 2808 | // handler of the old RenderViewHost before we can allow it to proceed. |
| 2809 | render_manager_.OnCrossSiteResponse(new_render_process_host_id, |
| 2810 | new_request_id); |
| 2811 | } |
| 2812 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2813 | gfx::Rect TabContents::GetRootWindowResizerRect() const { |
| 2814 | if (delegate()) |
| 2815 | return delegate()->GetRootWindowResizerRect(); |
| 2816 | return gfx::Rect(); |
| 2817 | } |
| 2818 | |
| 2819 | void TabContents::RendererUnresponsive(RenderViewHost* rvh, |
| 2820 | bool is_during_unload) { |
| 2821 | if (is_during_unload) { |
| 2822 | // Hang occurred while firing the beforeunload/unload handler. |
| 2823 | // Pretend the handler fired so tab closing continues as if it had. |
[email protected] | 829e761 | 2009-04-25 01:15:11 | [diff] [blame] | 2824 | rvh->set_sudden_termination_allowed(true); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2825 | |
| 2826 | if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer()) |
| 2827 | return; |
| 2828 | |
| 2829 | // If the tab hangs in the beforeunload/unload handler there's really |
| 2830 | // nothing we can do to recover. Pretend the unload listeners have |
| 2831 | // all fired and close the tab. If the hang is in the beforeunload handler |
| 2832 | // then the user will not have the option of cancelling the close. |
| 2833 | Close(rvh); |
| 2834 | return; |
| 2835 | } |
| 2836 | |
| 2837 | if (render_view_host() && render_view_host()->IsRenderViewLive()) |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2838 | hung_renderer_dialog::ShowForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2839 | } |
| 2840 | |
| 2841 | void TabContents::RendererResponsive(RenderViewHost* render_view_host) { |
[email protected] | e7b8d83 | 2009-11-20 22:41:00 | [diff] [blame] | 2842 | hung_renderer_dialog::HideForTabContents(this); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2843 | } |
| 2844 | |
| 2845 | void TabContents::LoadStateChanged(const GURL& url, |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2846 | net::LoadState load_state, |
| 2847 | uint64 upload_position, |
| 2848 | uint64 upload_size) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2849 | load_state_ = load_state; |
[email protected] | 094e5b2 | 2009-09-25 04:23:56 | [diff] [blame] | 2850 | upload_position_ = upload_position; |
| 2851 | upload_size_ = upload_size; |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 2852 | std::wstring languages = |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 2853 | UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)); |
[email protected] | d686e81 | 2009-06-03 19:10:29 | [diff] [blame] | 2854 | std::string host = url.host(); |
[email protected] | ce85f60 | 2009-11-07 01:34:53 | [diff] [blame] | 2855 | load_state_host_ = |
| 2856 | net::IDNToUnicode(host.c_str(), host.size(), languages, NULL); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2857 | if (load_state_ == net::LOAD_STATE_READING_RESPONSE) |
| 2858 | SetNotWaitingForResponse(); |
| 2859 | if (is_loading()) |
[email protected] | c9cd222 | 2009-05-06 05:16:50 | [diff] [blame] | 2860 | NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2861 | } |
| 2862 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2863 | bool TabContents::IsExternalTabContainer() const { |
| 2864 | if (!delegate()) |
| 2865 | return false; |
| 2866 | |
| 2867 | return delegate()->IsExternalTabContainer(); |
| 2868 | } |
| 2869 | |
[email protected] | 1ee61486 | 2009-07-06 20:29:18 | [diff] [blame] | 2870 | void TabContents::DidInsertCSS() { |
| 2871 | // This RVHDelegate function is used for extensions and not us. |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2872 | } |
| 2873 | |
[email protected] | 130efb0 | 2009-09-18 18:54:35 | [diff] [blame] | 2874 | void TabContents::FocusedNodeChanged() { |
| 2875 | NotificationService::current()->Notify( |
| 2876 | NotificationType::FOCUS_CHANGED_IN_PAGE, |
| 2877 | Source<RenderViewHost>(render_view_host()), |
| 2878 | NotificationService::NoDetails()); |
| 2879 | } |
| 2880 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2881 | void TabContents::FileSelected(const FilePath& path, |
| 2882 | int index, void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2883 | profile()->set_last_selected_directory(path.DirName()); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2884 | std::vector<FilePath> files; |
| 2885 | files.push_back(path); |
| 2886 | render_view_host()->FilesSelectedInChooser(files); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2887 | } |
| 2888 | |
| 2889 | void TabContents::MultiFilesSelected(const std::vector<FilePath>& files, |
| 2890 | void* params) { |
[email protected] | 35896a3 | 2010-06-09 08:42:51 | [diff] [blame] | 2891 | if (!files.empty()) |
| 2892 | profile()->set_last_selected_directory(files[0].DirName()); |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2893 | render_view_host()->FilesSelectedInChooser(files); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2894 | } |
| 2895 | |
| 2896 | void TabContents::FileSelectionCanceled(void* params) { |
| 2897 | // If the user cancels choosing a file to upload we pass back an |
| 2898 | // empty vector. |
[email protected] | cdaf8d0 | 2010-03-30 19:52:47 | [diff] [blame] | 2899 | render_view_host()->FilesSelectedInChooser(std::vector<FilePath>()); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2900 | } |
| 2901 | |
| 2902 | void TabContents::BeforeUnloadFiredFromRenderManager( |
| 2903 | bool proceed, |
| 2904 | bool* proceed_to_fire_unload) { |
| 2905 | if (delegate()) |
| 2906 | delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload); |
| 2907 | } |
| 2908 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2909 | void TabContents::DidStartLoadingFromRenderManager( |
| 2910 | RenderViewHost* render_view_host) { |
| 2911 | DidStartLoading(); |
| 2912 | } |
| 2913 | |
| 2914 | void TabContents::RenderViewGoneFromRenderManager( |
| 2915 | RenderViewHost* render_view_host) { |
| 2916 | RenderViewGone(render_view_host); |
| 2917 | } |
| 2918 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2919 | void TabContents::UpdateRenderViewSizeForRenderManager() { |
| 2920 | // TODO(brettw) this is a hack. See TabContentsView::SizeContents. |
[email protected] | 0323ee4 | 2010-02-17 22:03:26 | [diff] [blame] | 2921 | gfx::Size size = view_->GetContainerSize(); |
| 2922 | // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be |
| 2923 | // here during container initialization and normal window size will be set |
| 2924 | // later. In case of tab duplication this resizing to 0x0 prevents setting |
| 2925 | // normal size later so just ignore it. |
| 2926 | if (!size.IsEmpty()) |
| 2927 | view_->SizeContents(size); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2928 | } |
| 2929 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 2930 | void TabContents::NotifySwappedFromRenderManager() { |
| 2931 | NotifySwapped(); |
| 2932 | } |
| 2933 | |
| 2934 | NavigationController& TabContents::GetControllerForRenderManager() { |
| 2935 | return controller(); |
| 2936 | } |
| 2937 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2938 | DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) { |
[email protected] | d82ed61e | 2009-06-16 02:46:22 | [diff] [blame] | 2939 | return DOMUIFactory::CreateDOMUIForURL(this, url); |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2940 | } |
| 2941 | |
| 2942 | NavigationEntry* |
| 2943 | TabContents::GetLastCommittedNavigationEntryForRenderManager() { |
| 2944 | return controller_.GetLastCommittedEntry(); |
| 2945 | } |
| 2946 | |
| 2947 | bool TabContents::CreateRenderViewForRenderManager( |
| 2948 | RenderViewHost* render_view_host) { |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2949 | RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host); |
[email protected] | 1a98a93 | 2009-11-17 00:12:52 | [diff] [blame] | 2950 | |
| 2951 | scoped_refptr<URLRequestContextGetter> request_context = request_context_; |
| 2952 | if (!request_context.get()) |
| 2953 | request_context = profile()->GetRequestContext(); |
| 2954 | |
[email protected] | 8ab0465 | 2010-06-12 02:47:26 | [diff] [blame] | 2955 | if (!render_view_host->CreateRenderView(request_context, string16())) |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 2956 | return false; |
| 2957 | |
| 2958 | // Now that the RenderView has been created, we need to tell it its size. |
| 2959 | rwh_view->SetSize(view_->GetContainerSize()); |
| 2960 | |
| 2961 | UpdateMaxPageIDIfNecessary(render_view_host->site_instance(), |
| 2962 | render_view_host); |
| 2963 | return true; |
| 2964 | } |
| 2965 | |
| 2966 | void TabContents::Observe(NotificationType type, |
| 2967 | const NotificationSource& source, |
| 2968 | const NotificationDetails& details) { |
| 2969 | switch (type.value) { |
| 2970 | case NotificationType::BOOKMARK_MODEL_LOADED: |
| 2971 | // BookmarkModel finished loading, fall through to update starred state. |
| 2972 | case NotificationType::URLS_STARRED: { |
| 2973 | // Somewhere, a URL has been starred. |
| 2974 | // Ignore notifications for profiles other than our current one. |
| 2975 | Profile* source_profile = Source<Profile>(source).ptr(); |
| 2976 | if (!source_profile || !source_profile->IsSameProfile(profile())) |
| 2977 | return; |
| 2978 | |
| 2979 | UpdateStarredStateForCurrentURL(); |
| 2980 | break; |
| 2981 | } |
| 2982 | case NotificationType::PREF_CHANGED: { |
| 2983 | std::wstring* pref_name_in = Details<std::wstring>(details).ptr(); |
| 2984 | DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs()); |
| 2985 | if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { |
| 2986 | UpdateAlternateErrorPageURL(); |
| 2987 | } else if (*pref_name_in == prefs::kDefaultCharset || |
| 2988 | StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true) |
| 2989 | ) { |
| 2990 | UpdateWebPreferences(); |
| 2991 | } else { |
| 2992 | NOTREACHED() << "unexpected pref change notification" << *pref_name_in; |
| 2993 | } |
| 2994 | break; |
| 2995 | } |
| 2996 | case NotificationType::RENDER_WIDGET_HOST_DESTROYED: |
| 2997 | view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr()); |
| 2998 | break; |
| 2999 | |
| 3000 | case NotificationType::NAV_ENTRY_COMMITTED: { |
| 3001 | DCHECK(&controller_ == Source<NavigationController>(source).ptr()); |
| 3002 | |
| 3003 | NavigationController::LoadCommittedDetails& committed_details = |
| 3004 | *(Details<NavigationController::LoadCommittedDetails>(details).ptr()); |
| 3005 | ExpireInfoBars(committed_details); |
| 3006 | break; |
| 3007 | } |
| 3008 | |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 3009 | #if defined(OS_LINUX) |
| 3010 | case NotificationType::BROWSER_THEME_CHANGED: { |
[email protected] | 7ff431e | 2010-01-07 18:18:54 | [diff] [blame] | 3011 | renderer_preferences_util::UpdateFromSystemSettings( |
| 3012 | &renderer_preferences_, profile()); |
[email protected] | d3ba7727 | 2009-09-03 00:06:09 | [diff] [blame] | 3013 | render_view_host()->SyncRendererPrefs(); |
| 3014 | break; |
| 3015 | } |
| 3016 | #endif |
| 3017 | |
[email protected] | 6c32ce7 | 2010-03-08 05:18:06 | [diff] [blame] | 3018 | case NotificationType::USER_STYLE_SHEET_UPDATED: |
| 3019 | UpdateWebPreferences(); |
| 3020 | break; |
| 3021 | |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3022 | case NotificationType::CONTENT_SETTINGS_CHANGED: { |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3023 | Details<const HostContentSettingsMap::ContentSettingsDetails> |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3024 | settings_details(details); |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3025 | NavigationEntry* entry = controller_.GetActiveEntry(); |
[email protected] | da0c8e9 | 2010-02-09 23:25:49 | [diff] [blame] | 3026 | GURL entry_url; |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3027 | if (entry) |
[email protected] | da0c8e9 | 2010-02-09 23:25:49 | [diff] [blame] | 3028 | entry_url = entry->url(); |
[email protected] | 0314ae0 | 2010-04-08 09:18:29 | [diff] [blame] | 3029 | if (settings_details.ptr()->update_all() || |
| 3030 | settings_details.ptr()->pattern().Matches(entry_url)) { |
| 3031 | render_view_host()->SendContentSettings(entry_url, |
[email protected] | b9a4ea7f | 2010-06-25 07:11:23 | [diff] [blame] | 3032 | profile()->GetHostContentSettingsMap()-> |
| 3033 | GetContentSettings(entry_url)); |
[email protected] | 79580c6 | 2010-02-02 02:36:25 | [diff] [blame] | 3034 | } |
| 3035 | break; |
| 3036 | } |
| 3037 | |
[email protected] | e5adff7 | 2010-06-14 18:13:06 | [diff] [blame] | 3038 | case NotificationType::EXTENSION_LOADED: |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3039 | break; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3040 | |
| 3041 | case NotificationType::EXTENSION_UNLOADED: |
[email protected] | e5adff7 | 2010-06-14 18:13:06 | [diff] [blame] | 3042 | case NotificationType::EXTENSION_UNLOADED_DISABLED: |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3043 | break; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3044 | |
[email protected] | 420ae01 | 2009-04-24 05:16:32 | [diff] [blame] | 3045 | default: |
| 3046 | NOTREACHED(); |
| 3047 | } |
| 3048 | } |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 3049 | |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3050 | void TabContents::UpdateExtensionAppIcon(Extension* extension) { |
| 3051 | extension_app_icon_.reset(); |
[email protected] | f075fe0a2 | 2010-04-26 04:06:43 | [diff] [blame] | 3052 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3053 | if (extension) { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3054 | extension_app_image_loader_.reset(new ImageLoadingTracker(this)); |
| 3055 | extension_app_image_loader_->LoadImage( |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3056 | extension, |
| 3057 | extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH), |
| 3058 | gfx::Size(Extension::EXTENSION_ICON_SMALLISH, |
| 3059 | Extension::EXTENSION_ICON_SMALLISH), |
| 3060 | ImageLoadingTracker::CACHE); |
| 3061 | } else { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3062 | extension_app_image_loader_.reset(NULL); |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3063 | } |
| 3064 | } |
| 3065 | |
| 3066 | Extension* TabContents::GetExtensionContaining(const GURL& url) { |
| 3067 | ExtensionsService* extensions_service = profile()->GetExtensionsService(); |
| 3068 | if (!extensions_service) |
| 3069 | return NULL; |
| 3070 | |
| 3071 | Extension* extension = extensions_service->GetExtensionByURL(url); |
| 3072 | return extension ? |
| 3073 | extension : extensions_service->GetExtensionByWebExtent(url); |
| 3074 | } |
| 3075 | |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3076 | void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource, |
| 3077 | int index) { |
| 3078 | if (image) { |
[email protected] | 98aa0b5 | 2010-05-06 17:03:08 | [diff] [blame] | 3079 | extension_app_icon_ = *image; |
[email protected] | a888b29e6 | 2010-04-01 13:38:57 | [diff] [blame] | 3080 | NotifyNavigationStateChanged(INVALIDATE_TAB); |
| 3081 | } |
| 3082 | } |
| 3083 | |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 3084 | std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url, |
| 3085 | bool is_alert) { |
| 3086 | if (!frame_url.has_host()) |
| 3087 | return l10n_util::GetString( |
| 3088 | is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE |
| 3089 | : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE); |
| 3090 | |
| 3091 | // We really only want the scheme, hostname, and port. |
| 3092 | GURL::Replacements replacements; |
| 3093 | replacements.ClearUsername(); |
| 3094 | replacements.ClearPassword(); |
| 3095 | replacements.ClearPath(); |
| 3096 | replacements.ClearQuery(); |
| 3097 | replacements.ClearRef(); |
| 3098 | GURL clean_url = frame_url.ReplaceComponents(replacements); |
| 3099 | |
| 3100 | // TODO(brettw) it should be easier than this to do the correct language |
| 3101 | // handling without getting the accept language from the profile. |
| 3102 | std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0, |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 3103 | UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages))); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 3104 | // Force URL to have LTR directionality. |
[email protected] | 4a4afe3 | 2010-05-05 01:39:56 | [diff] [blame] | 3105 | base::i18n::GetDisplayStringInLTRDirectionality(&base_address); |
[email protected] | beb440c | 2009-11-06 04:08:54 | [diff] [blame] | 3106 | |
| 3107 | return l10n_util::GetStringF( |
| 3108 | is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE, |
| 3109 | base_address); |
| 3110 | } |
| 3111 | |
| 3112 | gfx::NativeWindow TabContents::GetMessageBoxRootWindow() { |
| 3113 | return view_->GetTopLevelNativeWindow(); |
| 3114 | } |
| 3115 | |
| 3116 | void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg, |
| 3117 | bool success, |
| 3118 | const std::wstring& prompt) { |
| 3119 | last_javascript_message_dismissal_ = base::TimeTicks::Now(); |
| 3120 | if (is_showing_before_unload_dialog_ && !success) { |
| 3121 | // If a beforeunload dialog is canceled, we need to stop the throbber from |
| 3122 | // spinning, since we forced it to start spinning in Navigate. |
| 3123 | DidStopLoading(); |
| 3124 | |
| 3125 | tab_close_start_time_ = base::TimeTicks(); |
| 3126 | } |
| 3127 | is_showing_before_unload_dialog_ = false; |
| 3128 | render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt); |
| 3129 | } |
| 3130 | |
| 3131 | void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { |
| 3132 | set_suppress_javascript_messages(suppress_message_boxes); |
| 3133 | } |
| 3134 | |
[email protected] | 3a3d4747 | 2010-07-15 21:03:54 | [diff] [blame] | 3135 | TabContents* TabContents::AsTabContents() { |
| 3136 | return this; |
| 3137 | } |
| 3138 | |
| 3139 | ExtensionHost* TabContents::AsExtensionHost() { |
| 3140 | return NULL; |
| 3141 | } |
| 3142 | |
[email protected] | 41fc032 | 2009-09-04 22:23:40 | [diff] [blame] | 3143 | void TabContents::set_encoding(const std::string& encoding) { |
[email protected] | aacd7cc | 2009-09-02 14:51:10 | [diff] [blame] | 3144 | encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); |
| 3145 | } |
[email protected] | f45d2a7 | 2010-03-08 23:28:35 | [diff] [blame] | 3146 | |
| 3147 | void TabContents::SetAppIcon(const SkBitmap& app_icon) { |
| 3148 | app_icon_ = app_icon; |
| 3149 | NotifyNavigationStateChanged(INVALIDATE_TITLE); |
| 3150 | } |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3151 | |
| 3152 | // After a successful *new* login attempt, we take the PasswordFormManager in |
| 3153 | // provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while |
| 3154 | // the user makes up their mind with the "save password" infobar. Note if the |
| 3155 | // login is one we already know about, the end of the line is |
| 3156 | // provisional_save_manager_ because we just update it on success and so such |
| 3157 | // forms never end up in an infobar. |
| 3158 | class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate { |
| 3159 | public: |
| 3160 | SavePasswordInfoBarDelegate(TabContents* tab_contents, |
[email protected] | 12bb682 | 2010-06-16 02:00:46 | [diff] [blame] | 3161 | PasswordFormManager* form_to_save) |
| 3162 | : ConfirmInfoBarDelegate(tab_contents), |
| 3163 | form_to_save_(form_to_save), |
| 3164 | infobar_response_(kNoResponse) { |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | virtual ~SavePasswordInfoBarDelegate() { } |
| 3168 | |
| 3169 | // Overridden from ConfirmInfoBarDelegate: |
| 3170 | virtual void InfoBarClosed() { |
[email protected] | 12bb682 | 2010-06-16 02:00:46 | [diff] [blame] | 3171 | UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse", |
| 3172 | infobar_response_, kNumResponseTypes); |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3173 | delete this; |
| 3174 | } |
| 3175 | |
| 3176 | virtual std::wstring GetMessageText() const { |
| 3177 | return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT); |
| 3178 | } |
| 3179 | |
| 3180 | virtual SkBitmap* GetIcon() const { |
| 3181 | return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 3182 | IDR_INFOBAR_SAVE_PASSWORD); |
| 3183 | } |
| 3184 | |
| 3185 | virtual int GetButtons() const { |
| 3186 | return BUTTON_OK | BUTTON_CANCEL; |
| 3187 | } |
| 3188 | |
| 3189 | virtual std::wstring GetButtonLabel(InfoBarButton button) const { |
| 3190 | if (button == BUTTON_OK) |
| 3191 | return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON); |
| 3192 | if (button == BUTTON_CANCEL) |
| 3193 | return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON); |
| 3194 | NOTREACHED(); |
| 3195 | return std::wstring(); |
| 3196 | } |
| 3197 | |
| 3198 | virtual bool Accept() { |
| 3199 | DCHECK(form_to_save_.get()); |
| 3200 | form_to_save_->Save(); |
[email protected] | 12bb682 | 2010-06-16 02:00:46 | [diff] [blame] | 3201 | infobar_response_ = kRememberPassword; |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3202 | return true; |
| 3203 | } |
| 3204 | |
| 3205 | virtual bool Cancel() { |
| 3206 | DCHECK(form_to_save_.get()); |
| 3207 | form_to_save_->PermanentlyBlacklist(); |
[email protected] | 12bb682 | 2010-06-16 02:00:46 | [diff] [blame] | 3208 | infobar_response_ = kDontRememberPassword; |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3209 | return true; |
| 3210 | } |
| 3211 | |
| 3212 | private: |
| 3213 | // The PasswordFormManager managing the form we're asking the user about, |
| 3214 | // and should update as per her decision. |
| 3215 | scoped_ptr<PasswordFormManager> form_to_save_; |
| 3216 | |
[email protected] | 12bb682 | 2010-06-16 02:00:46 | [diff] [blame] | 3217 | // Used to track the results we get from the info bar. |
| 3218 | enum ResponseType { |
| 3219 | kNoResponse = 0, |
| 3220 | kRememberPassword, |
| 3221 | kDontRememberPassword, |
| 3222 | kNumResponseTypes, |
| 3223 | }; |
| 3224 | ResponseType infobar_response_; |
| 3225 | |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3226 | DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate); |
| 3227 | }; |
| 3228 | |
| 3229 | void TabContents::FillPasswordForm( |
[email protected] | e768baf | 2010-07-16 19:36:16 | [diff] [blame] | 3230 | const webkit_glue::PasswordFormFillData& form_data) { |
[email protected] | ea68c06a | 2010-04-23 17:25:37 | [diff] [blame] | 3231 | render_view_host()->FillPasswordForm(form_data); |
| 3232 | } |
| 3233 | |
| 3234 | void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) { |
| 3235 | AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save)); |
| 3236 | } |
| 3237 | |
| 3238 | Profile* TabContents::GetProfileForPasswordManager() { |
| 3239 | return profile(); |
| 3240 | } |
| 3241 | |
| 3242 | bool TabContents::DidLastPageLoadEncounterSSLErrors() { |
| 3243 | return controller().ssl_manager()->ProcessedSSLErrorFromRequest(); |
| 3244 | } |