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