blob: 18050bf68c3785d26668d5400d7337c729cd463a [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]06821f42d2010-05-03 22:34:357#if defined(OS_CHROMEOS)
8// For GdkScreen
9#include <gdk/gdk.h>
10#endif // defined(OS_CHROMEOS)
11
[email protected]a92b8642009-05-05 23:38:5612#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]420ae012009-04-24 05:16:3218#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5419#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3720#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5421#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4522#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2123#include "chrome/browser/autofill/autofill_manager.h"
[email protected]66ba4932009-06-04 19:22:1324#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3225#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]9155324b2010-08-02 18:24:5326#include "chrome/browser/browser.h"
[email protected]96d185d2009-04-24 03:28:5427#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5528#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1030#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5431#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3232#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/dom_ui/dom_ui.h"
34#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0235#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0137#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4938#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0839#include "chrome/browser/extensions/extensions_service.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4841#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5342#include "chrome/browser/find_bar_state.h"
[email protected]420ae012009-04-24 05:16:3243#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2544#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2645#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1446#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3247#include "chrome/browser/load_from_memory_cache_details.h"
48#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4449#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0550#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1051#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5752#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2453#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5754#include "chrome/browser/plugin_installer.h"
[email protected]8e0bbf12010-07-20 00:03:4355#include "chrome/browser/popup_blocked_animation.h"
[email protected]052313b2010-02-19 09:43:0856#include "chrome/browser/pref_service.h"
[email protected]12802702010-07-09 19:43:0957#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4458#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0759#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1660#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5461#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3762#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0763#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5464#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3265#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1666#include "chrome/browser/search_engines/template_url_fetcher.h"
67#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1768#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1769#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5470#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1671#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4372#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1673#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4974#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5775#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0276#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1677#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5878#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2779#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4980#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5781#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1482#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0983#include "chrome/common/extensions/url_pattern.h"
84#include "chrome/common/navigation_types.h"
85#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5686#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2987#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3288#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1889#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5490#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3791#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2692#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3293#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0694#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3795#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3296#include "net/base/mime_util.h"
97#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2998#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3299#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18100#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03101#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00102
[email protected]420ae012009-04-24 05:16:32103// Cross-Site Navigations
104//
105// If a TabContents is told to navigate to a different web site (as determined
106// by SiteInstance), it will replace its current RenderViewHost with a new
107// RenderViewHost dedicated to the new SiteInstance. This works as follows:
108//
109// - Navigate determines whether the destination is cross-site, and if so,
110// it creates a pending_render_view_host_ and moves into the PENDING
111// RendererState.
112// - The pending RVH is "suspended," so that no navigation messages are sent to
113// its renderer until the onbeforeunload JavaScript handler has a chance to
114// run in the current RVH.
115// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
116// that it has a pending cross-site request. ResourceDispatcherHost will
117// check for this when the response arrives.
118// - The current RVH runs its onbeforeunload handler. If it returns false, we
119// cancel all the pending logic and go back to NORMAL. Otherwise we allow
120// the pending RVH to send the navigation request to its renderer.
121// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
122// checks CrossSiteRequestManager to see that the RVH responsible has a
123// pending cross-site request, and then installs a CrossSiteEventHandler.
124// - When RDH receives a response, the BufferedEventHandler determines whether
125// it is a download. If so, it sends a message to the new renderer causing
126// it to cancel the request, and the download proceeds in the download
127// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34128// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32129// doesn't affect any functionality.
130// - After RDH receives a response and determines that it is safe and not a
131// download, it pauses the response to first run the old page's onunload
132// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34133// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32134// to the current RVH.
135// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
136// the ResourceDispatcherHost, who unpauses the response. Data is then sent
137// to the pending RVH.
138// - The pending renderer sends a FrameNavigate message that invokes the
139// DidNavigate method. This replaces the current RVH with the
140// pending RVH and goes back to the NORMAL RendererState.
141
142namespace {
143
144// Amount of time we wait between when a key event is received and the renderer
145// is queried for its state and pushed to the NavigationEntry.
146const int kQueryStateDelay = 5000;
147
148const int kSyncWaitDelay = 40;
149
[email protected]304f8792009-08-19 21:28:09150#if defined(OS_CHROMEOS)
151// If a popup window is bigger than this fraction of the screen on chrome os,
152// turn it into a tab
153const float kMaxWidthFactor = 0.5;
154const float kMaxHeightFactor = 0.6;
155#endif
156
[email protected]420ae012009-04-24 05:16:32157// If another javascript message box is displayed within
158// kJavascriptMessageExpectedDelay of a previous javascript message box being
159// dismissed, display an option to suppress future message boxes from this
160// contents.
161const int kJavascriptMessageExpectedDelay = 1000;
162
[email protected]420ae012009-04-24 05:16:32163// The list of prefs we want to observe.
164const wchar_t* kPrefsToObserve[] = {
165 prefs::kAlternateErrorPagesEnabled,
166 prefs::kWebKitJavaEnabled,
167 prefs::kWebKitJavascriptEnabled,
168 prefs::kWebKitLoadsImagesAutomatically,
169 prefs::kWebKitPluginsEnabled,
170 prefs::kWebKitUsesUniversalDetector,
171 prefs::kWebKitSerifFontFamily,
172 prefs::kWebKitSansSerifFontFamily,
173 prefs::kWebKitFixedFontFamily,
174 prefs::kWebKitDefaultFontSize,
175 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36176 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32177 prefs::kDefaultCharset
178 // kWebKitStandardFontIsSerif needs to be added
179 // if we let users pick which font to use, serif or sans-serif when
180 // no font is specified or a CSS generic family (serif or sans-serif)
181 // is not specified.
182};
183
184const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
185
[email protected]420ae012009-04-24 05:16:32186// Returns true if the entry's transition type is FORM_SUBMIT.
187bool IsFormSubmit(const NavigationEntry* entry) {
188 return (PageTransition::StripQualifier(entry->transition_type()) ==
189 PageTransition::FORM_SUBMIT);
190}
191
192#if defined(OS_WIN)
193
194BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
195 // Note: erase is required to properly paint some widgets borders. This can
196 // be seen with textfields.
197 InvalidateRect(hwnd, NULL, TRUE);
198 return TRUE;
199}
200#endif
201
[email protected]5e369672009-11-03 23:48:30202ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16203 Profile* profile, const NavigationEntry& entry,
204 NavigationController::ReloadType reload_type) {
205 switch (reload_type) {
206 case NavigationController::RELOAD:
207 return ViewMsg_Navigate_Params::RELOAD;
208 case NavigationController::RELOAD_IGNORING_CACHE:
209 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
210 case NavigationController::NO_RELOAD:
211 break; // Fall through to rest of function.
212 }
[email protected]5e369672009-11-03 23:48:30213
214 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
215 profile->DidLastSessionExitCleanly())
216 return ViewMsg_Navigate_Params::RESTORE;
217
218 return ViewMsg_Navigate_Params::NORMAL;
219}
220
[email protected]3cc72b12010-03-18 23:03:00221void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16222 NavigationController::ReloadType reload_type,
223 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00224 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34225 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00226 params->pending_history_list_offset = controller.pending_entry_index();
227 params->current_history_list_offset = controller.last_committed_entry_index();
228 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34229 params->url = entry.url();
230 params->referrer = entry.referrer();
231 params->transition = entry.transition_type();
232 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00233 params->navigation_type =
234 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34235 params->request_time = base::Time::Now();
236}
237
[email protected]420ae012009-04-24 05:16:32238} // namespace
239
240// -----------------------------------------------------------------------------
241
[email protected]fdd61c62009-04-22 19:22:57242// static
243int TabContents::find_request_id_counter_ = -1;
244
[email protected]420ae012009-04-24 05:16:32245
[email protected]420ae012009-04-24 05:16:32246TabContents::TabContents(Profile* profile,
247 SiteInstance* site_instance,
248 int routing_id,
[email protected]34ac70502009-09-25 17:07:23249 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42250 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13251 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
252 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22253 TabContentsView::Create(this))),
254 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57255 property_bag_(),
256 registrar_(),
[email protected]12802702010-07-09 19:43:09257 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
258 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57259 save_package_(),
[email protected]6db0def92010-03-02 19:55:45260 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21261 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57262 password_manager_(),
263 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06264 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22265 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57266 select_file_dialog_(),
[email protected]d5f942ba2008-09-26 19:30:34267 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29268 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34269 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34270 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57271 current_load_start_(),
272 load_state_(net::LOAD_STATE_IDLE),
273 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56274 upload_size_(0),
275 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57276 received_page_title_(false),
277 is_starred_(false),
278 contents_mime_type_(),
279 encoding_(),
[email protected]332af7732009-03-11 13:21:35280 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49281 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47282 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57283 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57284 find_ui_active_(false),
285 find_op_aborted_(false),
286 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12287 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12288 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08289 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57290 capturing_contents_(false),
291 is_being_destroyed_(false),
292 notify_disconnection_(false),
293 history_requests_(),
294#if defined(OS_WIN)
295 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
296#endif
297 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44298 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01299 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54300 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54301 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16302 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38303 closed_by_user_gesture_(false),
304 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54305 renderer_preferences_util::UpdateFromSystemSettings(
306 &renderer_preferences_, profile);
307
[email protected]9fb83e82010-07-02 18:24:55308 content_settings_delegate_.reset(
309 new TabSpecificContentSettings(this, profile));
310
[email protected]16779842009-07-08 23:45:29311#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02312 // Make sure the thumbnailer is started before starting the render manager.
313 // The thumbnailer will want to listen for RVH creations, one of which will
314 // happen in RVHManager::Init.
315 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
316 if (generator)
317 generator->StartThumbnailing();
318#endif
319
[email protected]12636df2009-09-28 22:32:21320 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32321
[email protected]34ac70502009-09-25 17:07:23322 // We have the initial size of the view be based on the size of the passed in
323 // tab contents (normally a tab from the same window).
324 view_->CreateView(base_tab_contents ?
325 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32326
327 // Register for notifications about all interested prefs change.
328 PrefService* prefs = profile->GetPrefs();
329 if (prefs) {
330 for (int i = 0; i < kPrefsToObserveLength; ++i)
331 prefs->AddPrefObserver(kPrefsToObserve[i], this);
332 }
333
334 // Register for notifications about URL starredness changing on any profile.
335 registrar_.Add(this, NotificationType::URLS_STARRED,
336 NotificationService::AllSources());
337 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
338 NotificationService::AllSources());
339 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
340 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09341#if defined(OS_LINUX)
342 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
343 NotificationService::AllSources());
344#endif
[email protected]420ae012009-04-24 05:16:32345
[email protected]6c32ce72010-03-08 05:18:06346 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
347 NotificationService::AllSources());
348
[email protected]79580c62010-02-02 02:36:25349 // Register for notifications about content setting changes.
350 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
351 NotificationService::AllSources());
352
[email protected]a888b29e62010-04-01 13:38:57353 // Listen for extension changes so we can update extension_for_current_page_.
354 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
355 NotificationService::AllSources());
356 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
357 NotificationService::AllSources());
358 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
359 NotificationService::AllSources());
360
[email protected]c8865482009-07-23 20:40:10361 // Set-up the showing of the omnibox search infobar if applicable.
362 if (OmniboxSearchHint::IsEnabled(profile))
363 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35364}
initial.commit09911bf2008-07-26 23:55:29365
366TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32367 is_being_destroyed_ = true;
368
[email protected]bfe4c1582009-10-02 18:11:09369 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32370 registrar_.RemoveAll();
371
372 // Unregister the notifications of all observed prefs change.
373 PrefService* prefs = profile()->GetPrefs();
374 if (prefs) {
375 for (int i = 0; i < kPrefsToObserveLength; ++i)
376 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
377 }
378
[email protected]420ae012009-04-24 05:16:32379 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00380 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32381
[email protected]420ae012009-04-24 05:16:32382 // First cleanly close all child windows.
383 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
384 // some of these to close. CloseWindows is async, so it might get called
385 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49386 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32387
[email protected]8cc8d492010-02-02 10:40:49388 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13389 if (blocked_popups_)
390 blocked_popups_->Destroy();
391
[email protected]420ae012009-04-24 05:16:32392 // Notify any observer that have a reference on this tab contents.
393 NotificationService::current()->Notify(
394 NotificationType::TAB_CONTENTS_DESTROYED,
395 Source<TabContents>(this),
396 NotificationService::NoDetails());
397
[email protected]1e5e74f2009-05-27 20:55:12398 // Notify any lasting InfobarDelegates that have not yet been removed that
399 // whatever infobar they were handling in this TabContents has closed,
400 // because the TabContents is going away entirely.
401 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
402 // notification may trigger infobars calls that access their delegate. (and
403 // some implementations of InfoBarDelegate do delete themselves on
404 // InfoBarClosed()).
405 for (int i = 0; i < infobar_delegate_count(); ++i) {
406 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
407 delegate->InfoBarClosed();
408 }
409 infobar_delegates_.clear();
410
[email protected]420ae012009-04-24 05:16:32411 // TODO(brettw) this should be moved to the view.
412#if defined(OS_WIN)
413 // If we still have a window handle, destroy it. GetNativeView can return
414 // NULL if this contents was part of a window that closed.
415 if (GetNativeView())
416 ::DestroyWindow(GetNativeView());
417#endif
[email protected]7ab1e7d62009-10-14 23:32:01418
419 // OnCloseStarted isn't called in unit tests.
420 if (!tab_close_start_time_.is_null()) {
421 UMA_HISTOGRAM_TIMES("Tab.Close",
422 base::TimeTicks::Now() - tab_close_start_time_);
423 }
initial.commit09911bf2008-07-26 23:55:29424}
425
[email protected]d5f942ba2008-09-26 19:30:34426// static
427void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32428 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
429
430 WebPreferences pref_defaults;
431 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
432 pref_defaults.javascript_enabled);
433 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
434 pref_defaults.web_security_enabled);
435 prefs->RegisterBooleanPref(
436 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
437 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
438 pref_defaults.loads_images_automatically);
439 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
440 pref_defaults.plugins_enabled);
441 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
442 pref_defaults.dom_paste_enabled);
443 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
444 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14445 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32446 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
447 pref_defaults.text_areas_are_resizable);
448 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
449 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36450 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
451 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32452
453 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
454 IDS_ACCEPT_LANGUAGES);
455 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
456 IDS_DEFAULT_ENCODING);
457 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
458 IDS_STANDARD_FONT_IS_SERIF);
459 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
460 IDS_FIXED_FONT_FAMILY);
461 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
462 IDS_SERIF_FONT_FAMILY);
463 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
464 IDS_SANS_SERIF_FONT_FAMILY);
465 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
466 IDS_CURSIVE_FONT_FAMILY);
467 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
468 IDS_FANTASY_FONT_FAMILY);
469 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
470 IDS_DEFAULT_FONT_SIZE);
471 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
472 IDS_DEFAULT_FIXED_FONT_SIZE);
473 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
474 IDS_MINIMUM_FONT_SIZE);
475 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
476 IDS_MINIMUM_LOGICAL_FONT_SIZE);
477 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
478 IDS_USES_UNIVERSAL_DETECTOR);
479 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
480 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29481}
482
[email protected]13367f72009-07-08 16:39:02483// Returns true if contains content rendered by an extension.
484bool TabContents::HostsExtension() const {
485 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34486}
487
[email protected]cf28ec52010-04-09 22:56:34488AutoFillManager* TabContents::GetAutoFillManager() {
489 if (autofill_manager_.get() == NULL)
490 autofill_manager_.reset(new AutoFillManager(this));
491 return autofill_manager_.get();
492}
493
[email protected]6e95706d2009-04-23 22:55:01494PasswordManager* TabContents::GetPasswordManager() {
495 if (password_manager_.get() == NULL)
496 password_manager_.reset(new PasswordManager(this));
497 return password_manager_.get();
498}
499
500PluginInstaller* TabContents::GetPluginInstaller() {
501 if (plugin_installer_.get() == NULL)
502 plugin_installer_.reset(new PluginInstaller(this));
503 return plugin_installer_.get();
504}
505
[email protected]1f18184a2010-07-21 19:34:49506TabContentsSSLHelper* TabContents::GetSSLHelper() {
507 if (ssl_helper_.get() == NULL)
508 ssl_helper_.reset(new TabContentsSSLHelper(this));
509 return ssl_helper_.get();
510}
511
[email protected]8cb5d5b2010-02-09 11:36:16512RenderProcessHost* TabContents::GetRenderProcessHost() const {
513 return render_manager_.current_host()->process();
514}
515
[email protected]98aa0b52010-05-06 17:03:08516void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46517 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08518 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10519
[email protected]98aa0b52010-05-06 17:03:08520 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57521
[email protected]fca656c2010-02-10 20:30:10522 NotificationService::current()->Notify(
523 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
524 Source<TabContents>(this),
525 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49526}
527
[email protected]98aa0b52010-05-06 17:03:08528void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
529 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40530 return;
531
532 ExtensionsService* extension_service = profile()->GetExtensionsService();
533 if (extension_service && extension_service->is_ready()) {
534 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08535 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40536 if (extension)
[email protected]98aa0b52010-05-06 17:03:08537 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40538 }
539}
540
[email protected]98aa0b52010-05-06 17:03:08541SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]9155324b2010-08-02 18:24:53542 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
543 // for those windows, we already have a big icon in the top-left outside any
544 // tab. Having big tab icons too looks kinda redonk.
545 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
546 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
547 return NULL;
548
[email protected]98aa0b52010-05-06 17:03:08549 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51550 return NULL;
551
[email protected]98aa0b52010-05-06 17:03:08552 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51553}
554
[email protected]d5f942ba2008-09-26 19:30:34555const GURL& TabContents::GetURL() const {
556 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57557 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54558 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34559}
560
[email protected]96d185d2009-04-24 03:28:54561const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55562 // Transient entries take precedence. They are used for interstitial pages
563 // that are shown on top of existing pages.
564 NavigationEntry* entry = controller_.GetTransientEntry();
565 if (entry)
566 return entry->GetTitleForDisplay(&controller_);
567
[email protected]96d185d2009-04-24 03:28:54568 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
569 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
570 if (our_dom_ui) {
571 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55572 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54573 if (!(entry && entry->IsViewSourceMode())) {
574 // Give the DOM UI the chance to override our title.
575 const string16& title = our_dom_ui->overridden_title();
576 if (!title.empty())
577 return title;
578 }
579 }
580
581 // We use the title for the last committed entry rather than a pending
582 // navigation entry. For example, when the user types in a URL, we want to
583 // keep the old page's title until the new load has committed and we get a new
584 // title.
[email protected]96d185d2009-04-24 03:28:54585 entry = controller_.GetLastCommittedEntry();
586 if (entry)
587 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54588 return EmptyString16();
589}
590
[email protected]bbbc1ef2010-02-12 18:03:41591// static
592string16 TabContents::GetDefaultTitle() {
593 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
594}
595
[email protected]d5f942ba2008-09-26 19:30:34596int32 TabContents::GetMaxPageID() {
597 if (GetSiteInstance())
598 return GetSiteInstance()->max_page_id();
599 else
600 return max_page_id_;
601}
602
603void TabContents::UpdateMaxPageID(int32 page_id) {
604 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34605 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34606 // testing.
607 if (GetSiteInstance())
608 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16609 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34610}
611
[email protected]96d185d2009-04-24 03:28:54612SiteInstance* TabContents::GetSiteInstance() const {
613 return render_manager_.current_host()->site_instance();
614}
615
[email protected]96d185d2009-04-24 03:28:54616bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15617 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54618 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15619 if (entry && (entry->IsViewSourceMode() ||
620 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54621 return true;
[email protected]8ab24cc2009-11-13 20:56:15622 }
[email protected]83e3895b2009-06-11 00:07:16623
[email protected]96d185d2009-04-24 03:28:54624 DOMUI* dom_ui = GetDOMUIForCurrentState();
625 if (dom_ui)
626 return !dom_ui->should_hide_url();
627 return true;
628}
629
[email protected]d5f942ba2008-09-26 19:30:34630SkBitmap TabContents::GetFavIcon() const {
631 // Like GetTitle(), we also want to use the favicon for the last committed
632 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57633 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47634 if (entry)
635 return entry->favicon().bitmap();
636
[email protected]ce3fa3c2009-04-20 19:55:57637 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34638 if (entry)
639 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34640 return SkBitmap();
641}
642
[email protected]0b303cc2009-09-28 22:35:15643bool TabContents::FavIconIsValid() const {
644 NavigationEntry* entry = controller_.GetTransientEntry();
645 if (entry)
646 return entry->favicon().is_valid();
647
648 entry = controller_.GetLastCommittedEntry();
649 if (entry)
650 return entry->favicon().is_valid();
651
652 return false;
653}
654
[email protected]96d185d2009-04-24 03:28:54655bool TabContents::ShouldDisplayFavIcon() {
656 // Always display a throbber during pending loads.
657 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
658 return true;
659
660 DOMUI* dom_ui = GetDOMUIForCurrentState();
661 if (dom_ui)
662 return !dom_ui->hide_favicon();
663 return true;
664}
665
[email protected]96d185d2009-04-24 03:28:54666std::wstring TabContents::GetStatusText() const {
667 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
668 return std::wstring();
669
670 switch (load_state_) {
671 case net::LOAD_STATE_WAITING_FOR_CACHE:
672 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04673 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
674 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54675 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
676 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
677 case net::LOAD_STATE_RESOLVING_HOST:
678 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
679 case net::LOAD_STATE_CONNECTING:
680 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06681 case net::LOAD_STATE_SSL_HANDSHAKE:
682 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54683 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56684 if (upload_size_)
685 return l10n_util::GetStringF(
686 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
687 static_cast<int>((100 * upload_position_) / upload_size_));
688 else
689 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54690 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
691 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
692 load_state_host_);
693 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
694 case net::LOAD_STATE_IDLE:
695 case net::LOAD_STATE_READING_RESPONSE:
696 break;
697 }
698
699 return std::wstring();
700}
701
[email protected]d5f942ba2008-09-26 19:30:34702void TabContents::SetIsCrashed(bool state) {
703 if (state == is_crashed_)
704 return;
705
706 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50707 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34708}
709
[email protected]744ef172009-10-16 21:53:46710void TabContents::PageActionStateChanged() {
711 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00712}
[email protected]ce5c4502009-05-06 16:46:11713
[email protected]d5f942ba2008-09-26 19:30:34714void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
715 if (delegate_)
716 delegate_->NavigationStateChanged(this, changed_flags);
717}
718
[email protected]96d185d2009-04-24 03:28:54719void TabContents::DidBecomeSelected() {
720 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16721 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
722 if (rwhv) {
723 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43724#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16725 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43726#endif
727 }
[email protected]96d185d2009-04-24 03:28:54728
[email protected]8cb5d5b2010-02-09 11:36:16729 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54730}
731
732void TabContents::WasHidden() {
733 if (!capturing_contents()) {
734 // |render_view_host()| can be NULL if the user middle clicks a link to open
735 // a tab in then background, then closes the tab before selecting it. This
736 // is because closing the tab calls TabContents::Destroy(), which removes
737 // the |render_view_host()|; then when we actually destroy the window,
738 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16739 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
740 if (rwhv)
741 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54742 }
743
744 NotificationService::current()->Notify(
745 NotificationType::TAB_CONTENTS_HIDDEN,
746 Source<TabContents>(this),
747 NotificationService::NoDetails());
748}
749
[email protected]d5f942ba2008-09-26 19:30:34750void TabContents::Activate() {
751 if (delegate_)
752 delegate_->ActivateContents(this);
753}
754
[email protected]96d185d2009-04-24 03:28:54755void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16756 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
757 if (rwhv)
758 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54759}
760
761void TabContents::HideContents() {
762 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
763 // our superclass HideContents(), because some callers want to be very picky
764 // about the order in which these get called. In addition to making the code
765 // here practically impossible to understand, this also means we end up
766 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34767 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54768 WasHidden();
769}
770
[email protected]c0588052008-10-27 23:01:50771void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34772 WindowOpenDisposition disposition,
773 PageTransition::Type transition) {
774 if (delegate_)
[email protected]c0588052008-10-27 23:01:50775 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34776}
777
[email protected]1ccb3568d2010-02-19 10:51:16778bool TabContents::NavigateToPendingEntry(
779 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54780 const NavigationEntry& entry = *controller_.pending_entry();
781
782 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
783 if (!dest_render_view_host)
784 return false; // Unable to create the desired render view host.
785
[email protected]770dd8b2010-05-24 18:11:39786 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
787 dest_render_view_host->EnablePreferredSizeChangedMode(
788 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
789 }
[email protected]9fb325e2010-05-06 18:23:24790
[email protected]0352e5472010-04-29 00:11:40791 // For security, we should never send non-DOM-UI URLs (other than about:blank)
792 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58793 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40794 bool is_allowed_in_dom_ui_renderer =
795 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
796 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58797 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40798 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58799
[email protected]96d185d2009-04-24 03:28:54800 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12801 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32802 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00803 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
804 dest_render_view_host,
805 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32806 }
[email protected]96d185d2009-04-24 03:28:54807
808 // Used for page load time metrics.
809 current_load_start_ = base::TimeTicks::Now();
810
811 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34812 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00813 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34814 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54815
816 if (entry.page_id() == -1) {
817 // HACK!! This code suppresses javascript: URLs from being added to
818 // session history, which is what we want to do for javascript: URLs that
819 // do not generate content. What we really need is a message from the
820 // renderer telling us that a new page was not created. The same message
821 // could be used for mailto: URLs and the like.
822 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
823 return false;
824 }
825
826 // Clear any provisional password saves - this stops password infobars
827 // showing up on pages the user navigates to while the right page is
828 // loading.
829 GetPasswordManager()->ClearProvisionalSave();
830
[email protected]1ccb3568d2010-02-19 10:51:16831 if (reload_type != NavigationController::NO_RELOAD &&
832 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48833 FaviconService* favicon_service =
834 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
835 if (favicon_service)
836 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54837 }
838
[email protected]d5f942ba2008-09-26 19:30:34839 return true;
840}
841
[email protected]96d185d2009-04-24 03:28:54842void TabContents::Stop() {
843 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09844 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54845}
846
[email protected]96d185d2009-04-24 03:28:54847void TabContents::DisassociateFromPopupCount() {
848 render_view_host()->DisassociateFromPopupCount();
849}
850
851TabContents* TabContents::Clone() {
852 // We create a new SiteInstance so that the new tab won't share processes
853 // with the old one. This can be changed in the future if we need it to share
854 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32855 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54856 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21857 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54858 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08859 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08860 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54861 return tc;
862}
863
[email protected]4d677202009-07-19 07:37:12864void TabContents::ShowPageInfo(const GURL& url,
865 const NavigationEntry::SSLStatus& ssl,
866 bool show_history) {
867 if (!delegate_)
868 return;
869
[email protected]bb678332009-07-21 00:15:50870 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12871}
872
initial.commit09911bf2008-07-26 23:55:29873ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28874 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29875 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28876 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29877 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44878
879 if (child_windows_.size() == 1) {
880 window->ShowConstrainedWindow();
881 BlockTabContent(true);
882 }
883
initial.commit09911bf2008-07-26 23:55:29884 return window;
885}
886
[email protected]fa1cf0b82010-01-15 21:49:44887void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55888 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
889 if (rwhv)
890 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44891 render_view_host()->set_ignore_input_events(blocked);
892 if (delegate_)
893 delegate_->SetTabContentBlocked(this, blocked);
894}
895
initial.commit09911bf2008-07-26 23:55:29896void TabContents::AddNewContents(TabContents* new_contents,
897 WindowOpenDisposition disposition,
898 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29899 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29900 if (!delegate_)
901 return;
902
[email protected]35f7d212009-04-29 21:19:27903 if ((disposition == NEW_POPUP) && !user_gesture &&
904 !CommandLine::ForCurrentProcess()->HasSwitch(
905 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22906 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31907 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29908 delegate_->GetConstrainingContents(this)->AddPopup(
909 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31910 } else {
[email protected]304f8792009-08-19 21:28:09911#if defined(OS_CHROMEOS)
912 if (disposition == NEW_POPUP) {
913 // If the popup is bigger than a given factor of the screen, then
914 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11915 // Also check for width or height == 0, which would otherwise indicate
916 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09917 GdkScreen* screen = gdk_screen_get_default();
918 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
919 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11920 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
921 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09922 disposition = NEW_FOREGROUND_TAB;
923 }
924 }
925#endif
926
[email protected]0aa55312008-10-17 21:53:08927 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29928 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
929 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49930 NotificationService::current()->Notify(
931 NotificationType::TAB_ADDED,
932 Source<TabContentsDelegate>(delegate_),
933 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29934 }
initial.commit09911bf2008-07-26 23:55:29935
[email protected]8cc8d492010-02-02 10:40:49936 // TODO(pkasting): Why is this necessary?
937 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29938}
939
[email protected]bcd9dc42010-01-23 16:38:18940bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20941 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20942 bool is_js_code, const std::string& code_string,
943 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51944 RenderViewHost* host = render_view_host();
945 if (!host)
946 return false;
947
948 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
949 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
950 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35951}
952
[email protected]96d185d2009-04-24 03:28:54953void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49954 if (is_being_destroyed_)
955 return;
[email protected]9fb83e82010-07-02 18:24:55956 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:49957 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40958 render_view_host()->AllowScriptToClose(!visible);
[email protected]8e0bbf12010-07-20 00:03:43959 if (visible)
960 PopupBlockedAnimation::Show(this);
[email protected]96d185d2009-04-24 03:28:54961}
962
[email protected]5c9e97a2009-09-09 23:48:30963gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54964 return view_->GetContentNativeView();
965}
966
967gfx::NativeView TabContents::GetNativeView() const {
968 return view_->GetNativeView();
969}
970
971void TabContents::GetContainerBounds(gfx::Rect *out) const {
972 view_->GetContainerBounds(out);
973}
974
975void TabContents::Focus() {
976 view_->Focus();
977}
978
[email protected]90daadb42009-06-08 21:27:28979void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54980 if (showing_interstitial_page()) {
981 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
982 return;
983 }
[email protected]96d185d2009-04-24 03:28:54984 render_view_host()->SetInitialFocus(reverse);
985}
986
987bool TabContents::FocusLocationBarByDefault() {
988 DOMUI* dom_ui = GetDOMUIForCurrentState();
989 if (dom_ui)
990 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43991 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25992 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43993 return true;
[email protected]96d185d2009-04-24 03:28:54994 return false;
995}
996
[email protected]a26dc362010-04-23 01:48:58997void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38998 if (delegate())
[email protected]a26dc362010-04-23 01:48:58999 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381000}
1001
[email protected]616ed5a2008-11-21 22:27:241002void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321003 if (delegate_ && !delegate_->infobars_enabled()) {
1004 delegate->InfoBarClosed();
1005 return;
1006 }
1007
[email protected]616ed5a2008-11-21 22:27:241008 // Look through the existing InfoBarDelegates we have for a match. If we've
1009 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051010 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451011 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1012 // Tell the new infobar to close so that it can clean itself up.
1013 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241014 return;
[email protected]6d27a7b2009-12-18 23:25:451015 }
[email protected]616ed5a2008-11-21 22:27:241016 }
1017
1018 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561019 NotificationService::current()->Notify(
1020 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1021 Source<TabContents>(this),
1022 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241023
1024 // Add ourselves as an observer for navigations the first time a delegate is
1025 // added. We use this notification to expire InfoBars that need to expire on
1026 // page transitions.
1027 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561028 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571029 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241030 }
1031}
1032
1033void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321034 if (delegate_ && !delegate_->infobars_enabled()) {
1035 return;
1036 }
1037
[email protected]616ed5a2008-11-21 22:27:241038 std::vector<InfoBarDelegate*>::iterator it =
1039 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1040 if (it != infobar_delegates_.end()) {
1041 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561042 NotificationService::current()->Notify(
1043 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1044 Source<TabContents>(this),
1045 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051046 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241047
[email protected]6a02963e2009-01-06 16:58:031048 // Remove ourselves as an observer if we are tracking no more InfoBars.
1049 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561050 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571051 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031052 }
[email protected]616ed5a2008-11-21 22:27:241053 }
1054}
[email protected]3edd9522009-03-04 22:19:411055
[email protected]f81821c2009-08-07 01:29:471056void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1057 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321058 if (delegate_ && !delegate_->infobars_enabled()) {
1059 new_delegate->InfoBarClosed();
1060 return;
1061 }
1062
[email protected]f81821c2009-08-07 01:29:471063 std::vector<InfoBarDelegate*>::iterator it =
1064 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1065 DCHECK(it != infobar_delegates_.end());
1066
1067 // Notify the container about the change of plans.
1068 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1069 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1070 old_delegate, new_delegate));
1071 NotificationService::current()->Notify(
1072 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1073 Source<TabContents>(this),
1074 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1075
1076 // Remove the old one.
1077 infobar_delegates_.erase(it);
1078
1079 // Add the new one.
1080 infobar_delegates_.push_back(new_delegate);
1081}
1082
[email protected]20ede072009-10-06 00:28:351083bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271084 if (showing_interstitial_page())
1085 return false;
1086
[email protected]96d185d2009-04-24 03:28:541087 // See GetDOMUIForCurrentState() comment for more info. This case is very
1088 // similar, but for non-first loads, we want to use the committed entry. This
1089 // is so the bookmarks bar disappears at the same time the page does.
1090 if (controller_.GetLastCommittedEntry()) {
1091 // Not the first load, always use the committed DOM UI.
1092 if (render_manager_.dom_ui())
1093 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1094 return false; // Default.
1095 }
1096
1097 // When it's the first load, we know either the pending one or the committed
1098 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1099 // of them will be valid, so we can just check both.
1100 if (render_manager_.pending_dom_ui())
1101 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1102 if (render_manager_.dom_ui())
1103 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1104 return false; // Default.
1105}
1106
[email protected]d8f16ae2009-08-30 03:47:261107bool TabContents::IsExtensionShelfAlwaysVisible() {
1108 // See GetDOMUIForCurrentState() comment for more info. This case is very
1109 // similar, but for non-first loads, we want to use the committed entry. This
1110 // is so the bookmarks bar disappears at the same time the page does.
1111 if (controller_.GetLastCommittedEntry()) {
1112 // Not the first load, always use the committed DOM UI.
1113 if (render_manager_.dom_ui())
1114 return render_manager_.dom_ui()->force_extension_shelf_visible();
1115 return false; // Default.
1116 }
1117
1118 // When it's the first load, we know either the pending one or the committed
1119 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1120 // of them will be valid, so we can just check both.
1121 if (render_manager_.pending_dom_ui())
1122 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1123 if (render_manager_.dom_ui())
1124 return render_manager_.dom_ui()->force_extension_shelf_visible();
1125 return false; // Default.
1126}
1127
[email protected]3edd9522009-03-04 22:19:411128void TabContents::ToolbarSizeChanged(bool is_animating) {
1129 TabContentsDelegate* d = delegate();
1130 if (d)
1131 d->ToolbarSizeChanged(this, is_animating);
1132}
[email protected]616ed5a2008-11-21 22:27:241133
[email protected]fc6fb7fb2009-11-07 02:35:041134bool TabContents::CanDownload(int request_id) {
1135 TabContentsDelegate* d = delegate();
1136 if (d)
1137 return d->CanDownload(request_id);
1138 return true;
1139}
1140
[email protected]d5f942ba2008-09-26 19:30:341141void TabContents::OnStartDownload(DownloadItem* download) {
1142 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341143
1144 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311145 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341146
[email protected]c70f9b82010-04-21 07:31:111147 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221148 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111149 // If the download occurs in a new tab, close it
1150 if (controller_.IsInitialNavigation() && (tab_contents == this))
1151 delegate()->CloseContents(this);
1152 }
[email protected]3edd9522009-03-04 22:19:411153}
[email protected]3edd9522009-03-04 22:19:411154
[email protected]d5f942ba2008-09-26 19:30:341155void TabContents::WillClose(ConstrainedWindow* window) {
1156 ConstrainedWindowList::iterator it =
1157 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441158 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341159 if (it != child_windows_.end())
1160 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371161 if (child_windows_.size() > 0) {
1162 if (removed_topmost_window) {
1163 child_windows_[0]->ShowConstrainedWindow();
1164 }
[email protected]fa1cf0b82010-01-15 21:49:441165 BlockTabContent(true);
1166 } else {
1167 BlockTabContent(false);
1168 }
[email protected]66ba4932009-06-04 19:22:131169}
[email protected]d5f942ba2008-09-26 19:30:341170
[email protected]66ba4932009-06-04 19:22:131171void TabContents::WillCloseBlockedPopupContainer(
1172 BlockedPopupContainer* container) {
1173 DCHECK(blocked_popups_ == container);
1174 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491175 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341176}
1177
[email protected]d5f942ba2008-09-26 19:30:341178void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351179#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061180 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351181#endif
[email protected]d5f942ba2008-09-26 19:30:341182}
1183
[email protected]c1dc9f132009-11-20 23:13:211184void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121185 bool forward_direction,
1186 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211187 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011188 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211189 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531190 string16 last_search_prepopulate_text =
1191 FindBarState::GetLastPrepopulateText(profile());
1192
[email protected]87fae512009-12-11 02:20:211193 // Try the last thing we searched for on this tab, then the last thing
1194 // searched for on any tab.
1195 if (!previous_find_text_.empty())
1196 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531197 else if (!last_search_prepopulate_text.empty())
1198 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211199 else
[email protected]e491f1c2009-05-22 20:28:121200 return;
[email protected]e491f1c2009-05-22 20:28:121201 }
[email protected]6e95706d2009-04-23 22:55:011202
[email protected]101c90e2009-10-26 21:14:441203 // Keep track of the previous search.
1204 previous_find_text_ = find_text_;
1205
[email protected]6e95706d2009-04-23 22:55:011206 // This is a FindNext operation if we are searching for the same text again,
1207 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1208 // exception to this is if the Find was aborted (then we don't want FindNext
1209 // because the highlighting has been cleared and we need it to reappear). We
1210 // therefore treat FindNext after an aborted Find operation as a full fledged
1211 // Find.
[email protected]c1dc9f132009-11-20 23:13:211212 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121213 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011214 !find_op_aborted_;
1215 if (!find_next)
1216 current_find_request_id_ = find_request_id_counter_++;
1217
[email protected]c1dc9f132009-11-20 23:13:211218 if (!search_string.empty())
1219 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121220 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011221
1222 find_op_aborted_ = false;
1223
1224 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531225 FindBarState* find_bar_state = profile()->GetFindBarState();
1226 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011227 render_view_host()->StartFinding(current_find_request_id_,
1228 find_text_,
1229 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121230 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011231 find_next);
1232}
1233
[email protected]5bc8fe92010-03-11 18:19:001234void TabContents::StopFinding(
1235 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011236 if (selection_action == FindBarController::kClearSelection) {
1237 // kClearSelection means the find string has been cleared by the user, but
1238 // the UI has not been dismissed. In that case we want to clear the
1239 // previously remembered search (http://crbug.com/42639).
1240 previous_find_text_ = string16();
1241 } else {
[email protected]2d2dffc2009-06-09 21:41:001242 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011243 if (!find_text_.empty())
1244 previous_find_text_ = find_text_;
1245 }
[email protected]101c90e2009-10-26 21:14:441246 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011247 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121248 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001249 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011250}
1251
[email protected]420ae012009-04-24 05:16:321252void TabContents::OnSavePage() {
1253 // If we can not save the page, try to download it.
1254 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1255 DownloadManager* dlm = profile()->GetDownloadManager();
1256 const GURL& current_page_url = GetURL();
1257 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221258 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321259 return;
1260 }
1261
1262 Stop();
1263
1264 // Create the save package and possibly prompt the user for the name to save
1265 // the page as. The user prompt is an asynchronous operation that runs on
1266 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221267 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321268 save_package_->GetSaveInfo();
1269}
1270
1271// Used in automated testing to bypass prompting the user for file names.
1272// Instead, the names and paths are hard coded rather than running them through
1273// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111274bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321275 SavePackage::SavePackageType save_type) {
1276 // Stop the page from navigating.
1277 Stop();
1278
[email protected]828cabe2009-09-26 22:47:111279 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591280 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321281}
1282
[email protected]89d6e6e2009-12-03 23:06:511283void TabContents::EmailPageLocation() {
1284 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1285 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1286 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1287 title + "&body=%0A%0A" + page_url;
1288 platform_util::OpenExternal(GURL(mailto));
1289}
1290
[email protected]420ae012009-04-24 05:16:321291void TabContents::PrintPreview() {
1292 // We don't show the print preview yet, only the print dialog.
1293 PrintNow();
1294}
1295
1296bool TabContents::PrintNow() {
1297 // We can't print interstitial page for now.
1298 if (showing_interstitial_page())
1299 return false;
1300
1301 return render_view_host()->PrintPages();
1302}
1303
[email protected]82270452009-06-19 15:58:011304void TabContents::PrintingDone(int document_cookie, bool success) {
1305 render_view_host()->PrintingDone(document_cookie, success);
1306}
1307
[email protected]420ae012009-04-24 05:16:321308bool TabContents::IsActiveEntry(int32 page_id) {
1309 NavigationEntry* active_entry = controller_.GetActiveEntry();
1310 return (active_entry != NULL &&
1311 active_entry->site_instance() == GetSiteInstance() &&
1312 active_entry->page_id() == page_id);
1313}
1314
[email protected]b2fe07d12010-02-09 14:38:081315void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161316 set_encoding(encoding);
1317 render_view_host()->SetPageEncoding(encoding);
1318}
1319
[email protected]b2fe07d12010-02-09 14:38:081320void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161321 reset_encoding();
1322 render_view_host()->ResetPageEncodingToDefault();
1323}
1324
1325void TabContents::WindowMoveOrResizeStarted() {
1326 render_view_host()->WindowMoveOrResizeStarted();
1327}
1328
[email protected]3f8eb7f2009-10-02 23:58:051329void TabContents::LogNewTabTime(const std::string& event_name) {
1330 // Not all new tab pages get timed. In those cases, we don't have a
1331 // new_tab_start_time_.
1332 if (new_tab_start_time_.is_null())
1333 return;
1334
1335 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441336 MetricEventDurationDetails details(event_name,
1337 static_cast<int>(duration.InMilliseconds()));
1338
[email protected]7ab1e7d62009-10-14 23:32:011339 if (event_name == "Tab.NewTabScriptStart") {
1340 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1341 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1342 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1343 } else if (event_name == "Tab.NewTabOnload") {
1344 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051345 // The new tab page has finished loading; reset it.
1346 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441347 } else {
1348 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051349 }
[email protected]84abba62009-10-07 17:01:441350 NotificationService::current()->Notify(
1351 NotificationType::METRIC_EVENT_DURATION,
1352 Source<TabContents>(this),
1353 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051354}
1355
[email protected]7ab1e7d62009-10-14 23:32:011356void TabContents::OnCloseStarted() {
1357 if (tab_close_start_time_.is_null())
1358 tab_close_start_time_ = base::TimeTicks::Now();
1359}
1360
[email protected]b5558cf22010-07-12 17:30:061361void TabContents::set_request_context(URLRequestContextGetter* context) {
1362 request_context_ = context;
1363}
1364
[email protected]46624bf2010-06-09 16:04:191365bool TabContents::ShouldAcceptDragAndDrop() const {
1366#if defined(OS_CHROMEOS)
1367 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1368 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561369 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191370#else
1371 return true;
1372#endif
1373}
1374
[email protected]c37e3b62010-01-22 00:15:171375TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171376 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161377
1378 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081379 if (extension_app_)
1380 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161381 else if (entry)
1382 tab_nav.SetFromNavigationEntry(*entry);
1383
[email protected]c37e3b62010-01-22 00:15:171384 std::vector<TabNavigation> navigations;
1385 navigations.push_back(tab_nav);
1386
1387 TabContents* new_contents =
1388 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081389 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171390 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171391
[email protected]98aa0b52010-05-06 17:03:081392 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161393 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1394
[email protected]c37e3b62010-01-22 00:15:171395 return new_contents;
1396}
1397
[email protected]96d185d2009-04-24 03:28:541398// Notifies the RenderWidgetHost instance about the fact that the page is
1399// loading, or done loading and calls the base implementation.
1400void TabContents::SetIsLoading(bool is_loading,
1401 LoadNotificationDetails* details) {
1402 if (is_loading == is_loading_)
1403 return;
1404
1405 if (!is_loading) {
1406 load_state_ = net::LOAD_STATE_IDLE;
1407 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561408 upload_size_ = 0;
1409 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541410 }
1411
1412 render_manager_.SetIsLoading(is_loading);
1413
1414 is_loading_ = is_loading;
1415 waiting_for_response_ = is_loading;
1416
1417 if (delegate_)
1418 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351419 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541420
1421 NotificationType type = is_loading ? NotificationType::LOAD_START :
1422 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111423 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541424 if (details)
1425 det = Details<LoadNotificationDetails>(details);
1426 NotificationService::current()->Notify(type,
1427 Source<NavigationController>(&controller_),
1428 det);
1429}
1430
[email protected]b6c874582009-05-08 19:38:311431void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291432 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061433 // A page can't spawn popups (or do anything else, either) until its load
1434 // commits, so when we reach here, the popup was spawned by the
1435 // NavigationController's last committed entry, not the active entry. For
1436 // example, if a page opens a popup in an onunload() handler, then the active
1437 // entry is the page to be loaded as we navigate away from the unloading
1438 // page. For this reason, we can't use GetURL() to get the opener URL,
1439 // because it returns the active entry.
1440 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1441 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1442
1443 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491444 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061445 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491446 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1447 } else {
1448 if (!blocked_popups_)
1449 blocked_popups_ = new BlockedPopupContainer(this);
1450 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]9fb83e82010-07-02 18:24:551451 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS);
[email protected]8cc8d492010-02-02 10:40:491452 }
[email protected]b9681312008-11-07 00:08:261453}
[email protected]616ed5a2008-11-21 22:27:241454
1455namespace {
1456bool TransitionIsReload(PageTransition::Type transition) {
1457 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1458}
1459}
1460
1461void TabContents::ExpireInfoBars(
1462 const NavigationController::LoadCommittedDetails& details) {
1463 // Only hide InfoBars when the user has done something that makes the main
1464 // frame load. We don't want various automatic or subframe navigations making
1465 // it disappear.
1466 if (!details.is_user_initiated_main_frame_load())
1467 return;
1468
[email protected]f86a07022008-11-25 01:06:051469 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241470 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051471 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241472 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241473 }
1474}
[email protected]fdd61c62009-04-22 19:22:571475
[email protected]96d185d2009-04-24 03:28:541476DOMUI* TabContents::GetDOMUIForCurrentState() {
1477 // When there is a pending navigation entry, we want to use the pending DOMUI
1478 // that goes along with it to control the basic flags. For example, we want to
1479 // show the pending URL in the URL bar, so we want the display_url flag to
1480 // be from the pending entry.
1481 //
1482 // The confusion comes because there are multiple possibilities for the
1483 // initial load in a tab as a side effect of the way the RenderViewHostManager
1484 // works.
1485 //
1486 // - For the very first tab the load looks "normal". The new tab DOM UI is
1487 // the pending one, and we want it to apply here.
1488 //
1489 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1490 // get switched to the one previously associated with the new tab pages.
1491 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1492 // have a committed DOM UI in this case.
1493 //
1494 // This condition handles all of these cases:
1495 //
1496 // - First load in first tab: no committed nav entry + pending nav entry +
1497 // pending dom ui:
1498 // -> Use pending DOM UI if any.
1499 //
1500 // - First load in second tab: no committed nav entry + pending nav entry +
1501 // no pending DOM UI:
1502 // -> Use the committed DOM UI if any.
1503 //
1504 // - Second navigation in any tab: committed nav entry + pending nav entry:
1505 // -> Use pending DOM UI if any.
1506 //
1507 // - Normal state with no load: committed nav entry + no pending nav entry:
1508 // -> Use committed DOM UI.
1509 if (controller_.pending_entry() &&
1510 (controller_.GetLastCommittedEntry() ||
1511 render_manager_.pending_dom_ui()))
1512 return render_manager_.pending_dom_ui();
1513 return render_manager_.dom_ui();
1514}
[email protected]420ae012009-04-24 05:16:321515
1516void TabContents::DidNavigateMainFramePostCommit(
1517 const NavigationController::LoadCommittedDetails& details,
1518 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441519 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1520 // If this is a window.open navigation, use the same DOMUI as the renderer
1521 // that opened the window, as long as both renderers have the same
1522 // privileges.
1523 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1524 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1525 // dom_ui might be NULL if the URL refers to a non-existent extension.
1526 if (dom_ui) {
1527 render_manager_.SetDOMUIPostCommit(dom_ui);
1528 dom_ui->RenderViewCreated(render_view_host());
1529 }
1530 }
1531 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1532 }
1533
[email protected]420ae012009-04-24 05:16:321534 if (details.is_user_initiated_main_frame_load()) {
1535 // Clear the status bubble. This is a workaround for a bug where WebKit
1536 // doesn't let us know that the cursor left an element during a
1537 // transition (this is also why the mouse cursor remains as a hand after
1538 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1539 // clear the bubble when a user navigates to a named anchor in the same
1540 // page.
1541 UpdateTargetURL(details.entry->page_id(), GURL());
1542
1543 // UpdateHelpersForDidNavigate will handle the case where the password_form
1544 // origin is valid.
1545 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1546 // cleaned up and covered by tests.
1547 if (!params.password_form.origin.is_valid())
1548 GetPasswordManager()->DidNavigate();
1549 }
1550
1551 // The keyword generator uses the navigation entries, so must be called after
1552 // the commit.
1553 GenerateKeywordIfNecessary(params);
1554
1555 // Allow the new page to set the title again.
1556 received_page_title_ = false;
1557
1558 // Get the favicon, either from history or request it from the net.
1559 fav_icon_helper_.FetchFavIcon(details.entry->url());
1560
[email protected]0de80162010-02-03 04:52:351561 // Clear all page actions, blocked content notifications and browser actions
1562 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141563 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081564 ExtensionsService* service = profile()->GetExtensionsService();
1565 if (service) {
1566 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571567 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081568 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521569 if (browser_action) {
1570 browser_action->ClearAllValuesForTab(controller().session_id().id());
1571 NotificationService::current()->Notify(
1572 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571573 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521574 NotificationService::NoDetails());
1575 }
[email protected]92c6f9b92009-10-24 04:35:081576
[email protected]5d246db22009-10-27 06:17:571577 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521578 service->extensions()->at(i)->page_action();
1579 if (page_action) {
1580 page_action->ClearAllValuesForTab(controller().session_id().id());
1581 PageActionStateChanged();
1582 }
[email protected]92c6f9b92009-10-24 04:35:081583 }
[email protected]aece2c7f2009-08-27 20:43:171584 }
[email protected]0de80162010-02-03 04:52:351585
1586 // Close blocked popups.
1587 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341588 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351589 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461590 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351591 }
1592
1593 // Clear "blocked" flags.
[email protected]9fb83e82010-07-02 18:24:551594 content_settings_delegate_->ClearBlockedContentSettings();
1595 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471596
1597 // Once the main frame is navigated, we're no longer considered to have
1598 // displayed insecure content.
1599 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171600 }
[email protected]ce5c4502009-05-06 16:46:111601
[email protected]8cc8d492010-02-02 10:40:491602 // Close constrained windows if necessary.
1603 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1604 details.previous_url, details.entry->url()))
1605 CloseConstrainedWindows();
1606
[email protected]420ae012009-04-24 05:16:321607 // Update the starred state.
1608 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531609
1610 // Clear the cache of forms in AutoFill.
1611 if (autofill_manager_.get())
1612 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321613}
1614
1615void TabContents::DidNavigateAnyFramePostCommit(
1616 RenderViewHost* render_view_host,
1617 const NavigationController::LoadCommittedDetails& details,
1618 const ViewHostMsg_FrameNavigate_Params& params) {
1619 // If we navigate, start showing messages again. This does nothing to prevent
1620 // a malicious script from spamming messages, since the script could just
1621 // reload the page to stop blocking.
1622 suppress_javascript_messages_ = false;
1623
[email protected]420ae012009-04-24 05:16:321624 // Notify the password manager of the navigation or form submit.
1625 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1626 // cleaned up and covered by tests.
1627 if (params.password_form.origin.is_valid())
1628 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551629
1630 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011631 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1632 details.type == NavigationType::SAME_PAGE;
1633 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321634}
1635
[email protected]8cc8d492010-02-02 10:40:491636void TabContents::CloseConstrainedWindows() {
1637 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321638 // We use indices instead of iterators in case CloseWindow does something
1639 // that may invalidate an iterator.
1640 int size = static_cast<int>(child_windows_.size());
1641 for (int i = size - 1; i >= 0; --i) {
1642 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441643 if (window) {
[email protected]420ae012009-04-24 05:16:321644 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441645 BlockTabContent(false);
1646 }
[email protected]420ae012009-04-24 05:16:321647 }
1648}
1649
1650void TabContents::UpdateStarredStateForCurrentURL() {
1651 BookmarkModel* model = profile()->GetBookmarkModel();
1652 const bool old_state = is_starred_;
1653 is_starred_ = (model && model->IsBookmarked(GetURL()));
1654
1655 if (is_starred_ != old_state && delegate())
1656 delegate()->URLStarredChanged(this, is_starred_);
1657}
1658
1659void TabContents::UpdateAlternateErrorPageURL() {
1660 GURL url = GetAlternateErrorPageURL();
1661 render_view_host()->SetAlternateErrorPageURL(url);
1662}
1663
1664void TabContents::UpdateWebPreferences() {
1665 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1666}
1667
1668void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1669 RenderViewHost* rvh) {
1670 // If we are creating a RVH for a restored controller, then we might
1671 // have more page IDs than the SiteInstance's current max page ID. We must
1672 // make sure that the max page ID is larger than any restored page ID.
1673 // Note that it is ok for conflicting page IDs to exist in another tab
1674 // (i.e., NavigationController), but if any page ID is larger than the max,
1675 // the back/forward list will get confused.
1676 int max_restored_page_id = controller_.max_restored_page_id();
1677 if (max_restored_page_id > 0) {
1678 int curr_max_page_id = site_instance->max_page_id();
1679 if (max_restored_page_id > curr_max_page_id) {
1680 // Need to update the site instance immediately.
1681 site_instance->UpdateMaxPageID(max_restored_page_id);
1682
1683 // Also tell the renderer to update its internal representation. We
1684 // need to reserve enough IDs to make all restored page IDs less than
1685 // the max.
1686 if (curr_max_page_id < 0)
1687 curr_max_page_id = 0;
1688 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1689 }
1690 }
1691}
1692
1693void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541694 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471695 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321696 const ViewHostMsg_FrameNavigate_Params& params) {
1697 if (profile()->IsOffTheRecord())
1698 return;
1699
1700 // Add to history service.
1701 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1702 if (hs) {
1703 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541704 virtual_url != params.url) {
1705 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321706 // types of URLs, we will display a magic URL that is different from where
1707 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541708 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1709 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321710 // to sub-frames.
1711 std::vector<GURL> redirects = params.redirects;
1712 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541713 redirects.back() = virtual_url;
1714 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471715 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321716 } else {
1717 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471718 params.transition, params.redirects,
1719 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321720 }
1721 }
1722}
1723
1724bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1725 const std::wstring& title) {
1726 // For file URLs without a title, use the pathname instead. In the case of a
1727 // synthesized title, we don't want the update to count toward the "one set
1728 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251729 string16 final_title;
[email protected]420ae012009-04-24 05:16:321730 bool explicit_set;
1731 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251732 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321733 explicit_set = false; // Don't count synthetic titles toward the set limit.
1734 } else {
[email protected]e53668962010-06-23 15:35:251735 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321736 explicit_set = true;
1737 }
1738
[email protected]e53668962010-06-23 15:35:251739 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321740 return false; // Nothing changed, don't bother.
1741
[email protected]e53668962010-06-23 15:35:251742 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321743
1744 // Update the history system for this page.
1745 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1746 HistoryService* hs =
1747 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1748 if (hs)
[email protected]ebe89e062009-08-13 23:16:541749 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321750
1751 // Don't allow the title to be saved again for explicitly set ones.
1752 received_page_title_ = explicit_set;
1753 }
1754
1755 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251756 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321757
[email protected]cbc0e1b2010-04-12 18:33:041758 NotificationService::current()->Notify(
1759 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1760 Source<TabContents>(this),
1761 NotificationService::NoDetails());
1762
[email protected]420ae012009-04-24 05:16:321763 return true;
1764}
1765
1766void TabContents::NotifySwapped() {
1767 // After sending out a swap notification, we need to send a disconnect
1768 // notification so that clients that pick up a pointer to |this| can NULL the
1769 // pointer. See Bug 1230284.
1770 notify_disconnection_ = true;
1771 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341772 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221773 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321774 NotificationService::NoDetails());
1775}
1776
1777void TabContents::NotifyConnected() {
1778 notify_disconnection_ = true;
1779 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341780 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221781 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321782 NotificationService::NoDetails());
1783}
1784
1785void TabContents::NotifyDisconnected() {
1786 if (!notify_disconnection_)
1787 return;
1788
1789 notify_disconnection_ = false;
1790 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341791 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221792 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321793 NotificationService::NoDetails());
1794}
1795
1796void TabContents::GenerateKeywordIfNecessary(
1797 const ViewHostMsg_FrameNavigate_Params& params) {
1798 if (!params.searchable_form_url.is_valid())
1799 return;
1800
1801 if (profile()->IsOffTheRecord())
1802 return;
1803
1804 int last_index = controller_.last_committed_entry_index();
1805 // When there was no previous page, the last index will be 0. This is
1806 // normally due to a form submit that opened in a new tab.
1807 // TODO(brettw) bug 916126: we should support keywords when form submits
1808 // happen in new tabs.
1809 if (last_index <= 0)
1810 return;
1811 const NavigationEntry* previous_entry =
1812 controller_.GetEntryAtIndex(last_index - 1);
1813 if (IsFormSubmit(previous_entry)) {
1814 // Only generate a keyword if the previous page wasn't itself a form
1815 // submit.
1816 return;
1817 }
1818
1819 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1820 previous_entry->user_typed_url() : previous_entry->url();
1821 std::wstring keyword =
1822 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1823 if (keyword.empty())
1824 return;
1825
1826 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1827 if (!url_model)
1828 return;
1829
1830 if (!url_model->loaded()) {
1831 url_model->Load();
1832 return;
1833 }
1834
1835 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191836 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321837 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1838 return;
1839
1840 if (current_url) {
1841 if (current_url->originating_url().is_valid()) {
1842 // The existing keyword was generated from an OpenSearch description
1843 // document, don't regenerate.
1844 return;
1845 }
1846 url_model->Remove(current_url);
1847 }
1848 TemplateURL* new_url = new TemplateURL();
1849 new_url->set_keyword(keyword);
1850 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191851 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321852 new_url->add_input_encoding(params.searchable_form_encoding);
1853 DCHECK(controller_.GetLastCommittedEntry());
1854 const GURL& favicon_url =
1855 controller_.GetLastCommittedEntry()->favicon().url();
1856 if (favicon_url.is_valid()) {
1857 new_url->SetFavIconURL(favicon_url);
1858 } else {
1859 // The favicon url isn't valid. This means there really isn't a favicon,
1860 // or the favicon url wasn't obtained before the load started. This assumes
1861 // the later.
1862 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1863 // its url.
1864 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1865 }
1866 new_url->set_safe_for_autoreplace(true);
1867 url_model->Add(new_url);
1868}
1869
[email protected]bf5c2ff392009-07-08 16:24:331870void TabContents::OnUserGesture() {
1871 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011872 DownloadRequestLimiter* limiter =
1873 g_browser_process->download_request_limiter();
1874 if (limiter)
1875 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261876 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331877 controller_.OnUserGesture();
1878}
1879
1880void TabContents::OnFindReply(int request_id,
1881 int number_of_matches,
1882 const gfx::Rect& selection_rect,
1883 int active_match_ordinal,
1884 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421885 // Ignore responses for requests that have been aborted.
1886 if (find_op_aborted_)
1887 return;
1888
[email protected]bf5c2ff392009-07-08 16:24:331889 // Ignore responses for requests other than the one we have most recently
1890 // issued. That way we won't act on stale results when the user has
1891 // already typed in another query.
1892 if (request_id != current_find_request_id_)
1893 return;
1894
1895 if (number_of_matches == -1)
1896 number_of_matches = last_search_result_.number_of_matches();
1897 if (active_match_ordinal == -1)
1898 active_match_ordinal = last_search_result_.active_match_ordinal();
1899
1900 gfx::Rect selection = selection_rect;
1901 if (selection.IsEmpty())
1902 selection = last_search_result_.selection_rect();
1903
1904 // Notify the UI, automation and any other observers that a find result was
1905 // found.
1906 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1907 selection, active_match_ordinal,
1908 final_update);
1909 NotificationService::current()->Notify(
1910 NotificationType::FIND_RESULT_AVAILABLE,
1911 Source<TabContents>(this),
1912 Details<FindNotificationDetails>(&last_search_result_));
1913}
1914
1915void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381916 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1917 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331918}
1919
[email protected]bf5c2ff392009-07-08 16:24:331920void TabContents::OnMissingPluginStatus(int status) {
1921#if defined(OS_WIN)
1922// TODO(PORT): pull in when plug-ins work
1923 GetPluginInstaller()->OnMissingPluginStatus(status);
1924#endif
1925}
1926
1927void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331928 DCHECK(!plugin_path.value().empty());
1929
1930 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351931#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331932 scoped_ptr<FileVersionInfo> version_info(
1933 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1934 if (version_info.get()) {
1935 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371936 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331937 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371938#if defined(OS_MACOSX)
1939 // Many plugins on the Mac have .plugin in the actual name, which looks
1940 // terrible, so look for that and strip it off if present.
1941 const std::wstring plugin_extension(L".plugin");
1942 if (EndsWith(plugin_name, plugin_extension, true))
1943 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1944#endif // OS_MACOSX
1945 }
[email protected]bf5c2ff392009-07-08 16:24:331946 }
[email protected]4a560ed2009-07-13 23:35:261947#else
1948 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1949#endif
[email protected]2ae8a922010-06-28 20:27:531950 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
1951 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:331952 AddInfoBar(new SimpleAlertInfoBarDelegate(
1953 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]2ae8a922010-06-28 20:27:531954 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:331955}
1956
1957void TabContents::OnCrashedWorker() {
1958 AddInfoBar(new SimpleAlertInfoBarDelegate(
1959 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421960 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331961}
1962
1963void TabContents::OnDidGetApplicationInfo(
1964 int32 page_id,
1965 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511966 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331967
[email protected]ed5431872009-11-17 08:39:511968 if (delegate())
1969 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331970}
1971
[email protected]a2cf65eb2010-01-18 08:20:381972void TabContents::OnPageContents(const GURL& url,
1973 int renderer_process_id,
1974 int32 page_id,
[email protected]e5106202010-06-11 21:12:361975 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:101976 const std::string& language,
1977 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:381978 // Don't index any https pages. People generally don't want their bank
1979 // accounts, etc. indexed on their computer, especially since some of these
1980 // things are not marked cachable.
1981 // TODO(brettw) we may want to consider more elaborate heuristics such as
1982 // the cachability of the page. We may also want to consider subframes (this
1983 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271984 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1985 // content indexing for chromeos in some future releases.
1986#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381987 if (!url.SchemeIsSecure()) {
1988 Profile* p = profile();
1989 if (p && !p->IsOffTheRecord()) {
1990 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1991 if (hs)
1992 hs->SetPageContents(url, contents);
1993 }
1994 }
[email protected]ccd40a52010-05-11 16:15:271995#endif
[email protected]a8a81292010-01-21 00:32:451996
[email protected]1c57b7b2010-07-12 17:38:101997 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:451998
1999 std::string lang = language;
2000 NotificationService::current()->Notify(
2001 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152002 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452003 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382004}
2005
[email protected]7e0831b2010-02-01 08:45:152006void TabContents::OnPageTranslated(int32 page_id,
2007 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162008 const std::string& translated_lang,
2009 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552010 language_state_.set_current_language(translated_lang);
2011 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162012 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152013 NotificationService::current()->Notify(
2014 NotificationType::PAGE_TRANSLATED,
2015 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162016 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152017}
2018
[email protected]bf5c2ff392009-07-08 16:24:332019void TabContents::DidStartProvisionalLoadForFrame(
2020 RenderViewHost* render_view_host,
2021 bool is_main_frame,
2022 const GURL& url) {
2023 ProvisionalLoadDetails details(is_main_frame,
2024 controller_.IsURLInPageNavigation(url),
2025 url, std::string(), false);
2026 NotificationService::current()->Notify(
2027 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2028 Source<NavigationController>(&controller_),
2029 Details<ProvisionalLoadDetails>(&details));
2030}
2031
2032void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202033 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332034 NotificationService::current()->Notify(
2035 NotificationType::RESOURCE_RESPONSE_STARTED,
2036 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202037 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332038}
2039
[email protected]3dbb80b2010-02-09 22:41:202040void TabContents::DidRedirectResource(
2041 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332042 NotificationService::current()->Notify(
2043 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2044 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202045 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332046}
2047
2048void TabContents::DidLoadResourceFromMemoryCache(
2049 const GURL& url,
2050 const std::string& frame_origin,
2051 const std::string& main_frame_origin,
2052 const std::string& security_info) {
2053 // Send out a notification that we loaded a resource from our memory cache.
[email protected]fc7de492010-07-12 14:49:042054 int cert_id = 0, cert_status = 0, security_bits = 0, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332055 SSLManager::DeserializeSecurityInfo(security_info,
2056 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042057 &security_bits,
2058 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332059 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162060 GetRenderProcessHost()->id(), cert_id,
2061 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332062
2063 NotificationService::current()->Notify(
2064 NotificationType::LOAD_FROM_MEMORY_CACHE,
2065 Source<NavigationController>(&controller_),
2066 Details<LoadFromMemoryCacheDetails>(&details));
2067}
2068
[email protected]e3d60e5d2009-09-25 21:08:292069void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472070 displayed_insecure_content_ = true;
2071 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292072}
2073
2074void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592075 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292076}
2077
[email protected]bf5c2ff392009-07-08 16:24:332078void TabContents::DidFailProvisionalLoadWithError(
2079 RenderViewHost* render_view_host,
2080 bool is_main_frame,
2081 int error_code,
2082 const GURL& url,
2083 bool showing_repost_interstitial) {
2084 if (net::ERR_ABORTED == error_code) {
2085 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2086 // This means that the interstitial won't be torn down properly, which is
2087 // bad. But if we have an interstitial, go back to another tab type, and
2088 // then load the same interstitial again, we could end up getting the first
2089 // interstitial's "failed" message (as a result of the cancel) when we're on
2090 // the second one.
2091 //
2092 // We can't tell this apart, so we think we're tearing down the current page
2093 // which will cause a crash later one. There is also some code in
2094 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2095 // out because of this problem.
2096 //
2097 // http://code.google.com/p/chromium/issues/detail?id=2855
2098 // Because this will not tear down the interstitial properly, if "back" is
2099 // back to another tab type, the interstitial will still be somewhat alive
2100 // in the previous tab type. If you navigate somewhere that activates the
2101 // tab with the interstitial again, you'll see a flash before the new load
2102 // commits of the interstitial page.
2103 if (showing_interstitial_page()) {
2104 LOG(WARNING) << "Discarding message during interstitial.";
2105 return;
2106 }
2107
2108 // This will discard our pending entry if we cancelled the load (e.g., if we
2109 // decided to download the file instead of load it). Only discard the
2110 // pending entry if the URLs match, otherwise the user initiated a navigate
2111 // before the page loaded so that the discard would discard the wrong entry.
2112 NavigationEntry* pending_entry = controller_.pending_entry();
2113 if (pending_entry && pending_entry->url() == url) {
2114 controller_.DiscardNonCommittedEntries();
2115 // Update the URL display.
2116 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2117 }
2118
2119 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2120 }
2121
2122 // Send out a notification that we failed a provisional load with an error.
2123 ProvisionalLoadDetails details(is_main_frame,
2124 controller_.IsURLInPageNavigation(url),
2125 url, std::string(), false);
2126 details.set_error_code(error_code);
2127
2128 NotificationService::current()->Notify(
2129 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2130 Source<NavigationController>(&controller_),
2131 Details<ProvisionalLoadDetails>(&details));
2132}
2133
2134void TabContents::DocumentLoadedInFrame() {
2135 controller_.DocumentLoadedInFrame();
2136}
2137
[email protected]9fb83e82010-07-02 18:24:552138void TabContents::OnContentSettingsChange() {
[email protected]614c0e12010-03-25 10:12:562139 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242140 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562141}
2142
[email protected]8d3347f2009-07-09 22:00:212143RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322144 return view_.get();
2145}
2146
[email protected]8d3347f2009-07-09 22:00:212147RenderViewHostDelegate::RendererManagement*
2148TabContents::GetRendererManagementDelegate() {
2149 return &render_manager_;
2150}
2151
[email protected]bf5c2ff392009-07-08 16:24:332152RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212153 TabContents::GetBrowserIntegrationDelegate() {
2154 return this;
[email protected]bf5c2ff392009-07-08 16:24:332155}
2156
[email protected]8d3347f2009-07-09 22:00:212157RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2158 return this;
[email protected]bf5c2ff392009-07-08 16:24:332159}
2160
[email protected]46ba9082010-06-22 10:00:582161RenderViewHostDelegate::ContentSettings*
2162TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552163 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582164}
2165
[email protected]8d3347f2009-07-09 22:00:212166RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322167 return save_package_.get(); // May be NULL, but we can return NULL.
2168}
2169
[email protected]8d3347f2009-07-09 22:00:212170RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092171 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212172}
2173
2174RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2175 return &fav_icon_helper_;
2176}
2177
[email protected]e8dbd674b2010-03-11 18:34:402178RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452179 if (autocomplete_history_manager_.get() == NULL)
2180 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2181 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332182}
2183
[email protected]21674df2009-10-28 19:51:212184RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342185 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212186}
2187
[email protected]1f18184a2010-07-21 19:34:492188RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2189 return GetSSLHelper();
2190}
2191
[email protected]fd571bb2010-03-19 01:23:542192AutomationResourceRoutingDelegate*
2193TabContents::GetAutomationResourceRoutingDelegate() {
2194 return delegate();
2195}
2196
[email protected]ced90ae12010-02-20 02:06:162197RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2198 return bookmark_drag_;
2199}
2200
2201void TabContents::SetBookmarkDragDelegate(
2202 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2203 bookmark_drag_ = bookmark_drag;
2204}
2205
[email protected]9fb83e82010-07-02 18:24:552206TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2207 return content_settings_delegate_.get();
2208}
2209
[email protected]93623c5d2009-12-10 21:40:322210RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462211 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512212}
2213
[email protected]57c6a652009-05-04 07:58:342214TabContents* TabContents::GetAsTabContents() {
2215 return this;
2216}
2217
[email protected]7b291f92009-08-14 05:43:532218ViewType::Type TabContents::GetRenderViewType() const {
2219 return ViewType::TAB_CONTENTS;
2220}
2221
2222int TabContents::GetBrowserWindowID() const {
2223 return controller().window_id().id();
2224}
2225
[email protected]420ae012009-04-24 05:16:322226void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062227 NotificationService::current()->Notify(
2228 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2229 Source<TabContents>(this),
2230 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322231 NavigationEntry* entry = controller_.GetActiveEntry();
2232 if (!entry)
2233 return;
2234
2235 // When we're creating views, we're still doing initial setup, so we always
2236 // use the pending DOM UI rather than any possibly existing committed one.
2237 if (render_manager_.pending_dom_ui()) {
2238 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2239 }
2240
2241 if (entry->IsViewSourceMode()) {
2242 // Put the renderer in view source mode.
2243 render_view_host->Send(
2244 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2245 }
[email protected]0666aef2009-05-13 19:48:082246
2247 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322248}
2249
2250void TabContents::RenderViewReady(RenderViewHost* rvh) {
2251 if (rvh != render_view_host()) {
2252 // Don't notify the world, since this came from a renderer in the
2253 // background.
2254 return;
2255 }
2256
2257 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302258 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322259 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302260
2261 // Restore the focus to the tab (otherwise the focus will be on the top
2262 // window).
2263 if (was_crashed && !FocusLocationBarByDefault())
2264 Focus();
[email protected]420ae012009-04-24 05:16:322265}
2266
2267void TabContents::RenderViewGone(RenderViewHost* rvh) {
2268 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092269 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322270 return;
2271 if (rvh != render_view_host()) {
2272 // The pending page's RenderViewHost is gone.
2273 return;
2274 }
2275
2276 SetIsLoading(false, NULL);
2277 NotifyDisconnected();
2278 SetIsCrashed(true);
2279
[email protected]ff9efc62010-02-18 22:10:542280 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212281 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542282 RemoveInfoBar(GetInfoBarDelegateAt(i));
2283
[email protected]8e537302009-06-10 21:19:582284 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552285 // Only do this if we're not in browser shutdown, so that TabContents
2286 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2287 // visible do not flash a sad tab page.
2288 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2289 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322290
2291 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002292 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322293}
2294
[email protected]2e4633c2009-07-09 16:58:062295void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2296 NotificationService::current()->Notify(
2297 NotificationType::RENDER_VIEW_HOST_DELETED,
2298 Source<TabContents>(this),
2299 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482300 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062301}
2302
[email protected]420ae012009-04-24 05:16:322303void TabContents::DidNavigate(RenderViewHost* rvh,
2304 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372305 int extra_invalidate_flags = 0;
2306
2307 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352308 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372309 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2310
[email protected]420ae012009-04-24 05:16:322311 render_manager_.DidNavigateMainFrame(rvh);
2312
[email protected]20ede072009-10-06 00:28:352313 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372314 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2315 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2316 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2317 }
2318
[email protected]420ae012009-04-24 05:16:322319 // Update the site of the SiteInstance if it doesn't have one yet.
2320 if (!GetSiteInstance()->has_site())
2321 GetSiteInstance()->SetSite(params.url);
2322
2323 // Need to update MIME type here because it's referred to in
2324 // UpdateNavigationCommands() called by RendererDidNavigate() to
2325 // determine whether or not to enable the encoding menu.
2326 // It's updated only for the main frame. For a subframe,
2327 // RenderView::UpdateURL does not set params.contents_mime_type.
2328 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2329 // TODO(jungshik): Add a test for the encoding menu to avoid
2330 // regressing it again.
2331 if (PageTransition::IsMainFrame(params.transition))
2332 contents_mime_type_ = params.contents_mime_type;
2333
2334 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372335 bool did_navigate = controller_.RendererDidNavigate(
2336 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392337
2338 // Update history. Note that this needs to happen after the entry is complete,
2339 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352340 if (params.should_update_history &&
2341 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392342 // Most of the time, the displayURL matches the loaded URL, but for about:
2343 // URLs, we use a data: URL as the real value. We actually want to save
2344 // the about: URL to the history db and keep the data: URL hidden. This is
2345 // what the TabContents' URL getter does.
2346 UpdateHistoryForNavigation(GetURL(), details, params);
2347 }
2348
[email protected]76543b92009-08-31 17:27:452349 if (!did_navigate)
2350 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322351
2352 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2353 // for the appropriate notification (best) or you can add it to
2354 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2355 // necessary, please).
2356
2357 // Run post-commit tasks.
2358 if (details.is_main_frame)
2359 DidNavigateMainFramePostCommit(details, params);
2360 DidNavigateAnyFramePostCommit(rvh, details, params);
2361}
2362
2363void TabContents::UpdateState(RenderViewHost* rvh,
2364 int32 page_id,
2365 const std::string& state) {
2366 DCHECK(rvh == render_view_host());
2367
2368 // We must be prepared to handle state updates for any page, these occur
2369 // when the user is scrolling and entering form data, as well as when we're
2370 // leaving a page, in which case our state may have already been moved to
2371 // the next page. The navigation controller will look up the appropriate
2372 // NavigationEntry and update it when it is notified via the delegate.
2373
2374 int entry_index = controller_.GetEntryIndexWithPageID(
2375 GetSiteInstance(), page_id);
2376 if (entry_index < 0)
2377 return;
2378 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2379
2380 if (state == entry->content_state())
2381 return; // Nothing to update.
2382 entry->set_content_state(state);
2383 controller_.NotifyEntryChanged(entry, entry_index);
2384}
2385
2386void TabContents::UpdateTitle(RenderViewHost* rvh,
2387 int32 page_id, const std::wstring& title) {
2388 // If we have a title, that's a pretty good indication that we've started
2389 // getting useful data.
2390 SetNotWaitingForResponse();
2391
2392 DCHECK(rvh == render_view_host());
2393 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2394 page_id);
2395 if (!entry || !UpdateTitleForEntry(entry, title))
2396 return;
2397
2398 // Broadcast notifications when the UI should be updated.
2399 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032400 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322401}
2402
[email protected]420ae012009-04-24 05:16:322403void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402404 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322405 set_encoding(encoding);
2406}
2407
2408void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2409 if (delegate())
2410 delegate()->UpdateTargetURL(this, url);
2411}
2412
2413void TabContents::UpdateThumbnail(const GURL& url,
2414 const SkBitmap& bitmap,
2415 const ThumbnailScore& score) {
2416 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422417 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492418 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422419 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282420 } else {
2421 HistoryService* hs;
2422 if (!profile()->IsOffTheRecord() &&
2423 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2424 hs->SetPageThumbnail(url, bitmap, score);
2425 }
[email protected]420ae012009-04-24 05:16:322426 }
2427}
2428
[email protected]c4e98902010-06-01 10:20:142429void TabContents::UpdateInspectorSetting(const std::string& key,
2430 const std::string& value) {
2431 DictionaryValue* inspector_settings =
2432 profile()->GetPrefs()->GetMutableDictionary(
2433 prefs::kWebKitInspectorSettings);
[email protected]628cf5a52010-06-07 14:25:332434 inspector_settings->SetWithoutPathExpansion(UTF8ToWide(key),
2435 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082436}
2437
[email protected]45aafc92010-06-07 14:18:532438void TabContents::ClearInspectorSettings() {
2439 DictionaryValue* inspector_settings =
2440 profile()->GetPrefs()->GetMutableDictionary(
2441 prefs::kWebKitInspectorSettings);
2442 inspector_settings->Clear();
2443}
2444
[email protected]420ae012009-04-24 05:16:322445void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292446 // The UI may be in an event-tracking loop, such as between the
2447 // mouse-down and mouse-up in text selection or a button click.
2448 // Defer the close until after tracking is complete, so that we
2449 // don't free objects out from under the UI.
2450 // TODO(shess): This could probably be integrated with the
2451 // IsDoingDrag() test below. Punting for now because I need more
2452 // research to understand how this impacts platforms other than Mac.
2453 // TODO(shess): This could get more fine-grained. For instance,
2454 // closing a tab in another window while selecting text in the
2455 // current window's Omnibox should be just fine.
2456 if (view()->IsEventTracking()) {
2457 view()->CloseTabAfterEventTracking();
2458 return;
2459 }
2460
[email protected]24a4d1062009-07-10 23:10:422461 // If we close the tab while we're in the middle of a drag, we'll crash.
2462 // Instead, cancel the drag and close it as soon as the drag ends.
2463 if (view()->IsDoingDrag()) {
2464 view()->CancelDragAndCloseTab();
2465 return;
2466 }
2467
[email protected]420ae012009-04-24 05:16:322468 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2469 if (delegate() && rvh == render_view_host())
2470 delegate()->CloseContents(this);
2471}
2472
2473void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2474 if (delegate() && delegate()->IsPopup(this))
2475 delegate()->MoveContents(this, new_bounds);
2476}
2477
[email protected]7ab1e7d62009-10-14 23:32:012478void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382479 // By default, we assume that the content is not PDF. The renderer
2480 // will tell us if this is not the case.
2481 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322482 SetIsLoading(true, NULL);
2483}
2484
[email protected]7ab1e7d62009-10-14 23:32:012485void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322486 scoped_ptr<LoadNotificationDetails> details;
2487
2488 NavigationEntry* entry = controller_.GetActiveEntry();
2489 // An entry may not exist for a stop when loading an initial blank page or
2490 // if an iframe injected by script into a blank page finishes loading.
2491 if (entry) {
[email protected]420ae012009-04-24 05:16:322492 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2493
2494 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542495 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322496 entry->transition_type(),
2497 elapsed,
2498 &controller_,
2499 controller_.GetCurrentEntryIndex()));
2500 }
2501
2502 // Tell PasswordManager we've finished a page load, which serves as a
2503 // green light to save pending passwords and reset itself.
2504 GetPasswordManager()->DidStopLoading();
2505
2506 SetIsLoading(false, details.get());
2507}
2508
[email protected]420ae012009-04-24 05:16:322509void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2510 const GURL& source_url,
2511 const GURL& target_url) {
2512 NavigationEntry* entry;
2513 if (page_id == -1)
2514 entry = controller_.pending_entry();
2515 else
2516 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2517 if (!entry || entry->url() != source_url)
2518 return;
2519 entry->set_url(target_url);
2520}
2521
[email protected]420ae012009-04-24 05:16:322522void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2523 WindowOpenDisposition disposition) {
2524 if (render_manager_.dom_ui()) {
2525 // When we're a DOM UI, it will provide a page transition type for us (this
2526 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2527 // generated suggestions).
2528 //
2529 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162530 // want web sites to see a referrer of "chrome://blah" (and some
2531 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322532 // send to the site), so we send no referrer.
2533 OpenURL(url, GURL(), disposition,
2534 render_manager_.dom_ui()->link_transition_type());
2535 } else {
2536 OpenURL(url, referrer, disposition, PageTransition::LINK);
2537 }
2538}
2539
[email protected]1ee614862009-07-06 20:29:182540void TabContents::DomOperationResponse(const std::string& json_string,
2541 int automation_id) {
2542}
2543
[email protected]420ae012009-04-24 05:16:322544void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152545 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392546 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252547 int request_id,
2548 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322549 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442550 // This can happen if someone uses window.open() to open an extension URL
2551 // from a non-extension context.
2552 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322553 return;
2554 }
[email protected]bb64b512010-04-02 21:01:392555 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2556 request_id,
[email protected]811bfe32009-07-01 08:46:252557 has_callback);
[email protected]420ae012009-04-24 05:16:322558}
2559
2560void TabContents::ProcessExternalHostMessage(const std::string& message,
2561 const std::string& origin,
2562 const std::string& target) {
2563 if (delegate())
2564 delegate()->ForwardMessageToExternalHost(message, origin, target);
2565}
2566
[email protected]cdaf8d02010-03-30 19:52:472567void TabContents::RunFileChooser(
2568 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322569 if (!select_file_dialog_.get())
2570 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472571
2572 SelectFileDialog::Type dialog_type;
2573 switch (params.mode) {
2574 case ViewHostMsg_RunFileChooser_Params::Open:
2575 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2576 break;
2577 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2578 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2579 break;
2580 case ViewHostMsg_RunFileChooser_Params::Save:
2581 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2582 break;
2583 default:
[email protected]bed31952010-03-30 20:07:592584 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472585 NOTREACHED();
2586 }
[email protected]35896a32010-06-09 08:42:512587 FilePath default_file_name = params.default_file_name;
2588 if (default_file_name.empty())
2589 default_file_name = profile()->last_selected_directory();
[email protected]cdaf8d02010-03-30 19:52:472590 select_file_dialog_->SelectFile(dialog_type, params.title,
[email protected]35896a32010-06-09 08:42:512591 default_file_name,
[email protected]420ae012009-04-24 05:16:322592 NULL, 0, FILE_PATH_LITERAL(""),
2593 view_->GetTopLevelNativeWindow(), NULL);
2594}
2595
2596void TabContents::RunJavaScriptMessage(
2597 const std::wstring& message,
2598 const std::wstring& default_prompt,
2599 const GURL& frame_url,
2600 const int flags,
2601 IPC::Message* reply_msg,
2602 bool* did_suppress_message) {
2603 // Suppress javascript messages when requested and when inside a constrained
2604 // popup window (because that activates them and breaks them out of the
2605 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552606 // Also suppress messages when showing an interstitial. The interstitial is
2607 // shown over the previous page, we don't want the hidden page dialogs to
2608 // interfere with the interstitial.
2609 bool suppress_this_message = suppress_javascript_messages_ ||
2610 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322611 if (delegate())
2612 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312613 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322614
2615 *did_suppress_message = suppress_this_message;
2616
2617 if (!suppress_this_message) {
2618 base::TimeDelta time_since_last_message(
2619 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2620 bool show_suppress_checkbox = false;
2621 // Show a checkbox offering to suppress further messages if this message is
2622 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2623 if (time_since_last_message <
2624 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2625 show_suppress_checkbox = true;
2626
[email protected]d82ed61e2009-06-16 02:46:222627 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322628 show_suppress_checkbox, reply_msg);
2629 } else {
2630 // If we are suppressing messages, just reply as is if the user immediately
2631 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542632 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322633 }
2634}
2635
2636void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2637 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012638 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222639 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322640}
2641
2642void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2643 const std::string& json_arguments,
2644 IPC::Message* reply_msg) {
2645 if (delegate()) {
2646 HtmlDialogUIDelegate* dialog_delegate =
2647 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222648 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322649 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2650 }
2651}
2652
[email protected]4d44a1c2010-04-28 19:20:412653void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562654 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412655 GetPasswordManager()->PasswordFormsFound(forms);
2656}
2657
2658void TabContents::PasswordFormsVisible(
2659 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2660 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322661}
2662
[email protected]420ae012009-04-24 05:16:322663// Checks to see if we should generate a keyword based on the OSDD, and if
2664// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2665void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2666 int32 page_id, const GURL& url,
2667 bool autodetected) {
2668 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2669 DCHECK(url.is_valid());
2670 if (!IsActiveEntry(page_id))
2671 return;
2672 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2673 if (!url_model)
2674 return;
2675 if (!url_model->loaded()) {
2676 url_model->Load();
2677 return;
2678 }
2679 if (!profile()->GetTemplateURLFetcher())
2680 return;
2681
2682 if (profile()->IsOffTheRecord())
2683 return;
2684
2685 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2686 DCHECK(entry);
2687
2688 const NavigationEntry* base_entry = entry;
2689 if (IsFormSubmit(base_entry)) {
2690 // If the current page is a form submit, find the last page that was not
2691 // a form submit and use its url to generate the keyword from.
2692 int index = controller_.last_committed_entry_index() - 1;
2693 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2694 index--;
2695 if (index >= 0)
2696 base_entry = controller_.GetEntryAtIndex(index);
2697 else
2698 base_entry = NULL;
2699 }
2700
2701 // We want to use the user typed URL if available since that represents what
2702 // the user typed to get here, and fall back on the regular URL if not.
2703 if (!base_entry)
2704 return;
2705 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2706 base_entry->user_typed_url() : base_entry->url();
2707 if (!keyword_url.is_valid())
2708 return;
2709 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2710 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532711
2712 // For JS added OSDD empty keyword is OK because we will generate keyword
2713 // later from OSDD content.
2714 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322715 return;
2716 const TemplateURL* template_url =
2717 url_model->GetTemplateURLForKeyword(keyword);
2718 if (template_url && (!template_url->safe_for_autoreplace() ||
2719 template_url->originating_url() == url)) {
2720 // Either there is a user created TemplateURL for this keyword, or the
2721 // keyword has the same OSDD url and we've parsed it.
2722 return;
2723 }
2724
2725 // Download the OpenSearch description document. If this is successful a
2726 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322727 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2728 keyword,
2729 url,
2730 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162731 this,
[email protected]420ae012009-04-24 05:16:322732 autodetected);
2733}
2734
[email protected]155f35e2010-07-17 00:30:182735// Indicates if the two inputs have the same security origin.
2736// |requested_origin| should only be a security origin (no path, etc.).
2737// It is ok if |template_url| is NULL.
2738static bool IsSameOrigin(const GURL& requested_origin,
2739 const TemplateURL* template_url) {
2740 DCHECK(requested_origin == requested_origin.GetOrigin());
2741 return template_url && requested_origin ==
2742 TemplateURLModel::GenerateSearchURL(template_url).GetOrigin();
2743}
2744
2745ViewHostMsg_GetSearchProviderInstallState_Params
2746 TabContents::GetSearchProviderInstallState(const GURL& requested_host) {
2747 // Get the last committed entry since that is the page executing the
2748 // javascript as opposed to a page being navigated to. We don't want
2749 // to trust the page to tell us the url to avoid using potentially
2750 // compromised information.
2751 NavigationEntry* entry = controller_.GetLastCommittedEntry();
2752 GURL page_origin = entry ? entry->virtual_url().GetOrigin() : GURL();
2753 GURL requested_origin = requested_host.GetOrigin();
2754 // Do the security check before any others to avoid information leaks.
2755 if (page_origin != requested_origin)
2756 return ViewHostMsg_GetSearchProviderInstallState_Params::Denied();
2757
2758 // In incognito mode, no search information is exposed. (This check must be
2759 // done after the security check or else a web site can detect that the
2760 // user is in incognito mode just by doing a cross origin request.)
2761 if (profile()->IsOffTheRecord())
2762 return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
2763
2764 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2765 if (!url_model)
2766 return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
2767 if (!url_model->loaded())
2768 url_model->Load();
2769
2770 // First check to see if the url is the default search provider.
2771 if (IsSameOrigin(requested_origin, url_model->GetDefaultSearchProvider())) {
2772 return ViewHostMsg_GetSearchProviderInstallState_Params::
2773 InstalledAsDefault();
2774 }
2775
2776 // Is the url any search provider?
2777 std::vector<const TemplateURL*> urls = url_model->GetTemplateURLs();
2778 for (std::vector<const TemplateURL*>::iterator i = urls.begin();
2779 i != urls.end(); ++i) {
2780 const TemplateURL* template_url = (*i);
2781 if (IsSameOrigin(requested_origin, template_url)) {
2782 return ViewHostMsg_GetSearchProviderInstallState_Params::
2783 InstallButNotDefault();
2784 }
2785 }
2786 return ViewHostMsg_GetSearchProviderInstallState_Params::NotInstalled();
2787}
2788
[email protected]420ae012009-04-24 05:16:322789GURL TabContents::GetAlternateErrorPageURL() const {
2790 GURL url;
2791 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2792 if (profile()->IsOffTheRecord())
2793 return url;
2794
2795 PrefService* prefs = profile()->GetPrefs();
2796 DCHECK(prefs);
2797 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152798 url = google_util::AppendGoogleLocaleParam(
2799 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322800 url = google_util::AppendGoogleTLDParam(url);
2801 }
2802 return url;
2803}
2804
2805WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062806 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552807 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062808 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322809}
2810
[email protected]fa1cf0b82010-01-15 21:49:442811void TabContents::OnIgnoredUIEvent() {
2812 if (constrained_window_count()) {
2813 ConstrainedWindow* window = *constrained_window_begin();
2814 window->FocusConstrainedWindow();
2815 }
2816}
2817
[email protected]420ae012009-04-24 05:16:322818void TabContents::OnJSOutOfMemory() {
2819 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422820 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322821}
2822
[email protected]420ae012009-04-24 05:16:322823void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2824 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342825 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322826 // delivered to a pending RenderViewHost. We must first run the onunload
2827 // handler of the old RenderViewHost before we can allow it to proceed.
2828 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2829 new_request_id);
2830}
2831
[email protected]420ae012009-04-24 05:16:322832gfx::Rect TabContents::GetRootWindowResizerRect() const {
2833 if (delegate())
2834 return delegate()->GetRootWindowResizerRect();
2835 return gfx::Rect();
2836}
2837
2838void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2839 bool is_during_unload) {
2840 if (is_during_unload) {
2841 // Hang occurred while firing the beforeunload/unload handler.
2842 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112843 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322844
2845 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2846 return;
2847
2848 // If the tab hangs in the beforeunload/unload handler there's really
2849 // nothing we can do to recover. Pretend the unload listeners have
2850 // all fired and close the tab. If the hang is in the beforeunload handler
2851 // then the user will not have the option of cancelling the close.
2852 Close(rvh);
2853 return;
2854 }
2855
2856 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002857 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322858}
2859
2860void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002861 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322862}
2863
2864void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562865 net::LoadState load_state,
2866 uint64 upload_position,
2867 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322868 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562869 upload_position_ = upload_position;
2870 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292871 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192872 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292873 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532874 load_state_host_ =
2875 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322876 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2877 SetNotWaitingForResponse();
2878 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502879 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322880}
2881
[email protected]1ee614862009-07-06 20:29:182882bool TabContents::IsExternalTabContainer() const {
2883 if (!delegate())
2884 return false;
2885
2886 return delegate()->IsExternalTabContainer();
2887}
2888
[email protected]1ee614862009-07-06 20:29:182889void TabContents::DidInsertCSS() {
2890 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322891}
2892
[email protected]130efb02009-09-18 18:54:352893void TabContents::FocusedNodeChanged() {
2894 NotificationService::current()->Notify(
2895 NotificationType::FOCUS_CHANGED_IN_PAGE,
2896 Source<RenderViewHost>(render_view_host()),
2897 NotificationService::NoDetails());
2898}
2899
[email protected]ebf40a72010-07-22 01:46:382900void TabContents::SetDisplayingPDFContent() {
2901 displaying_pdf_content_ = true;
2902 if (delegate())
2903 delegate()->ContentTypeChanged(this);
2904}
2905
[email protected]420ae012009-04-24 05:16:322906void TabContents::FileSelected(const FilePath& path,
2907 int index, void* params) {
[email protected]35896a32010-06-09 08:42:512908 profile()->set_last_selected_directory(path.DirName());
[email protected]cdaf8d02010-03-30 19:52:472909 std::vector<FilePath> files;
2910 files.push_back(path);
2911 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322912}
2913
2914void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2915 void* params) {
[email protected]35896a32010-06-09 08:42:512916 if (!files.empty())
2917 profile()->set_last_selected_directory(files[0].DirName());
[email protected]cdaf8d02010-03-30 19:52:472918 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322919}
2920
2921void TabContents::FileSelectionCanceled(void* params) {
2922 // If the user cancels choosing a file to upload we pass back an
2923 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472924 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322925}
2926
2927void TabContents::BeforeUnloadFiredFromRenderManager(
2928 bool proceed,
2929 bool* proceed_to_fire_unload) {
2930 if (delegate())
2931 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2932}
2933
[email protected]3a3d47472010-07-15 21:03:542934void TabContents::DidStartLoadingFromRenderManager(
2935 RenderViewHost* render_view_host) {
2936 DidStartLoading();
2937}
2938
2939void TabContents::RenderViewGoneFromRenderManager(
2940 RenderViewHost* render_view_host) {
2941 RenderViewGone(render_view_host);
2942}
2943
[email protected]420ae012009-04-24 05:16:322944void TabContents::UpdateRenderViewSizeForRenderManager() {
2945 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262946 gfx::Size size = view_->GetContainerSize();
2947 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2948 // here during container initialization and normal window size will be set
2949 // later. In case of tab duplication this resizing to 0x0 prevents setting
2950 // normal size later so just ignore it.
2951 if (!size.IsEmpty())
2952 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322953}
2954
[email protected]3a3d47472010-07-15 21:03:542955void TabContents::NotifySwappedFromRenderManager() {
2956 NotifySwapped();
2957}
2958
2959NavigationController& TabContents::GetControllerForRenderManager() {
2960 return controller();
2961}
2962
[email protected]420ae012009-04-24 05:16:322963DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222964 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322965}
2966
2967NavigationEntry*
2968TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2969 return controller_.GetLastCommittedEntry();
2970}
2971
2972bool TabContents::CreateRenderViewForRenderManager(
2973 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322974 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522975
2976 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2977 if (!request_context.get())
2978 request_context = profile()->GetRequestContext();
2979
[email protected]8ab04652010-06-12 02:47:262980 if (!render_view_host->CreateRenderView(request_context, string16()))
[email protected]420ae012009-04-24 05:16:322981 return false;
2982
2983 // Now that the RenderView has been created, we need to tell it its size.
2984 rwh_view->SetSize(view_->GetContainerSize());
2985
2986 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2987 render_view_host);
2988 return true;
2989}
2990
2991void TabContents::Observe(NotificationType type,
2992 const NotificationSource& source,
2993 const NotificationDetails& details) {
2994 switch (type.value) {
2995 case NotificationType::BOOKMARK_MODEL_LOADED:
2996 // BookmarkModel finished loading, fall through to update starred state.
2997 case NotificationType::URLS_STARRED: {
2998 // Somewhere, a URL has been starred.
2999 // Ignore notifications for profiles other than our current one.
3000 Profile* source_profile = Source<Profile>(source).ptr();
3001 if (!source_profile || !source_profile->IsSameProfile(profile()))
3002 return;
3003
3004 UpdateStarredStateForCurrentURL();
3005 break;
3006 }
3007 case NotificationType::PREF_CHANGED: {
3008 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
3009 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3010 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3011 UpdateAlternateErrorPageURL();
3012 } else if (*pref_name_in == prefs::kDefaultCharset ||
3013 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
3014 ) {
3015 UpdateWebPreferences();
3016 } else {
3017 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3018 }
3019 break;
3020 }
3021 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3022 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3023 break;
3024
3025 case NotificationType::NAV_ENTRY_COMMITTED: {
3026 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3027
3028 NavigationController::LoadCommittedDetails& committed_details =
3029 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3030 ExpireInfoBars(committed_details);
3031 break;
3032 }
3033
[email protected]d3ba77272009-09-03 00:06:093034#if defined(OS_LINUX)
3035 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543036 renderer_preferences_util::UpdateFromSystemSettings(
3037 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093038 render_view_host()->SyncRendererPrefs();
3039 break;
3040 }
3041#endif
3042
[email protected]6c32ce72010-03-08 05:18:063043 case NotificationType::USER_STYLE_SHEET_UPDATED:
3044 UpdateWebPreferences();
3045 break;
3046
[email protected]79580c62010-02-02 02:36:253047 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293048 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253049 settings_details(details);
[email protected]79580c62010-02-02 02:36:253050 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493051 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293052 if (entry)
[email protected]da0c8e92010-02-09 23:25:493053 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293054 if (settings_details.ptr()->update_all() ||
3055 settings_details.ptr()->pattern().Matches(entry_url)) {
3056 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233057 profile()->GetHostContentSettingsMap()->
3058 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253059 }
3060 break;
3061 }
3062
[email protected]e5adff72010-06-14 18:13:063063 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573064 break;
[email protected]a888b29e62010-04-01 13:38:573065
3066 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063067 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573068 break;
[email protected]a888b29e62010-04-01 13:38:573069
[email protected]420ae012009-04-24 05:16:323070 default:
3071 NOTREACHED();
3072 }
3073}
[email protected]aacd7cc2009-09-02 14:51:103074
[email protected]98aa0b52010-05-06 17:03:083075void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3076 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433077
[email protected]a888b29e62010-04-01 13:38:573078 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083079 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3080 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573081 extension,
3082 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3083 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3084 Extension::EXTENSION_ICON_SMALLISH),
3085 ImageLoadingTracker::CACHE);
3086 } else {
[email protected]98aa0b52010-05-06 17:03:083087 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573088 }
3089}
3090
3091Extension* TabContents::GetExtensionContaining(const GURL& url) {
3092 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3093 if (!extensions_service)
3094 return NULL;
3095
3096 Extension* extension = extensions_service->GetExtensionByURL(url);
3097 return extension ?
3098 extension : extensions_service->GetExtensionByWebExtent(url);
3099}
3100
[email protected]a888b29e62010-04-01 13:38:573101void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3102 int index) {
3103 if (image) {
[email protected]98aa0b52010-05-06 17:03:083104 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573105 NotifyNavigationStateChanged(INVALIDATE_TAB);
3106 }
3107}
3108
[email protected]beb440c2009-11-06 04:08:543109std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3110 bool is_alert) {
3111 if (!frame_url.has_host())
3112 return l10n_util::GetString(
3113 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3114 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3115
3116 // We really only want the scheme, hostname, and port.
3117 GURL::Replacements replacements;
3118 replacements.ClearUsername();
3119 replacements.ClearPassword();
3120 replacements.ClearPath();
3121 replacements.ClearQuery();
3122 replacements.ClearRef();
3123 GURL clean_url = frame_url.ReplaceComponents(replacements);
3124
3125 // TODO(brettw) it should be easier than this to do the correct language
3126 // handling without getting the accept language from the profile.
3127 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
[email protected]ddd231e2010-06-29 20:35:193128 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages)));
[email protected]beb440c2009-11-06 04:08:543129 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563130 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543131
3132 return l10n_util::GetStringF(
3133 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3134 base_address);
3135}
3136
3137gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3138 return view_->GetTopLevelNativeWindow();
3139}
3140
3141void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3142 bool success,
3143 const std::wstring& prompt) {
3144 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3145 if (is_showing_before_unload_dialog_ && !success) {
3146 // If a beforeunload dialog is canceled, we need to stop the throbber from
3147 // spinning, since we forced it to start spinning in Navigate.
3148 DidStopLoading();
3149
3150 tab_close_start_time_ = base::TimeTicks();
3151 }
3152 is_showing_before_unload_dialog_ = false;
3153 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3154}
3155
3156void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3157 set_suppress_javascript_messages(suppress_message_boxes);
3158}
3159
[email protected]3a3d47472010-07-15 21:03:543160TabContents* TabContents::AsTabContents() {
3161 return this;
3162}
3163
3164ExtensionHost* TabContents::AsExtensionHost() {
3165 return NULL;
3166}
3167
[email protected]41fc0322009-09-04 22:23:403168void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103169 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3170}
[email protected]f45d2a72010-03-08 23:28:353171
3172void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3173 app_icon_ = app_icon;
3174 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3175}
[email protected]ea68c06a2010-04-23 17:25:373176
3177// After a successful *new* login attempt, we take the PasswordFormManager in
3178// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3179// the user makes up their mind with the "save password" infobar. Note if the
3180// login is one we already know about, the end of the line is
3181// provisional_save_manager_ because we just update it on success and so such
3182// forms never end up in an infobar.
3183class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3184 public:
3185 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463186 PasswordFormManager* form_to_save)
3187 : ConfirmInfoBarDelegate(tab_contents),
3188 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583189 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373190
[email protected]d75aba1d2010-08-02 23:35:583191 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373192
[email protected]d75aba1d2010-08-02 23:35:583193 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373194 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463195 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583196 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373197 delete this;
3198 }
3199
[email protected]d75aba1d2010-08-02 23:35:583200 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3201
[email protected]ea68c06a2010-04-23 17:25:373202 virtual std::wstring GetMessageText() const {
3203 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3204 }
3205
3206 virtual SkBitmap* GetIcon() const {
3207 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3208 IDR_INFOBAR_SAVE_PASSWORD);
3209 }
3210
3211 virtual int GetButtons() const {
3212 return BUTTON_OK | BUTTON_CANCEL;
3213 }
3214
3215 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3216 if (button == BUTTON_OK)
3217 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3218 if (button == BUTTON_CANCEL)
3219 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3220 NOTREACHED();
3221 return std::wstring();
3222 }
3223
3224 virtual bool Accept() {
3225 DCHECK(form_to_save_.get());
3226 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583227 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373228 return true;
3229 }
3230
3231 virtual bool Cancel() {
3232 DCHECK(form_to_save_.get());
3233 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583234 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373235 return true;
3236 }
[email protected]d75aba1d2010-08-02 23:35:583237 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373238
3239 private:
3240 // The PasswordFormManager managing the form we're asking the user about,
3241 // and should update as per her decision.
3242 scoped_ptr<PasswordFormManager> form_to_save_;
3243
[email protected]12bb6822010-06-16 02:00:463244 // Used to track the results we get from the info bar.
3245 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583246 NO_RESPONSE = 0,
3247 REMEMBER_PASSWORD,
3248 DONT_REMEMBER_PASSWORD,
3249 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463250 };
3251 ResponseType infobar_response_;
3252
[email protected]ea68c06a2010-04-23 17:25:373253 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3254};
3255
3256void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163257 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373258 render_view_host()->FillPasswordForm(form_data);
3259}
3260
3261void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3262 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3263}
3264
3265Profile* TabContents::GetProfileForPasswordManager() {
3266 return profile();
3267}
3268
3269bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3270 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3271}