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