blob: 573a6feee0548e593975dd54e58ecf67b62ffda6 [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]523623c2010-05-19 16:03:4239#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4840#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5341#include "chrome/browser/find_bar_state.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]942690b132010-05-11 06:42:1479#include "chrome/common/extensions/extension_resource.h"
[email protected]bfd04a62009-02-01 18:16:5680#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2981#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3282#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1883#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5484#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3785#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2686#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3287#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0688#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3789#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3290#include "net/base/mime_util.h"
91#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:2992#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:3293#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:1894#include "webkit/glue/password_form.h"
95#include "webkit/glue/webpreferences.h"
[email protected]3e45ba92009-02-20 21:09:0096
[email protected]420ae012009-04-24 05:16:3297// Cross-Site Navigations
98//
99// If a TabContents is told to navigate to a different web site (as determined
100// by SiteInstance), it will replace its current RenderViewHost with a new
101// RenderViewHost dedicated to the new SiteInstance. This works as follows:
102//
103// - Navigate determines whether the destination is cross-site, and if so,
104// it creates a pending_render_view_host_ and moves into the PENDING
105// RendererState.
106// - The pending RVH is "suspended," so that no navigation messages are sent to
107// its renderer until the onbeforeunload JavaScript handler has a chance to
108// run in the current RVH.
109// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
110// that it has a pending cross-site request. ResourceDispatcherHost will
111// check for this when the response arrives.
112// - The current RVH runs its onbeforeunload handler. If it returns false, we
113// cancel all the pending logic and go back to NORMAL. Otherwise we allow
114// the pending RVH to send the navigation request to its renderer.
115// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
116// checks CrossSiteRequestManager to see that the RVH responsible has a
117// pending cross-site request, and then installs a CrossSiteEventHandler.
118// - When RDH receives a response, the BufferedEventHandler determines whether
119// it is a download. If so, it sends a message to the new renderer causing
120// it to cancel the request, and the download proceeds in the download
121// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34122// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32123// doesn't affect any functionality.
124// - After RDH receives a response and determines that it is safe and not a
125// download, it pauses the response to first run the old page's onunload
126// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34127// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32128// to the current RVH.
129// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
130// the ResourceDispatcherHost, who unpauses the response. Data is then sent
131// to the pending RVH.
132// - The pending renderer sends a FrameNavigate message that invokes the
133// DidNavigate method. This replaces the current RVH with the
134// pending RVH and goes back to the NORMAL RendererState.
135
136namespace {
137
138// Amount of time we wait between when a key event is received and the renderer
139// is queried for its state and pushed to the NavigationEntry.
140const int kQueryStateDelay = 5000;
141
142const int kSyncWaitDelay = 40;
143
[email protected]304f8792009-08-19 21:28:09144#if defined(OS_CHROMEOS)
145// If a popup window is bigger than this fraction of the screen on chrome os,
146// turn it into a tab
147const float kMaxWidthFactor = 0.5;
148const float kMaxHeightFactor = 0.6;
149#endif
150
[email protected]420ae012009-04-24 05:16:32151// If another javascript message box is displayed within
152// kJavascriptMessageExpectedDelay of a previous javascript message box being
153// dismissed, display an option to suppress future message boxes from this
154// contents.
155const int kJavascriptMessageExpectedDelay = 1000;
156
[email protected]420ae012009-04-24 05:16:32157// The list of prefs we want to observe.
158const wchar_t* kPrefsToObserve[] = {
159 prefs::kAlternateErrorPagesEnabled,
160 prefs::kWebKitJavaEnabled,
161 prefs::kWebKitJavascriptEnabled,
162 prefs::kWebKitLoadsImagesAutomatically,
163 prefs::kWebKitPluginsEnabled,
164 prefs::kWebKitUsesUniversalDetector,
165 prefs::kWebKitSerifFontFamily,
166 prefs::kWebKitSansSerifFontFamily,
167 prefs::kWebKitFixedFontFamily,
168 prefs::kWebKitDefaultFontSize,
169 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36170 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32171 prefs::kDefaultCharset
172 // kWebKitStandardFontIsSerif needs to be added
173 // if we let users pick which font to use, serif or sans-serif when
174 // no font is specified or a CSS generic family (serif or sans-serif)
175 // is not specified.
176};
177
178const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
179
[email protected]420ae012009-04-24 05:16:32180// Returns true if the entry's transition type is FORM_SUBMIT.
181bool IsFormSubmit(const NavigationEntry* entry) {
182 return (PageTransition::StripQualifier(entry->transition_type()) ==
183 PageTransition::FORM_SUBMIT);
184}
185
186#if defined(OS_WIN)
187
188BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
189 // Note: erase is required to properly paint some widgets borders. This can
190 // be seen with textfields.
191 InvalidateRect(hwnd, NULL, TRUE);
192 return TRUE;
193}
194#endif
195
[email protected]5e369672009-11-03 23:48:30196ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16197 Profile* profile, const NavigationEntry& entry,
198 NavigationController::ReloadType reload_type) {
199 switch (reload_type) {
200 case NavigationController::RELOAD:
201 return ViewMsg_Navigate_Params::RELOAD;
202 case NavigationController::RELOAD_IGNORING_CACHE:
203 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
204 case NavigationController::NO_RELOAD:
205 break; // Fall through to rest of function.
206 }
[email protected]5e369672009-11-03 23:48:30207
208 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
209 profile->DidLastSessionExitCleanly())
210 return ViewMsg_Navigate_Params::RESTORE;
211
212 return ViewMsg_Navigate_Params::NORMAL;
213}
214
[email protected]3cc72b12010-03-18 23:03:00215void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16216 NavigationController::ReloadType reload_type,
217 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00218 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34219 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00220 params->pending_history_list_offset = controller.pending_entry_index();
221 params->current_history_list_offset = controller.last_committed_entry_index();
222 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34223 params->url = entry.url();
224 params->referrer = entry.referrer();
225 params->transition = entry.transition_type();
226 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00227 params->navigation_type =
228 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34229 params->request_time = base::Time::Now();
230}
231
[email protected]420ae012009-04-24 05:16:32232} // namespace
233
234// -----------------------------------------------------------------------------
235
[email protected]fdd61c62009-04-22 19:22:57236// static
237int TabContents::find_request_id_counter_ = -1;
238
[email protected]420ae012009-04-24 05:16:32239
[email protected]420ae012009-04-24 05:16:32240TabContents::TabContents(Profile* profile,
241 SiteInstance* site_instance,
242 int routing_id,
[email protected]34ac70502009-09-25 17:07:23243 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42244 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13245 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
246 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22247 TabContentsView::Create(this))),
248 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57249 property_bag_(),
250 registrar_(),
[email protected]d82ed61e2009-06-16 02:46:22251 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(*this)),
[email protected]fdd61c62009-04-22 19:22:57252 save_package_(),
[email protected]6db0def92010-03-02 19:55:45253 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21254 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57255 password_manager_(),
256 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06257 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22258 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]fdd61c62009-04-22 19:22:57259 select_file_dialog_(),
[email protected]d5f942ba2008-09-26 19:30:34260 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29261 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34262 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34263 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57264 current_load_start_(),
265 load_state_(net::LOAD_STATE_IDLE),
266 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56267 upload_size_(0),
268 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57269 received_page_title_(false),
270 is_starred_(false),
271 contents_mime_type_(),
272 encoding_(),
[email protected]332af7732009-03-11 13:21:35273 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49274 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47275 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57276 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57277 find_ui_active_(false),
278 find_op_aborted_(false),
279 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12280 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12281 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08282 extension_app_(NULL),
283 extension_app_for_current_page_(NULL),
[email protected]fdd61c62009-04-22 19:22:57284 capturing_contents_(false),
285 is_being_destroyed_(false),
286 notify_disconnection_(false),
287 history_requests_(),
288#if defined(OS_WIN)
289 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
290#endif
291 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44292 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01293 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54294 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54295 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16296 language_state_(&controller_),
[email protected]b3df5a42010-05-11 14:31:09297 geolocation_settings_state_(profile),
[email protected]0cce15f2010-05-21 16:58:39298 requested_accessibility_tree_(false),
299 closed_by_user_gesture_(false) {
[email protected]0de80162010-02-03 04:52:35300 ClearBlockedContentSettings();
[email protected]7ff431e2010-01-07 18:18:54301 renderer_preferences_util::UpdateFromSystemSettings(
302 &renderer_preferences_, profile);
303
[email protected]16779842009-07-08 23:45:29304#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02305 // Make sure the thumbnailer is started before starting the render manager.
306 // The thumbnailer will want to listen for RVH creations, one of which will
307 // happen in RVHManager::Init.
308 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
309 if (generator)
310 generator->StartThumbnailing();
311#endif
312
[email protected]12636df2009-09-28 22:32:21313 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32314
[email protected]34ac70502009-09-25 17:07:23315 // We have the initial size of the view be based on the size of the passed in
316 // tab contents (normally a tab from the same window).
317 view_->CreateView(base_tab_contents ?
318 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32319
320 // Register for notifications about all interested prefs change.
321 PrefService* prefs = profile->GetPrefs();
322 if (prefs) {
323 for (int i = 0; i < kPrefsToObserveLength; ++i)
324 prefs->AddPrefObserver(kPrefsToObserve[i], this);
325 }
326
327 // Register for notifications about URL starredness changing on any profile.
328 registrar_.Add(this, NotificationType::URLS_STARRED,
329 NotificationService::AllSources());
330 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
331 NotificationService::AllSources());
332 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
333 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09334#if defined(OS_LINUX)
335 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
336 NotificationService::AllSources());
337#endif
[email protected]420ae012009-04-24 05:16:32338
[email protected]6c32ce72010-03-08 05:18:06339 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
340 NotificationService::AllSources());
341
[email protected]79580c62010-02-02 02:36:25342 // Register for notifications about content setting changes.
343 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
344 NotificationService::AllSources());
345
[email protected]a888b29e62010-04-01 13:38:57346 // Listen for extension changes so we can update extension_for_current_page_.
347 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
348 NotificationService::AllSources());
349 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
350 NotificationService::AllSources());
351 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
352 NotificationService::AllSources());
353
[email protected]c8865482009-07-23 20:40:10354 // Set-up the showing of the omnibox search infobar if applicable.
355 if (OmniboxSearchHint::IsEnabled(profile))
356 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]b3df5a42010-05-11 14:31:09357
358 renderer_accessible_ =
359 CommandLine::ForCurrentProcess()->HasSwitch(
360 switches::kEnableRendererAccessibility);
[email protected]332af7732009-03-11 13:21:35361}
initial.commit09911bf2008-07-26 23:55:29362
363TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32364 is_being_destroyed_ = true;
365
[email protected]bfe4c1582009-10-02 18:11:09366 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32367 registrar_.RemoveAll();
368
369 // Unregister the notifications of all observed prefs change.
370 PrefService* prefs = profile()->GetPrefs();
371 if (prefs) {
372 for (int i = 0; i < kPrefsToObserveLength; ++i)
373 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
374 }
375
[email protected]420ae012009-04-24 05:16:32376 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00377 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32378
[email protected]420ae012009-04-24 05:16:32379 // First cleanly close all child windows.
380 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
381 // some of these to close. CloseWindows is async, so it might get called
382 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49383 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32384
[email protected]8cc8d492010-02-02 10:40:49385 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13386 if (blocked_popups_)
387 blocked_popups_->Destroy();
388
[email protected]420ae012009-04-24 05:16:32389 // Notify any observer that have a reference on this tab contents.
390 NotificationService::current()->Notify(
391 NotificationType::TAB_CONTENTS_DESTROYED,
392 Source<TabContents>(this),
393 NotificationService::NoDetails());
394
[email protected]1e5e74f2009-05-27 20:55:12395 // Notify any lasting InfobarDelegates that have not yet been removed that
396 // whatever infobar they were handling in this TabContents has closed,
397 // because the TabContents is going away entirely.
398 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
399 // notification may trigger infobars calls that access their delegate. (and
400 // some implementations of InfoBarDelegate do delete themselves on
401 // InfoBarClosed()).
402 for (int i = 0; i < infobar_delegate_count(); ++i) {
403 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
404 delegate->InfoBarClosed();
405 }
406 infobar_delegates_.clear();
407
[email protected]420ae012009-04-24 05:16:32408 // TODO(brettw) this should be moved to the view.
409#if defined(OS_WIN)
410 // If we still have a window handle, destroy it. GetNativeView can return
411 // NULL if this contents was part of a window that closed.
412 if (GetNativeView())
413 ::DestroyWindow(GetNativeView());
414#endif
[email protected]7ab1e7d62009-10-14 23:32:01415
416 // OnCloseStarted isn't called in unit tests.
417 if (!tab_close_start_time_.is_null()) {
418 UMA_HISTOGRAM_TIMES("Tab.Close",
419 base::TimeTicks::Now() - tab_close_start_time_);
420 }
initial.commit09911bf2008-07-26 23:55:29421}
422
[email protected]d5f942ba2008-09-26 19:30:34423// static
424void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32425 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
426
427 WebPreferences pref_defaults;
428 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
429 pref_defaults.javascript_enabled);
430 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
431 pref_defaults.web_security_enabled);
432 prefs->RegisterBooleanPref(
433 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
434 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
435 pref_defaults.loads_images_automatically);
436 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
437 pref_defaults.plugins_enabled);
438 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
439 pref_defaults.dom_paste_enabled);
440 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
441 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]0df30122009-06-03 12:13:08442 prefs->RegisterStringPref(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:26443 UTF8ToWide(pref_defaults.inspector_settings));
[email protected]420ae012009-04-24 05:16:32444 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
445 pref_defaults.text_areas_are_resizable);
446 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
447 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36448 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
449 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32450
451 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
452 IDS_ACCEPT_LANGUAGES);
453 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
454 IDS_DEFAULT_ENCODING);
455 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
456 IDS_STANDARD_FONT_IS_SERIF);
457 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
458 IDS_FIXED_FONT_FAMILY);
459 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
460 IDS_SERIF_FONT_FAMILY);
461 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
462 IDS_SANS_SERIF_FONT_FAMILY);
463 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
464 IDS_CURSIVE_FONT_FAMILY);
465 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
466 IDS_FANTASY_FONT_FAMILY);
467 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
468 IDS_DEFAULT_FONT_SIZE);
469 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
470 IDS_DEFAULT_FIXED_FONT_SIZE);
471 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
472 IDS_MINIMUM_FONT_SIZE);
473 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
474 IDS_MINIMUM_LOGICAL_FONT_SIZE);
475 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
476 IDS_USES_UNIVERSAL_DETECTOR);
477 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
478 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29479}
480
[email protected]13367f72009-07-08 16:39:02481// Returns true if contains content rendered by an extension.
482bool TabContents::HostsExtension() const {
483 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34484}
485
[email protected]cf28ec52010-04-09 22:56:34486AutoFillManager* TabContents::GetAutoFillManager() {
487 if (autofill_manager_.get() == NULL)
488 autofill_manager_.reset(new AutoFillManager(this));
489 return autofill_manager_.get();
490}
491
[email protected]6e95706d2009-04-23 22:55:01492PasswordManager* TabContents::GetPasswordManager() {
493 if (password_manager_.get() == NULL)
494 password_manager_.reset(new PasswordManager(this));
495 return password_manager_.get();
496}
497
498PluginInstaller* TabContents::GetPluginInstaller() {
499 if (plugin_installer_.get() == NULL)
500 plugin_installer_.reset(new PluginInstaller(this));
501 return plugin_installer_.get();
502}
503
[email protected]8cb5d5b2010-02-09 11:36:16504RenderProcessHost* TabContents::GetRenderProcessHost() const {
505 return render_manager_.current_host()->process();
506}
507
[email protected]98aa0b52010-05-06 17:03:08508void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46509 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08510 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10511
[email protected]98aa0b52010-05-06 17:03:08512 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57513
[email protected]fca656c2010-02-10 20:30:10514 NotificationService::current()->Notify(
515 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
516 Source<TabContents>(this),
517 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49518}
519
[email protected]98aa0b52010-05-06 17:03:08520void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
521 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40522 return;
523
524 ExtensionsService* extension_service = profile()->GetExtensionsService();
525 if (extension_service && extension_service->is_ready()) {
526 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08527 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40528 if (extension)
[email protected]98aa0b52010-05-06 17:03:08529 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40530 }
531}
532
[email protected]98aa0b52010-05-06 17:03:08533SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]8eb043b2010-04-30 07:19:51534 // We don't show the big icons in tabs for TYPE_EXTENSION_APP windows because
535 // for those windows, we already have a big icon in the top-left outside any
536 // tab. Having big tab icons too looks kinda redonk.
[email protected]06821f42d2010-05-03 22:34:35537 Browser* browser = delegate_ ? delegate_->GetBrowser() : NULL;
538 if (browser && browser->type() == Browser::TYPE_EXTENSION_APP)
[email protected]8eb043b2010-04-30 07:19:51539 return NULL;
[email protected]8eb043b2010-04-30 07:19:51540
[email protected]98aa0b52010-05-06 17:03:08541 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51542 return NULL;
543
[email protected]98aa0b52010-05-06 17:03:08544 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51545}
546
[email protected]d5f942ba2008-09-26 19:30:34547const GURL& TabContents::GetURL() const {
548 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57549 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54550 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34551}
552
[email protected]96d185d2009-04-24 03:28:54553const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55554 // Transient entries take precedence. They are used for interstitial pages
555 // that are shown on top of existing pages.
556 NavigationEntry* entry = controller_.GetTransientEntry();
557 if (entry)
558 return entry->GetTitleForDisplay(&controller_);
559
[email protected]96d185d2009-04-24 03:28:54560 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
561 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
562 if (our_dom_ui) {
563 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55564 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54565 if (!(entry && entry->IsViewSourceMode())) {
566 // Give the DOM UI the chance to override our title.
567 const string16& title = our_dom_ui->overridden_title();
568 if (!title.empty())
569 return title;
570 }
571 }
572
573 // We use the title for the last committed entry rather than a pending
574 // navigation entry. For example, when the user types in a URL, we want to
575 // keep the old page's title until the new load has committed and we get a new
576 // title.
[email protected]96d185d2009-04-24 03:28:54577 entry = controller_.GetLastCommittedEntry();
578 if (entry)
579 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54580 return EmptyString16();
581}
582
[email protected]bbbc1ef2010-02-12 18:03:41583// static
584string16 TabContents::GetDefaultTitle() {
585 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
586}
587
[email protected]d5f942ba2008-09-26 19:30:34588int32 TabContents::GetMaxPageID() {
589 if (GetSiteInstance())
590 return GetSiteInstance()->max_page_id();
591 else
592 return max_page_id_;
593}
594
595void TabContents::UpdateMaxPageID(int32 page_id) {
596 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34597 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34598 // testing.
599 if (GetSiteInstance())
600 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16601 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34602}
603
[email protected]96d185d2009-04-24 03:28:54604SiteInstance* TabContents::GetSiteInstance() const {
605 return render_manager_.current_host()->site_instance();
606}
607
[email protected]96d185d2009-04-24 03:28:54608bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15609 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54610 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15611 if (entry && (entry->IsViewSourceMode() ||
612 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54613 return true;
[email protected]8ab24cc2009-11-13 20:56:15614 }
[email protected]83e3895b2009-06-11 00:07:16615
[email protected]96d185d2009-04-24 03:28:54616 DOMUI* dom_ui = GetDOMUIForCurrentState();
617 if (dom_ui)
618 return !dom_ui->should_hide_url();
619 return true;
620}
621
[email protected]d5f942ba2008-09-26 19:30:34622SkBitmap TabContents::GetFavIcon() const {
623 // Like GetTitle(), we also want to use the favicon for the last committed
624 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57625 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47626 if (entry)
627 return entry->favicon().bitmap();
628
[email protected]ce3fa3c2009-04-20 19:55:57629 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34630 if (entry)
631 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34632 return SkBitmap();
633}
634
[email protected]0b303cc2009-09-28 22:35:15635bool TabContents::FavIconIsValid() const {
636 NavigationEntry* entry = controller_.GetTransientEntry();
637 if (entry)
638 return entry->favicon().is_valid();
639
640 entry = controller_.GetLastCommittedEntry();
641 if (entry)
642 return entry->favicon().is_valid();
643
644 return false;
645}
646
[email protected]96d185d2009-04-24 03:28:54647bool TabContents::ShouldDisplayFavIcon() {
648 // Always display a throbber during pending loads.
649 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
650 return true;
651
652 DOMUI* dom_ui = GetDOMUIForCurrentState();
653 if (dom_ui)
654 return !dom_ui->hide_favicon();
655 return true;
656}
657
[email protected]2d5a3592010-01-30 04:29:52658bool TabContents::IsContentBlocked(ContentSettingsType content_type) const {
[email protected]8cc8d492010-02-02 10:40:49659 if (content_type == CONTENT_SETTINGS_TYPE_POPUPS)
660 return blocked_popups_ != NULL;
661
[email protected]0de80162010-02-03 04:52:35662 if (content_type == CONTENT_SETTINGS_TYPE_IMAGES ||
663 content_type == CONTENT_SETTINGS_TYPE_JAVASCRIPT ||
[email protected]3dbb80b2010-02-09 22:41:20664 content_type == CONTENT_SETTINGS_TYPE_PLUGINS ||
665 content_type == CONTENT_SETTINGS_TYPE_COOKIES)
[email protected]0de80162010-02-03 04:52:35666 return content_blocked_[content_type];
667
[email protected]b1235062010-03-25 17:31:27668 // TODO(joth): remove once fully implemented.
669 if (content_type == CONTENT_SETTINGS_TYPE_GEOLOCATION)
670 return false;
671
[email protected]3dbb80b2010-02-09 22:41:20672 NOTREACHED();
[email protected]2d5a3592010-01-30 04:29:52673 return false;
674}
675
[email protected]96d185d2009-04-24 03:28:54676std::wstring TabContents::GetStatusText() const {
677 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
678 return std::wstring();
679
680 switch (load_state_) {
681 case net::LOAD_STATE_WAITING_FOR_CACHE:
682 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04683 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
684 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54685 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
686 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
687 case net::LOAD_STATE_RESOLVING_HOST:
688 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
689 case net::LOAD_STATE_CONNECTING:
690 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
691 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56692 if (upload_size_)
693 return l10n_util::GetStringF(
694 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
695 static_cast<int>((100 * upload_position_) / upload_size_));
696 else
697 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54698 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
699 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
700 load_state_host_);
701 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
702 case net::LOAD_STATE_IDLE:
703 case net::LOAD_STATE_READING_RESPONSE:
704 break;
705 }
706
707 return std::wstring();
708}
709
[email protected]d5f942ba2008-09-26 19:30:34710void TabContents::SetIsCrashed(bool state) {
711 if (state == is_crashed_)
712 return;
713
714 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50715 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34716}
717
[email protected]744ef172009-10-16 21:53:46718void TabContents::PageActionStateChanged() {
719 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00720}
[email protected]ce5c4502009-05-06 16:46:11721
[email protected]d5f942ba2008-09-26 19:30:34722void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
723 if (delegate_)
724 delegate_->NavigationStateChanged(this, changed_flags);
725}
726
[email protected]96d185d2009-04-24 03:28:54727void TabContents::DidBecomeSelected() {
728 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16729 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
730 if (rwhv) {
731 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43732#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16733 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43734#endif
735 }
[email protected]96d185d2009-04-24 03:28:54736
[email protected]8cb5d5b2010-02-09 11:36:16737 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54738}
739
740void TabContents::WasHidden() {
741 if (!capturing_contents()) {
742 // |render_view_host()| can be NULL if the user middle clicks a link to open
743 // a tab in then background, then closes the tab before selecting it. This
744 // is because closing the tab calls TabContents::Destroy(), which removes
745 // the |render_view_host()|; then when we actually destroy the window,
746 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16747 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
748 if (rwhv)
749 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54750 }
751
752 NotificationService::current()->Notify(
753 NotificationType::TAB_CONTENTS_HIDDEN,
754 Source<TabContents>(this),
755 NotificationService::NoDetails());
756}
757
[email protected]d5f942ba2008-09-26 19:30:34758void TabContents::Activate() {
759 if (delegate_)
760 delegate_->ActivateContents(this);
761}
762
[email protected]96d185d2009-04-24 03:28:54763void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16764 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
765 if (rwhv)
766 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54767}
768
769void TabContents::HideContents() {
770 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
771 // our superclass HideContents(), because some callers want to be very picky
772 // about the order in which these get called. In addition to making the code
773 // here practically impossible to understand, this also means we end up
774 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34775 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54776 WasHidden();
777}
778
[email protected]c0588052008-10-27 23:01:50779void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34780 WindowOpenDisposition disposition,
781 PageTransition::Type transition) {
782 if (delegate_)
[email protected]c0588052008-10-27 23:01:50783 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34784}
785
[email protected]1ccb3568d2010-02-19 10:51:16786bool TabContents::NavigateToPendingEntry(
787 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54788 const NavigationEntry& entry = *controller_.pending_entry();
789
790 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
791 if (!dest_render_view_host)
792 return false; // Unable to create the desired render view host.
793
[email protected]770dd8b2010-05-24 18:11:39794 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
795 dest_render_view_host->EnablePreferredSizeChangedMode(
796 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
797 }
[email protected]9fb325e2010-05-06 18:23:24798
[email protected]0352e5472010-04-29 00:11:40799 // For security, we should never send non-DOM-UI URLs (other than about:blank)
800 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58801 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40802 bool is_allowed_in_dom_ui_renderer =
803 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
804 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58805 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40806 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58807
[email protected]96d185d2009-04-24 03:28:54808 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12809 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32810 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00811 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
812 dest_render_view_host,
813 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32814 }
[email protected]96d185d2009-04-24 03:28:54815
816 // Used for page load time metrics.
817 current_load_start_ = base::TimeTicks::Now();
818
819 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34820 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00821 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34822 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54823
824 if (entry.page_id() == -1) {
825 // HACK!! This code suppresses javascript: URLs from being added to
826 // session history, which is what we want to do for javascript: URLs that
827 // do not generate content. What we really need is a message from the
828 // renderer telling us that a new page was not created. The same message
829 // could be used for mailto: URLs and the like.
830 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
831 return false;
832 }
833
834 // Clear any provisional password saves - this stops password infobars
835 // showing up on pages the user navigates to while the right page is
836 // loading.
837 GetPasswordManager()->ClearProvisionalSave();
838
[email protected]1ccb3568d2010-02-19 10:51:16839 if (reload_type != NavigationController::NO_RELOAD &&
840 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48841 FaviconService* favicon_service =
842 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
843 if (favicon_service)
844 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54845 }
846
[email protected]a888b29e62010-04-01 13:38:57847 // The url likely changed, see if there is an extension whose extent contains
848 // the current page.
[email protected]98aa0b52010-05-06 17:03:08849 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:57850
[email protected]d5f942ba2008-09-26 19:30:34851 return true;
852}
853
[email protected]96d185d2009-04-24 03:28:54854void TabContents::Stop() {
855 render_manager_.Stop();
856 printing_.Stop();
857}
858
[email protected]96d185d2009-04-24 03:28:54859void TabContents::DisassociateFromPopupCount() {
860 render_view_host()->DisassociateFromPopupCount();
861}
862
863TabContents* TabContents::Clone() {
864 // We create a new SiteInstance so that the new tab won't share processes
865 // with the old one. This can be changed in the future if we need it to share
866 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32867 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54868 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21869 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54870 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08871 tc->extension_app_ = extension_app_;
872 tc->extension_app_for_current_page_ = extension_app_for_current_page_;
873 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54874 return tc;
875}
876
[email protected]4d677202009-07-19 07:37:12877void TabContents::ShowPageInfo(const GURL& url,
878 const NavigationEntry::SSLStatus& ssl,
879 bool show_history) {
880 if (!delegate_)
881 return;
882
[email protected]bb678332009-07-21 00:15:50883 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12884}
885
initial.commit09911bf2008-07-26 23:55:29886ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28887 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29888 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28889 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29890 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44891
892 if (child_windows_.size() == 1) {
893 window->ShowConstrainedWindow();
894 BlockTabContent(true);
895 }
896
initial.commit09911bf2008-07-26 23:55:29897 return window;
898}
899
[email protected]fa1cf0b82010-01-15 21:49:44900void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55901 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
902 if (rwhv)
903 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44904 render_view_host()->set_ignore_input_events(blocked);
905 if (delegate_)
906 delegate_->SetTabContentBlocked(this, blocked);
907}
908
initial.commit09911bf2008-07-26 23:55:29909void TabContents::AddNewContents(TabContents* new_contents,
910 WindowOpenDisposition disposition,
911 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29912 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29913 if (!delegate_)
914 return;
915
[email protected]35f7d212009-04-29 21:19:27916 if ((disposition == NEW_POPUP) && !user_gesture &&
917 !CommandLine::ForCurrentProcess()->HasSwitch(
918 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22919 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31920 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29921 delegate_->GetConstrainingContents(this)->AddPopup(
922 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31923 } else {
[email protected]304f8792009-08-19 21:28:09924#if defined(OS_CHROMEOS)
925 if (disposition == NEW_POPUP) {
926 // If the popup is bigger than a given factor of the screen, then
927 // turn it into a foreground tab (on chrome os only)
928 GdkScreen* screen = gdk_screen_get_default();
929 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
930 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
931 if (initial_pos.width() > max_width ||
932 initial_pos.height() > max_height) {
933 disposition = NEW_FOREGROUND_TAB;
934 }
935 }
936#endif
937
[email protected]0aa55312008-10-17 21:53:08938 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29939 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
940 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49941 NotificationService::current()->Notify(
942 NotificationType::TAB_ADDED,
943 Source<TabContentsDelegate>(delegate_),
944 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29945 }
initial.commit09911bf2008-07-26 23:55:29946
[email protected]8cc8d492010-02-02 10:40:49947 // TODO(pkasting): Why is this necessary?
948 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29949}
950
[email protected]bcd9dc42010-01-23 16:38:18951bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20952 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20953 bool is_js_code, const std::string& code_string,
954 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51955 RenderViewHost* host = render_view_host();
956 if (!host)
957 return false;
958
959 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
960 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
961 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35962}
963
[email protected]96d185d2009-04-24 03:28:54964void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49965 if (is_being_destroyed_)
966 return;
967 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40968 render_view_host()->AllowScriptToClose(!visible);
[email protected]0de80162010-02-03 04:52:35969 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24970 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54971}
972
[email protected]5c9e97a2009-09-09 23:48:30973gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54974 return view_->GetContentNativeView();
975}
976
977gfx::NativeView TabContents::GetNativeView() const {
978 return view_->GetNativeView();
979}
980
981void TabContents::GetContainerBounds(gfx::Rect *out) const {
982 view_->GetContainerBounds(out);
983}
984
985void TabContents::Focus() {
986 view_->Focus();
987}
988
[email protected]90daadb42009-06-08 21:27:28989void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54990 if (showing_interstitial_page()) {
991 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
992 return;
993 }
[email protected]96d185d2009-04-24 03:28:54994 render_view_host()->SetInitialFocus(reverse);
995}
996
997bool TabContents::FocusLocationBarByDefault() {
998 DOMUI* dom_ui = GetDOMUIForCurrentState();
999 if (dom_ui)
1000 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431001 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251002 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431003 return true;
[email protected]96d185d2009-04-24 03:28:541004 return false;
1005}
1006
[email protected]a26dc362010-04-23 01:48:581007void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381008 if (delegate())
[email protected]a26dc362010-04-23 01:48:581009 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381010}
1011
[email protected]616ed5a2008-11-21 22:27:241012void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321013 if (delegate_ && !delegate_->infobars_enabled()) {
1014 delegate->InfoBarClosed();
1015 return;
1016 }
1017
[email protected]616ed5a2008-11-21 22:27:241018 // Look through the existing InfoBarDelegates we have for a match. If we've
1019 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051020 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451021 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1022 // Tell the new infobar to close so that it can clean itself up.
1023 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241024 return;
[email protected]6d27a7b2009-12-18 23:25:451025 }
[email protected]616ed5a2008-11-21 22:27:241026 }
1027
1028 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561029 NotificationService::current()->Notify(
1030 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1031 Source<TabContents>(this),
1032 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241033
1034 // Add ourselves as an observer for navigations the first time a delegate is
1035 // added. We use this notification to expire InfoBars that need to expire on
1036 // page transitions.
1037 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561038 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571039 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241040 }
1041}
1042
1043void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321044 if (delegate_ && !delegate_->infobars_enabled()) {
1045 return;
1046 }
1047
[email protected]616ed5a2008-11-21 22:27:241048 std::vector<InfoBarDelegate*>::iterator it =
1049 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1050 if (it != infobar_delegates_.end()) {
1051 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561052 NotificationService::current()->Notify(
1053 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1054 Source<TabContents>(this),
1055 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051056 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241057
[email protected]6a02963e2009-01-06 16:58:031058 // Remove ourselves as an observer if we are tracking no more InfoBars.
1059 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561060 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571061 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031062 }
[email protected]616ed5a2008-11-21 22:27:241063 }
1064}
[email protected]3edd9522009-03-04 22:19:411065
[email protected]f81821c2009-08-07 01:29:471066void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1067 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321068 if (delegate_ && !delegate_->infobars_enabled()) {
1069 new_delegate->InfoBarClosed();
1070 return;
1071 }
1072
[email protected]f81821c2009-08-07 01:29:471073 std::vector<InfoBarDelegate*>::iterator it =
1074 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1075 DCHECK(it != infobar_delegates_.end());
1076
1077 // Notify the container about the change of plans.
1078 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1079 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1080 old_delegate, new_delegate));
1081 NotificationService::current()->Notify(
1082 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1083 Source<TabContents>(this),
1084 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1085
1086 // Remove the old one.
1087 infobar_delegates_.erase(it);
1088
1089 // Add the new one.
1090 infobar_delegates_.push_back(new_delegate);
1091}
1092
[email protected]20ede072009-10-06 00:28:351093bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271094 if (showing_interstitial_page())
1095 return false;
1096
[email protected]96d185d2009-04-24 03:28:541097 // See GetDOMUIForCurrentState() comment for more info. This case is very
1098 // similar, but for non-first loads, we want to use the committed entry. This
1099 // is so the bookmarks bar disappears at the same time the page does.
1100 if (controller_.GetLastCommittedEntry()) {
1101 // Not the first load, always use the committed DOM UI.
1102 if (render_manager_.dom_ui())
1103 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1104 return false; // Default.
1105 }
1106
1107 // When it's the first load, we know either the pending one or the committed
1108 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1109 // of them will be valid, so we can just check both.
1110 if (render_manager_.pending_dom_ui())
1111 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1112 if (render_manager_.dom_ui())
1113 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1114 return false; // Default.
1115}
1116
[email protected]d8f16ae2009-08-30 03:47:261117bool TabContents::IsExtensionShelfAlwaysVisible() {
1118 // See GetDOMUIForCurrentState() comment for more info. This case is very
1119 // similar, but for non-first loads, we want to use the committed entry. This
1120 // is so the bookmarks bar disappears at the same time the page does.
1121 if (controller_.GetLastCommittedEntry()) {
1122 // Not the first load, always use the committed DOM UI.
1123 if (render_manager_.dom_ui())
1124 return render_manager_.dom_ui()->force_extension_shelf_visible();
1125 return false; // Default.
1126 }
1127
1128 // When it's the first load, we know either the pending one or the committed
1129 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1130 // of them will be valid, so we can just check both.
1131 if (render_manager_.pending_dom_ui())
1132 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1133 if (render_manager_.dom_ui())
1134 return render_manager_.dom_ui()->force_extension_shelf_visible();
1135 return false; // Default.
1136}
1137
[email protected]3edd9522009-03-04 22:19:411138void TabContents::ToolbarSizeChanged(bool is_animating) {
1139 TabContentsDelegate* d = delegate();
1140 if (d)
1141 d->ToolbarSizeChanged(this, is_animating);
1142}
[email protected]616ed5a2008-11-21 22:27:241143
[email protected]fc6fb7fb2009-11-07 02:35:041144bool TabContents::CanDownload(int request_id) {
1145 TabContentsDelegate* d = delegate();
1146 if (d)
1147 return d->CanDownload(request_id);
1148 return true;
1149}
1150
[email protected]d5f942ba2008-09-26 19:30:341151void TabContents::OnStartDownload(DownloadItem* download) {
1152 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341153
1154 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311155 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341156
[email protected]c70f9b82010-04-21 07:31:111157 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221158 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111159 // If the download occurs in a new tab, close it
1160 if (controller_.IsInitialNavigation() && (tab_contents == this))
1161 delegate()->CloseContents(this);
1162 }
[email protected]3edd9522009-03-04 22:19:411163}
[email protected]3edd9522009-03-04 22:19:411164
[email protected]d5f942ba2008-09-26 19:30:341165void TabContents::WillClose(ConstrainedWindow* window) {
1166 ConstrainedWindowList::iterator it =
1167 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441168 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341169 if (it != child_windows_.end())
1170 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371171 if (child_windows_.size() > 0) {
1172 if (removed_topmost_window) {
1173 child_windows_[0]->ShowConstrainedWindow();
1174 }
[email protected]fa1cf0b82010-01-15 21:49:441175 BlockTabContent(true);
1176 } else {
1177 BlockTabContent(false);
1178 }
[email protected]66ba4932009-06-04 19:22:131179}
[email protected]d5f942ba2008-09-26 19:30:341180
[email protected]66ba4932009-06-04 19:22:131181void TabContents::WillCloseBlockedPopupContainer(
1182 BlockedPopupContainer* container) {
1183 DCHECK(blocked_popups_ == container);
1184 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491185 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341186}
1187
[email protected]d5f942ba2008-09-26 19:30:341188void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351189#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061190 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351191#endif
[email protected]d5f942ba2008-09-26 19:30:341192}
1193
[email protected]c1dc9f132009-11-20 23:13:211194void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121195 bool forward_direction,
1196 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211197 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011198 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211199 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531200 string16 last_search_prepopulate_text =
1201 FindBarState::GetLastPrepopulateText(profile());
1202
[email protected]87fae512009-12-11 02:20:211203 // Try the last thing we searched for on this tab, then the last thing
1204 // searched for on any tab.
1205 if (!previous_find_text_.empty())
1206 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531207 else if (!last_search_prepopulate_text.empty())
1208 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211209 else
[email protected]e491f1c2009-05-22 20:28:121210 return;
[email protected]e491f1c2009-05-22 20:28:121211 }
[email protected]6e95706d2009-04-23 22:55:011212
[email protected]101c90e2009-10-26 21:14:441213 // Keep track of the previous search.
1214 previous_find_text_ = find_text_;
1215
[email protected]6e95706d2009-04-23 22:55:011216 // This is a FindNext operation if we are searching for the same text again,
1217 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1218 // exception to this is if the Find was aborted (then we don't want FindNext
1219 // because the highlighting has been cleared and we need it to reappear). We
1220 // therefore treat FindNext after an aborted Find operation as a full fledged
1221 // Find.
[email protected]c1dc9f132009-11-20 23:13:211222 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121223 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011224 !find_op_aborted_;
1225 if (!find_next)
1226 current_find_request_id_ = find_request_id_counter_++;
1227
[email protected]c1dc9f132009-11-20 23:13:211228 if (!search_string.empty())
1229 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121230 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011231
1232 find_op_aborted_ = false;
1233
1234 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531235 FindBarState* find_bar_state = profile()->GetFindBarState();
1236 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011237 render_view_host()->StartFinding(current_find_request_id_,
1238 find_text_,
1239 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121240 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011241 find_next);
1242}
1243
[email protected]5bc8fe92010-03-11 18:19:001244void TabContents::StopFinding(
1245 FindBarController::SelectionAction selection_action) {
1246 // When the action is kClearAction, it means the find string has been cleared
[email protected]2d2dffc2009-06-09 21:41:001247 // by the user, but the UI has not been dismissed.
[email protected]5bc8fe92010-03-11 18:19:001248 if (selection_action != FindBarController::kClearSelection)
[email protected]2d2dffc2009-06-09 21:41:001249 find_ui_active_ = false;
[email protected]726bdbd72010-04-05 17:08:071250 if (!find_text_.empty())
1251 previous_find_text_ = find_text_;
[email protected]101c90e2009-10-26 21:14:441252 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011253 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121254 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001255 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011256}
1257
[email protected]420ae012009-04-24 05:16:321258void TabContents::OnSavePage() {
1259 // If we can not save the page, try to download it.
1260 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1261 DownloadManager* dlm = profile()->GetDownloadManager();
1262 const GURL& current_page_url = GetURL();
1263 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221264 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321265 return;
1266 }
1267
1268 Stop();
1269
1270 // Create the save package and possibly prompt the user for the name to save
1271 // the page as. The user prompt is an asynchronous operation that runs on
1272 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221273 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321274 save_package_->GetSaveInfo();
1275}
1276
1277// Used in automated testing to bypass prompting the user for file names.
1278// Instead, the names and paths are hard coded rather than running them through
1279// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111280bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321281 SavePackage::SavePackageType save_type) {
1282 // Stop the page from navigating.
1283 Stop();
1284
[email protected]828cabe2009-09-26 22:47:111285 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591286 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321287}
1288
[email protected]89d6e6e2009-12-03 23:06:511289void TabContents::EmailPageLocation() {
1290 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1291 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1292 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1293 title + "&body=%0A%0A" + page_url;
1294 platform_util::OpenExternal(GURL(mailto));
1295}
1296
[email protected]420ae012009-04-24 05:16:321297void TabContents::PrintPreview() {
1298 // We don't show the print preview yet, only the print dialog.
1299 PrintNow();
1300}
1301
1302bool TabContents::PrintNow() {
1303 // We can't print interstitial page for now.
1304 if (showing_interstitial_page())
1305 return false;
1306
1307 return render_view_host()->PrintPages();
1308}
1309
[email protected]82270452009-06-19 15:58:011310void TabContents::PrintingDone(int document_cookie, bool success) {
1311 render_view_host()->PrintingDone(document_cookie, success);
1312}
1313
[email protected]420ae012009-04-24 05:16:321314bool TabContents::IsActiveEntry(int32 page_id) {
1315 NavigationEntry* active_entry = controller_.GetActiveEntry();
1316 return (active_entry != NULL &&
1317 active_entry->site_instance() == GetSiteInstance() &&
1318 active_entry->page_id() == page_id);
1319}
1320
[email protected]b2fe07d12010-02-09 14:38:081321void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161322 set_encoding(encoding);
1323 render_view_host()->SetPageEncoding(encoding);
1324}
1325
[email protected]b2fe07d12010-02-09 14:38:081326void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161327 reset_encoding();
1328 render_view_host()->ResetPageEncodingToDefault();
1329}
1330
1331void TabContents::WindowMoveOrResizeStarted() {
1332 render_view_host()->WindowMoveOrResizeStarted();
1333}
1334
[email protected]3f8eb7f2009-10-02 23:58:051335void TabContents::LogNewTabTime(const std::string& event_name) {
1336 // Not all new tab pages get timed. In those cases, we don't have a
1337 // new_tab_start_time_.
1338 if (new_tab_start_time_.is_null())
1339 return;
1340
1341 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441342 MetricEventDurationDetails details(event_name,
1343 static_cast<int>(duration.InMilliseconds()));
1344
[email protected]7ab1e7d62009-10-14 23:32:011345 if (event_name == "Tab.NewTabScriptStart") {
1346 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1347 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1348 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1349 } else if (event_name == "Tab.NewTabOnload") {
1350 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051351 // The new tab page has finished loading; reset it.
1352 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441353 } else {
1354 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051355 }
[email protected]84abba62009-10-07 17:01:441356 NotificationService::current()->Notify(
1357 NotificationType::METRIC_EVENT_DURATION,
1358 Source<TabContents>(this),
1359 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051360}
1361
[email protected]7ab1e7d62009-10-14 23:32:011362void TabContents::OnCloseStarted() {
1363 if (tab_close_start_time_.is_null())
1364 tab_close_start_time_ = base::TimeTicks::Now();
1365}
1366
[email protected]c37e3b62010-01-22 00:15:171367TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171368 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161369
1370 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081371 if (extension_app_)
1372 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161373 else if (entry)
1374 tab_nav.SetFromNavigationEntry(*entry);
1375
[email protected]c37e3b62010-01-22 00:15:171376 std::vector<TabNavigation> navigations;
1377 navigations.push_back(tab_nav);
1378
1379 TabContents* new_contents =
1380 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081381 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171382 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171383
[email protected]98aa0b52010-05-06 17:03:081384 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161385 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1386
[email protected]c37e3b62010-01-22 00:15:171387 return new_contents;
1388}
1389
[email protected]0de80162010-02-03 04:52:351390// Resets the |content_blocked_| array.
1391void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491392 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351393 content_blocked_[i] = false;
1394}
1395
[email protected]96d185d2009-04-24 03:28:541396// Notifies the RenderWidgetHost instance about the fact that the page is
1397// loading, or done loading and calls the base implementation.
1398void TabContents::SetIsLoading(bool is_loading,
1399 LoadNotificationDetails* details) {
1400 if (is_loading == is_loading_)
1401 return;
1402
1403 if (!is_loading) {
1404 load_state_ = net::LOAD_STATE_IDLE;
1405 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561406 upload_size_ = 0;
1407 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541408 }
1409
1410 render_manager_.SetIsLoading(is_loading);
1411
1412 is_loading_ = is_loading;
1413 waiting_for_response_ = is_loading;
1414
1415 if (delegate_)
1416 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351417 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541418
1419 NotificationType type = is_loading ? NotificationType::LOAD_START :
1420 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111421 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541422 if (details)
1423 det = Details<LoadNotificationDetails>(details);
1424 NotificationService::current()->Notify(type,
1425 Source<NavigationController>(&controller_),
1426 det);
1427}
1428
[email protected]b6c874582009-05-08 19:38:311429void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291430 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061431 // A page can't spawn popups (or do anything else, either) until its load
1432 // commits, so when we reach here, the popup was spawned by the
1433 // NavigationController's last committed entry, not the active entry. For
1434 // example, if a page opens a popup in an onunload() handler, then the active
1435 // entry is the page to be loaded as we navigate away from the unloading
1436 // page. For this reason, we can't use GetURL() to get the opener URL,
1437 // because it returns the active entry.
1438 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1439 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1440
1441 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491442 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061443 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491444 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1445 } else {
1446 if (!blocked_popups_)
1447 blocked_popups_ = new BlockedPopupContainer(this);
1448 blocked_popups_->AddTabContents(new_contents, initial_pos);
1449 }
[email protected]b9681312008-11-07 00:08:261450}
[email protected]616ed5a2008-11-21 22:27:241451
1452namespace {
1453bool TransitionIsReload(PageTransition::Type transition) {
1454 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1455}
1456}
1457
1458void TabContents::ExpireInfoBars(
1459 const NavigationController::LoadCommittedDetails& details) {
1460 // Only hide InfoBars when the user has done something that makes the main
1461 // frame load. We don't want various automatic or subframe navigations making
1462 // it disappear.
1463 if (!details.is_user_initiated_main_frame_load())
1464 return;
1465
[email protected]f86a07022008-11-25 01:06:051466 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241467 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051468 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241469 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241470 }
1471}
[email protected]fdd61c62009-04-22 19:22:571472
[email protected]96d185d2009-04-24 03:28:541473DOMUI* TabContents::GetDOMUIForCurrentState() {
1474 // When there is a pending navigation entry, we want to use the pending DOMUI
1475 // that goes along with it to control the basic flags. For example, we want to
1476 // show the pending URL in the URL bar, so we want the display_url flag to
1477 // be from the pending entry.
1478 //
1479 // The confusion comes because there are multiple possibilities for the
1480 // initial load in a tab as a side effect of the way the RenderViewHostManager
1481 // works.
1482 //
1483 // - For the very first tab the load looks "normal". The new tab DOM UI is
1484 // the pending one, and we want it to apply here.
1485 //
1486 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1487 // get switched to the one previously associated with the new tab pages.
1488 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1489 // have a committed DOM UI in this case.
1490 //
1491 // This condition handles all of these cases:
1492 //
1493 // - First load in first tab: no committed nav entry + pending nav entry +
1494 // pending dom ui:
1495 // -> Use pending DOM UI if any.
1496 //
1497 // - First load in second tab: no committed nav entry + pending nav entry +
1498 // no pending DOM UI:
1499 // -> Use the committed DOM UI if any.
1500 //
1501 // - Second navigation in any tab: committed nav entry + pending nav entry:
1502 // -> Use pending DOM UI if any.
1503 //
1504 // - Normal state with no load: committed nav entry + no pending nav entry:
1505 // -> Use committed DOM UI.
1506 if (controller_.pending_entry() &&
1507 (controller_.GetLastCommittedEntry() ||
1508 render_manager_.pending_dom_ui()))
1509 return render_manager_.pending_dom_ui();
1510 return render_manager_.dom_ui();
1511}
[email protected]420ae012009-04-24 05:16:321512
1513void TabContents::DidNavigateMainFramePostCommit(
1514 const NavigationController::LoadCommittedDetails& details,
1515 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441516 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1517 // If this is a window.open navigation, use the same DOMUI as the renderer
1518 // that opened the window, as long as both renderers have the same
1519 // privileges.
1520 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1521 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1522 // dom_ui might be NULL if the URL refers to a non-existent extension.
1523 if (dom_ui) {
1524 render_manager_.SetDOMUIPostCommit(dom_ui);
1525 dom_ui->RenderViewCreated(render_view_host());
1526 }
1527 }
1528 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1529 }
1530
[email protected]420ae012009-04-24 05:16:321531 if (details.is_user_initiated_main_frame_load()) {
1532 // Clear the status bubble. This is a workaround for a bug where WebKit
1533 // doesn't let us know that the cursor left an element during a
1534 // transition (this is also why the mouse cursor remains as a hand after
1535 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1536 // clear the bubble when a user navigates to a named anchor in the same
1537 // page.
1538 UpdateTargetURL(details.entry->page_id(), GURL());
1539
1540 // UpdateHelpersForDidNavigate will handle the case where the password_form
1541 // origin is valid.
1542 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1543 // cleaned up and covered by tests.
1544 if (!params.password_form.origin.is_valid())
1545 GetPasswordManager()->DidNavigate();
1546 }
1547
1548 // The keyword generator uses the navigation entries, so must be called after
1549 // the commit.
1550 GenerateKeywordIfNecessary(params);
1551
1552 // Allow the new page to set the title again.
1553 received_page_title_ = false;
1554
1555 // Get the favicon, either from history or request it from the net.
1556 fav_icon_helper_.FetchFavIcon(details.entry->url());
1557
[email protected]0de80162010-02-03 04:52:351558 // Clear all page actions, blocked content notifications and browser actions
1559 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141560 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081561 ExtensionsService* service = profile()->GetExtensionsService();
1562 if (service) {
1563 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571564 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081565 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521566 if (browser_action) {
1567 browser_action->ClearAllValuesForTab(controller().session_id().id());
1568 NotificationService::current()->Notify(
1569 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571570 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521571 NotificationService::NoDetails());
1572 }
[email protected]92c6f9b92009-10-24 04:35:081573
[email protected]5d246db22009-10-27 06:17:571574 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521575 service->extensions()->at(i)->page_action();
1576 if (page_action) {
1577 page_action->ClearAllValuesForTab(controller().session_id().id());
1578 PageActionStateChanged();
1579 }
[email protected]92c6f9b92009-10-24 04:35:081580 }
[email protected]aece2c7f2009-08-27 20:43:171581 }
[email protected]0de80162010-02-03 04:52:351582
1583 // Close blocked popups.
1584 if (blocked_popups_) {
1585 AutoReset auto_reset(&dont_notify_render_view_, true);
1586 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461587 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351588 }
1589
1590 // Clear "blocked" flags.
1591 ClearBlockedContentSettings();
[email protected]777a7b62010-05-11 13:28:161592 geolocation_settings_state_.DidNavigate(details);
[email protected]0de80162010-02-03 04:52:351593 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241594 delegate_->OnContentSettingsChange(this);
[email protected]f17a0ee2010-05-17 17:38:471595
1596 // Once the main frame is navigated, we're no longer considered to have
1597 // displayed insecure content.
1598 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171599 }
[email protected]ce5c4502009-05-06 16:46:111600
[email protected]8cc8d492010-02-02 10:40:491601 // Close constrained windows if necessary.
1602 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1603 details.previous_url, details.entry->url()))
1604 CloseConstrainedWindows();
1605
[email protected]420ae012009-04-24 05:16:321606 // Update the starred state.
1607 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531608
1609 // Clear the cache of forms in AutoFill.
1610 if (autofill_manager_.get())
1611 autofill_manager_->Reset();
[email protected]a888b29e62010-04-01 13:38:571612
1613 // The url likely changed, see if there is an extension whose extent contains
1614 // the current page.
[email protected]98aa0b52010-05-06 17:03:081615 UpdateExtensionAppForCurrentPage();
[email protected]420ae012009-04-24 05:16:321616}
1617
1618void TabContents::DidNavigateAnyFramePostCommit(
1619 RenderViewHost* render_view_host,
1620 const NavigationController::LoadCommittedDetails& details,
1621 const ViewHostMsg_FrameNavigate_Params& params) {
1622 // If we navigate, start showing messages again. This does nothing to prevent
1623 // a malicious script from spamming messages, since the script could just
1624 // reload the page to stop blocking.
1625 suppress_javascript_messages_ = false;
1626
[email protected]420ae012009-04-24 05:16:321627 // Notify the password manager of the navigation or form submit.
1628 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1629 // cleaned up and covered by tests.
1630 if (params.password_form.origin.is_valid())
1631 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551632
1633 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011634 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1635 details.type == NavigationType::SAME_PAGE;
1636 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321637}
1638
[email protected]8cc8d492010-02-02 10:40:491639void TabContents::CloseConstrainedWindows() {
1640 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321641 // We use indices instead of iterators in case CloseWindow does something
1642 // that may invalidate an iterator.
1643 int size = static_cast<int>(child_windows_.size());
1644 for (int i = size - 1; i >= 0; --i) {
1645 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441646 if (window) {
[email protected]420ae012009-04-24 05:16:321647 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441648 BlockTabContent(false);
1649 }
[email protected]420ae012009-04-24 05:16:321650 }
1651}
1652
1653void TabContents::UpdateStarredStateForCurrentURL() {
1654 BookmarkModel* model = profile()->GetBookmarkModel();
1655 const bool old_state = is_starred_;
1656 is_starred_ = (model && model->IsBookmarked(GetURL()));
1657
1658 if (is_starred_ != old_state && delegate())
1659 delegate()->URLStarredChanged(this, is_starred_);
1660}
1661
1662void TabContents::UpdateAlternateErrorPageURL() {
1663 GURL url = GetAlternateErrorPageURL();
1664 render_view_host()->SetAlternateErrorPageURL(url);
1665}
1666
1667void TabContents::UpdateWebPreferences() {
1668 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1669}
1670
1671void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1672 RenderViewHost* rvh) {
1673 // If we are creating a RVH for a restored controller, then we might
1674 // have more page IDs than the SiteInstance's current max page ID. We must
1675 // make sure that the max page ID is larger than any restored page ID.
1676 // Note that it is ok for conflicting page IDs to exist in another tab
1677 // (i.e., NavigationController), but if any page ID is larger than the max,
1678 // the back/forward list will get confused.
1679 int max_restored_page_id = controller_.max_restored_page_id();
1680 if (max_restored_page_id > 0) {
1681 int curr_max_page_id = site_instance->max_page_id();
1682 if (max_restored_page_id > curr_max_page_id) {
1683 // Need to update the site instance immediately.
1684 site_instance->UpdateMaxPageID(max_restored_page_id);
1685
1686 // Also tell the renderer to update its internal representation. We
1687 // need to reserve enough IDs to make all restored page IDs less than
1688 // the max.
1689 if (curr_max_page_id < 0)
1690 curr_max_page_id = 0;
1691 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1692 }
1693 }
1694}
1695
1696void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541697 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471698 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321699 const ViewHostMsg_FrameNavigate_Params& params) {
1700 if (profile()->IsOffTheRecord())
1701 return;
1702
1703 // Add to history service.
1704 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1705 if (hs) {
1706 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541707 virtual_url != params.url) {
1708 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321709 // types of URLs, we will display a magic URL that is different from where
1710 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541711 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1712 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321713 // to sub-frames.
1714 std::vector<GURL> redirects = params.redirects;
1715 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541716 redirects.back() = virtual_url;
1717 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471718 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321719 } else {
1720 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471721 params.transition, params.redirects,
1722 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321723 }
1724 }
1725}
1726
1727bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1728 const std::wstring& title) {
1729 // For file URLs without a title, use the pathname instead. In the case of a
1730 // synthesized title, we don't want the update to count toward the "one set
1731 // per page of the title to history."
1732 std::wstring final_title;
1733 bool explicit_set;
1734 if (entry->url().SchemeIsFile() && title.empty()) {
1735 final_title = UTF8ToWide(entry->url().ExtractFileName());
1736 explicit_set = false; // Don't count synthetic titles toward the set limit.
1737 } else {
1738 TrimWhitespace(title, TRIM_ALL, &final_title);
1739 explicit_set = true;
1740 }
1741
1742 if (final_title == UTF16ToWideHack(entry->title()))
1743 return false; // Nothing changed, don't bother.
1744
1745 entry->set_title(WideToUTF16Hack(final_title));
1746
1747 // Update the history system for this page.
1748 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1749 HistoryService* hs =
1750 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1751 if (hs)
[email protected]ebe89e062009-08-13 23:16:541752 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321753
1754 // Don't allow the title to be saved again for explicitly set ones.
1755 received_page_title_ = explicit_set;
1756 }
1757
1758 // Lastly, set the title for the view.
1759 view_->SetPageTitle(final_title);
1760
[email protected]cbc0e1b2010-04-12 18:33:041761 NotificationService::current()->Notify(
1762 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1763 Source<TabContents>(this),
1764 NotificationService::NoDetails());
1765
[email protected]420ae012009-04-24 05:16:321766 return true;
1767}
1768
1769void TabContents::NotifySwapped() {
1770 // After sending out a swap notification, we need to send a disconnect
1771 // notification so that clients that pick up a pointer to |this| can NULL the
1772 // pointer. See Bug 1230284.
1773 notify_disconnection_ = true;
1774 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341775 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221776 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321777 NotificationService::NoDetails());
1778}
1779
1780void TabContents::NotifyConnected() {
1781 notify_disconnection_ = true;
1782 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341783 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221784 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321785 NotificationService::NoDetails());
1786}
1787
1788void TabContents::NotifyDisconnected() {
1789 if (!notify_disconnection_)
1790 return;
1791
1792 notify_disconnection_ = false;
1793 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341794 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221795 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321796 NotificationService::NoDetails());
1797}
1798
1799void TabContents::GenerateKeywordIfNecessary(
1800 const ViewHostMsg_FrameNavigate_Params& params) {
1801 if (!params.searchable_form_url.is_valid())
1802 return;
1803
1804 if (profile()->IsOffTheRecord())
1805 return;
1806
1807 int last_index = controller_.last_committed_entry_index();
1808 // When there was no previous page, the last index will be 0. This is
1809 // normally due to a form submit that opened in a new tab.
1810 // TODO(brettw) bug 916126: we should support keywords when form submits
1811 // happen in new tabs.
1812 if (last_index <= 0)
1813 return;
1814 const NavigationEntry* previous_entry =
1815 controller_.GetEntryAtIndex(last_index - 1);
1816 if (IsFormSubmit(previous_entry)) {
1817 // Only generate a keyword if the previous page wasn't itself a form
1818 // submit.
1819 return;
1820 }
1821
1822 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1823 previous_entry->user_typed_url() : previous_entry->url();
1824 std::wstring keyword =
1825 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1826 if (keyword.empty())
1827 return;
1828
1829 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1830 if (!url_model)
1831 return;
1832
1833 if (!url_model->loaded()) {
1834 url_model->Load();
1835 return;
1836 }
1837
1838 const TemplateURL* current_url;
1839 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1840 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1841 return;
1842
1843 if (current_url) {
1844 if (current_url->originating_url().is_valid()) {
1845 // The existing keyword was generated from an OpenSearch description
1846 // document, don't regenerate.
1847 return;
1848 }
1849 url_model->Remove(current_url);
1850 }
1851 TemplateURL* new_url = new TemplateURL();
1852 new_url->set_keyword(keyword);
1853 new_url->set_short_name(keyword);
1854 new_url->SetURL(url, 0, 0);
1855 new_url->add_input_encoding(params.searchable_form_encoding);
1856 DCHECK(controller_.GetLastCommittedEntry());
1857 const GURL& favicon_url =
1858 controller_.GetLastCommittedEntry()->favicon().url();
1859 if (favicon_url.is_valid()) {
1860 new_url->SetFavIconURL(favicon_url);
1861 } else {
1862 // The favicon url isn't valid. This means there really isn't a favicon,
1863 // or the favicon url wasn't obtained before the load started. This assumes
1864 // the later.
1865 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1866 // its url.
1867 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1868 }
1869 new_url->set_safe_for_autoreplace(true);
1870 url_model->Add(new_url);
1871}
1872
[email protected]bf5c2ff392009-07-08 16:24:331873void TabContents::OnUserGesture() {
1874 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1875 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1876 if (drm)
1877 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491878 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331879 controller_.OnUserGesture();
1880}
1881
1882void TabContents::OnFindReply(int request_id,
1883 int number_of_matches,
1884 const gfx::Rect& selection_rect,
1885 int active_match_ordinal,
1886 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421887 // Ignore responses for requests that have been aborted.
1888 if (find_op_aborted_)
1889 return;
1890
[email protected]bf5c2ff392009-07-08 16:24:331891 // Ignore responses for requests other than the one we have most recently
1892 // issued. That way we won't act on stale results when the user has
1893 // already typed in another query.
1894 if (request_id != current_find_request_id_)
1895 return;
1896
1897 if (number_of_matches == -1)
1898 number_of_matches = last_search_result_.number_of_matches();
1899 if (active_match_ordinal == -1)
1900 active_match_ordinal = last_search_result_.active_match_ordinal();
1901
1902 gfx::Rect selection = selection_rect;
1903 if (selection.IsEmpty())
1904 selection = last_search_result_.selection_rect();
1905
1906 // Notify the UI, automation and any other observers that a find result was
1907 // found.
1908 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1909 selection, active_match_ordinal,
1910 final_update);
1911 NotificationService::current()->Notify(
1912 NotificationType::FIND_RESULT_AVAILABLE,
1913 Source<TabContents>(this),
1914 Details<FindNotificationDetails>(&last_search_result_));
1915}
1916
1917void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381918 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1919 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331920}
1921
[email protected]bf5c2ff392009-07-08 16:24:331922void TabContents::OnMissingPluginStatus(int status) {
1923#if defined(OS_WIN)
1924// TODO(PORT): pull in when plug-ins work
1925 GetPluginInstaller()->OnMissingPluginStatus(status);
1926#endif
1927}
1928
1929void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331930 DCHECK(!plugin_path.value().empty());
1931
1932 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351933#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331934 scoped_ptr<FileVersionInfo> version_info(
1935 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1936 if (version_info.get()) {
1937 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371938 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331939 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371940#if defined(OS_MACOSX)
1941 // Many plugins on the Mac have .plugin in the actual name, which looks
1942 // terrible, so look for that and strip it off if present.
1943 const std::wstring plugin_extension(L".plugin");
1944 if (EndsWith(plugin_name, plugin_extension, true))
1945 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1946#endif // OS_MACOSX
1947 }
[email protected]bf5c2ff392009-07-08 16:24:331948 }
[email protected]4a560ed2009-07-13 23:35:261949#else
1950 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1951#endif
[email protected]bf5c2ff392009-07-08 16:24:331952 AddInfoBar(new SimpleAlertInfoBarDelegate(
1953 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]938e1f92010-04-01 18:09:421954 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331955}
1956
1957void TabContents::OnCrashedWorker() {
1958 AddInfoBar(new SimpleAlertInfoBarDelegate(
1959 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421960 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331961}
1962
1963void TabContents::OnDidGetApplicationInfo(
1964 int32 page_id,
1965 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511966 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331967
[email protected]ed5431872009-11-17 08:39:511968 if (delegate())
1969 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331970}
1971
[email protected]a2cf65eb2010-01-18 08:20:381972void TabContents::OnPageContents(const GURL& url,
1973 int renderer_process_id,
1974 int32 page_id,
[email protected]a8a81292010-01-21 00:32:451975 const std::wstring& contents,
1976 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381977 // Don't index any https pages. People generally don't want their bank
1978 // accounts, etc. indexed on their computer, especially since some of these
1979 // things are not marked cachable.
1980 // TODO(brettw) we may want to consider more elaborate heuristics such as
1981 // the cachability of the page. We may also want to consider subframes (this
1982 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271983 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1984 // content indexing for chromeos in some future releases.
1985#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381986 if (!url.SchemeIsSecure()) {
1987 Profile* p = profile();
1988 if (p && !p->IsOffTheRecord()) {
1989 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1990 if (hs)
1991 hs->SetPageContents(url, contents);
1992 }
1993 }
[email protected]ccd40a52010-05-11 16:15:271994#endif
[email protected]a8a81292010-01-21 00:32:451995
[email protected]3b1c1812010-02-12 21:53:551996 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451997
1998 std::string lang = language;
1999 NotificationService::current()->Notify(
2000 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152001 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452002 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382003}
2004
[email protected]7e0831b2010-02-01 08:45:152005void TabContents::OnPageTranslated(int32 page_id,
2006 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162007 const std::string& translated_lang,
2008 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552009 language_state_.set_current_language(translated_lang);
2010 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162011 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152012 NotificationService::current()->Notify(
2013 NotificationType::PAGE_TRANSLATED,
2014 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162015 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152016}
2017
[email protected]bf5c2ff392009-07-08 16:24:332018void TabContents::DidStartProvisionalLoadForFrame(
2019 RenderViewHost* render_view_host,
2020 bool is_main_frame,
2021 const GURL& url) {
2022 ProvisionalLoadDetails details(is_main_frame,
2023 controller_.IsURLInPageNavigation(url),
2024 url, std::string(), false);
2025 NotificationService::current()->Notify(
2026 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2027 Source<NavigationController>(&controller_),
2028 Details<ProvisionalLoadDetails>(&details));
2029}
2030
2031void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202032 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332033 NotificationService::current()->Notify(
2034 NotificationType::RESOURCE_RESPONSE_STARTED,
2035 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202036 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332037}
2038
[email protected]3dbb80b2010-02-09 22:41:202039void TabContents::DidRedirectResource(
2040 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332041 NotificationService::current()->Notify(
2042 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2043 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202044 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332045}
2046
2047void TabContents::DidLoadResourceFromMemoryCache(
2048 const GURL& url,
2049 const std::string& frame_origin,
2050 const std::string& main_frame_origin,
2051 const std::string& security_info) {
2052 // Send out a notification that we loaded a resource from our memory cache.
2053 int cert_id = 0, cert_status = 0, security_bits = 0;
2054 SSLManager::DeserializeSecurityInfo(security_info,
2055 &cert_id, &cert_status,
2056 &security_bits);
2057 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162058 GetRenderProcessHost()->id(), cert_id,
2059 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332060
2061 NotificationService::current()->Notify(
2062 NotificationType::LOAD_FROM_MEMORY_CACHE,
2063 Source<NavigationController>(&controller_),
2064 Details<LoadFromMemoryCacheDetails>(&details));
2065}
2066
[email protected]e3d60e5d2009-09-25 21:08:292067void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472068 displayed_insecure_content_ = true;
2069 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292070}
2071
2072void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592073 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292074}
2075
[email protected]bf5c2ff392009-07-08 16:24:332076void TabContents::DidFailProvisionalLoadWithError(
2077 RenderViewHost* render_view_host,
2078 bool is_main_frame,
2079 int error_code,
2080 const GURL& url,
2081 bool showing_repost_interstitial) {
2082 if (net::ERR_ABORTED == error_code) {
2083 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2084 // This means that the interstitial won't be torn down properly, which is
2085 // bad. But if we have an interstitial, go back to another tab type, and
2086 // then load the same interstitial again, we could end up getting the first
2087 // interstitial's "failed" message (as a result of the cancel) when we're on
2088 // the second one.
2089 //
2090 // We can't tell this apart, so we think we're tearing down the current page
2091 // which will cause a crash later one. There is also some code in
2092 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2093 // out because of this problem.
2094 //
2095 // http://code.google.com/p/chromium/issues/detail?id=2855
2096 // Because this will not tear down the interstitial properly, if "back" is
2097 // back to another tab type, the interstitial will still be somewhat alive
2098 // in the previous tab type. If you navigate somewhere that activates the
2099 // tab with the interstitial again, you'll see a flash before the new load
2100 // commits of the interstitial page.
2101 if (showing_interstitial_page()) {
2102 LOG(WARNING) << "Discarding message during interstitial.";
2103 return;
2104 }
2105
2106 // This will discard our pending entry if we cancelled the load (e.g., if we
2107 // decided to download the file instead of load it). Only discard the
2108 // pending entry if the URLs match, otherwise the user initiated a navigate
2109 // before the page loaded so that the discard would discard the wrong entry.
2110 NavigationEntry* pending_entry = controller_.pending_entry();
2111 if (pending_entry && pending_entry->url() == url) {
2112 controller_.DiscardNonCommittedEntries();
2113 // Update the URL display.
2114 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2115 }
2116
2117 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2118 }
2119
2120 // Send out a notification that we failed a provisional load with an error.
2121 ProvisionalLoadDetails details(is_main_frame,
2122 controller_.IsURLInPageNavigation(url),
2123 url, std::string(), false);
2124 details.set_error_code(error_code);
2125
2126 NotificationService::current()->Notify(
2127 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2128 Source<NavigationController>(&controller_),
2129 Details<ProvisionalLoadDetails>(&details));
2130}
2131
2132void TabContents::DocumentLoadedInFrame() {
2133 controller_.DocumentLoadedInFrame();
[email protected]b3df5a42010-05-11 14:31:092134 if (renderer_accessible_ && !requested_accessibility_tree_) {
2135 render_view_host()->RequestAccessibilityTree();
2136 requested_accessibility_tree_ = true;
2137 }
[email protected]bf5c2ff392009-07-08 16:24:332138}
2139
[email protected]0de80162010-02-03 04:52:352140void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]b1235062010-03-25 17:31:272141 // TODO(joth): remove once fully implemented.
2142 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION);
[email protected]0de80162010-02-03 04:52:352143 content_blocked_[type] = true;
2144 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242145 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352146}
2147
[email protected]614c0e12010-03-25 10:12:562148void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2149 bool allowed) {
[email protected]777a7b62010-05-11 13:28:162150 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
2151 allowed);
[email protected]614c0e12010-03-25 10:12:562152 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242153 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562154}
2155
[email protected]8d3347f2009-07-09 22:00:212156RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322157 return view_.get();
2158}
2159
[email protected]8d3347f2009-07-09 22:00:212160RenderViewHostDelegate::RendererManagement*
2161TabContents::GetRendererManagementDelegate() {
2162 return &render_manager_;
2163}
2164
[email protected]bf5c2ff392009-07-08 16:24:332165RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212166 TabContents::GetBrowserIntegrationDelegate() {
2167 return this;
[email protected]bf5c2ff392009-07-08 16:24:332168}
2169
[email protected]8d3347f2009-07-09 22:00:212170RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2171 return this;
[email protected]bf5c2ff392009-07-08 16:24:332172}
2173
[email protected]8d3347f2009-07-09 22:00:212174RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322175 return save_package_.get(); // May be NULL, but we can return NULL.
2176}
2177
[email protected]8d3347f2009-07-09 22:00:212178RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2179 return &printing_;
2180}
2181
2182RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2183 return &fav_icon_helper_;
2184}
2185
[email protected]e8dbd674b2010-03-11 18:34:402186RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452187 if (autocomplete_history_manager_.get() == NULL)
2188 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2189 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332190}
2191
[email protected]21674df2009-10-28 19:51:212192RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342193 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212194}
2195
[email protected]fd571bb2010-03-19 01:23:542196AutomationResourceRoutingDelegate*
2197TabContents::GetAutomationResourceRoutingDelegate() {
2198 return delegate();
2199}
2200
[email protected]ced90ae12010-02-20 02:06:162201RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2202 return bookmark_drag_;
2203}
2204
2205void TabContents::SetBookmarkDragDelegate(
2206 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2207 bookmark_drag_ = bookmark_drag;
2208}
2209
[email protected]93623c5d2009-12-10 21:40:322210RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462211 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512212}
2213
[email protected]57c6a652009-05-04 07:58:342214TabContents* TabContents::GetAsTabContents() {
2215 return this;
2216}
2217
[email protected]7b291f92009-08-14 05:43:532218ViewType::Type TabContents::GetRenderViewType() const {
2219 return ViewType::TAB_CONTENTS;
2220}
2221
2222int TabContents::GetBrowserWindowID() const {
2223 return controller().window_id().id();
2224}
2225
[email protected]420ae012009-04-24 05:16:322226void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062227 NotificationService::current()->Notify(
2228 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2229 Source<TabContents>(this),
2230 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322231 NavigationEntry* entry = controller_.GetActiveEntry();
2232 if (!entry)
2233 return;
2234
2235 // When we're creating views, we're still doing initial setup, so we always
2236 // use the pending DOM UI rather than any possibly existing committed one.
2237 if (render_manager_.pending_dom_ui()) {
2238 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2239 }
2240
2241 if (entry->IsViewSourceMode()) {
2242 // Put the renderer in view source mode.
2243 render_view_host->Send(
2244 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2245 }
[email protected]0666aef2009-05-13 19:48:082246
2247 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322248}
2249
2250void TabContents::RenderViewReady(RenderViewHost* rvh) {
2251 if (rvh != render_view_host()) {
2252 // Don't notify the world, since this came from a renderer in the
2253 // background.
2254 return;
2255 }
2256
2257 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302258 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322259 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302260
2261 // Restore the focus to the tab (otherwise the focus will be on the top
2262 // window).
2263 if (was_crashed && !FocusLocationBarByDefault())
2264 Focus();
[email protected]420ae012009-04-24 05:16:322265}
2266
2267void TabContents::RenderViewGone(RenderViewHost* rvh) {
2268 // Ask the print preview if this renderer was valuable.
2269 if (!printing_.OnRenderViewGone(rvh))
2270 return;
2271 if (rvh != render_view_host()) {
2272 // The pending page's RenderViewHost is gone.
2273 return;
2274 }
2275
2276 SetIsLoading(false, NULL);
2277 NotifyDisconnected();
2278 SetIsCrashed(true);
2279
[email protected]ff9efc62010-02-18 22:10:542280 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212281 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542282 RemoveInfoBar(GetInfoBarDelegateAt(i));
2283
[email protected]8e537302009-06-10 21:19:582284 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552285 // Only do this if we're not in browser shutdown, so that TabContents
2286 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2287 // visible do not flash a sad tab page.
2288 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2289 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322290
2291 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002292 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322293}
2294
[email protected]2e4633c2009-07-09 16:58:062295void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2296 NotificationService::current()->Notify(
2297 NotificationType::RENDER_VIEW_HOST_DELETED,
2298 Source<TabContents>(this),
2299 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482300 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062301}
2302
[email protected]420ae012009-04-24 05:16:322303void TabContents::DidNavigate(RenderViewHost* rvh,
2304 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372305 int extra_invalidate_flags = 0;
2306
[email protected]b3df5a42010-05-11 14:31:092307 requested_accessibility_tree_ = false;
2308
[email protected]8030f012009-09-25 18:09:372309 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352310 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372311 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2312
[email protected]420ae012009-04-24 05:16:322313 render_manager_.DidNavigateMainFrame(rvh);
2314
[email protected]20ede072009-10-06 00:28:352315 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372316 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2317 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2318 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2319 }
2320
[email protected]420ae012009-04-24 05:16:322321 // Update the site of the SiteInstance if it doesn't have one yet.
2322 if (!GetSiteInstance()->has_site())
2323 GetSiteInstance()->SetSite(params.url);
2324
2325 // Need to update MIME type here because it's referred to in
2326 // UpdateNavigationCommands() called by RendererDidNavigate() to
2327 // determine whether or not to enable the encoding menu.
2328 // It's updated only for the main frame. For a subframe,
2329 // RenderView::UpdateURL does not set params.contents_mime_type.
2330 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2331 // TODO(jungshik): Add a test for the encoding menu to avoid
2332 // regressing it again.
2333 if (PageTransition::IsMainFrame(params.transition))
2334 contents_mime_type_ = params.contents_mime_type;
2335
2336 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372337 bool did_navigate = controller_.RendererDidNavigate(
2338 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392339
2340 // Update history. Note that this needs to happen after the entry is complete,
2341 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352342 if (params.should_update_history &&
2343 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392344 // Most of the time, the displayURL matches the loaded URL, but for about:
2345 // URLs, we use a data: URL as the real value. We actually want to save
2346 // the about: URL to the history db and keep the data: URL hidden. This is
2347 // what the TabContents' URL getter does.
2348 UpdateHistoryForNavigation(GetURL(), details, params);
2349 }
2350
[email protected]76543b92009-08-31 17:27:452351 if (!did_navigate)
2352 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322353
2354 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2355 // for the appropriate notification (best) or you can add it to
2356 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2357 // necessary, please).
2358
2359 // Run post-commit tasks.
2360 if (details.is_main_frame)
2361 DidNavigateMainFramePostCommit(details, params);
2362 DidNavigateAnyFramePostCommit(rvh, details, params);
2363}
2364
2365void TabContents::UpdateState(RenderViewHost* rvh,
2366 int32 page_id,
2367 const std::string& state) {
2368 DCHECK(rvh == render_view_host());
2369
2370 // We must be prepared to handle state updates for any page, these occur
2371 // when the user is scrolling and entering form data, as well as when we're
2372 // leaving a page, in which case our state may have already been moved to
2373 // the next page. The navigation controller will look up the appropriate
2374 // NavigationEntry and update it when it is notified via the delegate.
2375
2376 int entry_index = controller_.GetEntryIndexWithPageID(
2377 GetSiteInstance(), page_id);
2378 if (entry_index < 0)
2379 return;
2380 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2381
2382 if (state == entry->content_state())
2383 return; // Nothing to update.
2384 entry->set_content_state(state);
2385 controller_.NotifyEntryChanged(entry, entry_index);
2386}
2387
2388void TabContents::UpdateTitle(RenderViewHost* rvh,
2389 int32 page_id, const std::wstring& title) {
2390 // If we have a title, that's a pretty good indication that we've started
2391 // getting useful data.
2392 SetNotWaitingForResponse();
2393
2394 DCHECK(rvh == render_view_host());
2395 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2396 page_id);
2397 if (!entry || !UpdateTitleForEntry(entry, title))
2398 return;
2399
2400 // Broadcast notifications when the UI should be updated.
2401 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032402 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322403}
2404
[email protected]420ae012009-04-24 05:16:322405void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402406 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322407 set_encoding(encoding);
2408}
2409
2410void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2411 if (delegate())
2412 delegate()->UpdateTargetURL(this, url);
2413}
2414
2415void TabContents::UpdateThumbnail(const GURL& url,
2416 const SkBitmap& bitmap,
2417 const ThumbnailScore& score) {
2418 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422419 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492420 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422421 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282422 } else {
2423 HistoryService* hs;
2424 if (!profile()->IsOffTheRecord() &&
2425 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2426 hs->SetPageThumbnail(url, bitmap, score);
2427 }
[email protected]420ae012009-04-24 05:16:322428 }
2429}
2430
[email protected]8922e1f2009-10-03 05:01:262431void TabContents::UpdateInspectorSettings(const std::string& raw_settings) {
[email protected]0df30122009-06-03 12:13:082432 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:262433 UTF8ToWide(raw_settings));
[email protected]0df30122009-06-03 12:13:082434}
2435
[email protected]420ae012009-04-24 05:16:322436void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292437 // The UI may be in an event-tracking loop, such as between the
2438 // mouse-down and mouse-up in text selection or a button click.
2439 // Defer the close until after tracking is complete, so that we
2440 // don't free objects out from under the UI.
2441 // TODO(shess): This could probably be integrated with the
2442 // IsDoingDrag() test below. Punting for now because I need more
2443 // research to understand how this impacts platforms other than Mac.
2444 // TODO(shess): This could get more fine-grained. For instance,
2445 // closing a tab in another window while selecting text in the
2446 // current window's Omnibox should be just fine.
2447 if (view()->IsEventTracking()) {
2448 view()->CloseTabAfterEventTracking();
2449 return;
2450 }
2451
[email protected]24a4d1062009-07-10 23:10:422452 // If we close the tab while we're in the middle of a drag, we'll crash.
2453 // Instead, cancel the drag and close it as soon as the drag ends.
2454 if (view()->IsDoingDrag()) {
2455 view()->CancelDragAndCloseTab();
2456 return;
2457 }
2458
[email protected]420ae012009-04-24 05:16:322459 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2460 if (delegate() && rvh == render_view_host())
2461 delegate()->CloseContents(this);
2462}
2463
2464void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2465 if (delegate() && delegate()->IsPopup(this))
2466 delegate()->MoveContents(this, new_bounds);
2467}
2468
[email protected]7ab1e7d62009-10-14 23:32:012469void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322470 SetIsLoading(true, NULL);
2471}
2472
[email protected]7ab1e7d62009-10-14 23:32:012473void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322474 scoped_ptr<LoadNotificationDetails> details;
2475
2476 NavigationEntry* entry = controller_.GetActiveEntry();
2477 // An entry may not exist for a stop when loading an initial blank page or
2478 // if an iframe injected by script into a blank page finishes loading.
2479 if (entry) {
[email protected]420ae012009-04-24 05:16:322480 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2481
2482 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542483 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322484 entry->transition_type(),
2485 elapsed,
2486 &controller_,
2487 controller_.GetCurrentEntryIndex()));
2488 }
2489
2490 // Tell PasswordManager we've finished a page load, which serves as a
2491 // green light to save pending passwords and reset itself.
2492 GetPasswordManager()->DidStopLoading();
2493
2494 SetIsLoading(false, details.get());
2495}
2496
[email protected]420ae012009-04-24 05:16:322497void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2498 const GURL& source_url,
2499 const GURL& target_url) {
2500 NavigationEntry* entry;
2501 if (page_id == -1)
2502 entry = controller_.pending_entry();
2503 else
2504 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2505 if (!entry || entry->url() != source_url)
2506 return;
2507 entry->set_url(target_url);
2508}
2509
[email protected]420ae012009-04-24 05:16:322510void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2511 WindowOpenDisposition disposition) {
2512 if (render_manager_.dom_ui()) {
2513 // When we're a DOM UI, it will provide a page transition type for us (this
2514 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2515 // generated suggestions).
2516 //
2517 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162518 // want web sites to see a referrer of "chrome://blah" (and some
2519 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322520 // send to the site), so we send no referrer.
2521 OpenURL(url, GURL(), disposition,
2522 render_manager_.dom_ui()->link_transition_type());
2523 } else {
2524 OpenURL(url, referrer, disposition, PageTransition::LINK);
2525 }
2526}
2527
[email protected]1ee614862009-07-06 20:29:182528void TabContents::DomOperationResponse(const std::string& json_string,
2529 int automation_id) {
2530}
2531
[email protected]420ae012009-04-24 05:16:322532void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]438c97d2010-05-21 23:30:152533 const ListValue* content,
[email protected]bb64b512010-04-02 21:01:392534 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252535 int request_id,
2536 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322537 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442538 // This can happen if someone uses window.open() to open an extension URL
2539 // from a non-extension context.
2540 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322541 return;
2542 }
[email protected]bb64b512010-04-02 21:01:392543 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2544 request_id,
[email protected]811bfe32009-07-01 08:46:252545 has_callback);
[email protected]420ae012009-04-24 05:16:322546}
2547
2548void TabContents::ProcessExternalHostMessage(const std::string& message,
2549 const std::string& origin,
2550 const std::string& target) {
2551 if (delegate())
2552 delegate()->ForwardMessageToExternalHost(message, origin, target);
2553}
2554
[email protected]cdaf8d02010-03-30 19:52:472555void TabContents::RunFileChooser(
2556 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322557 if (!select_file_dialog_.get())
2558 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472559
2560 SelectFileDialog::Type dialog_type;
2561 switch (params.mode) {
2562 case ViewHostMsg_RunFileChooser_Params::Open:
2563 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2564 break;
2565 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2566 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2567 break;
2568 case ViewHostMsg_RunFileChooser_Params::Save:
2569 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2570 break;
2571 default:
[email protected]bed31952010-03-30 20:07:592572 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472573 NOTREACHED();
2574 }
2575 select_file_dialog_->SelectFile(dialog_type, params.title,
2576 params.default_file_name,
[email protected]420ae012009-04-24 05:16:322577 NULL, 0, FILE_PATH_LITERAL(""),
2578 view_->GetTopLevelNativeWindow(), NULL);
2579}
2580
2581void TabContents::RunJavaScriptMessage(
2582 const std::wstring& message,
2583 const std::wstring& default_prompt,
2584 const GURL& frame_url,
2585 const int flags,
2586 IPC::Message* reply_msg,
2587 bool* did_suppress_message) {
2588 // Suppress javascript messages when requested and when inside a constrained
2589 // popup window (because that activates them and breaks them out of the
2590 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552591 // Also suppress messages when showing an interstitial. The interstitial is
2592 // shown over the previous page, we don't want the hidden page dialogs to
2593 // interfere with the interstitial.
2594 bool suppress_this_message = suppress_javascript_messages_ ||
2595 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322596 if (delegate())
2597 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312598 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322599
2600 *did_suppress_message = suppress_this_message;
2601
2602 if (!suppress_this_message) {
2603 base::TimeDelta time_since_last_message(
2604 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2605 bool show_suppress_checkbox = false;
2606 // Show a checkbox offering to suppress further messages if this message is
2607 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2608 if (time_since_last_message <
2609 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2610 show_suppress_checkbox = true;
2611
[email protected]d82ed61e2009-06-16 02:46:222612 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322613 show_suppress_checkbox, reply_msg);
2614 } else {
2615 // If we are suppressing messages, just reply as is if the user immediately
2616 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542617 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322618 }
2619}
2620
2621void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2622 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012623 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222624 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322625}
2626
2627void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2628 const std::string& json_arguments,
2629 IPC::Message* reply_msg) {
2630 if (delegate()) {
2631 HtmlDialogUIDelegate* dialog_delegate =
2632 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222633 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322634 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2635 }
2636}
2637
[email protected]4d44a1c2010-04-28 19:20:412638void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562639 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412640 GetPasswordManager()->PasswordFormsFound(forms);
2641}
2642
2643void TabContents::PasswordFormsVisible(
2644 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2645 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322646}
2647
[email protected]420ae012009-04-24 05:16:322648// Checks to see if we should generate a keyword based on the OSDD, and if
2649// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2650void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2651 int32 page_id, const GURL& url,
2652 bool autodetected) {
2653 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2654 DCHECK(url.is_valid());
2655 if (!IsActiveEntry(page_id))
2656 return;
2657 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2658 if (!url_model)
2659 return;
2660 if (!url_model->loaded()) {
2661 url_model->Load();
2662 return;
2663 }
2664 if (!profile()->GetTemplateURLFetcher())
2665 return;
2666
2667 if (profile()->IsOffTheRecord())
2668 return;
2669
2670 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2671 DCHECK(entry);
2672
2673 const NavigationEntry* base_entry = entry;
2674 if (IsFormSubmit(base_entry)) {
2675 // If the current page is a form submit, find the last page that was not
2676 // a form submit and use its url to generate the keyword from.
2677 int index = controller_.last_committed_entry_index() - 1;
2678 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2679 index--;
2680 if (index >= 0)
2681 base_entry = controller_.GetEntryAtIndex(index);
2682 else
2683 base_entry = NULL;
2684 }
2685
2686 // We want to use the user typed URL if available since that represents what
2687 // the user typed to get here, and fall back on the regular URL if not.
2688 if (!base_entry)
2689 return;
2690 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2691 base_entry->user_typed_url() : base_entry->url();
2692 if (!keyword_url.is_valid())
2693 return;
2694 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2695 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532696
2697 // For JS added OSDD empty keyword is OK because we will generate keyword
2698 // later from OSDD content.
2699 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322700 return;
2701 const TemplateURL* template_url =
2702 url_model->GetTemplateURLForKeyword(keyword);
2703 if (template_url && (!template_url->safe_for_autoreplace() ||
2704 template_url->originating_url() == url)) {
2705 // Either there is a user created TemplateURL for this keyword, or the
2706 // keyword has the same OSDD url and we've parsed it.
2707 return;
2708 }
2709
2710 // Download the OpenSearch description document. If this is successful a
2711 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322712 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2713 keyword,
2714 url,
2715 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162716 this,
[email protected]420ae012009-04-24 05:16:322717 autodetected);
2718}
2719
[email protected]420ae012009-04-24 05:16:322720GURL TabContents::GetAlternateErrorPageURL() const {
2721 GURL url;
2722 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2723 if (profile()->IsOffTheRecord())
2724 return url;
2725
2726 PrefService* prefs = profile()->GetPrefs();
2727 DCHECK(prefs);
2728 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152729 url = google_util::AppendGoogleLocaleParam(
2730 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322731 url = google_util::AppendGoogleTLDParam(url);
2732 }
2733 return url;
2734}
2735
2736WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062737 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552738 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062739 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322740}
2741
[email protected]fa1cf0b82010-01-15 21:49:442742void TabContents::OnIgnoredUIEvent() {
2743 if (constrained_window_count()) {
2744 ConstrainedWindow* window = *constrained_window_begin();
2745 window->FocusConstrainedWindow();
2746 }
2747}
2748
[email protected]420ae012009-04-24 05:16:322749void TabContents::OnJSOutOfMemory() {
2750 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422751 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322752}
2753
[email protected]420ae012009-04-24 05:16:322754void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2755 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342756 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322757 // delivered to a pending RenderViewHost. We must first run the onunload
2758 // handler of the old RenderViewHost before we can allow it to proceed.
2759 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2760 new_request_id);
2761}
2762
2763bool TabContents::CanBlur() const {
2764 return delegate() ? delegate()->CanBlur() : true;
2765}
2766
2767gfx::Rect TabContents::GetRootWindowResizerRect() const {
2768 if (delegate())
2769 return delegate()->GetRootWindowResizerRect();
2770 return gfx::Rect();
2771}
2772
2773void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2774 bool is_during_unload) {
2775 if (is_during_unload) {
2776 // Hang occurred while firing the beforeunload/unload handler.
2777 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112778 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322779
2780 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2781 return;
2782
2783 // If the tab hangs in the beforeunload/unload handler there's really
2784 // nothing we can do to recover. Pretend the unload listeners have
2785 // all fired and close the tab. If the hang is in the beforeunload handler
2786 // then the user will not have the option of cancelling the close.
2787 Close(rvh);
2788 return;
2789 }
2790
2791 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002792 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322793}
2794
2795void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002796 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322797}
2798
2799void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562800 net::LoadState load_state,
2801 uint64 upload_position,
2802 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322803 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562804 upload_position_ = upload_position;
2805 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292806 std::wstring languages =
2807 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292808 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532809 load_state_host_ =
2810 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322811 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2812 SetNotWaitingForResponse();
2813 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502814 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322815}
2816
[email protected]1ee614862009-07-06 20:29:182817bool TabContents::IsExternalTabContainer() const {
2818 if (!delegate())
2819 return false;
2820
2821 return delegate()->IsExternalTabContainer();
2822}
2823
[email protected]1ee614862009-07-06 20:29:182824void TabContents::DidInsertCSS() {
2825 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322826}
2827
[email protected]130efb02009-09-18 18:54:352828void TabContents::FocusedNodeChanged() {
2829 NotificationService::current()->Notify(
2830 NotificationType::FOCUS_CHANGED_IN_PAGE,
2831 Source<RenderViewHost>(render_view_host()),
2832 NotificationService::NoDetails());
2833}
2834
[email protected]420ae012009-04-24 05:16:322835void TabContents::FileSelected(const FilePath& path,
2836 int index, void* params) {
[email protected]cdaf8d02010-03-30 19:52:472837 std::vector<FilePath> files;
2838 files.push_back(path);
2839 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322840}
2841
2842void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2843 void* params) {
[email protected]cdaf8d02010-03-30 19:52:472844 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322845}
2846
2847void TabContents::FileSelectionCanceled(void* params) {
2848 // If the user cancels choosing a file to upload we pass back an
2849 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472850 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322851}
2852
2853void TabContents::BeforeUnloadFiredFromRenderManager(
2854 bool proceed,
2855 bool* proceed_to_fire_unload) {
2856 if (delegate())
2857 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2858}
2859
2860void TabContents::UpdateRenderViewSizeForRenderManager() {
2861 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262862 gfx::Size size = view_->GetContainerSize();
2863 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2864 // here during container initialization and normal window size will be set
2865 // later. In case of tab duplication this resizing to 0x0 prevents setting
2866 // normal size later so just ignore it.
2867 if (!size.IsEmpty())
2868 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322869}
2870
2871DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222872 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322873}
2874
2875NavigationEntry*
2876TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2877 return controller_.GetLastCommittedEntry();
2878}
2879
2880bool TabContents::CreateRenderViewForRenderManager(
2881 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322882 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522883
2884 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2885 if (!request_context.get())
2886 request_context = profile()->GetRequestContext();
2887
2888 if (!render_view_host->CreateRenderView(request_context))
[email protected]420ae012009-04-24 05:16:322889 return false;
2890
2891 // Now that the RenderView has been created, we need to tell it its size.
2892 rwh_view->SetSize(view_->GetContainerSize());
2893
2894 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2895 render_view_host);
2896 return true;
2897}
2898
2899void TabContents::Observe(NotificationType type,
2900 const NotificationSource& source,
2901 const NotificationDetails& details) {
2902 switch (type.value) {
2903 case NotificationType::BOOKMARK_MODEL_LOADED:
2904 // BookmarkModel finished loading, fall through to update starred state.
2905 case NotificationType::URLS_STARRED: {
2906 // Somewhere, a URL has been starred.
2907 // Ignore notifications for profiles other than our current one.
2908 Profile* source_profile = Source<Profile>(source).ptr();
2909 if (!source_profile || !source_profile->IsSameProfile(profile()))
2910 return;
2911
2912 UpdateStarredStateForCurrentURL();
2913 break;
2914 }
2915 case NotificationType::PREF_CHANGED: {
2916 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2917 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2918 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2919 UpdateAlternateErrorPageURL();
2920 } else if (*pref_name_in == prefs::kDefaultCharset ||
2921 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2922 ) {
2923 UpdateWebPreferences();
2924 } else {
2925 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2926 }
2927 break;
2928 }
2929 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2930 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2931 break;
2932
2933 case NotificationType::NAV_ENTRY_COMMITTED: {
2934 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2935
2936 NavigationController::LoadCommittedDetails& committed_details =
2937 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2938 ExpireInfoBars(committed_details);
2939 break;
2940 }
2941
[email protected]d3ba77272009-09-03 00:06:092942#if defined(OS_LINUX)
2943 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542944 renderer_preferences_util::UpdateFromSystemSettings(
2945 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092946 render_view_host()->SyncRendererPrefs();
2947 break;
2948 }
2949#endif
2950
[email protected]6c32ce72010-03-08 05:18:062951 case NotificationType::USER_STYLE_SHEET_UPDATED:
2952 UpdateWebPreferences();
2953 break;
2954
[email protected]79580c62010-02-02 02:36:252955 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292956 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252957 settings_details(details);
[email protected]79580c62010-02-02 02:36:252958 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492959 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292960 if (entry)
[email protected]da0c8e92010-02-09 23:25:492961 entry_url = entry->url();
[email protected]79580c62010-02-02 02:36:252962 Source<HostContentSettingsMap> content_settings(source);
[email protected]0314ae02010-04-08 09:18:292963 if (settings_details.ptr()->update_all() ||
2964 settings_details.ptr()->pattern().Matches(entry_url)) {
2965 render_view_host()->SendContentSettings(entry_url,
[email protected]da0c8e92010-02-09 23:25:492966 content_settings.ptr()->GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252967 }
2968 break;
2969 }
2970
[email protected]a888b29e62010-04-01 13:38:572971 case NotificationType::EXTENSION_LOADED: {
[email protected]98aa0b52010-05-06 17:03:082972 if (!extension_app_ && !extension_app_for_current_page_ &&
[email protected]a888b29e62010-04-01 13:38:572973 Source<Profile>(source).ptr() == profile()) {
[email protected]98aa0b52010-05-06 17:03:082974 UpdateExtensionAppForCurrentPage();
2975 if (extension_app_for_current_page_)
[email protected]a888b29e62010-04-01 13:38:572976 NotifyNavigationStateChanged(INVALIDATE_TAB);
2977 }
2978 break;
2979 }
2980
2981 case NotificationType::EXTENSION_UNLOADED:
2982 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
[email protected]98aa0b52010-05-06 17:03:082983 if (extension_app_for_current_page_ ==
[email protected]a888b29e62010-04-01 13:38:572984 Details<Extension>(details).ptr()) {
[email protected]98aa0b52010-05-06 17:03:082985 extension_app_for_current_page_ = NULL;
2986 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:572987 NotifyNavigationStateChanged(INVALIDATE_TAB);
2988 }
2989 break;
2990 }
2991
[email protected]420ae012009-04-24 05:16:322992 default:
2993 NOTREACHED();
2994 }
2995}
[email protected]aacd7cc2009-09-02 14:51:102996
[email protected]98aa0b52010-05-06 17:03:082997void TabContents::UpdateExtensionAppIcon(Extension* extension) {
2998 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432999
[email protected]a888b29e62010-04-01 13:38:573000 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083001 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3002 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573003 extension,
3004 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3005 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3006 Extension::EXTENSION_ICON_SMALLISH),
3007 ImageLoadingTracker::CACHE);
3008 } else {
[email protected]98aa0b52010-05-06 17:03:083009 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573010 }
3011}
3012
3013Extension* TabContents::GetExtensionContaining(const GURL& url) {
3014 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3015 if (!extensions_service)
3016 return NULL;
3017
3018 Extension* extension = extensions_service->GetExtensionByURL(url);
3019 return extension ?
3020 extension : extensions_service->GetExtensionByWebExtent(url);
3021}
3022
[email protected]98aa0b52010-05-06 17:03:083023void TabContents::UpdateExtensionAppForCurrentPage() {
3024 if (extension_app_) {
[email protected]a888b29e62010-04-01 13:38:573025 // Tab has an explicit app extension; nothing to do.
3026 return;
3027 }
3028
3029 // Check the current extension before iterating through all extensions.
[email protected]98aa0b52010-05-06 17:03:083030 if (extension_app_for_current_page_ &&
3031 extension_app_for_current_page_->web_extent().ContainsURL(GetURL())) {
[email protected]a888b29e62010-04-01 13:38:573032 return;
3033 }
3034
[email protected]98aa0b52010-05-06 17:03:083035 extension_app_for_current_page_ = GetExtensionContaining(GetURL());
3036 UpdateExtensionAppIcon(extension_app_for_current_page_);
[email protected]a888b29e62010-04-01 13:38:573037}
3038
3039void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3040 int index) {
3041 if (image) {
[email protected]98aa0b52010-05-06 17:03:083042 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573043 NotifyNavigationStateChanged(INVALIDATE_TAB);
3044 }
3045}
3046
[email protected]beb440c2009-11-06 04:08:543047std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3048 bool is_alert) {
3049 if (!frame_url.has_host())
3050 return l10n_util::GetString(
3051 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3052 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3053
3054 // We really only want the scheme, hostname, and port.
3055 GURL::Replacements replacements;
3056 replacements.ClearUsername();
3057 replacements.ClearPassword();
3058 replacements.ClearPath();
3059 replacements.ClearQuery();
3060 replacements.ClearRef();
3061 GURL clean_url = frame_url.ReplaceComponents(replacements);
3062
3063 // TODO(brettw) it should be easier than this to do the correct language
3064 // handling without getting the accept language from the profile.
3065 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3066 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3067 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563068 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543069
3070 return l10n_util::GetStringF(
3071 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3072 base_address);
3073}
3074
3075gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3076 return view_->GetTopLevelNativeWindow();
3077}
3078
3079void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3080 bool success,
3081 const std::wstring& prompt) {
3082 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3083 if (is_showing_before_unload_dialog_ && !success) {
3084 // If a beforeunload dialog is canceled, we need to stop the throbber from
3085 // spinning, since we forced it to start spinning in Navigate.
3086 DidStopLoading();
3087
3088 tab_close_start_time_ = base::TimeTicks();
3089 }
3090 is_showing_before_unload_dialog_ = false;
3091 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3092}
3093
3094void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3095 set_suppress_javascript_messages(suppress_message_boxes);
3096}
3097
[email protected]41fc0322009-09-04 22:23:403098void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103099 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3100}
[email protected]f45d2a72010-03-08 23:28:353101
3102void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3103 app_icon_ = app_icon;
3104 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3105}
[email protected]ea68c06a2010-04-23 17:25:373106
3107// After a successful *new* login attempt, we take the PasswordFormManager in
3108// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3109// the user makes up their mind with the "save password" infobar. Note if the
3110// login is one we already know about, the end of the line is
3111// provisional_save_manager_ because we just update it on success and so such
3112// forms never end up in an infobar.
3113class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3114 public:
3115 SavePasswordInfoBarDelegate(TabContents* tab_contents,
3116 PasswordFormManager* form_to_save) :
3117 ConfirmInfoBarDelegate(tab_contents),
3118 form_to_save_(form_to_save) {
3119 }
3120
3121 virtual ~SavePasswordInfoBarDelegate() { }
3122
3123 // Overridden from ConfirmInfoBarDelegate:
3124 virtual void InfoBarClosed() {
3125 delete this;
3126 }
3127
3128 virtual std::wstring GetMessageText() const {
3129 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3130 }
3131
3132 virtual SkBitmap* GetIcon() const {
3133 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3134 IDR_INFOBAR_SAVE_PASSWORD);
3135 }
3136
3137 virtual int GetButtons() const {
3138 return BUTTON_OK | BUTTON_CANCEL;
3139 }
3140
3141 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3142 if (button == BUTTON_OK)
3143 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3144 if (button == BUTTON_CANCEL)
3145 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3146 NOTREACHED();
3147 return std::wstring();
3148 }
3149
3150 virtual bool Accept() {
3151 DCHECK(form_to_save_.get());
3152 form_to_save_->Save();
3153 return true;
3154 }
3155
3156 virtual bool Cancel() {
3157 DCHECK(form_to_save_.get());
3158 form_to_save_->PermanentlyBlacklist();
3159 return true;
3160 }
3161
3162 private:
3163 // The PasswordFormManager managing the form we're asking the user about,
3164 // and should update as per her decision.
3165 scoped_ptr<PasswordFormManager> form_to_save_;
3166
3167 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3168};
3169
3170void TabContents::FillPasswordForm(
3171 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3172 render_view_host()->FillPasswordForm(form_data);
3173}
3174
3175void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3176 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3177}
3178
3179Profile* TabContents::GetProfileForPasswordManager() {
3180 return profile();
3181}
3182
3183bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3184 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3185}