blob: f3160ccd58569cd7e297cb9e66c933ce0a1ce931 [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]06821f42d2010-05-03 22:34:357#if defined(OS_CHROMEOS)
8// For GdkScreen
9#include <gdk/gdk.h>
10#endif // defined(OS_CHROMEOS)
11
[email protected]a92b8642009-05-05 23:38:5612#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]420ae012009-04-24 05:16:3218#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5419#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3720#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5421#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4522#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2123#include "chrome/browser/autofill/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1324#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3225#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5426#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5527#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1029#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5430#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5432#include "chrome/browser/dom_ui/dom_ui.h"
33#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0234#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/download/download_manager.h"
36#include "chrome/browser/download/download_request_manager.h"
[email protected]e7eaedde2009-09-25 20:09:4937#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0838#include "chrome/browser/extensions/extensions_service.h"
[email protected]523623c2010-05-19 16:03:4239#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4840#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5341#include "chrome/browser/find_bar_state.h"
[email protected]420ae012009-04-24 05:16:3242#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2543#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2644#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1445#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3246#include "chrome/browser/load_from_memory_cache_details.h"
47#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4448#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0549#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1050#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5751#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2452#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5753#include "chrome/browser/plugin_installer.h"
[email protected]052313b2010-02-19 09:43:0854#include "chrome/browser/pref_service.h"
[email protected]ce560f82009-06-03 09:39:4455#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0756#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1657#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5458#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3759#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5461#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3262#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1663#include "chrome/browser/search_engines/template_url_fetcher.h"
64#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1765#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1766#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5467#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1668#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4369#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1670#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5771#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0272#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2873#include "chrome/browser/thumbnail_store.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5875#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2776#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4977#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5778#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1479#include "chrome/common/extensions/extension_resource.h"
[email protected]bfd04a62009-02-01 18:16:5680#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2981#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3282#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1883#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5484#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3785#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2686#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3287#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0688#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3789#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3290#include "net/base/mime_util.h"
91#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2992#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3293#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1894#include "webkit/glue/password_form.h"
95#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0096
[email protected]420ae012009-04-24 05:16:3297// Cross-Site Navigations
98//
99// If a TabContents is told to navigate to a different web site (as determined
100// by SiteInstance), it will replace its current RenderViewHost with a new
101// RenderViewHost dedicated to the new SiteInstance. This works as follows:
102//
103// - Navigate determines whether the destination is cross-site, and if so,
104// it creates a pending_render_view_host_ and moves into the PENDING
105// RendererState.
106// - The pending RVH is "suspended," so that no navigation messages are sent to
107// its renderer until the onbeforeunload JavaScript handler has a chance to
108// run in the current RVH.
109// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
110// that it has a pending cross-site request. ResourceDispatcherHost will
111// check for this when the response arrives.
112// - The current RVH runs its onbeforeunload handler. If it returns false, we
113// cancel all the pending logic and go back to NORMAL. Otherwise we allow
114// the pending RVH to send the navigation request to its renderer.
115// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
116// checks CrossSiteRequestManager to see that the RVH responsible has a
117// pending cross-site request, and then installs a CrossSiteEventHandler.
118// - When RDH receives a response, the BufferedEventHandler determines whether
119// it is a download. If so, it sends a message to the new renderer causing
120// it to cancel the request, and the download proceeds in the download
121// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34122// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32123// doesn't affect any functionality.
124// - After RDH receives a response and determines that it is safe and not a
125// download, it pauses the response to first run the old page's onunload
126// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34127// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32128// to the current RVH.
129// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
130// the ResourceDispatcherHost, who unpauses the response. Data is then sent
131// to the pending RVH.
132// - The pending renderer sends a FrameNavigate message that invokes the
133// DidNavigate method. This replaces the current RVH with the
134// pending RVH and goes back to the NORMAL RendererState.
135
136namespace {
137
138// Amount of time we wait between when a key event is received and the renderer
139// is queried for its state and pushed to the NavigationEntry.
140const int kQueryStateDelay = 5000;
141
142const int kSyncWaitDelay = 40;
143
[email protected]304f8792009-08-19 21:28:09144#if defined(OS_CHROMEOS)
145// If a popup window is bigger than this fraction of the screen on chrome os,
146// turn it into a tab
147const float kMaxWidthFactor = 0.5;
148const float kMaxHeightFactor = 0.6;
149#endif
150
[email protected]420ae012009-04-24 05:16:32151// If another javascript message box is displayed within
152// kJavascriptMessageExpectedDelay of a previous javascript message box being
153// dismissed, display an option to suppress future message boxes from this
154// contents.
155const int kJavascriptMessageExpectedDelay = 1000;
156
[email protected]420ae012009-04-24 05:16:32157// The list of prefs we want to observe.
158const wchar_t* kPrefsToObserve[] = {
159 prefs::kAlternateErrorPagesEnabled,
160 prefs::kWebKitJavaEnabled,
161 prefs::kWebKitJavascriptEnabled,
162 prefs::kWebKitLoadsImagesAutomatically,
163 prefs::kWebKitPluginsEnabled,
164 prefs::kWebKitUsesUniversalDetector,
165 prefs::kWebKitSerifFontFamily,
166 prefs::kWebKitSansSerifFontFamily,
167 prefs::kWebKitFixedFontFamily,
168 prefs::kWebKitDefaultFontSize,
169 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36170 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32171 prefs::kDefaultCharset
172 // kWebKitStandardFontIsSerif needs to be added
173 // if we let users pick which font to use, serif or sans-serif when
174 // no font is specified or a CSS generic family (serif or sans-serif)
175 // is not specified.
176};
177
178const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
179
[email protected]420ae012009-04-24 05:16:32180// Returns true if the entry's transition type is FORM_SUBMIT.
181bool IsFormSubmit(const NavigationEntry* entry) {
182 return (PageTransition::StripQualifier(entry->transition_type()) ==
183 PageTransition::FORM_SUBMIT);
184}
185
186#if defined(OS_WIN)
187
188BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
189 // Note: erase is required to properly paint some widgets borders. This can
190 // be seen with textfields.
191 InvalidateRect(hwnd, NULL, TRUE);
192 return TRUE;
193}
194#endif
195
[email protected]5e369672009-11-03 23:48:30196ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16197 Profile* profile, const NavigationEntry& entry,
198 NavigationController::ReloadType reload_type) {
199 switch (reload_type) {
200 case NavigationController::RELOAD:
201 return ViewMsg_Navigate_Params::RELOAD;
202 case NavigationController::RELOAD_IGNORING_CACHE:
203 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
204 case NavigationController::NO_RELOAD:
205 break; // Fall through to rest of function.
206 }
[email protected]5e369672009-11-03 23:48:30207
208 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
209 profile->DidLastSessionExitCleanly())
210 return ViewMsg_Navigate_Params::RESTORE;
211
212 return ViewMsg_Navigate_Params::NORMAL;
213}
214
[email protected]3cc72b12010-03-18 23:03:00215void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16216 NavigationController::ReloadType reload_type,
217 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00218 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34219 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00220 params->pending_history_list_offset = controller.pending_entry_index();
221 params->current_history_list_offset = controller.last_committed_entry_index();
222 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34223 params->url = entry.url();
224 params->referrer = entry.referrer();
225 params->transition = entry.transition_type();
226 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00227 params->navigation_type =
228 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34229 params->request_time = base::Time::Now();
230}
231
[email protected]420ae012009-04-24 05:16:32232} // namespace
233
234// -----------------------------------------------------------------------------
235
[email protected]fdd61c62009-04-22 19:22:57236// static
237int TabContents::find_request_id_counter_ = -1;
238
[email protected]420ae012009-04-24 05:16:32239
[email protected]420ae012009-04-24 05:16:32240TabContents::TabContents(Profile* profile,
241 SiteInstance* site_instance,
242 int routing_id,
[email protected]34ac70502009-09-25 17:07:23243 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42244 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13245 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
246 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22247 TabContentsView::Create(this))),
248 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57249 property_bag_(),
250 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22251 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57252 save_package_(),
[email protected]6db0def92010-03-02 19:55:45253 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21254 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57255 password_manager_(),
256 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06257 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22258 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57259 select_file_dialog_(),
[email protected]d5f942ba2008-09-26 19:30:34260 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29261 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34262 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34263 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57264 current_load_start_(),
265 load_state_(net::LOAD_STATE_IDLE),
266 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56267 upload_size_(0),
268 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57269 received_page_title_(false),
270 is_starred_(false),
271 contents_mime_type_(),
272 encoding_(),
[email protected]332af7732009-03-11 13:21:35273 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49274 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47275 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57276 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57277 find_ui_active_(false),
278 find_op_aborted_(false),
279 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12280 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12281 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08282 extension_app_(NULL),
283 extension_app_for_current_page_(NULL),
[email protected]fdd61c62009-04-22 19:22:57284 capturing_contents_(false),
285 is_being_destroyed_(false),
286 notify_disconnection_(false),
287 history_requests_(),
288#if defined(OS_WIN)
289 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
290#endif
291 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44292 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01293 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54294 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54295 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16296 language_state_(&controller_),
[email protected]b3df5a42010-05-11 14:31:09297 geolocation_settings_state_(profile),
[email protected]0cce15f2010-05-21 16:58:39298 requested_accessibility_tree_(false),
299 closed_by_user_gesture_(false) {
[email protected]0de80162010-02-03 04:52:35300 ClearBlockedContentSettings();
[email protected]7ff431e2010-01-07 18:18:54301 renderer_preferences_util::UpdateFromSystemSettings(
302 &renderer_preferences_, profile);
303
[email protected]16779842009-07-08 23:45:29304#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02305 // Make sure the thumbnailer is started before starting the render manager.
306 // The thumbnailer will want to listen for RVH creations, one of which will
307 // happen in RVHManager::Init.
308 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
309 if (generator)
310 generator->StartThumbnailing();
311#endif
312
[email protected]12636df2009-09-28 22:32:21313 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32314
[email protected]34ac70502009-09-25 17:07:23315 // We have the initial size of the view be based on the size of the passed in
316 // tab contents (normally a tab from the same window).
317 view_->CreateView(base_tab_contents ?
318 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32319
320 // Register for notifications about all interested prefs change.
321 PrefService* prefs = profile->GetPrefs();
322 if (prefs) {
323 for (int i = 0; i < kPrefsToObserveLength; ++i)
324 prefs->AddPrefObserver(kPrefsToObserve[i], this);
325 }
326
327 // Register for notifications about URL starredness changing on any profile.
328 registrar_.Add(this, NotificationType::URLS_STARRED,
329 NotificationService::AllSources());
330 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
331 NotificationService::AllSources());
332 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
333 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09334#if defined(OS_LINUX)
335 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
336 NotificationService::AllSources());
337#endif
[email protected]420ae012009-04-24 05:16:32338
[email protected]6c32ce72010-03-08 05:18:06339 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
340 NotificationService::AllSources());
341
[email protected]79580c62010-02-02 02:36:25342 // Register for notifications about content setting changes.
343 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
344 NotificationService::AllSources());
345
[email protected]a888b29e62010-04-01 13:38:57346 // Listen for extension changes so we can update extension_for_current_page_.
347 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
348 NotificationService::AllSources());
349 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
350 NotificationService::AllSources());
351 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
352 NotificationService::AllSources());
353
[email protected]c8865482009-07-23 20:40:10354 // Set-up the showing of the omnibox search infobar if applicable.
355 if (OmniboxSearchHint::IsEnabled(profile))
356 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]b3df5a42010-05-11 14:31:09357
358 renderer_accessible_ =
359 CommandLine::ForCurrentProcess()->HasSwitch(
360 switches::kEnableRendererAccessibility);
[email protected]332af7732009-03-11 13:21:35361}
initial.commit09911bf2008-07-26 23:55:29362
363TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32364 is_being_destroyed_ = true;
365
[email protected]bfe4c1582009-10-02 18:11:09366 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32367 registrar_.RemoveAll();
368
369 // Unregister the notifications of all observed prefs change.
370 PrefService* prefs = profile()->GetPrefs();
371 if (prefs) {
372 for (int i = 0; i < kPrefsToObserveLength; ++i)
373 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
374 }
375
[email protected]420ae012009-04-24 05:16:32376 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00377 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32378
[email protected]420ae012009-04-24 05:16:32379 // First cleanly close all child windows.
380 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
381 // some of these to close. CloseWindows is async, so it might get called
382 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49383 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32384
[email protected]8cc8d492010-02-02 10:40:49385 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13386 if (blocked_popups_)
387 blocked_popups_->Destroy();
388
[email protected]420ae012009-04-24 05:16:32389 // Notify any observer that have a reference on this tab contents.
390 NotificationService::current()->Notify(
391 NotificationType::TAB_CONTENTS_DESTROYED,
392 Source<TabContents>(this),
393 NotificationService::NoDetails());
394
[email protected]1e5e74f2009-05-27 20:55:12395 // Notify any lasting InfobarDelegates that have not yet been removed that
396 // whatever infobar they were handling in this TabContents has closed,
397 // because the TabContents is going away entirely.
398 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
399 // notification may trigger infobars calls that access their delegate. (and
400 // some implementations of InfoBarDelegate do delete themselves on
401 // InfoBarClosed()).
402 for (int i = 0; i < infobar_delegate_count(); ++i) {
403 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
404 delegate->InfoBarClosed();
405 }
406 infobar_delegates_.clear();
407
[email protected]420ae012009-04-24 05:16:32408 // TODO(brettw) this should be moved to the view.
409#if defined(OS_WIN)
410 // If we still have a window handle, destroy it. GetNativeView can return
411 // NULL if this contents was part of a window that closed.
412 if (GetNativeView())
413 ::DestroyWindow(GetNativeView());
414#endif
[email protected]7ab1e7d62009-10-14 23:32:01415
416 // OnCloseStarted isn't called in unit tests.
417 if (!tab_close_start_time_.is_null()) {
418 UMA_HISTOGRAM_TIMES("Tab.Close",
419 base::TimeTicks::Now() - tab_close_start_time_);
420 }
initial.commit09911bf2008-07-26 23:55:29421}
422
[email protected]d5f942ba2008-09-26 19:30:34423// static
424void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32425 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
426
427 WebPreferences pref_defaults;
428 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
429 pref_defaults.javascript_enabled);
430 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
431 pref_defaults.web_security_enabled);
432 prefs->RegisterBooleanPref(
433 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
434 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
435 pref_defaults.loads_images_automatically);
436 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
437 pref_defaults.plugins_enabled);
438 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
439 pref_defaults.dom_paste_enabled);
440 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
441 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08442 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:26443 UTF8ToWide(pref_defaults.inspector_settings));
[email protected]420ae012009-04-24 05:16:32444 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
445 pref_defaults.text_areas_are_resizable);
446 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
447 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36448 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
449 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32450
451 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
452 IDS_ACCEPT_LANGUAGES);
453 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
454 IDS_DEFAULT_ENCODING);
455 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
456 IDS_STANDARD_FONT_IS_SERIF);
457 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
458 IDS_FIXED_FONT_FAMILY);
459 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
460 IDS_SERIF_FONT_FAMILY);
461 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
462 IDS_SANS_SERIF_FONT_FAMILY);
463 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
464 IDS_CURSIVE_FONT_FAMILY);
465 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
466 IDS_FANTASY_FONT_FAMILY);
467 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
468 IDS_DEFAULT_FONT_SIZE);
469 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
470 IDS_DEFAULT_FIXED_FONT_SIZE);
471 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
472 IDS_MINIMUM_FONT_SIZE);
473 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
474 IDS_MINIMUM_LOGICAL_FONT_SIZE);
475 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
476 IDS_USES_UNIVERSAL_DETECTOR);
477 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
478 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29479}
480
[email protected]13367f72009-07-08 16:39:02481// Returns true if contains content rendered by an extension.
482bool TabContents::HostsExtension() const {
483 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34484}
485
[email protected]cf28ec52010-04-09 22:56:34486AutoFillManager* TabContents::GetAutoFillManager() {
487 if (autofill_manager_.get() == NULL)
488 autofill_manager_.reset(new AutoFillManager(this));
489 return autofill_manager_.get();
490}
491
[email protected]6e95706d2009-04-23 22:55:01492PasswordManager* TabContents::GetPasswordManager() {
493 if (password_manager_.get() == NULL)
494 password_manager_.reset(new PasswordManager(this));
495 return password_manager_.get();
496}
497
498PluginInstaller* TabContents::GetPluginInstaller() {
499 if (plugin_installer_.get() == NULL)
500 plugin_installer_.reset(new PluginInstaller(this));
501 return plugin_installer_.get();
502}
503
[email protected]8cb5d5b2010-02-09 11:36:16504RenderProcessHost* TabContents::GetRenderProcessHost() const {
505 return render_manager_.current_host()->process();
506}
507
[email protected]98aa0b52010-05-06 17:03:08508void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46509 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08510 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10511
[email protected]98aa0b52010-05-06 17:03:08512 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57513
[email protected]fca656c2010-02-10 20:30:10514 NotificationService::current()->Notify(
515 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
516 Source<TabContents>(this),
517 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49518}
519
[email protected]98aa0b52010-05-06 17:03:08520void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
521 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40522 return;
523
524 ExtensionsService* extension_service = profile()->GetExtensionsService();
525 if (extension_service && extension_service->is_ready()) {
526 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08527 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40528 if (extension)
[email protected]98aa0b52010-05-06 17:03:08529 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40530 }
531}
532
[email protected]98aa0b52010-05-06 17:03:08533SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]8eb043b2010-04-30 07:19:51534 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
535 // for those windows, we already have a big icon in the top-left outside any
536 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35537 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
538 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51539 return NULL;
[email protected]8eb043b2010-04-30 07:19:51540
[email protected]98aa0b52010-05-06 17:03:08541 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51542 return NULL;
543
[email protected]98aa0b52010-05-06 17:03:08544 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51545}
546
[email protected]d5f942ba2008-09-26 19:30:34547const GURL& TabContents::GetURL() const {
548 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57549 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54550 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34551}
552
[email protected]96d185d2009-04-24 03:28:54553const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55554 // Transient entries take precedence. They are used for interstitial pages
555 // that are shown on top of existing pages.
556 NavigationEntry* entry = controller_.GetTransientEntry();
557 if (entry)
558 return entry->GetTitleForDisplay(&controller_);
559
[email protected]96d185d2009-04-24 03:28:54560 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
561 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
562 if (our_dom_ui) {
563 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55564 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54565 if (!(entry && entry->IsViewSourceMode())) {
566 // Give the DOM UI the chance to override our title.
567 const string16& title = our_dom_ui->overridden_title();
568 if (!title.empty())
569 return title;
570 }
571 }
572
573 // We use the title for the last committed entry rather than a pending
574 // navigation entry. For example, when the user types in a URL, we want to
575 // keep the old page's title until the new load has committed and we get a new
576 // title.
[email protected]96d185d2009-04-24 03:28:54577 entry = controller_.GetLastCommittedEntry();
578 if (entry)
579 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54580 return EmptyString16();
581}
582
[email protected]bbbc1ef2010-02-12 18:03:41583// static
584string16 TabContents::GetDefaultTitle() {
585 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
586}
587
[email protected]d5f942ba2008-09-26 19:30:34588int32 TabContents::GetMaxPageID() {
589 if (GetSiteInstance())
590 return GetSiteInstance()->max_page_id();
591 else
592 return max_page_id_;
593}
594
595void TabContents::UpdateMaxPageID(int32 page_id) {
596 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34597 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34598 // testing.
599 if (GetSiteInstance())
600 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16601 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34602}
603
[email protected]96d185d2009-04-24 03:28:54604SiteInstance* TabContents::GetSiteInstance() const {
605 return render_manager_.current_host()->site_instance();
606}
607
[email protected]96d185d2009-04-24 03:28:54608bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15609 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54610 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15611 if (entry && (entry->IsViewSourceMode() ||
612 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54613 return true;
[email protected]8ab24cc2009-11-13 20:56:15614 }
[email protected]83e3895b2009-06-11 00:07:16615
[email protected]96d185d2009-04-24 03:28:54616 DOMUI* dom_ui = GetDOMUIForCurrentState();
617 if (dom_ui)
618 return !dom_ui->should_hide_url();
619 return true;
620}
621
[email protected]d5f942ba2008-09-26 19:30:34622SkBitmap TabContents::GetFavIcon() const {
623 // Like GetTitle(), we also want to use the favicon for the last committed
624 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57625 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47626 if (entry)
627 return entry->favicon().bitmap();
628
[email protected]ce3fa3c2009-04-20 19:55:57629 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34630 if (entry)
631 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34632 return SkBitmap();
633}
634
[email protected]0b303cc2009-09-28 22:35:15635bool TabContents::FavIconIsValid() const {
636 NavigationEntry* entry = controller_.GetTransientEntry();
637 if (entry)
638 return entry->favicon().is_valid();
639
640 entry = controller_.GetLastCommittedEntry();
641 if (entry)
642 return entry->favicon().is_valid();
643
644 return false;
645}
646
[email protected]96d185d2009-04-24 03:28:54647bool TabContents::ShouldDisplayFavIcon() {
648 // Always display a throbber during pending loads.
649 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
650 return true;
651
652 DOMUI* dom_ui = GetDOMUIForCurrentState();
653 if (dom_ui)
654 return !dom_ui->hide_favicon();
655 return true;
656}
657
[email protected]2d5a3592010-01-30 04:29:52658bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
[email protected]8cc8d492010-02-02 10:40:49659 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
660 return blocked_popups_ != NULL;
661
[email protected]0de80162010-02-03 04:52:35662 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
663 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
[email protected]3dbb80b2010-02-09 22:41:20664 content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
665 content_type == CONTENT_SETTINGS_TYPE_COOKIES)
[email protected]0de80162010-02-03 04:52:35666 return content_blocked_[content_type];
667
[email protected]b1235062010-03-25 17:31:27668 // TODO(joth): remove once fully implemented.
669 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
670 return false;
671
[email protected]3dbb80b2010-02-09 22:41:20672 NOTREACHED();
[email protected]2d5a3592010-01-30 04:29:52673 return false;
674}
675
[email protected]96d185d2009-04-24 03:28:54676std::wstring TabContents::GetStatusText() const {
677 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
678 return std::wstring();
679
680 switch (load_state_) {
681 case net::LOAD_STATE_WAITING_FOR_CACHE:
682 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
683 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
684 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
685 case net::LOAD_STATE_RESOLVING_HOST:
686 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
687 case net::LOAD_STATE_CONNECTING:
688 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
689 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56690 if (upload_size_)
691 return l10n_util::GetStringF(
692 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
693 static_cast<int>((100 * upload_position_) / upload_size_));
694 else
695 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54696 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
697 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
698 load_state_host_);
699 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
700 case net::LOAD_STATE_IDLE:
701 case net::LOAD_STATE_READING_RESPONSE:
702 break;
703 }
704
705 return std::wstring();
706}
707
[email protected]d5f942ba2008-09-26 19:30:34708void TabContents::SetIsCrashed(bool state) {
709 if (state == is_crashed_)
710 return;
711
712 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50713 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34714}
715
[email protected]744ef172009-10-16 21:53:46716void TabContents::PageActionStateChanged() {
717 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00718}
[email protected]ce5c4502009-05-06 16:46:11719
[email protected]d5f942ba2008-09-26 19:30:34720void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
721 if (delegate_)
722 delegate_->NavigationStateChanged(this, changed_flags);
723}
724
[email protected]96d185d2009-04-24 03:28:54725void TabContents::DidBecomeSelected() {
726 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16727 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
728 if (rwhv) {
729 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43730#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16731 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43732#endif
733 }
[email protected]96d185d2009-04-24 03:28:54734
[email protected]8cb5d5b2010-02-09 11:36:16735 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54736}
737
738void TabContents::WasHidden() {
739 if (!capturing_contents()) {
740 // |render_view_host()| can be NULL if the user middle clicks a link to open
741 // a tab in then background, then closes the tab before selecting it. This
742 // is because closing the tab calls TabContents::Destroy(), which removes
743 // the |render_view_host()|; then when we actually destroy the window,
744 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16745 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
746 if (rwhv)
747 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54748 }
749
750 NotificationService::current()->Notify(
751 NotificationType::TAB_CONTENTS_HIDDEN,
752 Source<TabContents>(this),
753 NotificationService::NoDetails());
754}
755
[email protected]d5f942ba2008-09-26 19:30:34756void TabContents::Activate() {
757 if (delegate_)
758 delegate_->ActivateContents(this);
759}
760
[email protected]96d185d2009-04-24 03:28:54761void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16762 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
763 if (rwhv)
764 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54765}
766
767void TabContents::HideContents() {
768 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
769 // our superclass HideContents(), because some callers want to be very picky
770 // about the order in which these get called. In addition to making the code
771 // here practically impossible to understand, this also means we end up
772 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34773 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54774 WasHidden();
775}
776
[email protected]c0588052008-10-27 23:01:50777void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34778 WindowOpenDisposition disposition,
779 PageTransition::Type transition) {
780 if (delegate_)
[email protected]c0588052008-10-27 23:01:50781 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34782}
783
[email protected]1ccb3568d2010-02-19 10:51:16784bool TabContents::NavigateToPendingEntry(
785 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54786 const NavigationEntry& entry = *controller_.pending_entry();
787
788 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
789 if (!dest_render_view_host)
790 return false; // Unable to create the desired render view host.
791
[email protected]770dd8b2010-05-24 18:11:39792 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
793 dest_render_view_host->EnablePreferredSizeChangedMode(
794 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
795 }
[email protected]9fb325e2010-05-06 18:23:24796
[email protected]0352e5472010-04-29 00:11:40797 // For security, we should never send non-DOM-UI URLs (other than about:blank)
798 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58799 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40800 bool is_allowed_in_dom_ui_renderer =
801 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
802 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58803 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40804 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58805
[email protected]96d185d2009-04-24 03:28:54806 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12807 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32808 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00809 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
810 dest_render_view_host,
811 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32812 }
[email protected]96d185d2009-04-24 03:28:54813
814 // Used for page load time metrics.
815 current_load_start_ = base::TimeTicks::Now();
816
817 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34818 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00819 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34820 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54821
822 if (entry.page_id() == -1) {
823 // HACK!! This code suppresses javascript: URLs from being added to
824 // session history, which is what we want to do for javascript: URLs that
825 // do not generate content. What we really need is a message from the
826 // renderer telling us that a new page was not created. The same message
827 // could be used for mailto: URLs and the like.
828 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
829 return false;
830 }
831
832 // Clear any provisional password saves - this stops password infobars
833 // showing up on pages the user navigates to while the right page is
834 // loading.
835 GetPasswordManager()->ClearProvisionalSave();
836
[email protected]1ccb3568d2010-02-19 10:51:16837 if (reload_type != NavigationController::NO_RELOAD &&
838 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48839 FaviconService* favicon_service =
840 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
841 if (favicon_service)
842 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54843 }
844
[email protected]a888b29e62010-04-01 13:38:57845 // The url likely changed, see if there is an extension whose extent contains
846 // the current page.
[email protected]98aa0b52010-05-06 17:03:08847 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:57848
[email protected]d5f942ba2008-09-26 19:30:34849 return true;
850}
851
[email protected]96d185d2009-04-24 03:28:54852void TabContents::Stop() {
853 render_manager_.Stop();
854 printing_.Stop();
855}
856
[email protected]96d185d2009-04-24 03:28:54857void TabContents::DisassociateFromPopupCount() {
858 render_view_host()->DisassociateFromPopupCount();
859}
860
861TabContents* TabContents::Clone() {
862 // We create a new SiteInstance so that the new tab won't share processes
863 // with the old one. This can be changed in the future if we need it to share
864 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32865 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54866 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21867 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54868 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08869 tc->extension_app_ = extension_app_;
870 tc->extension_app_for_current_page_ = extension_app_for_current_page_;
871 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54872 return tc;
873}
874
[email protected]4d677202009-07-19 07:37:12875void TabContents::ShowPageInfo(const GURL& url,
876 const NavigationEntry::SSLStatus& ssl,
877 bool show_history) {
878 if (!delegate_)
879 return;
880
[email protected]bb678332009-07-21 00:15:50881 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12882}
883
initial.commit09911bf2008-07-26 23:55:29884ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28885 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29886 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28887 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29888 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44889
890 if (child_windows_.size() == 1) {
891 window->ShowConstrainedWindow();
892 BlockTabContent(true);
893 }
894
initial.commit09911bf2008-07-26 23:55:29895 return window;
896}
897
[email protected]fa1cf0b82010-01-15 21:49:44898void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55899 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
900 if (rwhv)
901 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44902 render_view_host()->set_ignore_input_events(blocked);
903 if (delegate_)
904 delegate_->SetTabContentBlocked(this, blocked);
905}
906
initial.commit09911bf2008-07-26 23:55:29907void TabContents::AddNewContents(TabContents* new_contents,
908 WindowOpenDisposition disposition,
909 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29910 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29911 if (!delegate_)
912 return;
913
[email protected]35f7d212009-04-29 21:19:27914 if ((disposition == NEW_POPUP) && !user_gesture &&
915 !CommandLine::ForCurrentProcess()->HasSwitch(
916 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22917 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31918 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29919 delegate_->GetConstrainingContents(this)->AddPopup(
920 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31921 } else {
[email protected]304f8792009-08-19 21:28:09922#if defined(OS_CHROMEOS)
923 if (disposition == NEW_POPUP) {
924 // If the popup is bigger than a given factor of the screen, then
925 // turn it into a foreground tab (on chrome os only)
926 GdkScreen* screen = gdk_screen_get_default();
927 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
928 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
929 if (initial_pos.width() > max_width ||
930 initial_pos.height() > max_height) {
931 disposition = NEW_FOREGROUND_TAB;
932 }
933 }
934#endif
935
[email protected]0aa55312008-10-17 21:53:08936 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29937 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
938 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49939 NotificationService::current()->Notify(
940 NotificationType::TAB_ADDED,
941 Source<TabContentsDelegate>(delegate_),
942 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29943 }
initial.commit09911bf2008-07-26 23:55:29944
[email protected]8cc8d492010-02-02 10:40:49945 // TODO(pkasting): Why is this necessary?
946 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29947}
948
[email protected]bcd9dc42010-01-23 16:38:18949bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20950 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20951 bool is_js_code, const std::string& code_string,
952 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51953 RenderViewHost* host = render_view_host();
954 if (!host)
955 return false;
956
957 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
958 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
959 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35960}
961
[email protected]96d185d2009-04-24 03:28:54962void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49963 if (is_being_destroyed_)
964 return;
965 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40966 render_view_host()->AllowScriptToClose(!visible);
[email protected]0de80162010-02-03 04:52:35967 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24968 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54969}
970
[email protected]5c9e97a2009-09-09 23:48:30971gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54972 return view_->GetContentNativeView();
973}
974
975gfx::NativeView TabContents::GetNativeView() const {
976 return view_->GetNativeView();
977}
978
979void TabContents::GetContainerBounds(gfx::Rect *out) const {
980 view_->GetContainerBounds(out);
981}
982
983void TabContents::Focus() {
984 view_->Focus();
985}
986
[email protected]90daadb42009-06-08 21:27:28987void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54988 if (showing_interstitial_page()) {
989 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
990 return;
991 }
[email protected]96d185d2009-04-24 03:28:54992 render_view_host()->SetInitialFocus(reverse);
993}
994
995bool TabContents::FocusLocationBarByDefault() {
996 DOMUI* dom_ui = GetDOMUIForCurrentState();
997 if (dom_ui)
998 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43999 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251000 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431001 return true;
[email protected]96d185d2009-04-24 03:28:541002 return false;
1003}
1004
[email protected]a26dc362010-04-23 01:48:581005void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381006 if (delegate())
[email protected]a26dc362010-04-23 01:48:581007 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381008}
1009
[email protected]616ed5a2008-11-21 22:27:241010void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321011 if (delegate_ && !delegate_->infobars_enabled()) {
1012 delegate->InfoBarClosed();
1013 return;
1014 }
1015
[email protected]616ed5a2008-11-21 22:27:241016 // Look through the existing InfoBarDelegates we have for a match. If we've
1017 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051018 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451019 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1020 // Tell the new infobar to close so that it can clean itself up.
1021 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241022 return;
[email protected]6d27a7b2009-12-18 23:25:451023 }
[email protected]616ed5a2008-11-21 22:27:241024 }
1025
1026 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561027 NotificationService::current()->Notify(
1028 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1029 Source<TabContents>(this),
1030 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241031
1032 // Add ourselves as an observer for navigations the first time a delegate is
1033 // added. We use this notification to expire InfoBars that need to expire on
1034 // page transitions.
1035 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561036 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571037 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241038 }
1039}
1040
1041void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321042 if (delegate_ && !delegate_->infobars_enabled()) {
1043 return;
1044 }
1045
[email protected]616ed5a2008-11-21 22:27:241046 std::vector<InfoBarDelegate*>::iterator it =
1047 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1048 if (it != infobar_delegates_.end()) {
1049 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561050 NotificationService::current()->Notify(
1051 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1052 Source<TabContents>(this),
1053 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051054 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241055
[email protected]6a02963e2009-01-06 16:58:031056 // Remove ourselves as an observer if we are tracking no more InfoBars.
1057 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561058 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571059 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031060 }
[email protected]616ed5a2008-11-21 22:27:241061 }
1062}
[email protected]3edd9522009-03-04 22:19:411063
[email protected]f81821c2009-08-07 01:29:471064void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1065 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321066 if (delegate_ && !delegate_->infobars_enabled()) {
1067 new_delegate->InfoBarClosed();
1068 return;
1069 }
1070
[email protected]f81821c2009-08-07 01:29:471071 std::vector<InfoBarDelegate*>::iterator it =
1072 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1073 DCHECK(it != infobar_delegates_.end());
1074
1075 // Notify the container about the change of plans.
1076 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1077 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1078 old_delegate, new_delegate));
1079 NotificationService::current()->Notify(
1080 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1081 Source<TabContents>(this),
1082 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1083
1084 // Remove the old one.
1085 infobar_delegates_.erase(it);
1086
1087 // Add the new one.
1088 infobar_delegates_.push_back(new_delegate);
1089}
1090
[email protected]20ede072009-10-06 00:28:351091bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271092 if (showing_interstitial_page())
1093 return false;
1094
[email protected]96d185d2009-04-24 03:28:541095 // See GetDOMUIForCurrentState() comment for more info. This case is very
1096 // similar, but for non-first loads, we want to use the committed entry. This
1097 // is so the bookmarks bar disappears at the same time the page does.
1098 if (controller_.GetLastCommittedEntry()) {
1099 // Not the first load, always use the committed DOM UI.
1100 if (render_manager_.dom_ui())
1101 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1102 return false; // Default.
1103 }
1104
1105 // When it's the first load, we know either the pending one or the committed
1106 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1107 // of them will be valid, so we can just check both.
1108 if (render_manager_.pending_dom_ui())
1109 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1110 if (render_manager_.dom_ui())
1111 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1112 return false; // Default.
1113}
1114
[email protected]d8f16ae2009-08-30 03:47:261115bool TabContents::IsExtensionShelfAlwaysVisible() {
1116 // See GetDOMUIForCurrentState() comment for more info. This case is very
1117 // similar, but for non-first loads, we want to use the committed entry. This
1118 // is so the bookmarks bar disappears at the same time the page does.
1119 if (controller_.GetLastCommittedEntry()) {
1120 // Not the first load, always use the committed DOM UI.
1121 if (render_manager_.dom_ui())
1122 return render_manager_.dom_ui()->force_extension_shelf_visible();
1123 return false; // Default.
1124 }
1125
1126 // When it's the first load, we know either the pending one or the committed
1127 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1128 // of them will be valid, so we can just check both.
1129 if (render_manager_.pending_dom_ui())
1130 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1131 if (render_manager_.dom_ui())
1132 return render_manager_.dom_ui()->force_extension_shelf_visible();
1133 return false; // Default.
1134}
1135
[email protected]3edd9522009-03-04 22:19:411136void TabContents::ToolbarSizeChanged(bool is_animating) {
1137 TabContentsDelegate* d = delegate();
1138 if (d)
1139 d->ToolbarSizeChanged(this, is_animating);
1140}
[email protected]616ed5a2008-11-21 22:27:241141
[email protected]fc6fb7fb2009-11-07 02:35:041142bool TabContents::CanDownload(int request_id) {
1143 TabContentsDelegate* d = delegate();
1144 if (d)
1145 return d->CanDownload(request_id);
1146 return true;
1147}
1148
[email protected]d5f942ba2008-09-26 19:30:341149void TabContents::OnStartDownload(DownloadItem* download) {
1150 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341151
1152 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311153 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341154
[email protected]c70f9b82010-04-21 07:31:111155 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221156 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111157 // If the download occurs in a new tab, close it
1158 if (controller_.IsInitialNavigation() && (tab_contents == this))
1159 delegate()->CloseContents(this);
1160 }
[email protected]3edd9522009-03-04 22:19:411161}
[email protected]3edd9522009-03-04 22:19:411162
[email protected]d5f942ba2008-09-26 19:30:341163void TabContents::WillClose(ConstrainedWindow* window) {
1164 ConstrainedWindowList::iterator it =
1165 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441166 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341167 if (it != child_windows_.end())
1168 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371169 if (child_windows_.size() > 0) {
1170 if (removed_topmost_window) {
1171 child_windows_[0]->ShowConstrainedWindow();
1172 }
[email protected]fa1cf0b82010-01-15 21:49:441173 BlockTabContent(true);
1174 } else {
1175 BlockTabContent(false);
1176 }
[email protected]66ba4932009-06-04 19:22:131177}
[email protected]d5f942ba2008-09-26 19:30:341178
[email protected]66ba4932009-06-04 19:22:131179void TabContents::WillCloseBlockedPopupContainer(
1180 BlockedPopupContainer* container) {
1181 DCHECK(blocked_popups_ == container);
1182 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491183 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341184}
1185
[email protected]d5f942ba2008-09-26 19:30:341186void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351187#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061188 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351189#endif
[email protected]d5f942ba2008-09-26 19:30:341190}
1191
[email protected]c1dc9f132009-11-20 23:13:211192void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121193 bool forward_direction,
1194 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211195 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011196 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211197 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531198 string16 last_search_prepopulate_text =
1199 FindBarState::GetLastPrepopulateText(profile());
1200
[email protected]87fae512009-12-11 02:20:211201 // Try the last thing we searched for on this tab, then the last thing
1202 // searched for on any tab.
1203 if (!previous_find_text_.empty())
1204 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531205 else if (!last_search_prepopulate_text.empty())
1206 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211207 else
[email protected]e491f1c2009-05-22 20:28:121208 return;
[email protected]e491f1c2009-05-22 20:28:121209 }
[email protected]6e95706d2009-04-23 22:55:011210
[email protected]101c90e2009-10-26 21:14:441211 // Keep track of the previous search.
1212 previous_find_text_ = find_text_;
1213
[email protected]6e95706d2009-04-23 22:55:011214 // This is a FindNext operation if we are searching for the same text again,
1215 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1216 // exception to this is if the Find was aborted (then we don't want FindNext
1217 // because the highlighting has been cleared and we need it to reappear). We
1218 // therefore treat FindNext after an aborted Find operation as a full fledged
1219 // Find.
[email protected]c1dc9f132009-11-20 23:13:211220 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121221 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011222 !find_op_aborted_;
1223 if (!find_next)
1224 current_find_request_id_ = find_request_id_counter_++;
1225
[email protected]c1dc9f132009-11-20 23:13:211226 if (!search_string.empty())
1227 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121228 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011229
1230 find_op_aborted_ = false;
1231
1232 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531233 FindBarState* find_bar_state = profile()->GetFindBarState();
1234 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011235 render_view_host()->StartFinding(current_find_request_id_,
1236 find_text_,
1237 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121238 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011239 find_next);
1240}
1241
[email protected]5bc8fe92010-03-11 18:19:001242void TabContents::StopFinding(
1243 FindBarController::SelectionAction selection_action) {
1244 // When the action is kClearAction, it means the find string has been cleared
[email protected]2d2dffc2009-06-09 21:41:001245 // by the user, but the UI has not been dismissed.
[email protected]5bc8fe92010-03-11 18:19:001246 if (selection_action != FindBarController::kClearSelection)
[email protected]2d2dffc2009-06-09 21:41:001247 find_ui_active_ = false;
[email protected]726bdbd72010-04-05 17:08:071248 if (!find_text_.empty())
1249 previous_find_text_ = find_text_;
[email protected]101c90e2009-10-26 21:14:441250 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011251 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121252 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001253 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011254}
1255
[email protected]420ae012009-04-24 05:16:321256void TabContents::OnSavePage() {
1257 // If we can not save the page, try to download it.
1258 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1259 DownloadManager* dlm = profile()->GetDownloadManager();
1260 const GURL& current_page_url = GetURL();
1261 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221262 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321263 return;
1264 }
1265
1266 Stop();
1267
1268 // Create the save package and possibly prompt the user for the name to save
1269 // the page as. The user prompt is an asynchronous operation that runs on
1270 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221271 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321272 save_package_->GetSaveInfo();
1273}
1274
1275// Used in automated testing to bypass prompting the user for file names.
1276// Instead, the names and paths are hard coded rather than running them through
1277// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111278bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321279 SavePackage::SavePackageType save_type) {
1280 // Stop the page from navigating.
1281 Stop();
1282
[email protected]828cabe2009-09-26 22:47:111283 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591284 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321285}
1286
[email protected]89d6e6e2009-12-03 23:06:511287void TabContents::EmailPageLocation() {
1288 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1289 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1290 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1291 title + "&body=%0A%0A" + page_url;
1292 platform_util::OpenExternal(GURL(mailto));
1293}
1294
[email protected]420ae012009-04-24 05:16:321295void TabContents::PrintPreview() {
1296 // We don't show the print preview yet, only the print dialog.
1297 PrintNow();
1298}
1299
1300bool TabContents::PrintNow() {
1301 // We can't print interstitial page for now.
1302 if (showing_interstitial_page())
1303 return false;
1304
1305 return render_view_host()->PrintPages();
1306}
1307
[email protected]82270452009-06-19 15:58:011308void TabContents::PrintingDone(int document_cookie, bool success) {
1309 render_view_host()->PrintingDone(document_cookie, success);
1310}
1311
[email protected]420ae012009-04-24 05:16:321312bool TabContents::IsActiveEntry(int32 page_id) {
1313 NavigationEntry* active_entry = controller_.GetActiveEntry();
1314 return (active_entry != NULL &&
1315 active_entry->site_instance() == GetSiteInstance() &&
1316 active_entry->page_id() == page_id);
1317}
1318
[email protected]b2fe07d12010-02-09 14:38:081319void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161320 set_encoding(encoding);
1321 render_view_host()->SetPageEncoding(encoding);
1322}
1323
[email protected]b2fe07d12010-02-09 14:38:081324void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161325 reset_encoding();
1326 render_view_host()->ResetPageEncodingToDefault();
1327}
1328
1329void TabContents::WindowMoveOrResizeStarted() {
1330 render_view_host()->WindowMoveOrResizeStarted();
1331}
1332
[email protected]3f8eb7f2009-10-02 23:58:051333void TabContents::LogNewTabTime(const std::string& event_name) {
1334 // Not all new tab pages get timed. In those cases, we don't have a
1335 // new_tab_start_time_.
1336 if (new_tab_start_time_.is_null())
1337 return;
1338
1339 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441340 MetricEventDurationDetails details(event_name,
1341 static_cast<int>(duration.InMilliseconds()));
1342
[email protected]7ab1e7d62009-10-14 23:32:011343 if (event_name == "Tab.NewTabScriptStart") {
1344 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1345 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1346 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1347 } else if (event_name == "Tab.NewTabOnload") {
1348 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051349 // The new tab page has finished loading; reset it.
1350 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441351 } else {
1352 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051353 }
[email protected]84abba62009-10-07 17:01:441354 NotificationService::current()->Notify(
1355 NotificationType::METRIC_EVENT_DURATION,
1356 Source<TabContents>(this),
1357 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051358}
1359
[email protected]7ab1e7d62009-10-14 23:32:011360void TabContents::OnCloseStarted() {
1361 if (tab_close_start_time_.is_null())
1362 tab_close_start_time_ = base::TimeTicks::Now();
1363}
1364
[email protected]c37e3b62010-01-22 00:15:171365TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171366 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161367
1368 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081369 if (extension_app_)
1370 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161371 else if (entry)
1372 tab_nav.SetFromNavigationEntry(*entry);
1373
[email protected]c37e3b62010-01-22 00:15:171374 std::vector<TabNavigation> navigations;
1375 navigations.push_back(tab_nav);
1376
1377 TabContents* new_contents =
1378 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081379 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171380 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171381
[email protected]98aa0b52010-05-06 17:03:081382 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161383 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1384
[email protected]c37e3b62010-01-22 00:15:171385 return new_contents;
1386}
1387
[email protected]0de80162010-02-03 04:52:351388// Resets the |content_blocked_| array.
1389void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491390 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351391 content_blocked_[i] = false;
1392}
1393
[email protected]96d185d2009-04-24 03:28:541394// Notifies the RenderWidgetHost instance about the fact that the page is
1395// loading, or done loading and calls the base implementation.
1396void TabContents::SetIsLoading(bool is_loading,
1397 LoadNotificationDetails* details) {
1398 if (is_loading == is_loading_)
1399 return;
1400
1401 if (!is_loading) {
1402 load_state_ = net::LOAD_STATE_IDLE;
1403 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561404 upload_size_ = 0;
1405 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541406 }
1407
1408 render_manager_.SetIsLoading(is_loading);
1409
1410 is_loading_ = is_loading;
1411 waiting_for_response_ = is_loading;
1412
1413 if (delegate_)
1414 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351415 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541416
1417 NotificationType type = is_loading ? NotificationType::LOAD_START :
1418 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111419 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541420 if (details)
1421 det = Details<LoadNotificationDetails>(details);
1422 NotificationService::current()->Notify(type,
1423 Source<NavigationController>(&controller_),
1424 det);
1425}
1426
[email protected]b6c874582009-05-08 19:38:311427void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291428 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061429 // A page can't spawn popups (or do anything else, either) until its load
1430 // commits, so when we reach here, the popup was spawned by the
1431 // NavigationController's last committed entry, not the active entry. For
1432 // example, if a page opens a popup in an onunload() handler, then the active
1433 // entry is the page to be loaded as we navigate away from the unloading
1434 // page. For this reason, we can't use GetURL() to get the opener URL,
1435 // because it returns the active entry.
1436 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1437 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1438
1439 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491440 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061441 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491442 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1443 } else {
1444 if (!blocked_popups_)
1445 blocked_popups_ = new BlockedPopupContainer(this);
1446 blocked_popups_->AddTabContents(new_contents, initial_pos);
1447 }
[email protected]b9681312008-11-07 00:08:261448}
[email protected]616ed5a2008-11-21 22:27:241449
1450namespace {
1451bool TransitionIsReload(PageTransition::Type transition) {
1452 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1453}
1454}
1455
1456void TabContents::ExpireInfoBars(
1457 const NavigationController::LoadCommittedDetails& details) {
1458 // Only hide InfoBars when the user has done something that makes the main
1459 // frame load. We don't want various automatic or subframe navigations making
1460 // it disappear.
1461 if (!details.is_user_initiated_main_frame_load())
1462 return;
1463
[email protected]f86a07022008-11-25 01:06:051464 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241465 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051466 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241467 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241468 }
1469}
[email protected]fdd61c62009-04-22 19:22:571470
[email protected]96d185d2009-04-24 03:28:541471DOMUI* TabContents::GetDOMUIForCurrentState() {
1472 // When there is a pending navigation entry, we want to use the pending DOMUI
1473 // that goes along with it to control the basic flags. For example, we want to
1474 // show the pending URL in the URL bar, so we want the display_url flag to
1475 // be from the pending entry.
1476 //
1477 // The confusion comes because there are multiple possibilities for the
1478 // initial load in a tab as a side effect of the way the RenderViewHostManager
1479 // works.
1480 //
1481 // - For the very first tab the load looks "normal". The new tab DOM UI is
1482 // the pending one, and we want it to apply here.
1483 //
1484 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1485 // get switched to the one previously associated with the new tab pages.
1486 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1487 // have a committed DOM UI in this case.
1488 //
1489 // This condition handles all of these cases:
1490 //
1491 // - First load in first tab: no committed nav entry + pending nav entry +
1492 // pending dom ui:
1493 // -> Use pending DOM UI if any.
1494 //
1495 // - First load in second tab: no committed nav entry + pending nav entry +
1496 // no pending DOM UI:
1497 // -> Use the committed DOM UI if any.
1498 //
1499 // - Second navigation in any tab: committed nav entry + pending nav entry:
1500 // -> Use pending DOM UI if any.
1501 //
1502 // - Normal state with no load: committed nav entry + no pending nav entry:
1503 // -> Use committed DOM UI.
1504 if (controller_.pending_entry() &&
1505 (controller_.GetLastCommittedEntry() ||
1506 render_manager_.pending_dom_ui()))
1507 return render_manager_.pending_dom_ui();
1508 return render_manager_.dom_ui();
1509}
[email protected]420ae012009-04-24 05:16:321510
1511void TabContents::DidNavigateMainFramePostCommit(
1512 const NavigationController::LoadCommittedDetails& details,
1513 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441514 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1515 // If this is a window.open navigation, use the same DOMUI as the renderer
1516 // that opened the window, as long as both renderers have the same
1517 // privileges.
1518 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1519 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1520 // dom_ui might be NULL if the URL refers to a non-existent extension.
1521 if (dom_ui) {
1522 render_manager_.SetDOMUIPostCommit(dom_ui);
1523 dom_ui->RenderViewCreated(render_view_host());
1524 }
1525 }
1526 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1527 }
1528
[email protected]420ae012009-04-24 05:16:321529 if (details.is_user_initiated_main_frame_load()) {
1530 // Clear the status bubble. This is a workaround for a bug where WebKit
1531 // doesn't let us know that the cursor left an element during a
1532 // transition (this is also why the mouse cursor remains as a hand after
1533 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1534 // clear the bubble when a user navigates to a named anchor in the same
1535 // page.
1536 UpdateTargetURL(details.entry->page_id(), GURL());
1537
1538 // UpdateHelpersForDidNavigate will handle the case where the password_form
1539 // origin is valid.
1540 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1541 // cleaned up and covered by tests.
1542 if (!params.password_form.origin.is_valid())
1543 GetPasswordManager()->DidNavigate();
1544 }
1545
1546 // The keyword generator uses the navigation entries, so must be called after
1547 // the commit.
1548 GenerateKeywordIfNecessary(params);
1549
1550 // Allow the new page to set the title again.
1551 received_page_title_ = false;
1552
1553 // Get the favicon, either from history or request it from the net.
1554 fav_icon_helper_.FetchFavIcon(details.entry->url());
1555
[email protected]0de80162010-02-03 04:52:351556 // Clear all page actions, blocked content notifications and browser actions
1557 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141558 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081559 ExtensionsService* service = profile()->GetExtensionsService();
1560 if (service) {
1561 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571562 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081563 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521564 if (browser_action) {
1565 browser_action->ClearAllValuesForTab(controller().session_id().id());
1566 NotificationService::current()->Notify(
1567 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571568 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521569 NotificationService::NoDetails());
1570 }
[email protected]92c6f9b92009-10-24 04:35:081571
[email protected]5d246db22009-10-27 06:17:571572 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521573 service->extensions()->at(i)->page_action();
1574 if (page_action) {
1575 page_action->ClearAllValuesForTab(controller().session_id().id());
1576 PageActionStateChanged();
1577 }
[email protected]92c6f9b92009-10-24 04:35:081578 }
[email protected]aece2c7f2009-08-27 20:43:171579 }
[email protected]0de80162010-02-03 04:52:351580
1581 // Close blocked popups.
1582 if (blocked_popups_) {
1583 AutoReset auto_reset(&dont_notify_render_view_, true);
1584 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461585 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351586 }
1587
1588 // Clear "blocked" flags.
1589 ClearBlockedContentSettings();
[email protected]777a7b62010-05-11 13:28:161590 geolocation_settings_state_.DidNavigate(details);
[email protected]0de80162010-02-03 04:52:351591 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241592 delegate_->OnContentSettingsChange(this);
[email protected]f17a0ee2010-05-17 17:38:471593
1594 // Once the main frame is navigated, we're no longer considered to have
1595 // displayed insecure content.
1596 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171597 }
[email protected]ce5c4502009-05-06 16:46:111598
[email protected]8cc8d492010-02-02 10:40:491599 // Close constrained windows if necessary.
1600 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1601 details.previous_url, details.entry->url()))
1602 CloseConstrainedWindows();
1603
[email protected]420ae012009-04-24 05:16:321604 // Update the starred state.
1605 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531606
1607 // Clear the cache of forms in AutoFill.
1608 if (autofill_manager_.get())
1609 autofill_manager_->Reset();
[email protected]a888b29e62010-04-01 13:38:571610
1611 // The url likely changed, see if there is an extension whose extent contains
1612 // the current page.
[email protected]98aa0b52010-05-06 17:03:081613 UpdateExtensionAppForCurrentPage();
[email protected]420ae012009-04-24 05:16:321614}
1615
1616void TabContents::DidNavigateAnyFramePostCommit(
1617 RenderViewHost* render_view_host,
1618 const NavigationController::LoadCommittedDetails& details,
1619 const ViewHostMsg_FrameNavigate_Params& params) {
1620 // If we navigate, start showing messages again. This does nothing to prevent
1621 // a malicious script from spamming messages, since the script could just
1622 // reload the page to stop blocking.
1623 suppress_javascript_messages_ = false;
1624
[email protected]420ae012009-04-24 05:16:321625 // Notify the password manager of the navigation or form submit.
1626 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1627 // cleaned up and covered by tests.
1628 if (params.password_form.origin.is_valid())
1629 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551630
1631 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011632 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1633 details.type == NavigationType::SAME_PAGE;
1634 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321635}
1636
[email protected]8cc8d492010-02-02 10:40:491637void TabContents::CloseConstrainedWindows() {
1638 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321639 // We use indices instead of iterators in case CloseWindow does something
1640 // that may invalidate an iterator.
1641 int size = static_cast<int>(child_windows_.size());
1642 for (int i = size - 1; i >= 0; --i) {
1643 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441644 if (window) {
[email protected]420ae012009-04-24 05:16:321645 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441646 BlockTabContent(false);
1647 }
[email protected]420ae012009-04-24 05:16:321648 }
1649}
1650
1651void TabContents::UpdateStarredStateForCurrentURL() {
1652 BookmarkModel* model = profile()->GetBookmarkModel();
1653 const bool old_state = is_starred_;
1654 is_starred_ = (model && model->IsBookmarked(GetURL()));
1655
1656 if (is_starred_ != old_state && delegate())
1657 delegate()->URLStarredChanged(this, is_starred_);
1658}
1659
1660void TabContents::UpdateAlternateErrorPageURL() {
1661 GURL url = GetAlternateErrorPageURL();
1662 render_view_host()->SetAlternateErrorPageURL(url);
1663}
1664
1665void TabContents::UpdateWebPreferences() {
1666 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1667}
1668
1669void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1670 RenderViewHost* rvh) {
1671 // If we are creating a RVH for a restored controller, then we might
1672 // have more page IDs than the SiteInstance's current max page ID. We must
1673 // make sure that the max page ID is larger than any restored page ID.
1674 // Note that it is ok for conflicting page IDs to exist in another tab
1675 // (i.e., NavigationController), but if any page ID is larger than the max,
1676 // the back/forward list will get confused.
1677 int max_restored_page_id = controller_.max_restored_page_id();
1678 if (max_restored_page_id > 0) {
1679 int curr_max_page_id = site_instance->max_page_id();
1680 if (max_restored_page_id > curr_max_page_id) {
1681 // Need to update the site instance immediately.
1682 site_instance->UpdateMaxPageID(max_restored_page_id);
1683
1684 // Also tell the renderer to update its internal representation. We
1685 // need to reserve enough IDs to make all restored page IDs less than
1686 // the max.
1687 if (curr_max_page_id < 0)
1688 curr_max_page_id = 0;
1689 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1690 }
1691 }
1692}
1693
1694void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541695 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471696 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321697 const ViewHostMsg_FrameNavigate_Params& params) {
1698 if (profile()->IsOffTheRecord())
1699 return;
1700
1701 // Add to history service.
1702 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1703 if (hs) {
1704 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541705 virtual_url != params.url) {
1706 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321707 // types of URLs, we will display a magic URL that is different from where
1708 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541709 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1710 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321711 // to sub-frames.
1712 std::vector<GURL> redirects = params.redirects;
1713 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541714 redirects.back() = virtual_url;
1715 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471716 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321717 } else {
1718 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471719 params.transition, params.redirects,
1720 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321721 }
1722 }
1723}
1724
1725bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1726 const std::wstring& title) {
1727 // For file URLs without a title, use the pathname instead. In the case of a
1728 // synthesized title, we don't want the update to count toward the "one set
1729 // per page of the title to history."
1730 std::wstring final_title;
1731 bool explicit_set;
1732 if (entry->url().SchemeIsFile() && title.empty()) {
1733 final_title = UTF8ToWide(entry->url().ExtractFileName());
1734 explicit_set = false; // Don't count synthetic titles toward the set limit.
1735 } else {
1736 TrimWhitespace(title, TRIM_ALL, &final_title);
1737 explicit_set = true;
1738 }
1739
1740 if (final_title == UTF16ToWideHack(entry->title()))
1741 return false; // Nothing changed, don't bother.
1742
1743 entry->set_title(WideToUTF16Hack(final_title));
1744
1745 // Update the history system for this page.
1746 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1747 HistoryService* hs =
1748 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1749 if (hs)
[email protected]ebe89e062009-08-13 23:16:541750 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321751
1752 // Don't allow the title to be saved again for explicitly set ones.
1753 received_page_title_ = explicit_set;
1754 }
1755
1756 // Lastly, set the title for the view.
1757 view_->SetPageTitle(final_title);
1758
[email protected]cbc0e1b2010-04-12 18:33:041759 NotificationService::current()->Notify(
1760 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1761 Source<TabContents>(this),
1762 NotificationService::NoDetails());
1763
[email protected]420ae012009-04-24 05:16:321764 return true;
1765}
1766
1767void TabContents::NotifySwapped() {
1768 // After sending out a swap notification, we need to send a disconnect
1769 // notification so that clients that pick up a pointer to |this| can NULL the
1770 // pointer. See Bug 1230284.
1771 notify_disconnection_ = true;
1772 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341773 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221774 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321775 NotificationService::NoDetails());
1776}
1777
1778void TabContents::NotifyConnected() {
1779 notify_disconnection_ = true;
1780 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341781 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221782 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321783 NotificationService::NoDetails());
1784}
1785
1786void TabContents::NotifyDisconnected() {
1787 if (!notify_disconnection_)
1788 return;
1789
1790 notify_disconnection_ = false;
1791 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341792 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221793 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321794 NotificationService::NoDetails());
1795}
1796
1797void TabContents::GenerateKeywordIfNecessary(
1798 const ViewHostMsg_FrameNavigate_Params& params) {
1799 if (!params.searchable_form_url.is_valid())
1800 return;
1801
1802 if (profile()->IsOffTheRecord())
1803 return;
1804
1805 int last_index = controller_.last_committed_entry_index();
1806 // When there was no previous page, the last index will be 0. This is
1807 // normally due to a form submit that opened in a new tab.
1808 // TODO(brettw) bug 916126: we should support keywords when form submits
1809 // happen in new tabs.
1810 if (last_index <= 0)
1811 return;
1812 const NavigationEntry* previous_entry =
1813 controller_.GetEntryAtIndex(last_index - 1);
1814 if (IsFormSubmit(previous_entry)) {
1815 // Only generate a keyword if the previous page wasn't itself a form
1816 // submit.
1817 return;
1818 }
1819
1820 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1821 previous_entry->user_typed_url() : previous_entry->url();
1822 std::wstring keyword =
1823 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1824 if (keyword.empty())
1825 return;
1826
1827 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1828 if (!url_model)
1829 return;
1830
1831 if (!url_model->loaded()) {
1832 url_model->Load();
1833 return;
1834 }
1835
1836 const TemplateURL* current_url;
1837 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1838 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1839 return;
1840
1841 if (current_url) {
1842 if (current_url->originating_url().is_valid()) {
1843 // The existing keyword was generated from an OpenSearch description
1844 // document, don't regenerate.
1845 return;
1846 }
1847 url_model->Remove(current_url);
1848 }
1849 TemplateURL* new_url = new TemplateURL();
1850 new_url->set_keyword(keyword);
1851 new_url->set_short_name(keyword);
1852 new_url->SetURL(url, 0, 0);
1853 new_url->add_input_encoding(params.searchable_form_encoding);
1854 DCHECK(controller_.GetLastCommittedEntry());
1855 const GURL& favicon_url =
1856 controller_.GetLastCommittedEntry()->favicon().url();
1857 if (favicon_url.is_valid()) {
1858 new_url->SetFavIconURL(favicon_url);
1859 } else {
1860 // The favicon url isn't valid. This means there really isn't a favicon,
1861 // or the favicon url wasn't obtained before the load started. This assumes
1862 // the later.
1863 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1864 // its url.
1865 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1866 }
1867 new_url->set_safe_for_autoreplace(true);
1868 url_model->Add(new_url);
1869}
1870
[email protected]bf5c2ff392009-07-08 16:24:331871void TabContents::OnUserGesture() {
1872 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1873 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1874 if (drm)
1875 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491876 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331877 controller_.OnUserGesture();
1878}
1879
1880void TabContents::OnFindReply(int request_id,
1881 int number_of_matches,
1882 const gfx::Rect& selection_rect,
1883 int active_match_ordinal,
1884 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421885 // Ignore responses for requests that have been aborted.
1886 if (find_op_aborted_)
1887 return;
1888
[email protected]bf5c2ff392009-07-08 16:24:331889 // Ignore responses for requests other than the one we have most recently
1890 // issued. That way we won't act on stale results when the user has
1891 // already typed in another query.
1892 if (request_id != current_find_request_id_)
1893 return;
1894
1895 if (number_of_matches == -1)
1896 number_of_matches = last_search_result_.number_of_matches();
1897 if (active_match_ordinal == -1)
1898 active_match_ordinal = last_search_result_.active_match_ordinal();
1899
1900 gfx::Rect selection = selection_rect;
1901 if (selection.IsEmpty())
1902 selection = last_search_result_.selection_rect();
1903
1904 // Notify the UI, automation and any other observers that a find result was
1905 // found.
1906 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1907 selection, active_match_ordinal,
1908 final_update);
1909 NotificationService::current()->Notify(
1910 NotificationType::FIND_RESULT_AVAILABLE,
1911 Source<TabContents>(this),
1912 Details<FindNotificationDetails>(&last_search_result_));
1913}
1914
1915void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381916 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1917 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331918}
1919
[email protected]bf5c2ff392009-07-08 16:24:331920void TabContents::OnMissingPluginStatus(int status) {
1921#if defined(OS_WIN)
1922// TODO(PORT): pull in when plug-ins work
1923 GetPluginInstaller()->OnMissingPluginStatus(status);
1924#endif
1925}
1926
1927void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331928 DCHECK(!plugin_path.value().empty());
1929
1930 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351931#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331932 scoped_ptr<FileVersionInfo> version_info(
1933 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1934 if (version_info.get()) {
1935 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371936 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331937 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371938#if defined(OS_MACOSX)
1939 // Many plugins on the Mac have .plugin in the actual name, which looks
1940 // terrible, so look for that and strip it off if present.
1941 const std::wstring plugin_extension(L".plugin");
1942 if (EndsWith(plugin_name, plugin_extension, true))
1943 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1944#endif // OS_MACOSX
1945 }
[email protected]bf5c2ff392009-07-08 16:24:331946 }
[email protected]4a560ed2009-07-13 23:35:261947#else
1948 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1949#endif
[email protected]bf5c2ff392009-07-08 16:24:331950 AddInfoBar(new SimpleAlertInfoBarDelegate(
1951 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]938e1f92010-04-01 18:09:421952 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331953}
1954
1955void TabContents::OnCrashedWorker() {
1956 AddInfoBar(new SimpleAlertInfoBarDelegate(
1957 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421958 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331959}
1960
1961void TabContents::OnDidGetApplicationInfo(
1962 int32 page_id,
1963 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511964 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331965
[email protected]ed5431872009-11-17 08:39:511966 if (delegate())
1967 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331968}
1969
[email protected]a2cf65eb2010-01-18 08:20:381970void TabContents::OnPageContents(const GURL& url,
1971 int renderer_process_id,
1972 int32 page_id,
[email protected]a8a81292010-01-21 00:32:451973 const std::wstring& contents,
1974 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381975 // Don't index any https pages. People generally don't want their bank
1976 // accounts, etc. indexed on their computer, especially since some of these
1977 // things are not marked cachable.
1978 // TODO(brettw) we may want to consider more elaborate heuristics such as
1979 // the cachability of the page. We may also want to consider subframes (this
1980 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271981 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1982 // content indexing for chromeos in some future releases.
1983#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381984 if (!url.SchemeIsSecure()) {
1985 Profile* p = profile();
1986 if (p && !p->IsOffTheRecord()) {
1987 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1988 if (hs)
1989 hs->SetPageContents(url, contents);
1990 }
1991 }
[email protected]ccd40a52010-05-11 16:15:271992#endif
[email protected]a8a81292010-01-21 00:32:451993
[email protected]3b1c1812010-02-12 21:53:551994 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451995
1996 std::string lang = language;
1997 NotificationService::current()->Notify(
1998 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151999 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452000 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382001}
2002
[email protected]7e0831b2010-02-01 08:45:152003void TabContents::OnPageTranslated(int32 page_id,
2004 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162005 const std::string& translated_lang,
2006 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552007 language_state_.set_current_language(translated_lang);
2008 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162009 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152010 NotificationService::current()->Notify(
2011 NotificationType::PAGE_TRANSLATED,
2012 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162013 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152014}
2015
[email protected]bf5c2ff392009-07-08 16:24:332016void TabContents::DidStartProvisionalLoadForFrame(
2017 RenderViewHost* render_view_host,
2018 bool is_main_frame,
2019 const GURL& url) {
2020 ProvisionalLoadDetails details(is_main_frame,
2021 controller_.IsURLInPageNavigation(url),
2022 url, std::string(), false);
2023 NotificationService::current()->Notify(
2024 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2025 Source<NavigationController>(&controller_),
2026 Details<ProvisionalLoadDetails>(&details));
2027}
2028
2029void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202030 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332031 NotificationService::current()->Notify(
2032 NotificationType::RESOURCE_RESPONSE_STARTED,
2033 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202034 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332035}
2036
[email protected]3dbb80b2010-02-09 22:41:202037void TabContents::DidRedirectResource(
2038 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332039 NotificationService::current()->Notify(
2040 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2041 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202042 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332043}
2044
2045void TabContents::DidLoadResourceFromMemoryCache(
2046 const GURL& url,
2047 const std::string& frame_origin,
2048 const std::string& main_frame_origin,
2049 const std::string& security_info) {
2050 // Send out a notification that we loaded a resource from our memory cache.
2051 int cert_id = 0, cert_status = 0, security_bits = 0;
2052 SSLManager::DeserializeSecurityInfo(security_info,
2053 &cert_id, &cert_status,
2054 &security_bits);
2055 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162056 GetRenderProcessHost()->id(), cert_id,
2057 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332058
2059 NotificationService::current()->Notify(
2060 NotificationType::LOAD_FROM_MEMORY_CACHE,
2061 Source<NavigationController>(&controller_),
2062 Details<LoadFromMemoryCacheDetails>(&details));
2063}
2064
[email protected]e3d60e5d2009-09-25 21:08:292065void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472066 displayed_insecure_content_ = true;
2067 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292068}
2069
2070void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592071 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292072}
2073
[email protected]bf5c2ff392009-07-08 16:24:332074void TabContents::DidFailProvisionalLoadWithError(
2075 RenderViewHost* render_view_host,
2076 bool is_main_frame,
2077 int error_code,
2078 const GURL& url,
2079 bool showing_repost_interstitial) {
2080 if (net::ERR_ABORTED == error_code) {
2081 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2082 // This means that the interstitial won't be torn down properly, which is
2083 // bad. But if we have an interstitial, go back to another tab type, and
2084 // then load the same interstitial again, we could end up getting the first
2085 // interstitial's "failed" message (as a result of the cancel) when we're on
2086 // the second one.
2087 //
2088 // We can't tell this apart, so we think we're tearing down the current page
2089 // which will cause a crash later one. There is also some code in
2090 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2091 // out because of this problem.
2092 //
2093 // http://code.google.com/p/chromium/issues/detail?id=2855
2094 // Because this will not tear down the interstitial properly, if "back" is
2095 // back to another tab type, the interstitial will still be somewhat alive
2096 // in the previous tab type. If you navigate somewhere that activates the
2097 // tab with the interstitial again, you'll see a flash before the new load
2098 // commits of the interstitial page.
2099 if (showing_interstitial_page()) {
2100 LOG(WARNING) << "Discarding message during interstitial.";
2101 return;
2102 }
2103
2104 // This will discard our pending entry if we cancelled the load (e.g., if we
2105 // decided to download the file instead of load it). Only discard the
2106 // pending entry if the URLs match, otherwise the user initiated a navigate
2107 // before the page loaded so that the discard would discard the wrong entry.
2108 NavigationEntry* pending_entry = controller_.pending_entry();
2109 if (pending_entry && pending_entry->url() == url) {
2110 controller_.DiscardNonCommittedEntries();
2111 // Update the URL display.
2112 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2113 }
2114
2115 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2116 }
2117
2118 // Send out a notification that we failed a provisional load with an error.
2119 ProvisionalLoadDetails details(is_main_frame,
2120 controller_.IsURLInPageNavigation(url),
2121 url, std::string(), false);
2122 details.set_error_code(error_code);
2123
2124 NotificationService::current()->Notify(
2125 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2126 Source<NavigationController>(&controller_),
2127 Details<ProvisionalLoadDetails>(&details));
2128}
2129
2130void TabContents::DocumentLoadedInFrame() {
2131 controller_.DocumentLoadedInFrame();
[email protected]b3df5a42010-05-11 14:31:092132 if (renderer_accessible_ && !requested_accessibility_tree_) {
2133 render_view_host()->RequestAccessibilityTree();
2134 requested_accessibility_tree_ = true;
2135 }
[email protected]bf5c2ff392009-07-08 16:24:332136}
2137
[email protected]0de80162010-02-03 04:52:352138void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]b1235062010-03-25 17:31:272139 // TODO(joth): remove once fully implemented.
2140 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION);
[email protected]0de80162010-02-03 04:52:352141 content_blocked_[type] = true;
2142 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242143 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352144}
2145
[email protected]614c0e12010-03-25 10:12:562146void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2147 bool allowed) {
[email protected]777a7b62010-05-11 13:28:162148 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
2149 allowed);
[email protected]614c0e12010-03-25 10:12:562150 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242151 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562152}
2153
[email protected]8d3347f2009-07-09 22:00:212154RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322155 return view_.get();
2156}
2157
[email protected]8d3347f2009-07-09 22:00:212158RenderViewHostDelegate::RendererManagement*
2159TabContents::GetRendererManagementDelegate() {
2160 return &render_manager_;
2161}
2162
[email protected]bf5c2ff392009-07-08 16:24:332163RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212164 TabContents::GetBrowserIntegrationDelegate() {
2165 return this;
[email protected]bf5c2ff392009-07-08 16:24:332166}
2167
[email protected]8d3347f2009-07-09 22:00:212168RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2169 return this;
[email protected]bf5c2ff392009-07-08 16:24:332170}
2171
[email protected]8d3347f2009-07-09 22:00:212172RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322173 return save_package_.get(); // May be NULL, but we can return NULL.
2174}
2175
[email protected]8d3347f2009-07-09 22:00:212176RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2177 return &printing_;
2178}
2179
2180RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2181 return &fav_icon_helper_;
2182}
2183
[email protected]e8dbd674b2010-03-11 18:34:402184RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452185 if (autocomplete_history_manager_.get() == NULL)
2186 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2187 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332188}
2189
[email protected]21674df2009-10-28 19:51:212190RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342191 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212192}
2193
[email protected]fd571bb2010-03-19 01:23:542194AutomationResourceRoutingDelegate*
2195TabContents::GetAutomationResourceRoutingDelegate() {
2196 return delegate();
2197}
2198
[email protected]ced90ae12010-02-20 02:06:162199RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2200 return bookmark_drag_;
2201}
2202
2203void TabContents::SetBookmarkDragDelegate(
2204 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2205 bookmark_drag_ = bookmark_drag;
2206}
2207
[email protected]93623c5d2009-12-10 21:40:322208RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462209 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512210}
2211
[email protected]57c6a652009-05-04 07:58:342212TabContents* TabContents::GetAsTabContents() {
2213 return this;
2214}
2215
[email protected]7b291f92009-08-14 05:43:532216ViewType::Type TabContents::GetRenderViewType() const {
2217 return ViewType::TAB_CONTENTS;
2218}
2219
2220int TabContents::GetBrowserWindowID() const {
2221 return controller().window_id().id();
2222}
2223
[email protected]420ae012009-04-24 05:16:322224void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062225 NotificationService::current()->Notify(
2226 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2227 Source<TabContents>(this),
2228 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322229 NavigationEntry* entry = controller_.GetActiveEntry();
2230 if (!entry)
2231 return;
2232
2233 // When we're creating views, we're still doing initial setup, so we always
2234 // use the pending DOM UI rather than any possibly existing committed one.
2235 if (render_manager_.pending_dom_ui()) {
2236 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2237 }
2238
2239 if (entry->IsViewSourceMode()) {
2240 // Put the renderer in view source mode.
2241 render_view_host->Send(
2242 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2243 }
[email protected]0666aef2009-05-13 19:48:082244
2245 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322246}
2247
2248void TabContents::RenderViewReady(RenderViewHost* rvh) {
2249 if (rvh != render_view_host()) {
2250 // Don't notify the world, since this came from a renderer in the
2251 // background.
2252 return;
2253 }
2254
2255 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302256 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322257 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302258
2259 // Restore the focus to the tab (otherwise the focus will be on the top
2260 // window).
2261 if (was_crashed && !FocusLocationBarByDefault())
2262 Focus();
[email protected]420ae012009-04-24 05:16:322263}
2264
2265void TabContents::RenderViewGone(RenderViewHost* rvh) {
2266 // Ask the print preview if this renderer was valuable.
2267 if (!printing_.OnRenderViewGone(rvh))
2268 return;
2269 if (rvh != render_view_host()) {
2270 // The pending page's RenderViewHost is gone.
2271 return;
2272 }
2273
2274 SetIsLoading(false, NULL);
2275 NotifyDisconnected();
2276 SetIsCrashed(true);
2277
[email protected]ff9efc62010-02-18 22:10:542278 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212279 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542280 RemoveInfoBar(GetInfoBarDelegateAt(i));
2281
[email protected]8e537302009-06-10 21:19:582282 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552283 // Only do this if we're not in browser shutdown, so that TabContents
2284 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2285 // visible do not flash a sad tab page.
2286 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2287 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322288
2289 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002290 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322291}
2292
[email protected]2e4633c2009-07-09 16:58:062293void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2294 NotificationService::current()->Notify(
2295 NotificationType::RENDER_VIEW_HOST_DELETED,
2296 Source<TabContents>(this),
2297 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482298 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062299}
2300
[email protected]420ae012009-04-24 05:16:322301void TabContents::DidNavigate(RenderViewHost* rvh,
2302 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372303 int extra_invalidate_flags = 0;
2304
[email protected]b3df5a42010-05-11 14:31:092305 requested_accessibility_tree_ = false;
2306
[email protected]8030f012009-09-25 18:09:372307 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352308 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372309 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2310
[email protected]420ae012009-04-24 05:16:322311 render_manager_.DidNavigateMainFrame(rvh);
2312
[email protected]20ede072009-10-06 00:28:352313 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372314 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2315 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2316 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2317 }
2318
[email protected]420ae012009-04-24 05:16:322319 // Update the site of the SiteInstance if it doesn't have one yet.
2320 if (!GetSiteInstance()->has_site())
2321 GetSiteInstance()->SetSite(params.url);
2322
2323 // Need to update MIME type here because it's referred to in
2324 // UpdateNavigationCommands() called by RendererDidNavigate() to
2325 // determine whether or not to enable the encoding menu.
2326 // It's updated only for the main frame. For a subframe,
2327 // RenderView::UpdateURL does not set params.contents_mime_type.
2328 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2329 // TODO(jungshik): Add a test for the encoding menu to avoid
2330 // regressing it again.
2331 if (PageTransition::IsMainFrame(params.transition))
2332 contents_mime_type_ = params.contents_mime_type;
2333
2334 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372335 bool did_navigate = controller_.RendererDidNavigate(
2336 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392337
2338 // Update history. Note that this needs to happen after the entry is complete,
2339 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352340 if (params.should_update_history &&
2341 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392342 // Most of the time, the displayURL matches the loaded URL, but for about:
2343 // URLs, we use a data: URL as the real value. We actually want to save
2344 // the about: URL to the history db and keep the data: URL hidden. This is
2345 // what the TabContents' URL getter does.
2346 UpdateHistoryForNavigation(GetURL(), details, params);
2347 }
2348
[email protected]76543b92009-08-31 17:27:452349 if (!did_navigate)
2350 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322351
2352 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2353 // for the appropriate notification (best) or you can add it to
2354 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2355 // necessary, please).
2356
2357 // Run post-commit tasks.
2358 if (details.is_main_frame)
2359 DidNavigateMainFramePostCommit(details, params);
2360 DidNavigateAnyFramePostCommit(rvh, details, params);
2361}
2362
2363void TabContents::UpdateState(RenderViewHost* rvh,
2364 int32 page_id,
2365 const std::string& state) {
2366 DCHECK(rvh == render_view_host());
2367
2368 // We must be prepared to handle state updates for any page, these occur
2369 // when the user is scrolling and entering form data, as well as when we're
2370 // leaving a page, in which case our state may have already been moved to
2371 // the next page. The navigation controller will look up the appropriate
2372 // NavigationEntry and update it when it is notified via the delegate.
2373
2374 int entry_index = controller_.GetEntryIndexWithPageID(
2375 GetSiteInstance(), page_id);
2376 if (entry_index < 0)
2377 return;
2378 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2379
2380 if (state == entry->content_state())
2381 return; // Nothing to update.
2382 entry->set_content_state(state);
2383 controller_.NotifyEntryChanged(entry, entry_index);
2384}
2385
2386void TabContents::UpdateTitle(RenderViewHost* rvh,
2387 int32 page_id, const std::wstring& title) {
2388 // If we have a title, that's a pretty good indication that we've started
2389 // getting useful data.
2390 SetNotWaitingForResponse();
2391
2392 DCHECK(rvh == render_view_host());
2393 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2394 page_id);
2395 if (!entry || !UpdateTitleForEntry(entry, title))
2396 return;
2397
2398 // Broadcast notifications when the UI should be updated.
2399 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032400 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322401}
2402
[email protected]420ae012009-04-24 05:16:322403void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402404 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322405 set_encoding(encoding);
2406}
2407
2408void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2409 if (delegate())
2410 delegate()->UpdateTargetURL(this, url);
2411}
2412
2413void TabContents::UpdateThumbnail(const GURL& url,
2414 const SkBitmap& bitmap,
2415 const ThumbnailScore& score) {
2416 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422417 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492418 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422419 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282420 } else {
2421 HistoryService* hs;
2422 if (!profile()->IsOffTheRecord() &&
2423 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2424 hs->SetPageThumbnail(url, bitmap, score);
2425 }
[email protected]420ae012009-04-24 05:16:322426 }
2427}
2428
[email protected]8922e1f2009-10-03 05:01:262429void TabContents::UpdateInspectorSettings(const std::string& raw_settings) {
[email protected]0df30122009-06-03 12:13:082430 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:262431 UTF8ToWide(raw_settings));
[email protected]0df30122009-06-03 12:13:082432}
2433
[email protected]420ae012009-04-24 05:16:322434void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292435 // The UI may be in an event-tracking loop, such as between the
2436 // mouse-down and mouse-up in text selection or a button click.
2437 // Defer the close until after tracking is complete, so that we
2438 // don't free objects out from under the UI.
2439 // TODO(shess): This could probably be integrated with the
2440 // IsDoingDrag() test below. Punting for now because I need more
2441 // research to understand how this impacts platforms other than Mac.
2442 // TODO(shess): This could get more fine-grained. For instance,
2443 // closing a tab in another window while selecting text in the
2444 // current window's Omnibox should be just fine.
2445 if (view()->IsEventTracking()) {
2446 view()->CloseTabAfterEventTracking();
2447 return;
2448 }
2449
[email protected]24a4d1062009-07-10 23:10:422450 // If we close the tab while we're in the middle of a drag, we'll crash.
2451 // Instead, cancel the drag and close it as soon as the drag ends.
2452 if (view()->IsDoingDrag()) {
2453 view()->CancelDragAndCloseTab();
2454 return;
2455 }
2456
[email protected]420ae012009-04-24 05:16:322457 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2458 if (delegate() && rvh == render_view_host())
2459 delegate()->CloseContents(this);
2460}
2461
2462void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2463 if (delegate() && delegate()->IsPopup(this))
2464 delegate()->MoveContents(this, new_bounds);
2465}
2466
[email protected]7ab1e7d62009-10-14 23:32:012467void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322468 SetIsLoading(true, NULL);
2469}
2470
[email protected]7ab1e7d62009-10-14 23:32:012471void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322472 scoped_ptr<LoadNotificationDetails> details;
2473
2474 NavigationEntry* entry = controller_.GetActiveEntry();
2475 // An entry may not exist for a stop when loading an initial blank page or
2476 // if an iframe injected by script into a blank page finishes loading.
2477 if (entry) {
[email protected]420ae012009-04-24 05:16:322478 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2479
2480 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542481 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322482 entry->transition_type(),
2483 elapsed,
2484 &controller_,
2485 controller_.GetCurrentEntryIndex()));
2486 }
2487
2488 // Tell PasswordManager we've finished a page load, which serves as a
2489 // green light to save pending passwords and reset itself.
2490 GetPasswordManager()->DidStopLoading();
2491
2492 SetIsLoading(false, details.get());
2493}
2494
[email protected]420ae012009-04-24 05:16:322495void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2496 const GURL& source_url,
2497 const GURL& target_url) {
2498 NavigationEntry* entry;
2499 if (page_id == -1)
2500 entry = controller_.pending_entry();
2501 else
2502 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2503 if (!entry || entry->url() != source_url)
2504 return;
2505 entry->set_url(target_url);
2506}
2507
[email protected]420ae012009-04-24 05:16:322508void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2509 WindowOpenDisposition disposition) {
2510 if (render_manager_.dom_ui()) {
2511 // When we're a DOM UI, it will provide a page transition type for us (this
2512 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2513 // generated suggestions).
2514 //
2515 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162516 // want web sites to see a referrer of "chrome://blah" (and some
2517 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322518 // send to the site), so we send no referrer.
2519 OpenURL(url, GURL(), disposition,
2520 render_manager_.dom_ui()->link_transition_type());
2521 } else {
2522 OpenURL(url, referrer, disposition, PageTransition::LINK);
2523 }
2524}
2525
[email protected]1ee614862009-07-06 20:29:182526void TabContents::DomOperationResponse(const std::string& json_string,
2527 int automation_id) {
2528}
2529
[email protected]420ae012009-04-24 05:16:322530void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152531 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392532 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252533 int request_id,
2534 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322535 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442536 // This can happen if someone uses window.open() to open an extension URL
2537 // from a non-extension context.
2538 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322539 return;
2540 }
[email protected]bb64b512010-04-02 21:01:392541 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2542 request_id,
[email protected]811bfe32009-07-01 08:46:252543 has_callback);
[email protected]420ae012009-04-24 05:16:322544}
2545
2546void TabContents::ProcessExternalHostMessage(const std::string& message,
2547 const std::string& origin,
2548 const std::string& target) {
2549 if (delegate())
2550 delegate()->ForwardMessageToExternalHost(message, origin, target);
2551}
2552
[email protected]cdaf8d02010-03-30 19:52:472553void TabContents::RunFileChooser(
2554 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322555 if (!select_file_dialog_.get())
2556 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472557
2558 SelectFileDialog::Type dialog_type;
2559 switch (params.mode) {
2560 case ViewHostMsg_RunFileChooser_Params::Open:
2561 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2562 break;
2563 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2564 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2565 break;
2566 case ViewHostMsg_RunFileChooser_Params::Save:
2567 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2568 break;
2569 default:
[email protected]bed31952010-03-30 20:07:592570 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472571 NOTREACHED();
2572 }
2573 select_file_dialog_->SelectFile(dialog_type, params.title,
2574 params.default_file_name,
[email protected]420ae012009-04-24 05:16:322575 NULL, 0, FILE_PATH_LITERAL(""),
2576 view_->GetTopLevelNativeWindow(), NULL);
2577}
2578
2579void TabContents::RunJavaScriptMessage(
2580 const std::wstring& message,
2581 const std::wstring& default_prompt,
2582 const GURL& frame_url,
2583 const int flags,
2584 IPC::Message* reply_msg,
2585 bool* did_suppress_message) {
2586 // Suppress javascript messages when requested and when inside a constrained
2587 // popup window (because that activates them and breaks them out of the
2588 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552589 // Also suppress messages when showing an interstitial. The interstitial is
2590 // shown over the previous page, we don't want the hidden page dialogs to
2591 // interfere with the interstitial.
2592 bool suppress_this_message = suppress_javascript_messages_ ||
2593 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322594 if (delegate())
2595 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312596 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322597
2598 *did_suppress_message = suppress_this_message;
2599
2600 if (!suppress_this_message) {
2601 base::TimeDelta time_since_last_message(
2602 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2603 bool show_suppress_checkbox = false;
2604 // Show a checkbox offering to suppress further messages if this message is
2605 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2606 if (time_since_last_message <
2607 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2608 show_suppress_checkbox = true;
2609
[email protected]d82ed61e2009-06-16 02:46:222610 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322611 show_suppress_checkbox, reply_msg);
2612 } else {
2613 // If we are suppressing messages, just reply as is if the user immediately
2614 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542615 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322616 }
2617}
2618
2619void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2620 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012621 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222622 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322623}
2624
2625void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2626 const std::string& json_arguments,
2627 IPC::Message* reply_msg) {
2628 if (delegate()) {
2629 HtmlDialogUIDelegate* dialog_delegate =
2630 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222631 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322632 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2633 }
2634}
2635
[email protected]4d44a1c2010-04-28 19:20:412636void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562637 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412638 GetPasswordManager()->PasswordFormsFound(forms);
2639}
2640
2641void TabContents::PasswordFormsVisible(
2642 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2643 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322644}
2645
[email protected]420ae012009-04-24 05:16:322646// Checks to see if we should generate a keyword based on the OSDD, and if
2647// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2648void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2649 int32 page_id, const GURL& url,
2650 bool autodetected) {
2651 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2652 DCHECK(url.is_valid());
2653 if (!IsActiveEntry(page_id))
2654 return;
2655 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2656 if (!url_model)
2657 return;
2658 if (!url_model->loaded()) {
2659 url_model->Load();
2660 return;
2661 }
2662 if (!profile()->GetTemplateURLFetcher())
2663 return;
2664
2665 if (profile()->IsOffTheRecord())
2666 return;
2667
2668 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2669 DCHECK(entry);
2670
2671 const NavigationEntry* base_entry = entry;
2672 if (IsFormSubmit(base_entry)) {
2673 // If the current page is a form submit, find the last page that was not
2674 // a form submit and use its url to generate the keyword from.
2675 int index = controller_.last_committed_entry_index() - 1;
2676 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2677 index--;
2678 if (index >= 0)
2679 base_entry = controller_.GetEntryAtIndex(index);
2680 else
2681 base_entry = NULL;
2682 }
2683
2684 // We want to use the user typed URL if available since that represents what
2685 // the user typed to get here, and fall back on the regular URL if not.
2686 if (!base_entry)
2687 return;
2688 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2689 base_entry->user_typed_url() : base_entry->url();
2690 if (!keyword_url.is_valid())
2691 return;
2692 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2693 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532694
2695 // For JS added OSDD empty keyword is OK because we will generate keyword
2696 // later from OSDD content.
2697 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322698 return;
2699 const TemplateURL* template_url =
2700 url_model->GetTemplateURLForKeyword(keyword);
2701 if (template_url && (!template_url->safe_for_autoreplace() ||
2702 template_url->originating_url() == url)) {
2703 // Either there is a user created TemplateURL for this keyword, or the
2704 // keyword has the same OSDD url and we've parsed it.
2705 return;
2706 }
2707
2708 // Download the OpenSearch description document. If this is successful a
2709 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322710 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2711 keyword,
2712 url,
2713 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162714 this,
[email protected]420ae012009-04-24 05:16:322715 autodetected);
2716}
2717
[email protected]420ae012009-04-24 05:16:322718GURL TabContents::GetAlternateErrorPageURL() const {
2719 GURL url;
2720 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2721 if (profile()->IsOffTheRecord())
2722 return url;
2723
2724 PrefService* prefs = profile()->GetPrefs();
2725 DCHECK(prefs);
2726 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152727 url = google_util::AppendGoogleLocaleParam(
2728 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322729 url = google_util::AppendGoogleTLDParam(url);
2730 }
2731 return url;
2732}
2733
2734WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062735 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552736 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062737 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322738}
2739
[email protected]fa1cf0b82010-01-15 21:49:442740void TabContents::OnIgnoredUIEvent() {
2741 if (constrained_window_count()) {
2742 ConstrainedWindow* window = *constrained_window_begin();
2743 window->FocusConstrainedWindow();
2744 }
2745}
2746
[email protected]420ae012009-04-24 05:16:322747void TabContents::OnJSOutOfMemory() {
2748 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422749 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322750}
2751
[email protected]420ae012009-04-24 05:16:322752void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2753 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342754 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322755 // delivered to a pending RenderViewHost. We must first run the onunload
2756 // handler of the old RenderViewHost before we can allow it to proceed.
2757 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2758 new_request_id);
2759}
2760
2761bool TabContents::CanBlur() const {
2762 return delegate() ? delegate()->CanBlur() : true;
2763}
2764
2765gfx::Rect TabContents::GetRootWindowResizerRect() const {
2766 if (delegate())
2767 return delegate()->GetRootWindowResizerRect();
2768 return gfx::Rect();
2769}
2770
2771void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2772 bool is_during_unload) {
2773 if (is_during_unload) {
2774 // Hang occurred while firing the beforeunload/unload handler.
2775 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112776 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322777
2778 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2779 return;
2780
2781 // If the tab hangs in the beforeunload/unload handler there's really
2782 // nothing we can do to recover. Pretend the unload listeners have
2783 // all fired and close the tab. If the hang is in the beforeunload handler
2784 // then the user will not have the option of cancelling the close.
2785 Close(rvh);
2786 return;
2787 }
2788
2789 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002790 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322791}
2792
2793void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002794 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322795}
2796
2797void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562798 net::LoadState load_state,
2799 uint64 upload_position,
2800 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322801 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562802 upload_position_ = upload_position;
2803 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292804 std::wstring languages =
2805 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292806 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532807 load_state_host_ =
2808 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322809 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2810 SetNotWaitingForResponse();
2811 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502812 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322813}
2814
[email protected]1ee614862009-07-06 20:29:182815bool TabContents::IsExternalTabContainer() const {
2816 if (!delegate())
2817 return false;
2818
2819 return delegate()->IsExternalTabContainer();
2820}
2821
[email protected]1ee614862009-07-06 20:29:182822void TabContents::DidInsertCSS() {
2823 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322824}
2825
[email protected]130efb02009-09-18 18:54:352826void TabContents::FocusedNodeChanged() {
2827 NotificationService::current()->Notify(
2828 NotificationType::FOCUS_CHANGED_IN_PAGE,
2829 Source<RenderViewHost>(render_view_host()),
2830 NotificationService::NoDetails());
2831}
2832
[email protected]420ae012009-04-24 05:16:322833void TabContents::FileSelected(const FilePath& path,
2834 int index, void* params) {
[email protected]cdaf8d02010-03-30 19:52:472835 std::vector<FilePath> files;
2836 files.push_back(path);
2837 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322838}
2839
2840void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2841 void* params) {
[email protected]cdaf8d02010-03-30 19:52:472842 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322843}
2844
2845void TabContents::FileSelectionCanceled(void* params) {
2846 // If the user cancels choosing a file to upload we pass back an
2847 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472848 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322849}
2850
2851void TabContents::BeforeUnloadFiredFromRenderManager(
2852 bool proceed,
2853 bool* proceed_to_fire_unload) {
2854 if (delegate())
2855 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2856}
2857
2858void TabContents::UpdateRenderViewSizeForRenderManager() {
2859 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262860 gfx::Size size = view_->GetContainerSize();
2861 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2862 // here during container initialization and normal window size will be set
2863 // later. In case of tab duplication this resizing to 0x0 prevents setting
2864 // normal size later so just ignore it.
2865 if (!size.IsEmpty())
2866 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322867}
2868
2869DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222870 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322871}
2872
2873NavigationEntry*
2874TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2875 return controller_.GetLastCommittedEntry();
2876}
2877
2878bool TabContents::CreateRenderViewForRenderManager(
2879 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322880 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522881
2882 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2883 if (!request_context.get())
2884 request_context = profile()->GetRequestContext();
2885
2886 if (!render_view_host->CreateRenderView(request_context))
[email protected]420ae012009-04-24 05:16:322887 return false;
2888
2889 // Now that the RenderView has been created, we need to tell it its size.
2890 rwh_view->SetSize(view_->GetContainerSize());
2891
2892 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2893 render_view_host);
2894 return true;
2895}
2896
2897void TabContents::Observe(NotificationType type,
2898 const NotificationSource& source,
2899 const NotificationDetails& details) {
2900 switch (type.value) {
2901 case NotificationType::BOOKMARK_MODEL_LOADED:
2902 // BookmarkModel finished loading, fall through to update starred state.
2903 case NotificationType::URLS_STARRED: {
2904 // Somewhere, a URL has been starred.
2905 // Ignore notifications for profiles other than our current one.
2906 Profile* source_profile = Source<Profile>(source).ptr();
2907 if (!source_profile || !source_profile->IsSameProfile(profile()))
2908 return;
2909
2910 UpdateStarredStateForCurrentURL();
2911 break;
2912 }
2913 case NotificationType::PREF_CHANGED: {
2914 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2915 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2916 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2917 UpdateAlternateErrorPageURL();
2918 } else if (*pref_name_in == prefs::kDefaultCharset ||
2919 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2920 ) {
2921 UpdateWebPreferences();
2922 } else {
2923 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2924 }
2925 break;
2926 }
2927 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2928 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2929 break;
2930
2931 case NotificationType::NAV_ENTRY_COMMITTED: {
2932 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2933
2934 NavigationController::LoadCommittedDetails& committed_details =
2935 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2936 ExpireInfoBars(committed_details);
2937 break;
2938 }
2939
[email protected]d3ba77272009-09-03 00:06:092940#if defined(OS_LINUX)
2941 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542942 renderer_preferences_util::UpdateFromSystemSettings(
2943 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092944 render_view_host()->SyncRendererPrefs();
2945 break;
2946 }
2947#endif
2948
[email protected]6c32ce72010-03-08 05:18:062949 case NotificationType::USER_STYLE_SHEET_UPDATED:
2950 UpdateWebPreferences();
2951 break;
2952
[email protected]79580c62010-02-02 02:36:252953 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292954 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252955 settings_details(details);
[email protected]79580c62010-02-02 02:36:252956 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492957 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292958 if (entry)
[email protected]da0c8e92010-02-09 23:25:492959 entry_url = entry->url();
[email protected]79580c62010-02-02 02:36:252960 Source<HostContentSettingsMap> content_settings(source);
[email protected]0314ae02010-04-08 09:18:292961 if (settings_details.ptr()->update_all() ||
2962 settings_details.ptr()->pattern().Matches(entry_url)) {
2963 render_view_host()->SendContentSettings(entry_url,
[email protected]da0c8e92010-02-09 23:25:492964 content_settings.ptr()->GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252965 }
2966 break;
2967 }
2968
[email protected]a888b29e62010-04-01 13:38:572969 case NotificationType::EXTENSION_LOADED: {
[email protected]98aa0b52010-05-06 17:03:082970 if (!extension_app_ && !extension_app_for_current_page_ &&
[email protected]a888b29e62010-04-01 13:38:572971 Source<Profile>(source).ptr() == profile()) {
[email protected]98aa0b52010-05-06 17:03:082972 UpdateExtensionAppForCurrentPage();
2973 if (extension_app_for_current_page_)
[email protected]a888b29e62010-04-01 13:38:572974 NotifyNavigationStateChanged(INVALIDATE_TAB);
2975 }
2976 break;
2977 }
2978
2979 case NotificationType::EXTENSION_UNLOADED:
2980 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
[email protected]98aa0b52010-05-06 17:03:082981 if (extension_app_for_current_page_ ==
[email protected]a888b29e62010-04-01 13:38:572982 Details<Extension>(details).ptr()) {
[email protected]98aa0b52010-05-06 17:03:082983 extension_app_for_current_page_ = NULL;
2984 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:572985 NotifyNavigationStateChanged(INVALIDATE_TAB);
2986 }
2987 break;
2988 }
2989
[email protected]420ae012009-04-24 05:16:322990 default:
2991 NOTREACHED();
2992 }
2993}
[email protected]aacd7cc2009-09-02 14:51:102994
[email protected]98aa0b52010-05-06 17:03:082995void TabContents::UpdateExtensionAppIcon(Extension* extension) {
2996 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432997
[email protected]a888b29e62010-04-01 13:38:572998 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082999 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3000 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573001 extension,
3002 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3003 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3004 Extension::EXTENSION_ICON_SMALLISH),
3005 ImageLoadingTracker::CACHE);
3006 } else {
[email protected]98aa0b52010-05-06 17:03:083007 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573008 }
3009}
3010
3011Extension* TabContents::GetExtensionContaining(const GURL& url) {
3012 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3013 if (!extensions_service)
3014 return NULL;
3015
3016 Extension* extension = extensions_service->GetExtensionByURL(url);
3017 return extension ?
3018 extension : extensions_service->GetExtensionByWebExtent(url);
3019}
3020
[email protected]98aa0b52010-05-06 17:03:083021void TabContents::UpdateExtensionAppForCurrentPage() {
3022 if (extension_app_) {
[email protected]a888b29e62010-04-01 13:38:573023 // Tab has an explicit app extension; nothing to do.
3024 return;
3025 }
3026
3027 // Check the current extension before iterating through all extensions.
[email protected]98aa0b52010-05-06 17:03:083028 if (extension_app_for_current_page_ &&
3029 extension_app_for_current_page_->web_extent().ContainsURL(GetURL())) {
[email protected]a888b29e62010-04-01 13:38:573030 return;
3031 }
3032
[email protected]98aa0b52010-05-06 17:03:083033 extension_app_for_current_page_ = GetExtensionContaining(GetURL());
3034 UpdateExtensionAppIcon(extension_app_for_current_page_);
[email protected]a888b29e62010-04-01 13:38:573035}
3036
3037void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3038 int index) {
3039 if (image) {
[email protected]98aa0b52010-05-06 17:03:083040 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573041 NotifyNavigationStateChanged(INVALIDATE_TAB);
3042 }
3043}
3044
[email protected]beb440c2009-11-06 04:08:543045std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3046 bool is_alert) {
3047 if (!frame_url.has_host())
3048 return l10n_util::GetString(
3049 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3050 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3051
3052 // We really only want the scheme, hostname, and port.
3053 GURL::Replacements replacements;
3054 replacements.ClearUsername();
3055 replacements.ClearPassword();
3056 replacements.ClearPath();
3057 replacements.ClearQuery();
3058 replacements.ClearRef();
3059 GURL clean_url = frame_url.ReplaceComponents(replacements);
3060
3061 // TODO(brettw) it should be easier than this to do the correct language
3062 // handling without getting the accept language from the profile.
3063 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3064 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3065 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563066 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543067
3068 return l10n_util::GetStringF(
3069 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3070 base_address);
3071}
3072
3073gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3074 return view_->GetTopLevelNativeWindow();
3075}
3076
3077void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3078 bool success,
3079 const std::wstring& prompt) {
3080 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3081 if (is_showing_before_unload_dialog_ && !success) {
3082 // If a beforeunload dialog is canceled, we need to stop the throbber from
3083 // spinning, since we forced it to start spinning in Navigate.
3084 DidStopLoading();
3085
3086 tab_close_start_time_ = base::TimeTicks();
3087 }
3088 is_showing_before_unload_dialog_ = false;
3089 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3090}
3091
3092void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3093 set_suppress_javascript_messages(suppress_message_boxes);
3094}
3095
[email protected]41fc0322009-09-04 22:23:403096void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103097 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3098}
[email protected]f45d2a72010-03-08 23:28:353099
3100void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3101 app_icon_ = app_icon;
3102 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3103}
[email protected]ea68c06a2010-04-23 17:25:373104
3105// After a successful *new* login attempt, we take the PasswordFormManager in
3106// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3107// the user makes up their mind with the "save password" infobar. Note if the
3108// login is one we already know about, the end of the line is
3109// provisional_save_manager_ because we just update it on success and so such
3110// forms never end up in an infobar.
3111class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3112 public:
3113 SavePasswordInfoBarDelegate(TabContents* tab_contents,
3114 PasswordFormManager* form_to_save) :
3115 ConfirmInfoBarDelegate(tab_contents),
3116 form_to_save_(form_to_save) {
3117 }
3118
3119 virtual ~SavePasswordInfoBarDelegate() { }
3120
3121 // Overridden from ConfirmInfoBarDelegate:
3122 virtual void InfoBarClosed() {
3123 delete this;
3124 }
3125
3126 virtual std::wstring GetMessageText() const {
3127 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3128 }
3129
3130 virtual SkBitmap* GetIcon() const {
3131 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3132 IDR_INFOBAR_SAVE_PASSWORD);
3133 }
3134
3135 virtual int GetButtons() const {
3136 return BUTTON_OK | BUTTON_CANCEL;
3137 }
3138
3139 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3140 if (button == BUTTON_OK)
3141 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3142 if (button == BUTTON_CANCEL)
3143 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3144 NOTREACHED();
3145 return std::wstring();
3146 }
3147
3148 virtual bool Accept() {
3149 DCHECK(form_to_save_.get());
3150 form_to_save_->Save();
3151 return true;
3152 }
3153
3154 virtual bool Cancel() {
3155 DCHECK(form_to_save_.get());
3156 form_to_save_->PermanentlyBlacklist();
3157 return true;
3158 }
3159
3160 private:
3161 // The PasswordFormManager managing the form we're asking the user about,
3162 // and should update as per her decision.
3163 scoped_ptr<PasswordFormManager> form_to_save_;
3164
3165 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3166};
3167
3168void TabContents::FillPasswordForm(
3169 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3170 render_view_host()->FillPasswordForm(form_data);
3171}
3172
3173void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3174 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3175}
3176
3177Profile* TabContents::GetProfileForPasswordManager() {
3178 return profile();
3179}
3180
3181bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3182 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3183}