blob: 2f3e743bfc32dc9a24de18c7b069142c2af7499e [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]96d185d2009-04-24 03:28:5426#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5527#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2928#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1029#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5430#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5432#include "chrome/browser/dom_ui/dom_ui.h"
33#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0234#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/download/download_manager.h"
36#include "chrome/browser/download/download_request_manager.h"
[email protected]e7eaedde2009-09-25 20:09:4937#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0838#include "chrome/browser/extensions/extensions_service.h"
[email protected]0189bc722009-08-28 21:56:4839#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5340#include "chrome/browser/find_bar_state.h"
[email protected]9d062b12010-04-14 09:36:5541#include "chrome/browser/geolocation/geolocation_content_settings_map.h"
[email protected]420ae012009-04-24 05:16:3242#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2543#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2644#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1445#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3246#include "chrome/browser/load_from_memory_cache_details.h"
47#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4448#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0549#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1050#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5751#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2452#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5753#include "chrome/browser/plugin_installer.h"
[email protected]052313b2010-02-19 09:43:0854#include "chrome/browser/pref_service.h"
[email protected]ce560f82009-06-03 09:39:4455#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0756#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1657#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5458#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3759#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5461#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3262#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1663#include "chrome/browser/search_engines/template_url_fetcher.h"
64#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1765#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1766#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5467#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1668#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4369#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1670#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]fdd61c62009-04-22 19:22:5771#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0272#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]449478302009-06-09 20:04:2873#include "chrome/browser/thumbnail_store.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5875#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2776#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4977#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5778#include "chrome/common/extensions/extension_action.h"
[email protected]bfd04a62009-02-01 18:16:5679#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2980#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3281#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1882#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5483#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3784#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2685#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3286#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0687#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3788#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3289#include "net/base/mime_util.h"
90#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2991#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3292#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1893#include "webkit/glue/password_form.h"
94#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0095
[email protected]420ae012009-04-24 05:16:3296// Cross-Site Navigations
97//
98// If a TabContents is told to navigate to a different web site (as determined
99// by SiteInstance), it will replace its current RenderViewHost with a new
100// RenderViewHost dedicated to the new SiteInstance. This works as follows:
101//
102// - Navigate determines whether the destination is cross-site, and if so,
103// it creates a pending_render_view_host_ and moves into the PENDING
104// RendererState.
105// - The pending RVH is "suspended," so that no navigation messages are sent to
106// its renderer until the onbeforeunload JavaScript handler has a chance to
107// run in the current RVH.
108// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
109// that it has a pending cross-site request. ResourceDispatcherHost will
110// check for this when the response arrives.
111// - The current RVH runs its onbeforeunload handler. If it returns false, we
112// cancel all the pending logic and go back to NORMAL. Otherwise we allow
113// the pending RVH to send the navigation request to its renderer.
114// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
115// checks CrossSiteRequestManager to see that the RVH responsible has a
116// pending cross-site request, and then installs a CrossSiteEventHandler.
117// - When RDH receives a response, the BufferedEventHandler determines whether
118// it is a download. If so, it sends a message to the new renderer causing
119// it to cancel the request, and the download proceeds in the download
120// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34121// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32122// doesn't affect any functionality.
123// - After RDH receives a response and determines that it is safe and not a
124// download, it pauses the response to first run the old page's onunload
125// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34126// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32127// to the current RVH.
128// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
129// the ResourceDispatcherHost, who unpauses the response. Data is then sent
130// to the pending RVH.
131// - The pending renderer sends a FrameNavigate message that invokes the
132// DidNavigate method. This replaces the current RVH with the
133// pending RVH and goes back to the NORMAL RendererState.
134
135namespace {
136
137// Amount of time we wait between when a key event is received and the renderer
138// is queried for its state and pushed to the NavigationEntry.
139const int kQueryStateDelay = 5000;
140
141const int kSyncWaitDelay = 40;
142
[email protected]304f8792009-08-19 21:28:09143#if defined(OS_CHROMEOS)
144// If a popup window is bigger than this fraction of the screen on chrome os,
145// turn it into a tab
146const float kMaxWidthFactor = 0.5;
147const float kMaxHeightFactor = 0.6;
148#endif
149
[email protected]420ae012009-04-24 05:16:32150// If another javascript message box is displayed within
151// kJavascriptMessageExpectedDelay of a previous javascript message box being
152// dismissed, display an option to suppress future message boxes from this
153// contents.
154const int kJavascriptMessageExpectedDelay = 1000;
155
[email protected]420ae012009-04-24 05:16:32156// The list of prefs we want to observe.
157const wchar_t* kPrefsToObserve[] = {
158 prefs::kAlternateErrorPagesEnabled,
159 prefs::kWebKitJavaEnabled,
160 prefs::kWebKitJavascriptEnabled,
161 prefs::kWebKitLoadsImagesAutomatically,
162 prefs::kWebKitPluginsEnabled,
163 prefs::kWebKitUsesUniversalDetector,
164 prefs::kWebKitSerifFontFamily,
165 prefs::kWebKitSansSerifFontFamily,
166 prefs::kWebKitFixedFontFamily,
167 prefs::kWebKitDefaultFontSize,
168 prefs::kWebKitDefaultFixedFontSize,
169 prefs::kDefaultCharset
170 // kWebKitStandardFontIsSerif needs to be added
171 // if we let users pick which font to use, serif or sans-serif when
172 // no font is specified or a CSS generic family (serif or sans-serif)
173 // is not specified.
174};
175
176const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
177
[email protected]420ae012009-04-24 05:16:32178// Returns true if the entry's transition type is FORM_SUBMIT.
179bool IsFormSubmit(const NavigationEntry* entry) {
180 return (PageTransition::StripQualifier(entry->transition_type()) ==
181 PageTransition::FORM_SUBMIT);
182}
183
184#if defined(OS_WIN)
185
186BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
187 // Note: erase is required to properly paint some widgets borders. This can
188 // be seen with textfields.
189 InvalidateRect(hwnd, NULL, TRUE);
190 return TRUE;
191}
192#endif
193
[email protected]5e369672009-11-03 23:48:30194ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16195 Profile* profile, const NavigationEntry& entry,
196 NavigationController::ReloadType reload_type) {
197 switch (reload_type) {
198 case NavigationController::RELOAD:
199 return ViewMsg_Navigate_Params::RELOAD;
200 case NavigationController::RELOAD_IGNORING_CACHE:
201 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
202 case NavigationController::NO_RELOAD:
203 break; // Fall through to rest of function.
204 }
[email protected]5e369672009-11-03 23:48:30205
206 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
207 profile->DidLastSessionExitCleanly())
208 return ViewMsg_Navigate_Params::RESTORE;
209
210 return ViewMsg_Navigate_Params::NORMAL;
211}
212
[email protected]3cc72b12010-03-18 23:03:00213void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16214 NavigationController::ReloadType reload_type,
215 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00216 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34217 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00218 params->pending_history_list_offset = controller.pending_entry_index();
219 params->current_history_list_offset = controller.last_committed_entry_index();
220 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34221 params->url = entry.url();
222 params->referrer = entry.referrer();
223 params->transition = entry.transition_type();
224 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00225 params->navigation_type =
226 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34227 params->request_time = base::Time::Now();
228}
229
[email protected]420ae012009-04-24 05:16:32230} // namespace
231
232// -----------------------------------------------------------------------------
233
[email protected]fdd61c62009-04-22 19:22:57234// static
235int TabContents::find_request_id_counter_ = -1;
236
[email protected]420ae012009-04-24 05:16:32237
[email protected]420ae012009-04-24 05:16:32238TabContents::TabContents(Profile* profile,
239 SiteInstance* site_instance,
240 int routing_id,
[email protected]34ac70502009-09-25 17:07:23241 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42242 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13243 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
244 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22245 TabContentsView::Create(this))),
246 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57247 property_bag_(),
248 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22249 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57250 save_package_(),
[email protected]6db0def92010-03-02 19:55:45251 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21252 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57253 password_manager_(),
254 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06255 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22256 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57257 select_file_dialog_(),
[email protected]d5f942ba2008-09-26 19:30:34258 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29259 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34260 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34261 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57262 current_load_start_(),
263 load_state_(net::LOAD_STATE_IDLE),
264 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56265 upload_size_(0),
266 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57267 received_page_title_(false),
268 is_starred_(false),
269 contents_mime_type_(),
270 encoding_(),
[email protected]332af7732009-03-11 13:21:35271 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49272 dont_notify_render_view_(false),
[email protected]fdd61c62009-04-22 19:22:57273 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57274 find_ui_active_(false),
275 find_op_aborted_(false),
276 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12277 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12278 last_search_result_(),
[email protected]a888b29e62010-04-01 13:38:57279 app_extension_(NULL),
280 app_extension_for_current_page_(NULL),
[email protected]fdd61c62009-04-22 19:22:57281 capturing_contents_(false),
282 is_being_destroyed_(false),
283 notify_disconnection_(false),
284 history_requests_(),
285#if defined(OS_WIN)
286 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
287#endif
288 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44289 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01290 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54291 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54292 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]3b1c1812010-02-12 21:53:55293 language_state_(&controller_) {
[email protected]0de80162010-02-03 04:52:35294 ClearBlockedContentSettings();
[email protected]7ff431e2010-01-07 18:18:54295 renderer_preferences_util::UpdateFromSystemSettings(
296 &renderer_preferences_, profile);
297
[email protected]16779842009-07-08 23:45:29298#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02299 // Make sure the thumbnailer is started before starting the render manager.
300 // The thumbnailer will want to listen for RVH creations, one of which will
301 // happen in RVHManager::Init.
302 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
303 if (generator)
304 generator->StartThumbnailing();
305#endif
306
[email protected]12636df2009-09-28 22:32:21307 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32308
[email protected]34ac70502009-09-25 17:07:23309 // We have the initial size of the view be based on the size of the passed in
310 // tab contents (normally a tab from the same window).
311 view_->CreateView(base_tab_contents ?
312 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32313
314 // Register for notifications about all interested prefs change.
315 PrefService* prefs = profile->GetPrefs();
316 if (prefs) {
317 for (int i = 0; i < kPrefsToObserveLength; ++i)
318 prefs->AddPrefObserver(kPrefsToObserve[i], this);
319 }
320
321 // Register for notifications about URL starredness changing on any profile.
322 registrar_.Add(this, NotificationType::URLS_STARRED,
323 NotificationService::AllSources());
324 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
325 NotificationService::AllSources());
326 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
327 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09328#if defined(OS_LINUX)
329 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
330 NotificationService::AllSources());
331#endif
[email protected]420ae012009-04-24 05:16:32332
[email protected]6c32ce72010-03-08 05:18:06333 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
334 NotificationService::AllSources());
335
[email protected]79580c62010-02-02 02:36:25336 // Register for notifications about content setting changes.
337 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
338 NotificationService::AllSources());
339
[email protected]a888b29e62010-04-01 13:38:57340 // Listen for extension changes so we can update extension_for_current_page_.
341 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
342 NotificationService::AllSources());
343 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
344 NotificationService::AllSources());
345 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
346 NotificationService::AllSources());
347
[email protected]c8865482009-07-23 20:40:10348 // Set-up the showing of the omnibox search infobar if applicable.
349 if (OmniboxSearchHint::IsEnabled(profile))
350 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35351}
initial.commit09911bf2008-07-26 23:55:29352
353TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32354 is_being_destroyed_ = true;
355
[email protected]bfe4c1582009-10-02 18:11:09356 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32357 registrar_.RemoveAll();
358
359 // Unregister the notifications of all observed prefs change.
360 PrefService* prefs = profile()->GetPrefs();
361 if (prefs) {
362 for (int i = 0; i < kPrefsToObserveLength; ++i)
363 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
364 }
365
[email protected]420ae012009-04-24 05:16:32366 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00367 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32368
[email protected]420ae012009-04-24 05:16:32369 // First cleanly close all child windows.
370 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
371 // some of these to close. CloseWindows is async, so it might get called
372 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49373 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32374
[email protected]8cc8d492010-02-02 10:40:49375 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13376 if (blocked_popups_)
377 blocked_popups_->Destroy();
378
[email protected]420ae012009-04-24 05:16:32379 // Notify any observer that have a reference on this tab contents.
380 NotificationService::current()->Notify(
381 NotificationType::TAB_CONTENTS_DESTROYED,
382 Source<TabContents>(this),
383 NotificationService::NoDetails());
384
[email protected]1e5e74f2009-05-27 20:55:12385 // Notify any lasting InfobarDelegates that have not yet been removed that
386 // whatever infobar they were handling in this TabContents has closed,
387 // because the TabContents is going away entirely.
388 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
389 // notification may trigger infobars calls that access their delegate. (and
390 // some implementations of InfoBarDelegate do delete themselves on
391 // InfoBarClosed()).
392 for (int i = 0; i < infobar_delegate_count(); ++i) {
393 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
394 delegate->InfoBarClosed();
395 }
396 infobar_delegates_.clear();
397
[email protected]420ae012009-04-24 05:16:32398 // TODO(brettw) this should be moved to the view.
399#if defined(OS_WIN)
400 // If we still have a window handle, destroy it. GetNativeView can return
401 // NULL if this contents was part of a window that closed.
402 if (GetNativeView())
403 ::DestroyWindow(GetNativeView());
404#endif
[email protected]7ab1e7d62009-10-14 23:32:01405
406 // OnCloseStarted isn't called in unit tests.
407 if (!tab_close_start_time_.is_null()) {
408 UMA_HISTOGRAM_TIMES("Tab.Close",
409 base::TimeTicks::Now() - tab_close_start_time_);
410 }
initial.commit09911bf2008-07-26 23:55:29411}
412
[email protected]d5f942ba2008-09-26 19:30:34413// static
414void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32415 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
416
417 WebPreferences pref_defaults;
418 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
419 pref_defaults.javascript_enabled);
420 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
421 pref_defaults.web_security_enabled);
422 prefs->RegisterBooleanPref(
423 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
424 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
425 pref_defaults.loads_images_automatically);
426 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
427 pref_defaults.plugins_enabled);
428 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
429 pref_defaults.dom_paste_enabled);
430 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
431 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08432 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:26433 UTF8ToWide(pref_defaults.inspector_settings));
[email protected]420ae012009-04-24 05:16:32434 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
435 pref_defaults.text_areas_are_resizable);
436 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
437 pref_defaults.java_enabled);
438
439 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
440 IDS_ACCEPT_LANGUAGES);
441 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
442 IDS_DEFAULT_ENCODING);
443 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
444 IDS_STANDARD_FONT_IS_SERIF);
445 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
446 IDS_FIXED_FONT_FAMILY);
447 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
448 IDS_SERIF_FONT_FAMILY);
449 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
450 IDS_SANS_SERIF_FONT_FAMILY);
451 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
452 IDS_CURSIVE_FONT_FAMILY);
453 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
454 IDS_FANTASY_FONT_FAMILY);
455 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
456 IDS_DEFAULT_FONT_SIZE);
457 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
458 IDS_DEFAULT_FIXED_FONT_SIZE);
459 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
460 IDS_MINIMUM_FONT_SIZE);
461 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
462 IDS_MINIMUM_LOGICAL_FONT_SIZE);
463 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
464 IDS_USES_UNIVERSAL_DETECTOR);
465 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
466 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29467}
468
[email protected]13367f72009-07-08 16:39:02469// Returns true if contains content rendered by an extension.
470bool TabContents::HostsExtension() const {
471 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34472}
473
[email protected]cf28ec52010-04-09 22:56:34474AutoFillManager* TabContents::GetAutoFillManager() {
475 if (autofill_manager_.get() == NULL)
476 autofill_manager_.reset(new AutoFillManager(this));
477 return autofill_manager_.get();
478}
479
[email protected]6e95706d2009-04-23 22:55:01480PasswordManager* TabContents::GetPasswordManager() {
481 if (password_manager_.get() == NULL)
482 password_manager_.reset(new PasswordManager(this));
483 return password_manager_.get();
484}
485
486PluginInstaller* TabContents::GetPluginInstaller() {
487 if (plugin_installer_.get() == NULL)
488 plugin_installer_.reset(new PluginInstaller(this));
489 return plugin_installer_.get();
490}
491
[email protected]8cb5d5b2010-02-09 11:36:16492RenderProcessHost* TabContents::GetRenderProcessHost() const {
493 return render_manager_.current_host()->process();
494}
495
[email protected]3b355642010-02-05 16:01:49496void TabContents::SetAppExtension(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46497 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]3b355642010-02-05 16:01:49498 app_extension_ = extension;
[email protected]fca656c2010-02-10 20:30:10499
[email protected]a888b29e62010-04-01 13:38:57500 UpdateAppExtensionIcon(app_extension_);
501
[email protected]fca656c2010-02-10 20:30:10502 NotificationService::current()->Notify(
503 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
504 Source<TabContents>(this),
505 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49506}
507
[email protected]911f8152010-03-18 16:46:40508void TabContents::SetAppExtensionById(const std::string& app_extension_id) {
509 if (app_extension_id.empty())
510 return;
511
512 ExtensionsService* extension_service = profile()->GetExtensionsService();
513 if (extension_service && extension_service->is_ready()) {
514 Extension* extension =
515 extension_service->GetExtensionById(app_extension_id, false);
516 if (extension)
517 SetAppExtension(extension);
518 }
519}
520
[email protected]8eb043b2010-04-30 07:19:51521SkBitmap* TabContents::GetAppExtensionIcon() {
522 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
523 // for those windows, we already have a big icon in the top-left outside any
524 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35525 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
526 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51527 return NULL;
[email protected]8eb043b2010-04-30 07:19:51528
529 if (app_extension_icon_.empty())
530 return NULL;
531
532 return &app_extension_icon_;
533}
534
[email protected]d5f942ba2008-09-26 19:30:34535const GURL& TabContents::GetURL() const {
536 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57537 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54538 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34539}
540
[email protected]96d185d2009-04-24 03:28:54541const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55542 // Transient entries take precedence. They are used for interstitial pages
543 // that are shown on top of existing pages.
544 NavigationEntry* entry = controller_.GetTransientEntry();
545 if (entry)
546 return entry->GetTitleForDisplay(&controller_);
547
[email protected]96d185d2009-04-24 03:28:54548 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
549 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
550 if (our_dom_ui) {
551 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55552 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54553 if (!(entry && entry->IsViewSourceMode())) {
554 // Give the DOM UI the chance to override our title.
555 const string16& title = our_dom_ui->overridden_title();
556 if (!title.empty())
557 return title;
558 }
559 }
560
561 // We use the title for the last committed entry rather than a pending
562 // navigation entry. For example, when the user types in a URL, we want to
563 // keep the old page's title until the new load has committed and we get a new
564 // title.
[email protected]96d185d2009-04-24 03:28:54565 entry = controller_.GetLastCommittedEntry();
566 if (entry)
567 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54568 return EmptyString16();
569}
570
[email protected]bbbc1ef2010-02-12 18:03:41571// static
572string16 TabContents::GetDefaultTitle() {
573 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
574}
575
[email protected]d5f942ba2008-09-26 19:30:34576int32 TabContents::GetMaxPageID() {
577 if (GetSiteInstance())
578 return GetSiteInstance()->max_page_id();
579 else
580 return max_page_id_;
581}
582
583void TabContents::UpdateMaxPageID(int32 page_id) {
584 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34585 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34586 // testing.
587 if (GetSiteInstance())
588 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16589 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34590}
591
[email protected]96d185d2009-04-24 03:28:54592SiteInstance* TabContents::GetSiteInstance() const {
593 return render_manager_.current_host()->site_instance();
594}
595
[email protected]96d185d2009-04-24 03:28:54596bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15597 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54598 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15599 if (entry && (entry->IsViewSourceMode() ||
600 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54601 return true;
[email protected]8ab24cc2009-11-13 20:56:15602 }
[email protected]83e3895b2009-06-11 00:07:16603
[email protected]96d185d2009-04-24 03:28:54604 DOMUI* dom_ui = GetDOMUIForCurrentState();
605 if (dom_ui)
606 return !dom_ui->should_hide_url();
607 return true;
608}
609
[email protected]d5f942ba2008-09-26 19:30:34610SkBitmap TabContents::GetFavIcon() const {
611 // Like GetTitle(), we also want to use the favicon for the last committed
612 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57613 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47614 if (entry)
615 return entry->favicon().bitmap();
616
[email protected]ce3fa3c2009-04-20 19:55:57617 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34618 if (entry)
619 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34620 return SkBitmap();
621}
622
[email protected]0b303cc2009-09-28 22:35:15623bool TabContents::FavIconIsValid() const {
624 NavigationEntry* entry = controller_.GetTransientEntry();
625 if (entry)
626 return entry->favicon().is_valid();
627
628 entry = controller_.GetLastCommittedEntry();
629 if (entry)
630 return entry->favicon().is_valid();
631
632 return false;
633}
634
[email protected]96d185d2009-04-24 03:28:54635bool TabContents::ShouldDisplayFavIcon() {
636 // Always display a throbber during pending loads.
637 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
638 return true;
639
640 DOMUI* dom_ui = GetDOMUIForCurrentState();
641 if (dom_ui)
642 return !dom_ui->hide_favicon();
643 return true;
644}
645
[email protected]2d5a3592010-01-30 04:29:52646bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
[email protected]8cc8d492010-02-02 10:40:49647 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
648 return blocked_popups_ != NULL;
649
[email protected]0de80162010-02-03 04:52:35650 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
651 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
[email protected]3dbb80b2010-02-09 22:41:20652 content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
653 content_type == CONTENT_SETTINGS_TYPE_COOKIES)
[email protected]0de80162010-02-03 04:52:35654 return content_blocked_[content_type];
655
[email protected]b1235062010-03-25 17:31:27656 // TODO(joth): remove once fully implemented.
657 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
658 return false;
659
[email protected]3dbb80b2010-02-09 22:41:20660 NOTREACHED();
[email protected]2d5a3592010-01-30 04:29:52661 return false;
662}
663
[email protected]96d185d2009-04-24 03:28:54664std::wstring TabContents::GetStatusText() const {
665 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
666 return std::wstring();
667
668 switch (load_state_) {
669 case net::LOAD_STATE_WAITING_FOR_CACHE:
670 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
671 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
672 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
673 case net::LOAD_STATE_RESOLVING_HOST:
674 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
675 case net::LOAD_STATE_CONNECTING:
676 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
677 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56678 if (upload_size_)
679 return l10n_util::GetStringF(
680 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
681 static_cast<int>((100 * upload_position_) / upload_size_));
682 else
683 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54684 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
685 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
686 load_state_host_);
687 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
688 case net::LOAD_STATE_IDLE:
689 case net::LOAD_STATE_READING_RESPONSE:
690 break;
691 }
692
693 return std::wstring();
694}
695
[email protected]d5f942ba2008-09-26 19:30:34696void TabContents::SetIsCrashed(bool state) {
697 if (state == is_crashed_)
698 return;
699
700 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50701 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34702}
703
[email protected]744ef172009-10-16 21:53:46704void TabContents::PageActionStateChanged() {
705 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00706}
[email protected]ce5c4502009-05-06 16:46:11707
[email protected]d5f942ba2008-09-26 19:30:34708void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
709 if (delegate_)
710 delegate_->NavigationStateChanged(this, changed_flags);
711}
712
[email protected]96d185d2009-04-24 03:28:54713void TabContents::DidBecomeSelected() {
714 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16715 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
716 if (rwhv) {
717 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43718#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16719 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43720#endif
721 }
[email protected]96d185d2009-04-24 03:28:54722
[email protected]8cb5d5b2010-02-09 11:36:16723 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54724}
725
726void TabContents::WasHidden() {
727 if (!capturing_contents()) {
728 // |render_view_host()| can be NULL if the user middle clicks a link to open
729 // a tab in then background, then closes the tab before selecting it. This
730 // is because closing the tab calls TabContents::Destroy(), which removes
731 // the |render_view_host()|; then when we actually destroy the window,
732 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16733 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
734 if (rwhv)
735 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54736 }
737
738 NotificationService::current()->Notify(
739 NotificationType::TAB_CONTENTS_HIDDEN,
740 Source<TabContents>(this),
741 NotificationService::NoDetails());
742}
743
[email protected]d5f942ba2008-09-26 19:30:34744void TabContents::Activate() {
745 if (delegate_)
746 delegate_->ActivateContents(this);
747}
748
[email protected]96d185d2009-04-24 03:28:54749void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16750 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
751 if (rwhv)
752 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54753}
754
755void TabContents::HideContents() {
756 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
757 // our superclass HideContents(), because some callers want to be very picky
758 // about the order in which these get called. In addition to making the code
759 // here practically impossible to understand, this also means we end up
760 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34761 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54762 WasHidden();
763}
764
[email protected]c0588052008-10-27 23:01:50765void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34766 WindowOpenDisposition disposition,
767 PageTransition::Type transition) {
768 if (delegate_)
[email protected]c0588052008-10-27 23:01:50769 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34770}
771
[email protected]1ccb3568d2010-02-19 10:51:16772bool TabContents::NavigateToPendingEntry(
773 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54774 const NavigationEntry& entry = *controller_.pending_entry();
775
776 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
777 if (!dest_render_view_host)
778 return false; // Unable to create the desired render view host.
779
[email protected]0352e5472010-04-29 00:11:40780 // For security, we should never send non-DOM-UI URLs (other than about:blank)
781 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58782 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40783 bool is_allowed_in_dom_ui_renderer =
784 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
785 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58786 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40787 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58788
[email protected]96d185d2009-04-24 03:28:54789 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12790 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32791 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00792 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
793 dest_render_view_host,
794 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32795 }
[email protected]96d185d2009-04-24 03:28:54796
797 // Used for page load time metrics.
798 current_load_start_ = base::TimeTicks::Now();
799
800 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34801 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00802 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34803 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54804
805 if (entry.page_id() == -1) {
806 // HACK!! This code suppresses javascript: URLs from being added to
807 // session history, which is what we want to do for javascript: URLs that
808 // do not generate content. What we really need is a message from the
809 // renderer telling us that a new page was not created. The same message
810 // could be used for mailto: URLs and the like.
811 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
812 return false;
813 }
814
815 // Clear any provisional password saves - this stops password infobars
816 // showing up on pages the user navigates to while the right page is
817 // loading.
818 GetPasswordManager()->ClearProvisionalSave();
819
[email protected]1ccb3568d2010-02-19 10:51:16820 if (reload_type != NavigationController::NO_RELOAD &&
821 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48822 FaviconService* favicon_service =
823 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
824 if (favicon_service)
825 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54826 }
827
[email protected]a888b29e62010-04-01 13:38:57828 // The url likely changed, see if there is an extension whose extent contains
829 // the current page.
830 UpdateAppExtensionForCurrentPage();
831
[email protected]d5f942ba2008-09-26 19:30:34832 return true;
833}
834
[email protected]96d185d2009-04-24 03:28:54835void TabContents::Stop() {
836 render_manager_.Stop();
837 printing_.Stop();
838}
839
[email protected]96d185d2009-04-24 03:28:54840void TabContents::DisassociateFromPopupCount() {
841 render_view_host()->DisassociateFromPopupCount();
842}
843
844TabContents* TabContents::Clone() {
845 // We create a new SiteInstance so that the new tab won't share processes
846 // with the old one. This can be changed in the future if we need it to share
847 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32848 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54849 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21850 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54851 tc->controller().CopyStateFrom(controller_);
[email protected]dda1abb2010-05-03 23:31:24852 tc->app_extension_ = app_extension_;
853 tc->app_extension_for_current_page_ = app_extension_for_current_page_;
854 tc->app_extension_icon_ = app_extension_icon_;
[email protected]96d185d2009-04-24 03:28:54855 return tc;
856}
857
[email protected]4d677202009-07-19 07:37:12858void TabContents::ShowPageInfo(const GURL& url,
859 const NavigationEntry::SSLStatus& ssl,
860 bool show_history) {
861 if (!delegate_)
862 return;
863
[email protected]bb678332009-07-21 00:15:50864 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12865}
866
initial.commit09911bf2008-07-26 23:55:29867ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28868 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29869 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28870 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29871 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44872
873 if (child_windows_.size() == 1) {
874 window->ShowConstrainedWindow();
875 BlockTabContent(true);
876 }
877
initial.commit09911bf2008-07-26 23:55:29878 return window;
879}
880
[email protected]fa1cf0b82010-01-15 21:49:44881void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55882 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
883 if (rwhv)
884 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44885 render_view_host()->set_ignore_input_events(blocked);
886 if (delegate_)
887 delegate_->SetTabContentBlocked(this, blocked);
888}
889
initial.commit09911bf2008-07-26 23:55:29890void TabContents::AddNewContents(TabContents* new_contents,
891 WindowOpenDisposition disposition,
892 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29893 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29894 if (!delegate_)
895 return;
896
[email protected]35f7d212009-04-29 21:19:27897 if ((disposition == NEW_POPUP) && !user_gesture &&
898 !CommandLine::ForCurrentProcess()->HasSwitch(
899 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22900 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31901 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29902 delegate_->GetConstrainingContents(this)->AddPopup(
903 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31904 } else {
[email protected]304f8792009-08-19 21:28:09905#if defined(OS_CHROMEOS)
906 if (disposition == NEW_POPUP) {
907 // If the popup is bigger than a given factor of the screen, then
908 // turn it into a foreground tab (on chrome os only)
909 GdkScreen* screen = gdk_screen_get_default();
910 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
911 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
912 if (initial_pos.width() > max_width ||
913 initial_pos.height() > max_height) {
914 disposition = NEW_FOREGROUND_TAB;
915 }
916 }
917#endif
918
[email protected]0aa55312008-10-17 21:53:08919 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29920 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
921 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49922 NotificationService::current()->Notify(
923 NotificationType::TAB_ADDED,
924 Source<TabContentsDelegate>(delegate_),
925 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29926 }
initial.commit09911bf2008-07-26 23:55:29927
[email protected]8cc8d492010-02-02 10:40:49928 // TODO(pkasting): Why is this necessary?
929 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29930}
931
[email protected]bcd9dc42010-01-23 16:38:18932bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20933 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20934 bool is_js_code, const std::string& code_string,
935 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51936 RenderViewHost* host = render_view_host();
937 if (!host)
938 return false;
939
940 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
941 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
942 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35943}
944
[email protected]96d185d2009-04-24 03:28:54945void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49946 if (is_being_destroyed_)
947 return;
948 if (!dont_notify_render_view_)
949 render_view_host()->PopupNotificationVisibilityChanged(visible);
[email protected]0de80162010-02-03 04:52:35950 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24951 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54952}
953
[email protected]5c9e97a2009-09-09 23:48:30954gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54955 return view_->GetContentNativeView();
956}
957
958gfx::NativeView TabContents::GetNativeView() const {
959 return view_->GetNativeView();
960}
961
962void TabContents::GetContainerBounds(gfx::Rect *out) const {
963 view_->GetContainerBounds(out);
964}
965
966void TabContents::Focus() {
967 view_->Focus();
968}
969
[email protected]90daadb42009-06-08 21:27:28970void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54971 if (showing_interstitial_page()) {
972 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
973 return;
974 }
[email protected]96d185d2009-04-24 03:28:54975 render_view_host()->SetInitialFocus(reverse);
976}
977
978bool TabContents::FocusLocationBarByDefault() {
979 DOMUI* dom_ui = GetDOMUIForCurrentState();
980 if (dom_ui)
981 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43982 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25983 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43984 return true;
[email protected]96d185d2009-04-24 03:28:54985 return false;
986}
987
[email protected]a26dc362010-04-23 01:48:58988void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:38989 if (delegate())
[email protected]a26dc362010-04-23 01:48:58990 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:38991}
992
[email protected]616ed5a2008-11-21 22:27:24993void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:32994 if (delegate_ && !delegate_->infobars_enabled()) {
995 delegate->InfoBarClosed();
996 return;
997 }
998
[email protected]616ed5a2008-11-21 22:27:24999 // Look through the existing InfoBarDelegates we have for a match. If we've
1000 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051001 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451002 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1003 // Tell the new infobar to close so that it can clean itself up.
1004 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241005 return;
[email protected]6d27a7b2009-12-18 23:25:451006 }
[email protected]616ed5a2008-11-21 22:27:241007 }
1008
1009 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561010 NotificationService::current()->Notify(
1011 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1012 Source<TabContents>(this),
1013 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241014
1015 // Add ourselves as an observer for navigations the first time a delegate is
1016 // added. We use this notification to expire InfoBars that need to expire on
1017 // page transitions.
1018 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561019 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571020 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241021 }
1022}
1023
1024void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321025 if (delegate_ && !delegate_->infobars_enabled()) {
1026 return;
1027 }
1028
[email protected]616ed5a2008-11-21 22:27:241029 std::vector<InfoBarDelegate*>::iterator it =
1030 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1031 if (it != infobar_delegates_.end()) {
1032 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561033 NotificationService::current()->Notify(
1034 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1035 Source<TabContents>(this),
1036 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051037 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241038
[email protected]6a02963e2009-01-06 16:58:031039 // Remove ourselves as an observer if we are tracking no more InfoBars.
1040 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561041 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571042 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031043 }
[email protected]616ed5a2008-11-21 22:27:241044 }
1045}
[email protected]3edd9522009-03-04 22:19:411046
[email protected]f81821c2009-08-07 01:29:471047void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1048 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321049 if (delegate_ && !delegate_->infobars_enabled()) {
1050 new_delegate->InfoBarClosed();
1051 return;
1052 }
1053
[email protected]f81821c2009-08-07 01:29:471054 std::vector<InfoBarDelegate*>::iterator it =
1055 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1056 DCHECK(it != infobar_delegates_.end());
1057
1058 // Notify the container about the change of plans.
1059 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1060 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1061 old_delegate, new_delegate));
1062 NotificationService::current()->Notify(
1063 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1064 Source<TabContents>(this),
1065 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1066
1067 // Remove the old one.
1068 infobar_delegates_.erase(it);
1069
1070 // Add the new one.
1071 infobar_delegates_.push_back(new_delegate);
1072}
1073
[email protected]20ede072009-10-06 00:28:351074bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271075 if (showing_interstitial_page())
1076 return false;
1077
[email protected]96d185d2009-04-24 03:28:541078 // See GetDOMUIForCurrentState() comment for more info. This case is very
1079 // similar, but for non-first loads, we want to use the committed entry. This
1080 // is so the bookmarks bar disappears at the same time the page does.
1081 if (controller_.GetLastCommittedEntry()) {
1082 // Not the first load, always use the committed DOM UI.
1083 if (render_manager_.dom_ui())
1084 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1085 return false; // Default.
1086 }
1087
1088 // When it's the first load, we know either the pending one or the committed
1089 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1090 // of them will be valid, so we can just check both.
1091 if (render_manager_.pending_dom_ui())
1092 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1093 if (render_manager_.dom_ui())
1094 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1095 return false; // Default.
1096}
1097
[email protected]d8f16ae2009-08-30 03:47:261098bool TabContents::IsExtensionShelfAlwaysVisible() {
1099 // See GetDOMUIForCurrentState() comment for more info. This case is very
1100 // similar, but for non-first loads, we want to use the committed entry. This
1101 // is so the bookmarks bar disappears at the same time the page does.
1102 if (controller_.GetLastCommittedEntry()) {
1103 // Not the first load, always use the committed DOM UI.
1104 if (render_manager_.dom_ui())
1105 return render_manager_.dom_ui()->force_extension_shelf_visible();
1106 return false; // Default.
1107 }
1108
1109 // When it's the first load, we know either the pending one or the committed
1110 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1111 // of them will be valid, so we can just check both.
1112 if (render_manager_.pending_dom_ui())
1113 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1114 if (render_manager_.dom_ui())
1115 return render_manager_.dom_ui()->force_extension_shelf_visible();
1116 return false; // Default.
1117}
1118
[email protected]3edd9522009-03-04 22:19:411119void TabContents::ToolbarSizeChanged(bool is_animating) {
1120 TabContentsDelegate* d = delegate();
1121 if (d)
1122 d->ToolbarSizeChanged(this, is_animating);
1123}
[email protected]616ed5a2008-11-21 22:27:241124
[email protected]fc6fb7fb2009-11-07 02:35:041125bool TabContents::CanDownload(int request_id) {
1126 TabContentsDelegate* d = delegate();
1127 if (d)
1128 return d->CanDownload(request_id);
1129 return true;
1130}
1131
[email protected]d5f942ba2008-09-26 19:30:341132void TabContents::OnStartDownload(DownloadItem* download) {
1133 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341134
1135 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311136 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341137
[email protected]c70f9b82010-04-21 07:31:111138 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221139 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111140 // If the download occurs in a new tab, close it
1141 if (controller_.IsInitialNavigation() && (tab_contents == this))
1142 delegate()->CloseContents(this);
1143 }
[email protected]3edd9522009-03-04 22:19:411144}
[email protected]3edd9522009-03-04 22:19:411145
[email protected]d5f942ba2008-09-26 19:30:341146void TabContents::WillClose(ConstrainedWindow* window) {
1147 ConstrainedWindowList::iterator it =
1148 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441149 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341150 if (it != child_windows_.end())
1151 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371152 if (child_windows_.size() > 0) {
1153 if (removed_topmost_window) {
1154 child_windows_[0]->ShowConstrainedWindow();
1155 }
[email protected]fa1cf0b82010-01-15 21:49:441156 BlockTabContent(true);
1157 } else {
1158 BlockTabContent(false);
1159 }
[email protected]66ba4932009-06-04 19:22:131160}
[email protected]d5f942ba2008-09-26 19:30:341161
[email protected]66ba4932009-06-04 19:22:131162void TabContents::WillCloseBlockedPopupContainer(
1163 BlockedPopupContainer* container) {
1164 DCHECK(blocked_popups_ == container);
1165 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491166 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341167}
1168
[email protected]d5f942ba2008-09-26 19:30:341169void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351170#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061171 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351172#endif
[email protected]d5f942ba2008-09-26 19:30:341173}
1174
[email protected]c1dc9f132009-11-20 23:13:211175void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121176 bool forward_direction,
1177 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211178 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011179 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211180 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531181 string16 last_search_prepopulate_text =
1182 FindBarState::GetLastPrepopulateText(profile());
1183
[email protected]87fae512009-12-11 02:20:211184 // Try the last thing we searched for on this tab, then the last thing
1185 // searched for on any tab.
1186 if (!previous_find_text_.empty())
1187 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531188 else if (!last_search_prepopulate_text.empty())
1189 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211190 else
[email protected]e491f1c2009-05-22 20:28:121191 return;
[email protected]e491f1c2009-05-22 20:28:121192 }
[email protected]6e95706d2009-04-23 22:55:011193
[email protected]101c90e2009-10-26 21:14:441194 // Keep track of the previous search.
1195 previous_find_text_ = find_text_;
1196
[email protected]6e95706d2009-04-23 22:55:011197 // This is a FindNext operation if we are searching for the same text again,
1198 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1199 // exception to this is if the Find was aborted (then we don't want FindNext
1200 // because the highlighting has been cleared and we need it to reappear). We
1201 // therefore treat FindNext after an aborted Find operation as a full fledged
1202 // Find.
[email protected]c1dc9f132009-11-20 23:13:211203 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121204 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011205 !find_op_aborted_;
1206 if (!find_next)
1207 current_find_request_id_ = find_request_id_counter_++;
1208
[email protected]c1dc9f132009-11-20 23:13:211209 if (!search_string.empty())
1210 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121211 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011212
1213 find_op_aborted_ = false;
1214
1215 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531216 FindBarState* find_bar_state = profile()->GetFindBarState();
1217 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011218 render_view_host()->StartFinding(current_find_request_id_,
1219 find_text_,
1220 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121221 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011222 find_next);
1223}
1224
[email protected]5bc8fe92010-03-11 18:19:001225void TabContents::StopFinding(
1226 FindBarController::SelectionAction selection_action) {
1227 // When the action is kClearAction, it means the find string has been cleared
[email protected]2d2dffc2009-06-09 21:41:001228 // by the user, but the UI has not been dismissed.
[email protected]5bc8fe92010-03-11 18:19:001229 if (selection_action != FindBarController::kClearSelection)
[email protected]2d2dffc2009-06-09 21:41:001230 find_ui_active_ = false;
[email protected]726bdbd72010-04-05 17:08:071231 if (!find_text_.empty())
1232 previous_find_text_ = find_text_;
[email protected]101c90e2009-10-26 21:14:441233 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011234 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121235 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001236 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011237}
1238
[email protected]420ae012009-04-24 05:16:321239void TabContents::OnSavePage() {
1240 // If we can not save the page, try to download it.
1241 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1242 DownloadManager* dlm = profile()->GetDownloadManager();
1243 const GURL& current_page_url = GetURL();
1244 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221245 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321246 return;
1247 }
1248
1249 Stop();
1250
1251 // Create the save package and possibly prompt the user for the name to save
1252 // the page as. The user prompt is an asynchronous operation that runs on
1253 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221254 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321255 save_package_->GetSaveInfo();
1256}
1257
1258// Used in automated testing to bypass prompting the user for file names.
1259// Instead, the names and paths are hard coded rather than running them through
1260// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111261bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321262 SavePackage::SavePackageType save_type) {
1263 // Stop the page from navigating.
1264 Stop();
1265
[email protected]828cabe2009-09-26 22:47:111266 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591267 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321268}
1269
[email protected]89d6e6e2009-12-03 23:06:511270void TabContents::EmailPageLocation() {
1271 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1272 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1273 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1274 title + "&body=%0A%0A" + page_url;
1275 platform_util::OpenExternal(GURL(mailto));
1276}
1277
[email protected]420ae012009-04-24 05:16:321278void TabContents::PrintPreview() {
1279 // We don't show the print preview yet, only the print dialog.
1280 PrintNow();
1281}
1282
1283bool TabContents::PrintNow() {
1284 // We can't print interstitial page for now.
1285 if (showing_interstitial_page())
1286 return false;
1287
1288 return render_view_host()->PrintPages();
1289}
1290
[email protected]82270452009-06-19 15:58:011291void TabContents::PrintingDone(int document_cookie, bool success) {
1292 render_view_host()->PrintingDone(document_cookie, success);
1293}
1294
[email protected]420ae012009-04-24 05:16:321295bool TabContents::IsActiveEntry(int32 page_id) {
1296 NavigationEntry* active_entry = controller_.GetActiveEntry();
1297 return (active_entry != NULL &&
1298 active_entry->site_instance() == GetSiteInstance() &&
1299 active_entry->page_id() == page_id);
1300}
1301
[email protected]b2fe07d12010-02-09 14:38:081302void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161303 set_encoding(encoding);
1304 render_view_host()->SetPageEncoding(encoding);
1305}
1306
[email protected]b2fe07d12010-02-09 14:38:081307void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161308 reset_encoding();
1309 render_view_host()->ResetPageEncodingToDefault();
1310}
1311
1312void TabContents::WindowMoveOrResizeStarted() {
1313 render_view_host()->WindowMoveOrResizeStarted();
1314}
1315
[email protected]3f8eb7f2009-10-02 23:58:051316void TabContents::LogNewTabTime(const std::string& event_name) {
1317 // Not all new tab pages get timed. In those cases, we don't have a
1318 // new_tab_start_time_.
1319 if (new_tab_start_time_.is_null())
1320 return;
1321
1322 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441323 MetricEventDurationDetails details(event_name,
1324 static_cast<int>(duration.InMilliseconds()));
1325
[email protected]7ab1e7d62009-10-14 23:32:011326 if (event_name == "Tab.NewTabScriptStart") {
1327 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1328 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1329 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1330 } else if (event_name == "Tab.NewTabOnload") {
1331 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051332 // The new tab page has finished loading; reset it.
1333 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441334 } else {
1335 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051336 }
[email protected]84abba62009-10-07 17:01:441337 NotificationService::current()->Notify(
1338 NotificationType::METRIC_EVENT_DURATION,
1339 Source<TabContents>(this),
1340 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051341}
1342
[email protected]7ab1e7d62009-10-14 23:32:011343void TabContents::OnCloseStarted() {
1344 if (tab_close_start_time_.is_null())
1345 tab_close_start_time_ = base::TimeTicks::Now();
1346}
1347
[email protected]c37e3b62010-01-22 00:15:171348TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171349 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161350
1351 NavigationEntry* entry = controller().GetActiveEntry();
1352 if (app_extension_)
[email protected]b6ea7412010-05-04 23:26:471353 tab_nav.set_virtual_url(app_extension_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161354 else if (entry)
1355 tab_nav.SetFromNavigationEntry(*entry);
1356
[email protected]c37e3b62010-01-22 00:15:171357 std::vector<TabNavigation> navigations;
1358 navigations.push_back(tab_nav);
1359
1360 TabContents* new_contents =
1361 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]3b355642010-02-05 16:01:491362 new_contents->SetAppExtension(app_extension_);
[email protected]c37e3b62010-01-22 00:15:171363 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171364
[email protected]df72ac72010-02-06 00:43:161365 if (!app_extension_ && entry)
1366 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1367
[email protected]c37e3b62010-01-22 00:15:171368 return new_contents;
1369}
1370
[email protected]0de80162010-02-03 04:52:351371// Resets the |content_blocked_| array.
1372void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491373 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351374 content_blocked_[i] = false;
1375}
1376
[email protected]614c0e12010-03-25 10:12:561377// Resets the |geolocation_settings_| map.
[email protected]9d062b12010-04-14 09:36:551378void TabContents::ClearGeolocationContentSettings(
1379 const NavigationController::LoadCommittedDetails& details) {
1380 if (!geolocation_content_settings_.empty()) {
1381 // Clear the geolocation settings only if we're going to a new origin,
1382 // or if we're staying at the same origin and its setting is ASK.
1383 // This is to prevent clearing the icon by just changing some URL param.
1384 // TODO(bulach): refactor this logic into its own class and remove the
1385 // duplication from ContentSettingDomainListBubbleModel.
1386 if (!details.entry ||
1387 details.previous_url.GetOrigin() != details.entry->url().GetOrigin() ||
1388 (details.entry->url().is_valid() &&
1389 profile()->GetGeolocationContentSettingsMap()->GetContentSetting(
1390 details.entry->url(), details.entry->url()) ==
1391 CONTENT_SETTING_ASK)) {
1392 geolocation_content_settings_.clear();
1393 }
1394 }
[email protected]614c0e12010-03-25 10:12:561395}
1396
[email protected]96d185d2009-04-24 03:28:541397// Notifies the RenderWidgetHost instance about the fact that the page is
1398// loading, or done loading and calls the base implementation.
1399void TabContents::SetIsLoading(bool is_loading,
1400 LoadNotificationDetails* details) {
1401 if (is_loading == is_loading_)
1402 return;
1403
1404 if (!is_loading) {
1405 load_state_ = net::LOAD_STATE_IDLE;
1406 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561407 upload_size_ = 0;
1408 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541409 }
1410
1411 render_manager_.SetIsLoading(is_loading);
1412
1413 is_loading_ = is_loading;
1414 waiting_for_response_ = is_loading;
1415
1416 if (delegate_)
1417 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351418 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541419
1420 NotificationType type = is_loading ? NotificationType::LOAD_START :
1421 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111422 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541423 if (details)
1424 det = Details<LoadNotificationDetails>(details);
1425 NotificationService::current()->Notify(type,
1426 Source<NavigationController>(&controller_),
1427 det);
1428}
1429
[email protected]b6c874582009-05-08 19:38:311430void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291431 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061432 // A page can't spawn popups (or do anything else, either) until its load
1433 // commits, so when we reach here, the popup was spawned by the
1434 // NavigationController's last committed entry, not the active entry. For
1435 // example, if a page opens a popup in an onunload() handler, then the active
1436 // entry is the page to be loaded as we navigate away from the unloading
1437 // page. For this reason, we can't use GetURL() to get the opener URL,
1438 // because it returns the active entry.
1439 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1440 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1441
1442 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491443 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061444 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491445 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1446 } else {
1447 if (!blocked_popups_)
1448 blocked_popups_ = new BlockedPopupContainer(this);
1449 blocked_popups_->AddTabContents(new_contents, initial_pos);
1450 }
[email protected]b9681312008-11-07 00:08:261451}
[email protected]616ed5a2008-11-21 22:27:241452
1453namespace {
1454bool TransitionIsReload(PageTransition::Type transition) {
1455 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1456}
1457}
1458
1459void TabContents::ExpireInfoBars(
1460 const NavigationController::LoadCommittedDetails& details) {
1461 // Only hide InfoBars when the user has done something that makes the main
1462 // frame load. We don't want various automatic or subframe navigations making
1463 // it disappear.
1464 if (!details.is_user_initiated_main_frame_load())
1465 return;
1466
[email protected]f86a07022008-11-25 01:06:051467 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241468 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051469 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241470 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241471 }
1472}
[email protected]fdd61c62009-04-22 19:22:571473
[email protected]96d185d2009-04-24 03:28:541474DOMUI* TabContents::GetDOMUIForCurrentState() {
1475 // When there is a pending navigation entry, we want to use the pending DOMUI
1476 // that goes along with it to control the basic flags. For example, we want to
1477 // show the pending URL in the URL bar, so we want the display_url flag to
1478 // be from the pending entry.
1479 //
1480 // The confusion comes because there are multiple possibilities for the
1481 // initial load in a tab as a side effect of the way the RenderViewHostManager
1482 // works.
1483 //
1484 // - For the very first tab the load looks "normal". The new tab DOM UI is
1485 // the pending one, and we want it to apply here.
1486 //
1487 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1488 // get switched to the one previously associated with the new tab pages.
1489 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1490 // have a committed DOM UI in this case.
1491 //
1492 // This condition handles all of these cases:
1493 //
1494 // - First load in first tab: no committed nav entry + pending nav entry +
1495 // pending dom ui:
1496 // -> Use pending DOM UI if any.
1497 //
1498 // - First load in second tab: no committed nav entry + pending nav entry +
1499 // no pending DOM UI:
1500 // -> Use the committed DOM UI if any.
1501 //
1502 // - Second navigation in any tab: committed nav entry + pending nav entry:
1503 // -> Use pending DOM UI if any.
1504 //
1505 // - Normal state with no load: committed nav entry + no pending nav entry:
1506 // -> Use committed DOM UI.
1507 if (controller_.pending_entry() &&
1508 (controller_.GetLastCommittedEntry() ||
1509 render_manager_.pending_dom_ui()))
1510 return render_manager_.pending_dom_ui();
1511 return render_manager_.dom_ui();
1512}
[email protected]420ae012009-04-24 05:16:321513
1514void TabContents::DidNavigateMainFramePostCommit(
1515 const NavigationController::LoadCommittedDetails& details,
1516 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441517 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1518 // If this is a window.open navigation, use the same DOMUI as the renderer
1519 // that opened the window, as long as both renderers have the same
1520 // privileges.
1521 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1522 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1523 // dom_ui might be NULL if the URL refers to a non-existent extension.
1524 if (dom_ui) {
1525 render_manager_.SetDOMUIPostCommit(dom_ui);
1526 dom_ui->RenderViewCreated(render_view_host());
1527 }
1528 }
1529 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1530 }
1531
[email protected]420ae012009-04-24 05:16:321532 if (details.is_user_initiated_main_frame_load()) {
1533 // Clear the status bubble. This is a workaround for a bug where WebKit
1534 // doesn't let us know that the cursor left an element during a
1535 // transition (this is also why the mouse cursor remains as a hand after
1536 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1537 // clear the bubble when a user navigates to a named anchor in the same
1538 // page.
1539 UpdateTargetURL(details.entry->page_id(), GURL());
1540
1541 // UpdateHelpersForDidNavigate will handle the case where the password_form
1542 // origin is valid.
1543 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1544 // cleaned up and covered by tests.
1545 if (!params.password_form.origin.is_valid())
1546 GetPasswordManager()->DidNavigate();
1547 }
1548
1549 // The keyword generator uses the navigation entries, so must be called after
1550 // the commit.
1551 GenerateKeywordIfNecessary(params);
1552
1553 // Allow the new page to set the title again.
1554 received_page_title_ = false;
1555
1556 // Get the favicon, either from history or request it from the net.
1557 fav_icon_helper_.FetchFavIcon(details.entry->url());
1558
[email protected]0de80162010-02-03 04:52:351559 // Clear all page actions, blocked content notifications and browser actions
1560 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141561 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081562 ExtensionsService* service = profile()->GetExtensionsService();
1563 if (service) {
1564 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571565 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081566 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521567 if (browser_action) {
1568 browser_action->ClearAllValuesForTab(controller().session_id().id());
1569 NotificationService::current()->Notify(
1570 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571571 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521572 NotificationService::NoDetails());
1573 }
[email protected]92c6f9b92009-10-24 04:35:081574
[email protected]5d246db22009-10-27 06:17:571575 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521576 service->extensions()->at(i)->page_action();
1577 if (page_action) {
1578 page_action->ClearAllValuesForTab(controller().session_id().id());
1579 PageActionStateChanged();
1580 }
[email protected]92c6f9b92009-10-24 04:35:081581 }
[email protected]aece2c7f2009-08-27 20:43:171582 }
[email protected]0de80162010-02-03 04:52:351583
1584 // Close blocked popups.
1585 if (blocked_popups_) {
1586 AutoReset auto_reset(&dont_notify_render_view_, true);
1587 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461588 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351589 }
1590
1591 // Clear "blocked" flags.
1592 ClearBlockedContentSettings();
[email protected]9d062b12010-04-14 09:36:551593 ClearGeolocationContentSettings(details);
[email protected]0de80162010-02-03 04:52:351594 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241595 delegate_->OnContentSettingsChange(this);
[email protected]aece2c7f2009-08-27 20:43:171596 }
[email protected]ce5c4502009-05-06 16:46:111597
[email protected]8cc8d492010-02-02 10:40:491598 // Close constrained windows if necessary.
1599 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1600 details.previous_url, details.entry->url()))
1601 CloseConstrainedWindows();
1602
[email protected]420ae012009-04-24 05:16:321603 // Update the starred state.
1604 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531605
1606 // Clear the cache of forms in AutoFill.
1607 if (autofill_manager_.get())
1608 autofill_manager_->Reset();
[email protected]a888b29e62010-04-01 13:38:571609
1610 // The url likely changed, see if there is an extension whose extent contains
1611 // the current page.
1612 UpdateAppExtensionForCurrentPage();
[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."
1729 std::wstring final_title;
1730 bool explicit_set;
1731 if (entry->url().SchemeIsFile() && title.empty()) {
1732 final_title = UTF8ToWide(entry->url().ExtractFileName());
1733 explicit_set = false; // Don't count synthetic titles toward the set limit.
1734 } else {
1735 TrimWhitespace(title, TRIM_ALL, &final_title);
1736 explicit_set = true;
1737 }
1738
1739 if (final_title == UTF16ToWideHack(entry->title()))
1740 return false; // Nothing changed, don't bother.
1741
1742 entry->set_title(WideToUTF16Hack(final_title));
1743
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.
1756 view_->SetPageTitle(final_title);
1757
[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;
1836 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1837 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);
1851 new_url->SetURL(url, 0, 0);
1852 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.
1872 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1873 if (drm)
1874 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491875 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331876 controller_.OnUserGesture();
1877}
1878
1879void TabContents::OnFindReply(int request_id,
1880 int number_of_matches,
1881 const gfx::Rect& selection_rect,
1882 int active_match_ordinal,
1883 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421884 // Ignore responses for requests that have been aborted.
1885 if (find_op_aborted_)
1886 return;
1887
[email protected]bf5c2ff392009-07-08 16:24:331888 // Ignore responses for requests other than the one we have most recently
1889 // issued. That way we won't act on stale results when the user has
1890 // already typed in another query.
1891 if (request_id != current_find_request_id_)
1892 return;
1893
1894 if (number_of_matches == -1)
1895 number_of_matches = last_search_result_.number_of_matches();
1896 if (active_match_ordinal == -1)
1897 active_match_ordinal = last_search_result_.active_match_ordinal();
1898
1899 gfx::Rect selection = selection_rect;
1900 if (selection.IsEmpty())
1901 selection = last_search_result_.selection_rect();
1902
1903 // Notify the UI, automation and any other observers that a find result was
1904 // found.
1905 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1906 selection, active_match_ordinal,
1907 final_update);
1908 NotificationService::current()->Notify(
1909 NotificationType::FIND_RESULT_AVAILABLE,
1910 Source<TabContents>(this),
1911 Details<FindNotificationDetails>(&last_search_result_));
1912}
1913
1914void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381915 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1916 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331917}
1918
[email protected]bf5c2ff392009-07-08 16:24:331919void TabContents::OnMissingPluginStatus(int status) {
1920#if defined(OS_WIN)
1921// TODO(PORT): pull in when plug-ins work
1922 GetPluginInstaller()->OnMissingPluginStatus(status);
1923#endif
1924}
1925
1926void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331927 DCHECK(!plugin_path.value().empty());
1928
1929 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351930#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331931 scoped_ptr<FileVersionInfo> version_info(
1932 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1933 if (version_info.get()) {
1934 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371935 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331936 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371937#if defined(OS_MACOSX)
1938 // Many plugins on the Mac have .plugin in the actual name, which looks
1939 // terrible, so look for that and strip it off if present.
1940 const std::wstring plugin_extension(L".plugin");
1941 if (EndsWith(plugin_name, plugin_extension, true))
1942 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1943#endif // OS_MACOSX
1944 }
[email protected]bf5c2ff392009-07-08 16:24:331945 }
[email protected]4a560ed2009-07-13 23:35:261946#else
1947 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1948#endif
[email protected]bf5c2ff392009-07-08 16:24:331949 AddInfoBar(new SimpleAlertInfoBarDelegate(
1950 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]938e1f92010-04-01 18:09:421951 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331952}
1953
1954void TabContents::OnCrashedWorker() {
1955 AddInfoBar(new SimpleAlertInfoBarDelegate(
1956 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421957 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331958}
1959
1960void TabContents::OnDidGetApplicationInfo(
1961 int32 page_id,
1962 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511963 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331964
[email protected]ed5431872009-11-17 08:39:511965 if (delegate())
1966 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331967}
1968
[email protected]a2cf65eb2010-01-18 08:20:381969void TabContents::OnPageContents(const GURL& url,
1970 int renderer_process_id,
1971 int32 page_id,
[email protected]a8a81292010-01-21 00:32:451972 const std::wstring& contents,
1973 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381974 // Don't index any https pages. People generally don't want their bank
1975 // accounts, etc. indexed on their computer, especially since some of these
1976 // things are not marked cachable.
1977 // TODO(brettw) we may want to consider more elaborate heuristics such as
1978 // the cachability of the page. We may also want to consider subframes (this
1979 // test will still index subframes if the subframe is SSL).
1980 if (!url.SchemeIsSecure()) {
1981 Profile* p = profile();
1982 if (p && !p->IsOffTheRecord()) {
1983 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1984 if (hs)
1985 hs->SetPageContents(url, contents);
1986 }
1987 }
[email protected]a8a81292010-01-21 00:32:451988
[email protected]3b1c1812010-02-12 21:53:551989 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451990
1991 std::string lang = language;
1992 NotificationService::current()->Notify(
1993 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151994 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451995 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:381996}
1997
[email protected]7e0831b2010-02-01 08:45:151998void TabContents::OnPageTranslated(int32 page_id,
1999 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162000 const std::string& translated_lang,
2001 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552002 language_state_.set_current_language(translated_lang);
2003 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162004 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152005 NotificationService::current()->Notify(
2006 NotificationType::PAGE_TRANSLATED,
2007 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162008 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152009}
2010
[email protected]bf5c2ff392009-07-08 16:24:332011void TabContents::DidStartProvisionalLoadForFrame(
2012 RenderViewHost* render_view_host,
2013 bool is_main_frame,
2014 const GURL& url) {
2015 ProvisionalLoadDetails details(is_main_frame,
2016 controller_.IsURLInPageNavigation(url),
2017 url, std::string(), false);
2018 NotificationService::current()->Notify(
2019 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2020 Source<NavigationController>(&controller_),
2021 Details<ProvisionalLoadDetails>(&details));
2022}
2023
2024void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202025 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332026 NotificationService::current()->Notify(
2027 NotificationType::RESOURCE_RESPONSE_STARTED,
2028 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202029 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332030}
2031
[email protected]3dbb80b2010-02-09 22:41:202032void TabContents::DidRedirectResource(
2033 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332034 NotificationService::current()->Notify(
2035 NotificationType::RESOURCE_RECEIVED_REDIRECT,
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
2040void TabContents::DidLoadResourceFromMemoryCache(
2041 const GURL& url,
2042 const std::string& frame_origin,
2043 const std::string& main_frame_origin,
2044 const std::string& security_info) {
2045 // Send out a notification that we loaded a resource from our memory cache.
2046 int cert_id = 0, cert_status = 0, security_bits = 0;
2047 SSLManager::DeserializeSecurityInfo(security_info,
2048 &cert_id, &cert_status,
2049 &security_bits);
2050 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162051 GetRenderProcessHost()->id(), cert_id,
2052 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332053
2054 NotificationService::current()->Notify(
2055 NotificationType::LOAD_FROM_MEMORY_CACHE,
2056 Source<NavigationController>(&controller_),
2057 Details<LoadFromMemoryCacheDetails>(&details));
2058}
2059
[email protected]e3d60e5d2009-09-25 21:08:292060void TabContents::DidDisplayInsecureContent() {
[email protected]09843b5f2009-09-26 08:30:592061 controller_.ssl_manager()->DidDisplayInsecureContent();
[email protected]e3d60e5d2009-09-25 21:08:292062}
2063
2064void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592065 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292066}
2067
[email protected]bf5c2ff392009-07-08 16:24:332068void TabContents::DidFailProvisionalLoadWithError(
2069 RenderViewHost* render_view_host,
2070 bool is_main_frame,
2071 int error_code,
2072 const GURL& url,
2073 bool showing_repost_interstitial) {
2074 if (net::ERR_ABORTED == error_code) {
2075 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2076 // This means that the interstitial won't be torn down properly, which is
2077 // bad. But if we have an interstitial, go back to another tab type, and
2078 // then load the same interstitial again, we could end up getting the first
2079 // interstitial's "failed" message (as a result of the cancel) when we're on
2080 // the second one.
2081 //
2082 // We can't tell this apart, so we think we're tearing down the current page
2083 // which will cause a crash later one. There is also some code in
2084 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2085 // out because of this problem.
2086 //
2087 // http://code.google.com/p/chromium/issues/detail?id=2855
2088 // Because this will not tear down the interstitial properly, if "back" is
2089 // back to another tab type, the interstitial will still be somewhat alive
2090 // in the previous tab type. If you navigate somewhere that activates the
2091 // tab with the interstitial again, you'll see a flash before the new load
2092 // commits of the interstitial page.
2093 if (showing_interstitial_page()) {
2094 LOG(WARNING) << "Discarding message during interstitial.";
2095 return;
2096 }
2097
2098 // This will discard our pending entry if we cancelled the load (e.g., if we
2099 // decided to download the file instead of load it). Only discard the
2100 // pending entry if the URLs match, otherwise the user initiated a navigate
2101 // before the page loaded so that the discard would discard the wrong entry.
2102 NavigationEntry* pending_entry = controller_.pending_entry();
2103 if (pending_entry && pending_entry->url() == url) {
2104 controller_.DiscardNonCommittedEntries();
2105 // Update the URL display.
2106 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2107 }
2108
2109 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2110 }
2111
2112 // Send out a notification that we failed a provisional load with an error.
2113 ProvisionalLoadDetails details(is_main_frame,
2114 controller_.IsURLInPageNavigation(url),
2115 url, std::string(), false);
2116 details.set_error_code(error_code);
2117
2118 NotificationService::current()->Notify(
2119 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2120 Source<NavigationController>(&controller_),
2121 Details<ProvisionalLoadDetails>(&details));
2122}
2123
2124void TabContents::DocumentLoadedInFrame() {
2125 controller_.DocumentLoadedInFrame();
2126}
2127
[email protected]0de80162010-02-03 04:52:352128void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]b1235062010-03-25 17:31:272129 // TODO(joth): remove once fully implemented.
2130 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION);
[email protected]0de80162010-02-03 04:52:352131 content_blocked_[type] = true;
2132 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242133 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352134}
2135
[email protected]614c0e12010-03-25 10:12:562136void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2137 bool allowed) {
2138 geolocation_content_settings_[requesting_origin] =
2139 allowed ? CONTENT_SETTING_ALLOW : CONTENT_SETTING_BLOCK;
[email protected]614c0e12010-03-25 10:12:562140 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242141 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562142}
2143
[email protected]8d3347f2009-07-09 22:00:212144RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322145 return view_.get();
2146}
2147
[email protected]8d3347f2009-07-09 22:00:212148RenderViewHostDelegate::RendererManagement*
2149TabContents::GetRendererManagementDelegate() {
2150 return &render_manager_;
2151}
2152
[email protected]bf5c2ff392009-07-08 16:24:332153RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212154 TabContents::GetBrowserIntegrationDelegate() {
2155 return this;
[email protected]bf5c2ff392009-07-08 16:24:332156}
2157
[email protected]8d3347f2009-07-09 22:00:212158RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2159 return this;
[email protected]bf5c2ff392009-07-08 16:24:332160}
2161
[email protected]8d3347f2009-07-09 22:00:212162RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322163 return save_package_.get(); // May be NULL, but we can return NULL.
2164}
2165
[email protected]8d3347f2009-07-09 22:00:212166RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2167 return &printing_;
2168}
2169
2170RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2171 return &fav_icon_helper_;
2172}
2173
[email protected]e8dbd674b2010-03-11 18:34:402174RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452175 if (autocomplete_history_manager_.get() == NULL)
2176 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2177 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332178}
2179
[email protected]21674df2009-10-28 19:51:212180RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342181 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212182}
2183
[email protected]fd571bb2010-03-19 01:23:542184AutomationResourceRoutingDelegate*
2185TabContents::GetAutomationResourceRoutingDelegate() {
2186 return delegate();
2187}
2188
[email protected]ced90ae12010-02-20 02:06:162189RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2190 return bookmark_drag_;
2191}
2192
2193void TabContents::SetBookmarkDragDelegate(
2194 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2195 bookmark_drag_ = bookmark_drag;
2196}
2197
[email protected]93623c5d2009-12-10 21:40:322198RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462199 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512200}
2201
[email protected]57c6a652009-05-04 07:58:342202TabContents* TabContents::GetAsTabContents() {
2203 return this;
2204}
2205
[email protected]7b291f92009-08-14 05:43:532206ViewType::Type TabContents::GetRenderViewType() const {
2207 return ViewType::TAB_CONTENTS;
2208}
2209
2210int TabContents::GetBrowserWindowID() const {
2211 return controller().window_id().id();
2212}
2213
[email protected]420ae012009-04-24 05:16:322214void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062215 NotificationService::current()->Notify(
2216 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2217 Source<TabContents>(this),
2218 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322219 NavigationEntry* entry = controller_.GetActiveEntry();
2220 if (!entry)
2221 return;
2222
2223 // When we're creating views, we're still doing initial setup, so we always
2224 // use the pending DOM UI rather than any possibly existing committed one.
2225 if (render_manager_.pending_dom_ui()) {
2226 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2227 }
2228
2229 if (entry->IsViewSourceMode()) {
2230 // Put the renderer in view source mode.
2231 render_view_host->Send(
2232 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2233 }
[email protected]0666aef2009-05-13 19:48:082234
2235 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322236}
2237
2238void TabContents::RenderViewReady(RenderViewHost* rvh) {
2239 if (rvh != render_view_host()) {
2240 // Don't notify the world, since this came from a renderer in the
2241 // background.
2242 return;
2243 }
2244
2245 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302246 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322247 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302248
2249 // Restore the focus to the tab (otherwise the focus will be on the top
2250 // window).
2251 if (was_crashed && !FocusLocationBarByDefault())
2252 Focus();
[email protected]420ae012009-04-24 05:16:322253}
2254
2255void TabContents::RenderViewGone(RenderViewHost* rvh) {
2256 // Ask the print preview if this renderer was valuable.
2257 if (!printing_.OnRenderViewGone(rvh))
2258 return;
2259 if (rvh != render_view_host()) {
2260 // The pending page's RenderViewHost is gone.
2261 return;
2262 }
2263
2264 SetIsLoading(false, NULL);
2265 NotifyDisconnected();
2266 SetIsCrashed(true);
2267
[email protected]ff9efc62010-02-18 22:10:542268 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212269 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542270 RemoveInfoBar(GetInfoBarDelegateAt(i));
2271
[email protected]8e537302009-06-10 21:19:582272 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552273 // Only do this if we're not in browser shutdown, so that TabContents
2274 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2275 // visible do not flash a sad tab page.
2276 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2277 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322278
2279 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002280 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322281}
2282
[email protected]2e4633c2009-07-09 16:58:062283void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2284 NotificationService::current()->Notify(
2285 NotificationType::RENDER_VIEW_HOST_DELETED,
2286 Source<TabContents>(this),
2287 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482288 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062289}
2290
[email protected]420ae012009-04-24 05:16:322291void TabContents::DidNavigate(RenderViewHost* rvh,
2292 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372293 int extra_invalidate_flags = 0;
2294
2295 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352296 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372297 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2298
[email protected]420ae012009-04-24 05:16:322299 render_manager_.DidNavigateMainFrame(rvh);
2300
[email protected]20ede072009-10-06 00:28:352301 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372302 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2303 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2304 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2305 }
2306
[email protected]420ae012009-04-24 05:16:322307 // Update the site of the SiteInstance if it doesn't have one yet.
2308 if (!GetSiteInstance()->has_site())
2309 GetSiteInstance()->SetSite(params.url);
2310
2311 // Need to update MIME type here because it's referred to in
2312 // UpdateNavigationCommands() called by RendererDidNavigate() to
2313 // determine whether or not to enable the encoding menu.
2314 // It's updated only for the main frame. For a subframe,
2315 // RenderView::UpdateURL does not set params.contents_mime_type.
2316 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2317 // TODO(jungshik): Add a test for the encoding menu to avoid
2318 // regressing it again.
2319 if (PageTransition::IsMainFrame(params.transition))
2320 contents_mime_type_ = params.contents_mime_type;
2321
2322 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372323 bool did_navigate = controller_.RendererDidNavigate(
2324 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392325
2326 // Update history. Note that this needs to happen after the entry is complete,
2327 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352328 if (params.should_update_history &&
2329 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392330 // Most of the time, the displayURL matches the loaded URL, but for about:
2331 // URLs, we use a data: URL as the real value. We actually want to save
2332 // the about: URL to the history db and keep the data: URL hidden. This is
2333 // what the TabContents' URL getter does.
2334 UpdateHistoryForNavigation(GetURL(), details, params);
2335 }
2336
[email protected]76543b92009-08-31 17:27:452337 if (!did_navigate)
2338 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322339
2340 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2341 // for the appropriate notification (best) or you can add it to
2342 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2343 // necessary, please).
2344
2345 // Run post-commit tasks.
2346 if (details.is_main_frame)
2347 DidNavigateMainFramePostCommit(details, params);
2348 DidNavigateAnyFramePostCommit(rvh, details, params);
2349}
2350
2351void TabContents::UpdateState(RenderViewHost* rvh,
2352 int32 page_id,
2353 const std::string& state) {
2354 DCHECK(rvh == render_view_host());
2355
2356 // We must be prepared to handle state updates for any page, these occur
2357 // when the user is scrolling and entering form data, as well as when we're
2358 // leaving a page, in which case our state may have already been moved to
2359 // the next page. The navigation controller will look up the appropriate
2360 // NavigationEntry and update it when it is notified via the delegate.
2361
2362 int entry_index = controller_.GetEntryIndexWithPageID(
2363 GetSiteInstance(), page_id);
2364 if (entry_index < 0)
2365 return;
2366 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2367
2368 if (state == entry->content_state())
2369 return; // Nothing to update.
2370 entry->set_content_state(state);
2371 controller_.NotifyEntryChanged(entry, entry_index);
2372}
2373
2374void TabContents::UpdateTitle(RenderViewHost* rvh,
2375 int32 page_id, const std::wstring& title) {
2376 // If we have a title, that's a pretty good indication that we've started
2377 // getting useful data.
2378 SetNotWaitingForResponse();
2379
2380 DCHECK(rvh == render_view_host());
2381 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2382 page_id);
2383 if (!entry || !UpdateTitleForEntry(entry, title))
2384 return;
2385
2386 // Broadcast notifications when the UI should be updated.
2387 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032388 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322389}
2390
[email protected]420ae012009-04-24 05:16:322391void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402392 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322393 set_encoding(encoding);
2394}
2395
2396void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2397 if (delegate())
2398 delegate()->UpdateTargetURL(this, url);
2399}
2400
2401void TabContents::UpdateThumbnail(const GURL& url,
2402 const SkBitmap& bitmap,
2403 const ThumbnailScore& score) {
2404 // Tell History about this thumbnail
[email protected]449478302009-06-09 20:04:282405 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kThumbnailStore)) {
[email protected]72d0fc72009-07-09 17:30:492406 if (!profile()->IsOffTheRecord())
[email protected]42339402009-07-17 17:27:192407 profile()->GetThumbnailStore()->SetPageThumbnail(url, bitmap,
2408 score, true);
[email protected]449478302009-06-09 20:04:282409 } else {
2410 HistoryService* hs;
2411 if (!profile()->IsOffTheRecord() &&
2412 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2413 hs->SetPageThumbnail(url, bitmap, score);
2414 }
[email protected]420ae012009-04-24 05:16:322415 }
2416}
2417
[email protected]8922e1f2009-10-03 05:01:262418void TabContents::UpdateInspectorSettings(const std::string& raw_settings) {
[email protected]0df30122009-06-03 12:13:082419 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:262420 UTF8ToWide(raw_settings));
[email protected]0df30122009-06-03 12:13:082421}
2422
[email protected]420ae012009-04-24 05:16:322423void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292424 // The UI may be in an event-tracking loop, such as between the
2425 // mouse-down and mouse-up in text selection or a button click.
2426 // Defer the close until after tracking is complete, so that we
2427 // don't free objects out from under the UI.
2428 // TODO(shess): This could probably be integrated with the
2429 // IsDoingDrag() test below. Punting for now because I need more
2430 // research to understand how this impacts platforms other than Mac.
2431 // TODO(shess): This could get more fine-grained. For instance,
2432 // closing a tab in another window while selecting text in the
2433 // current window's Omnibox should be just fine.
2434 if (view()->IsEventTracking()) {
2435 view()->CloseTabAfterEventTracking();
2436 return;
2437 }
2438
[email protected]24a4d1062009-07-10 23:10:422439 // If we close the tab while we're in the middle of a drag, we'll crash.
2440 // Instead, cancel the drag and close it as soon as the drag ends.
2441 if (view()->IsDoingDrag()) {
2442 view()->CancelDragAndCloseTab();
2443 return;
2444 }
2445
[email protected]420ae012009-04-24 05:16:322446 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2447 if (delegate() && rvh == render_view_host())
2448 delegate()->CloseContents(this);
2449}
2450
2451void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2452 if (delegate() && delegate()->IsPopup(this))
2453 delegate()->MoveContents(this, new_bounds);
2454}
2455
[email protected]7ab1e7d62009-10-14 23:32:012456void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322457 SetIsLoading(true, NULL);
2458}
2459
[email protected]7ab1e7d62009-10-14 23:32:012460void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322461 scoped_ptr<LoadNotificationDetails> details;
2462
2463 NavigationEntry* entry = controller_.GetActiveEntry();
2464 // An entry may not exist for a stop when loading an initial blank page or
2465 // if an iframe injected by script into a blank page finishes loading.
2466 if (entry) {
[email protected]420ae012009-04-24 05:16:322467 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2468
2469 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542470 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322471 entry->transition_type(),
2472 elapsed,
2473 &controller_,
2474 controller_.GetCurrentEntryIndex()));
2475 }
2476
2477 // Tell PasswordManager we've finished a page load, which serves as a
2478 // green light to save pending passwords and reset itself.
2479 GetPasswordManager()->DidStopLoading();
2480
2481 SetIsLoading(false, details.get());
2482}
2483
[email protected]420ae012009-04-24 05:16:322484void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2485 const GURL& source_url,
2486 const GURL& target_url) {
2487 NavigationEntry* entry;
2488 if (page_id == -1)
2489 entry = controller_.pending_entry();
2490 else
2491 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2492 if (!entry || entry->url() != source_url)
2493 return;
2494 entry->set_url(target_url);
2495}
2496
[email protected]420ae012009-04-24 05:16:322497void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2498 WindowOpenDisposition disposition) {
2499 if (render_manager_.dom_ui()) {
2500 // When we're a DOM UI, it will provide a page transition type for us (this
2501 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2502 // generated suggestions).
2503 //
2504 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162505 // want web sites to see a referrer of "chrome://blah" (and some
2506 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322507 // send to the site), so we send no referrer.
2508 OpenURL(url, GURL(), disposition,
2509 render_manager_.dom_ui()->link_transition_type());
2510 } else {
2511 OpenURL(url, referrer, disposition, PageTransition::LINK);
2512 }
2513}
2514
[email protected]1ee614862009-07-06 20:29:182515void TabContents::DomOperationResponse(const std::string& json_string,
2516 int automation_id) {
2517}
2518
[email protected]420ae012009-04-24 05:16:322519void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]e4dad9fb2009-10-06 18:15:582520 const Value* content,
[email protected]bb64b512010-04-02 21:01:392521 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252522 int request_id,
2523 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322524 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442525 // This can happen if someone uses window.open() to open an extension URL
2526 // from a non-extension context.
2527 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322528 return;
2529 }
[email protected]bb64b512010-04-02 21:01:392530 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2531 request_id,
[email protected]811bfe32009-07-01 08:46:252532 has_callback);
[email protected]420ae012009-04-24 05:16:322533}
2534
2535void TabContents::ProcessExternalHostMessage(const std::string& message,
2536 const std::string& origin,
2537 const std::string& target) {
2538 if (delegate())
2539 delegate()->ForwardMessageToExternalHost(message, origin, target);
2540}
2541
[email protected]cdaf8d02010-03-30 19:52:472542void TabContents::RunFileChooser(
2543 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322544 if (!select_file_dialog_.get())
2545 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472546
2547 SelectFileDialog::Type dialog_type;
2548 switch (params.mode) {
2549 case ViewHostMsg_RunFileChooser_Params::Open:
2550 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2551 break;
2552 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2553 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2554 break;
2555 case ViewHostMsg_RunFileChooser_Params::Save:
2556 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2557 break;
2558 default:
[email protected]bed31952010-03-30 20:07:592559 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472560 NOTREACHED();
2561 }
2562 select_file_dialog_->SelectFile(dialog_type, params.title,
2563 params.default_file_name,
[email protected]420ae012009-04-24 05:16:322564 NULL, 0, FILE_PATH_LITERAL(""),
2565 view_->GetTopLevelNativeWindow(), NULL);
2566}
2567
2568void TabContents::RunJavaScriptMessage(
2569 const std::wstring& message,
2570 const std::wstring& default_prompt,
2571 const GURL& frame_url,
2572 const int flags,
2573 IPC::Message* reply_msg,
2574 bool* did_suppress_message) {
2575 // Suppress javascript messages when requested and when inside a constrained
2576 // popup window (because that activates them and breaks them out of the
2577 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552578 // Also suppress messages when showing an interstitial. The interstitial is
2579 // shown over the previous page, we don't want the hidden page dialogs to
2580 // interfere with the interstitial.
2581 bool suppress_this_message = suppress_javascript_messages_ ||
2582 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322583 if (delegate())
2584 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312585 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322586
2587 *did_suppress_message = suppress_this_message;
2588
2589 if (!suppress_this_message) {
2590 base::TimeDelta time_since_last_message(
2591 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2592 bool show_suppress_checkbox = false;
2593 // Show a checkbox offering to suppress further messages if this message is
2594 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2595 if (time_since_last_message <
2596 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2597 show_suppress_checkbox = true;
2598
[email protected]d82ed61e2009-06-16 02:46:222599 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322600 show_suppress_checkbox, reply_msg);
2601 } else {
2602 // If we are suppressing messages, just reply as is if the user immediately
2603 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542604 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322605 }
2606}
2607
2608void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2609 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012610 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222611 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322612}
2613
2614void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2615 const std::string& json_arguments,
2616 IPC::Message* reply_msg) {
2617 if (delegate()) {
2618 HtmlDialogUIDelegate* dialog_delegate =
2619 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222620 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322621 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2622 }
2623}
2624
[email protected]4d44a1c2010-04-28 19:20:412625void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562626 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412627 GetPasswordManager()->PasswordFormsFound(forms);
2628}
2629
2630void TabContents::PasswordFormsVisible(
2631 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2632 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322633}
2634
[email protected]420ae012009-04-24 05:16:322635// Checks to see if we should generate a keyword based on the OSDD, and if
2636// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2637void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2638 int32 page_id, const GURL& url,
2639 bool autodetected) {
2640 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2641 DCHECK(url.is_valid());
2642 if (!IsActiveEntry(page_id))
2643 return;
2644 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2645 if (!url_model)
2646 return;
2647 if (!url_model->loaded()) {
2648 url_model->Load();
2649 return;
2650 }
2651 if (!profile()->GetTemplateURLFetcher())
2652 return;
2653
2654 if (profile()->IsOffTheRecord())
2655 return;
2656
2657 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2658 DCHECK(entry);
2659
2660 const NavigationEntry* base_entry = entry;
2661 if (IsFormSubmit(base_entry)) {
2662 // If the current page is a form submit, find the last page that was not
2663 // a form submit and use its url to generate the keyword from.
2664 int index = controller_.last_committed_entry_index() - 1;
2665 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2666 index--;
2667 if (index >= 0)
2668 base_entry = controller_.GetEntryAtIndex(index);
2669 else
2670 base_entry = NULL;
2671 }
2672
2673 // We want to use the user typed URL if available since that represents what
2674 // the user typed to get here, and fall back on the regular URL if not.
2675 if (!base_entry)
2676 return;
2677 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2678 base_entry->user_typed_url() : base_entry->url();
2679 if (!keyword_url.is_valid())
2680 return;
2681 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2682 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532683
2684 // For JS added OSDD empty keyword is OK because we will generate keyword
2685 // later from OSDD content.
2686 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322687 return;
2688 const TemplateURL* template_url =
2689 url_model->GetTemplateURLForKeyword(keyword);
2690 if (template_url && (!template_url->safe_for_autoreplace() ||
2691 template_url->originating_url() == url)) {
2692 // Either there is a user created TemplateURL for this keyword, or the
2693 // keyword has the same OSDD url and we've parsed it.
2694 return;
2695 }
2696
2697 // Download the OpenSearch description document. If this is successful a
2698 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322699 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2700 keyword,
2701 url,
2702 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162703 this,
[email protected]420ae012009-04-24 05:16:322704 autodetected);
2705}
2706
[email protected]420ae012009-04-24 05:16:322707GURL TabContents::GetAlternateErrorPageURL() const {
2708 GURL url;
2709 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2710 if (profile()->IsOffTheRecord())
2711 return url;
2712
2713 PrefService* prefs = profile()->GetPrefs();
2714 DCHECK(prefs);
2715 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152716 url = google_util::AppendGoogleLocaleParam(
2717 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322718 url = google_util::AppendGoogleTLDParam(url);
2719 }
2720 return url;
2721}
2722
2723WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062724 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552725 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062726 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322727}
2728
[email protected]fa1cf0b82010-01-15 21:49:442729void TabContents::OnIgnoredUIEvent() {
2730 if (constrained_window_count()) {
2731 ConstrainedWindow* window = *constrained_window_begin();
2732 window->FocusConstrainedWindow();
2733 }
2734}
2735
[email protected]420ae012009-04-24 05:16:322736void TabContents::OnJSOutOfMemory() {
2737 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422738 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322739}
2740
[email protected]420ae012009-04-24 05:16:322741void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2742 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342743 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322744 // delivered to a pending RenderViewHost. We must first run the onunload
2745 // handler of the old RenderViewHost before we can allow it to proceed.
2746 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2747 new_request_id);
2748}
2749
2750bool TabContents::CanBlur() const {
2751 return delegate() ? delegate()->CanBlur() : true;
2752}
2753
2754gfx::Rect TabContents::GetRootWindowResizerRect() const {
2755 if (delegate())
2756 return delegate()->GetRootWindowResizerRect();
2757 return gfx::Rect();
2758}
2759
2760void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2761 bool is_during_unload) {
2762 if (is_during_unload) {
2763 // Hang occurred while firing the beforeunload/unload handler.
2764 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112765 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322766
2767 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2768 return;
2769
2770 // If the tab hangs in the beforeunload/unload handler there's really
2771 // nothing we can do to recover. Pretend the unload listeners have
2772 // all fired and close the tab. If the hang is in the beforeunload handler
2773 // then the user will not have the option of cancelling the close.
2774 Close(rvh);
2775 return;
2776 }
2777
2778 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002779 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322780}
2781
2782void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002783 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322784}
2785
2786void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562787 net::LoadState load_state,
2788 uint64 upload_position,
2789 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322790 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562791 upload_position_ = upload_position;
2792 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292793 std::wstring languages =
2794 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292795 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532796 load_state_host_ =
2797 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322798 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2799 SetNotWaitingForResponse();
2800 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502801 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322802}
2803
[email protected]1ee614862009-07-06 20:29:182804bool TabContents::IsExternalTabContainer() const {
2805 if (!delegate())
2806 return false;
2807
2808 return delegate()->IsExternalTabContainer();
2809}
2810
[email protected]1ee614862009-07-06 20:29:182811void TabContents::DidInsertCSS() {
2812 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322813}
2814
[email protected]130efb02009-09-18 18:54:352815void TabContents::FocusedNodeChanged() {
2816 NotificationService::current()->Notify(
2817 NotificationType::FOCUS_CHANGED_IN_PAGE,
2818 Source<RenderViewHost>(render_view_host()),
2819 NotificationService::NoDetails());
2820}
2821
[email protected]420ae012009-04-24 05:16:322822void TabContents::FileSelected(const FilePath& path,
2823 int index, void* params) {
[email protected]cdaf8d02010-03-30 19:52:472824 std::vector<FilePath> files;
2825 files.push_back(path);
2826 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322827}
2828
2829void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2830 void* params) {
[email protected]cdaf8d02010-03-30 19:52:472831 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322832}
2833
2834void TabContents::FileSelectionCanceled(void* params) {
2835 // If the user cancels choosing a file to upload we pass back an
2836 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472837 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322838}
2839
2840void TabContents::BeforeUnloadFiredFromRenderManager(
2841 bool proceed,
2842 bool* proceed_to_fire_unload) {
2843 if (delegate())
2844 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2845}
2846
2847void TabContents::UpdateRenderViewSizeForRenderManager() {
2848 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262849 gfx::Size size = view_->GetContainerSize();
2850 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2851 // here during container initialization and normal window size will be set
2852 // later. In case of tab duplication this resizing to 0x0 prevents setting
2853 // normal size later so just ignore it.
2854 if (!size.IsEmpty())
2855 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322856}
2857
2858DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222859 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322860}
2861
2862NavigationEntry*
2863TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2864 return controller_.GetLastCommittedEntry();
2865}
2866
2867bool TabContents::CreateRenderViewForRenderManager(
2868 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322869 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522870
2871 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2872 if (!request_context.get())
2873 request_context = profile()->GetRequestContext();
2874
2875 if (!render_view_host->CreateRenderView(request_context))
[email protected]420ae012009-04-24 05:16:322876 return false;
2877
2878 // Now that the RenderView has been created, we need to tell it its size.
2879 rwh_view->SetSize(view_->GetContainerSize());
2880
2881 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2882 render_view_host);
2883 return true;
2884}
2885
2886void TabContents::Observe(NotificationType type,
2887 const NotificationSource& source,
2888 const NotificationDetails& details) {
2889 switch (type.value) {
2890 case NotificationType::BOOKMARK_MODEL_LOADED:
2891 // BookmarkModel finished loading, fall through to update starred state.
2892 case NotificationType::URLS_STARRED: {
2893 // Somewhere, a URL has been starred.
2894 // Ignore notifications for profiles other than our current one.
2895 Profile* source_profile = Source<Profile>(source).ptr();
2896 if (!source_profile || !source_profile->IsSameProfile(profile()))
2897 return;
2898
2899 UpdateStarredStateForCurrentURL();
2900 break;
2901 }
2902 case NotificationType::PREF_CHANGED: {
2903 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2904 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2905 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2906 UpdateAlternateErrorPageURL();
2907 } else if (*pref_name_in == prefs::kDefaultCharset ||
2908 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2909 ) {
2910 UpdateWebPreferences();
2911 } else {
2912 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2913 }
2914 break;
2915 }
2916 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2917 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2918 break;
2919
2920 case NotificationType::NAV_ENTRY_COMMITTED: {
2921 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2922
2923 NavigationController::LoadCommittedDetails& committed_details =
2924 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2925 ExpireInfoBars(committed_details);
2926 break;
2927 }
2928
[email protected]d3ba77272009-09-03 00:06:092929#if defined(OS_LINUX)
2930 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542931 renderer_preferences_util::UpdateFromSystemSettings(
2932 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092933 render_view_host()->SyncRendererPrefs();
2934 break;
2935 }
2936#endif
2937
[email protected]6c32ce72010-03-08 05:18:062938 case NotificationType::USER_STYLE_SHEET_UPDATED:
2939 UpdateWebPreferences();
2940 break;
2941
[email protected]79580c62010-02-02 02:36:252942 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292943 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252944 settings_details(details);
[email protected]79580c62010-02-02 02:36:252945 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492946 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292947 if (entry)
[email protected]da0c8e92010-02-09 23:25:492948 entry_url = entry->url();
[email protected]79580c62010-02-02 02:36:252949 Source<HostContentSettingsMap> content_settings(source);
[email protected]0314ae02010-04-08 09:18:292950 if (settings_details.ptr()->update_all() ||
2951 settings_details.ptr()->pattern().Matches(entry_url)) {
2952 render_view_host()->SendContentSettings(entry_url,
[email protected]da0c8e92010-02-09 23:25:492953 content_settings.ptr()->GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252954 }
2955 break;
2956 }
2957
[email protected]a888b29e62010-04-01 13:38:572958 case NotificationType::EXTENSION_LOADED: {
2959 if (!app_extension_ && !app_extension_for_current_page_ &&
2960 Source<Profile>(source).ptr() == profile()) {
2961 UpdateAppExtensionForCurrentPage();
2962 if (app_extension_for_current_page_)
2963 NotifyNavigationStateChanged(INVALIDATE_TAB);
2964 }
2965 break;
2966 }
2967
2968 case NotificationType::EXTENSION_UNLOADED:
2969 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
2970 if (app_extension_for_current_page_ ==
2971 Details<Extension>(details).ptr()) {
2972 app_extension_for_current_page_ = NULL;
2973 UpdateAppExtensionForCurrentPage();
2974 NotifyNavigationStateChanged(INVALIDATE_TAB);
2975 }
2976 break;
2977 }
2978
[email protected]420ae012009-04-24 05:16:322979 default:
2980 NOTREACHED();
2981 }
2982}
[email protected]aacd7cc2009-09-02 14:51:102983
[email protected]a888b29e62010-04-01 13:38:572984void TabContents::UpdateAppExtensionIcon(Extension* extension) {
2985 app_extension_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432986
[email protected]a888b29e62010-04-01 13:38:572987 if (extension) {
2988 app_extension_image_loader_.reset(new ImageLoadingTracker(this));
2989 app_extension_image_loader_->LoadImage(
2990 extension,
2991 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
2992 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2993 Extension::EXTENSION_ICON_SMALLISH),
2994 ImageLoadingTracker::CACHE);
2995 } else {
2996 app_extension_image_loader_.reset(NULL);
2997 }
2998}
2999
3000Extension* TabContents::GetExtensionContaining(const GURL& url) {
3001 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3002 if (!extensions_service)
3003 return NULL;
3004
3005 Extension* extension = extensions_service->GetExtensionByURL(url);
3006 return extension ?
3007 extension : extensions_service->GetExtensionByWebExtent(url);
3008}
3009
3010void TabContents::UpdateAppExtensionForCurrentPage() {
3011 if (app_extension_) {
3012 // Tab has an explicit app extension; nothing to do.
3013 return;
3014 }
3015
3016 // Check the current extension before iterating through all extensions.
3017 if (app_extension_for_current_page_ &&
3018 app_extension_for_current_page_->web_extent().ContainsURL(GetURL())) {
3019 return;
3020 }
3021
3022 app_extension_for_current_page_ = GetExtensionContaining(GetURL());
3023 UpdateAppExtensionIcon(app_extension_for_current_page_);
3024}
3025
3026void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3027 int index) {
3028 if (image) {
3029 app_extension_icon_ = *image;
3030 NotifyNavigationStateChanged(INVALIDATE_TAB);
3031 }
3032}
3033
[email protected]beb440c2009-11-06 04:08:543034std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3035 bool is_alert) {
3036 if (!frame_url.has_host())
3037 return l10n_util::GetString(
3038 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3039 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3040
3041 // We really only want the scheme, hostname, and port.
3042 GURL::Replacements replacements;
3043 replacements.ClearUsername();
3044 replacements.ClearPassword();
3045 replacements.ClearPath();
3046 replacements.ClearQuery();
3047 replacements.ClearRef();
3048 GURL clean_url = frame_url.ReplaceComponents(replacements);
3049
3050 // TODO(brettw) it should be easier than this to do the correct language
3051 // handling without getting the accept language from the profile.
3052 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3053 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3054 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563055 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543056
3057 return l10n_util::GetStringF(
3058 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3059 base_address);
3060}
3061
3062gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3063 return view_->GetTopLevelNativeWindow();
3064}
3065
3066void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3067 bool success,
3068 const std::wstring& prompt) {
3069 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3070 if (is_showing_before_unload_dialog_ && !success) {
3071 // If a beforeunload dialog is canceled, we need to stop the throbber from
3072 // spinning, since we forced it to start spinning in Navigate.
3073 DidStopLoading();
3074
3075 tab_close_start_time_ = base::TimeTicks();
3076 }
3077 is_showing_before_unload_dialog_ = false;
3078 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3079}
3080
3081void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3082 set_suppress_javascript_messages(suppress_message_boxes);
3083}
3084
[email protected]41fc0322009-09-04 22:23:403085void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103086 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3087}
[email protected]f45d2a72010-03-08 23:28:353088
3089void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3090 app_icon_ = app_icon;
3091 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3092}
[email protected]ea68c06a2010-04-23 17:25:373093
3094// After a successful *new* login attempt, we take the PasswordFormManager in
3095// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3096// the user makes up their mind with the "save password" infobar. Note if the
3097// login is one we already know about, the end of the line is
3098// provisional_save_manager_ because we just update it on success and so such
3099// forms never end up in an infobar.
3100class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3101 public:
3102 SavePasswordInfoBarDelegate(TabContents* tab_contents,
3103 PasswordFormManager* form_to_save) :
3104 ConfirmInfoBarDelegate(tab_contents),
3105 form_to_save_(form_to_save) {
3106 }
3107
3108 virtual ~SavePasswordInfoBarDelegate() { }
3109
3110 // Overridden from ConfirmInfoBarDelegate:
3111 virtual void InfoBarClosed() {
3112 delete this;
3113 }
3114
3115 virtual std::wstring GetMessageText() const {
3116 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3117 }
3118
3119 virtual SkBitmap* GetIcon() const {
3120 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3121 IDR_INFOBAR_SAVE_PASSWORD);
3122 }
3123
3124 virtual int GetButtons() const {
3125 return BUTTON_OK | BUTTON_CANCEL;
3126 }
3127
3128 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3129 if (button == BUTTON_OK)
3130 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3131 if (button == BUTTON_CANCEL)
3132 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3133 NOTREACHED();
3134 return std::wstring();
3135 }
3136
3137 virtual bool Accept() {
3138 DCHECK(form_to_save_.get());
3139 form_to_save_->Save();
3140 return true;
3141 }
3142
3143 virtual bool Cancel() {
3144 DCHECK(form_to_save_.get());
3145 form_to_save_->PermanentlyBlacklist();
3146 return true;
3147 }
3148
3149 private:
3150 // The PasswordFormManager managing the form we're asking the user about,
3151 // and should update as per her decision.
3152 scoped_ptr<PasswordFormManager> form_to_save_;
3153
3154 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3155};
3156
3157void TabContents::FillPasswordForm(
3158 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3159 render_view_host()->FillPasswordForm(form_data);
3160}
3161
3162void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3163 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3164}
3165
3166Profile* TabContents::GetProfileForPasswordManager() {
3167 return profile();
3168}
3169
3170bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3171 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3172}