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