blob: c7c1c37bf9c092496fbdf97306c7499c9447b385 [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"
[email protected]996fd702009-09-04 19:12:3712#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5413#include "base/time.h"
[email protected]fdd61c62009-04-22 19:22:5714#include "chrome/browser/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1315#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3216#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5417#include "chrome/browser/browser_process.h"
initial.commit09911bf2008-07-26 23:55:2918#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1019#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5420#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3221#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5422#include "chrome/browser/dom_ui/dom_ui.h"
23#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0224#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3225#include "chrome/browser/download/download_manager.h"
26#include "chrome/browser/download/download_request_manager.h"
[email protected]0189bc722009-08-28 21:56:4827#include "chrome/browser/favicon_service.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/gears_integration.h"
29#include "chrome/browser/google_util.h"
[email protected]8897c382009-05-06 17:53:2630#include "chrome/browser/hung_renderer_dialog.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/jsmessage_box_handler.h"
32#include "chrome/browser/load_from_memory_cache_details.h"
33#include "chrome/browser/load_notification_details.h"
[email protected]ea0e80892009-08-22 00:36:0534#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1035#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5736#include "chrome/browser/password_manager/password_manager.h"
37#include "chrome/browser/plugin_installer.h"
[email protected]ce560f82009-06-03 09:39:4438#include "chrome/browser/profile.h"
[email protected]96d185d2009-04-24 03:28:5439#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3740#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]96d185d2009-04-24 03:28:5441#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]bd1ad682009-05-15 22:19:1742#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5443#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1644#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4345#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1646#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5747#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0248#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2849#include "chrome/browser/thumbnail_store.h"
[email protected]420ae012009-04-24 05:16:3250#include "chrome/browser/search_engines/template_url_fetcher.h"
51#include "chrome/browser/search_engines/template_url_model.h"
[email protected]35f7d212009-04-29 21:19:2752#include "chrome/common/chrome_switches.h"
[email protected]bfd04a62009-02-01 18:16:5653#include "chrome/common/notification_service.h"
[email protected]ce5c4502009-05-06 16:46:1154#include "chrome/common/page_action.h"
initial.commit09911bf2008-07-26 23:55:2955#include "chrome/common/pref_names.h"
[email protected]1eb89e82008-08-15 12:27:0356#include "chrome/common/pref_service.h"
[email protected]420ae012009-04-24 05:16:3257#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1858#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5459#include "chrome/common/url_constants.h"
[email protected]8897c382009-05-06 17:53:2660#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3261#include "grit/locale_settings.h"
62#include "net/base/mime_util.h"
63#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2964#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3265#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1866#include "webkit/glue/password_form.h"
67#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0068
[email protected]304f8792009-08-19 21:28:0969#if defined(OS_CHROMEOS)
70// For GdkScreen
71#include <gdk/gdk.h>
[email protected]0ba5c5e2009-08-20 16:47:1372#endif // defined(OS_CHROMEOS)
73
74#if defined(OS_LINUX)
75#include "chrome/browser/gtk/create_application_shortcuts_dialog_gtk.h"
[email protected]d3ba77272009-09-03 00:06:0976#include "chrome/browser/gtk/gtk_theme_provider.h"
[email protected]0ba5c5e2009-08-20 16:47:1377#endif // defined(OS_LINUX)
78
[email protected]420ae012009-04-24 05:16:3279// Cross-Site Navigations
80//
81// If a TabContents is told to navigate to a different web site (as determined
82// by SiteInstance), it will replace its current RenderViewHost with a new
83// RenderViewHost dedicated to the new SiteInstance. This works as follows:
84//
85// - Navigate determines whether the destination is cross-site, and if so,
86// it creates a pending_render_view_host_ and moves into the PENDING
87// RendererState.
88// - The pending RVH is "suspended," so that no navigation messages are sent to
89// its renderer until the onbeforeunload JavaScript handler has a chance to
90// run in the current RVH.
91// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
92// that it has a pending cross-site request. ResourceDispatcherHost will
93// check for this when the response arrives.
94// - The current RVH runs its onbeforeunload handler. If it returns false, we
95// cancel all the pending logic and go back to NORMAL. Otherwise we allow
96// the pending RVH to send the navigation request to its renderer.
97// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
98// checks CrossSiteRequestManager to see that the RVH responsible has a
99// pending cross-site request, and then installs a CrossSiteEventHandler.
100// - When RDH receives a response, the BufferedEventHandler determines whether
101// it is a download. If so, it sends a message to the new renderer causing
102// it to cancel the request, and the download proceeds in the download
103// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34104// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32105// doesn't affect any functionality.
106// - After RDH receives a response and determines that it is safe and not a
107// download, it pauses the response to first run the old page's onunload
108// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34109// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32110// to the current RVH.
111// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
112// the ResourceDispatcherHost, who unpauses the response. Data is then sent
113// to the pending RVH.
114// - The pending renderer sends a FrameNavigate message that invokes the
115// DidNavigate method. This replaces the current RVH with the
116// pending RVH and goes back to the NORMAL RendererState.
117
118namespace {
119
120// Amount of time we wait between when a key event is received and the renderer
121// is queried for its state and pushed to the NavigationEntry.
122const int kQueryStateDelay = 5000;
123
124const int kSyncWaitDelay = 40;
125
[email protected]304f8792009-08-19 21:28:09126#if defined(OS_CHROMEOS)
127// If a popup window is bigger than this fraction of the screen on chrome os,
128// turn it into a tab
129const float kMaxWidthFactor = 0.5;
130const float kMaxHeightFactor = 0.6;
131#endif
132
[email protected]420ae012009-04-24 05:16:32133// If another javascript message box is displayed within
134// kJavascriptMessageExpectedDelay of a previous javascript message box being
135// dismissed, display an option to suppress future message boxes from this
136// contents.
137const int kJavascriptMessageExpectedDelay = 1000;
138
[email protected]2bd6ca1c2009-08-27 16:42:20139const char kLinkDoctorBaseURL[] =
140 "http://linkhelp.clients.google.com/tbproxy/lh/fixurl";
141
[email protected]420ae012009-04-24 05:16:32142// The list of prefs we want to observe.
143const wchar_t* kPrefsToObserve[] = {
144 prefs::kAlternateErrorPagesEnabled,
145 prefs::kWebKitJavaEnabled,
146 prefs::kWebKitJavascriptEnabled,
147 prefs::kWebKitLoadsImagesAutomatically,
148 prefs::kWebKitPluginsEnabled,
149 prefs::kWebKitUsesUniversalDetector,
150 prefs::kWebKitSerifFontFamily,
151 prefs::kWebKitSansSerifFontFamily,
152 prefs::kWebKitFixedFontFamily,
153 prefs::kWebKitDefaultFontSize,
154 prefs::kWebKitDefaultFixedFontSize,
155 prefs::kDefaultCharset
156 // kWebKitStandardFontIsSerif needs to be added
157 // if we let users pick which font to use, serif or sans-serif when
158 // no font is specified or a CSS generic family (serif or sans-serif)
159 // is not specified.
160};
161
162const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
163
[email protected]420ae012009-04-24 05:16:32164// Returns true if the entry's transition type is FORM_SUBMIT.
165bool IsFormSubmit(const NavigationEntry* entry) {
166 return (PageTransition::StripQualifier(entry->transition_type()) ==
167 PageTransition::FORM_SUBMIT);
168}
169
170#if defined(OS_WIN)
171
172BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
173 // Note: erase is required to properly paint some widgets borders. This can
174 // be seen with textfields.
175 InvalidateRect(hwnd, NULL, TRUE);
176 return TRUE;
177}
178#endif
179
[email protected]056de2d2009-06-26 16:41:34180void MakeNavigateParams(const NavigationEntry& entry, bool reload,
181 ViewMsg_Navigate_Params* params) {
182 params->page_id = entry.page_id();
183 params->url = entry.url();
184 params->referrer = entry.referrer();
185 params->transition = entry.transition_type();
186 params->state = entry.content_state();
187 params->reload = reload;
188 params->request_time = base::Time::Now();
189}
190
[email protected]420ae012009-04-24 05:16:32191} // namespace
192
193// -----------------------------------------------------------------------------
194
[email protected]fdd61c62009-04-22 19:22:57195// static
196int TabContents::find_request_id_counter_ = -1;
197
[email protected]420ae012009-04-24 05:16:32198class TabContents::GearsCreateShortcutCallbackFunctor {
199 public:
200 explicit GearsCreateShortcutCallbackFunctor(TabContents* contents)
201 : contents_(contents) {}
202
203 void Run(const GearsShortcutData2& shortcut_data, bool success) {
204 if (contents_)
205 contents_->OnGearsCreateShortcutDone(shortcut_data, success);
206 delete this;
207 }
208 void Cancel() {
209 contents_ = NULL;
210 }
211
212 private:
213 TabContents* contents_;
214};
215
[email protected]420ae012009-04-24 05:16:32216TabContents::TabContents(Profile* profile,
217 SiteInstance* site_instance,
218 int routing_id,
219 base::WaitableEvent* modal_dialog_event)
[email protected]b680ad22009-04-15 23:19:42220 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13221 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
222 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22223 TabContentsView::Create(this))),
224 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57225 property_bag_(),
226 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22227 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57228 save_package_(),
229 cancelable_consumer_(),
230 autofill_manager_(),
231 password_manager_(),
232 plugin_installer_(),
[email protected]d82ed61e2009-06-16 02:46:22233 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57234 select_file_dialog_(),
235 pending_install_(),
[email protected]d5f942ba2008-09-26 19:30:34236 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29237 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34238 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34239 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57240 current_load_start_(),
241 load_state_(net::LOAD_STATE_IDLE),
242 load_state_host_(),
243 received_page_title_(false),
244 is_starred_(false),
245 contents_mime_type_(),
246 encoding_(),
[email protected]332af7732009-03-11 13:21:35247 blocked_popups_(NULL),
[email protected]fdd61c62009-04-22 19:22:57248 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57249 find_ui_active_(false),
250 find_op_aborted_(false),
251 current_find_request_id_(find_request_id_counter_++),
252 find_text_(),
[email protected]e491f1c2009-05-22 20:28:12253 last_search_case_sensitive_(false),
254 last_search_prepopulate_text_(NULL),
255 last_search_result_(),
[email protected]fdd61c62009-04-22 19:22:57256 capturing_contents_(false),
257 is_being_destroyed_(false),
258 notify_disconnection_(false),
259 history_requests_(),
260#if defined(OS_WIN)
261 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
262#endif
263 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44264 suppress_javascript_messages_(false),
265 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI) {
[email protected]420ae012009-04-24 05:16:32266 pending_install_.page_id = 0;
267 pending_install_.callback_functor = NULL;
268
[email protected]16779842009-07-08 23:45:29269#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02270 // Make sure the thumbnailer is started before starting the render manager.
271 // The thumbnailer will want to listen for RVH creations, one of which will
272 // happen in RVHManager::Init.
273 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
274 if (generator)
275 generator->StartThumbnailing();
276#endif
277
[email protected]420ae012009-04-24 05:16:32278 render_manager_.Init(profile, site_instance, routing_id, modal_dialog_event);
279
280 view_->CreateView();
281
282 // Register for notifications about all interested prefs change.
283 PrefService* prefs = profile->GetPrefs();
284 if (prefs) {
285 for (int i = 0; i < kPrefsToObserveLength; ++i)
286 prefs->AddPrefObserver(kPrefsToObserve[i], this);
287 }
288
289 // Register for notifications about URL starredness changing on any profile.
290 registrar_.Add(this, NotificationType::URLS_STARRED,
291 NotificationService::AllSources());
292 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
293 NotificationService::AllSources());
294 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
295 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09296#if defined(OS_LINUX)
297 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
298 NotificationService::AllSources());
299#endif
[email protected]420ae012009-04-24 05:16:32300
301 // Keep a global copy of the previous search string (if any).
302 static string16 global_last_search = string16();
[email protected]e491f1c2009-05-22 20:28:12303 last_search_prepopulate_text_ = &global_last_search;
[email protected]840b1512009-07-21 16:53:46304
[email protected]c8865482009-07-23 20:40:10305 // Set-up the showing of the omnibox search infobar if applicable.
306 if (OmniboxSearchHint::IsEnabled(profile))
307 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
308
[email protected]840b1512009-07-21 16:53:46309 view_->InitRendererPrefs(&renderer_preferences_);
[email protected]332af7732009-03-11 13:21:35310}
initial.commit09911bf2008-07-26 23:55:29311
312TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32313 is_being_destroyed_ = true;
314
315 // We don't want any notifications while we're runnign our destructor.
316 registrar_.RemoveAll();
317
318 // Unregister the notifications of all observed prefs change.
319 PrefService* prefs = profile()->GetPrefs();
320 if (prefs) {
321 for (int i = 0; i < kPrefsToObserveLength; ++i)
322 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
323 }
324
325 // Clean up subwindows like plugins and the find in page bar.
326 view_->OnContentsDestroy();
327
328 NotifyDisconnected();
[email protected]d82ed61e2009-06-16 02:46:22329 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32330
331 if (pending_install_.callback_functor)
332 pending_install_.callback_functor->Cancel();
333
334 // First cleanly close all child windows.
335 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
336 // some of these to close. CloseWindows is async, so it might get called
337 // twice before it runs.
338 int size = static_cast<int>(child_windows_.size());
339 for (int i = size - 1; i >= 0; --i) {
340 ConstrainedWindow* window = child_windows_[i];
341 if (window)
342 window->CloseConstrainedWindow();
343 }
344
[email protected]66ba4932009-06-04 19:22:13345 if (blocked_popups_)
346 blocked_popups_->Destroy();
347
[email protected]420ae012009-04-24 05:16:32348 // Notify any observer that have a reference on this tab contents.
349 NotificationService::current()->Notify(
350 NotificationType::TAB_CONTENTS_DESTROYED,
351 Source<TabContents>(this),
352 NotificationService::NoDetails());
353
[email protected]1e5e74f2009-05-27 20:55:12354 // Notify any lasting InfobarDelegates that have not yet been removed that
355 // whatever infobar they were handling in this TabContents has closed,
356 // because the TabContents is going away entirely.
357 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
358 // notification may trigger infobars calls that access their delegate. (and
359 // some implementations of InfoBarDelegate do delete themselves on
360 // InfoBarClosed()).
361 for (int i = 0; i < infobar_delegate_count(); ++i) {
362 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
363 delegate->InfoBarClosed();
364 }
365 infobar_delegates_.clear();
366
[email protected]420ae012009-04-24 05:16:32367 // TODO(brettw) this should be moved to the view.
368#if defined(OS_WIN)
369 // If we still have a window handle, destroy it. GetNativeView can return
370 // NULL if this contents was part of a window that closed.
371 if (GetNativeView())
372 ::DestroyWindow(GetNativeView());
373#endif
initial.commit09911bf2008-07-26 23:55:29374}
375
[email protected]d5f942ba2008-09-26 19:30:34376// static
377void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32378 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
379
380 WebPreferences pref_defaults;
381 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
382 pref_defaults.javascript_enabled);
383 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
384 pref_defaults.web_security_enabled);
385 prefs->RegisterBooleanPref(
386 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
387 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
388 pref_defaults.loads_images_automatically);
389 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
390 pref_defaults.plugins_enabled);
391 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
392 pref_defaults.dom_paste_enabled);
393 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
394 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08395 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
396 pref_defaults.inspector_settings);
[email protected]420ae012009-04-24 05:16:32397 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
398 pref_defaults.text_areas_are_resizable);
399 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
400 pref_defaults.java_enabled);
401
402 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
403 IDS_ACCEPT_LANGUAGES);
404 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
405 IDS_DEFAULT_ENCODING);
406 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
407 IDS_STANDARD_FONT_IS_SERIF);
408 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
409 IDS_FIXED_FONT_FAMILY);
410 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
411 IDS_SERIF_FONT_FAMILY);
412 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
413 IDS_SANS_SERIF_FONT_FAMILY);
414 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
415 IDS_CURSIVE_FONT_FAMILY);
416 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
417 IDS_FANTASY_FONT_FAMILY);
418 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
419 IDS_DEFAULT_FONT_SIZE);
420 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
421 IDS_DEFAULT_FIXED_FONT_SIZE);
422 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
423 IDS_MINIMUM_FONT_SIZE);
424 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
425 IDS_MINIMUM_LOGICAL_FONT_SIZE);
426 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
427 IDS_USES_UNIVERSAL_DETECTOR);
428 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
429 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29430}
431
[email protected]13367f72009-07-08 16:39:02432// Returns true if contains content rendered by an extension.
433bool TabContents::HostsExtension() const {
434 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34435}
436
[email protected]6e95706d2009-04-23 22:55:01437PasswordManager* TabContents::GetPasswordManager() {
438 if (password_manager_.get() == NULL)
439 password_manager_.reset(new PasswordManager(this));
440 return password_manager_.get();
441}
442
443PluginInstaller* TabContents::GetPluginInstaller() {
444 if (plugin_installer_.get() == NULL)
445 plugin_installer_.reset(new PluginInstaller(this));
446 return plugin_installer_.get();
447}
448
[email protected]d5f942ba2008-09-26 19:30:34449const GURL& TabContents::GetURL() const {
450 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57451 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54452 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34453}
454
[email protected]96d185d2009-04-24 03:28:54455const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55456 // Transient entries take precedence. They are used for interstitial pages
457 // that are shown on top of existing pages.
458 NavigationEntry* entry = controller_.GetTransientEntry();
459 if (entry)
460 return entry->GetTitleForDisplay(&controller_);
461
[email protected]96d185d2009-04-24 03:28:54462 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
463 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
464 if (our_dom_ui) {
465 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55466 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54467 if (!(entry && entry->IsViewSourceMode())) {
468 // Give the DOM UI the chance to override our title.
469 const string16& title = our_dom_ui->overridden_title();
470 if (!title.empty())
471 return title;
472 }
473 }
474
475 // We use the title for the last committed entry rather than a pending
476 // navigation entry. For example, when the user types in a URL, we want to
477 // keep the old page's title until the new load has committed and we get a new
478 // title.
[email protected]96d185d2009-04-24 03:28:54479 entry = controller_.GetLastCommittedEntry();
480 if (entry)
481 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54482 return EmptyString16();
483}
484
[email protected]d5f942ba2008-09-26 19:30:34485int32 TabContents::GetMaxPageID() {
486 if (GetSiteInstance())
487 return GetSiteInstance()->max_page_id();
488 else
489 return max_page_id_;
490}
491
492void TabContents::UpdateMaxPageID(int32 page_id) {
493 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34494 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34495 // testing.
496 if (GetSiteInstance())
497 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]57c6a652009-05-04 07:58:34498 process()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34499}
500
[email protected]96d185d2009-04-24 03:28:54501SiteInstance* TabContents::GetSiteInstance() const {
502 return render_manager_.current_host()->site_instance();
503}
504
[email protected]d5f942ba2008-09-26 19:30:34505const std::wstring TabContents::GetDefaultTitle() const {
506 return l10n_util::GetString(IDS_DEFAULT_TAB_TITLE);
507}
508
[email protected]96d185d2009-04-24 03:28:54509bool TabContents::ShouldDisplayURL() {
510 // Don't hide the url in view source mode.
511 NavigationEntry* entry = controller_.GetActiveEntry();
512 if (entry && entry->IsViewSourceMode())
513 return true;
[email protected]83e3895b2009-06-11 00:07:16514
[email protected]96d185d2009-04-24 03:28:54515 DOMUI* dom_ui = GetDOMUIForCurrentState();
516 if (dom_ui)
517 return !dom_ui->should_hide_url();
518 return true;
519}
520
[email protected]d5f942ba2008-09-26 19:30:34521SkBitmap TabContents::GetFavIcon() const {
522 // Like GetTitle(), we also want to use the favicon for the last committed
523 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57524 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47525 if (entry)
526 return entry->favicon().bitmap();
527
[email protected]ce3fa3c2009-04-20 19:55:57528 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34529 if (entry)
530 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34531 return SkBitmap();
532}
533
[email protected]96d185d2009-04-24 03:28:54534bool TabContents::ShouldDisplayFavIcon() {
535 // Always display a throbber during pending loads.
536 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
537 return true;
538
539 DOMUI* dom_ui = GetDOMUIForCurrentState();
540 if (dom_ui)
541 return !dom_ui->hide_favicon();
542 return true;
543}
544
[email protected]96d185d2009-04-24 03:28:54545std::wstring TabContents::GetStatusText() const {
546 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
547 return std::wstring();
548
549 switch (load_state_) {
550 case net::LOAD_STATE_WAITING_FOR_CACHE:
551 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
552 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
553 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
554 case net::LOAD_STATE_RESOLVING_HOST:
555 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
556 case net::LOAD_STATE_CONNECTING:
557 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
558 case net::LOAD_STATE_SENDING_REQUEST:
559 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
560 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
561 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
562 load_state_host_);
563 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
564 case net::LOAD_STATE_IDLE:
565 case net::LOAD_STATE_READING_RESPONSE:
566 break;
567 }
568
569 return std::wstring();
570}
571
[email protected]d5f942ba2008-09-26 19:30:34572void TabContents::SetIsCrashed(bool state) {
573 if (state == is_crashed_)
574 return;
575
576 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50577 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34578}
579
[email protected]f9b1a7b2009-06-22 17:26:38580void TabContents::SetPageActionEnabled(const PageAction* page_action,
[email protected]d7eaf572009-07-01 21:57:00581 bool enable,
582 const std::string& title,
583 int icon_id) {
[email protected]ce5c4502009-05-06 16:46:11584 DCHECK(page_action);
585
[email protected]d7eaf572009-07-01 21:57:00586 if (!enable &&
587 enabled_page_actions_.end() == enabled_page_actions_.find(page_action)) {
588 return; // Don't need to disable twice.
589 }
[email protected]ce5c4502009-05-06 16:46:11590
[email protected]d7eaf572009-07-01 21:57:00591 if (enable) {
592 enabled_page_actions_[page_action].reset(
593 new PageActionState(title, icon_id));
594 } else {
[email protected]f9b1a7b2009-06-22 17:26:38595 enabled_page_actions_.erase(page_action);
[email protected]d7eaf572009-07-01 21:57:00596 }
[email protected]ce5c4502009-05-06 16:46:11597}
598
[email protected]d7eaf572009-07-01 21:57:00599const PageActionState* TabContents::GetPageActionState(
600 const PageAction* page_action) {
601 if (enabled_page_actions_.end() == enabled_page_actions_.find(page_action))
602 return NULL;
[email protected]ce5c4502009-05-06 16:46:11603
[email protected]d7eaf572009-07-01 21:57:00604 return enabled_page_actions_[page_action].get();
605}
[email protected]ce5c4502009-05-06 16:46:11606
[email protected]d5f942ba2008-09-26 19:30:34607void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
608 if (delegate_)
609 delegate_->NavigationStateChanged(this, changed_flags);
610}
611
[email protected]96d185d2009-04-24 03:28:54612void TabContents::DidBecomeSelected() {
613 controller_.SetActive(true);
[email protected]789e9152009-08-04 21:59:43614 if (render_widget_host_view()) {
[email protected]96d185d2009-04-24 03:28:54615 render_widget_host_view()->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43616#if defined(OS_MACOSX)
617 render_widget_host_view()->SetActive(true);
618#endif
619 }
[email protected]96d185d2009-04-24 03:28:54620
[email protected]76543b92009-08-31 17:27:45621 WebCacheManager::GetInstance()->ObserveActivity(process()->id());
[email protected]96d185d2009-04-24 03:28:54622}
623
624void TabContents::WasHidden() {
625 if (!capturing_contents()) {
626 // |render_view_host()| can be NULL if the user middle clicks a link to open
627 // a tab in then background, then closes the tab before selecting it. This
628 // is because closing the tab calls TabContents::Destroy(), which removes
629 // the |render_view_host()|; then when we actually destroy the window,
630 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
631 if (render_widget_host_view())
632 render_widget_host_view()->WasHidden();
[email protected]96d185d2009-04-24 03:28:54633 }
634
635 NotificationService::current()->Notify(
636 NotificationType::TAB_CONTENTS_HIDDEN,
637 Source<TabContents>(this),
638 NotificationService::NoDetails());
639}
640
[email protected]d5f942ba2008-09-26 19:30:34641void TabContents::Activate() {
642 if (delegate_)
643 delegate_->ActivateContents(this);
644}
645
[email protected]96d185d2009-04-24 03:28:54646void TabContents::ShowContents() {
647 if (render_widget_host_view())
648 render_widget_host_view()->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54649}
650
651void TabContents::HideContents() {
652 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
653 // our superclass HideContents(), because some callers want to be very picky
654 // about the order in which these get called. In addition to making the code
655 // here practically impossible to understand, this also means we end up
656 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34657 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54658 WasHidden();
659}
660
[email protected]c0588052008-10-27 23:01:50661void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34662 WindowOpenDisposition disposition,
663 PageTransition::Type transition) {
664 if (delegate_)
[email protected]c0588052008-10-27 23:01:50665 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34666}
667
668bool TabContents::NavigateToPendingEntry(bool reload) {
[email protected]96d185d2009-04-24 03:28:54669 const NavigationEntry& entry = *controller_.pending_entry();
670
671 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
672 if (!dest_render_view_host)
673 return false; // Unable to create the desired render view host.
674
675 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12676 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32677 if (devtools_manager) { // NULL in unit tests.
[email protected]684b4ba22009-05-07 06:27:41678 devtools_manager->OnNavigatingToPendingEntry(
679 render_view_host(),
680 dest_render_view_host,
681 controller_.pending_entry()->url());
[email protected]7e8e6b62009-05-08 11:28:32682 }
[email protected]96d185d2009-04-24 03:28:54683
684 // Used for page load time metrics.
685 current_load_start_ = base::TimeTicks::Now();
686
687 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34688 ViewMsg_Navigate_Params navigate_params;
689 MakeNavigateParams(entry, reload, &navigate_params);
690 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54691
692 if (entry.page_id() == -1) {
693 // HACK!! This code suppresses javascript: URLs from being added to
694 // session history, which is what we want to do for javascript: URLs that
695 // do not generate content. What we really need is a message from the
696 // renderer telling us that a new page was not created. The same message
697 // could be used for mailto: URLs and the like.
698 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
699 return false;
700 }
701
702 // Clear any provisional password saves - this stops password infobars
703 // showing up on pages the user navigates to while the right page is
704 // loading.
705 GetPasswordManager()->ClearProvisionalSave();
706
707 if (reload && !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48708 FaviconService* favicon_service =
709 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
710 if (favicon_service)
711 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54712 }
713
[email protected]d5f942ba2008-09-26 19:30:34714 return true;
715}
716
[email protected]96d185d2009-04-24 03:28:54717void TabContents::Stop() {
718 render_manager_.Stop();
719 printing_.Stop();
720}
721
722void TabContents::Cut() {
723 render_view_host()->Cut();
724}
725
726void TabContents::Copy() {
727 render_view_host()->Copy();
728}
729
[email protected]c0cc3092009-09-12 08:27:27730#if defined(OS_MACOSX)
[email protected]a954bf72009-09-12 07:30:35731void TabContents::CopyToFindPboard() {
732 render_view_host()->CopyToFindPboard();
733}
[email protected]c0cc3092009-09-12 08:27:27734#endif
[email protected]a954bf72009-09-12 07:30:35735
[email protected]96d185d2009-04-24 03:28:54736void TabContents::Paste() {
737 render_view_host()->Paste();
738}
739
740void TabContents::DisassociateFromPopupCount() {
741 render_view_host()->DisassociateFromPopupCount();
742}
743
744TabContents* TabContents::Clone() {
745 // We create a new SiteInstance so that the new tab won't share processes
746 // with the old one. This can be changed in the future if we need it to share
747 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32748 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54749 SiteInstance::CreateSiteInstance(profile()),
750 MSG_ROUTING_NONE, NULL);
751 tc->controller().CopyStateFrom(controller_);
752 return tc;
753}
754
[email protected]420ae012009-04-24 05:16:32755void TabContents::CreateShortcut() {
756 NavigationEntry* entry = controller_.GetLastCommittedEntry();
757 if (!entry)
758 return;
759
[email protected]70b8d6b2009-08-20 16:56:24760#if defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)
[email protected]0ba5c5e2009-08-20 16:47:13761 CreateApplicationShortcutsDialogGtk::Show(view()->GetTopLevelNativeWindow(),
762 GetURL(), GetTitle());
[email protected]b96aa932009-08-12 21:34:49763#else
[email protected]420ae012009-04-24 05:16:32764 // We only allow one pending install request. By resetting the page id we
765 // effectively cancel the pending install request.
766 pending_install_.page_id = entry->page_id();
767 pending_install_.icon = GetFavIcon();
768 pending_install_.title = UTF16ToWideHack(GetTitle());
769 pending_install_.url = GetURL();
770 if (pending_install_.callback_functor) {
771 pending_install_.callback_functor->Cancel();
772 pending_install_.callback_functor = NULL;
773 }
774 DCHECK(!pending_install_.icon.isNull()) << "Menu item should be disabled.";
775 if (pending_install_.title.empty())
776 pending_install_.title = UTF8ToWide(GetURL().spec());
777
778 // Request the application info. When done OnDidGetApplicationInfo is invoked
779 // and we'll create the shortcut.
780 render_view_host()->GetApplicationInfo(pending_install_.page_id);
[email protected]b96aa932009-08-12 21:34:49781#endif
[email protected]420ae012009-04-24 05:16:32782}
783
[email protected]4d677202009-07-19 07:37:12784void TabContents::ShowPageInfo(const GURL& url,
785 const NavigationEntry::SSLStatus& ssl,
786 bool show_history) {
787 if (!delegate_)
788 return;
789
[email protected]bb678332009-07-21 00:15:50790 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12791}
792
initial.commit09911bf2008-07-26 23:55:29793ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28794 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29795 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28796 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29797 child_windows_.push_back(window);
798 return window;
799}
800
801void TabContents::AddNewContents(TabContents* new_contents,
802 WindowOpenDisposition disposition,
803 const gfx::Rect& initial_pos,
[email protected]c88a70fe2009-05-05 20:00:22804 bool user_gesture,
805 const GURL& creator_url) {
initial.commit09911bf2008-07-26 23:55:29806 if (!delegate_)
807 return;
808
[email protected]35f7d212009-04-29 21:19:27809 if ((disposition == NEW_POPUP) && !user_gesture &&
810 !CommandLine::ForCurrentProcess()->HasSwitch(
811 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22812 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31813 // the whitelist. The popup owner will handle checking this.
814 delegate_->GetConstrainingContents(this)->AddPopup(new_contents,
815 initial_pos,
816 creator_url.is_valid() ? creator_url.host() : std::string());
817 } else {
[email protected]304f8792009-08-19 21:28:09818#if defined(OS_CHROMEOS)
819 if (disposition == NEW_POPUP) {
820 // If the popup is bigger than a given factor of the screen, then
821 // turn it into a foreground tab (on chrome os only)
822 GdkScreen* screen = gdk_screen_get_default();
823 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
824 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
825 if (initial_pos.width() > max_width ||
826 initial_pos.height() > max_height) {
827 disposition = NEW_FOREGROUND_TAB;
828 }
829 }
830#endif
831
[email protected]0aa55312008-10-17 21:53:08832 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29833 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
834 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49835 NotificationService::current()->Notify(
836 NotificationType::TAB_ADDED,
837 Source<TabContentsDelegate>(delegate_),
838 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29839 }
[email protected]b6c874582009-05-08 19:38:31840 PopupNotificationVisibilityChanged(ShowingBlockedPopupNotification());
initial.commit09911bf2008-07-26 23:55:29841}
842
initial.commit09911bf2008-07-26 23:55:29843void TabContents::CloseAllSuppressedPopups() {
[email protected]d6598c052008-11-05 19:03:25844 if (blocked_popups_)
[email protected]2c4410d2009-05-06 23:46:22845 blocked_popups_->CloseAll();
initial.commit09911bf2008-07-26 23:55:29846}
847
[email protected]912256b32009-09-18 09:47:35848void TabContents::ExecuteCode(int request_id, const std::string& extension_id,
849 bool is_js_code, const std::string& code_string) {
850 render_view_host()->Send(
851 new ViewMsg_ExecuteCode(render_view_host()->routing_id(), request_id,
852 extension_id, is_js_code, code_string));
853}
854
[email protected]96d185d2009-04-24 03:28:54855void TabContents::PopupNotificationVisibilityChanged(bool visible) {
856 render_view_host()->PopupNotificationVisibilityChanged(visible);
857}
858
[email protected]5c9e97a2009-09-09 23:48:30859gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54860 return view_->GetContentNativeView();
861}
862
863gfx::NativeView TabContents::GetNativeView() const {
864 return view_->GetNativeView();
865}
866
867void TabContents::GetContainerBounds(gfx::Rect *out) const {
868 view_->GetContainerBounds(out);
869}
870
871void TabContents::Focus() {
872 view_->Focus();
873}
874
[email protected]90daadb42009-06-08 21:27:28875void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54876 if (showing_interstitial_page()) {
877 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
878 return;
879 }
[email protected]96d185d2009-04-24 03:28:54880 render_view_host()->SetInitialFocus(reverse);
881}
882
883bool TabContents::FocusLocationBarByDefault() {
884 DOMUI* dom_ui = GetDOMUIForCurrentState();
885 if (dom_ui)
886 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43887 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25888 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43889 return true;
[email protected]96d185d2009-04-24 03:28:54890 return false;
891}
892
[email protected]616ed5a2008-11-21 22:27:24893void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
894 // Look through the existing InfoBarDelegates we have for a match. If we've
895 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:05896 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]616ed5a2008-11-21 22:27:24897 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate))
898 return;
899 }
900
901 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:56902 NotificationService::current()->Notify(
903 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
904 Source<TabContents>(this),
905 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:24906
907 // Add ourselves as an observer for navigations the first time a delegate is
908 // added. We use this notification to expire InfoBars that need to expire on
909 // page transitions.
910 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:56911 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57912 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:24913 }
914}
915
916void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
917 std::vector<InfoBarDelegate*>::iterator it =
918 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
919 if (it != infobar_delegates_.end()) {
920 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:56921 NotificationService::current()->Notify(
922 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
923 Source<TabContents>(this),
924 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:05925 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:24926
[email protected]6a02963e2009-01-06 16:58:03927 // Remove ourselves as an observer if we are tracking no more InfoBars.
928 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:56929 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:57930 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:03931 }
[email protected]616ed5a2008-11-21 22:27:24932 }
933}
[email protected]3edd9522009-03-04 22:19:41934
[email protected]f81821c2009-08-07 01:29:47935void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
936 InfoBarDelegate* new_delegate) {
937 std::vector<InfoBarDelegate*>::iterator it =
938 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
939 DCHECK(it != infobar_delegates_.end());
940
941 // Notify the container about the change of plans.
942 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
943 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
944 old_delegate, new_delegate));
945 NotificationService::current()->Notify(
946 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
947 Source<TabContents>(this),
948 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
949
950 // Remove the old one.
951 infobar_delegates_.erase(it);
952
953 // Add the new one.
954 infobar_delegates_.push_back(new_delegate);
955}
956
[email protected]96d185d2009-04-24 03:28:54957bool TabContents::IsBookmarkBarAlwaysVisible() {
958 // See GetDOMUIForCurrentState() comment for more info. This case is very
959 // similar, but for non-first loads, we want to use the committed entry. This
960 // is so the bookmarks bar disappears at the same time the page does.
961 if (controller_.GetLastCommittedEntry()) {
962 // Not the first load, always use the committed DOM UI.
963 if (render_manager_.dom_ui())
964 return render_manager_.dom_ui()->force_bookmark_bar_visible();
965 return false; // Default.
966 }
967
968 // When it's the first load, we know either the pending one or the committed
969 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
970 // of them will be valid, so we can just check both.
971 if (render_manager_.pending_dom_ui())
972 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
973 if (render_manager_.dom_ui())
974 return render_manager_.dom_ui()->force_bookmark_bar_visible();
975 return false; // Default.
976}
977
[email protected]d8f16ae2009-08-30 03:47:26978bool TabContents::IsExtensionShelfAlwaysVisible() {
979 // See GetDOMUIForCurrentState() comment for more info. This case is very
980 // similar, but for non-first loads, we want to use the committed entry. This
981 // is so the bookmarks bar disappears at the same time the page does.
982 if (controller_.GetLastCommittedEntry()) {
983 // Not the first load, always use the committed DOM UI.
984 if (render_manager_.dom_ui())
985 return render_manager_.dom_ui()->force_extension_shelf_visible();
986 return false; // Default.
987 }
988
989 // When it's the first load, we know either the pending one or the committed
990 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
991 // of them will be valid, so we can just check both.
992 if (render_manager_.pending_dom_ui())
993 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
994 if (render_manager_.dom_ui())
995 return render_manager_.dom_ui()->force_extension_shelf_visible();
996 return false; // Default.
997}
998
[email protected]3edd9522009-03-04 22:19:41999void TabContents::ToolbarSizeChanged(bool is_animating) {
1000 TabContentsDelegate* d = delegate();
1001 if (d)
1002 d->ToolbarSizeChanged(this, is_animating);
1003}
[email protected]616ed5a2008-11-21 22:27:241004
[email protected]d5f942ba2008-09-26 19:30:341005void TabContents::OnStartDownload(DownloadItem* download) {
1006 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341007
1008 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311009 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341010
[email protected]59560e0b2009-06-04 03:30:221011 if (tab_contents && tab_contents->delegate())
1012 tab_contents->delegate()->OnStartDownload(download);
[email protected]3edd9522009-03-04 22:19:411013}
[email protected]3edd9522009-03-04 22:19:411014
[email protected]d5f942ba2008-09-26 19:30:341015void TabContents::WillClose(ConstrainedWindow* window) {
1016 ConstrainedWindowList::iterator it =
1017 find(child_windows_.begin(), child_windows_.end(), window);
1018 if (it != child_windows_.end())
1019 child_windows_.erase(it);
[email protected]66ba4932009-06-04 19:22:131020}
[email protected]d5f942ba2008-09-26 19:30:341021
[email protected]66ba4932009-06-04 19:22:131022void TabContents::WillCloseBlockedPopupContainer(
1023 BlockedPopupContainer* container) {
1024 DCHECK(blocked_popups_ == container);
1025 blocked_popups_ = NULL;
[email protected]d5f942ba2008-09-26 19:30:341026}
1027
[email protected]d5f942ba2008-09-26 19:30:341028void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351029#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061030 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351031#endif
[email protected]d5f942ba2008-09-26 19:30:341032}
1033
[email protected]e491f1c2009-05-22 20:28:121034void TabContents::StartFinding(string16 find_text,
1035 bool forward_direction,
1036 bool case_sensitive) {
[email protected]6e95706d2009-04-23 22:55:011037 // If find_text is empty, it means FindNext was pressed with a keyboard
1038 // shortcut so unless we have something to search for we return early.
[email protected]e491f1c2009-05-22 20:28:121039 if (find_text.empty() && find_text_.empty()) {
1040 if (last_search_prepopulate_text_->empty())
1041 return;
1042 // Try whatever we searched for last in any tab.
1043 find_text = *last_search_prepopulate_text_;
1044 }
[email protected]6e95706d2009-04-23 22:55:011045
1046 // This is a FindNext operation if we are searching for the same text again,
1047 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1048 // exception to this is if the Find was aborted (then we don't want FindNext
1049 // because the highlighting has been cleared and we need it to reappear). We
1050 // therefore treat FindNext after an aborted Find operation as a full fledged
1051 // Find.
1052 bool find_next = (find_text_ == find_text || find_text.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121053 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011054 !find_op_aborted_;
1055 if (!find_next)
1056 current_find_request_id_ = find_request_id_counter_++;
1057
1058 if (!find_text.empty())
1059 find_text_ = find_text;
[email protected]e491f1c2009-05-22 20:28:121060 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011061
1062 find_op_aborted_ = false;
1063
1064 // Keep track of what the last search was across the tabs.
[email protected]e491f1c2009-05-22 20:28:121065 *last_search_prepopulate_text_ = find_text;
[email protected]6e95706d2009-04-23 22:55:011066
1067 render_view_host()->StartFinding(current_find_request_id_,
1068 find_text_,
1069 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121070 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011071 find_next);
1072}
1073
1074void TabContents::StopFinding(bool clear_selection) {
[email protected]2d2dffc2009-06-09 21:41:001075 // When |clear_selection| is true, it means the find string has been cleared
1076 // by the user, but the UI has not been dismissed.
1077 if (!clear_selection)
1078 find_ui_active_ = false;
[email protected]6e95706d2009-04-23 22:55:011079 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121080 last_search_result_ = FindNotificationDetails();
[email protected]6e95706d2009-04-23 22:55:011081 render_view_host()->StopFinding(clear_selection);
1082}
1083
[email protected]5c4266922009-07-10 16:41:271084void TabContents::GetPageLanguage() {
1085 render_view_host()->GetPageLanguage();
1086}
1087
[email protected]420ae012009-04-24 05:16:321088void TabContents::OnJavaScriptMessageBoxClosed(IPC::Message* reply_msg,
1089 bool success,
1090 const std::wstring& prompt) {
1091 last_javascript_message_dismissal_ = base::TimeTicks::Now();
1092 render_manager_.OnJavaScriptMessageBoxClosed(reply_msg, success, prompt);
1093}
1094
[email protected]571e31152009-05-15 19:34:021095void TabContents::OnJavaScriptMessageBoxWindowDestroyed() {
1096 render_manager_.OnJavaScriptMessageBoxWindowDestroyed();
1097}
1098
[email protected]420ae012009-04-24 05:16:321099void TabContents::OnSavePage() {
1100 // If we can not save the page, try to download it.
1101 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1102 DownloadManager* dlm = profile()->GetDownloadManager();
1103 const GURL& current_page_url = GetURL();
1104 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221105 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321106 return;
1107 }
1108
1109 Stop();
1110
1111 // Create the save package and possibly prompt the user for the name to save
1112 // the page as. The user prompt is an asynchronous operation that runs on
1113 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221114 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321115 save_package_->GetSaveInfo();
1116}
1117
1118// Used in automated testing to bypass prompting the user for file names.
1119// Instead, the names and paths are hard coded rather than running them through
1120// file name sanitation and extension / mime checking.
[email protected]cdf6cc82009-08-04 21:48:591121bool TabContents::SavePage(const std::wstring& main_file,
[email protected]420ae012009-04-24 05:16:321122 const std::wstring& dir_path,
1123 SavePackage::SavePackageType save_type) {
1124 // Stop the page from navigating.
1125 Stop();
1126
[email protected]d82ed61e2009-06-16 02:46:221127 save_package_ = new SavePackage(this, save_type,
[email protected]420ae012009-04-24 05:16:321128 FilePath::FromWStringHack(main_file),
1129 FilePath::FromWStringHack(dir_path));
[email protected]cdf6cc82009-08-04 21:48:591130 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321131}
1132
1133void TabContents::PrintPreview() {
1134 // We don't show the print preview yet, only the print dialog.
1135 PrintNow();
1136}
1137
1138bool TabContents::PrintNow() {
1139 // We can't print interstitial page for now.
1140 if (showing_interstitial_page())
1141 return false;
1142
1143 return render_view_host()->PrintPages();
1144}
1145
[email protected]82270452009-06-19 15:58:011146void TabContents::PrintingDone(int document_cookie, bool success) {
1147 render_view_host()->PrintingDone(document_cookie, success);
1148}
1149
[email protected]420ae012009-04-24 05:16:321150bool TabContents::IsActiveEntry(int32 page_id) {
1151 NavigationEntry* active_entry = controller_.GetActiveEntry();
1152 return (active_entry != NULL &&
1153 active_entry->site_instance() == GetSiteInstance() &&
1154 active_entry->page_id() == page_id);
1155}
1156
[email protected]96d185d2009-04-24 03:28:541157// Notifies the RenderWidgetHost instance about the fact that the page is
1158// loading, or done loading and calls the base implementation.
1159void TabContents::SetIsLoading(bool is_loading,
1160 LoadNotificationDetails* details) {
1161 if (is_loading == is_loading_)
1162 return;
1163
1164 if (!is_loading) {
1165 load_state_ = net::LOAD_STATE_IDLE;
1166 load_state_host_.clear();
1167 }
1168
1169 render_manager_.SetIsLoading(is_loading);
1170
1171 is_loading_ = is_loading;
1172 waiting_for_response_ = is_loading;
1173
1174 if (delegate_)
1175 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351176 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541177
1178 NotificationType type = is_loading ? NotificationType::LOAD_START :
1179 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111180 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541181 if (details)
1182 det = Details<LoadNotificationDetails>(details);
1183 NotificationService::current()->Notify(type,
1184 Source<NavigationController>(&controller_),
1185 det);
1186}
1187
[email protected]2c4410d2009-05-06 23:46:221188void TabContents::CreateBlockedPopupContainerIfNecessary() {
1189 if (blocked_popups_)
1190 return;
1191
[email protected]4d4c0b92009-06-08 23:13:011192 blocked_popups_ = BlockedPopupContainer::Create(this, profile());
[email protected]2c4410d2009-05-06 23:46:221193}
1194
[email protected]b6c874582009-05-08 19:38:311195void TabContents::AddPopup(TabContents* new_contents,
1196 const gfx::Rect& initial_pos,
1197 const std::string& host) {
[email protected]2c4410d2009-05-06 23:46:221198 CreateBlockedPopupContainerIfNecessary();
1199 blocked_popups_->AddTabContents(new_contents, initial_pos, host);
[email protected]2c4410d2009-05-06 23:46:221200}
1201
[email protected]e69bce3dd2009-04-20 22:05:121202// TODO(brettw) This should be on the TabContentsView.
[email protected]66ba4932009-06-04 19:22:131203void TabContents::RepositionSupressedPopupsToFit() {
[email protected]d6598c052008-11-05 19:03:251204 if (blocked_popups_)
[email protected]4d4c0b92009-06-08 23:13:011205 blocked_popups_->RepositionBlockedPopupContainer();
[email protected]d5f942ba2008-09-26 19:30:341206}
1207
[email protected]b9681312008-11-07 00:08:261208bool TabContents::ShowingBlockedPopupNotification() const {
1209 return blocked_popups_ != NULL &&
[email protected]2c4410d2009-05-06 23:46:221210 blocked_popups_->GetBlockedPopupCount() != 0;
[email protected]b9681312008-11-07 00:08:261211}
[email protected]616ed5a2008-11-21 22:27:241212
1213namespace {
1214bool TransitionIsReload(PageTransition::Type transition) {
1215 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1216}
1217}
1218
1219void TabContents::ExpireInfoBars(
1220 const NavigationController::LoadCommittedDetails& details) {
1221 // Only hide InfoBars when the user has done something that makes the main
1222 // frame load. We don't want various automatic or subframe navigations making
1223 // it disappear.
1224 if (!details.is_user_initiated_main_frame_load())
1225 return;
1226
[email protected]f86a07022008-11-25 01:06:051227 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241228 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051229 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241230 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241231 }
1232}
[email protected]fdd61c62009-04-22 19:22:571233
1234void TabContents::OnGearsCreateShortcutDone(
1235 const GearsShortcutData2& shortcut_data, bool success) {
1236 NavigationEntry* current_entry = controller_.GetLastCommittedEntry();
1237 bool same_page =
1238 current_entry && pending_install_.page_id == current_entry->page_id();
1239
1240 if (success && same_page) {
1241 // Only switch to app mode if the user chose to create a shortcut and
1242 // we're still on the same page that it corresponded to.
1243 if (delegate())
1244 delegate()->ConvertContentsToApplication(this);
1245 }
1246
1247 // Reset the page id to indicate no requests are pending.
1248 pending_install_.page_id = 0;
1249 pending_install_.callback_functor = NULL;
1250}
[email protected]96d185d2009-04-24 03:28:541251
1252DOMUI* TabContents::GetDOMUIForCurrentState() {
1253 // When there is a pending navigation entry, we want to use the pending DOMUI
1254 // that goes along with it to control the basic flags. For example, we want to
1255 // show the pending URL in the URL bar, so we want the display_url flag to
1256 // be from the pending entry.
1257 //
1258 // The confusion comes because there are multiple possibilities for the
1259 // initial load in a tab as a side effect of the way the RenderViewHostManager
1260 // works.
1261 //
1262 // - For the very first tab the load looks "normal". The new tab DOM UI is
1263 // the pending one, and we want it to apply here.
1264 //
1265 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1266 // get switched to the one previously associated with the new tab pages.
1267 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1268 // have a committed DOM UI in this case.
1269 //
1270 // This condition handles all of these cases:
1271 //
1272 // - First load in first tab: no committed nav entry + pending nav entry +
1273 // pending dom ui:
1274 // -> Use pending DOM UI if any.
1275 //
1276 // - First load in second tab: no committed nav entry + pending nav entry +
1277 // no pending DOM UI:
1278 // -> Use the committed DOM UI if any.
1279 //
1280 // - Second navigation in any tab: committed nav entry + pending nav entry:
1281 // -> Use pending DOM UI if any.
1282 //
1283 // - Normal state with no load: committed nav entry + no pending nav entry:
1284 // -> Use committed DOM UI.
1285 if (controller_.pending_entry() &&
1286 (controller_.GetLastCommittedEntry() ||
1287 render_manager_.pending_dom_ui()))
1288 return render_manager_.pending_dom_ui();
1289 return render_manager_.dom_ui();
1290}
[email protected]420ae012009-04-24 05:16:321291
1292void TabContents::DidNavigateMainFramePostCommit(
1293 const NavigationController::LoadCommittedDetails& details,
1294 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441295 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1296 // If this is a window.open navigation, use the same DOMUI as the renderer
1297 // that opened the window, as long as both renderers have the same
1298 // privileges.
1299 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1300 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1301 // dom_ui might be NULL if the URL refers to a non-existent extension.
1302 if (dom_ui) {
1303 render_manager_.SetDOMUIPostCommit(dom_ui);
1304 dom_ui->RenderViewCreated(render_view_host());
1305 }
1306 }
1307 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1308 }
1309
[email protected]420ae012009-04-24 05:16:321310 if (details.is_user_initiated_main_frame_load()) {
1311 // Clear the status bubble. This is a workaround for a bug where WebKit
1312 // doesn't let us know that the cursor left an element during a
1313 // transition (this is also why the mouse cursor remains as a hand after
1314 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1315 // clear the bubble when a user navigates to a named anchor in the same
1316 // page.
1317 UpdateTargetURL(details.entry->page_id(), GURL());
1318
1319 // UpdateHelpersForDidNavigate will handle the case where the password_form
1320 // origin is valid.
1321 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1322 // cleaned up and covered by tests.
1323 if (!params.password_form.origin.is_valid())
1324 GetPasswordManager()->DidNavigate();
1325 }
1326
1327 // The keyword generator uses the navigation entries, so must be called after
1328 // the commit.
1329 GenerateKeywordIfNecessary(params);
1330
1331 // Allow the new page to set the title again.
1332 received_page_title_ = false;
1333
1334 // Get the favicon, either from history or request it from the net.
1335 fav_icon_helper_.FetchFavIcon(details.entry->url());
1336
[email protected]aece2c7f2009-08-27 20:43:171337 // Disable all page actions, unless this is an in-page navigation.
1338 if (!enabled_page_actions_.empty()) {
1339 url_canon::Replacements<char> replacements;
1340 replacements.ClearRef();
1341 if (params.url.ReplaceComponents(replacements) !=
1342 params.referrer.ReplaceComponents(replacements)) {
1343 enabled_page_actions_.clear();
1344 }
1345 }
[email protected]ce5c4502009-05-06 16:46:111346
[email protected]420ae012009-04-24 05:16:321347 // Close constrained popups if necessary.
1348 MaybeCloseChildWindows(details.previous_url, details.entry->url());
1349
1350 // Update the starred state.
1351 UpdateStarredStateForCurrentURL();
1352}
1353
1354void TabContents::DidNavigateAnyFramePostCommit(
1355 RenderViewHost* render_view_host,
1356 const NavigationController::LoadCommittedDetails& details,
1357 const ViewHostMsg_FrameNavigate_Params& params) {
1358 // If we navigate, start showing messages again. This does nothing to prevent
1359 // a malicious script from spamming messages, since the script could just
1360 // reload the page to stop blocking.
1361 suppress_javascript_messages_ = false;
1362
[email protected]420ae012009-04-24 05:16:321363 // Notify the password manager of the navigation or form submit.
1364 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1365 // cleaned up and covered by tests.
1366 if (params.password_form.origin.is_valid())
1367 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
1368}
1369
1370void TabContents::MaybeCloseChildWindows(const GURL& previous_url,
1371 const GURL& current_url) {
1372 if (net::RegistryControlledDomainService::SameDomainOrHost(
1373 previous_url, current_url))
1374 return;
1375
1376 // Clear out any child windows since we are leaving this page entirely.
1377 // We use indices instead of iterators in case CloseWindow does something
1378 // that may invalidate an iterator.
1379 int size = static_cast<int>(child_windows_.size());
1380 for (int i = size - 1; i >= 0; --i) {
1381 ConstrainedWindow* window = child_windows_[i];
1382 if (window)
1383 window->CloseConstrainedWindow();
1384 }
[email protected]e29300cd2009-07-23 21:14:591385
1386 // Close the popup container.
1387 if (blocked_popups_) {
1388 blocked_popups_->Destroy();
1389 blocked_popups_ = NULL;
1390 }
[email protected]420ae012009-04-24 05:16:321391}
1392
1393void TabContents::UpdateStarredStateForCurrentURL() {
1394 BookmarkModel* model = profile()->GetBookmarkModel();
1395 const bool old_state = is_starred_;
1396 is_starred_ = (model && model->IsBookmarked(GetURL()));
1397
1398 if (is_starred_ != old_state && delegate())
1399 delegate()->URLStarredChanged(this, is_starred_);
1400}
1401
1402void TabContents::UpdateAlternateErrorPageURL() {
1403 GURL url = GetAlternateErrorPageURL();
1404 render_view_host()->SetAlternateErrorPageURL(url);
1405}
1406
1407void TabContents::UpdateWebPreferences() {
1408 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1409}
1410
1411void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1412 RenderViewHost* rvh) {
1413 // If we are creating a RVH for a restored controller, then we might
1414 // have more page IDs than the SiteInstance's current max page ID. We must
1415 // make sure that the max page ID is larger than any restored page ID.
1416 // Note that it is ok for conflicting page IDs to exist in another tab
1417 // (i.e., NavigationController), but if any page ID is larger than the max,
1418 // the back/forward list will get confused.
1419 int max_restored_page_id = controller_.max_restored_page_id();
1420 if (max_restored_page_id > 0) {
1421 int curr_max_page_id = site_instance->max_page_id();
1422 if (max_restored_page_id > curr_max_page_id) {
1423 // Need to update the site instance immediately.
1424 site_instance->UpdateMaxPageID(max_restored_page_id);
1425
1426 // Also tell the renderer to update its internal representation. We
1427 // need to reserve enough IDs to make all restored page IDs less than
1428 // the max.
1429 if (curr_max_page_id < 0)
1430 curr_max_page_id = 0;
1431 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1432 }
1433 }
1434}
1435
1436void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541437 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471438 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321439 const ViewHostMsg_FrameNavigate_Params& params) {
1440 if (profile()->IsOffTheRecord())
1441 return;
1442
1443 // Add to history service.
1444 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1445 if (hs) {
1446 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541447 virtual_url != params.url) {
1448 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321449 // types of URLs, we will display a magic URL that is different from where
1450 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541451 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1452 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321453 // to sub-frames.
1454 std::vector<GURL> redirects = params.redirects;
1455 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541456 redirects.back() = virtual_url;
1457 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471458 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321459 } else {
1460 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471461 params.transition, params.redirects,
1462 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321463 }
1464 }
1465}
1466
1467bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1468 const std::wstring& title) {
1469 // For file URLs without a title, use the pathname instead. In the case of a
1470 // synthesized title, we don't want the update to count toward the "one set
1471 // per page of the title to history."
1472 std::wstring final_title;
1473 bool explicit_set;
1474 if (entry->url().SchemeIsFile() && title.empty()) {
1475 final_title = UTF8ToWide(entry->url().ExtractFileName());
1476 explicit_set = false; // Don't count synthetic titles toward the set limit.
1477 } else {
1478 TrimWhitespace(title, TRIM_ALL, &final_title);
1479 explicit_set = true;
1480 }
1481
1482 if (final_title == UTF16ToWideHack(entry->title()))
1483 return false; // Nothing changed, don't bother.
1484
1485 entry->set_title(WideToUTF16Hack(final_title));
1486
1487 // Update the history system for this page.
1488 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1489 HistoryService* hs =
1490 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1491 if (hs)
[email protected]ebe89e062009-08-13 23:16:541492 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321493
1494 // Don't allow the title to be saved again for explicitly set ones.
1495 received_page_title_ = explicit_set;
1496 }
1497
1498 // Lastly, set the title for the view.
1499 view_->SetPageTitle(final_title);
1500
1501 return true;
1502}
1503
1504void TabContents::NotifySwapped() {
1505 // After sending out a swap notification, we need to send a disconnect
1506 // notification so that clients that pick up a pointer to |this| can NULL the
1507 // pointer. See Bug 1230284.
1508 notify_disconnection_ = true;
1509 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341510 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221511 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321512 NotificationService::NoDetails());
1513}
1514
1515void TabContents::NotifyConnected() {
1516 notify_disconnection_ = true;
1517 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341518 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221519 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321520 NotificationService::NoDetails());
1521}
1522
1523void TabContents::NotifyDisconnected() {
1524 if (!notify_disconnection_)
1525 return;
1526
1527 notify_disconnection_ = false;
1528 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341529 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221530 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321531 NotificationService::NoDetails());
1532}
1533
1534void TabContents::GenerateKeywordIfNecessary(
1535 const ViewHostMsg_FrameNavigate_Params& params) {
1536 if (!params.searchable_form_url.is_valid())
1537 return;
1538
1539 if (profile()->IsOffTheRecord())
1540 return;
1541
1542 int last_index = controller_.last_committed_entry_index();
1543 // When there was no previous page, the last index will be 0. This is
1544 // normally due to a form submit that opened in a new tab.
1545 // TODO(brettw) bug 916126: we should support keywords when form submits
1546 // happen in new tabs.
1547 if (last_index <= 0)
1548 return;
1549 const NavigationEntry* previous_entry =
1550 controller_.GetEntryAtIndex(last_index - 1);
1551 if (IsFormSubmit(previous_entry)) {
1552 // Only generate a keyword if the previous page wasn't itself a form
1553 // submit.
1554 return;
1555 }
1556
1557 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1558 previous_entry->user_typed_url() : previous_entry->url();
1559 std::wstring keyword =
1560 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1561 if (keyword.empty())
1562 return;
1563
1564 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1565 if (!url_model)
1566 return;
1567
1568 if (!url_model->loaded()) {
1569 url_model->Load();
1570 return;
1571 }
1572
1573 const TemplateURL* current_url;
1574 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1575 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1576 return;
1577
1578 if (current_url) {
1579 if (current_url->originating_url().is_valid()) {
1580 // The existing keyword was generated from an OpenSearch description
1581 // document, don't regenerate.
1582 return;
1583 }
1584 url_model->Remove(current_url);
1585 }
1586 TemplateURL* new_url = new TemplateURL();
1587 new_url->set_keyword(keyword);
1588 new_url->set_short_name(keyword);
1589 new_url->SetURL(url, 0, 0);
1590 new_url->add_input_encoding(params.searchable_form_encoding);
1591 DCHECK(controller_.GetLastCommittedEntry());
1592 const GURL& favicon_url =
1593 controller_.GetLastCommittedEntry()->favicon().url();
1594 if (favicon_url.is_valid()) {
1595 new_url->SetFavIconURL(favicon_url);
1596 } else {
1597 // The favicon url isn't valid. This means there really isn't a favicon,
1598 // or the favicon url wasn't obtained before the load started. This assumes
1599 // the later.
1600 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1601 // its url.
1602 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1603 }
1604 new_url->set_safe_for_autoreplace(true);
1605 url_model->Add(new_url);
1606}
1607
[email protected]bf5c2ff392009-07-08 16:24:331608void TabContents::OnUserGesture() {
1609 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1610 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1611 if (drm)
1612 drm->OnUserGesture(this);
1613 controller_.OnUserGesture();
1614}
1615
1616void TabContents::OnFindReply(int request_id,
1617 int number_of_matches,
1618 const gfx::Rect& selection_rect,
1619 int active_match_ordinal,
1620 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421621 // Ignore responses for requests that have been aborted.
1622 if (find_op_aborted_)
1623 return;
1624
[email protected]bf5c2ff392009-07-08 16:24:331625 // Ignore responses for requests other than the one we have most recently
1626 // issued. That way we won't act on stale results when the user has
1627 // already typed in another query.
1628 if (request_id != current_find_request_id_)
1629 return;
1630
1631 if (number_of_matches == -1)
1632 number_of_matches = last_search_result_.number_of_matches();
1633 if (active_match_ordinal == -1)
1634 active_match_ordinal = last_search_result_.active_match_ordinal();
1635
1636 gfx::Rect selection = selection_rect;
1637 if (selection.IsEmpty())
1638 selection = last_search_result_.selection_rect();
1639
1640 // Notify the UI, automation and any other observers that a find result was
1641 // found.
1642 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1643 selection, active_match_ordinal,
1644 final_update);
1645 NotificationService::current()->Notify(
1646 NotificationType::FIND_RESULT_AVAILABLE,
1647 Source<TabContents>(this),
1648 Details<FindNotificationDetails>(&last_search_result_));
1649}
1650
1651void TabContents::GoToEntryAtOffset(int offset) {
1652 controller_.GoToOffset(offset);
1653}
1654
1655void TabContents::GetHistoryListCount(int* back_list_count,
1656 int* forward_list_count) {
1657 int current_index = controller_.last_committed_entry_index();
1658 *back_list_count = current_index;
1659 *forward_list_count = controller_.entry_count() - current_index - 1;
1660}
1661
1662void TabContents::OnMissingPluginStatus(int status) {
1663#if defined(OS_WIN)
1664// TODO(PORT): pull in when plug-ins work
1665 GetPluginInstaller()->OnMissingPluginStatus(status);
1666#endif
1667}
1668
1669void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331670 DCHECK(!plugin_path.value().empty());
1671
1672 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351673#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331674 scoped_ptr<FileVersionInfo> version_info(
1675 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1676 if (version_info.get()) {
1677 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371678 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331679 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371680#if defined(OS_MACOSX)
1681 // Many plugins on the Mac have .plugin in the actual name, which looks
1682 // terrible, so look for that and strip it off if present.
1683 const std::wstring plugin_extension(L".plugin");
1684 if (EndsWith(plugin_name, plugin_extension, true))
1685 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1686#endif // OS_MACOSX
1687 }
[email protected]bf5c2ff392009-07-08 16:24:331688 }
[email protected]4a560ed2009-07-13 23:35:261689#else
1690 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1691#endif
[email protected]bf5c2ff392009-07-08 16:24:331692 AddInfoBar(new SimpleAlertInfoBarDelegate(
1693 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
1694 NULL));
[email protected]bf5c2ff392009-07-08 16:24:331695}
1696
1697void TabContents::OnCrashedWorker() {
1698 AddInfoBar(new SimpleAlertInfoBarDelegate(
1699 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
1700 NULL));
1701}
1702
1703void TabContents::OnDidGetApplicationInfo(
1704 int32 page_id,
1705 const webkit_glue::WebApplicationInfo& info) {
1706 if (pending_install_.page_id != page_id)
1707 return; // The user clicked create on a separate page. Ignore this.
1708
1709 pending_install_.callback_functor =
1710 new GearsCreateShortcutCallbackFunctor(this);
1711 GearsCreateShortcut(
1712 info, pending_install_.title, pending_install_.url, pending_install_.icon,
1713 NewCallback(pending_install_.callback_functor,
1714 &GearsCreateShortcutCallbackFunctor::Run));
1715}
1716
1717void TabContents::DidStartProvisionalLoadForFrame(
1718 RenderViewHost* render_view_host,
1719 bool is_main_frame,
1720 const GURL& url) {
1721 ProvisionalLoadDetails details(is_main_frame,
1722 controller_.IsURLInPageNavigation(url),
1723 url, std::string(), false);
1724 NotificationService::current()->Notify(
1725 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1726 Source<NavigationController>(&controller_),
1727 Details<ProvisionalLoadDetails>(&details));
1728}
1729
1730void TabContents::DidStartReceivingResourceResponse(
1731 ResourceRequestDetails* details) {
1732 NotificationService::current()->Notify(
1733 NotificationType::RESOURCE_RESPONSE_STARTED,
1734 Source<NavigationController>(&controller()),
1735 Details<ResourceRequestDetails>(details));
1736}
1737
1738void TabContents::DidRedirectResource(ResourceRequestDetails* details) {
1739 NotificationService::current()->Notify(
1740 NotificationType::RESOURCE_RECEIVED_REDIRECT,
1741 Source<NavigationController>(&controller()),
1742 Details<ResourceRequestDetails>(details));
1743}
1744
1745void TabContents::DidLoadResourceFromMemoryCache(
1746 const GURL& url,
1747 const std::string& frame_origin,
1748 const std::string& main_frame_origin,
1749 const std::string& security_info) {
1750 // Send out a notification that we loaded a resource from our memory cache.
1751 int cert_id = 0, cert_status = 0, security_bits = 0;
1752 SSLManager::DeserializeSecurityInfo(security_info,
1753 &cert_id, &cert_status,
1754 &security_bits);
1755 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]76543b92009-08-31 17:27:451756 process()->id(), cert_id, cert_status);
[email protected]bf5c2ff392009-07-08 16:24:331757
1758 NotificationService::current()->Notify(
1759 NotificationType::LOAD_FROM_MEMORY_CACHE,
1760 Source<NavigationController>(&controller_),
1761 Details<LoadFromMemoryCacheDetails>(&details));
1762}
1763
1764void TabContents::DidFailProvisionalLoadWithError(
1765 RenderViewHost* render_view_host,
1766 bool is_main_frame,
1767 int error_code,
1768 const GURL& url,
1769 bool showing_repost_interstitial) {
1770 if (net::ERR_ABORTED == error_code) {
1771 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1772 // This means that the interstitial won't be torn down properly, which is
1773 // bad. But if we have an interstitial, go back to another tab type, and
1774 // then load the same interstitial again, we could end up getting the first
1775 // interstitial's "failed" message (as a result of the cancel) when we're on
1776 // the second one.
1777 //
1778 // We can't tell this apart, so we think we're tearing down the current page
1779 // which will cause a crash later one. There is also some code in
1780 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1781 // out because of this problem.
1782 //
1783 // http://code.google.com/p/chromium/issues/detail?id=2855
1784 // Because this will not tear down the interstitial properly, if "back" is
1785 // back to another tab type, the interstitial will still be somewhat alive
1786 // in the previous tab type. If you navigate somewhere that activates the
1787 // tab with the interstitial again, you'll see a flash before the new load
1788 // commits of the interstitial page.
1789 if (showing_interstitial_page()) {
1790 LOG(WARNING) << "Discarding message during interstitial.";
1791 return;
1792 }
1793
1794 // This will discard our pending entry if we cancelled the load (e.g., if we
1795 // decided to download the file instead of load it). Only discard the
1796 // pending entry if the URLs match, otherwise the user initiated a navigate
1797 // before the page loaded so that the discard would discard the wrong entry.
1798 NavigationEntry* pending_entry = controller_.pending_entry();
1799 if (pending_entry && pending_entry->url() == url) {
1800 controller_.DiscardNonCommittedEntries();
1801 // Update the URL display.
1802 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1803 }
1804
1805 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
1806 }
1807
1808 // Send out a notification that we failed a provisional load with an error.
1809 ProvisionalLoadDetails details(is_main_frame,
1810 controller_.IsURLInPageNavigation(url),
1811 url, std::string(), false);
1812 details.set_error_code(error_code);
1813
1814 NotificationService::current()->Notify(
1815 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1816 Source<NavigationController>(&controller_),
1817 Details<ProvisionalLoadDetails>(&details));
1818}
1819
1820void TabContents::DocumentLoadedInFrame() {
1821 controller_.DocumentLoadedInFrame();
1822}
1823
[email protected]8d3347f2009-07-09 22:00:211824RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:321825 return view_.get();
1826}
1827
[email protected]8d3347f2009-07-09 22:00:211828RenderViewHostDelegate::RendererManagement*
1829TabContents::GetRendererManagementDelegate() {
1830 return &render_manager_;
1831}
1832
[email protected]bf5c2ff392009-07-08 16:24:331833RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:211834 TabContents::GetBrowserIntegrationDelegate() {
1835 return this;
[email protected]bf5c2ff392009-07-08 16:24:331836}
1837
[email protected]8d3347f2009-07-09 22:00:211838RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
1839 return this;
[email protected]bf5c2ff392009-07-08 16:24:331840}
1841
[email protected]8d3347f2009-07-09 22:00:211842RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:321843 return save_package_.get(); // May be NULL, but we can return NULL.
1844}
1845
[email protected]8d3347f2009-07-09 22:00:211846RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
1847 return &printing_;
1848}
1849
1850RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
1851 return &fav_icon_helper_;
1852}
1853
1854RenderViewHostDelegate::Autofill* TabContents::GetAutofillDelegate() {
1855 if (autofill_manager_.get() == NULL)
1856 autofill_manager_.reset(new AutofillManager(this));
1857 return autofill_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:331858}
1859
[email protected]80d96fa2009-06-10 22:34:511860RendererPreferences TabContents::GetRendererPrefs() const {
[email protected]840b1512009-07-21 16:53:461861 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:511862}
1863
[email protected]57c6a652009-05-04 07:58:341864TabContents* TabContents::GetAsTabContents() {
1865 return this;
1866}
1867
[email protected]3e7cf1362009-08-21 17:47:081868void TabContents::AddBlockedNotice(const GURL& url, const string16& reason) {
1869 CreateBlockedPopupContainerIfNecessary();
1870 blocked_popups_->AddBlockedNotice(url, reason);
1871}
1872
[email protected]7b291f92009-08-14 05:43:531873ViewType::Type TabContents::GetRenderViewType() const {
1874 return ViewType::TAB_CONTENTS;
1875}
1876
1877int TabContents::GetBrowserWindowID() const {
1878 return controller().window_id().id();
1879}
1880
[email protected]420ae012009-04-24 05:16:321881void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:061882 NotificationService::current()->Notify(
1883 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
1884 Source<TabContents>(this),
1885 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:321886 NavigationEntry* entry = controller_.GetActiveEntry();
1887 if (!entry)
1888 return;
1889
1890 // When we're creating views, we're still doing initial setup, so we always
1891 // use the pending DOM UI rather than any possibly existing committed one.
1892 if (render_manager_.pending_dom_ui()) {
1893 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
1894 }
1895
1896 if (entry->IsViewSourceMode()) {
1897 // Put the renderer in view source mode.
1898 render_view_host->Send(
1899 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
1900 }
[email protected]0666aef2009-05-13 19:48:081901
1902 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:321903}
1904
1905void TabContents::RenderViewReady(RenderViewHost* rvh) {
1906 if (rvh != render_view_host()) {
1907 // Don't notify the world, since this came from a renderer in the
1908 // background.
1909 return;
1910 }
1911
1912 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:301913 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:321914 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:301915
1916 // Restore the focus to the tab (otherwise the focus will be on the top
1917 // window).
1918 if (was_crashed && !FocusLocationBarByDefault())
1919 Focus();
[email protected]420ae012009-04-24 05:16:321920}
1921
1922void TabContents::RenderViewGone(RenderViewHost* rvh) {
1923 // Ask the print preview if this renderer was valuable.
1924 if (!printing_.OnRenderViewGone(rvh))
1925 return;
1926 if (rvh != render_view_host()) {
1927 // The pending page's RenderViewHost is gone.
1928 return;
1929 }
1930
1931 SetIsLoading(false, NULL);
1932 NotifyDisconnected();
1933 SetIsCrashed(true);
1934
[email protected]8e537302009-06-10 21:19:581935 // Tell the view that we've crashed so it can prepare the sad tab page.
1936 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:321937
1938 // Hide any visible hung renderer warning for this web contents' process.
[email protected]d82ed61e2009-06-16 02:46:221939 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:321940}
1941
[email protected]2e4633c2009-07-09 16:58:061942void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
1943 NotificationService::current()->Notify(
1944 NotificationType::RENDER_VIEW_HOST_DELETED,
1945 Source<TabContents>(this),
1946 Details<RenderViewHost>(rvh));
1947}
1948
[email protected]420ae012009-04-24 05:16:321949void TabContents::DidNavigate(RenderViewHost* rvh,
1950 const ViewHostMsg_FrameNavigate_Params& params) {
1951 if (PageTransition::IsMainFrame(params.transition))
1952 render_manager_.DidNavigateMainFrame(rvh);
1953
1954 // Update the site of the SiteInstance if it doesn't have one yet.
1955 if (!GetSiteInstance()->has_site())
1956 GetSiteInstance()->SetSite(params.url);
1957
1958 // Need to update MIME type here because it's referred to in
1959 // UpdateNavigationCommands() called by RendererDidNavigate() to
1960 // determine whether or not to enable the encoding menu.
1961 // It's updated only for the main frame. For a subframe,
1962 // RenderView::UpdateURL does not set params.contents_mime_type.
1963 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
1964 // TODO(jungshik): Add a test for the encoding menu to avoid
1965 // regressing it again.
1966 if (PageTransition::IsMainFrame(params.transition))
1967 contents_mime_type_ = params.contents_mime_type;
1968
1969 NavigationController::LoadCommittedDetails details;
[email protected]3e90d4a2009-07-03 17:38:391970 bool did_navigate = controller_.RendererDidNavigate(params, &details);
1971
1972 // Update history. Note that this needs to happen after the entry is complete,
1973 // which WillNavigate[Main,Sub]Frame will do before this function is called.
1974 if (params.should_update_history) {
1975 // Most of the time, the displayURL matches the loaded URL, but for about:
1976 // URLs, we use a data: URL as the real value. We actually want to save
1977 // the about: URL to the history db and keep the data: URL hidden. This is
1978 // what the TabContents' URL getter does.
1979 UpdateHistoryForNavigation(GetURL(), details, params);
1980 }
1981
[email protected]76543b92009-08-31 17:27:451982 if (!did_navigate)
1983 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:321984
1985 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
1986 // for the appropriate notification (best) or you can add it to
1987 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
1988 // necessary, please).
1989
1990 // Run post-commit tasks.
1991 if (details.is_main_frame)
1992 DidNavigateMainFramePostCommit(details, params);
1993 DidNavigateAnyFramePostCommit(rvh, details, params);
1994}
1995
1996void TabContents::UpdateState(RenderViewHost* rvh,
1997 int32 page_id,
1998 const std::string& state) {
1999 DCHECK(rvh == render_view_host());
2000
2001 // We must be prepared to handle state updates for any page, these occur
2002 // when the user is scrolling and entering form data, as well as when we're
2003 // leaving a page, in which case our state may have already been moved to
2004 // the next page. The navigation controller will look up the appropriate
2005 // NavigationEntry and update it when it is notified via the delegate.
2006
2007 int entry_index = controller_.GetEntryIndexWithPageID(
2008 GetSiteInstance(), page_id);
2009 if (entry_index < 0)
2010 return;
2011 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2012
2013 if (state == entry->content_state())
2014 return; // Nothing to update.
2015 entry->set_content_state(state);
2016 controller_.NotifyEntryChanged(entry, entry_index);
2017}
2018
2019void TabContents::UpdateTitle(RenderViewHost* rvh,
2020 int32 page_id, const std::wstring& title) {
2021 // If we have a title, that's a pretty good indication that we've started
2022 // getting useful data.
2023 SetNotWaitingForResponse();
2024
2025 DCHECK(rvh == render_view_host());
2026 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2027 page_id);
2028 if (!entry || !UpdateTitleForEntry(entry, title))
2029 return;
2030
2031 // Broadcast notifications when the UI should be updated.
2032 if (entry == controller_.GetEntryAtOffset(0))
[email protected]c9cd2222009-05-06 05:16:502033 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322034}
2035
[email protected]420ae012009-04-24 05:16:322036void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402037 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322038 set_encoding(encoding);
2039}
2040
2041void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2042 if (delegate())
2043 delegate()->UpdateTargetURL(this, url);
2044}
2045
2046void TabContents::UpdateThumbnail(const GURL& url,
2047 const SkBitmap& bitmap,
2048 const ThumbnailScore& score) {
2049 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282050 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492051 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192052 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2053 score, true);
[email protected]449478302009-06-09 20:04:282054 } else {
2055 HistoryService* hs;
2056 if (!profile()->IsOffTheRecord() &&
2057 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2058 hs->SetPageThumbnail(url, bitmap, score);
2059 }
[email protected]420ae012009-04-24 05:16:322060 }
2061}
2062
[email protected]0df30122009-06-03 12:13:082063void TabContents::UpdateInspectorSettings(const std::wstring& raw_settings) {
2064 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
2065 raw_settings);
2066}
2067
[email protected]420ae012009-04-24 05:16:322068void TabContents::Close(RenderViewHost* rvh) {
[email protected]24a4d1062009-07-10 23:10:422069 // If we close the tab while we're in the middle of a drag, we'll crash.
2070 // Instead, cancel the drag and close it as soon as the drag ends.
2071 if (view()->IsDoingDrag()) {
2072 view()->CancelDragAndCloseTab();
2073 return;
2074 }
2075
[email protected]420ae012009-04-24 05:16:322076 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2077 if (delegate() && rvh == render_view_host())
2078 delegate()->CloseContents(this);
2079}
2080
2081void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2082 if (delegate() && delegate()->IsPopup(this))
2083 delegate()->MoveContents(this, new_bounds);
2084}
2085
[email protected]329581b2009-04-28 06:52:352086void TabContents::DidStartLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322087 SetIsLoading(true, NULL);
2088}
2089
[email protected]329581b2009-04-28 06:52:352090void TabContents::DidStopLoading(RenderViewHost* rvh) {
[email protected]420ae012009-04-24 05:16:322091 scoped_ptr<LoadNotificationDetails> details;
2092
2093 NavigationEntry* entry = controller_.GetActiveEntry();
2094 // An entry may not exist for a stop when loading an initial blank page or
2095 // if an iframe injected by script into a blank page finishes loading.
2096 if (entry) {
2097 scoped_ptr<base::ProcessMetrics> metrics(
2098 base::ProcessMetrics::CreateProcessMetrics(
2099 process()->process().handle()));
2100
2101 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2102
2103 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542104 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322105 entry->transition_type(),
2106 elapsed,
2107 &controller_,
2108 controller_.GetCurrentEntryIndex()));
2109 }
2110
2111 // Tell PasswordManager we've finished a page load, which serves as a
2112 // green light to save pending passwords and reset itself.
2113 GetPasswordManager()->DidStopLoading();
2114
2115 SetIsLoading(false, details.get());
2116}
2117
[email protected]420ae012009-04-24 05:16:322118void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2119 const GURL& source_url,
2120 const GURL& target_url) {
2121 NavigationEntry* entry;
2122 if (page_id == -1)
2123 entry = controller_.pending_entry();
2124 else
2125 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2126 if (!entry || entry->url() != source_url)
2127 return;
2128 entry->set_url(target_url);
2129}
2130
[email protected]420ae012009-04-24 05:16:322131void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2132 WindowOpenDisposition disposition) {
2133 if (render_manager_.dom_ui()) {
2134 // When we're a DOM UI, it will provide a page transition type for us (this
2135 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2136 // generated suggestions).
2137 //
2138 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162139 // want web sites to see a referrer of "chrome://blah" (and some
2140 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322141 // send to the site), so we send no referrer.
2142 OpenURL(url, GURL(), disposition,
2143 render_manager_.dom_ui()->link_transition_type());
2144 } else {
2145 OpenURL(url, referrer, disposition, PageTransition::LINK);
2146 }
2147}
2148
[email protected]1ee614862009-07-06 20:29:182149void TabContents::DomOperationResponse(const std::string& json_string,
2150 int automation_id) {
2151}
2152
[email protected]420ae012009-04-24 05:16:322153void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]811bfe32009-07-01 08:46:252154 const std::string& content,
2155 int request_id,
2156 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322157 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442158 // This can happen if someone uses window.open() to open an extension URL
2159 // from a non-extension context.
2160 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322161 return;
2162 }
[email protected]811bfe32009-07-01 08:46:252163 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, request_id,
2164 has_callback);
[email protected]420ae012009-04-24 05:16:322165}
2166
2167void TabContents::ProcessExternalHostMessage(const std::string& message,
2168 const std::string& origin,
2169 const std::string& target) {
2170 if (delegate())
2171 delegate()->ForwardMessageToExternalHost(message, origin, target);
2172}
2173
[email protected]420ae012009-04-24 05:16:322174void TabContents::RunFileChooser(bool multiple_files,
2175 const string16& title,
2176 const FilePath& default_file) {
2177 if (!select_file_dialog_.get())
2178 select_file_dialog_ = SelectFileDialog::Create(this);
2179 SelectFileDialog::Type dialog_type =
2180 multiple_files ? SelectFileDialog::SELECT_OPEN_MULTI_FILE :
2181 SelectFileDialog::SELECT_OPEN_FILE;
2182 select_file_dialog_->SelectFile(dialog_type, title, default_file,
2183 NULL, 0, FILE_PATH_LITERAL(""),
2184 view_->GetTopLevelNativeWindow(), NULL);
2185}
2186
2187void TabContents::RunJavaScriptMessage(
2188 const std::wstring& message,
2189 const std::wstring& default_prompt,
2190 const GURL& frame_url,
2191 const int flags,
2192 IPC::Message* reply_msg,
2193 bool* did_suppress_message) {
2194 // Suppress javascript messages when requested and when inside a constrained
2195 // popup window (because that activates them and breaks them out of the
2196 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552197 // Also suppress messages when showing an interstitial. The interstitial is
2198 // shown over the previous page, we don't want the hidden page dialogs to
2199 // interfere with the interstitial.
2200 bool suppress_this_message = suppress_javascript_messages_ ||
2201 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322202 if (delegate())
2203 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312204 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322205
2206 *did_suppress_message = suppress_this_message;
2207
2208 if (!suppress_this_message) {
2209 base::TimeDelta time_since_last_message(
2210 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2211 bool show_suppress_checkbox = false;
2212 // Show a checkbox offering to suppress further messages if this message is
2213 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2214 if (time_since_last_message <
2215 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2216 show_suppress_checkbox = true;
2217
[email protected]d82ed61e2009-06-16 02:46:222218 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322219 show_suppress_checkbox, reply_msg);
2220 } else {
2221 // If we are suppressing messages, just reply as is if the user immediately
2222 // pressed "Cancel".
2223 OnJavaScriptMessageBoxClosed(reply_msg, false, std::wstring());
2224 }
2225}
2226
2227void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2228 IPC::Message* reply_msg) {
[email protected]d82ed61e2009-06-16 02:46:222229 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322230}
2231
2232void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2233 const std::string& json_arguments,
2234 IPC::Message* reply_msg) {
2235 if (delegate()) {
2236 HtmlDialogUIDelegate* dialog_delegate =
2237 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222238 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322239 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2240 }
2241}
2242
2243void TabContents::PasswordFormsSeen(
[email protected]ed3fb032009-06-16 19:50:562244 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]420ae012009-04-24 05:16:322245 GetPasswordManager()->PasswordFormsSeen(forms);
2246}
2247
[email protected]420ae012009-04-24 05:16:322248// Checks to see if we should generate a keyword based on the OSDD, and if
2249// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2250void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2251 int32 page_id, const GURL& url,
2252 bool autodetected) {
2253 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2254 DCHECK(url.is_valid());
2255 if (!IsActiveEntry(page_id))
2256 return;
2257 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2258 if (!url_model)
2259 return;
2260 if (!url_model->loaded()) {
2261 url_model->Load();
2262 return;
2263 }
2264 if (!profile()->GetTemplateURLFetcher())
2265 return;
2266
2267 if (profile()->IsOffTheRecord())
2268 return;
2269
2270 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2271 DCHECK(entry);
2272
2273 const NavigationEntry* base_entry = entry;
2274 if (IsFormSubmit(base_entry)) {
2275 // If the current page is a form submit, find the last page that was not
2276 // a form submit and use its url to generate the keyword from.
2277 int index = controller_.last_committed_entry_index() - 1;
2278 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2279 index--;
2280 if (index >= 0)
2281 base_entry = controller_.GetEntryAtIndex(index);
2282 else
2283 base_entry = NULL;
2284 }
2285
2286 // We want to use the user typed URL if available since that represents what
2287 // the user typed to get here, and fall back on the regular URL if not.
2288 if (!base_entry)
2289 return;
2290 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2291 base_entry->user_typed_url() : base_entry->url();
2292 if (!keyword_url.is_valid())
2293 return;
2294 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2295 autodetected);
2296 if (keyword.empty())
2297 return;
2298 const TemplateURL* template_url =
2299 url_model->GetTemplateURLForKeyword(keyword);
2300 if (template_url && (!template_url->safe_for_autoreplace() ||
2301 template_url->originating_url() == url)) {
2302 // Either there is a user created TemplateURL for this keyword, or the
2303 // keyword has the same OSDD url and we've parsed it.
2304 return;
2305 }
2306
2307 // Download the OpenSearch description document. If this is successful a
2308 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322309 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2310 keyword,
2311 url,
2312 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162313 this,
[email protected]420ae012009-04-24 05:16:322314 autodetected);
2315}
2316
[email protected]420ae012009-04-24 05:16:322317GURL TabContents::GetAlternateErrorPageURL() const {
2318 GURL url;
2319 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2320 if (profile()->IsOffTheRecord())
2321 return url;
2322
2323 PrefService* prefs = profile()->GetPrefs();
2324 DCHECK(prefs);
2325 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]2bd6ca1c2009-08-27 16:42:202326 url = google_util::AppendGoogleLocaleParam(GURL(kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322327 url = google_util::AppendGoogleTLDParam(url);
2328 }
2329 return url;
2330}
2331
2332WebPreferences TabContents::GetWebkitPrefs() {
2333 PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
[email protected]7ccddb8c2009-08-04 17:36:552334 bool is_dom_ui = false;
2335 return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322336}
2337
[email protected]420ae012009-04-24 05:16:322338void TabContents::OnJSOutOfMemory() {
2339 AddInfoBar(new SimpleAlertInfoBarDelegate(
2340 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL));
2341}
2342
[email protected]420ae012009-04-24 05:16:322343void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2344 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342345 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322346 // delivered to a pending RenderViewHost. We must first run the onunload
2347 // handler of the old RenderViewHost before we can allow it to proceed.
2348 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2349 new_request_id);
2350}
2351
2352bool TabContents::CanBlur() const {
2353 return delegate() ? delegate()->CanBlur() : true;
2354}
2355
2356gfx::Rect TabContents::GetRootWindowResizerRect() const {
2357 if (delegate())
2358 return delegate()->GetRootWindowResizerRect();
2359 return gfx::Rect();
2360}
2361
2362void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2363 bool is_during_unload) {
2364 if (is_during_unload) {
2365 // Hang occurred while firing the beforeunload/unload handler.
2366 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112367 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322368
2369 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2370 return;
2371
2372 // If the tab hangs in the beforeunload/unload handler there's really
2373 // nothing we can do to recover. Pretend the unload listeners have
2374 // all fired and close the tab. If the hang is in the beforeunload handler
2375 // then the user will not have the option of cancelling the close.
2376 Close(rvh);
2377 return;
2378 }
2379
2380 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]d82ed61e2009-06-16 02:46:222381 HungRendererDialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322382}
2383
2384void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]d82ed61e2009-06-16 02:46:222385 HungRendererDialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322386}
2387
2388void TabContents::LoadStateChanged(const GURL& url,
2389 net::LoadState load_state) {
2390 load_state_ = load_state;
[email protected]d686e812009-06-03 19:10:292391 std::wstring languages =
2392 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
2393 load_state_host_.clear();
2394 std::string host = url.host();
2395 net::IDNToUnicode(host.c_str(), host.size(), languages, &load_state_host_);
[email protected]420ae012009-04-24 05:16:322396 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2397 SetNotWaitingForResponse();
2398 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502399 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322400}
2401
[email protected]1ee614862009-07-06 20:29:182402bool TabContents::IsExternalTabContainer() const {
2403 if (!delegate())
2404 return false;
2405
2406 return delegate()->IsExternalTabContainer();
2407}
2408
[email protected]1ee614862009-07-06 20:29:182409void TabContents::DidInsertCSS() {
2410 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322411}
2412
2413void TabContents::FileSelected(const FilePath& path,
2414 int index, void* params) {
2415 render_view_host()->FileSelected(path);
2416}
2417
2418void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2419 void* params) {
2420 render_view_host()->MultiFilesSelected(files);
2421}
2422
2423void TabContents::FileSelectionCanceled(void* params) {
2424 // If the user cancels choosing a file to upload we pass back an
2425 // empty vector.
2426 render_view_host()->MultiFilesSelected(std::vector<FilePath>());
2427}
2428
2429void TabContents::BeforeUnloadFiredFromRenderManager(
2430 bool proceed,
2431 bool* proceed_to_fire_unload) {
2432 if (delegate())
2433 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2434}
2435
2436void TabContents::UpdateRenderViewSizeForRenderManager() {
2437 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
2438 view_->SizeContents(view_->GetContainerSize());
2439}
2440
2441DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222442 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322443}
2444
2445NavigationEntry*
2446TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2447 return controller_.GetLastCommittedEntry();
2448}
2449
2450bool TabContents::CreateRenderViewForRenderManager(
2451 RenderViewHost* render_view_host) {
[email protected]811bfe32009-07-01 08:46:252452 // If the pending navigation is to a DOMUI, tell the RenderView about any
2453 // bindings it will need enabled.
[email protected]420ae012009-04-24 05:16:322454 if (render_manager_.pending_dom_ui())
[email protected]811bfe32009-07-01 08:46:252455 render_view_host->AllowBindings(
2456 render_manager_.pending_dom_ui()->bindings());
[email protected]1adff062009-06-02 18:39:552457
[email protected]420ae012009-04-24 05:16:322458 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
2459 if (!render_view_host->CreateRenderView())
2460 return false;
2461
2462 // Now that the RenderView has been created, we need to tell it its size.
2463 rwh_view->SetSize(view_->GetContainerSize());
2464
2465 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2466 render_view_host);
2467 return true;
2468}
2469
2470void TabContents::Observe(NotificationType type,
2471 const NotificationSource& source,
2472 const NotificationDetails& details) {
2473 switch (type.value) {
2474 case NotificationType::BOOKMARK_MODEL_LOADED:
2475 // BookmarkModel finished loading, fall through to update starred state.
2476 case NotificationType::URLS_STARRED: {
2477 // Somewhere, a URL has been starred.
2478 // Ignore notifications for profiles other than our current one.
2479 Profile* source_profile = Source<Profile>(source).ptr();
2480 if (!source_profile || !source_profile->IsSameProfile(profile()))
2481 return;
2482
2483 UpdateStarredStateForCurrentURL();
2484 break;
2485 }
2486 case NotificationType::PREF_CHANGED: {
2487 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2488 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2489 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2490 UpdateAlternateErrorPageURL();
2491 } else if (*pref_name_in == prefs::kDefaultCharset ||
2492 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2493 ) {
2494 UpdateWebPreferences();
2495 } else {
2496 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2497 }
2498 break;
2499 }
2500 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2501 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2502 break;
2503
2504 case NotificationType::NAV_ENTRY_COMMITTED: {
2505 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2506
2507 NavigationController::LoadCommittedDetails& committed_details =
2508 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2509 ExpireInfoBars(committed_details);
2510 break;
2511 }
2512
[email protected]d3ba77272009-09-03 00:06:092513#if defined(OS_LINUX)
2514 case NotificationType::BROWSER_THEME_CHANGED: {
2515 render_view_host()->SyncRendererPrefs();
2516 break;
2517 }
2518#endif
2519
[email protected]420ae012009-04-24 05:16:322520 default:
2521 NOTREACHED();
2522 }
2523}
[email protected]aacd7cc2009-09-02 14:51:102524
[email protected]41fc0322009-09-04 22:23:402525void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102526 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2527}
2528