blob: 00d313aae08603ac2e5bf0b0d0253f85c1119cc6 [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"
[email protected]d3ba77272009-09-03 00:06:0975#include "chrome/browser/gtk/gtk_theme_provider.h"
[email protected]0ba5c5e2009-08-20 16:47:1376#endif // defined(OS_LINUX)
77
[email protected]420ae012009-04-24 05:16:3278// Cross-Site Navigations
79//
80// If a TabContents is told to navigate to a different web site (as determined
81// by SiteInstance), it will replace its current RenderViewHost with a new
82// RenderViewHost dedicated to the new SiteInstance. This works as follows:
83//
84// - Navigate determines whether the destination is cross-site, and if so,
85// it creates a pending_render_view_host_ and moves into the PENDING
86// RendererState.
87// - The pending RVH is "suspended," so that no navigation messages are sent to
88// its renderer until the onbeforeunload JavaScript handler has a chance to
89// run in the current RVH.
90// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
91// that it has a pending cross-site request. ResourceDispatcherHost will
92// check for this when the response arrives.
93// - The current RVH runs its onbeforeunload handler. If it returns false, we
94// cancel all the pending logic and go back to NORMAL. Otherwise we allow
95// the pending RVH to send the navigation request to its renderer.
96// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
97// checks CrossSiteRequestManager to see that the RVH responsible has a
98// pending cross-site request, and then installs a CrossSiteEventHandler.
99// - When RDH receives a response, the BufferedEventHandler determines whether
100// it is a download. If so, it sends a message to the new renderer causing
101// it to cancel the request, and the download proceeds in the download
102// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34103// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32104// doesn't affect any functionality.
105// - After RDH receives a response and determines that it is safe and not a
106// download, it pauses the response to first run the old page's onunload
107// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34108// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32109// to the current RVH.
110// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
111// the ResourceDispatcherHost, who unpauses the response. Data is then sent
112// to the pending RVH.
113// - The pending renderer sends a FrameNavigate message that invokes the
114// DidNavigate method. This replaces the current RVH with the
115// pending RVH and goes back to the NORMAL RendererState.
116
117namespace {
118
119// Amount of time we wait between when a key event is received and the renderer
120// is queried for its state and pushed to the NavigationEntry.
121const int kQueryStateDelay = 5000;
122
123const int kSyncWaitDelay = 40;
124
[email protected]304f8792009-08-19 21:28:09125#if defined(OS_CHROMEOS)
126// If a popup window is bigger than this fraction of the screen on chrome os,
127// turn it into a tab
128const float kMaxWidthFactor = 0.5;
129const float kMaxHeightFactor = 0.6;
130#endif
131
[email protected]420ae012009-04-24 05:16:32132// If another javascript message box is displayed within
133// kJavascriptMessageExpectedDelay of a previous javascript message box being
134// dismissed, display an option to suppress future message boxes from this
135// contents.
136const int kJavascriptMessageExpectedDelay = 1000;
137
[email protected]2bd6ca1c2009-08-27 16:42:20138const char kLinkDoctorBaseURL[] =
139 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
140
[email protected]420ae012009-04-24 05:16:32141// The list of prefs we want to observe.
142const wchar_t* kPrefsToObserve[] = {
143 prefs::kAlternateErrorPagesEnabled,
144 prefs::kWebKitJavaEnabled,
145 prefs::kWebKitJavascriptEnabled,
146 prefs::kWebKitLoadsImagesAutomatically,
147 prefs::kWebKitPluginsEnabled,
148 prefs::kWebKitUsesUniversalDetector,
149 prefs::kWebKitSerifFontFamily,
150 prefs::kWebKitSansSerifFontFamily,
151 prefs::kWebKitFixedFontFamily,
152 prefs::kWebKitDefaultFontSize,
153 prefs::kWebKitDefaultFixedFontSize,
154 prefs::kDefaultCharset
155 // kWebKitStandardFontIsSerif needs to be added
156 // if we let users pick which font to use, serif or sans-serif when
157 // no font is specified or a CSS generic family (serif or sans-serif)
158 // is not specified.
159};
160
161const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
162
[email protected]420ae012009-04-24 05:16:32163// Returns true if the entry's transition type is FORM_SUBMIT.
164bool IsFormSubmit(const NavigationEntry* entry) {
165 return (PageTransition::StripQualifier(entry->transition_type()) ==
166 PageTransition::FORM_SUBMIT);
167}
168
169#if defined(OS_WIN)
170
171BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
172 // Note: erase is required to properly paint some widgets borders. This can
173 // be seen with textfields.
174 InvalidateRect(hwnd, NULL, TRUE);
175 return TRUE;
176}
177#endif
178
[email protected]056de2d2009-06-26 16:41:34179void MakeNavigateParams(const NavigationEntry& entry, bool reload,
180 ViewMsg_Navigate_Params* params) {
181 params->page_id = entry.page_id();
182 params->url = entry.url();
183 params->referrer = entry.referrer();
184 params->transition = entry.transition_type();
185 params->state = entry.content_state();
186 params->reload = reload;
187 params->request_time = base::Time::Now();
188}
189
[email protected]420ae012009-04-24 05:16:32190} // namespace
191
192// -----------------------------------------------------------------------------
193
[email protected]fdd61c62009-04-22 19:22:57194// static
195int TabContents::find_request_id_counter_ = -1;
196
[email protected]420ae012009-04-24 05:16:32197class TabContents::GearsCreateShortcutCallbackFunctor {
198 public:
199 explicit GearsCreateShortcutCallbackFunctor(TabContents* contents)
200 : contents_(contents) {}
201
202 void Run(const GearsShortcutData2& shortcut_data, bool success) {
203 if (contents_)
204 contents_->OnGearsCreateShortcutDone(shortcut_data, success);
205 delete this;
206 }
207 void Cancel() {
208 contents_ = NULL;
209 }
210
211 private:
212 TabContents* contents_;
213};
214
[email protected]420ae012009-04-24 05:16:32215TabContents::TabContents(Profile* profile,
216 SiteInstance* site_instance,
217 int routing_id,
218 base::WaitableEvent* modal_dialog_event)
[email protected]b680ad22009-04-15 23:19:42219 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13220 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
221 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22222 TabContentsView::Create(this))),
223 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57224 property_bag_(),
225 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22226 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57227 save_package_(),
228 cancelable_consumer_(),
229 autofill_manager_(),
230 password_manager_(),
231 plugin_installer_(),
[email protected]d82ed61e2009-06-16 02:46:22232 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57233 select_file_dialog_(),
234 pending_install_(),
[email protected]d5f942ba2008-09-26 19:30:34235 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29236 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34237 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34238 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57239 current_load_start_(),
240 load_state_(net::LOAD_STATE_IDLE),
241 load_state_host_(),
242 received_page_title_(false),
243 is_starred_(false),
244 contents_mime_type_(),
245 encoding_(),
[email protected]332af7732009-03-11 13:21:35246 blocked_popups_(NULL),
[email protected]fdd61c62009-04-22 19:22:57247 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57248 find_ui_active_(false),
249 find_op_aborted_(false),
250 current_find_request_id_(find_request_id_counter_++),
251 find_text_(),
[email protected]e491f1c2009-05-22 20:28:12252 last_search_case_sensitive_(false),
253 last_search_prepopulate_text_(NULL),
254 last_search_result_(),
[email protected]fdd61c62009-04-22 19:22:57255 capturing_contents_(false),
256 is_being_destroyed_(false),
257 notify_disconnection_(false),
258 history_requests_(),
259#if defined(OS_WIN)
260 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
261#endif
262 last_javascript_message_dismissal_(),
[email protected]bce1e5912009-09-02 22:40:20263 suppress_javascript_messages_(false) {
[email protected]420ae012009-04-24 05:16:32264 pending_install_.page_id = 0;
265 pending_install_.callback_functor = NULL;
266
[email protected]16779842009-07-08 23:45:29267#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02268 // Make sure the thumbnailer is started before starting the render manager.
269 // The thumbnailer will want to listen for RVH creations, one of which will
270 // happen in RVHManager::Init.
271 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
272 if (generator)
273 generator->StartThumbnailing();
274#endif
275
[email protected]420ae012009-04-24 05:16:32276 render_manager_.Init(profile, site_instance, routing_id, modal_dialog_event);
277
278 view_->CreateView();
279
280 // Register for notifications about all interested prefs change.
281 PrefService* prefs = profile->GetPrefs();
282 if (prefs) {
283 for (int i = 0; i < kPrefsToObserveLength; ++i)
284 prefs->AddPrefObserver(kPrefsToObserve[i], this);
285 }
286
287 // Register for notifications about URL starredness changing on any profile.
288 registrar_.Add(this, NotificationType::URLS_STARRED,
289 NotificationService::AllSources());
290 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
291 NotificationService::AllSources());
292 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
293 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09294#if defined(OS_LINUX)
295 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
296 NotificationService::AllSources());
297#endif
[email protected]420ae012009-04-24 05:16:32298
299 // Keep a global copy of the previous search string (if any).
300 static string16 global_last_search = string16();
[email protected]e491f1c2009-05-22 20:28:12301 last_search_prepopulate_text_ = &global_last_search;
[email protected]840b1512009-07-21 16:53:46302
[email protected]c8865482009-07-23 20:40:10303 // Set-up the showing of the omnibox search infobar if applicable.
304 if (OmniboxSearchHint::IsEnabled(profile))
305 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
306
[email protected]840b1512009-07-21 16:53:46307 view_->InitRendererPrefs(&renderer_preferences_);
[email protected]332af7732009-03-11 13:21:35308}
initial.commit09911bf2008-07-26 23:55:29309
310TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32311 is_being_destroyed_ = true;
312
313 // We don't want any notifications while we're runnign our destructor.
314 registrar_.RemoveAll();
315
316 // Unregister the notifications of all observed prefs change.
317 PrefService* prefs = profile()->GetPrefs();
318 if (prefs) {
319 for (int i = 0; i < kPrefsToObserveLength; ++i)
320 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
321 }
322
323 // Clean up subwindows like plugins and the find in page bar.
324 view_->OnContentsDestroy();
325
326 NotifyDisconnected();
[email protected]d82ed61e2009-06-16 02:46:22327 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32328
329 if (pending_install_.callback_functor)
330 pending_install_.callback_functor->Cancel();
331
332 // First cleanly close all child windows.
333 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
334 // some of these to close. CloseWindows is async, so it might get called
335 // twice before it runs.
336 int size = static_cast<int>(child_windows_.size());
337 for (int i = size - 1; i >= 0; --i) {
338 ConstrainedWindow* window = child_windows_[i];
339 if (window)
340 window->CloseConstrainedWindow();
341 }
342
[email protected]66ba4932009-06-04 19:22:13343 if (blocked_popups_)
344 blocked_popups_->Destroy();
345
[email protected]420ae012009-04-24 05:16:32346 // Notify any observer that have a reference on this tab contents.
347 NotificationService::current()->Notify(
348 NotificationType::TAB_CONTENTS_DESTROYED,
349 Source<TabContents>(this),
350 NotificationService::NoDetails());
351
[email protected]1e5e74f2009-05-27 20:55:12352 // Notify any lasting InfobarDelegates that have not yet been removed that
353 // whatever infobar they were handling in this TabContents has closed,
354 // because the TabContents is going away entirely.
355 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
356 // notification may trigger infobars calls that access their delegate. (and
357 // some implementations of InfoBarDelegate do delete themselves on
358 // InfoBarClosed()).
359 for (int i = 0; i < infobar_delegate_count(); ++i) {
360 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
361 delegate->InfoBarClosed();
362 }
363 infobar_delegates_.clear();
364
[email protected]420ae012009-04-24 05:16:32365 // TODO(brettw) this should be moved to the view.
366#if defined(OS_WIN)
367 // If we still have a window handle, destroy it. GetNativeView can return
368 // NULL if this contents was part of a window that closed.
369 if (GetNativeView())
370 ::DestroyWindow(GetNativeView());
371#endif
initial.commit09911bf2008-07-26 23:55:29372}
373
[email protected]d5f942ba2008-09-26 19:30:34374// static
375void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32376 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
377
378 WebPreferences pref_defaults;
379 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
380 pref_defaults.javascript_enabled);
381 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
382 pref_defaults.web_security_enabled);
383 prefs->RegisterBooleanPref(
384 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
385 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
386 pref_defaults.loads_images_automatically);
387 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
388 pref_defaults.plugins_enabled);
389 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
390 pref_defaults.dom_paste_enabled);
391 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
392 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08393 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
394 pref_defaults.inspector_settings);
[email protected]420ae012009-04-24 05:16:32395 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
396 pref_defaults.text_areas_are_resizable);
397 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
398 pref_defaults.java_enabled);
399
400 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
401 IDS_ACCEPT_LANGUAGES);
402 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
403 IDS_DEFAULT_ENCODING);
404 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
405 IDS_STANDARD_FONT_IS_SERIF);
406 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
407 IDS_FIXED_FONT_FAMILY);
408 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
409 IDS_SERIF_FONT_FAMILY);
410 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
411 IDS_SANS_SERIF_FONT_FAMILY);
412 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
413 IDS_CURSIVE_FONT_FAMILY);
414 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
415 IDS_FANTASY_FONT_FAMILY);
416 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
417 IDS_DEFAULT_FONT_SIZE);
418 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
419 IDS_DEFAULT_FIXED_FONT_SIZE);
420 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
421 IDS_MINIMUM_FONT_SIZE);
422 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
423 IDS_MINIMUM_LOGICAL_FONT_SIZE);
424 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
425 IDS_USES_UNIVERSAL_DETECTOR);
426 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
427 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29428}
429
[email protected]13367f72009-07-08 16:39:02430// Returns true if contains content rendered by an extension.
431bool TabContents::HostsExtension() const {
432 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34433}
434
[email protected]6e95706d2009-04-23 22:55:01435PasswordManager* TabContents::GetPasswordManager() {
436 if (password_manager_.get() == NULL)
437 password_manager_.reset(new PasswordManager(this));
438 return password_manager_.get();
439}
440
441PluginInstaller* TabContents::GetPluginInstaller() {
442 if (plugin_installer_.get() == NULL)
443 plugin_installer_.reset(new PluginInstaller(this));
444 return plugin_installer_.get();
445}
446
[email protected]d5f942ba2008-09-26 19:30:34447const GURL& TabContents::GetURL() const {
448 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57449 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54450 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34451}
452
[email protected]96d185d2009-04-24 03:28:54453const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55454 // Transient entries take precedence. They are used for interstitial pages
455 // that are shown on top of existing pages.
456 NavigationEntry* entry = controller_.GetTransientEntry();
457 if (entry)
458 return entry->GetTitleForDisplay(&controller_);
459
[email protected]96d185d2009-04-24 03:28:54460 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
461 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
462 if (our_dom_ui) {
463 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55464 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54465 if (!(entry && entry->IsViewSourceMode())) {
466 // Give the DOM UI the chance to override our title.
467 const string16& title = our_dom_ui->overridden_title();
468 if (!title.empty())
469 return title;
470 }
471 }
472
473 // We use the title for the last committed entry rather than a pending
474 // navigation entry. For example, when the user types in a URL, we want to
475 // keep the old page's title until the new load has committed and we get a new
476 // title.
[email protected]96d185d2009-04-24 03:28:54477 entry = controller_.GetLastCommittedEntry();
478 if (entry)
479 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54480 return EmptyString16();
481}
482
[email protected]d5f942ba2008-09-26 19:30:34483int32 TabContents::GetMaxPageID() {
484 if (GetSiteInstance())
485 return GetSiteInstance()->max_page_id();
486 else
487 return max_page_id_;
488}
489
490void TabContents::UpdateMaxPageID(int32 page_id) {
491 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34492 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34493 // testing.
494 if (GetSiteInstance())
495 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]57c6a652009-05-04 07:58:34496 process()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34497}
498
[email protected]96d185d2009-04-24 03:28:54499SiteInstance* TabContents::GetSiteInstance() const {
500 return render_manager_.current_host()->site_instance();
501}
502
[email protected]d5f942ba2008-09-26 19:30:34503const std::wstring TabContents::GetDefaultTitle() const {
504 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
505}
506
[email protected]96d185d2009-04-24 03:28:54507bool TabContents::ShouldDisplayURL() {
508 // Don't hide the url in view source mode.
509 NavigationEntry* entry = controller_.GetActiveEntry();
510 if (entry && entry->IsViewSourceMode())
511 return true;
[email protected]83e3895b2009-06-11 00:07:16512
[email protected]96d185d2009-04-24 03:28:54513 DOMUI* dom_ui = GetDOMUIForCurrentState();
514 if (dom_ui)
515 return !dom_ui->should_hide_url();
516 return true;
517}
518
[email protected]d5f942ba2008-09-26 19:30:34519SkBitmap TabContents::GetFavIcon() const {
520 // Like GetTitle(), we also want to use the favicon for the last committed
521 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57522 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47523 if (entry)
524 return entry->favicon().bitmap();
525
[email protected]ce3fa3c2009-04-20 19:55:57526 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34527 if (entry)
528 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34529 return SkBitmap();
530}
531
[email protected]96d185d2009-04-24 03:28:54532bool TabContents::ShouldDisplayFavIcon() {
533 // Always display a throbber during pending loads.
534 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
535 return true;
536
537 DOMUI* dom_ui = GetDOMUIForCurrentState();
538 if (dom_ui)
539 return !dom_ui->hide_favicon();
540 return true;
541}
542
[email protected]96d185d2009-04-24 03:28:54543std::wstring TabContents::GetStatusText() const {
544 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
545 return std::wstring();
546
547 switch (load_state_) {
548 case net::LOAD_STATE_WAITING_FOR_CACHE:
549 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
550 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
551 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
552 case net::LOAD_STATE_RESOLVING_HOST:
553 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
554 case net::LOAD_STATE_CONNECTING:
555 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
556 case net::LOAD_STATE_SENDING_REQUEST:
557 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
558 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
559 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
560 load_state_host_);
561 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
562 case net::LOAD_STATE_IDLE:
563 case net::LOAD_STATE_READING_RESPONSE:
564 break;
565 }
566
567 return std::wstring();
568}
569
[email protected]d5f942ba2008-09-26 19:30:34570void TabContents::SetIsCrashed(bool state) {
571 if (state == is_crashed_)
572 return;
573
574 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50575 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34576}
577
[email protected]f9b1a7b2009-06-22 17:26:38578void TabContents::SetPageActionEnabled(const PageAction* page_action,
[email protected]d7eaf572009-07-01 21:57:00579 bool enable,
580 const std::string& title,
581 int icon_id) {
[email protected]ce5c4502009-05-06 16:46:11582 DCHECK(page_action);
583
[email protected]d7eaf572009-07-01 21:57:00584 if (!enable &&
585 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
586 return; // Don't need to disable twice.
587 }
[email protected]ce5c4502009-05-06 16:46:11588
[email protected]d7eaf572009-07-01 21:57:00589 if (enable) {
590 enabled_page_actions_[page_action].reset(
591 new PageActionState(title, icon_id));
592 } else {
[email protected]f9b1a7b2009-06-22 17:26:38593 enabled_page_actions_.erase(page_action);
[email protected]d7eaf572009-07-01 21:57:00594 }
[email protected]ce5c4502009-05-06 16:46:11595}
596
[email protected]d7eaf572009-07-01 21:57:00597const PageActionState* TabContents::GetPageActionState(
598 const PageAction* page_action) {
599 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
600 return NULL;
[email protected]ce5c4502009-05-06 16:46:11601
[email protected]d7eaf572009-07-01 21:57:00602 return enabled_page_actions_[page_action].get();
603}
[email protected]ce5c4502009-05-06 16:46:11604
[email protected]d5f942ba2008-09-26 19:30:34605void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
606 if (delegate_)
607 delegate_->NavigationStateChanged(this, changed_flags);
608}
609
[email protected]96d185d2009-04-24 03:28:54610void TabContents::DidBecomeSelected() {
611 controller_.SetActive(true);
[email protected]789e9152009-08-04 21:59:43612 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54613 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43614#if defined(OS_MACOSX)
615 render_widget_host_view()->SetActive(true);
616#endif
617 }
[email protected]96d185d2009-04-24 03:28:54618
[email protected]76543b92009-08-31 17:27:45619 WebCacheManager::GetInstance()->ObserveActivity(process()->id());
[email protected]96d185d2009-04-24 03:28:54620}
621
622void TabContents::WasHidden() {
623 if (!capturing_contents()) {
624 // |render_view_host()| can be NULL if the user middle clicks a link to open
625 // a tab in then background, then closes the tab before selecting it. This
626 // is because closing the tab calls TabContents::Destroy(), which removes
627 // the |render_view_host()|; then when we actually destroy the window,
628 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
629 if (render_widget_host_view())
630 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54631 }
632
633 NotificationService::current()->Notify(
634 NotificationType::TAB_CONTENTS_HIDDEN,
635 Source<TabContents>(this),
636 NotificationService::NoDetails());
637}
638
[email protected]d5f942ba2008-09-26 19:30:34639void TabContents::Activate() {
640 if (delegate_)
641 delegate_->ActivateContents(this);
642}
643
[email protected]96d185d2009-04-24 03:28:54644void TabContents::ShowContents() {
645 if (render_widget_host_view())
646 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54647}
648
649void TabContents::HideContents() {
650 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
651 // our superclass HideContents(), because some callers want to be very picky
652 // about the order in which these get called. In addition to making the code
653 // here practically impossible to understand, this also means we end up
654 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34655 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54656 WasHidden();
657}
658
[email protected]c0588052008-10-27 23:01:50659void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34660 WindowOpenDisposition disposition,
661 PageTransition::Type transition) {
662 if (delegate_)
[email protected]c0588052008-10-27 23:01:50663 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34664}
665
666bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54667 const NavigationEntry& entry = *controller_.pending_entry();
668
669 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
670 if (!dest_render_view_host)
671 return false; // Unable to create the desired render view host.
672
673 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12674 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32675 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41676 devtools_manager->OnNavigatingToPendingEntry(
677 render_view_host(),
678 dest_render_view_host,
679 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32680 }
[email protected]96d185d2009-04-24 03:28:54681
682 // Used for page load time metrics.
683 current_load_start_ = base::TimeTicks::Now();
684
685 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34686 ViewMsg_Navigate_Params navigate_params;
687 MakeNavigateParams(entry, reload, &navigate_params);
688 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54689
690 if (entry.page_id() == -1) {
691 // HACK!! This code suppresses javascript: URLs from being added to
692 // session history, which is what we want to do for javascript: URLs that
693 // do not generate content. What we really need is a message from the
694 // renderer telling us that a new page was not created. The same message
695 // could be used for mailto: URLs and the like.
696 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
697 return false;
698 }
699
700 // Clear any provisional password saves - this stops password infobars
701 // showing up on pages the user navigates to while the right page is
702 // loading.
703 GetPasswordManager()->ClearProvisionalSave();
704
705 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48706 FaviconService* favicon_service =
707 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
708 if (favicon_service)
709 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54710 }
711
[email protected]d5f942ba2008-09-26 19:30:34712 return true;
713}
714
[email protected]96d185d2009-04-24 03:28:54715void TabContents::Stop() {
716 render_manager_.Stop();
717 printing_.Stop();
718}
719
720void TabContents::Cut() {
721 render_view_host()->Cut();
722}
723
724void TabContents::Copy() {
725 render_view_host()->Copy();
726}
727
728void TabContents::Paste() {
729 render_view_host()->Paste();
730}
731
732void TabContents::DisassociateFromPopupCount() {
733 render_view_host()->DisassociateFromPopupCount();
734}
735
736TabContents* TabContents::Clone() {
737 // We create a new SiteInstance so that the new tab won't share processes
738 // with the old one. This can be changed in the future if we need it to share
739 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32740 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54741 SiteInstance::CreateSiteInstance(profile()),
742 MSG_ROUTING_NONE, NULL);
743 tc->controller().CopyStateFrom(controller_);
744 return tc;
745}
746
[email protected]420ae012009-04-24 05:16:32747void TabContents::CreateShortcut() {
748 NavigationEntry* entry = controller_.GetLastCommittedEntry();
749 if (!entry)
750 return;
751
[email protected]70b8d6b2009-08-20 16:56:24752#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13753 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
754 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49755#else
[email protected]420ae012009-04-24 05:16:32756 // We only allow one pending install request. By resetting the page id we
757 // effectively cancel the pending install request.
758 pending_install_.page_id = entry->page_id();
759 pending_install_.icon = GetFavIcon();
760 pending_install_.title = UTF16ToWideHack(GetTitle());
761 pending_install_.url = GetURL();
762 if (pending_install_.callback_functor) {
763 pending_install_.callback_functor->Cancel();
764 pending_install_.callback_functor = NULL;
765 }
766 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
767 if (pending_install_.title.empty())
768 pending_install_.title = UTF8ToWide(GetURL().spec());
769
770 // Request the application info. When done OnDidGetApplicationInfo is invoked
771 // and we'll create the shortcut.
772 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49773#endif
[email protected]420ae012009-04-24 05:16:32774}
775
[email protected]4d677202009-07-19 07:37:12776void TabContents::ShowPageInfo(const GURL& url,
777 const NavigationEntry::SSLStatus& ssl,
778 bool show_history) {
779 if (!delegate_)
780 return;
781
[email protected]bb678332009-07-21 00:15:50782 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12783}
784
initial.commit09911bf2008-07-26 23:55:29785ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28786 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29787 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28788 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29789 child_windows_.push_back(window);
790 return window;
791}
792
793void TabContents::AddNewContents(TabContents* new_contents,
794 WindowOpenDisposition disposition,
795 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22796 bool user_gesture,
797 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29798 if (!delegate_)
799 return;
800
[email protected]35f7d212009-04-29 21:19:27801 if ((disposition == NEW_POPUP) && !user_gesture &&
802 !CommandLine::ForCurrentProcess()->HasSwitch(
803 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22804 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31805 // the whitelist. The popup owner will handle checking this.
806 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
807 initial_pos,
808 creator_url.is_valid() ? creator_url.host() : std::string());
809 } else {
[email protected]304f8792009-08-19 21:28:09810#if defined(OS_CHROMEOS)
811 if (disposition == NEW_POPUP) {
812 // If the popup is bigger than a given factor of the screen, then
813 // turn it into a foreground tab (on chrome os only)
814 GdkScreen* screen = gdk_screen_get_default();
815 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
816 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
817 if (initial_pos.width() > max_width ||
818 initial_pos.height() > max_height) {
819 disposition = NEW_FOREGROUND_TAB;
820 }
821 }
822#endif
823
[email protected]0aa55312008-10-17 21:53:08824 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29825 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
826 user_gesture);
827 }
[email protected]b6c874582009-05-08 19:38:31828 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29829}
830
initial.commit09911bf2008-07-26 23:55:29831void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25832 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22833 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29834}
835
[email protected]96d185d2009-04-24 03:28:54836void TabContents::PopupNotificationVisibilityChanged(bool visible) {
837 render_view_host()->PopupNotificationVisibilityChanged(visible);
838}
839
840gfx::NativeView TabContents::GetContentNativeView() {
841 return view_->GetContentNativeView();
842}
843
844gfx::NativeView TabContents::GetNativeView() const {
845 return view_->GetNativeView();
846}
847
848void TabContents::GetContainerBounds(gfx::Rect *out) const {
849 view_->GetContainerBounds(out);
850}
851
852void TabContents::Focus() {
853 view_->Focus();
854}
855
[email protected]90daadb42009-06-08 21:27:28856void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54857 if (showing_interstitial_page()) {
858 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
859 return;
860 }
[email protected]96d185d2009-04-24 03:28:54861 render_view_host()->SetInitialFocus(reverse);
862}
863
864bool TabContents::FocusLocationBarByDefault() {
865 DOMUI* dom_ui = GetDOMUIForCurrentState();
866 if (dom_ui)
867 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43868 NavigationEntry* entry = controller_.GetActiveEntry();
869 if (entry && entry->url() == GURL("about:blank"))
870 return true;
[email protected]96d185d2009-04-24 03:28:54871 return false;
872}
873
[email protected]616ed5a2008-11-21 22:27:24874void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
875 // Look through the existing InfoBarDelegates we have for a match. If we've
876 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05877 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24878 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
879 return;
880 }
881
882 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56883 NotificationService::current()->Notify(
884 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
885 Source<TabContents>(this),
886 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24887
888 // Add ourselves as an observer for navigations the first time a delegate is
889 // added. We use this notification to expire InfoBars that need to expire on
890 // page transitions.
891 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56892 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57893 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24894 }
895}
896
897void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
898 std::vector<InfoBarDelegate*>::iterator it =
899 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
900 if (it != infobar_delegates_.end()) {
901 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56902 NotificationService::current()->Notify(
903 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
904 Source<TabContents>(this),
905 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05906 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24907
[email protected]6a02963e2009-01-06 16:58:03908 // Remove ourselves as an observer if we are tracking no more InfoBars.
909 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56910 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57911 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03912 }
[email protected]616ed5a2008-11-21 22:27:24913 }
914}
[email protected]3edd9522009-03-04 22:19:41915
[email protected]f81821c2009-08-07 01:29:47916void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
917 InfoBarDelegate* new_delegate) {
918 std::vector<InfoBarDelegate*>::iterator it =
919 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
920 DCHECK(it != infobar_delegates_.end());
921
922 // Notify the container about the change of plans.
923 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
924 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
925 old_delegate, new_delegate));
926 NotificationService::current()->Notify(
927 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
928 Source<TabContents>(this),
929 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
930
931 // Remove the old one.
932 infobar_delegates_.erase(it);
933
934 // Add the new one.
935 infobar_delegates_.push_back(new_delegate);
936}
937
[email protected]96d185d2009-04-24 03:28:54938bool TabContents::IsBookmarkBarAlwaysVisible() {
939 // See GetDOMUIForCurrentState() comment for more info. This case is very
940 // similar, but for non-first loads, we want to use the committed entry. This
941 // is so the bookmarks bar disappears at the same time the page does.
942 if (controller_.GetLastCommittedEntry()) {
943 // Not the first load, always use the committed DOM UI.
944 if (render_manager_.dom_ui())
945 return render_manager_.dom_ui()->force_bookmark_bar_visible();
946 return false; // Default.
947 }
948
949 // When it's the first load, we know either the pending one or the committed
950 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
951 // of them will be valid, so we can just check both.
952 if (render_manager_.pending_dom_ui())
953 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
954 if (render_manager_.dom_ui())
955 return render_manager_.dom_ui()->force_bookmark_bar_visible();
956 return false; // Default.
957}
958
[email protected]d8f16ae2009-08-30 03:47:26959bool TabContents::IsExtensionShelfAlwaysVisible() {
960 // See GetDOMUIForCurrentState() comment for more info. This case is very
961 // similar, but for non-first loads, we want to use the committed entry. This
962 // is so the bookmarks bar disappears at the same time the page does.
963 if (controller_.GetLastCommittedEntry()) {
964 // Not the first load, always use the committed DOM UI.
965 if (render_manager_.dom_ui())
966 return render_manager_.dom_ui()->force_extension_shelf_visible();
967 return false; // Default.
968 }
969
970 // When it's the first load, we know either the pending one or the committed
971 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
972 // of them will be valid, so we can just check both.
973 if (render_manager_.pending_dom_ui())
974 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
975 if (render_manager_.dom_ui())
976 return render_manager_.dom_ui()->force_extension_shelf_visible();
977 return false; // Default.
978}
979
[email protected]3edd9522009-03-04 22:19:41980void TabContents::ToolbarSizeChanged(bool is_animating) {
981 TabContentsDelegate* d = delegate();
982 if (d)
983 d->ToolbarSizeChanged(this, is_animating);
984}
[email protected]616ed5a2008-11-21 22:27:24985
[email protected]d5f942ba2008-09-26 19:30:34986void TabContents::OnStartDownload(DownloadItem* download) {
987 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:34988
989 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:31990 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:34991
[email protected]59560e0b2009-06-04 03:30:22992 if (tab_contents && tab_contents->delegate())
993 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:41994}
[email protected]3edd9522009-03-04 22:19:41995
[email protected]d5f942ba2008-09-26 19:30:34996void TabContents::WillClose(ConstrainedWindow* window) {
997 ConstrainedWindowList::iterator it =
998 find(child_windows_.begin(), child_windows_.end(), window);
999 if (it != child_windows_.end())
1000 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:131001}
[email protected]d5f942ba2008-09-26 19:30:341002
[email protected]66ba4932009-06-04 19:22:131003void TabContents::WillCloseBlockedPopupContainer(
1004 BlockedPopupContainer* container) {
1005 DCHECK(blocked_popups_ == container);
1006 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341007}
1008
[email protected]d5f942ba2008-09-26 19:30:341009void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351010#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061011 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351012#endif
[email protected]d5f942ba2008-09-26 19:30:341013}
1014
[email protected]e491f1c2009-05-22 20:28:121015void TabContents::StartFinding(string16 find_text,
1016 bool forward_direction,
1017 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011018 // If find_text is empty, it means FindNext was pressed with a keyboard
1019 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121020 if (find_text.empty() && find_text_.empty()) {
1021 if (last_search_prepopulate_text_->empty())
1022 return;
1023 // Try whatever we searched for last in any tab.
1024 find_text = *last_search_prepopulate_text_;
1025 }
[email protected]6e95706d2009-04-23 22:55:011026
1027 // This is a FindNext operation if we are searching for the same text again,
1028 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1029 // exception to this is if the Find was aborted (then we don't want FindNext
1030 // because the highlighting has been cleared and we need it to reappear). We
1031 // therefore treat FindNext after an aborted Find operation as a full fledged
1032 // Find.
1033 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121034 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011035 !find_op_aborted_;
1036 if (!find_next)
1037 current_find_request_id_ = find_request_id_counter_++;
1038
1039 if (!find_text.empty())
1040 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121041 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011042
1043 find_op_aborted_ = false;
1044
1045 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121046 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011047
1048 render_view_host()->StartFinding(current_find_request_id_,
1049 find_text_,
1050 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121051 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011052 find_next);
1053}
1054
1055void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001056 // When |clear_selection| is true, it means the find string has been cleared
1057 // by the user, but the UI has not been dismissed.
1058 if (!clear_selection)
1059 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011060 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121061 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011062 render_view_host()->StopFinding(clear_selection);
1063}
1064
[email protected]5c4266922009-07-10 16:41:271065void TabContents::GetPageLanguage() {
1066 render_view_host()->GetPageLanguage();
1067}
1068
[email protected]420ae012009-04-24 05:16:321069void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1070 bool success,
1071 const std::wstring& prompt) {
1072 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1073 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1074}
1075
[email protected]571e31152009-05-15 19:34:021076void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1077 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1078}
1079
[email protected]420ae012009-04-24 05:16:321080void TabContents::OnSavePage() {
1081 // If we can not save the page, try to download it.
1082 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1083 DownloadManager* dlm = profile()->GetDownloadManager();
1084 const GURL& current_page_url = GetURL();
1085 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221086 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321087 return;
1088 }
1089
1090 Stop();
1091
1092 // Create the save package and possibly prompt the user for the name to save
1093 // the page as. The user prompt is an asynchronous operation that runs on
1094 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221095 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321096 save_package_->GetSaveInfo();
1097}
1098
1099// Used in automated testing to bypass prompting the user for file names.
1100// Instead, the names and paths are hard coded rather than running them through
1101// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591102bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321103 const std::wstring& dir_path,
1104 SavePackage::SavePackageType save_type) {
1105 // Stop the page from navigating.
1106 Stop();
1107
[email protected]d82ed61e2009-06-16 02:46:221108 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321109 FilePath::FromWStringHack(main_file),
1110 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591111 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321112}
1113
1114void TabContents::PrintPreview() {
1115 // We don't show the print preview yet, only the print dialog.
1116 PrintNow();
1117}
1118
1119bool TabContents::PrintNow() {
1120 // We can't print interstitial page for now.
1121 if (showing_interstitial_page())
1122 return false;
1123
1124 return render_view_host()->PrintPages();
1125}
1126
[email protected]82270452009-06-19 15:58:011127void TabContents::PrintingDone(int document_cookie, bool success) {
1128 render_view_host()->PrintingDone(document_cookie, success);
1129}
1130
[email protected]420ae012009-04-24 05:16:321131bool TabContents::IsActiveEntry(int32 page_id) {
1132 NavigationEntry* active_entry = controller_.GetActiveEntry();
1133 return (active_entry != NULL &&
1134 active_entry->site_instance() == GetSiteInstance() &&
1135 active_entry->page_id() == page_id);
1136}
1137
[email protected]96d185d2009-04-24 03:28:541138// Notifies the RenderWidgetHost instance about the fact that the page is
1139// loading, or done loading and calls the base implementation.
1140void TabContents::SetIsLoading(bool is_loading,
1141 LoadNotificationDetails* details) {
1142 if (is_loading == is_loading_)
1143 return;
1144
1145 if (!is_loading) {
1146 load_state_ = net::LOAD_STATE_IDLE;
1147 load_state_host_.clear();
1148 }
1149
1150 render_manager_.SetIsLoading(is_loading);
1151
1152 is_loading_ = is_loading;
1153 waiting_for_response_ = is_loading;
1154
1155 if (delegate_)
1156 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351157 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541158
1159 NotificationType type = is_loading ? NotificationType::LOAD_START :
1160 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111161 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541162 if (details)
1163 det = Details<LoadNotificationDetails>(details);
1164 NotificationService::current()->Notify(type,
1165 Source<NavigationController>(&controller_),
1166 det);
1167}
1168
[email protected]2c4410d2009-05-06 23:46:221169void TabContents::CreateBlockedPopupContainerIfNecessary() {
1170 if (blocked_popups_)
1171 return;
1172
[email protected]4d4c0b92009-06-08 23:13:011173 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221174}
1175
[email protected]b6c874582009-05-08 19:38:311176void TabContents::AddPopup(TabContents* new_contents,
1177 const gfx::Rect& initial_pos,
1178 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221179 CreateBlockedPopupContainerIfNecessary();
1180 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221181}
1182
[email protected]e69bce3dd2009-04-20 22:05:121183// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131184void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251185 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011186 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341187}
1188
[email protected]b9681312008-11-07 00:08:261189bool TabContents::ShowingBlockedPopupNotification() const {
1190 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221191 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261192}
[email protected]616ed5a2008-11-21 22:27:241193
1194namespace {
1195bool TransitionIsReload(PageTransition::Type transition) {
1196 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1197}
1198}
1199
1200void TabContents::ExpireInfoBars(
1201 const NavigationController::LoadCommittedDetails& details) {
1202 // Only hide InfoBars when the user has done something that makes the main
1203 // frame load. We don't want various automatic or subframe navigations making
1204 // it disappear.
1205 if (!details.is_user_initiated_main_frame_load())
1206 return;
1207
[email protected]f86a07022008-11-25 01:06:051208 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241209 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051210 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241211 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241212 }
1213}
[email protected]fdd61c62009-04-22 19:22:571214
1215void TabContents::OnGearsCreateShortcutDone(
1216 const GearsShortcutData2& shortcut_data, bool success) {
1217 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1218 bool same_page =
1219 current_entry && pending_install_.page_id == current_entry->page_id();
1220
1221 if (success && same_page) {
1222 // Only switch to app mode if the user chose to create a shortcut and
1223 // we're still on the same page that it corresponded to.
1224 if (delegate())
1225 delegate()->ConvertContentsToApplication(this);
1226 }
1227
1228 // Reset the page id to indicate no requests are pending.
1229 pending_install_.page_id = 0;
1230 pending_install_.callback_functor = NULL;
1231}
[email protected]96d185d2009-04-24 03:28:541232
1233DOMUI* TabContents::GetDOMUIForCurrentState() {
1234 // When there is a pending navigation entry, we want to use the pending DOMUI
1235 // that goes along with it to control the basic flags. For example, we want to
1236 // show the pending URL in the URL bar, so we want the display_url flag to
1237 // be from the pending entry.
1238 //
1239 // The confusion comes because there are multiple possibilities for the
1240 // initial load in a tab as a side effect of the way the RenderViewHostManager
1241 // works.
1242 //
1243 // - For the very first tab the load looks "normal". The new tab DOM UI is
1244 // the pending one, and we want it to apply here.
1245 //
1246 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1247 // get switched to the one previously associated with the new tab pages.
1248 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1249 // have a committed DOM UI in this case.
1250 //
1251 // This condition handles all of these cases:
1252 //
1253 // - First load in first tab: no committed nav entry + pending nav entry +
1254 // pending dom ui:
1255 // -> Use pending DOM UI if any.
1256 //
1257 // - First load in second tab: no committed nav entry + pending nav entry +
1258 // no pending DOM UI:
1259 // -> Use the committed DOM UI if any.
1260 //
1261 // - Second navigation in any tab: committed nav entry + pending nav entry:
1262 // -> Use pending DOM UI if any.
1263 //
1264 // - Normal state with no load: committed nav entry + no pending nav entry:
1265 // -> Use committed DOM UI.
1266 if (controller_.pending_entry() &&
1267 (controller_.GetLastCommittedEntry() ||
1268 render_manager_.pending_dom_ui()))
1269 return render_manager_.pending_dom_ui();
1270 return render_manager_.dom_ui();
1271}
[email protected]420ae012009-04-24 05:16:321272
1273void TabContents::DidNavigateMainFramePostCommit(
1274 const NavigationController::LoadCommittedDetails& details,
1275 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]420ae012009-04-24 05:16:321276 if (details.is_user_initiated_main_frame_load()) {
1277 // Clear the status bubble. This is a workaround for a bug where WebKit
1278 // doesn't let us know that the cursor left an element during a
1279 // transition (this is also why the mouse cursor remains as a hand after
1280 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1281 // clear the bubble when a user navigates to a named anchor in the same
1282 // page.
1283 UpdateTargetURL(details.entry->page_id(), GURL());
1284
1285 // UpdateHelpersForDidNavigate will handle the case where the password_form
1286 // origin is valid.
1287 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1288 // cleaned up and covered by tests.
1289 if (!params.password_form.origin.is_valid())
1290 GetPasswordManager()->DidNavigate();
1291 }
1292
1293 // The keyword generator uses the navigation entries, so must be called after
1294 // the commit.
1295 GenerateKeywordIfNecessary(params);
1296
1297 // Allow the new page to set the title again.
1298 received_page_title_ = false;
1299
1300 // Get the favicon, either from history or request it from the net.
1301 fav_icon_helper_.FetchFavIcon(details.entry->url());
1302
[email protected]aece2c7f2009-08-27 20:43:171303 // Disable all page actions, unless this is an in-page navigation.
1304 if (!enabled_page_actions_.empty()) {
1305 url_canon::Replacements<char> replacements;
1306 replacements.ClearRef();
1307 if (params.url.ReplaceComponents(replacements) !=
1308 params.referrer.ReplaceComponents(replacements)) {
1309 enabled_page_actions_.clear();
1310 }
1311 }
[email protected]ce5c4502009-05-06 16:46:111312
[email protected]420ae012009-04-24 05:16:321313 // Close constrained popups if necessary.
1314 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1315
1316 // Update the starred state.
1317 UpdateStarredStateForCurrentURL();
1318}
1319
1320void TabContents::DidNavigateAnyFramePostCommit(
1321 RenderViewHost* render_view_host,
1322 const NavigationController::LoadCommittedDetails& details,
1323 const ViewHostMsg_FrameNavigate_Params& params) {
1324 // If we navigate, start showing messages again. This does nothing to prevent
1325 // a malicious script from spamming messages, since the script could just
1326 // reload the page to stop blocking.
1327 suppress_javascript_messages_ = false;
1328
[email protected]420ae012009-04-24 05:16:321329 // Notify the password manager of the navigation or form submit.
1330 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1331 // cleaned up and covered by tests.
1332 if (params.password_form.origin.is_valid())
1333 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1334}
1335
1336void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1337 const GURL& current_url) {
1338 if (net::RegistryControlledDomainService::SameDomainOrHost(
1339 previous_url, current_url))
1340 return;
1341
1342 // Clear out any child windows since we are leaving this page entirely.
1343 // We use indices instead of iterators in case CloseWindow does something
1344 // that may invalidate an iterator.
1345 int size = static_cast<int>(child_windows_.size());
1346 for (int i = size - 1; i >= 0; --i) {
1347 ConstrainedWindow* window = child_windows_[i];
1348 if (window)
1349 window->CloseConstrainedWindow();
1350 }
[email protected]e29300cd2009-07-23 21:14:591351
1352 // Close the popup container.
1353 if (blocked_popups_) {
1354 blocked_popups_->Destroy();
1355 blocked_popups_ = NULL;
1356 }
[email protected]420ae012009-04-24 05:16:321357}
1358
1359void TabContents::UpdateStarredStateForCurrentURL() {
1360 BookmarkModel* model = profile()->GetBookmarkModel();
1361 const bool old_state = is_starred_;
1362 is_starred_ = (model && model->IsBookmarked(GetURL()));
1363
1364 if (is_starred_ != old_state && delegate())
1365 delegate()->URLStarredChanged(this, is_starred_);
1366}
1367
1368void TabContents::UpdateAlternateErrorPageURL() {
1369 GURL url = GetAlternateErrorPageURL();
1370 render_view_host()->SetAlternateErrorPageURL(url);
1371}
1372
1373void TabContents::UpdateWebPreferences() {
1374 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1375}
1376
1377void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1378 RenderViewHost* rvh) {
1379 // If we are creating a RVH for a restored controller, then we might
1380 // have more page IDs than the SiteInstance's current max page ID. We must
1381 // make sure that the max page ID is larger than any restored page ID.
1382 // Note that it is ok for conflicting page IDs to exist in another tab
1383 // (i.e., NavigationController), but if any page ID is larger than the max,
1384 // the back/forward list will get confused.
1385 int max_restored_page_id = controller_.max_restored_page_id();
1386 if (max_restored_page_id > 0) {
1387 int curr_max_page_id = site_instance->max_page_id();
1388 if (max_restored_page_id > curr_max_page_id) {
1389 // Need to update the site instance immediately.
1390 site_instance->UpdateMaxPageID(max_restored_page_id);
1391
1392 // Also tell the renderer to update its internal representation. We
1393 // need to reserve enough IDs to make all restored page IDs less than
1394 // the max.
1395 if (curr_max_page_id < 0)
1396 curr_max_page_id = 0;
1397 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1398 }
1399 }
1400}
1401
1402void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541403 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471404 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321405 const ViewHostMsg_FrameNavigate_Params& params) {
1406 if (profile()->IsOffTheRecord())
1407 return;
1408
1409 // Add to history service.
1410 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1411 if (hs) {
1412 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541413 virtual_url != params.url) {
1414 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321415 // types of URLs, we will display a magic URL that is different from where
1416 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541417 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1418 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321419 // to sub-frames.
1420 std::vector<GURL> redirects = params.redirects;
1421 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541422 redirects.back() = virtual_url;
1423 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471424 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321425 } else {
1426 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471427 params.transition, params.redirects,
1428 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321429 }
1430 }
1431}
1432
1433bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1434 const std::wstring& title) {
1435 // For file URLs without a title, use the pathname instead. In the case of a
1436 // synthesized title, we don't want the update to count toward the "one set
1437 // per page of the title to history."
1438 std::wstring final_title;
1439 bool explicit_set;
1440 if (entry->url().SchemeIsFile() && title.empty()) {
1441 final_title = UTF8ToWide(entry->url().ExtractFileName());
1442 explicit_set = false; // Don't count synthetic titles toward the set limit.
1443 } else {
1444 TrimWhitespace(title, TRIM_ALL, &final_title);
1445 explicit_set = true;
1446 }
1447
1448 if (final_title == UTF16ToWideHack(entry->title()))
1449 return false; // Nothing changed, don't bother.
1450
1451 entry->set_title(WideToUTF16Hack(final_title));
1452
1453 // Update the history system for this page.
1454 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1455 HistoryService* hs =
1456 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1457 if (hs)
[email protected]ebe89e062009-08-13 23:16:541458 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321459
1460 // Don't allow the title to be saved again for explicitly set ones.
1461 received_page_title_ = explicit_set;
1462 }
1463
1464 // Lastly, set the title for the view.
1465 view_->SetPageTitle(final_title);
1466
1467 return true;
1468}
1469
1470void TabContents::NotifySwapped() {
1471 // After sending out a swap notification, we need to send a disconnect
1472 // notification so that clients that pick up a pointer to |this| can NULL the
1473 // pointer. See Bug 1230284.
1474 notify_disconnection_ = true;
1475 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341476 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221477 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321478 NotificationService::NoDetails());
1479}
1480
1481void TabContents::NotifyConnected() {
1482 notify_disconnection_ = true;
1483 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341484 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221485 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321486 NotificationService::NoDetails());
1487}
1488
1489void TabContents::NotifyDisconnected() {
1490 if (!notify_disconnection_)
1491 return;
1492
1493 notify_disconnection_ = false;
1494 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341495 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221496 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321497 NotificationService::NoDetails());
1498}
1499
1500void TabContents::GenerateKeywordIfNecessary(
1501 const ViewHostMsg_FrameNavigate_Params& params) {
1502 if (!params.searchable_form_url.is_valid())
1503 return;
1504
1505 if (profile()->IsOffTheRecord())
1506 return;
1507
1508 int last_index = controller_.last_committed_entry_index();
1509 // When there was no previous page, the last index will be 0. This is
1510 // normally due to a form submit that opened in a new tab.
1511 // TODO(brettw) bug 916126: we should support keywords when form submits
1512 // happen in new tabs.
1513 if (last_index <= 0)
1514 return;
1515 const NavigationEntry* previous_entry =
1516 controller_.GetEntryAtIndex(last_index - 1);
1517 if (IsFormSubmit(previous_entry)) {
1518 // Only generate a keyword if the previous page wasn't itself a form
1519 // submit.
1520 return;
1521 }
1522
1523 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1524 previous_entry->user_typed_url() : previous_entry->url();
1525 std::wstring keyword =
1526 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1527 if (keyword.empty())
1528 return;
1529
1530 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1531 if (!url_model)
1532 return;
1533
1534 if (!url_model->loaded()) {
1535 url_model->Load();
1536 return;
1537 }
1538
1539 const TemplateURL* current_url;
1540 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1541 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1542 return;
1543
1544 if (current_url) {
1545 if (current_url->originating_url().is_valid()) {
1546 // The existing keyword was generated from an OpenSearch description
1547 // document, don't regenerate.
1548 return;
1549 }
1550 url_model->Remove(current_url);
1551 }
1552 TemplateURL* new_url = new TemplateURL();
1553 new_url->set_keyword(keyword);
1554 new_url->set_short_name(keyword);
1555 new_url->SetURL(url, 0, 0);
1556 new_url->add_input_encoding(params.searchable_form_encoding);
1557 DCHECK(controller_.GetLastCommittedEntry());
1558 const GURL& favicon_url =
1559 controller_.GetLastCommittedEntry()->favicon().url();
1560 if (favicon_url.is_valid()) {
1561 new_url->SetFavIconURL(favicon_url);
1562 } else {
1563 // The favicon url isn't valid. This means there really isn't a favicon,
1564 // or the favicon url wasn't obtained before the load started. This assumes
1565 // the later.
1566 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1567 // its url.
1568 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1569 }
1570 new_url->set_safe_for_autoreplace(true);
1571 url_model->Add(new_url);
1572}
1573
[email protected]bf5c2ff392009-07-08 16:24:331574void TabContents::OnUserGesture() {
1575 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1576 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1577 if (drm)
1578 drm->OnUserGesture(this);
1579 controller_.OnUserGesture();
1580}
1581
1582void TabContents::OnFindReply(int request_id,
1583 int number_of_matches,
1584 const gfx::Rect& selection_rect,
1585 int active_match_ordinal,
1586 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421587 // Ignore responses for requests that have been aborted.
1588 if (find_op_aborted_)
1589 return;
1590
[email protected]bf5c2ff392009-07-08 16:24:331591 // Ignore responses for requests other than the one we have most recently
1592 // issued. That way we won't act on stale results when the user has
1593 // already typed in another query.
1594 if (request_id != current_find_request_id_)
1595 return;
1596
1597 if (number_of_matches == -1)
1598 number_of_matches = last_search_result_.number_of_matches();
1599 if (active_match_ordinal == -1)
1600 active_match_ordinal = last_search_result_.active_match_ordinal();
1601
1602 gfx::Rect selection = selection_rect;
1603 if (selection.IsEmpty())
1604 selection = last_search_result_.selection_rect();
1605
1606 // Notify the UI, automation and any other observers that a find result was
1607 // found.
1608 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1609 selection, active_match_ordinal,
1610 final_update);
1611 NotificationService::current()->Notify(
1612 NotificationType::FIND_RESULT_AVAILABLE,
1613 Source<TabContents>(this),
1614 Details<FindNotificationDetails>(&last_search_result_));
1615}
1616
1617void TabContents::GoToEntryAtOffset(int offset) {
1618 controller_.GoToOffset(offset);
1619}
1620
1621void TabContents::GetHistoryListCount(int* back_list_count,
1622 int* forward_list_count) {
1623 int current_index = controller_.last_committed_entry_index();
1624 *back_list_count = current_index;
1625 *forward_list_count = controller_.entry_count() - current_index - 1;
1626}
1627
1628void TabContents::OnMissingPluginStatus(int status) {
1629#if defined(OS_WIN)
1630// TODO(PORT): pull in when plug-ins work
1631 GetPluginInstaller()->OnMissingPluginStatus(status);
1632#endif
1633}
1634
1635void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331636 DCHECK(!plugin_path.value().empty());
1637
1638 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351639#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331640 scoped_ptr<FileVersionInfo> version_info(
1641 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1642 if (version_info.get()) {
1643 const std::wstring& product_name = version_info->product_name();
1644 if (!product_name.empty())
1645 plugin_name = product_name;
1646 }
[email protected]4a560ed2009-07-13 23:35:261647#else
1648 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1649#endif
[email protected]bf5c2ff392009-07-08 16:24:331650 AddInfoBar(new SimpleAlertInfoBarDelegate(
1651 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1652 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331653}
1654
1655void TabContents::OnCrashedWorker() {
1656 AddInfoBar(new SimpleAlertInfoBarDelegate(
1657 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1658 NULL));
1659}
1660
1661void TabContents::OnDidGetApplicationInfo(
1662 int32 page_id,
1663 const webkit_glue::WebApplicationInfo& info) {
1664 if (pending_install_.page_id != page_id)
1665 return; // The user clicked create on a separate page. Ignore this.
1666
1667 pending_install_.callback_functor =
1668 new GearsCreateShortcutCallbackFunctor(this);
1669 GearsCreateShortcut(
1670 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1671 NewCallback(pending_install_.callback_functor,
1672 &GearsCreateShortcutCallbackFunctor::Run));
1673}
1674
1675void TabContents::DidStartProvisionalLoadForFrame(
1676 RenderViewHost* render_view_host,
1677 bool is_main_frame,
1678 const GURL& url) {
1679 ProvisionalLoadDetails details(is_main_frame,
1680 controller_.IsURLInPageNavigation(url),
1681 url, std::string(), false);
1682 NotificationService::current()->Notify(
1683 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1684 Source<NavigationController>(&controller_),
1685 Details<ProvisionalLoadDetails>(&details));
1686}
1687
1688void TabContents::DidStartReceivingResourceResponse(
1689 ResourceRequestDetails* details) {
1690 NotificationService::current()->Notify(
1691 NotificationType::RESOURCE_RESPONSE_STARTED,
1692 Source<NavigationController>(&controller()),
1693 Details<ResourceRequestDetails>(details));
1694}
1695
1696void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1697 NotificationService::current()->Notify(
1698 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1699 Source<NavigationController>(&controller()),
1700 Details<ResourceRequestDetails>(details));
1701}
1702
1703void TabContents::DidLoadResourceFromMemoryCache(
1704 const GURL& url,
1705 const std::string& frame_origin,
1706 const std::string& main_frame_origin,
1707 const std::string& security_info) {
1708 // Send out a notification that we loaded a resource from our memory cache.
1709 int cert_id = 0, cert_status = 0, security_bits = 0;
1710 SSLManager::DeserializeSecurityInfo(security_info,
1711 &cert_id, &cert_status,
1712 &security_bits);
1713 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]76543b92009-08-31 17:27:451714 process()->id(), cert_id, cert_status);
[email protected]bf5c2ff392009-07-08 16:24:331715
1716 NotificationService::current()->Notify(
1717 NotificationType::LOAD_FROM_MEMORY_CACHE,
1718 Source<NavigationController>(&controller_),
1719 Details<LoadFromMemoryCacheDetails>(&details));
1720}
1721
1722void TabContents::DidFailProvisionalLoadWithError(
1723 RenderViewHost* render_view_host,
1724 bool is_main_frame,
1725 int error_code,
1726 const GURL& url,
1727 bool showing_repost_interstitial) {
1728 if (net::ERR_ABORTED == error_code) {
1729 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1730 // This means that the interstitial won't be torn down properly, which is
1731 // bad. But if we have an interstitial, go back to another tab type, and
1732 // then load the same interstitial again, we could end up getting the first
1733 // interstitial's "failed" message (as a result of the cancel) when we're on
1734 // the second one.
1735 //
1736 // We can't tell this apart, so we think we're tearing down the current page
1737 // which will cause a crash later one. There is also some code in
1738 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1739 // out because of this problem.
1740 //
1741 // http://code.google.com/p/chromium/issues/detail?id=2855
1742 // Because this will not tear down the interstitial properly, if "back" is
1743 // back to another tab type, the interstitial will still be somewhat alive
1744 // in the previous tab type. If you navigate somewhere that activates the
1745 // tab with the interstitial again, you'll see a flash before the new load
1746 // commits of the interstitial page.
1747 if (showing_interstitial_page()) {
1748 LOG(WARNING) << "Discarding message during interstitial.";
1749 return;
1750 }
1751
1752 // This will discard our pending entry if we cancelled the load (e.g., if we
1753 // decided to download the file instead of load it). Only discard the
1754 // pending entry if the URLs match, otherwise the user initiated a navigate
1755 // before the page loaded so that the discard would discard the wrong entry.
1756 NavigationEntry* pending_entry = controller_.pending_entry();
1757 if (pending_entry && pending_entry->url() == url) {
1758 controller_.DiscardNonCommittedEntries();
1759 // Update the URL display.
1760 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1761 }
1762
1763 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1764 }
1765
1766 // Send out a notification that we failed a provisional load with an error.
1767 ProvisionalLoadDetails details(is_main_frame,
1768 controller_.IsURLInPageNavigation(url),
1769 url, std::string(), false);
1770 details.set_error_code(error_code);
1771
1772 NotificationService::current()->Notify(
1773 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1774 Source<NavigationController>(&controller_),
1775 Details<ProvisionalLoadDetails>(&details));
1776}
1777
1778void TabContents::DocumentLoadedInFrame() {
1779 controller_.DocumentLoadedInFrame();
1780}
1781
[email protected]8d3347f2009-07-09 22:00:211782RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321783 return view_.get();
1784}
1785
[email protected]8d3347f2009-07-09 22:00:211786RenderViewHostDelegate::RendererManagement*
1787TabContents::GetRendererManagementDelegate() {
1788 return &render_manager_;
1789}
1790
[email protected]bf5c2ff392009-07-08 16:24:331791RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211792 TabContents::GetBrowserIntegrationDelegate() {
1793 return this;
[email protected]bf5c2ff392009-07-08 16:24:331794}
1795
[email protected]8d3347f2009-07-09 22:00:211796RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1797 return this;
[email protected]bf5c2ff392009-07-08 16:24:331798}
1799
[email protected]8d3347f2009-07-09 22:00:211800RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321801 return save_package_.get(); // May be NULL, but we can return NULL.
1802}
1803
[email protected]8d3347f2009-07-09 22:00:211804RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1805 return &printing_;
1806}
1807
1808RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1809 return &fav_icon_helper_;
1810}
1811
1812RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1813 if (autofill_manager_.get() == NULL)
1814 autofill_manager_.reset(new AutofillManager(this));
1815 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331816}
1817
[email protected]80d96fa2009-06-10 22:34:511818RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461819 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511820}
1821
[email protected]57c6a652009-05-04 07:58:341822TabContents* TabContents::GetAsTabContents() {
1823 return this;
1824}
1825
[email protected]3e7cf1362009-08-21 17:47:081826void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1827 CreateBlockedPopupContainerIfNecessary();
1828 blocked_popups_->AddBlockedNotice(url, reason);
1829}
1830
[email protected]7b291f92009-08-14 05:43:531831ViewType::Type TabContents::GetRenderViewType() const {
1832 return ViewType::TAB_CONTENTS;
1833}
1834
1835int TabContents::GetBrowserWindowID() const {
1836 return controller().window_id().id();
1837}
1838
[email protected]420ae012009-04-24 05:16:321839void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061840 NotificationService::current()->Notify(
1841 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1842 Source<TabContents>(this),
1843 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321844 NavigationEntry* entry = controller_.GetActiveEntry();
1845 if (!entry)
1846 return;
1847
1848 // When we're creating views, we're still doing initial setup, so we always
1849 // use the pending DOM UI rather than any possibly existing committed one.
1850 if (render_manager_.pending_dom_ui()) {
1851 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1852 }
1853
1854 if (entry->IsViewSourceMode()) {
1855 // Put the renderer in view source mode.
1856 render_view_host->Send(
1857 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1858 }
[email protected]0666aef2009-05-13 19:48:081859
1860 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321861}
1862
1863void TabContents::RenderViewReady(RenderViewHost* rvh) {
1864 if (rvh != render_view_host()) {
1865 // Don't notify the world, since this came from a renderer in the
1866 // background.
1867 return;
1868 }
1869
1870 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301871 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321872 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301873
1874 // Restore the focus to the tab (otherwise the focus will be on the top
1875 // window).
1876 if (was_crashed && !FocusLocationBarByDefault())
1877 Focus();
[email protected]420ae012009-04-24 05:16:321878}
1879
1880void TabContents::RenderViewGone(RenderViewHost* rvh) {
1881 // Ask the print preview if this renderer was valuable.
1882 if (!printing_.OnRenderViewGone(rvh))
1883 return;
1884 if (rvh != render_view_host()) {
1885 // The pending page's RenderViewHost is gone.
1886 return;
1887 }
1888
1889 SetIsLoading(false, NULL);
1890 NotifyDisconnected();
1891 SetIsCrashed(true);
1892
[email protected]8e537302009-06-10 21:19:581893 // Tell the view that we've crashed so it can prepare the sad tab page.
1894 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321895
1896 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221897 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321898}
1899
[email protected]2e4633c2009-07-09 16:58:061900void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1901 NotificationService::current()->Notify(
1902 NotificationType::RENDER_VIEW_HOST_DELETED,
1903 Source<TabContents>(this),
1904 Details<RenderViewHost>(rvh));
1905}
1906
[email protected]420ae012009-04-24 05:16:321907void TabContents::DidNavigate(RenderViewHost* rvh,
1908 const ViewHostMsg_FrameNavigate_Params& params) {
1909 if (PageTransition::IsMainFrame(params.transition))
1910 render_manager_.DidNavigateMainFrame(rvh);
1911
1912 // Update the site of the SiteInstance if it doesn't have one yet.
1913 if (!GetSiteInstance()->has_site())
1914 GetSiteInstance()->SetSite(params.url);
1915
1916 // Need to update MIME type here because it's referred to in
1917 // UpdateNavigationCommands() called by RendererDidNavigate() to
1918 // determine whether or not to enable the encoding menu.
1919 // It's updated only for the main frame. For a subframe,
1920 // RenderView::UpdateURL does not set params.contents_mime_type.
1921 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1922 // TODO(jungshik): Add a test for the encoding menu to avoid
1923 // regressing it again.
1924 if (PageTransition::IsMainFrame(params.transition))
1925 contents_mime_type_ = params.contents_mime_type;
1926
1927 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391928 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1929
1930 // Update history. Note that this needs to happen after the entry is complete,
1931 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1932 if (params.should_update_history) {
1933 // Most of the time, the displayURL matches the loaded URL, but for about:
1934 // URLs, we use a data: URL as the real value. We actually want to save
1935 // the about: URL to the history db and keep the data: URL hidden. This is
1936 // what the TabContents' URL getter does.
1937 UpdateHistoryForNavigation(GetURL(), details, params);
1938 }
1939
[email protected]76543b92009-08-31 17:27:451940 if (!did_navigate)
1941 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321942
1943 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1944 // for the appropriate notification (best) or you can add it to
1945 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1946 // necessary, please).
1947
1948 // Run post-commit tasks.
1949 if (details.is_main_frame)
1950 DidNavigateMainFramePostCommit(details, params);
1951 DidNavigateAnyFramePostCommit(rvh, details, params);
1952}
1953
1954void TabContents::UpdateState(RenderViewHost* rvh,
1955 int32 page_id,
1956 const std::string& state) {
1957 DCHECK(rvh == render_view_host());
1958
1959 // We must be prepared to handle state updates for any page, these occur
1960 // when the user is scrolling and entering form data, as well as when we're
1961 // leaving a page, in which case our state may have already been moved to
1962 // the next page. The navigation controller will look up the appropriate
1963 // NavigationEntry and update it when it is notified via the delegate.
1964
1965 int entry_index = controller_.GetEntryIndexWithPageID(
1966 GetSiteInstance(), page_id);
1967 if (entry_index < 0)
1968 return;
1969 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
1970
1971 if (state == entry->content_state())
1972 return; // Nothing to update.
1973 entry->set_content_state(state);
1974 controller_.NotifyEntryChanged(entry, entry_index);
1975}
1976
1977void TabContents::UpdateTitle(RenderViewHost* rvh,
1978 int32 page_id, const std::wstring& title) {
1979 // If we have a title, that's a pretty good indication that we've started
1980 // getting useful data.
1981 SetNotWaitingForResponse();
1982
1983 DCHECK(rvh == render_view_host());
1984 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
1985 page_id);
1986 if (!entry || !UpdateTitleForEntry(entry, title))
1987 return;
1988
1989 // Broadcast notifications when the UI should be updated.
1990 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:501991 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:321992}
1993
[email protected]420ae012009-04-24 05:16:321994void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
1995 const std::wstring& encoding) {
1996 set_encoding(encoding);
1997}
1998
1999void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2000 if (delegate())
2001 delegate()->UpdateTargetURL(this, url);
2002}
2003
2004void TabContents::UpdateThumbnail(const GURL& url,
2005 const SkBitmap& bitmap,
2006 const ThumbnailScore& score) {
2007 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282008 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492009 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192010 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2011 score, true);
[email protected]449478302009-06-09 20:04:282012 } else {
2013 HistoryService* hs;
2014 if (!profile()->IsOffTheRecord() &&
2015 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2016 hs->SetPageThumbnail(url, bitmap, score);
2017 }
[email protected]420ae012009-04-24 05:16:322018 }
2019}
2020
[email protected]0df30122009-06-03 12:13:082021void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2022 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2023 raw_settings);
2024}
2025
[email protected]420ae012009-04-24 05:16:322026void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422027 // If we close the tab while we're in the middle of a drag, we'll crash.
2028 // Instead, cancel the drag and close it as soon as the drag ends.
2029 if (view()->IsDoingDrag()) {
2030 view()->CancelDragAndCloseTab();
2031 return;
2032 }
2033
[email protected]420ae012009-04-24 05:16:322034 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2035 if (delegate() && rvh == render_view_host())
2036 delegate()->CloseContents(this);
2037}
2038
2039void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2040 if (delegate() && delegate()->IsPopup(this))
2041 delegate()->MoveContents(this, new_bounds);
2042}
2043
[email protected]329581b2009-04-28 06:52:352044void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322045 SetIsLoading(true, NULL);
2046}
2047
[email protected]329581b2009-04-28 06:52:352048void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322049 scoped_ptr<LoadNotificationDetails> details;
2050
2051 NavigationEntry* entry = controller_.GetActiveEntry();
2052 // An entry may not exist for a stop when loading an initial blank page or
2053 // if an iframe injected by script into a blank page finishes loading.
2054 if (entry) {
2055 scoped_ptr<base::ProcessMetrics> metrics(
2056 base::ProcessMetrics::CreateProcessMetrics(
2057 process()->process().handle()));
2058
2059 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2060
2061 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542062 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322063 entry->transition_type(),
2064 elapsed,
2065 &controller_,
2066 controller_.GetCurrentEntryIndex()));
2067 }
2068
2069 // Tell PasswordManager we've finished a page load, which serves as a
2070 // green light to save pending passwords and reset itself.
2071 GetPasswordManager()->DidStopLoading();
2072
2073 SetIsLoading(false, details.get());
2074}
2075
[email protected]420ae012009-04-24 05:16:322076void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2077 const GURL& source_url,
2078 const GURL& target_url) {
2079 NavigationEntry* entry;
2080 if (page_id == -1)
2081 entry = controller_.pending_entry();
2082 else
2083 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2084 if (!entry || entry->url() != source_url)
2085 return;
2086 entry->set_url(target_url);
2087}
2088
[email protected]420ae012009-04-24 05:16:322089void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2090 WindowOpenDisposition disposition) {
2091 if (render_manager_.dom_ui()) {
2092 // When we're a DOM UI, it will provide a page transition type for us (this
2093 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2094 // generated suggestions).
2095 //
2096 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162097 // want web sites to see a referrer of "chrome://blah" (and some
2098 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322099 // send to the site), so we send no referrer.
2100 OpenURL(url, GURL(), disposition,
2101 render_manager_.dom_ui()->link_transition_type());
2102 } else {
2103 OpenURL(url, referrer, disposition, PageTransition::LINK);
2104 }
2105}
2106
[email protected]1ee614862009-07-06 20:29:182107void TabContents::DomOperationResponse(const std::string& json_string,
2108 int automation_id) {
2109}
2110
[email protected]420ae012009-04-24 05:16:322111void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252112 const std::string& content,
2113 int request_id,
2114 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322115 if (!render_manager_.dom_ui()) {
[email protected]bce1e5912009-09-02 22:40:202116 // We shouldn't get a DOM UI message when we haven't enabled the DOM UI.
2117 // Because the renderer might be owned and sending random messages, we need
2118 // to ignore these inproper ones.
2119 NOTREACHED();
[email protected]420ae012009-04-24 05:16:322120 return;
2121 }
[email protected]811bfe32009-07-01 08:46:252122 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2123 has_callback);
[email protected]420ae012009-04-24 05:16:322124}
2125
2126void TabContents::ProcessExternalHostMessage(const std::string& message,
2127 const std::string& origin,
2128 const std::string& target) {
2129 if (delegate())
2130 delegate()->ForwardMessageToExternalHost(message, origin, target);
2131}
2132
[email protected]420ae012009-04-24 05:16:322133void TabContents::RunFileChooser(bool multiple_files,
2134 const string16& title,
2135 const FilePath& default_file) {
2136 if (!select_file_dialog_.get())
2137 select_file_dialog_ = SelectFileDialog::Create(this);
2138 SelectFileDialog::Type dialog_type =
2139 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2140 SelectFileDialog::SELECT_OPEN_FILE;
2141 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2142 NULL, 0, FILE_PATH_LITERAL(""),
2143 view_->GetTopLevelNativeWindow(), NULL);
2144}
2145
2146void TabContents::RunJavaScriptMessage(
2147 const std::wstring& message,
2148 const std::wstring& default_prompt,
2149 const GURL& frame_url,
2150 const int flags,
2151 IPC::Message* reply_msg,
2152 bool* did_suppress_message) {
2153 // Suppress javascript messages when requested and when inside a constrained
2154 // popup window (because that activates them and breaks them out of the
2155 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552156 // Also suppress messages when showing an interstitial. The interstitial is
2157 // shown over the previous page, we don't want the hidden page dialogs to
2158 // interfere with the interstitial.
2159 bool suppress_this_message = suppress_javascript_messages_ ||
2160 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322161 if (delegate())
2162 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312163 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322164
2165 *did_suppress_message = suppress_this_message;
2166
2167 if (!suppress_this_message) {
2168 base::TimeDelta time_since_last_message(
2169 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2170 bool show_suppress_checkbox = false;
2171 // Show a checkbox offering to suppress further messages if this message is
2172 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2173 if (time_since_last_message <
2174 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2175 show_suppress_checkbox = true;
2176
[email protected]d82ed61e2009-06-16 02:46:222177 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322178 show_suppress_checkbox, reply_msg);
2179 } else {
2180 // If we are suppressing messages, just reply as is if the user immediately
2181 // pressed "Cancel".
2182 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2183 }
2184}
2185
2186void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2187 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222188 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322189}
2190
2191void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2192 const std::string& json_arguments,
2193 IPC::Message* reply_msg) {
2194 if (delegate()) {
2195 HtmlDialogUIDelegate* dialog_delegate =
2196 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222197 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322198 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2199 }
2200}
2201
2202void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562203 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322204 GetPasswordManager()->PasswordFormsSeen(forms);
2205}
2206
[email protected]420ae012009-04-24 05:16:322207// Checks to see if we should generate a keyword based on the OSDD, and if
2208// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2209void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2210 int32 page_id, const GURL& url,
2211 bool autodetected) {
2212 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2213 DCHECK(url.is_valid());
2214 if (!IsActiveEntry(page_id))
2215 return;
2216 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2217 if (!url_model)
2218 return;
2219 if (!url_model->loaded()) {
2220 url_model->Load();
2221 return;
2222 }
2223 if (!profile()->GetTemplateURLFetcher())
2224 return;
2225
2226 if (profile()->IsOffTheRecord())
2227 return;
2228
2229 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2230 DCHECK(entry);
2231
2232 const NavigationEntry* base_entry = entry;
2233 if (IsFormSubmit(base_entry)) {
2234 // If the current page is a form submit, find the last page that was not
2235 // a form submit and use its url to generate the keyword from.
2236 int index = controller_.last_committed_entry_index() - 1;
2237 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2238 index--;
2239 if (index >= 0)
2240 base_entry = controller_.GetEntryAtIndex(index);
2241 else
2242 base_entry = NULL;
2243 }
2244
2245 // We want to use the user typed URL if available since that represents what
2246 // the user typed to get here, and fall back on the regular URL if not.
2247 if (!base_entry)
2248 return;
2249 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2250 base_entry->user_typed_url() : base_entry->url();
2251 if (!keyword_url.is_valid())
2252 return;
2253 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2254 autodetected);
2255 if (keyword.empty())
2256 return;
2257 const TemplateURL* template_url =
2258 url_model->GetTemplateURLForKeyword(keyword);
2259 if (template_url && (!template_url->safe_for_autoreplace() ||
2260 template_url->originating_url() == url)) {
2261 // Either there is a user created TemplateURL for this keyword, or the
2262 // keyword has the same OSDD url and we've parsed it.
2263 return;
2264 }
2265
2266 // Download the OpenSearch description document. If this is successful a
2267 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322268 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2269 keyword,
2270 url,
2271 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162272 this,
[email protected]420ae012009-04-24 05:16:322273 autodetected);
2274}
2275
[email protected]420ae012009-04-24 05:16:322276GURL TabContents::GetAlternateErrorPageURL() const {
2277 GURL url;
2278 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2279 if (profile()->IsOffTheRecord())
2280 return url;
2281
2282 PrefService* prefs = profile()->GetPrefs();
2283 DCHECK(prefs);
2284 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202285 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322286 url = google_util::AppendGoogleTLDParam(url);
2287 }
2288 return url;
2289}
2290
2291WebPreferences TabContents::GetWebkitPrefs() {
2292 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552293 bool is_dom_ui = false;
2294 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322295}
2296
[email protected]420ae012009-04-24 05:16:322297void TabContents::OnJSOutOfMemory() {
2298 AddInfoBar(new SimpleAlertInfoBarDelegate(
2299 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2300}
2301
[email protected]420ae012009-04-24 05:16:322302void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2303 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342304 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322305 // delivered to a pending RenderViewHost. We must first run the onunload
2306 // handler of the old RenderViewHost before we can allow it to proceed.
2307 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2308 new_request_id);
2309}
2310
2311bool TabContents::CanBlur() const {
2312 return delegate() ? delegate()->CanBlur() : true;
2313}
2314
2315gfx::Rect TabContents::GetRootWindowResizerRect() const {
2316 if (delegate())
2317 return delegate()->GetRootWindowResizerRect();
2318 return gfx::Rect();
2319}
2320
2321void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2322 bool is_during_unload) {
2323 if (is_during_unload) {
2324 // Hang occurred while firing the beforeunload/unload handler.
2325 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112326 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322327
2328 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2329 return;
2330
2331 // If the tab hangs in the beforeunload/unload handler there's really
2332 // nothing we can do to recover. Pretend the unload listeners have
2333 // all fired and close the tab. If the hang is in the beforeunload handler
2334 // then the user will not have the option of cancelling the close.
2335 Close(rvh);
2336 return;
2337 }
2338
2339 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222340 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322341}
2342
2343void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222344 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322345}
2346
2347void TabContents::LoadStateChanged(const GURL& url,
2348 net::LoadState load_state) {
2349 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292350 std::wstring languages =
2351 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2352 load_state_host_.clear();
2353 std::string host = url.host();
2354 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322355 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2356 SetNotWaitingForResponse();
2357 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502358 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]1ee614862009-07-06 20:29:182361bool TabContents::IsExternalTabContainer() const {
2362 if (!delegate())
2363 return false;
2364
2365 return delegate()->IsExternalTabContainer();
2366}
2367
[email protected]1ee614862009-07-06 20:29:182368void TabContents::DidInsertCSS() {
2369 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322370}
2371
2372void TabContents::FileSelected(const FilePath& path,
2373 int index, void* params) {
2374 render_view_host()->FileSelected(path);
2375}
2376
2377void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2378 void* params) {
2379 render_view_host()->MultiFilesSelected(files);
2380}
2381
2382void TabContents::FileSelectionCanceled(void* params) {
2383 // If the user cancels choosing a file to upload we pass back an
2384 // empty vector.
2385 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2386}
2387
2388void TabContents::BeforeUnloadFiredFromRenderManager(
2389 bool proceed,
2390 bool* proceed_to_fire_unload) {
2391 if (delegate())
2392 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2393}
2394
2395void TabContents::UpdateRenderViewSizeForRenderManager() {
2396 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2397 view_->SizeContents(view_->GetContainerSize());
2398}
2399
2400DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222401 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322402}
2403
2404NavigationEntry*
2405TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2406 return controller_.GetLastCommittedEntry();
2407}
2408
2409bool TabContents::CreateRenderViewForRenderManager(
2410 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252411 // If the pending navigation is to a DOMUI, tell the RenderView about any
2412 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322413 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252414 render_view_host->AllowBindings(
2415 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552416
[email protected]420ae012009-04-24 05:16:322417 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2418 if (!render_view_host->CreateRenderView())
2419 return false;
2420
2421 // Now that the RenderView has been created, we need to tell it its size.
2422 rwh_view->SetSize(view_->GetContainerSize());
2423
2424 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2425 render_view_host);
2426 return true;
2427}
2428
2429void TabContents::Observe(NotificationType type,
2430 const NotificationSource& source,
2431 const NotificationDetails& details) {
2432 switch (type.value) {
2433 case NotificationType::BOOKMARK_MODEL_LOADED:
2434 // BookmarkModel finished loading, fall through to update starred state.
2435 case NotificationType::URLS_STARRED: {
2436 // Somewhere, a URL has been starred.
2437 // Ignore notifications for profiles other than our current one.
2438 Profile* source_profile = Source<Profile>(source).ptr();
2439 if (!source_profile || !source_profile->IsSameProfile(profile()))
2440 return;
2441
2442 UpdateStarredStateForCurrentURL();
2443 break;
2444 }
2445 case NotificationType::PREF_CHANGED: {
2446 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2447 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2448 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2449 UpdateAlternateErrorPageURL();
2450 } else if (*pref_name_in == prefs::kDefaultCharset ||
2451 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2452 ) {
2453 UpdateWebPreferences();
2454 } else {
2455 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2456 }
2457 break;
2458 }
2459 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2460 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2461 break;
2462
2463 case NotificationType::NAV_ENTRY_COMMITTED: {
2464 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2465
2466 NavigationController::LoadCommittedDetails& committed_details =
2467 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2468 ExpireInfoBars(committed_details);
2469 break;
2470 }
2471
[email protected]d3ba77272009-09-03 00:06:092472#if defined(OS_LINUX)
2473 case NotificationType::BROWSER_THEME_CHANGED: {
2474 render_view_host()->SyncRendererPrefs();
2475 break;
2476 }
2477#endif
2478
[email protected]420ae012009-04-24 05:16:322479 default:
2480 NOTREACHED();
2481 }
2482}
[email protected]aacd7cc2009-09-02 14:51:102483
2484void TabContents::set_encoding(const std::wstring& encoding) {
2485 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2486}
2487