blob: d86a9bf4ffa143634b38204eaee4e8c4ffdc99d6 [file] [log] [blame]
[email protected]ce5c4502009-05-06 16:46:111// Copyright (c) 2009 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]a92b8642009-05-05 23:38:567#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:118#include "app/resource_bundle.h"
[email protected]420ae012009-04-24 05:16:329#include "base/file_version_info.h"
10#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5411#include "base/string16.h"
12#include "base/time.h"
[email protected]fdd61c62009-04-22 19:22:5713#include "chrome/browser/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1314#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3215#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5416#include "chrome/browser/browser_process.h"
initial.commit09911bf2008-07-26 23:55:2917#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1018#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5419#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3220#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5421#include "chrome/browser/dom_ui/dom_ui.h"
22#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0223#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3224#include "chrome/browser/download/download_manager.h"
25#include "chrome/browser/download/download_request_manager.h"
[email protected]0189bc722009-08-28 21:56:4826#include "chrome/browser/favicon_service.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/gears_integration.h"
28#include "chrome/browser/google_util.h"
[email protected]8897c382009-05-06 17:53:2629#include "chrome/browser/hung_renderer_dialog.h"
[email protected]420ae012009-04-24 05:16:3230#include "chrome/browser/jsmessage_box_handler.h"
31#include "chrome/browser/load_from_memory_cache_details.h"
32#include "chrome/browser/load_notification_details.h"
[email protected]ea0e80892009-08-22 00:36:0533#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1034#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5735#include "chrome/browser/password_manager/password_manager.h"
36#include "chrome/browser/plugin_installer.h"
[email protected]ce560f82009-06-03 09:39:4437#include "chrome/browser/profile.h"
[email protected]96d185d2009-04-24 03:28:5438#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3739#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]96d185d2009-04-24 03:28:5440#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]bd1ad682009-05-15 22:19:1741#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5442#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1643#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4344#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1645#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5746#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0247#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2848#include "chrome/browser/thumbnail_store.h"
[email protected]420ae012009-04-24 05:16:3249#include "chrome/browser/search_engines/template_url_fetcher.h"
50#include "chrome/browser/search_engines/template_url_model.h"
[email protected]35f7d212009-04-29 21:19:2751#include "chrome/common/chrome_switches.h"
[email protected]bfd04a62009-02-01 18:16:5652#include "chrome/common/notification_service.h"
[email protected]ce5c4502009-05-06 16:46:1153#include "chrome/common/page_action.h"
initial.commit09911bf2008-07-26 23:55:2954#include "chrome/common/pref_names.h"
[email protected]1eb89e82008-08-15 12:27:0355#include "chrome/common/pref_service.h"
[email protected]420ae012009-04-24 05:16:3256#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1857#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5458#include "chrome/common/url_constants.h"
[email protected]8897c382009-05-06 17:53:2659#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3260#include "grit/locale_settings.h"
61#include "net/base/mime_util.h"
62#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2963#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3264#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1865#include "webkit/glue/password_form.h"
66#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0067
[email protected]304f8792009-08-19 21:28:0968#if defined(OS_CHROMEOS)
69// For GdkScreen
70#include <gdk/gdk.h>
[email protected]0ba5c5e2009-08-20 16:47:1371#endif // defined(OS_CHROMEOS)
72
73#if defined(OS_LINUX)
74#include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h"
75#endif // defined(OS_LINUX)
76
[email protected]420ae012009-04-24 05:16:3277// Cross-Site Navigations
78//
79// If a TabContents is told to navigate to a different web site (as determined
80// by SiteInstance), it will replace its current RenderViewHost with a new
81// RenderViewHost dedicated to the new SiteInstance. This works as follows:
82//
83// - Navigate determines whether the destination is cross-site, and if so,
84// it creates a pending_render_view_host_ and moves into the PENDING
85// RendererState.
86// - The pending RVH is "suspended," so that no navigation messages are sent to
87// its renderer until the onbeforeunload JavaScript handler has a chance to
88// run in the current RVH.
89// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
90// that it has a pending cross-site request. ResourceDispatcherHost will
91// check for this when the response arrives.
92// - The current RVH runs its onbeforeunload handler. If it returns false, we
93// cancel all the pending logic and go back to NORMAL. Otherwise we allow
94// the pending RVH to send the navigation request to its renderer.
95// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
96// checks CrossSiteRequestManager to see that the RVH responsible has a
97// pending cross-site request, and then installs a CrossSiteEventHandler.
98// - When RDH receives a response, the BufferedEventHandler determines whether
99// it is a download. If so, it sends a message to the new renderer causing
100// it to cancel the request, and the download proceeds in the download
101// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34102// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32103// doesn't affect any functionality.
104// - After RDH receives a response and determines that it is safe and not a
105// download, it pauses the response to first run the old page's onunload
106// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34107// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32108// to the current RVH.
109// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
110// the ResourceDispatcherHost, who unpauses the response. Data is then sent
111// to the pending RVH.
112// - The pending renderer sends a FrameNavigate message that invokes the
113// DidNavigate method. This replaces the current RVH with the
114// pending RVH and goes back to the NORMAL RendererState.
115
116namespace {
117
118// Amount of time we wait between when a key event is received and the renderer
119// is queried for its state and pushed to the NavigationEntry.
120const int kQueryStateDelay = 5000;
121
122const int kSyncWaitDelay = 40;
123
[email protected]304f8792009-08-19 21:28:09124#if defined(OS_CHROMEOS)
125// If a popup window is bigger than this fraction of the screen on chrome os,
126// turn it into a tab
127const float kMaxWidthFactor = 0.5;
128const float kMaxHeightFactor = 0.6;
129#endif
130
[email protected]420ae012009-04-24 05:16:32131// If another javascript message box is displayed within
132// kJavascriptMessageExpectedDelay of a previous javascript message box being
133// dismissed, display an option to suppress future message boxes from this
134// contents.
135const int kJavascriptMessageExpectedDelay = 1000;
136
[email protected]2bd6ca1c2009-08-27 16:42:20137const char kLinkDoctorBaseURL[] =
138 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
139
[email protected]420ae012009-04-24 05:16:32140// The list of prefs we want to observe.
141const wchar_t* kPrefsToObserve[] = {
142 prefs::kAlternateErrorPagesEnabled,
143 prefs::kWebKitJavaEnabled,
144 prefs::kWebKitJavascriptEnabled,
145 prefs::kWebKitLoadsImagesAutomatically,
146 prefs::kWebKitPluginsEnabled,
147 prefs::kWebKitUsesUniversalDetector,
148 prefs::kWebKitSerifFontFamily,
149 prefs::kWebKitSansSerifFontFamily,
150 prefs::kWebKitFixedFontFamily,
151 prefs::kWebKitDefaultFontSize,
152 prefs::kWebKitDefaultFixedFontSize,
153 prefs::kDefaultCharset
154 // kWebKitStandardFontIsSerif needs to be added
155 // if we let users pick which font to use, serif or sans-serif when
156 // no font is specified or a CSS generic family (serif or sans-serif)
157 // is not specified.
158};
159
160const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
161
[email protected]420ae012009-04-24 05:16:32162// Returns true if the entry's transition type is FORM_SUBMIT.
163bool IsFormSubmit(const NavigationEntry* entry) {
164 return (PageTransition::StripQualifier(entry->transition_type()) ==
165 PageTransition::FORM_SUBMIT);
166}
167
168#if defined(OS_WIN)
169
170BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
171 // Note: erase is required to properly paint some widgets borders. This can
172 // be seen with textfields.
173 InvalidateRect(hwnd, NULL, TRUE);
174 return TRUE;
175}
176#endif
177
[email protected]056de2d2009-06-26 16:41:34178void MakeNavigateParams(const NavigationEntry& entry, bool reload,
179 ViewMsg_Navigate_Params* params) {
180 params->page_id = entry.page_id();
181 params->url = entry.url();
182 params->referrer = entry.referrer();
183 params->transition = entry.transition_type();
184 params->state = entry.content_state();
185 params->reload = reload;
186 params->request_time = base::Time::Now();
187}
188
[email protected]420ae012009-04-24 05:16:32189} // namespace
190
191// -----------------------------------------------------------------------------
192
[email protected]fdd61c62009-04-22 19:22:57193// static
194int TabContents::find_request_id_counter_ = -1;
195
[email protected]420ae012009-04-24 05:16:32196class TabContents::GearsCreateShortcutCallbackFunctor {
197 public:
198 explicit GearsCreateShortcutCallbackFunctor(TabContents* contents)
199 : contents_(contents) {}
200
201 void Run(const GearsShortcutData2& shortcut_data, bool success) {
202 if (contents_)
203 contents_->OnGearsCreateShortcutDone(shortcut_data, success);
204 delete this;
205 }
206 void Cancel() {
207 contents_ = NULL;
208 }
209
210 private:
211 TabContents* contents_;
212};
213
[email protected]420ae012009-04-24 05:16:32214TabContents::TabContents(Profile* profile,
215 SiteInstance* site_instance,
216 int routing_id,
217 base::WaitableEvent* modal_dialog_event)
[email protected]b680ad22009-04-15 23:19:42218 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13219 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
220 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22221 TabContentsView::Create(this))),
222 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57223 property_bag_(),
224 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22225 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57226 save_package_(),
227 cancelable_consumer_(),
228 autofill_manager_(),
229 password_manager_(),
230 plugin_installer_(),
[email protected]d82ed61e2009-06-16 02:46:22231 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57232 select_file_dialog_(),
233 pending_install_(),
[email protected]d5f942ba2008-09-26 19:30:34234 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29235 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34236 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34237 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57238 current_load_start_(),
239 load_state_(net::LOAD_STATE_IDLE),
240 load_state_host_(),
241 received_page_title_(false),
242 is_starred_(false),
243 contents_mime_type_(),
244 encoding_(),
[email protected]332af7732009-03-11 13:21:35245 blocked_popups_(NULL),
[email protected]fdd61c62009-04-22 19:22:57246 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57247 find_ui_active_(false),
248 find_op_aborted_(false),
249 current_find_request_id_(find_request_id_counter_++),
250 find_text_(),
[email protected]e491f1c2009-05-22 20:28:12251 last_search_case_sensitive_(false),
252 last_search_prepopulate_text_(NULL),
253 last_search_result_(),
[email protected]fdd61c62009-04-22 19:22:57254 capturing_contents_(false),
255 is_being_destroyed_(false),
256 notify_disconnection_(false),
257 history_requests_(),
258#if defined(OS_WIN)
259 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
260#endif
261 last_javascript_message_dismissal_(),
[email protected]94df7072009-09-01 23:48:28262 suppress_javascript_messages_(false) {
[email protected]420ae012009-04-24 05:16:32263 pending_install_.page_id = 0;
264 pending_install_.callback_functor = NULL;
265
[email protected]16779842009-07-08 23:45:29266#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02267 // Make sure the thumbnailer is started before starting the render manager.
268 // The thumbnailer will want to listen for RVH creations, one of which will
269 // happen in RVHManager::Init.
270 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
271 if (generator)
272 generator->StartThumbnailing();
273#endif
274
[email protected]420ae012009-04-24 05:16:32275 render_manager_.Init(profile, site_instance, routing_id, modal_dialog_event);
276
277 view_->CreateView();
278
279 // Register for notifications about all interested prefs change.
280 PrefService* prefs = profile->GetPrefs();
281 if (prefs) {
282 for (int i = 0; i < kPrefsToObserveLength; ++i)
283 prefs->AddPrefObserver(kPrefsToObserve[i], this);
284 }
285
286 // Register for notifications about URL starredness changing on any profile.
287 registrar_.Add(this, NotificationType::URLS_STARRED,
288 NotificationService::AllSources());
289 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
290 NotificationService::AllSources());
291 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
292 NotificationService::AllSources());
293
294 // Keep a global copy of the previous search string (if any).
295 static string16 global_last_search = string16();
[email protected]e491f1c2009-05-22 20:28:12296 last_search_prepopulate_text_ = &global_last_search;
[email protected]840b1512009-07-21 16:53:46297
[email protected]c8865482009-07-23 20:40:10298 // Set-up the showing of the omnibox search infobar if applicable.
299 if (OmniboxSearchHint::IsEnabled(profile))
300 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
301
[email protected]840b1512009-07-21 16:53:46302 view_->InitRendererPrefs(&renderer_preferences_);
[email protected]332af7732009-03-11 13:21:35303}
initial.commit09911bf2008-07-26 23:55:29304
305TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32306 is_being_destroyed_ = true;
307
308 // We don't want any notifications while we're runnign our destructor.
309 registrar_.RemoveAll();
310
311 // Unregister the notifications of all observed prefs change.
312 PrefService* prefs = profile()->GetPrefs();
313 if (prefs) {
314 for (int i = 0; i < kPrefsToObserveLength; ++i)
315 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
316 }
317
318 // Clean up subwindows like plugins and the find in page bar.
319 view_->OnContentsDestroy();
320
321 NotifyDisconnected();
[email protected]d82ed61e2009-06-16 02:46:22322 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32323
324 if (pending_install_.callback_functor)
325 pending_install_.callback_functor->Cancel();
326
327 // First cleanly close all child windows.
328 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
329 // some of these to close. CloseWindows is async, so it might get called
330 // twice before it runs.
331 int size = static_cast<int>(child_windows_.size());
332 for (int i = size - 1; i >= 0; --i) {
333 ConstrainedWindow* window = child_windows_[i];
334 if (window)
335 window->CloseConstrainedWindow();
336 }
337
[email protected]66ba4932009-06-04 19:22:13338 if (blocked_popups_)
339 blocked_popups_->Destroy();
340
[email protected]420ae012009-04-24 05:16:32341 // Notify any observer that have a reference on this tab contents.
342 NotificationService::current()->Notify(
343 NotificationType::TAB_CONTENTS_DESTROYED,
344 Source<TabContents>(this),
345 NotificationService::NoDetails());
346
[email protected]1e5e74f2009-05-27 20:55:12347 // Notify any lasting InfobarDelegates that have not yet been removed that
348 // whatever infobar they were handling in this TabContents has closed,
349 // because the TabContents is going away entirely.
350 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
351 // notification may trigger infobars calls that access their delegate. (and
352 // some implementations of InfoBarDelegate do delete themselves on
353 // InfoBarClosed()).
354 for (int i = 0; i < infobar_delegate_count(); ++i) {
355 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
356 delegate->InfoBarClosed();
357 }
358 infobar_delegates_.clear();
359
[email protected]420ae012009-04-24 05:16:32360 // TODO(brettw) this should be moved to the view.
361#if defined(OS_WIN)
362 // If we still have a window handle, destroy it. GetNativeView can return
363 // NULL if this contents was part of a window that closed.
364 if (GetNativeView())
365 ::DestroyWindow(GetNativeView());
366#endif
initial.commit09911bf2008-07-26 23:55:29367}
368
[email protected]d5f942ba2008-09-26 19:30:34369// static
370void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32371 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
372
373 WebPreferences pref_defaults;
374 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
375 pref_defaults.javascript_enabled);
376 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
377 pref_defaults.web_security_enabled);
378 prefs->RegisterBooleanPref(
379 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
380 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
381 pref_defaults.loads_images_automatically);
382 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
383 pref_defaults.plugins_enabled);
384 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
385 pref_defaults.dom_paste_enabled);
386 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
387 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08388 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
389 pref_defaults.inspector_settings);
[email protected]420ae012009-04-24 05:16:32390 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
391 pref_defaults.text_areas_are_resizable);
392 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
393 pref_defaults.java_enabled);
394
395 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
396 IDS_ACCEPT_LANGUAGES);
397 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
398 IDS_DEFAULT_ENCODING);
399 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
400 IDS_STANDARD_FONT_IS_SERIF);
401 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
402 IDS_FIXED_FONT_FAMILY);
403 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
404 IDS_SERIF_FONT_FAMILY);
405 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
406 IDS_SANS_SERIF_FONT_FAMILY);
407 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
408 IDS_CURSIVE_FONT_FAMILY);
409 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
410 IDS_FANTASY_FONT_FAMILY);
411 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
412 IDS_DEFAULT_FONT_SIZE);
413 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
414 IDS_DEFAULT_FIXED_FONT_SIZE);
415 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
416 IDS_MINIMUM_FONT_SIZE);
417 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
418 IDS_MINIMUM_LOGICAL_FONT_SIZE);
419 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
420 IDS_USES_UNIVERSAL_DETECTOR);
421 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
422 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29423}
424
[email protected]13367f72009-07-08 16:39:02425// Returns true if contains content rendered by an extension.
426bool TabContents::HostsExtension() const {
427 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34428}
429
[email protected]6e95706d2009-04-23 22:55:01430PasswordManager* TabContents::GetPasswordManager() {
431 if (password_manager_.get() == NULL)
432 password_manager_.reset(new PasswordManager(this));
433 return password_manager_.get();
434}
435
436PluginInstaller* TabContents::GetPluginInstaller() {
437 if (plugin_installer_.get() == NULL)
438 plugin_installer_.reset(new PluginInstaller(this));
439 return plugin_installer_.get();
440}
441
[email protected]d5f942ba2008-09-26 19:30:34442const GURL& TabContents::GetURL() const {
443 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57444 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54445 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34446}
447
[email protected]96d185d2009-04-24 03:28:54448const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55449 // Transient entries take precedence. They are used for interstitial pages
450 // that are shown on top of existing pages.
451 NavigationEntry* entry = controller_.GetTransientEntry();
452 if (entry)
453 return entry->GetTitleForDisplay(&controller_);
454
[email protected]96d185d2009-04-24 03:28:54455 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
456 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
457 if (our_dom_ui) {
458 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55459 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54460 if (!(entry && entry->IsViewSourceMode())) {
461 // Give the DOM UI the chance to override our title.
462 const string16& title = our_dom_ui->overridden_title();
463 if (!title.empty())
464 return title;
465 }
466 }
467
468 // We use the title for the last committed entry rather than a pending
469 // navigation entry. For example, when the user types in a URL, we want to
470 // keep the old page's title until the new load has committed and we get a new
471 // title.
[email protected]96d185d2009-04-24 03:28:54472 entry = controller_.GetLastCommittedEntry();
473 if (entry)
474 return entry->GetTitleForDisplay(&controller_);
475 else if (controller_.LoadingURLLazily())
476 return controller_.GetLazyTitle();
477 return EmptyString16();
478}
479
[email protected]d5f942ba2008-09-26 19:30:34480int32 TabContents::GetMaxPageID() {
481 if (GetSiteInstance())
482 return GetSiteInstance()->max_page_id();
483 else
484 return max_page_id_;
485}
486
487void TabContents::UpdateMaxPageID(int32 page_id) {
488 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34489 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34490 // testing.
491 if (GetSiteInstance())
492 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]57c6a652009-05-04 07:58:34493 process()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34494}
495
[email protected]96d185d2009-04-24 03:28:54496SiteInstance* TabContents::GetSiteInstance() const {
497 return render_manager_.current_host()->site_instance();
498}
499
[email protected]d5f942ba2008-09-26 19:30:34500const std::wstring TabContents::GetDefaultTitle() const {
501 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
502}
503
[email protected]96d185d2009-04-24 03:28:54504bool TabContents::ShouldDisplayURL() {
505 // Don't hide the url in view source mode.
506 NavigationEntry* entry = controller_.GetActiveEntry();
507 if (entry && entry->IsViewSourceMode())
508 return true;
[email protected]83e3895b2009-06-11 00:07:16509
[email protected]96d185d2009-04-24 03:28:54510 DOMUI* dom_ui = GetDOMUIForCurrentState();
511 if (dom_ui)
512 return !dom_ui->should_hide_url();
513 return true;
514}
515
[email protected]d5f942ba2008-09-26 19:30:34516SkBitmap TabContents::GetFavIcon() const {
517 // Like GetTitle(), we also want to use the favicon for the last committed
518 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57519 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47520 if (entry)
521 return entry->favicon().bitmap();
522
[email protected]ce3fa3c2009-04-20 19:55:57523 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34524 if (entry)
525 return entry->favicon().bitmap();
[email protected]ce3fa3c2009-04-20 19:55:57526 else if (controller_.LoadingURLLazily())
527 return controller_.GetLazyFavIcon();
[email protected]d5f942ba2008-09-26 19:30:34528 return SkBitmap();
529}
530
[email protected]96d185d2009-04-24 03:28:54531bool TabContents::ShouldDisplayFavIcon() {
532 // Always display a throbber during pending loads.
533 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
534 return true;
535
536 DOMUI* dom_ui = GetDOMUIForCurrentState();
537 if (dom_ui)
538 return !dom_ui->hide_favicon();
539 return true;
540}
541
[email protected]96d185d2009-04-24 03:28:54542std::wstring TabContents::GetStatusText() const {
543 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
544 return std::wstring();
545
546 switch (load_state_) {
547 case net::LOAD_STATE_WAITING_FOR_CACHE:
548 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
549 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
550 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
551 case net::LOAD_STATE_RESOLVING_HOST:
552 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
553 case net::LOAD_STATE_CONNECTING:
554 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
555 case net::LOAD_STATE_SENDING_REQUEST:
556 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
557 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
558 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
559 load_state_host_);
560 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
561 case net::LOAD_STATE_IDLE:
562 case net::LOAD_STATE_READING_RESPONSE:
563 break;
564 }
565
566 return std::wstring();
567}
568
[email protected]d5f942ba2008-09-26 19:30:34569void TabContents::SetIsCrashed(bool state) {
570 if (state == is_crashed_)
571 return;
572
573 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50574 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34575}
576
[email protected]f9b1a7b2009-06-22 17:26:38577void TabContents::SetPageActionEnabled(const PageAction* page_action,
[email protected]d7eaf572009-07-01 21:57:00578 bool enable,
579 const std::string& title,
580 int icon_id) {
[email protected]ce5c4502009-05-06 16:46:11581 DCHECK(page_action);
582
[email protected]d7eaf572009-07-01 21:57:00583 if (!enable &&
584 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
585 return; // Don't need to disable twice.
586 }
[email protected]ce5c4502009-05-06 16:46:11587
[email protected]d7eaf572009-07-01 21:57:00588 if (enable) {
589 enabled_page_actions_[page_action].reset(
590 new PageActionState(title, icon_id));
591 } else {
[email protected]f9b1a7b2009-06-22 17:26:38592 enabled_page_actions_.erase(page_action);
[email protected]d7eaf572009-07-01 21:57:00593 }
[email protected]ce5c4502009-05-06 16:46:11594}
595
[email protected]d7eaf572009-07-01 21:57:00596const PageActionState* TabContents::GetPageActionState(
597 const PageAction* page_action) {
598 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
599 return NULL;
[email protected]ce5c4502009-05-06 16:46:11600
[email protected]d7eaf572009-07-01 21:57:00601 return enabled_page_actions_[page_action].get();
602}
[email protected]ce5c4502009-05-06 16:46:11603
[email protected]d5f942ba2008-09-26 19:30:34604void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
605 if (delegate_)
606 delegate_->NavigationStateChanged(this, changed_flags);
607}
608
[email protected]96d185d2009-04-24 03:28:54609void TabContents::DidBecomeSelected() {
610 controller_.SetActive(true);
[email protected]789e9152009-08-04 21:59:43611 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54612 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43613#if defined(OS_MACOSX)
614 render_widget_host_view()->SetActive(true);
615#endif
616 }
[email protected]96d185d2009-04-24 03:28:54617
[email protected]76543b92009-08-31 17:27:45618 WebCacheManager::GetInstance()->ObserveActivity(process()->id());
[email protected]96d185d2009-04-24 03:28:54619}
620
621void TabContents::WasHidden() {
622 if (!capturing_contents()) {
623 // |render_view_host()| can be NULL if the user middle clicks a link to open
624 // a tab in then background, then closes the tab before selecting it. This
625 // is because closing the tab calls TabContents::Destroy(), which removes
626 // the |render_view_host()|; then when we actually destroy the window,
627 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
628 if (render_widget_host_view())
629 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54630 }
631
632 NotificationService::current()->Notify(
633 NotificationType::TAB_CONTENTS_HIDDEN,
634 Source<TabContents>(this),
635 NotificationService::NoDetails());
636}
637
[email protected]d5f942ba2008-09-26 19:30:34638void TabContents::Activate() {
639 if (delegate_)
640 delegate_->ActivateContents(this);
641}
642
[email protected]96d185d2009-04-24 03:28:54643void TabContents::ShowContents() {
644 if (render_widget_host_view())
645 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54646}
647
648void TabContents::HideContents() {
649 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
650 // our superclass HideContents(), because some callers want to be very picky
651 // about the order in which these get called. In addition to making the code
652 // here practically impossible to understand, this also means we end up
653 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34654 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54655 WasHidden();
656}
657
[email protected]c0588052008-10-27 23:01:50658void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34659 WindowOpenDisposition disposition,
660 PageTransition::Type transition) {
661 if (delegate_)
[email protected]c0588052008-10-27 23:01:50662 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34663}
664
665bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54666 const NavigationEntry& entry = *controller_.pending_entry();
667
668 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
669 if (!dest_render_view_host)
670 return false; // Unable to create the desired render view host.
671
672 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12673 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32674 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41675 devtools_manager->OnNavigatingToPendingEntry(
676 render_view_host(),
677 dest_render_view_host,
678 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32679 }
[email protected]96d185d2009-04-24 03:28:54680
681 // Used for page load time metrics.
682 current_load_start_ = base::TimeTicks::Now();
683
684 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34685 ViewMsg_Navigate_Params navigate_params;
686 MakeNavigateParams(entry, reload, &navigate_params);
687 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54688
689 if (entry.page_id() == -1) {
690 // HACK!! This code suppresses javascript: URLs from being added to
691 // session history, which is what we want to do for javascript: URLs that
692 // do not generate content. What we really need is a message from the
693 // renderer telling us that a new page was not created. The same message
694 // could be used for mailto: URLs and the like.
695 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
696 return false;
697 }
698
699 // Clear any provisional password saves - this stops password infobars
700 // showing up on pages the user navigates to while the right page is
701 // loading.
702 GetPasswordManager()->ClearProvisionalSave();
703
704 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48705 FaviconService* favicon_service =
706 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
707 if (favicon_service)
708 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54709 }
710
[email protected]d5f942ba2008-09-26 19:30:34711 return true;
712}
713
[email protected]96d185d2009-04-24 03:28:54714void TabContents::Stop() {
715 render_manager_.Stop();
716 printing_.Stop();
717}
718
719void TabContents::Cut() {
720 render_view_host()->Cut();
721}
722
723void TabContents::Copy() {
724 render_view_host()->Copy();
725}
726
727void TabContents::Paste() {
728 render_view_host()->Paste();
729}
730
731void TabContents::DisassociateFromPopupCount() {
732 render_view_host()->DisassociateFromPopupCount();
733}
734
735TabContents* TabContents::Clone() {
736 // We create a new SiteInstance so that the new tab won't share processes
737 // with the old one. This can be changed in the future if we need it to share
738 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32739 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54740 SiteInstance::CreateSiteInstance(profile()),
741 MSG_ROUTING_NONE, NULL);
742 tc->controller().CopyStateFrom(controller_);
743 return tc;
744}
745
[email protected]420ae012009-04-24 05:16:32746void TabContents::CreateShortcut() {
747 NavigationEntry* entry = controller_.GetLastCommittedEntry();
748 if (!entry)
749 return;
750
[email protected]70b8d6b2009-08-20 16:56:24751#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13752 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
753 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49754#else
[email protected]420ae012009-04-24 05:16:32755 // We only allow one pending install request. By resetting the page id we
756 // effectively cancel the pending install request.
757 pending_install_.page_id = entry->page_id();
758 pending_install_.icon = GetFavIcon();
759 pending_install_.title = UTF16ToWideHack(GetTitle());
760 pending_install_.url = GetURL();
761 if (pending_install_.callback_functor) {
762 pending_install_.callback_functor->Cancel();
763 pending_install_.callback_functor = NULL;
764 }
765 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
766 if (pending_install_.title.empty())
767 pending_install_.title = UTF8ToWide(GetURL().spec());
768
769 // Request the application info. When done OnDidGetApplicationInfo is invoked
770 // and we'll create the shortcut.
771 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49772#endif
[email protected]420ae012009-04-24 05:16:32773}
774
[email protected]4d677202009-07-19 07:37:12775void TabContents::ShowPageInfo(const GURL& url,
776 const NavigationEntry::SSLStatus& ssl,
777 bool show_history) {
778 if (!delegate_)
779 return;
780
[email protected]bb678332009-07-21 00:15:50781 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12782}
783
initial.commit09911bf2008-07-26 23:55:29784ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28785 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29786 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28787 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29788 child_windows_.push_back(window);
789 return window;
790}
791
792void TabContents::AddNewContents(TabContents* new_contents,
793 WindowOpenDisposition disposition,
794 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22795 bool user_gesture,
796 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29797 if (!delegate_)
798 return;
799
[email protected]35f7d212009-04-29 21:19:27800 if ((disposition == NEW_POPUP) && !user_gesture &&
801 !CommandLine::ForCurrentProcess()->HasSwitch(
802 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22803 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31804 // the whitelist. The popup owner will handle checking this.
805 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
806 initial_pos,
807 creator_url.is_valid() ? creator_url.host() : std::string());
808 } else {
[email protected]304f8792009-08-19 21:28:09809#if defined(OS_CHROMEOS)
810 if (disposition == NEW_POPUP) {
811 // If the popup is bigger than a given factor of the screen, then
812 // turn it into a foreground tab (on chrome os only)
813 GdkScreen* screen = gdk_screen_get_default();
814 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
815 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
816 if (initial_pos.width() > max_width ||
817 initial_pos.height() > max_height) {
818 disposition = NEW_FOREGROUND_TAB;
819 }
820 }
821#endif
822
[email protected]0aa55312008-10-17 21:53:08823 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29824 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
825 user_gesture);
826 }
[email protected]b6c874582009-05-08 19:38:31827 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29828}
829
initial.commit09911bf2008-07-26 23:55:29830void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25831 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22832 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29833}
834
[email protected]96d185d2009-04-24 03:28:54835void TabContents::PopupNotificationVisibilityChanged(bool visible) {
836 render_view_host()->PopupNotificationVisibilityChanged(visible);
837}
838
839gfx::NativeView TabContents::GetContentNativeView() {
840 return view_->GetContentNativeView();
841}
842
843gfx::NativeView TabContents::GetNativeView() const {
844 return view_->GetNativeView();
845}
846
847void TabContents::GetContainerBounds(gfx::Rect *out) const {
848 view_->GetContainerBounds(out);
849}
850
851void TabContents::Focus() {
852 view_->Focus();
853}
854
[email protected]90daadb42009-06-08 21:27:28855void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54856 if (showing_interstitial_page()) {
857 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
858 return;
859 }
[email protected]96d185d2009-04-24 03:28:54860 render_view_host()->SetInitialFocus(reverse);
861}
862
863bool TabContents::FocusLocationBarByDefault() {
864 DOMUI* dom_ui = GetDOMUIForCurrentState();
865 if (dom_ui)
866 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43867 NavigationEntry* entry = controller_.GetActiveEntry();
868 if (entry && entry->url() == GURL("about:blank"))
869 return true;
[email protected]96d185d2009-04-24 03:28:54870 return false;
871}
872
[email protected]616ed5a2008-11-21 22:27:24873void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
874 // Look through the existing InfoBarDelegates we have for a match. If we've
875 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05876 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24877 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
878 return;
879 }
880
881 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56882 NotificationService::current()->Notify(
883 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
884 Source<TabContents>(this),
885 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24886
887 // Add ourselves as an observer for navigations the first time a delegate is
888 // added. We use this notification to expire InfoBars that need to expire on
889 // page transitions.
890 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56891 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57892 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24893 }
894}
895
896void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
897 std::vector<InfoBarDelegate*>::iterator it =
898 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
899 if (it != infobar_delegates_.end()) {
900 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56901 NotificationService::current()->Notify(
902 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
903 Source<TabContents>(this),
904 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05905 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24906
[email protected]6a02963e2009-01-06 16:58:03907 // Remove ourselves as an observer if we are tracking no more InfoBars.
908 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56909 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57910 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03911 }
[email protected]616ed5a2008-11-21 22:27:24912 }
913}
[email protected]3edd9522009-03-04 22:19:41914
[email protected]f81821c2009-08-07 01:29:47915void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
916 InfoBarDelegate* new_delegate) {
917 std::vector<InfoBarDelegate*>::iterator it =
918 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
919 DCHECK(it != infobar_delegates_.end());
920
921 // Notify the container about the change of plans.
922 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
923 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
924 old_delegate, new_delegate));
925 NotificationService::current()->Notify(
926 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
927 Source<TabContents>(this),
928 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
929
930 // Remove the old one.
931 infobar_delegates_.erase(it);
932
933 // Add the new one.
934 infobar_delegates_.push_back(new_delegate);
935}
936
[email protected]96d185d2009-04-24 03:28:54937bool TabContents::IsBookmarkBarAlwaysVisible() {
938 // See GetDOMUIForCurrentState() comment for more info. This case is very
939 // similar, but for non-first loads, we want to use the committed entry. This
940 // is so the bookmarks bar disappears at the same time the page does.
941 if (controller_.GetLastCommittedEntry()) {
942 // Not the first load, always use the committed DOM UI.
943 if (render_manager_.dom_ui())
944 return render_manager_.dom_ui()->force_bookmark_bar_visible();
945 return false; // Default.
946 }
947
948 // When it's the first load, we know either the pending one or the committed
949 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
950 // of them will be valid, so we can just check both.
951 if (render_manager_.pending_dom_ui())
952 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
953 if (render_manager_.dom_ui())
954 return render_manager_.dom_ui()->force_bookmark_bar_visible();
955 return false; // Default.
956}
957
[email protected]d8f16ae2009-08-30 03:47:26958bool TabContents::IsExtensionShelfAlwaysVisible() {
959 // See GetDOMUIForCurrentState() comment for more info. This case is very
960 // similar, but for non-first loads, we want to use the committed entry. This
961 // is so the bookmarks bar disappears at the same time the page does.
962 if (controller_.GetLastCommittedEntry()) {
963 // Not the first load, always use the committed DOM UI.
964 if (render_manager_.dom_ui())
965 return render_manager_.dom_ui()->force_extension_shelf_visible();
966 return false; // Default.
967 }
968
969 // When it's the first load, we know either the pending one or the committed
970 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
971 // of them will be valid, so we can just check both.
972 if (render_manager_.pending_dom_ui())
973 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
974 if (render_manager_.dom_ui())
975 return render_manager_.dom_ui()->force_extension_shelf_visible();
976 return false; // Default.
977}
978
[email protected]3edd9522009-03-04 22:19:41979void TabContents::ToolbarSizeChanged(bool is_animating) {
980 TabContentsDelegate* d = delegate();
981 if (d)
982 d->ToolbarSizeChanged(this, is_animating);
983}
[email protected]616ed5a2008-11-21 22:27:24984
[email protected]d5f942ba2008-09-26 19:30:34985void TabContents::OnStartDownload(DownloadItem* download) {
986 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:34987
988 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:31989 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:34990
[email protected]59560e0b2009-06-04 03:30:22991 if (tab_contents && tab_contents->delegate())
992 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:41993}
[email protected]3edd9522009-03-04 22:19:41994
[email protected]d5f942ba2008-09-26 19:30:34995void TabContents::WillClose(ConstrainedWindow* window) {
996 ConstrainedWindowList::iterator it =
997 find(child_windows_.begin(), child_windows_.end(), window);
998 if (it != child_windows_.end())
999 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:131000}
[email protected]d5f942ba2008-09-26 19:30:341001
[email protected]66ba4932009-06-04 19:22:131002void TabContents::WillCloseBlockedPopupContainer(
1003 BlockedPopupContainer* container) {
1004 DCHECK(blocked_popups_ == container);
1005 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341006}
1007
[email protected]d5f942ba2008-09-26 19:30:341008void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351009#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061010 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351011#endif
[email protected]d5f942ba2008-09-26 19:30:341012}
1013
[email protected]e491f1c2009-05-22 20:28:121014void TabContents::StartFinding(string16 find_text,
1015 bool forward_direction,
1016 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011017 // If find_text is empty, it means FindNext was pressed with a keyboard
1018 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121019 if (find_text.empty() && find_text_.empty()) {
1020 if (last_search_prepopulate_text_->empty())
1021 return;
1022 // Try whatever we searched for last in any tab.
1023 find_text = *last_search_prepopulate_text_;
1024 }
[email protected]6e95706d2009-04-23 22:55:011025
1026 // This is a FindNext operation if we are searching for the same text again,
1027 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1028 // exception to this is if the Find was aborted (then we don't want FindNext
1029 // because the highlighting has been cleared and we need it to reappear). We
1030 // therefore treat FindNext after an aborted Find operation as a full fledged
1031 // Find.
1032 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121033 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011034 !find_op_aborted_;
1035 if (!find_next)
1036 current_find_request_id_ = find_request_id_counter_++;
1037
1038 if (!find_text.empty())
1039 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121040 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011041
1042 find_op_aborted_ = false;
1043
1044 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121045 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011046
1047 render_view_host()->StartFinding(current_find_request_id_,
1048 find_text_,
1049 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121050 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011051 find_next);
1052}
1053
1054void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001055 // When |clear_selection| is true, it means the find string has been cleared
1056 // by the user, but the UI has not been dismissed.
1057 if (!clear_selection)
1058 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011059 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121060 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011061 render_view_host()->StopFinding(clear_selection);
1062}
1063
[email protected]5c4266922009-07-10 16:41:271064void TabContents::GetPageLanguage() {
1065 render_view_host()->GetPageLanguage();
1066}
1067
[email protected]420ae012009-04-24 05:16:321068void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1069 bool success,
1070 const std::wstring& prompt) {
1071 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1072 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1073}
1074
[email protected]571e31152009-05-15 19:34:021075void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1076 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1077}
1078
[email protected]420ae012009-04-24 05:16:321079void TabContents::OnSavePage() {
1080 // If we can not save the page, try to download it.
1081 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1082 DownloadManager* dlm = profile()->GetDownloadManager();
1083 const GURL& current_page_url = GetURL();
1084 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221085 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321086 return;
1087 }
1088
1089 Stop();
1090
1091 // Create the save package and possibly prompt the user for the name to save
1092 // the page as. The user prompt is an asynchronous operation that runs on
1093 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221094 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321095 save_package_->GetSaveInfo();
1096}
1097
1098// Used in automated testing to bypass prompting the user for file names.
1099// Instead, the names and paths are hard coded rather than running them through
1100// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591101bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321102 const std::wstring& dir_path,
1103 SavePackage::SavePackageType save_type) {
1104 // Stop the page from navigating.
1105 Stop();
1106
[email protected]d82ed61e2009-06-16 02:46:221107 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321108 FilePath::FromWStringHack(main_file),
1109 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591110 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321111}
1112
1113void TabContents::PrintPreview() {
1114 // We don't show the print preview yet, only the print dialog.
1115 PrintNow();
1116}
1117
1118bool TabContents::PrintNow() {
1119 // We can't print interstitial page for now.
1120 if (showing_interstitial_page())
1121 return false;
1122
1123 return render_view_host()->PrintPages();
1124}
1125
[email protected]82270452009-06-19 15:58:011126void TabContents::PrintingDone(int document_cookie, bool success) {
1127 render_view_host()->PrintingDone(document_cookie, success);
1128}
1129
[email protected]420ae012009-04-24 05:16:321130bool TabContents::IsActiveEntry(int32 page_id) {
1131 NavigationEntry* active_entry = controller_.GetActiveEntry();
1132 return (active_entry != NULL &&
1133 active_entry->site_instance() == GetSiteInstance() &&
1134 active_entry->page_id() == page_id);
1135}
1136
[email protected]96d185d2009-04-24 03:28:541137// Notifies the RenderWidgetHost instance about the fact that the page is
1138// loading, or done loading and calls the base implementation.
1139void TabContents::SetIsLoading(bool is_loading,
1140 LoadNotificationDetails* details) {
1141 if (is_loading == is_loading_)
1142 return;
1143
1144 if (!is_loading) {
1145 load_state_ = net::LOAD_STATE_IDLE;
1146 load_state_host_.clear();
1147 }
1148
1149 render_manager_.SetIsLoading(is_loading);
1150
1151 is_loading_ = is_loading;
1152 waiting_for_response_ = is_loading;
1153
1154 if (delegate_)
1155 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351156 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541157
1158 NotificationType type = is_loading ? NotificationType::LOAD_START :
1159 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111160 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541161 if (details)
1162 det = Details<LoadNotificationDetails>(details);
1163 NotificationService::current()->Notify(type,
1164 Source<NavigationController>(&controller_),
1165 det);
1166}
1167
[email protected]2c4410d2009-05-06 23:46:221168void TabContents::CreateBlockedPopupContainerIfNecessary() {
1169 if (blocked_popups_)
1170 return;
1171
[email protected]4d4c0b92009-06-08 23:13:011172 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221173}
1174
[email protected]b6c874582009-05-08 19:38:311175void TabContents::AddPopup(TabContents* new_contents,
1176 const gfx::Rect& initial_pos,
1177 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221178 CreateBlockedPopupContainerIfNecessary();
1179 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221180}
1181
[email protected]e69bce3dd2009-04-20 22:05:121182// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131183void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251184 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011185 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341186}
1187
[email protected]b9681312008-11-07 00:08:261188bool TabContents::ShowingBlockedPopupNotification() const {
1189 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221190 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261191}
[email protected]616ed5a2008-11-21 22:27:241192
1193namespace {
1194bool TransitionIsReload(PageTransition::Type transition) {
1195 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1196}
1197}
1198
1199void TabContents::ExpireInfoBars(
1200 const NavigationController::LoadCommittedDetails& details) {
1201 // Only hide InfoBars when the user has done something that makes the main
1202 // frame load. We don't want various automatic or subframe navigations making
1203 // it disappear.
1204 if (!details.is_user_initiated_main_frame_load())
1205 return;
1206
[email protected]f86a07022008-11-25 01:06:051207 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241208 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051209 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241210 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241211 }
1212}
[email protected]fdd61c62009-04-22 19:22:571213
1214void TabContents::OnGearsCreateShortcutDone(
1215 const GearsShortcutData2& shortcut_data, bool success) {
1216 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1217 bool same_page =
1218 current_entry && pending_install_.page_id == current_entry->page_id();
1219
1220 if (success && same_page) {
1221 // Only switch to app mode if the user chose to create a shortcut and
1222 // we're still on the same page that it corresponded to.
1223 if (delegate())
1224 delegate()->ConvertContentsToApplication(this);
1225 }
1226
1227 // Reset the page id to indicate no requests are pending.
1228 pending_install_.page_id = 0;
1229 pending_install_.callback_functor = NULL;
1230}
[email protected]96d185d2009-04-24 03:28:541231
1232DOMUI* TabContents::GetDOMUIForCurrentState() {
1233 // When there is a pending navigation entry, we want to use the pending DOMUI
1234 // that goes along with it to control the basic flags. For example, we want to
1235 // show the pending URL in the URL bar, so we want the display_url flag to
1236 // be from the pending entry.
1237 //
1238 // The confusion comes because there are multiple possibilities for the
1239 // initial load in a tab as a side effect of the way the RenderViewHostManager
1240 // works.
1241 //
1242 // - For the very first tab the load looks "normal". The new tab DOM UI is
1243 // the pending one, and we want it to apply here.
1244 //
1245 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1246 // get switched to the one previously associated with the new tab pages.
1247 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1248 // have a committed DOM UI in this case.
1249 //
1250 // This condition handles all of these cases:
1251 //
1252 // - First load in first tab: no committed nav entry + pending nav entry +
1253 // pending dom ui:
1254 // -> Use pending DOM UI if any.
1255 //
1256 // - First load in second tab: no committed nav entry + pending nav entry +
1257 // no pending DOM UI:
1258 // -> Use the committed DOM UI if any.
1259 //
1260 // - Second navigation in any tab: committed nav entry + pending nav entry:
1261 // -> Use pending DOM UI if any.
1262 //
1263 // - Normal state with no load: committed nav entry + no pending nav entry:
1264 // -> Use committed DOM UI.
1265 if (controller_.pending_entry() &&
1266 (controller_.GetLastCommittedEntry() ||
1267 render_manager_.pending_dom_ui()))
1268 return render_manager_.pending_dom_ui();
1269 return render_manager_.dom_ui();
1270}
[email protected]420ae012009-04-24 05:16:321271
1272void TabContents::DidNavigateMainFramePostCommit(
1273 const NavigationController::LoadCommittedDetails& details,
1274 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]420ae012009-04-24 05:16:321275 if (details.is_user_initiated_main_frame_load()) {
1276 // Clear the status bubble. This is a workaround for a bug where WebKit
1277 // doesn't let us know that the cursor left an element during a
1278 // transition (this is also why the mouse cursor remains as a hand after
1279 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1280 // clear the bubble when a user navigates to a named anchor in the same
1281 // page.
1282 UpdateTargetURL(details.entry->page_id(), GURL());
1283
1284 // UpdateHelpersForDidNavigate will handle the case where the password_form
1285 // origin is valid.
1286 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1287 // cleaned up and covered by tests.
1288 if (!params.password_form.origin.is_valid())
1289 GetPasswordManager()->DidNavigate();
1290 }
1291
1292 // The keyword generator uses the navigation entries, so must be called after
1293 // the commit.
1294 GenerateKeywordIfNecessary(params);
1295
1296 // Allow the new page to set the title again.
1297 received_page_title_ = false;
1298
1299 // Get the favicon, either from history or request it from the net.
1300 fav_icon_helper_.FetchFavIcon(details.entry->url());
1301
[email protected]aece2c7f2009-08-27 20:43:171302 // Disable all page actions, unless this is an in-page navigation.
1303 if (!enabled_page_actions_.empty()) {
1304 url_canon::Replacements<char> replacements;
1305 replacements.ClearRef();
1306 if (params.url.ReplaceComponents(replacements) !=
1307 params.referrer.ReplaceComponents(replacements)) {
1308 enabled_page_actions_.clear();
1309 }
1310 }
[email protected]ce5c4502009-05-06 16:46:111311
[email protected]420ae012009-04-24 05:16:321312 // Close constrained popups if necessary.
1313 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1314
1315 // Update the starred state.
1316 UpdateStarredStateForCurrentURL();
1317}
1318
1319void TabContents::DidNavigateAnyFramePostCommit(
1320 RenderViewHost* render_view_host,
1321 const NavigationController::LoadCommittedDetails& details,
1322 const ViewHostMsg_FrameNavigate_Params& params) {
1323 // If we navigate, start showing messages again. This does nothing to prevent
1324 // a malicious script from spamming messages, since the script could just
1325 // reload the page to stop blocking.
1326 suppress_javascript_messages_ = false;
1327
[email protected]420ae012009-04-24 05:16:321328 // Notify the password manager of the navigation or form submit.
1329 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1330 // cleaned up and covered by tests.
1331 if (params.password_form.origin.is_valid())
1332 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1333}
1334
1335void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1336 const GURL& current_url) {
1337 if (net::RegistryControlledDomainService::SameDomainOrHost(
1338 previous_url, current_url))
1339 return;
1340
1341 // Clear out any child windows since we are leaving this page entirely.
1342 // We use indices instead of iterators in case CloseWindow does something
1343 // that may invalidate an iterator.
1344 int size = static_cast<int>(child_windows_.size());
1345 for (int i = size - 1; i >= 0; --i) {
1346 ConstrainedWindow* window = child_windows_[i];
1347 if (window)
1348 window->CloseConstrainedWindow();
1349 }
[email protected]e29300cd2009-07-23 21:14:591350
1351 // Close the popup container.
1352 if (blocked_popups_) {
1353 blocked_popups_->Destroy();
1354 blocked_popups_ = NULL;
1355 }
[email protected]420ae012009-04-24 05:16:321356}
1357
1358void TabContents::UpdateStarredStateForCurrentURL() {
1359 BookmarkModel* model = profile()->GetBookmarkModel();
1360 const bool old_state = is_starred_;
1361 is_starred_ = (model && model->IsBookmarked(GetURL()));
1362
1363 if (is_starred_ != old_state && delegate())
1364 delegate()->URLStarredChanged(this, is_starred_);
1365}
1366
1367void TabContents::UpdateAlternateErrorPageURL() {
1368 GURL url = GetAlternateErrorPageURL();
1369 render_view_host()->SetAlternateErrorPageURL(url);
1370}
1371
1372void TabContents::UpdateWebPreferences() {
1373 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1374}
1375
1376void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1377 RenderViewHost* rvh) {
1378 // If we are creating a RVH for a restored controller, then we might
1379 // have more page IDs than the SiteInstance's current max page ID. We must
1380 // make sure that the max page ID is larger than any restored page ID.
1381 // Note that it is ok for conflicting page IDs to exist in another tab
1382 // (i.e., NavigationController), but if any page ID is larger than the max,
1383 // the back/forward list will get confused.
1384 int max_restored_page_id = controller_.max_restored_page_id();
1385 if (max_restored_page_id > 0) {
1386 int curr_max_page_id = site_instance->max_page_id();
1387 if (max_restored_page_id > curr_max_page_id) {
1388 // Need to update the site instance immediately.
1389 site_instance->UpdateMaxPageID(max_restored_page_id);
1390
1391 // Also tell the renderer to update its internal representation. We
1392 // need to reserve enough IDs to make all restored page IDs less than
1393 // the max.
1394 if (curr_max_page_id < 0)
1395 curr_max_page_id = 0;
1396 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1397 }
1398 }
1399}
1400
1401void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541402 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471403 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321404 const ViewHostMsg_FrameNavigate_Params& params) {
1405 if (profile()->IsOffTheRecord())
1406 return;
1407
1408 // Add to history service.
1409 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1410 if (hs) {
1411 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541412 virtual_url != params.url) {
1413 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321414 // types of URLs, we will display a magic URL that is different from where
1415 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541416 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1417 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321418 // to sub-frames.
1419 std::vector<GURL> redirects = params.redirects;
1420 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541421 redirects.back() = virtual_url;
1422 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471423 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321424 } else {
1425 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471426 params.transition, params.redirects,
1427 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321428 }
1429 }
1430}
1431
1432bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1433 const std::wstring& title) {
1434 // For file URLs without a title, use the pathname instead. In the case of a
1435 // synthesized title, we don't want the update to count toward the "one set
1436 // per page of the title to history."
1437 std::wstring final_title;
1438 bool explicit_set;
1439 if (entry->url().SchemeIsFile() && title.empty()) {
1440 final_title = UTF8ToWide(entry->url().ExtractFileName());
1441 explicit_set = false; // Don't count synthetic titles toward the set limit.
1442 } else {
1443 TrimWhitespace(title, TRIM_ALL, &final_title);
1444 explicit_set = true;
1445 }
1446
1447 if (final_title == UTF16ToWideHack(entry->title()))
1448 return false; // Nothing changed, don't bother.
1449
1450 entry->set_title(WideToUTF16Hack(final_title));
1451
1452 // Update the history system for this page.
1453 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1454 HistoryService* hs =
1455 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1456 if (hs)
[email protected]ebe89e062009-08-13 23:16:541457 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321458
1459 // Don't allow the title to be saved again for explicitly set ones.
1460 received_page_title_ = explicit_set;
1461 }
1462
1463 // Lastly, set the title for the view.
1464 view_->SetPageTitle(final_title);
1465
1466 return true;
1467}
1468
1469void TabContents::NotifySwapped() {
1470 // After sending out a swap notification, we need to send a disconnect
1471 // notification so that clients that pick up a pointer to |this| can NULL the
1472 // pointer. See Bug 1230284.
1473 notify_disconnection_ = true;
1474 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341475 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221476 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321477 NotificationService::NoDetails());
1478}
1479
1480void TabContents::NotifyConnected() {
1481 notify_disconnection_ = true;
1482 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341483 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221484 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321485 NotificationService::NoDetails());
1486}
1487
1488void TabContents::NotifyDisconnected() {
1489 if (!notify_disconnection_)
1490 return;
1491
1492 notify_disconnection_ = false;
1493 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341494 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221495 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321496 NotificationService::NoDetails());
1497}
1498
1499void TabContents::GenerateKeywordIfNecessary(
1500 const ViewHostMsg_FrameNavigate_Params& params) {
1501 if (!params.searchable_form_url.is_valid())
1502 return;
1503
1504 if (profile()->IsOffTheRecord())
1505 return;
1506
1507 int last_index = controller_.last_committed_entry_index();
1508 // When there was no previous page, the last index will be 0. This is
1509 // normally due to a form submit that opened in a new tab.
1510 // TODO(brettw) bug 916126: we should support keywords when form submits
1511 // happen in new tabs.
1512 if (last_index <= 0)
1513 return;
1514 const NavigationEntry* previous_entry =
1515 controller_.GetEntryAtIndex(last_index - 1);
1516 if (IsFormSubmit(previous_entry)) {
1517 // Only generate a keyword if the previous page wasn't itself a form
1518 // submit.
1519 return;
1520 }
1521
1522 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1523 previous_entry->user_typed_url() : previous_entry->url();
1524 std::wstring keyword =
1525 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1526 if (keyword.empty())
1527 return;
1528
1529 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1530 if (!url_model)
1531 return;
1532
1533 if (!url_model->loaded()) {
1534 url_model->Load();
1535 return;
1536 }
1537
1538 const TemplateURL* current_url;
1539 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1540 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1541 return;
1542
1543 if (current_url) {
1544 if (current_url->originating_url().is_valid()) {
1545 // The existing keyword was generated from an OpenSearch description
1546 // document, don't regenerate.
1547 return;
1548 }
1549 url_model->Remove(current_url);
1550 }
1551 TemplateURL* new_url = new TemplateURL();
1552 new_url->set_keyword(keyword);
1553 new_url->set_short_name(keyword);
1554 new_url->SetURL(url, 0, 0);
1555 new_url->add_input_encoding(params.searchable_form_encoding);
1556 DCHECK(controller_.GetLastCommittedEntry());
1557 const GURL& favicon_url =
1558 controller_.GetLastCommittedEntry()->favicon().url();
1559 if (favicon_url.is_valid()) {
1560 new_url->SetFavIconURL(favicon_url);
1561 } else {
1562 // The favicon url isn't valid. This means there really isn't a favicon,
1563 // or the favicon url wasn't obtained before the load started. This assumes
1564 // the later.
1565 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1566 // its url.
1567 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1568 }
1569 new_url->set_safe_for_autoreplace(true);
1570 url_model->Add(new_url);
1571}
1572
[email protected]bf5c2ff392009-07-08 16:24:331573void TabContents::OnUserGesture() {
1574 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1575 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1576 if (drm)
1577 drm->OnUserGesture(this);
1578 controller_.OnUserGesture();
1579}
1580
1581void TabContents::OnFindReply(int request_id,
1582 int number_of_matches,
1583 const gfx::Rect& selection_rect,
1584 int active_match_ordinal,
1585 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421586 // Ignore responses for requests that have been aborted.
1587 if (find_op_aborted_)
1588 return;
1589
[email protected]bf5c2ff392009-07-08 16:24:331590 // Ignore responses for requests other than the one we have most recently
1591 // issued. That way we won't act on stale results when the user has
1592 // already typed in another query.
1593 if (request_id != current_find_request_id_)
1594 return;
1595
1596 if (number_of_matches == -1)
1597 number_of_matches = last_search_result_.number_of_matches();
1598 if (active_match_ordinal == -1)
1599 active_match_ordinal = last_search_result_.active_match_ordinal();
1600
1601 gfx::Rect selection = selection_rect;
1602 if (selection.IsEmpty())
1603 selection = last_search_result_.selection_rect();
1604
1605 // Notify the UI, automation and any other observers that a find result was
1606 // found.
1607 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1608 selection, active_match_ordinal,
1609 final_update);
1610 NotificationService::current()->Notify(
1611 NotificationType::FIND_RESULT_AVAILABLE,
1612 Source<TabContents>(this),
1613 Details<FindNotificationDetails>(&last_search_result_));
1614}
1615
1616void TabContents::GoToEntryAtOffset(int offset) {
1617 controller_.GoToOffset(offset);
1618}
1619
1620void TabContents::GetHistoryListCount(int* back_list_count,
1621 int* forward_list_count) {
1622 int current_index = controller_.last_committed_entry_index();
1623 *back_list_count = current_index;
1624 *forward_list_count = controller_.entry_count() - current_index - 1;
1625}
1626
1627void TabContents::OnMissingPluginStatus(int status) {
1628#if defined(OS_WIN)
1629// TODO(PORT): pull in when plug-ins work
1630 GetPluginInstaller()->OnMissingPluginStatus(status);
1631#endif
1632}
1633
1634void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331635 DCHECK(!plugin_path.value().empty());
1636
1637 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351638#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331639 scoped_ptr<FileVersionInfo> version_info(
1640 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1641 if (version_info.get()) {
1642 const std::wstring& product_name = version_info->product_name();
1643 if (!product_name.empty())
1644 plugin_name = product_name;
1645 }
[email protected]4a560ed2009-07-13 23:35:261646#else
1647 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1648#endif
[email protected]bf5c2ff392009-07-08 16:24:331649 AddInfoBar(new SimpleAlertInfoBarDelegate(
1650 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1651 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331652}
1653
1654void TabContents::OnCrashedWorker() {
1655 AddInfoBar(new SimpleAlertInfoBarDelegate(
1656 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1657 NULL));
1658}
1659
1660void TabContents::OnDidGetApplicationInfo(
1661 int32 page_id,
1662 const webkit_glue::WebApplicationInfo& info) {
1663 if (pending_install_.page_id != page_id)
1664 return; // The user clicked create on a separate page. Ignore this.
1665
1666 pending_install_.callback_functor =
1667 new GearsCreateShortcutCallbackFunctor(this);
1668 GearsCreateShortcut(
1669 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1670 NewCallback(pending_install_.callback_functor,
1671 &GearsCreateShortcutCallbackFunctor::Run));
1672}
1673
1674void TabContents::DidStartProvisionalLoadForFrame(
1675 RenderViewHost* render_view_host,
1676 bool is_main_frame,
1677 const GURL& url) {
1678 ProvisionalLoadDetails details(is_main_frame,
1679 controller_.IsURLInPageNavigation(url),
1680 url, std::string(), false);
1681 NotificationService::current()->Notify(
1682 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1683 Source<NavigationController>(&controller_),
1684 Details<ProvisionalLoadDetails>(&details));
1685}
1686
1687void TabContents::DidStartReceivingResourceResponse(
1688 ResourceRequestDetails* details) {
1689 NotificationService::current()->Notify(
1690 NotificationType::RESOURCE_RESPONSE_STARTED,
1691 Source<NavigationController>(&controller()),
1692 Details<ResourceRequestDetails>(details));
1693}
1694
1695void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1696 NotificationService::current()->Notify(
1697 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1698 Source<NavigationController>(&controller()),
1699 Details<ResourceRequestDetails>(details));
1700}
1701
1702void TabContents::DidLoadResourceFromMemoryCache(
1703 const GURL& url,
1704 const std::string& frame_origin,
1705 const std::string& main_frame_origin,
1706 const std::string& security_info) {
1707 // Send out a notification that we loaded a resource from our memory cache.
1708 int cert_id = 0, cert_status = 0, security_bits = 0;
1709 SSLManager::DeserializeSecurityInfo(security_info,
1710 &cert_id, &cert_status,
1711 &security_bits);
1712 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]76543b92009-08-31 17:27:451713 process()->id(), cert_id, cert_status);
[email protected]bf5c2ff392009-07-08 16:24:331714
1715 NotificationService::current()->Notify(
1716 NotificationType::LOAD_FROM_MEMORY_CACHE,
1717 Source<NavigationController>(&controller_),
1718 Details<LoadFromMemoryCacheDetails>(&details));
1719}
1720
1721void TabContents::DidFailProvisionalLoadWithError(
1722 RenderViewHost* render_view_host,
1723 bool is_main_frame,
1724 int error_code,
1725 const GURL& url,
1726 bool showing_repost_interstitial) {
1727 if (net::ERR_ABORTED == error_code) {
1728 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1729 // This means that the interstitial won't be torn down properly, which is
1730 // bad. But if we have an interstitial, go back to another tab type, and
1731 // then load the same interstitial again, we could end up getting the first
1732 // interstitial's "failed" message (as a result of the cancel) when we're on
1733 // the second one.
1734 //
1735 // We can't tell this apart, so we think we're tearing down the current page
1736 // which will cause a crash later one. There is also some code in
1737 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1738 // out because of this problem.
1739 //
1740 // http://code.google.com/p/chromium/issues/detail?id=2855
1741 // Because this will not tear down the interstitial properly, if "back" is
1742 // back to another tab type, the interstitial will still be somewhat alive
1743 // in the previous tab type. If you navigate somewhere that activates the
1744 // tab with the interstitial again, you'll see a flash before the new load
1745 // commits of the interstitial page.
1746 if (showing_interstitial_page()) {
1747 LOG(WARNING) << "Discarding message during interstitial.";
1748 return;
1749 }
1750
1751 // This will discard our pending entry if we cancelled the load (e.g., if we
1752 // decided to download the file instead of load it). Only discard the
1753 // pending entry if the URLs match, otherwise the user initiated a navigate
1754 // before the page loaded so that the discard would discard the wrong entry.
1755 NavigationEntry* pending_entry = controller_.pending_entry();
1756 if (pending_entry && pending_entry->url() == url) {
1757 controller_.DiscardNonCommittedEntries();
1758 // Update the URL display.
1759 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1760 }
1761
1762 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1763 }
1764
1765 // Send out a notification that we failed a provisional load with an error.
1766 ProvisionalLoadDetails details(is_main_frame,
1767 controller_.IsURLInPageNavigation(url),
1768 url, std::string(), false);
1769 details.set_error_code(error_code);
1770
1771 NotificationService::current()->Notify(
1772 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1773 Source<NavigationController>(&controller_),
1774 Details<ProvisionalLoadDetails>(&details));
1775}
1776
1777void TabContents::DocumentLoadedInFrame() {
1778 controller_.DocumentLoadedInFrame();
1779}
1780
[email protected]8d3347f2009-07-09 22:00:211781RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321782 return view_.get();
1783}
1784
[email protected]8d3347f2009-07-09 22:00:211785RenderViewHostDelegate::RendererManagement*
1786TabContents::GetRendererManagementDelegate() {
1787 return &render_manager_;
1788}
1789
[email protected]bf5c2ff392009-07-08 16:24:331790RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211791 TabContents::GetBrowserIntegrationDelegate() {
1792 return this;
[email protected]bf5c2ff392009-07-08 16:24:331793}
1794
[email protected]8d3347f2009-07-09 22:00:211795RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1796 return this;
[email protected]bf5c2ff392009-07-08 16:24:331797}
1798
[email protected]8d3347f2009-07-09 22:00:211799RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321800 return save_package_.get(); // May be NULL, but we can return NULL.
1801}
1802
[email protected]8d3347f2009-07-09 22:00:211803RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1804 return &printing_;
1805}
1806
1807RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1808 return &fav_icon_helper_;
1809}
1810
1811RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1812 if (autofill_manager_.get() == NULL)
1813 autofill_manager_.reset(new AutofillManager(this));
1814 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331815}
1816
[email protected]80d96fa2009-06-10 22:34:511817RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461818 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511819}
1820
[email protected]57c6a652009-05-04 07:58:341821TabContents* TabContents::GetAsTabContents() {
1822 return this;
1823}
1824
[email protected]3e7cf1362009-08-21 17:47:081825void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1826 CreateBlockedPopupContainerIfNecessary();
1827 blocked_popups_->AddBlockedNotice(url, reason);
1828}
1829
[email protected]7b291f92009-08-14 05:43:531830ViewType::Type TabContents::GetRenderViewType() const {
1831 return ViewType::TAB_CONTENTS;
1832}
1833
1834int TabContents::GetBrowserWindowID() const {
1835 return controller().window_id().id();
1836}
1837
[email protected]420ae012009-04-24 05:16:321838void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061839 NotificationService::current()->Notify(
1840 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1841 Source<TabContents>(this),
1842 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321843 NavigationEntry* entry = controller_.GetActiveEntry();
1844 if (!entry)
1845 return;
1846
1847 // When we're creating views, we're still doing initial setup, so we always
1848 // use the pending DOM UI rather than any possibly existing committed one.
1849 if (render_manager_.pending_dom_ui()) {
1850 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1851 }
1852
1853 if (entry->IsViewSourceMode()) {
1854 // Put the renderer in view source mode.
1855 render_view_host->Send(
1856 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1857 }
[email protected]0666aef2009-05-13 19:48:081858
1859 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321860}
1861
1862void TabContents::RenderViewReady(RenderViewHost* rvh) {
1863 if (rvh != render_view_host()) {
1864 // Don't notify the world, since this came from a renderer in the
1865 // background.
1866 return;
1867 }
1868
1869 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301870 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321871 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301872
1873 // Restore the focus to the tab (otherwise the focus will be on the top
1874 // window).
1875 if (was_crashed && !FocusLocationBarByDefault())
1876 Focus();
[email protected]420ae012009-04-24 05:16:321877}
1878
1879void TabContents::RenderViewGone(RenderViewHost* rvh) {
1880 // Ask the print preview if this renderer was valuable.
1881 if (!printing_.OnRenderViewGone(rvh))
1882 return;
1883 if (rvh != render_view_host()) {
1884 // The pending page's RenderViewHost is gone.
1885 return;
1886 }
1887
1888 SetIsLoading(false, NULL);
1889 NotifyDisconnected();
1890 SetIsCrashed(true);
1891
[email protected]8e537302009-06-10 21:19:581892 // Tell the view that we've crashed so it can prepare the sad tab page.
1893 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321894
1895 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221896 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321897}
1898
[email protected]2e4633c2009-07-09 16:58:061899void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1900 NotificationService::current()->Notify(
1901 NotificationType::RENDER_VIEW_HOST_DELETED,
1902 Source<TabContents>(this),
1903 Details<RenderViewHost>(rvh));
1904}
1905
[email protected]420ae012009-04-24 05:16:321906void TabContents::DidNavigate(RenderViewHost* rvh,
1907 const ViewHostMsg_FrameNavigate_Params& params) {
1908 if (PageTransition::IsMainFrame(params.transition))
1909 render_manager_.DidNavigateMainFrame(rvh);
1910
1911 // Update the site of the SiteInstance if it doesn't have one yet.
1912 if (!GetSiteInstance()->has_site())
1913 GetSiteInstance()->SetSite(params.url);
1914
1915 // Need to update MIME type here because it's referred to in
1916 // UpdateNavigationCommands() called by RendererDidNavigate() to
1917 // determine whether or not to enable the encoding menu.
1918 // It's updated only for the main frame. For a subframe,
1919 // RenderView::UpdateURL does not set params.contents_mime_type.
1920 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1921 // TODO(jungshik): Add a test for the encoding menu to avoid
1922 // regressing it again.
1923 if (PageTransition::IsMainFrame(params.transition))
1924 contents_mime_type_ = params.contents_mime_type;
1925
1926 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391927 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1928
1929 // Update history. Note that this needs to happen after the entry is complete,
1930 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1931 if (params.should_update_history) {
1932 // Most of the time, the displayURL matches the loaded URL, but for about:
1933 // URLs, we use a data: URL as the real value. We actually want to save
1934 // the about: URL to the history db and keep the data: URL hidden. This is
1935 // what the TabContents' URL getter does.
1936 UpdateHistoryForNavigation(GetURL(), details, params);
1937 }
1938
[email protected]76543b92009-08-31 17:27:451939 if (!did_navigate)
1940 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321941
1942 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1943 // for the appropriate notification (best) or you can add it to
1944 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1945 // necessary, please).
1946
1947 // Run post-commit tasks.
1948 if (details.is_main_frame)
1949 DidNavigateMainFramePostCommit(details, params);
1950 DidNavigateAnyFramePostCommit(rvh, details, params);
1951}
1952
1953void TabContents::UpdateState(RenderViewHost* rvh,
1954 int32 page_id,
1955 const std::string& state) {
1956 DCHECK(rvh == render_view_host());
1957
1958 // We must be prepared to handle state updates for any page, these occur
1959 // when the user is scrolling and entering form data, as well as when we're
1960 // leaving a page, in which case our state may have already been moved to
1961 // the next page. The navigation controller will look up the appropriate
1962 // NavigationEntry and update it when it is notified via the delegate.
1963
1964 int entry_index = controller_.GetEntryIndexWithPageID(
1965 GetSiteInstance(), page_id);
1966 if (entry_index < 0)
1967 return;
1968 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1969
1970 if (state == entry->content_state())
1971 return; // Nothing to update.
1972 entry->set_content_state(state);
1973 controller_.NotifyEntryChanged(entry, entry_index);
1974}
1975
1976void TabContents::UpdateTitle(RenderViewHost* rvh,
1977 int32 page_id, const std::wstring& title) {
1978 // If we have a title, that's a pretty good indication that we've started
1979 // getting useful data.
1980 SetNotWaitingForResponse();
1981
1982 DCHECK(rvh == render_view_host());
1983 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
1984 page_id);
1985 if (!entry || !UpdateTitleForEntry(entry, title))
1986 return;
1987
1988 // Broadcast notifications when the UI should be updated.
1989 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:501990 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321991}
1992
[email protected]420ae012009-04-24 05:16:321993void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
1994 const std::wstring& encoding) {
1995 set_encoding(encoding);
1996}
1997
1998void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1999 if (delegate())
2000 delegate()->UpdateTargetURL(this, url);
2001}
2002
2003void TabContents::UpdateThumbnail(const GURL& url,
2004 const SkBitmap& bitmap,
2005 const ThumbnailScore& score) {
2006 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282007 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492008 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192009 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2010 score, true);
[email protected]449478302009-06-09 20:04:282011 } else {
2012 HistoryService* hs;
2013 if (!profile()->IsOffTheRecord() &&
2014 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2015 hs->SetPageThumbnail(url, bitmap, score);
2016 }
[email protected]420ae012009-04-24 05:16:322017 }
2018}
2019
[email protected]0df30122009-06-03 12:13:082020void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2021 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2022 raw_settings);
2023}
2024
[email protected]420ae012009-04-24 05:16:322025void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422026 // If we close the tab while we're in the middle of a drag, we'll crash.
2027 // Instead, cancel the drag and close it as soon as the drag ends.
2028 if (view()->IsDoingDrag()) {
2029 view()->CancelDragAndCloseTab();
2030 return;
2031 }
2032
[email protected]420ae012009-04-24 05:16:322033 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2034 if (delegate() && rvh == render_view_host())
2035 delegate()->CloseContents(this);
2036}
2037
2038void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2039 if (delegate() && delegate()->IsPopup(this))
2040 delegate()->MoveContents(this, new_bounds);
2041}
2042
[email protected]329581b2009-04-28 06:52:352043void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322044 SetIsLoading(true, NULL);
2045}
2046
[email protected]329581b2009-04-28 06:52:352047void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322048 scoped_ptr<LoadNotificationDetails> details;
2049
2050 NavigationEntry* entry = controller_.GetActiveEntry();
2051 // An entry may not exist for a stop when loading an initial blank page or
2052 // if an iframe injected by script into a blank page finishes loading.
2053 if (entry) {
2054 scoped_ptr<base::ProcessMetrics> metrics(
2055 base::ProcessMetrics::CreateProcessMetrics(
2056 process()->process().handle()));
2057
2058 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2059
2060 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542061 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322062 entry->transition_type(),
2063 elapsed,
2064 &controller_,
2065 controller_.GetCurrentEntryIndex()));
2066 }
2067
2068 // Tell PasswordManager we've finished a page load, which serves as a
2069 // green light to save pending passwords and reset itself.
2070 GetPasswordManager()->DidStopLoading();
2071
2072 SetIsLoading(false, details.get());
2073}
2074
[email protected]420ae012009-04-24 05:16:322075void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2076 const GURL& source_url,
2077 const GURL& target_url) {
2078 NavigationEntry* entry;
2079 if (page_id == -1)
2080 entry = controller_.pending_entry();
2081 else
2082 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2083 if (!entry || entry->url() != source_url)
2084 return;
2085 entry->set_url(target_url);
2086}
2087
[email protected]420ae012009-04-24 05:16:322088void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2089 WindowOpenDisposition disposition) {
2090 if (render_manager_.dom_ui()) {
2091 // When we're a DOM UI, it will provide a page transition type for us (this
2092 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2093 // generated suggestions).
2094 //
2095 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162096 // want web sites to see a referrer of "chrome://blah" (and some
2097 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322098 // send to the site), so we send no referrer.
2099 OpenURL(url, GURL(), disposition,
2100 render_manager_.dom_ui()->link_transition_type());
2101 } else {
2102 OpenURL(url, referrer, disposition, PageTransition::LINK);
2103 }
2104}
2105
[email protected]1ee614862009-07-06 20:29:182106void TabContents::DomOperationResponse(const std::string& json_string,
2107 int automation_id) {
2108}
2109
[email protected]420ae012009-04-24 05:16:322110void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252111 const std::string& content,
2112 int request_id,
2113 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322114 if (!render_manager_.dom_ui()) {
2115 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI.
2116 // Because the renderer might be owned and sending random messages, we need
2117 // to ignore these inproper ones.
2118 NOTREACHED();
2119 return;
2120 }
[email protected]811bfe32009-07-01 08:46:252121 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2122 has_callback);
[email protected]420ae012009-04-24 05:16:322123}
2124
2125void TabContents::ProcessExternalHostMessage(const std::string& message,
2126 const std::string& origin,
2127 const std::string& target) {
2128 if (delegate())
2129 delegate()->ForwardMessageToExternalHost(message, origin, target);
2130}
2131
[email protected]420ae012009-04-24 05:16:322132void TabContents::RunFileChooser(bool multiple_files,
2133 const string16& title,
2134 const FilePath& default_file) {
2135 if (!select_file_dialog_.get())
2136 select_file_dialog_ = SelectFileDialog::Create(this);
2137 SelectFileDialog::Type dialog_type =
2138 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2139 SelectFileDialog::SELECT_OPEN_FILE;
2140 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2141 NULL, 0, FILE_PATH_LITERAL(""),
2142 view_->GetTopLevelNativeWindow(), NULL);
2143}
2144
2145void TabContents::RunJavaScriptMessage(
2146 const std::wstring& message,
2147 const std::wstring& default_prompt,
2148 const GURL& frame_url,
2149 const int flags,
2150 IPC::Message* reply_msg,
2151 bool* did_suppress_message) {
2152 // Suppress javascript messages when requested and when inside a constrained
2153 // popup window (because that activates them and breaks them out of the
2154 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552155 // Also suppress messages when showing an interstitial. The interstitial is
2156 // shown over the previous page, we don't want the hidden page dialogs to
2157 // interfere with the interstitial.
2158 bool suppress_this_message = suppress_javascript_messages_ ||
2159 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322160 if (delegate())
2161 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312162 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322163
2164 *did_suppress_message = suppress_this_message;
2165
2166 if (!suppress_this_message) {
2167 base::TimeDelta time_since_last_message(
2168 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2169 bool show_suppress_checkbox = false;
2170 // Show a checkbox offering to suppress further messages if this message is
2171 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2172 if (time_since_last_message <
2173 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2174 show_suppress_checkbox = true;
2175
[email protected]d82ed61e2009-06-16 02:46:222176 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322177 show_suppress_checkbox, reply_msg);
2178 } else {
2179 // If we are suppressing messages, just reply as is if the user immediately
2180 // pressed "Cancel".
2181 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2182 }
2183}
2184
2185void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2186 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222187 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322188}
2189
2190void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2191 const std::string& json_arguments,
2192 IPC::Message* reply_msg) {
2193 if (delegate()) {
2194 HtmlDialogUIDelegate* dialog_delegate =
2195 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222196 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322197 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2198 }
2199}
2200
2201void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562202 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322203 GetPasswordManager()->PasswordFormsSeen(forms);
2204}
2205
[email protected]420ae012009-04-24 05:16:322206// Checks to see if we should generate a keyword based on the OSDD, and if
2207// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2208void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2209 int32 page_id, const GURL& url,
2210 bool autodetected) {
2211 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2212 DCHECK(url.is_valid());
2213 if (!IsActiveEntry(page_id))
2214 return;
2215 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2216 if (!url_model)
2217 return;
2218 if (!url_model->loaded()) {
2219 url_model->Load();
2220 return;
2221 }
2222 if (!profile()->GetTemplateURLFetcher())
2223 return;
2224
2225 if (profile()->IsOffTheRecord())
2226 return;
2227
2228 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2229 DCHECK(entry);
2230
2231 const NavigationEntry* base_entry = entry;
2232 if (IsFormSubmit(base_entry)) {
2233 // If the current page is a form submit, find the last page that was not
2234 // a form submit and use its url to generate the keyword from.
2235 int index = controller_.last_committed_entry_index() - 1;
2236 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2237 index--;
2238 if (index >= 0)
2239 base_entry = controller_.GetEntryAtIndex(index);
2240 else
2241 base_entry = NULL;
2242 }
2243
2244 // We want to use the user typed URL if available since that represents what
2245 // the user typed to get here, and fall back on the regular URL if not.
2246 if (!base_entry)
2247 return;
2248 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2249 base_entry->user_typed_url() : base_entry->url();
2250 if (!keyword_url.is_valid())
2251 return;
2252 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2253 autodetected);
2254 if (keyword.empty())
2255 return;
2256 const TemplateURL* template_url =
2257 url_model->GetTemplateURLForKeyword(keyword);
2258 if (template_url && (!template_url->safe_for_autoreplace() ||
2259 template_url->originating_url() == url)) {
2260 // Either there is a user created TemplateURL for this keyword, or the
2261 // keyword has the same OSDD url and we've parsed it.
2262 return;
2263 }
2264
2265 // Download the OpenSearch description document. If this is successful a
2266 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322267 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2268 keyword,
2269 url,
2270 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162271 this,
[email protected]420ae012009-04-24 05:16:322272 autodetected);
2273}
2274
[email protected]420ae012009-04-24 05:16:322275GURL TabContents::GetAlternateErrorPageURL() const {
2276 GURL url;
2277 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2278 if (profile()->IsOffTheRecord())
2279 return url;
2280
2281 PrefService* prefs = profile()->GetPrefs();
2282 DCHECK(prefs);
2283 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202284 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322285 url = google_util::AppendGoogleTLDParam(url);
2286 }
2287 return url;
2288}
2289
2290WebPreferences TabContents::GetWebkitPrefs() {
2291 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552292 bool is_dom_ui = false;
2293 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322294}
2295
[email protected]420ae012009-04-24 05:16:322296void TabContents::OnJSOutOfMemory() {
2297 AddInfoBar(new SimpleAlertInfoBarDelegate(
2298 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2299}
2300
[email protected]420ae012009-04-24 05:16:322301void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2302 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342303 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322304 // delivered to a pending RenderViewHost. We must first run the onunload
2305 // handler of the old RenderViewHost before we can allow it to proceed.
2306 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2307 new_request_id);
2308}
2309
2310bool TabContents::CanBlur() const {
2311 return delegate() ? delegate()->CanBlur() : true;
2312}
2313
2314gfx::Rect TabContents::GetRootWindowResizerRect() const {
2315 if (delegate())
2316 return delegate()->GetRootWindowResizerRect();
2317 return gfx::Rect();
2318}
2319
2320void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2321 bool is_during_unload) {
2322 if (is_during_unload) {
2323 // Hang occurred while firing the beforeunload/unload handler.
2324 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112325 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322326
2327 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2328 return;
2329
2330 // If the tab hangs in the beforeunload/unload handler there's really
2331 // nothing we can do to recover. Pretend the unload listeners have
2332 // all fired and close the tab. If the hang is in the beforeunload handler
2333 // then the user will not have the option of cancelling the close.
2334 Close(rvh);
2335 return;
2336 }
2337
2338 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222339 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322340}
2341
2342void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222343 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322344}
2345
2346void TabContents::LoadStateChanged(const GURL& url,
2347 net::LoadState load_state) {
2348 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292349 std::wstring languages =
2350 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2351 load_state_host_.clear();
2352 std::string host = url.host();
2353 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322354 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2355 SetNotWaitingForResponse();
2356 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502357 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322358}
2359
[email protected]1ee614862009-07-06 20:29:182360bool TabContents::IsExternalTabContainer() const {
2361 if (!delegate())
2362 return false;
2363
2364 return delegate()->IsExternalTabContainer();
2365}
2366
[email protected]1ee614862009-07-06 20:29:182367void TabContents::DidInsertCSS() {
2368 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322369}
2370
2371void TabContents::FileSelected(const FilePath& path,
2372 int index, void* params) {
2373 render_view_host()->FileSelected(path);
2374}
2375
2376void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2377 void* params) {
2378 render_view_host()->MultiFilesSelected(files);
2379}
2380
2381void TabContents::FileSelectionCanceled(void* params) {
2382 // If the user cancels choosing a file to upload we pass back an
2383 // empty vector.
2384 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2385}
2386
2387void TabContents::BeforeUnloadFiredFromRenderManager(
2388 bool proceed,
2389 bool* proceed_to_fire_unload) {
2390 if (delegate())
2391 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2392}
2393
2394void TabContents::UpdateRenderViewSizeForRenderManager() {
2395 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2396 view_->SizeContents(view_->GetContainerSize());
2397}
2398
2399DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222400 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322401}
2402
2403NavigationEntry*
2404TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2405 return controller_.GetLastCommittedEntry();
2406}
2407
2408bool TabContents::CreateRenderViewForRenderManager(
2409 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252410 // If the pending navigation is to a DOMUI, tell the RenderView about any
2411 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322412 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252413 render_view_host->AllowBindings(
2414 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552415
[email protected]420ae012009-04-24 05:16:322416 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2417 if (!render_view_host->CreateRenderView())
2418 return false;
2419
2420 // Now that the RenderView has been created, we need to tell it its size.
2421 rwh_view->SetSize(view_->GetContainerSize());
2422
2423 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2424 render_view_host);
2425 return true;
2426}
2427
2428void TabContents::Observe(NotificationType type,
2429 const NotificationSource& source,
2430 const NotificationDetails& details) {
2431 switch (type.value) {
2432 case NotificationType::BOOKMARK_MODEL_LOADED:
2433 // BookmarkModel finished loading, fall through to update starred state.
2434 case NotificationType::URLS_STARRED: {
2435 // Somewhere, a URL has been starred.
2436 // Ignore notifications for profiles other than our current one.
2437 Profile* source_profile = Source<Profile>(source).ptr();
2438 if (!source_profile || !source_profile->IsSameProfile(profile()))
2439 return;
2440
2441 UpdateStarredStateForCurrentURL();
2442 break;
2443 }
2444 case NotificationType::PREF_CHANGED: {
2445 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2446 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2447 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2448 UpdateAlternateErrorPageURL();
2449 } else if (*pref_name_in == prefs::kDefaultCharset ||
2450 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2451 ) {
2452 UpdateWebPreferences();
2453 } else {
2454 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2455 }
2456 break;
2457 }
2458 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2459 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2460 break;
2461
2462 case NotificationType::NAV_ENTRY_COMMITTED: {
2463 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2464
2465 NavigationController::LoadCommittedDetails& committed_details =
2466 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2467 ExpireInfoBars(committed_details);
2468 break;
2469 }
2470
2471 default:
2472 NOTREACHED();
2473 }
2474}
[email protected]aacd7cc2009-09-02 14:51:102475
2476void TabContents::set_encoding(const std::wstring& encoding) {
2477 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2478}
2479