blob: b5b5111d409c69fd101683d6bb8cef92dd81e0ee [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]bce1e5912009-09-02 22:40:20262 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_);
[email protected]96d185d2009-04-24 03:28:54475 return EmptyString16();
476}
477
[email protected]d5f942ba2008-09-26 19:30:34478int32 TabContents::GetMaxPageID() {
479 if (GetSiteInstance())
480 return GetSiteInstance()->max_page_id();
481 else
482 return max_page_id_;
483}
484
485void TabContents::UpdateMaxPageID(int32 page_id) {
486 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34487 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34488 // testing.
489 if (GetSiteInstance())
490 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]57c6a652009-05-04 07:58:34491 process()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34492}
493
[email protected]96d185d2009-04-24 03:28:54494SiteInstance* TabContents::GetSiteInstance() const {
495 return render_manager_.current_host()->site_instance();
496}
497
[email protected]d5f942ba2008-09-26 19:30:34498const std::wstring TabContents::GetDefaultTitle() const {
499 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
500}
501
[email protected]96d185d2009-04-24 03:28:54502bool TabContents::ShouldDisplayURL() {
503 // Don't hide the url in view source mode.
504 NavigationEntry* entry = controller_.GetActiveEntry();
505 if (entry && entry->IsViewSourceMode())
506 return true;
[email protected]83e3895b2009-06-11 00:07:16507
[email protected]96d185d2009-04-24 03:28:54508 DOMUI* dom_ui = GetDOMUIForCurrentState();
509 if (dom_ui)
510 return !dom_ui->should_hide_url();
511 return true;
512}
513
[email protected]d5f942ba2008-09-26 19:30:34514SkBitmap TabContents::GetFavIcon() const {
515 // Like GetTitle(), we also want to use the favicon for the last committed
516 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57517 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47518 if (entry)
519 return entry->favicon().bitmap();
520
[email protected]ce3fa3c2009-04-20 19:55:57521 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34522 if (entry)
523 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34524 return SkBitmap();
525}
526
[email protected]96d185d2009-04-24 03:28:54527bool TabContents::ShouldDisplayFavIcon() {
528 // Always display a throbber during pending loads.
529 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
530 return true;
531
532 DOMUI* dom_ui = GetDOMUIForCurrentState();
533 if (dom_ui)
534 return !dom_ui->hide_favicon();
535 return true;
536}
537
[email protected]96d185d2009-04-24 03:28:54538std::wstring TabContents::GetStatusText() const {
539 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
540 return std::wstring();
541
542 switch (load_state_) {
543 case net::LOAD_STATE_WAITING_FOR_CACHE:
544 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
545 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
546 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
547 case net::LOAD_STATE_RESOLVING_HOST:
548 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
549 case net::LOAD_STATE_CONNECTING:
550 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
551 case net::LOAD_STATE_SENDING_REQUEST:
552 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
553 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
554 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
555 load_state_host_);
556 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
557 case net::LOAD_STATE_IDLE:
558 case net::LOAD_STATE_READING_RESPONSE:
559 break;
560 }
561
562 return std::wstring();
563}
564
[email protected]d5f942ba2008-09-26 19:30:34565void TabContents::SetIsCrashed(bool state) {
566 if (state == is_crashed_)
567 return;
568
569 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50570 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34571}
572
[email protected]f9b1a7b2009-06-22 17:26:38573void TabContents::SetPageActionEnabled(const PageAction* page_action,
[email protected]d7eaf572009-07-01 21:57:00574 bool enable,
575 const std::string& title,
576 int icon_id) {
[email protected]ce5c4502009-05-06 16:46:11577 DCHECK(page_action);
578
[email protected]d7eaf572009-07-01 21:57:00579 if (!enable &&
580 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
581 return; // Don't need to disable twice.
582 }
[email protected]ce5c4502009-05-06 16:46:11583
[email protected]d7eaf572009-07-01 21:57:00584 if (enable) {
585 enabled_page_actions_[page_action].reset(
586 new PageActionState(title, icon_id));
587 } else {
[email protected]f9b1a7b2009-06-22 17:26:38588 enabled_page_actions_.erase(page_action);
[email protected]d7eaf572009-07-01 21:57:00589 }
[email protected]ce5c4502009-05-06 16:46:11590}
591
[email protected]d7eaf572009-07-01 21:57:00592const PageActionState* TabContents::GetPageActionState(
593 const PageAction* page_action) {
594 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
595 return NULL;
[email protected]ce5c4502009-05-06 16:46:11596
[email protected]d7eaf572009-07-01 21:57:00597 return enabled_page_actions_[page_action].get();
598}
[email protected]ce5c4502009-05-06 16:46:11599
[email protected]d5f942ba2008-09-26 19:30:34600void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
601 if (delegate_)
602 delegate_->NavigationStateChanged(this, changed_flags);
603}
604
[email protected]96d185d2009-04-24 03:28:54605void TabContents::DidBecomeSelected() {
606 controller_.SetActive(true);
[email protected]789e9152009-08-04 21:59:43607 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54608 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43609#if defined(OS_MACOSX)
610 render_widget_host_view()->SetActive(true);
611#endif
612 }
[email protected]96d185d2009-04-24 03:28:54613
[email protected]76543b92009-08-31 17:27:45614 WebCacheManager::GetInstance()->ObserveActivity(process()->id());
[email protected]96d185d2009-04-24 03:28:54615}
616
617void TabContents::WasHidden() {
618 if (!capturing_contents()) {
619 // |render_view_host()| can be NULL if the user middle clicks a link to open
620 // a tab in then background, then closes the tab before selecting it. This
621 // is because closing the tab calls TabContents::Destroy(), which removes
622 // the |render_view_host()|; then when we actually destroy the window,
623 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
624 if (render_widget_host_view())
625 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54626 }
627
628 NotificationService::current()->Notify(
629 NotificationType::TAB_CONTENTS_HIDDEN,
630 Source<TabContents>(this),
631 NotificationService::NoDetails());
632}
633
[email protected]d5f942ba2008-09-26 19:30:34634void TabContents::Activate() {
635 if (delegate_)
636 delegate_->ActivateContents(this);
637}
638
[email protected]96d185d2009-04-24 03:28:54639void TabContents::ShowContents() {
640 if (render_widget_host_view())
641 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54642}
643
644void TabContents::HideContents() {
645 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
646 // our superclass HideContents(), because some callers want to be very picky
647 // about the order in which these get called. In addition to making the code
648 // here practically impossible to understand, this also means we end up
649 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34650 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54651 WasHidden();
652}
653
[email protected]c0588052008-10-27 23:01:50654void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34655 WindowOpenDisposition disposition,
656 PageTransition::Type transition) {
657 if (delegate_)
[email protected]c0588052008-10-27 23:01:50658 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34659}
660
661bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54662 const NavigationEntry& entry = *controller_.pending_entry();
663
664 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
665 if (!dest_render_view_host)
666 return false; // Unable to create the desired render view host.
667
668 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12669 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32670 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41671 devtools_manager->OnNavigatingToPendingEntry(
672 render_view_host(),
673 dest_render_view_host,
674 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32675 }
[email protected]96d185d2009-04-24 03:28:54676
677 // Used for page load time metrics.
678 current_load_start_ = base::TimeTicks::Now();
679
680 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34681 ViewMsg_Navigate_Params navigate_params;
682 MakeNavigateParams(entry, reload, &navigate_params);
683 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54684
685 if (entry.page_id() == -1) {
686 // HACK!! This code suppresses javascript: URLs from being added to
687 // session history, which is what we want to do for javascript: URLs that
688 // do not generate content. What we really need is a message from the
689 // renderer telling us that a new page was not created. The same message
690 // could be used for mailto: URLs and the like.
691 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
692 return false;
693 }
694
695 // Clear any provisional password saves - this stops password infobars
696 // showing up on pages the user navigates to while the right page is
697 // loading.
698 GetPasswordManager()->ClearProvisionalSave();
699
700 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48701 FaviconService* favicon_service =
702 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
703 if (favicon_service)
704 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54705 }
706
[email protected]d5f942ba2008-09-26 19:30:34707 return true;
708}
709
[email protected]96d185d2009-04-24 03:28:54710void TabContents::Stop() {
711 render_manager_.Stop();
712 printing_.Stop();
713}
714
715void TabContents::Cut() {
716 render_view_host()->Cut();
717}
718
719void TabContents::Copy() {
720 render_view_host()->Copy();
721}
722
723void TabContents::Paste() {
724 render_view_host()->Paste();
725}
726
727void TabContents::DisassociateFromPopupCount() {
728 render_view_host()->DisassociateFromPopupCount();
729}
730
731TabContents* TabContents::Clone() {
732 // We create a new SiteInstance so that the new tab won't share processes
733 // with the old one. This can be changed in the future if we need it to share
734 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32735 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54736 SiteInstance::CreateSiteInstance(profile()),
737 MSG_ROUTING_NONE, NULL);
738 tc->controller().CopyStateFrom(controller_);
739 return tc;
740}
741
[email protected]420ae012009-04-24 05:16:32742void TabContents::CreateShortcut() {
743 NavigationEntry* entry = controller_.GetLastCommittedEntry();
744 if (!entry)
745 return;
746
[email protected]70b8d6b2009-08-20 16:56:24747#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13748 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
749 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49750#else
[email protected]420ae012009-04-24 05:16:32751 // We only allow one pending install request. By resetting the page id we
752 // effectively cancel the pending install request.
753 pending_install_.page_id = entry->page_id();
754 pending_install_.icon = GetFavIcon();
755 pending_install_.title = UTF16ToWideHack(GetTitle());
756 pending_install_.url = GetURL();
757 if (pending_install_.callback_functor) {
758 pending_install_.callback_functor->Cancel();
759 pending_install_.callback_functor = NULL;
760 }
761 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
762 if (pending_install_.title.empty())
763 pending_install_.title = UTF8ToWide(GetURL().spec());
764
765 // Request the application info. When done OnDidGetApplicationInfo is invoked
766 // and we'll create the shortcut.
767 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49768#endif
[email protected]420ae012009-04-24 05:16:32769}
770
[email protected]4d677202009-07-19 07:37:12771void TabContents::ShowPageInfo(const GURL& url,
772 const NavigationEntry::SSLStatus& ssl,
773 bool show_history) {
774 if (!delegate_)
775 return;
776
[email protected]bb678332009-07-21 00:15:50777 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12778}
779
initial.commit09911bf2008-07-26 23:55:29780ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28781 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29782 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28783 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29784 child_windows_.push_back(window);
785 return window;
786}
787
788void TabContents::AddNewContents(TabContents* new_contents,
789 WindowOpenDisposition disposition,
790 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22791 bool user_gesture,
792 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29793 if (!delegate_)
794 return;
795
[email protected]35f7d212009-04-29 21:19:27796 if ((disposition == NEW_POPUP) && !user_gesture &&
797 !CommandLine::ForCurrentProcess()->HasSwitch(
798 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22799 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31800 // the whitelist. The popup owner will handle checking this.
801 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
802 initial_pos,
803 creator_url.is_valid() ? creator_url.host() : std::string());
804 } else {
[email protected]304f8792009-08-19 21:28:09805#if defined(OS_CHROMEOS)
806 if (disposition == NEW_POPUP) {
807 // If the popup is bigger than a given factor of the screen, then
808 // turn it into a foreground tab (on chrome os only)
809 GdkScreen* screen = gdk_screen_get_default();
810 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
811 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
812 if (initial_pos.width() > max_width ||
813 initial_pos.height() > max_height) {
814 disposition = NEW_FOREGROUND_TAB;
815 }
816 }
817#endif
818
[email protected]0aa55312008-10-17 21:53:08819 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29820 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
821 user_gesture);
822 }
[email protected]b6c874582009-05-08 19:38:31823 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29824}
825
initial.commit09911bf2008-07-26 23:55:29826void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25827 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22828 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29829}
830
[email protected]96d185d2009-04-24 03:28:54831void TabContents::PopupNotificationVisibilityChanged(bool visible) {
832 render_view_host()->PopupNotificationVisibilityChanged(visible);
833}
834
835gfx::NativeView TabContents::GetContentNativeView() {
836 return view_->GetContentNativeView();
837}
838
839gfx::NativeView TabContents::GetNativeView() const {
840 return view_->GetNativeView();
841}
842
843void TabContents::GetContainerBounds(gfx::Rect *out) const {
844 view_->GetContainerBounds(out);
845}
846
847void TabContents::Focus() {
848 view_->Focus();
849}
850
[email protected]90daadb42009-06-08 21:27:28851void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54852 if (showing_interstitial_page()) {
853 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
854 return;
855 }
[email protected]96d185d2009-04-24 03:28:54856 render_view_host()->SetInitialFocus(reverse);
857}
858
859bool TabContents::FocusLocationBarByDefault() {
860 DOMUI* dom_ui = GetDOMUIForCurrentState();
861 if (dom_ui)
862 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43863 NavigationEntry* entry = controller_.GetActiveEntry();
864 if (entry && entry->url() == GURL("about:blank"))
865 return true;
[email protected]96d185d2009-04-24 03:28:54866 return false;
867}
868
[email protected]616ed5a2008-11-21 22:27:24869void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
870 // Look through the existing InfoBarDelegates we have for a match. If we've
871 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05872 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24873 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
874 return;
875 }
876
877 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56878 NotificationService::current()->Notify(
879 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
880 Source<TabContents>(this),
881 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24882
883 // Add ourselves as an observer for navigations the first time a delegate is
884 // added. We use this notification to expire InfoBars that need to expire on
885 // page transitions.
886 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56887 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57888 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24889 }
890}
891
892void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
893 std::vector<InfoBarDelegate*>::iterator it =
894 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
895 if (it != infobar_delegates_.end()) {
896 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56897 NotificationService::current()->Notify(
898 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
899 Source<TabContents>(this),
900 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05901 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24902
[email protected]6a02963e2009-01-06 16:58:03903 // Remove ourselves as an observer if we are tracking no more InfoBars.
904 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56905 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57906 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03907 }
[email protected]616ed5a2008-11-21 22:27:24908 }
909}
[email protected]3edd9522009-03-04 22:19:41910
[email protected]f81821c2009-08-07 01:29:47911void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
912 InfoBarDelegate* new_delegate) {
913 std::vector<InfoBarDelegate*>::iterator it =
914 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
915 DCHECK(it != infobar_delegates_.end());
916
917 // Notify the container about the change of plans.
918 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
919 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
920 old_delegate, new_delegate));
921 NotificationService::current()->Notify(
922 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
923 Source<TabContents>(this),
924 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
925
926 // Remove the old one.
927 infobar_delegates_.erase(it);
928
929 // Add the new one.
930 infobar_delegates_.push_back(new_delegate);
931}
932
[email protected]96d185d2009-04-24 03:28:54933bool TabContents::IsBookmarkBarAlwaysVisible() {
934 // See GetDOMUIForCurrentState() comment for more info. This case is very
935 // similar, but for non-first loads, we want to use the committed entry. This
936 // is so the bookmarks bar disappears at the same time the page does.
937 if (controller_.GetLastCommittedEntry()) {
938 // Not the first load, always use the committed DOM UI.
939 if (render_manager_.dom_ui())
940 return render_manager_.dom_ui()->force_bookmark_bar_visible();
941 return false; // Default.
942 }
943
944 // When it's the first load, we know either the pending one or the committed
945 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
946 // of them will be valid, so we can just check both.
947 if (render_manager_.pending_dom_ui())
948 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
949 if (render_manager_.dom_ui())
950 return render_manager_.dom_ui()->force_bookmark_bar_visible();
951 return false; // Default.
952}
953
[email protected]d8f16ae2009-08-30 03:47:26954bool TabContents::IsExtensionShelfAlwaysVisible() {
955 // See GetDOMUIForCurrentState() comment for more info. This case is very
956 // similar, but for non-first loads, we want to use the committed entry. This
957 // is so the bookmarks bar disappears at the same time the page does.
958 if (controller_.GetLastCommittedEntry()) {
959 // Not the first load, always use the committed DOM UI.
960 if (render_manager_.dom_ui())
961 return render_manager_.dom_ui()->force_extension_shelf_visible();
962 return false; // Default.
963 }
964
965 // When it's the first load, we know either the pending one or the committed
966 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
967 // of them will be valid, so we can just check both.
968 if (render_manager_.pending_dom_ui())
969 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
970 if (render_manager_.dom_ui())
971 return render_manager_.dom_ui()->force_extension_shelf_visible();
972 return false; // Default.
973}
974
[email protected]3edd9522009-03-04 22:19:41975void TabContents::ToolbarSizeChanged(bool is_animating) {
976 TabContentsDelegate* d = delegate();
977 if (d)
978 d->ToolbarSizeChanged(this, is_animating);
979}
[email protected]616ed5a2008-11-21 22:27:24980
[email protected]d5f942ba2008-09-26 19:30:34981void TabContents::OnStartDownload(DownloadItem* download) {
982 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:34983
984 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:31985 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:34986
[email protected]59560e0b2009-06-04 03:30:22987 if (tab_contents && tab_contents->delegate())
988 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:41989}
[email protected]3edd9522009-03-04 22:19:41990
[email protected]d5f942ba2008-09-26 19:30:34991void TabContents::WillClose(ConstrainedWindow* window) {
992 ConstrainedWindowList::iterator it =
993 find(child_windows_.begin(), child_windows_.end(), window);
994 if (it != child_windows_.end())
995 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:13996}
[email protected]d5f942ba2008-09-26 19:30:34997
[email protected]66ba4932009-06-04 19:22:13998void TabContents::WillCloseBlockedPopupContainer(
999 BlockedPopupContainer* container) {
1000 DCHECK(blocked_popups_ == container);
1001 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341002}
1003
[email protected]d5f942ba2008-09-26 19:30:341004void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351005#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061006 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351007#endif
[email protected]d5f942ba2008-09-26 19:30:341008}
1009
[email protected]e491f1c2009-05-22 20:28:121010void TabContents::StartFinding(string16 find_text,
1011 bool forward_direction,
1012 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011013 // If find_text is empty, it means FindNext was pressed with a keyboard
1014 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121015 if (find_text.empty() && find_text_.empty()) {
1016 if (last_search_prepopulate_text_->empty())
1017 return;
1018 // Try whatever we searched for last in any tab.
1019 find_text = *last_search_prepopulate_text_;
1020 }
[email protected]6e95706d2009-04-23 22:55:011021
1022 // This is a FindNext operation if we are searching for the same text again,
1023 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1024 // exception to this is if the Find was aborted (then we don't want FindNext
1025 // because the highlighting has been cleared and we need it to reappear). We
1026 // therefore treat FindNext after an aborted Find operation as a full fledged
1027 // Find.
1028 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121029 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011030 !find_op_aborted_;
1031 if (!find_next)
1032 current_find_request_id_ = find_request_id_counter_++;
1033
1034 if (!find_text.empty())
1035 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121036 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011037
1038 find_op_aborted_ = false;
1039
1040 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121041 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011042
1043 render_view_host()->StartFinding(current_find_request_id_,
1044 find_text_,
1045 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121046 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011047 find_next);
1048}
1049
1050void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001051 // When |clear_selection| is true, it means the find string has been cleared
1052 // by the user, but the UI has not been dismissed.
1053 if (!clear_selection)
1054 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011055 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121056 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011057 render_view_host()->StopFinding(clear_selection);
1058}
1059
[email protected]5c4266922009-07-10 16:41:271060void TabContents::GetPageLanguage() {
1061 render_view_host()->GetPageLanguage();
1062}
1063
[email protected]420ae012009-04-24 05:16:321064void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1065 bool success,
1066 const std::wstring& prompt) {
1067 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1068 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1069}
1070
[email protected]571e31152009-05-15 19:34:021071void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1072 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1073}
1074
[email protected]420ae012009-04-24 05:16:321075void TabContents::OnSavePage() {
1076 // If we can not save the page, try to download it.
1077 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1078 DownloadManager* dlm = profile()->GetDownloadManager();
1079 const GURL& current_page_url = GetURL();
1080 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221081 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321082 return;
1083 }
1084
1085 Stop();
1086
1087 // Create the save package and possibly prompt the user for the name to save
1088 // the page as. The user prompt is an asynchronous operation that runs on
1089 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221090 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321091 save_package_->GetSaveInfo();
1092}
1093
1094// Used in automated testing to bypass prompting the user for file names.
1095// Instead, the names and paths are hard coded rather than running them through
1096// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591097bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321098 const std::wstring& dir_path,
1099 SavePackage::SavePackageType save_type) {
1100 // Stop the page from navigating.
1101 Stop();
1102
[email protected]d82ed61e2009-06-16 02:46:221103 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321104 FilePath::FromWStringHack(main_file),
1105 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591106 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321107}
1108
1109void TabContents::PrintPreview() {
1110 // We don't show the print preview yet, only the print dialog.
1111 PrintNow();
1112}
1113
1114bool TabContents::PrintNow() {
1115 // We can't print interstitial page for now.
1116 if (showing_interstitial_page())
1117 return false;
1118
1119 return render_view_host()->PrintPages();
1120}
1121
[email protected]82270452009-06-19 15:58:011122void TabContents::PrintingDone(int document_cookie, bool success) {
1123 render_view_host()->PrintingDone(document_cookie, success);
1124}
1125
[email protected]420ae012009-04-24 05:16:321126bool TabContents::IsActiveEntry(int32 page_id) {
1127 NavigationEntry* active_entry = controller_.GetActiveEntry();
1128 return (active_entry != NULL &&
1129 active_entry->site_instance() == GetSiteInstance() &&
1130 active_entry->page_id() == page_id);
1131}
1132
[email protected]96d185d2009-04-24 03:28:541133// Notifies the RenderWidgetHost instance about the fact that the page is
1134// loading, or done loading and calls the base implementation.
1135void TabContents::SetIsLoading(bool is_loading,
1136 LoadNotificationDetails* details) {
1137 if (is_loading == is_loading_)
1138 return;
1139
1140 if (!is_loading) {
1141 load_state_ = net::LOAD_STATE_IDLE;
1142 load_state_host_.clear();
1143 }
1144
1145 render_manager_.SetIsLoading(is_loading);
1146
1147 is_loading_ = is_loading;
1148 waiting_for_response_ = is_loading;
1149
1150 if (delegate_)
1151 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351152 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541153
1154 NotificationType type = is_loading ? NotificationType::LOAD_START :
1155 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111156 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541157 if (details)
1158 det = Details<LoadNotificationDetails>(details);
1159 NotificationService::current()->Notify(type,
1160 Source<NavigationController>(&controller_),
1161 det);
1162}
1163
[email protected]2c4410d2009-05-06 23:46:221164void TabContents::CreateBlockedPopupContainerIfNecessary() {
1165 if (blocked_popups_)
1166 return;
1167
[email protected]4d4c0b92009-06-08 23:13:011168 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221169}
1170
[email protected]b6c874582009-05-08 19:38:311171void TabContents::AddPopup(TabContents* new_contents,
1172 const gfx::Rect& initial_pos,
1173 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221174 CreateBlockedPopupContainerIfNecessary();
1175 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221176}
1177
[email protected]e69bce3dd2009-04-20 22:05:121178// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131179void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251180 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011181 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341182}
1183
[email protected]b9681312008-11-07 00:08:261184bool TabContents::ShowingBlockedPopupNotification() const {
1185 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221186 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261187}
[email protected]616ed5a2008-11-21 22:27:241188
1189namespace {
1190bool TransitionIsReload(PageTransition::Type transition) {
1191 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1192}
1193}
1194
1195void TabContents::ExpireInfoBars(
1196 const NavigationController::LoadCommittedDetails& details) {
1197 // Only hide InfoBars when the user has done something that makes the main
1198 // frame load. We don't want various automatic or subframe navigations making
1199 // it disappear.
1200 if (!details.is_user_initiated_main_frame_load())
1201 return;
1202
[email protected]f86a07022008-11-25 01:06:051203 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241204 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051205 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241206 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241207 }
1208}
[email protected]fdd61c62009-04-22 19:22:571209
1210void TabContents::OnGearsCreateShortcutDone(
1211 const GearsShortcutData2& shortcut_data, bool success) {
1212 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1213 bool same_page =
1214 current_entry && pending_install_.page_id == current_entry->page_id();
1215
1216 if (success && same_page) {
1217 // Only switch to app mode if the user chose to create a shortcut and
1218 // we're still on the same page that it corresponded to.
1219 if (delegate())
1220 delegate()->ConvertContentsToApplication(this);
1221 }
1222
1223 // Reset the page id to indicate no requests are pending.
1224 pending_install_.page_id = 0;
1225 pending_install_.callback_functor = NULL;
1226}
[email protected]96d185d2009-04-24 03:28:541227
1228DOMUI* TabContents::GetDOMUIForCurrentState() {
1229 // When there is a pending navigation entry, we want to use the pending DOMUI
1230 // that goes along with it to control the basic flags. For example, we want to
1231 // show the pending URL in the URL bar, so we want the display_url flag to
1232 // be from the pending entry.
1233 //
1234 // The confusion comes because there are multiple possibilities for the
1235 // initial load in a tab as a side effect of the way the RenderViewHostManager
1236 // works.
1237 //
1238 // - For the very first tab the load looks "normal". The new tab DOM UI is
1239 // the pending one, and we want it to apply here.
1240 //
1241 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1242 // get switched to the one previously associated with the new tab pages.
1243 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1244 // have a committed DOM UI in this case.
1245 //
1246 // This condition handles all of these cases:
1247 //
1248 // - First load in first tab: no committed nav entry + pending nav entry +
1249 // pending dom ui:
1250 // -> Use pending DOM UI if any.
1251 //
1252 // - First load in second tab: no committed nav entry + pending nav entry +
1253 // no pending DOM UI:
1254 // -> Use the committed DOM UI if any.
1255 //
1256 // - Second navigation in any tab: committed nav entry + pending nav entry:
1257 // -> Use pending DOM UI if any.
1258 //
1259 // - Normal state with no load: committed nav entry + no pending nav entry:
1260 // -> Use committed DOM UI.
1261 if (controller_.pending_entry() &&
1262 (controller_.GetLastCommittedEntry() ||
1263 render_manager_.pending_dom_ui()))
1264 return render_manager_.pending_dom_ui();
1265 return render_manager_.dom_ui();
1266}
[email protected]420ae012009-04-24 05:16:321267
1268void TabContents::DidNavigateMainFramePostCommit(
1269 const NavigationController::LoadCommittedDetails& details,
1270 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]420ae012009-04-24 05:16:321271 if (details.is_user_initiated_main_frame_load()) {
1272 // Clear the status bubble. This is a workaround for a bug where WebKit
1273 // doesn't let us know that the cursor left an element during a
1274 // transition (this is also why the mouse cursor remains as a hand after
1275 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1276 // clear the bubble when a user navigates to a named anchor in the same
1277 // page.
1278 UpdateTargetURL(details.entry->page_id(), GURL());
1279
1280 // UpdateHelpersForDidNavigate will handle the case where the password_form
1281 // origin is valid.
1282 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1283 // cleaned up and covered by tests.
1284 if (!params.password_form.origin.is_valid())
1285 GetPasswordManager()->DidNavigate();
1286 }
1287
1288 // The keyword generator uses the navigation entries, so must be called after
1289 // the commit.
1290 GenerateKeywordIfNecessary(params);
1291
1292 // Allow the new page to set the title again.
1293 received_page_title_ = false;
1294
1295 // Get the favicon, either from history or request it from the net.
1296 fav_icon_helper_.FetchFavIcon(details.entry->url());
1297
[email protected]aece2c7f2009-08-27 20:43:171298 // Disable all page actions, unless this is an in-page navigation.
1299 if (!enabled_page_actions_.empty()) {
1300 url_canon::Replacements<char> replacements;
1301 replacements.ClearRef();
1302 if (params.url.ReplaceComponents(replacements) !=
1303 params.referrer.ReplaceComponents(replacements)) {
1304 enabled_page_actions_.clear();
1305 }
1306 }
[email protected]ce5c4502009-05-06 16:46:111307
[email protected]420ae012009-04-24 05:16:321308 // Close constrained popups if necessary.
1309 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1310
1311 // Update the starred state.
1312 UpdateStarredStateForCurrentURL();
1313}
1314
1315void TabContents::DidNavigateAnyFramePostCommit(
1316 RenderViewHost* render_view_host,
1317 const NavigationController::LoadCommittedDetails& details,
1318 const ViewHostMsg_FrameNavigate_Params& params) {
1319 // If we navigate, start showing messages again. This does nothing to prevent
1320 // a malicious script from spamming messages, since the script could just
1321 // reload the page to stop blocking.
1322 suppress_javascript_messages_ = false;
1323
[email protected]420ae012009-04-24 05:16:321324 // Notify the password manager of the navigation or form submit.
1325 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1326 // cleaned up and covered by tests.
1327 if (params.password_form.origin.is_valid())
1328 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1329}
1330
1331void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1332 const GURL& current_url) {
1333 if (net::RegistryControlledDomainService::SameDomainOrHost(
1334 previous_url, current_url))
1335 return;
1336
1337 // Clear out any child windows since we are leaving this page entirely.
1338 // We use indices instead of iterators in case CloseWindow does something
1339 // that may invalidate an iterator.
1340 int size = static_cast<int>(child_windows_.size());
1341 for (int i = size - 1; i >= 0; --i) {
1342 ConstrainedWindow* window = child_windows_[i];
1343 if (window)
1344 window->CloseConstrainedWindow();
1345 }
[email protected]e29300cd2009-07-23 21:14:591346
1347 // Close the popup container.
1348 if (blocked_popups_) {
1349 blocked_popups_->Destroy();
1350 blocked_popups_ = NULL;
1351 }
[email protected]420ae012009-04-24 05:16:321352}
1353
1354void TabContents::UpdateStarredStateForCurrentURL() {
1355 BookmarkModel* model = profile()->GetBookmarkModel();
1356 const bool old_state = is_starred_;
1357 is_starred_ = (model && model->IsBookmarked(GetURL()));
1358
1359 if (is_starred_ != old_state && delegate())
1360 delegate()->URLStarredChanged(this, is_starred_);
1361}
1362
1363void TabContents::UpdateAlternateErrorPageURL() {
1364 GURL url = GetAlternateErrorPageURL();
1365 render_view_host()->SetAlternateErrorPageURL(url);
1366}
1367
1368void TabContents::UpdateWebPreferences() {
1369 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1370}
1371
1372void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1373 RenderViewHost* rvh) {
1374 // If we are creating a RVH for a restored controller, then we might
1375 // have more page IDs than the SiteInstance's current max page ID. We must
1376 // make sure that the max page ID is larger than any restored page ID.
1377 // Note that it is ok for conflicting page IDs to exist in another tab
1378 // (i.e., NavigationController), but if any page ID is larger than the max,
1379 // the back/forward list will get confused.
1380 int max_restored_page_id = controller_.max_restored_page_id();
1381 if (max_restored_page_id > 0) {
1382 int curr_max_page_id = site_instance->max_page_id();
1383 if (max_restored_page_id > curr_max_page_id) {
1384 // Need to update the site instance immediately.
1385 site_instance->UpdateMaxPageID(max_restored_page_id);
1386
1387 // Also tell the renderer to update its internal representation. We
1388 // need to reserve enough IDs to make all restored page IDs less than
1389 // the max.
1390 if (curr_max_page_id < 0)
1391 curr_max_page_id = 0;
1392 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1393 }
1394 }
1395}
1396
1397void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541398 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471399 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321400 const ViewHostMsg_FrameNavigate_Params& params) {
1401 if (profile()->IsOffTheRecord())
1402 return;
1403
1404 // Add to history service.
1405 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1406 if (hs) {
1407 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541408 virtual_url != params.url) {
1409 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321410 // types of URLs, we will display a magic URL that is different from where
1411 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541412 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1413 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321414 // to sub-frames.
1415 std::vector<GURL> redirects = params.redirects;
1416 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541417 redirects.back() = virtual_url;
1418 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471419 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321420 } else {
1421 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471422 params.transition, params.redirects,
1423 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321424 }
1425 }
1426}
1427
1428bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1429 const std::wstring& title) {
1430 // For file URLs without a title, use the pathname instead. In the case of a
1431 // synthesized title, we don't want the update to count toward the "one set
1432 // per page of the title to history."
1433 std::wstring final_title;
1434 bool explicit_set;
1435 if (entry->url().SchemeIsFile() && title.empty()) {
1436 final_title = UTF8ToWide(entry->url().ExtractFileName());
1437 explicit_set = false; // Don't count synthetic titles toward the set limit.
1438 } else {
1439 TrimWhitespace(title, TRIM_ALL, &final_title);
1440 explicit_set = true;
1441 }
1442
1443 if (final_title == UTF16ToWideHack(entry->title()))
1444 return false; // Nothing changed, don't bother.
1445
1446 entry->set_title(WideToUTF16Hack(final_title));
1447
1448 // Update the history system for this page.
1449 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1450 HistoryService* hs =
1451 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1452 if (hs)
[email protected]ebe89e062009-08-13 23:16:541453 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321454
1455 // Don't allow the title to be saved again for explicitly set ones.
1456 received_page_title_ = explicit_set;
1457 }
1458
1459 // Lastly, set the title for the view.
1460 view_->SetPageTitle(final_title);
1461
1462 return true;
1463}
1464
1465void TabContents::NotifySwapped() {
1466 // After sending out a swap notification, we need to send a disconnect
1467 // notification so that clients that pick up a pointer to |this| can NULL the
1468 // pointer. See Bug 1230284.
1469 notify_disconnection_ = true;
1470 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341471 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221472 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321473 NotificationService::NoDetails());
1474}
1475
1476void TabContents::NotifyConnected() {
1477 notify_disconnection_ = true;
1478 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341479 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221480 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321481 NotificationService::NoDetails());
1482}
1483
1484void TabContents::NotifyDisconnected() {
1485 if (!notify_disconnection_)
1486 return;
1487
1488 notify_disconnection_ = false;
1489 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341490 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221491 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321492 NotificationService::NoDetails());
1493}
1494
1495void TabContents::GenerateKeywordIfNecessary(
1496 const ViewHostMsg_FrameNavigate_Params& params) {
1497 if (!params.searchable_form_url.is_valid())
1498 return;
1499
1500 if (profile()->IsOffTheRecord())
1501 return;
1502
1503 int last_index = controller_.last_committed_entry_index();
1504 // When there was no previous page, the last index will be 0. This is
1505 // normally due to a form submit that opened in a new tab.
1506 // TODO(brettw) bug 916126: we should support keywords when form submits
1507 // happen in new tabs.
1508 if (last_index <= 0)
1509 return;
1510 const NavigationEntry* previous_entry =
1511 controller_.GetEntryAtIndex(last_index - 1);
1512 if (IsFormSubmit(previous_entry)) {
1513 // Only generate a keyword if the previous page wasn't itself a form
1514 // submit.
1515 return;
1516 }
1517
1518 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1519 previous_entry->user_typed_url() : previous_entry->url();
1520 std::wstring keyword =
1521 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1522 if (keyword.empty())
1523 return;
1524
1525 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1526 if (!url_model)
1527 return;
1528
1529 if (!url_model->loaded()) {
1530 url_model->Load();
1531 return;
1532 }
1533
1534 const TemplateURL* current_url;
1535 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1536 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1537 return;
1538
1539 if (current_url) {
1540 if (current_url->originating_url().is_valid()) {
1541 // The existing keyword was generated from an OpenSearch description
1542 // document, don't regenerate.
1543 return;
1544 }
1545 url_model->Remove(current_url);
1546 }
1547 TemplateURL* new_url = new TemplateURL();
1548 new_url->set_keyword(keyword);
1549 new_url->set_short_name(keyword);
1550 new_url->SetURL(url, 0, 0);
1551 new_url->add_input_encoding(params.searchable_form_encoding);
1552 DCHECK(controller_.GetLastCommittedEntry());
1553 const GURL& favicon_url =
1554 controller_.GetLastCommittedEntry()->favicon().url();
1555 if (favicon_url.is_valid()) {
1556 new_url->SetFavIconURL(favicon_url);
1557 } else {
1558 // The favicon url isn't valid. This means there really isn't a favicon,
1559 // or the favicon url wasn't obtained before the load started. This assumes
1560 // the later.
1561 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1562 // its url.
1563 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1564 }
1565 new_url->set_safe_for_autoreplace(true);
1566 url_model->Add(new_url);
1567}
1568
[email protected]bf5c2ff392009-07-08 16:24:331569void TabContents::OnUserGesture() {
1570 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1571 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1572 if (drm)
1573 drm->OnUserGesture(this);
1574 controller_.OnUserGesture();
1575}
1576
1577void TabContents::OnFindReply(int request_id,
1578 int number_of_matches,
1579 const gfx::Rect& selection_rect,
1580 int active_match_ordinal,
1581 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421582 // Ignore responses for requests that have been aborted.
1583 if (find_op_aborted_)
1584 return;
1585
[email protected]bf5c2ff392009-07-08 16:24:331586 // Ignore responses for requests other than the one we have most recently
1587 // issued. That way we won't act on stale results when the user has
1588 // already typed in another query.
1589 if (request_id != current_find_request_id_)
1590 return;
1591
1592 if (number_of_matches == -1)
1593 number_of_matches = last_search_result_.number_of_matches();
1594 if (active_match_ordinal == -1)
1595 active_match_ordinal = last_search_result_.active_match_ordinal();
1596
1597 gfx::Rect selection = selection_rect;
1598 if (selection.IsEmpty())
1599 selection = last_search_result_.selection_rect();
1600
1601 // Notify the UI, automation and any other observers that a find result was
1602 // found.
1603 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1604 selection, active_match_ordinal,
1605 final_update);
1606 NotificationService::current()->Notify(
1607 NotificationType::FIND_RESULT_AVAILABLE,
1608 Source<TabContents>(this),
1609 Details<FindNotificationDetails>(&last_search_result_));
1610}
1611
1612void TabContents::GoToEntryAtOffset(int offset) {
1613 controller_.GoToOffset(offset);
1614}
1615
1616void TabContents::GetHistoryListCount(int* back_list_count,
1617 int* forward_list_count) {
1618 int current_index = controller_.last_committed_entry_index();
1619 *back_list_count = current_index;
1620 *forward_list_count = controller_.entry_count() - current_index - 1;
1621}
1622
1623void TabContents::OnMissingPluginStatus(int status) {
1624#if defined(OS_WIN)
1625// TODO(PORT): pull in when plug-ins work
1626 GetPluginInstaller()->OnMissingPluginStatus(status);
1627#endif
1628}
1629
1630void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331631 DCHECK(!plugin_path.value().empty());
1632
1633 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351634#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331635 scoped_ptr<FileVersionInfo> version_info(
1636 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1637 if (version_info.get()) {
1638 const std::wstring& product_name = version_info->product_name();
1639 if (!product_name.empty())
1640 plugin_name = product_name;
1641 }
[email protected]4a560ed2009-07-13 23:35:261642#else
1643 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1644#endif
[email protected]bf5c2ff392009-07-08 16:24:331645 AddInfoBar(new SimpleAlertInfoBarDelegate(
1646 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1647 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331648}
1649
1650void TabContents::OnCrashedWorker() {
1651 AddInfoBar(new SimpleAlertInfoBarDelegate(
1652 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1653 NULL));
1654}
1655
1656void TabContents::OnDidGetApplicationInfo(
1657 int32 page_id,
1658 const webkit_glue::WebApplicationInfo& info) {
1659 if (pending_install_.page_id != page_id)
1660 return; // The user clicked create on a separate page. Ignore this.
1661
1662 pending_install_.callback_functor =
1663 new GearsCreateShortcutCallbackFunctor(this);
1664 GearsCreateShortcut(
1665 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1666 NewCallback(pending_install_.callback_functor,
1667 &GearsCreateShortcutCallbackFunctor::Run));
1668}
1669
1670void TabContents::DidStartProvisionalLoadForFrame(
1671 RenderViewHost* render_view_host,
1672 bool is_main_frame,
1673 const GURL& url) {
1674 ProvisionalLoadDetails details(is_main_frame,
1675 controller_.IsURLInPageNavigation(url),
1676 url, std::string(), false);
1677 NotificationService::current()->Notify(
1678 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1679 Source<NavigationController>(&controller_),
1680 Details<ProvisionalLoadDetails>(&details));
1681}
1682
1683void TabContents::DidStartReceivingResourceResponse(
1684 ResourceRequestDetails* details) {
1685 NotificationService::current()->Notify(
1686 NotificationType::RESOURCE_RESPONSE_STARTED,
1687 Source<NavigationController>(&controller()),
1688 Details<ResourceRequestDetails>(details));
1689}
1690
1691void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1692 NotificationService::current()->Notify(
1693 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1694 Source<NavigationController>(&controller()),
1695 Details<ResourceRequestDetails>(details));
1696}
1697
1698void TabContents::DidLoadResourceFromMemoryCache(
1699 const GURL& url,
1700 const std::string& frame_origin,
1701 const std::string& main_frame_origin,
1702 const std::string& security_info) {
1703 // Send out a notification that we loaded a resource from our memory cache.
1704 int cert_id = 0, cert_status = 0, security_bits = 0;
1705 SSLManager::DeserializeSecurityInfo(security_info,
1706 &cert_id, &cert_status,
1707 &security_bits);
1708 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]76543b92009-08-31 17:27:451709 process()->id(), cert_id, cert_status);
[email protected]bf5c2ff392009-07-08 16:24:331710
1711 NotificationService::current()->Notify(
1712 NotificationType::LOAD_FROM_MEMORY_CACHE,
1713 Source<NavigationController>(&controller_),
1714 Details<LoadFromMemoryCacheDetails>(&details));
1715}
1716
1717void TabContents::DidFailProvisionalLoadWithError(
1718 RenderViewHost* render_view_host,
1719 bool is_main_frame,
1720 int error_code,
1721 const GURL& url,
1722 bool showing_repost_interstitial) {
1723 if (net::ERR_ABORTED == error_code) {
1724 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1725 // This means that the interstitial won't be torn down properly, which is
1726 // bad. But if we have an interstitial, go back to another tab type, and
1727 // then load the same interstitial again, we could end up getting the first
1728 // interstitial's "failed" message (as a result of the cancel) when we're on
1729 // the second one.
1730 //
1731 // We can't tell this apart, so we think we're tearing down the current page
1732 // which will cause a crash later one. There is also some code in
1733 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1734 // out because of this problem.
1735 //
1736 // http://code.google.com/p/chromium/issues/detail?id=2855
1737 // Because this will not tear down the interstitial properly, if "back" is
1738 // back to another tab type, the interstitial will still be somewhat alive
1739 // in the previous tab type. If you navigate somewhere that activates the
1740 // tab with the interstitial again, you'll see a flash before the new load
1741 // commits of the interstitial page.
1742 if (showing_interstitial_page()) {
1743 LOG(WARNING) << "Discarding message during interstitial.";
1744 return;
1745 }
1746
1747 // This will discard our pending entry if we cancelled the load (e.g., if we
1748 // decided to download the file instead of load it). Only discard the
1749 // pending entry if the URLs match, otherwise the user initiated a navigate
1750 // before the page loaded so that the discard would discard the wrong entry.
1751 NavigationEntry* pending_entry = controller_.pending_entry();
1752 if (pending_entry && pending_entry->url() == url) {
1753 controller_.DiscardNonCommittedEntries();
1754 // Update the URL display.
1755 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1756 }
1757
1758 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1759 }
1760
1761 // Send out a notification that we failed a provisional load with an error.
1762 ProvisionalLoadDetails details(is_main_frame,
1763 controller_.IsURLInPageNavigation(url),
1764 url, std::string(), false);
1765 details.set_error_code(error_code);
1766
1767 NotificationService::current()->Notify(
1768 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1769 Source<NavigationController>(&controller_),
1770 Details<ProvisionalLoadDetails>(&details));
1771}
1772
1773void TabContents::DocumentLoadedInFrame() {
1774 controller_.DocumentLoadedInFrame();
1775}
1776
[email protected]8d3347f2009-07-09 22:00:211777RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321778 return view_.get();
1779}
1780
[email protected]8d3347f2009-07-09 22:00:211781RenderViewHostDelegate::RendererManagement*
1782TabContents::GetRendererManagementDelegate() {
1783 return &render_manager_;
1784}
1785
[email protected]bf5c2ff392009-07-08 16:24:331786RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211787 TabContents::GetBrowserIntegrationDelegate() {
1788 return this;
[email protected]bf5c2ff392009-07-08 16:24:331789}
1790
[email protected]8d3347f2009-07-09 22:00:211791RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1792 return this;
[email protected]bf5c2ff392009-07-08 16:24:331793}
1794
[email protected]8d3347f2009-07-09 22:00:211795RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321796 return save_package_.get(); // May be NULL, but we can return NULL.
1797}
1798
[email protected]8d3347f2009-07-09 22:00:211799RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1800 return &printing_;
1801}
1802
1803RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1804 return &fav_icon_helper_;
1805}
1806
1807RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1808 if (autofill_manager_.get() == NULL)
1809 autofill_manager_.reset(new AutofillManager(this));
1810 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331811}
1812
[email protected]80d96fa2009-06-10 22:34:511813RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461814 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511815}
1816
[email protected]57c6a652009-05-04 07:58:341817TabContents* TabContents::GetAsTabContents() {
1818 return this;
1819}
1820
[email protected]3e7cf1362009-08-21 17:47:081821void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1822 CreateBlockedPopupContainerIfNecessary();
1823 blocked_popups_->AddBlockedNotice(url, reason);
1824}
1825
[email protected]7b291f92009-08-14 05:43:531826ViewType::Type TabContents::GetRenderViewType() const {
1827 return ViewType::TAB_CONTENTS;
1828}
1829
1830int TabContents::GetBrowserWindowID() const {
1831 return controller().window_id().id();
1832}
1833
[email protected]420ae012009-04-24 05:16:321834void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061835 NotificationService::current()->Notify(
1836 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1837 Source<TabContents>(this),
1838 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321839 NavigationEntry* entry = controller_.GetActiveEntry();
1840 if (!entry)
1841 return;
1842
1843 // When we're creating views, we're still doing initial setup, so we always
1844 // use the pending DOM UI rather than any possibly existing committed one.
1845 if (render_manager_.pending_dom_ui()) {
1846 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1847 }
1848
1849 if (entry->IsViewSourceMode()) {
1850 // Put the renderer in view source mode.
1851 render_view_host->Send(
1852 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1853 }
[email protected]0666aef2009-05-13 19:48:081854
1855 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321856}
1857
1858void TabContents::RenderViewReady(RenderViewHost* rvh) {
1859 if (rvh != render_view_host()) {
1860 // Don't notify the world, since this came from a renderer in the
1861 // background.
1862 return;
1863 }
1864
1865 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301866 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321867 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301868
1869 // Restore the focus to the tab (otherwise the focus will be on the top
1870 // window).
1871 if (was_crashed && !FocusLocationBarByDefault())
1872 Focus();
[email protected]420ae012009-04-24 05:16:321873}
1874
1875void TabContents::RenderViewGone(RenderViewHost* rvh) {
1876 // Ask the print preview if this renderer was valuable.
1877 if (!printing_.OnRenderViewGone(rvh))
1878 return;
1879 if (rvh != render_view_host()) {
1880 // The pending page's RenderViewHost is gone.
1881 return;
1882 }
1883
1884 SetIsLoading(false, NULL);
1885 NotifyDisconnected();
1886 SetIsCrashed(true);
1887
[email protected]8e537302009-06-10 21:19:581888 // Tell the view that we've crashed so it can prepare the sad tab page.
1889 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321890
1891 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221892 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321893}
1894
[email protected]2e4633c2009-07-09 16:58:061895void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1896 NotificationService::current()->Notify(
1897 NotificationType::RENDER_VIEW_HOST_DELETED,
1898 Source<TabContents>(this),
1899 Details<RenderViewHost>(rvh));
1900}
1901
[email protected]420ae012009-04-24 05:16:321902void TabContents::DidNavigate(RenderViewHost* rvh,
1903 const ViewHostMsg_FrameNavigate_Params& params) {
1904 if (PageTransition::IsMainFrame(params.transition))
1905 render_manager_.DidNavigateMainFrame(rvh);
1906
1907 // Update the site of the SiteInstance if it doesn't have one yet.
1908 if (!GetSiteInstance()->has_site())
1909 GetSiteInstance()->SetSite(params.url);
1910
1911 // Need to update MIME type here because it's referred to in
1912 // UpdateNavigationCommands() called by RendererDidNavigate() to
1913 // determine whether or not to enable the encoding menu.
1914 // It's updated only for the main frame. For a subframe,
1915 // RenderView::UpdateURL does not set params.contents_mime_type.
1916 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1917 // TODO(jungshik): Add a test for the encoding menu to avoid
1918 // regressing it again.
1919 if (PageTransition::IsMainFrame(params.transition))
1920 contents_mime_type_ = params.contents_mime_type;
1921
1922 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391923 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1924
1925 // Update history. Note that this needs to happen after the entry is complete,
1926 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1927 if (params.should_update_history) {
1928 // Most of the time, the displayURL matches the loaded URL, but for about:
1929 // URLs, we use a data: URL as the real value. We actually want to save
1930 // the about: URL to the history db and keep the data: URL hidden. This is
1931 // what the TabContents' URL getter does.
1932 UpdateHistoryForNavigation(GetURL(), details, params);
1933 }
1934
[email protected]76543b92009-08-31 17:27:451935 if (!did_navigate)
1936 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321937
1938 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1939 // for the appropriate notification (best) or you can add it to
1940 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1941 // necessary, please).
1942
1943 // Run post-commit tasks.
1944 if (details.is_main_frame)
1945 DidNavigateMainFramePostCommit(details, params);
1946 DidNavigateAnyFramePostCommit(rvh, details, params);
1947}
1948
1949void TabContents::UpdateState(RenderViewHost* rvh,
1950 int32 page_id,
1951 const std::string& state) {
1952 DCHECK(rvh == render_view_host());
1953
1954 // We must be prepared to handle state updates for any page, these occur
1955 // when the user is scrolling and entering form data, as well as when we're
1956 // leaving a page, in which case our state may have already been moved to
1957 // the next page. The navigation controller will look up the appropriate
1958 // NavigationEntry and update it when it is notified via the delegate.
1959
1960 int entry_index = controller_.GetEntryIndexWithPageID(
1961 GetSiteInstance(), page_id);
1962 if (entry_index < 0)
1963 return;
1964 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1965
1966 if (state == entry->content_state())
1967 return; // Nothing to update.
1968 entry->set_content_state(state);
1969 controller_.NotifyEntryChanged(entry, entry_index);
1970}
1971
1972void TabContents::UpdateTitle(RenderViewHost* rvh,
1973 int32 page_id, const std::wstring& title) {
1974 // If we have a title, that's a pretty good indication that we've started
1975 // getting useful data.
1976 SetNotWaitingForResponse();
1977
1978 DCHECK(rvh == render_view_host());
1979 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
1980 page_id);
1981 if (!entry || !UpdateTitleForEntry(entry, title))
1982 return;
1983
1984 // Broadcast notifications when the UI should be updated.
1985 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:501986 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321987}
1988
[email protected]420ae012009-04-24 05:16:321989void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
1990 const std::wstring& encoding) {
1991 set_encoding(encoding);
1992}
1993
1994void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
1995 if (delegate())
1996 delegate()->UpdateTargetURL(this, url);
1997}
1998
1999void TabContents::UpdateThumbnail(const GURL& url,
2000 const SkBitmap& bitmap,
2001 const ThumbnailScore& score) {
2002 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282003 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492004 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192005 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2006 score, true);
[email protected]449478302009-06-09 20:04:282007 } else {
2008 HistoryService* hs;
2009 if (!profile()->IsOffTheRecord() &&
2010 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2011 hs->SetPageThumbnail(url, bitmap, score);
2012 }
[email protected]420ae012009-04-24 05:16:322013 }
2014}
2015
[email protected]0df30122009-06-03 12:13:082016void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2017 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2018 raw_settings);
2019}
2020
[email protected]420ae012009-04-24 05:16:322021void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422022 // If we close the tab while we're in the middle of a drag, we'll crash.
2023 // Instead, cancel the drag and close it as soon as the drag ends.
2024 if (view()->IsDoingDrag()) {
2025 view()->CancelDragAndCloseTab();
2026 return;
2027 }
2028
[email protected]420ae012009-04-24 05:16:322029 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2030 if (delegate() && rvh == render_view_host())
2031 delegate()->CloseContents(this);
2032}
2033
2034void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2035 if (delegate() && delegate()->IsPopup(this))
2036 delegate()->MoveContents(this, new_bounds);
2037}
2038
[email protected]329581b2009-04-28 06:52:352039void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322040 SetIsLoading(true, NULL);
2041}
2042
[email protected]329581b2009-04-28 06:52:352043void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322044 scoped_ptr<LoadNotificationDetails> details;
2045
2046 NavigationEntry* entry = controller_.GetActiveEntry();
2047 // An entry may not exist for a stop when loading an initial blank page or
2048 // if an iframe injected by script into a blank page finishes loading.
2049 if (entry) {
2050 scoped_ptr<base::ProcessMetrics> metrics(
2051 base::ProcessMetrics::CreateProcessMetrics(
2052 process()->process().handle()));
2053
2054 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2055
2056 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542057 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322058 entry->transition_type(),
2059 elapsed,
2060 &controller_,
2061 controller_.GetCurrentEntryIndex()));
2062 }
2063
2064 // Tell PasswordManager we've finished a page load, which serves as a
2065 // green light to save pending passwords and reset itself.
2066 GetPasswordManager()->DidStopLoading();
2067
2068 SetIsLoading(false, details.get());
2069}
2070
[email protected]420ae012009-04-24 05:16:322071void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2072 const GURL& source_url,
2073 const GURL& target_url) {
2074 NavigationEntry* entry;
2075 if (page_id == -1)
2076 entry = controller_.pending_entry();
2077 else
2078 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2079 if (!entry || entry->url() != source_url)
2080 return;
2081 entry->set_url(target_url);
2082}
2083
[email protected]420ae012009-04-24 05:16:322084void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2085 WindowOpenDisposition disposition) {
2086 if (render_manager_.dom_ui()) {
2087 // When we're a DOM UI, it will provide a page transition type for us (this
2088 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2089 // generated suggestions).
2090 //
2091 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162092 // want web sites to see a referrer of "chrome://blah" (and some
2093 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322094 // send to the site), so we send no referrer.
2095 OpenURL(url, GURL(), disposition,
2096 render_manager_.dom_ui()->link_transition_type());
2097 } else {
2098 OpenURL(url, referrer, disposition, PageTransition::LINK);
2099 }
2100}
2101
[email protected]1ee614862009-07-06 20:29:182102void TabContents::DomOperationResponse(const std::string& json_string,
2103 int automation_id) {
2104}
2105
[email protected]420ae012009-04-24 05:16:322106void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252107 const std::string& content,
2108 int request_id,
2109 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322110 if (!render_manager_.dom_ui()) {
[email protected]bce1e5912009-09-02 22:40:202111 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI.
2112 // Because the renderer might be owned and sending random messages, we need
2113 // to ignore these inproper ones.
2114 NOTREACHED();
[email protected]420ae012009-04-24 05:16:322115 return;
2116 }
[email protected]811bfe32009-07-01 08:46:252117 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2118 has_callback);
[email protected]420ae012009-04-24 05:16:322119}
2120
2121void TabContents::ProcessExternalHostMessage(const std::string& message,
2122 const std::string& origin,
2123 const std::string& target) {
2124 if (delegate())
2125 delegate()->ForwardMessageToExternalHost(message, origin, target);
2126}
2127
[email protected]420ae012009-04-24 05:16:322128void TabContents::RunFileChooser(bool multiple_files,
2129 const string16& title,
2130 const FilePath& default_file) {
2131 if (!select_file_dialog_.get())
2132 select_file_dialog_ = SelectFileDialog::Create(this);
2133 SelectFileDialog::Type dialog_type =
2134 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2135 SelectFileDialog::SELECT_OPEN_FILE;
2136 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2137 NULL, 0, FILE_PATH_LITERAL(""),
2138 view_->GetTopLevelNativeWindow(), NULL);
2139}
2140
2141void TabContents::RunJavaScriptMessage(
2142 const std::wstring& message,
2143 const std::wstring& default_prompt,
2144 const GURL& frame_url,
2145 const int flags,
2146 IPC::Message* reply_msg,
2147 bool* did_suppress_message) {
2148 // Suppress javascript messages when requested and when inside a constrained
2149 // popup window (because that activates them and breaks them out of the
2150 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552151 // Also suppress messages when showing an interstitial. The interstitial is
2152 // shown over the previous page, we don't want the hidden page dialogs to
2153 // interfere with the interstitial.
2154 bool suppress_this_message = suppress_javascript_messages_ ||
2155 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322156 if (delegate())
2157 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312158 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322159
2160 *did_suppress_message = suppress_this_message;
2161
2162 if (!suppress_this_message) {
2163 base::TimeDelta time_since_last_message(
2164 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2165 bool show_suppress_checkbox = false;
2166 // Show a checkbox offering to suppress further messages if this message is
2167 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2168 if (time_since_last_message <
2169 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2170 show_suppress_checkbox = true;
2171
[email protected]d82ed61e2009-06-16 02:46:222172 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322173 show_suppress_checkbox, reply_msg);
2174 } else {
2175 // If we are suppressing messages, just reply as is if the user immediately
2176 // pressed "Cancel".
2177 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2178 }
2179}
2180
2181void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2182 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222183 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322184}
2185
2186void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2187 const std::string& json_arguments,
2188 IPC::Message* reply_msg) {
2189 if (delegate()) {
2190 HtmlDialogUIDelegate* dialog_delegate =
2191 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222192 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322193 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2194 }
2195}
2196
2197void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562198 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322199 GetPasswordManager()->PasswordFormsSeen(forms);
2200}
2201
[email protected]420ae012009-04-24 05:16:322202// Checks to see if we should generate a keyword based on the OSDD, and if
2203// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2204void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2205 int32 page_id, const GURL& url,
2206 bool autodetected) {
2207 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2208 DCHECK(url.is_valid());
2209 if (!IsActiveEntry(page_id))
2210 return;
2211 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2212 if (!url_model)
2213 return;
2214 if (!url_model->loaded()) {
2215 url_model->Load();
2216 return;
2217 }
2218 if (!profile()->GetTemplateURLFetcher())
2219 return;
2220
2221 if (profile()->IsOffTheRecord())
2222 return;
2223
2224 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2225 DCHECK(entry);
2226
2227 const NavigationEntry* base_entry = entry;
2228 if (IsFormSubmit(base_entry)) {
2229 // If the current page is a form submit, find the last page that was not
2230 // a form submit and use its url to generate the keyword from.
2231 int index = controller_.last_committed_entry_index() - 1;
2232 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2233 index--;
2234 if (index >= 0)
2235 base_entry = controller_.GetEntryAtIndex(index);
2236 else
2237 base_entry = NULL;
2238 }
2239
2240 // We want to use the user typed URL if available since that represents what
2241 // the user typed to get here, and fall back on the regular URL if not.
2242 if (!base_entry)
2243 return;
2244 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2245 base_entry->user_typed_url() : base_entry->url();
2246 if (!keyword_url.is_valid())
2247 return;
2248 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2249 autodetected);
2250 if (keyword.empty())
2251 return;
2252 const TemplateURL* template_url =
2253 url_model->GetTemplateURLForKeyword(keyword);
2254 if (template_url && (!template_url->safe_for_autoreplace() ||
2255 template_url->originating_url() == url)) {
2256 // Either there is a user created TemplateURL for this keyword, or the
2257 // keyword has the same OSDD url and we've parsed it.
2258 return;
2259 }
2260
2261 // Download the OpenSearch description document. If this is successful a
2262 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322263 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2264 keyword,
2265 url,
2266 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162267 this,
[email protected]420ae012009-04-24 05:16:322268 autodetected);
2269}
2270
[email protected]420ae012009-04-24 05:16:322271GURL TabContents::GetAlternateErrorPageURL() const {
2272 GURL url;
2273 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2274 if (profile()->IsOffTheRecord())
2275 return url;
2276
2277 PrefService* prefs = profile()->GetPrefs();
2278 DCHECK(prefs);
2279 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202280 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322281 url = google_util::AppendGoogleTLDParam(url);
2282 }
2283 return url;
2284}
2285
2286WebPreferences TabContents::GetWebkitPrefs() {
2287 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552288 bool is_dom_ui = false;
2289 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322290}
2291
[email protected]420ae012009-04-24 05:16:322292void TabContents::OnJSOutOfMemory() {
2293 AddInfoBar(new SimpleAlertInfoBarDelegate(
2294 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2295}
2296
[email protected]420ae012009-04-24 05:16:322297void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2298 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342299 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322300 // delivered to a pending RenderViewHost. We must first run the onunload
2301 // handler of the old RenderViewHost before we can allow it to proceed.
2302 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2303 new_request_id);
2304}
2305
2306bool TabContents::CanBlur() const {
2307 return delegate() ? delegate()->CanBlur() : true;
2308}
2309
2310gfx::Rect TabContents::GetRootWindowResizerRect() const {
2311 if (delegate())
2312 return delegate()->GetRootWindowResizerRect();
2313 return gfx::Rect();
2314}
2315
2316void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2317 bool is_during_unload) {
2318 if (is_during_unload) {
2319 // Hang occurred while firing the beforeunload/unload handler.
2320 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112321 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322322
2323 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2324 return;
2325
2326 // If the tab hangs in the beforeunload/unload handler there's really
2327 // nothing we can do to recover. Pretend the unload listeners have
2328 // all fired and close the tab. If the hang is in the beforeunload handler
2329 // then the user will not have the option of cancelling the close.
2330 Close(rvh);
2331 return;
2332 }
2333
2334 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222335 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322336}
2337
2338void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222339 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322340}
2341
2342void TabContents::LoadStateChanged(const GURL& url,
2343 net::LoadState load_state) {
2344 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292345 std::wstring languages =
2346 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2347 load_state_host_.clear();
2348 std::string host = url.host();
2349 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322350 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2351 SetNotWaitingForResponse();
2352 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502353 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322354}
2355
[email protected]1ee614862009-07-06 20:29:182356bool TabContents::IsExternalTabContainer() const {
2357 if (!delegate())
2358 return false;
2359
2360 return delegate()->IsExternalTabContainer();
2361}
2362
[email protected]1ee614862009-07-06 20:29:182363void TabContents::DidInsertCSS() {
2364 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322365}
2366
2367void TabContents::FileSelected(const FilePath& path,
2368 int index, void* params) {
2369 render_view_host()->FileSelected(path);
2370}
2371
2372void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2373 void* params) {
2374 render_view_host()->MultiFilesSelected(files);
2375}
2376
2377void TabContents::FileSelectionCanceled(void* params) {
2378 // If the user cancels choosing a file to upload we pass back an
2379 // empty vector.
2380 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2381}
2382
2383void TabContents::BeforeUnloadFiredFromRenderManager(
2384 bool proceed,
2385 bool* proceed_to_fire_unload) {
2386 if (delegate())
2387 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2388}
2389
2390void TabContents::UpdateRenderViewSizeForRenderManager() {
2391 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2392 view_->SizeContents(view_->GetContainerSize());
2393}
2394
2395DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222396 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322397}
2398
2399NavigationEntry*
2400TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2401 return controller_.GetLastCommittedEntry();
2402}
2403
2404bool TabContents::CreateRenderViewForRenderManager(
2405 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252406 // If the pending navigation is to a DOMUI, tell the RenderView about any
2407 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322408 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252409 render_view_host->AllowBindings(
2410 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552411
[email protected]420ae012009-04-24 05:16:322412 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2413 if (!render_view_host->CreateRenderView())
2414 return false;
2415
2416 // Now that the RenderView has been created, we need to tell it its size.
2417 rwh_view->SetSize(view_->GetContainerSize());
2418
2419 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2420 render_view_host);
2421 return true;
2422}
2423
2424void TabContents::Observe(NotificationType type,
2425 const NotificationSource& source,
2426 const NotificationDetails& details) {
2427 switch (type.value) {
2428 case NotificationType::BOOKMARK_MODEL_LOADED:
2429 // BookmarkModel finished loading, fall through to update starred state.
2430 case NotificationType::URLS_STARRED: {
2431 // Somewhere, a URL has been starred.
2432 // Ignore notifications for profiles other than our current one.
2433 Profile* source_profile = Source<Profile>(source).ptr();
2434 if (!source_profile || !source_profile->IsSameProfile(profile()))
2435 return;
2436
2437 UpdateStarredStateForCurrentURL();
2438 break;
2439 }
2440 case NotificationType::PREF_CHANGED: {
2441 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2442 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2443 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2444 UpdateAlternateErrorPageURL();
2445 } else if (*pref_name_in == prefs::kDefaultCharset ||
2446 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2447 ) {
2448 UpdateWebPreferences();
2449 } else {
2450 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2451 }
2452 break;
2453 }
2454 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2455 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2456 break;
2457
2458 case NotificationType::NAV_ENTRY_COMMITTED: {
2459 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2460
2461 NavigationController::LoadCommittedDetails& committed_details =
2462 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2463 ExpireInfoBars(committed_details);
2464 break;
2465 }
2466
2467 default:
2468 NOTREACHED();
2469 }
2470}
[email protected]aacd7cc2009-09-02 14:51:102471
2472void TabContents::set_encoding(const std::wstring& encoding) {
2473 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2474}
2475