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