blob: 52b66984db36bba94bfc84ce7259220f1e7c86cf [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);
683 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
684 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
685 case net::LOAD_STATE_RESOLVING_HOST:
686 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
687 case net::LOAD_STATE_CONNECTING:
688 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
689 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56690 if (upload_size_)
691 return l10n_util::GetStringF(
692 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
693 static_cast<int>((100 * upload_position_) / upload_size_));
694 else
695 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54696 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
697 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
698 load_state_host_);
699 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
700 case net::LOAD_STATE_IDLE:
701 case net::LOAD_STATE_READING_RESPONSE:
702 break;
703 }
704
705 return std::wstring();
706}
707
[email protected]d5f942ba2008-09-26 19:30:34708void TabContents::SetIsCrashed(bool state) {
709 if (state == is_crashed_)
710 return;
711
712 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50713 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34714}
715
[email protected]744ef172009-10-16 21:53:46716void TabContents::PageActionStateChanged() {
717 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00718}
[email protected]ce5c4502009-05-06 16:46:11719
[email protected]d5f942ba2008-09-26 19:30:34720void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
721 if (delegate_)
722 delegate_->NavigationStateChanged(this, changed_flags);
723}
724
[email protected]96d185d2009-04-24 03:28:54725void TabContents::DidBecomeSelected() {
726 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16727 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
728 if (rwhv) {
729 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43730#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16731 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43732#endif
733 }
[email protected]96d185d2009-04-24 03:28:54734
[email protected]8cb5d5b2010-02-09 11:36:16735 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54736}
737
738void TabContents::WasHidden() {
739 if (!capturing_contents()) {
740 // |render_view_host()| can be NULL if the user middle clicks a link to open
741 // a tab in then background, then closes the tab before selecting it. This
742 // is because closing the tab calls TabContents::Destroy(), which removes
743 // the |render_view_host()|; then when we actually destroy the window,
744 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16745 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
746 if (rwhv)
747 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54748 }
749
750 NotificationService::current()->Notify(
751 NotificationType::TAB_CONTENTS_HIDDEN,
752 Source<TabContents>(this),
753 NotificationService::NoDetails());
754}
755
[email protected]d5f942ba2008-09-26 19:30:34756void TabContents::Activate() {
757 if (delegate_)
758 delegate_->ActivateContents(this);
759}
760
[email protected]96d185d2009-04-24 03:28:54761void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16762 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
763 if (rwhv)
764 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54765}
766
767void TabContents::HideContents() {
768 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
769 // our superclass HideContents(), because some callers want to be very picky
770 // about the order in which these get called. In addition to making the code
771 // here practically impossible to understand, this also means we end up
772 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34773 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54774 WasHidden();
775}
776
[email protected]c0588052008-10-27 23:01:50777void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34778 WindowOpenDisposition disposition,
779 PageTransition::Type transition) {
780 if (delegate_)
[email protected]c0588052008-10-27 23:01:50781 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34782}
783
[email protected]1ccb3568d2010-02-19 10:51:16784bool TabContents::NavigateToPendingEntry(
785 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54786 const NavigationEntry& entry = *controller_.pending_entry();
787
788 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
789 if (!dest_render_view_host)
790 return false; // Unable to create the desired render view host.
791
[email protected]9fb325e2010-05-06 18:23:24792 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications())
793 dest_render_view_host->EnablePreferredSizeChangedMode();
794
[email protected]0352e5472010-04-29 00:11:40795 // For security, we should never send non-DOM-UI URLs (other than about:blank)
796 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58797 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40798 bool is_allowed_in_dom_ui_renderer =
799 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
800 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58801 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40802 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58803
[email protected]96d185d2009-04-24 03:28:54804 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12805 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32806 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00807 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
808 dest_render_view_host,
809 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32810 }
[email protected]96d185d2009-04-24 03:28:54811
812 // Used for page load time metrics.
813 current_load_start_ = base::TimeTicks::Now();
814
815 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34816 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00817 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34818 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54819
820 if (entry.page_id() == -1) {
821 // HACK!! This code suppresses javascript: URLs from being added to
822 // session history, which is what we want to do for javascript: URLs that
823 // do not generate content. What we really need is a message from the
824 // renderer telling us that a new page was not created. The same message
825 // could be used for mailto: URLs and the like.
826 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
827 return false;
828 }
829
830 // Clear any provisional password saves - this stops password infobars
831 // showing up on pages the user navigates to while the right page is
832 // loading.
833 GetPasswordManager()->ClearProvisionalSave();
834
[email protected]1ccb3568d2010-02-19 10:51:16835 if (reload_type != NavigationController::NO_RELOAD &&
836 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48837 FaviconService* favicon_service =
838 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
839 if (favicon_service)
840 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54841 }
842
[email protected]a888b29e62010-04-01 13:38:57843 // The url likely changed, see if there is an extension whose extent contains
844 // the current page.
[email protected]98aa0b52010-05-06 17:03:08845 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:57846
[email protected]d5f942ba2008-09-26 19:30:34847 return true;
848}
849
[email protected]96d185d2009-04-24 03:28:54850void TabContents::Stop() {
851 render_manager_.Stop();
852 printing_.Stop();
853}
854
[email protected]96d185d2009-04-24 03:28:54855void TabContents::DisassociateFromPopupCount() {
856 render_view_host()->DisassociateFromPopupCount();
857}
858
859TabContents* TabContents::Clone() {
860 // We create a new SiteInstance so that the new tab won't share processes
861 // with the old one. This can be changed in the future if we need it to share
862 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32863 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54864 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21865 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54866 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08867 tc->extension_app_ = extension_app_;
868 tc->extension_app_for_current_page_ = extension_app_for_current_page_;
869 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54870 return tc;
871}
872
[email protected]4d677202009-07-19 07:37:12873void TabContents::ShowPageInfo(const GURL& url,
874 const NavigationEntry::SSLStatus& ssl,
875 bool show_history) {
876 if (!delegate_)
877 return;
878
[email protected]bb678332009-07-21 00:15:50879 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12880}
881
initial.commit09911bf2008-07-26 23:55:29882ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28883 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29884 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28885 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29886 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44887
888 if (child_windows_.size() == 1) {
889 window->ShowConstrainedWindow();
890 BlockTabContent(true);
891 }
892
initial.commit09911bf2008-07-26 23:55:29893 return window;
894}
895
[email protected]fa1cf0b82010-01-15 21:49:44896void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55897 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
898 if (rwhv)
899 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44900 render_view_host()->set_ignore_input_events(blocked);
901 if (delegate_)
902 delegate_->SetTabContentBlocked(this, blocked);
903}
904
initial.commit09911bf2008-07-26 23:55:29905void TabContents::AddNewContents(TabContents* new_contents,
906 WindowOpenDisposition disposition,
907 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29908 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29909 if (!delegate_)
910 return;
911
[email protected]35f7d212009-04-29 21:19:27912 if ((disposition == NEW_POPUP) && !user_gesture &&
913 !CommandLine::ForCurrentProcess()->HasSwitch(
914 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22915 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31916 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29917 delegate_->GetConstrainingContents(this)->AddPopup(
918 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31919 } else {
[email protected]304f8792009-08-19 21:28:09920#if defined(OS_CHROMEOS)
921 if (disposition == NEW_POPUP) {
922 // If the popup is bigger than a given factor of the screen, then
923 // turn it into a foreground tab (on chrome os only)
924 GdkScreen* screen = gdk_screen_get_default();
925 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
926 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
927 if (initial_pos.width() > max_width ||
928 initial_pos.height() > max_height) {
929 disposition = NEW_FOREGROUND_TAB;
930 }
931 }
932#endif
933
[email protected]0aa55312008-10-17 21:53:08934 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29935 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
936 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49937 NotificationService::current()->Notify(
938 NotificationType::TAB_ADDED,
939 Source<TabContentsDelegate>(delegate_),
940 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29941 }
initial.commit09911bf2008-07-26 23:55:29942
[email protected]8cc8d492010-02-02 10:40:49943 // TODO(pkasting): Why is this necessary?
944 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:29945}
946
[email protected]bcd9dc42010-01-23 16:38:18947bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:20948 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:20949 bool is_js_code, const std::string& code_string,
950 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:51951 RenderViewHost* host = render_view_host();
952 if (!host)
953 return false;
954
955 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
956 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
957 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:35958}
959
[email protected]96d185d2009-04-24 03:28:54960void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:49961 if (is_being_destroyed_)
962 return;
963 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:40964 render_view_host()->AllowScriptToClose(!visible);
[email protected]0de80162010-02-03 04:52:35965 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:24966 delegate_->OnContentSettingsChange(this);
[email protected]96d185d2009-04-24 03:28:54967}
968
[email protected]5c9e97a2009-09-09 23:48:30969gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:54970 return view_->GetContentNativeView();
971}
972
973gfx::NativeView TabContents::GetNativeView() const {
974 return view_->GetNativeView();
975}
976
977void TabContents::GetContainerBounds(gfx::Rect *out) const {
978 view_->GetContainerBounds(out);
979}
980
981void TabContents::Focus() {
982 view_->Focus();
983}
984
[email protected]90daadb42009-06-08 21:27:28985void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:54986 if (showing_interstitial_page()) {
987 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
988 return;
989 }
[email protected]96d185d2009-04-24 03:28:54990 render_view_host()->SetInitialFocus(reverse);
991}
992
993bool TabContents::FocusLocationBarByDefault() {
994 DOMUI* dom_ui = GetDOMUIForCurrentState();
995 if (dom_ui)
996 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:43997 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:25998 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:43999 return true;
[email protected]96d185d2009-04-24 03:28:541000 return false;
1001}
1002
[email protected]a26dc362010-04-23 01:48:581003void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381004 if (delegate())
[email protected]a26dc362010-04-23 01:48:581005 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381006}
1007
[email protected]616ed5a2008-11-21 22:27:241008void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321009 if (delegate_ && !delegate_->infobars_enabled()) {
1010 delegate->InfoBarClosed();
1011 return;
1012 }
1013
[email protected]616ed5a2008-11-21 22:27:241014 // Look through the existing InfoBarDelegates we have for a match. If we've
1015 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051016 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451017 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1018 // Tell the new infobar to close so that it can clean itself up.
1019 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241020 return;
[email protected]6d27a7b2009-12-18 23:25:451021 }
[email protected]616ed5a2008-11-21 22:27:241022 }
1023
1024 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561025 NotificationService::current()->Notify(
1026 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1027 Source<TabContents>(this),
1028 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241029
1030 // Add ourselves as an observer for navigations the first time a delegate is
1031 // added. We use this notification to expire InfoBars that need to expire on
1032 // page transitions.
1033 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561034 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571035 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241036 }
1037}
1038
1039void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321040 if (delegate_ && !delegate_->infobars_enabled()) {
1041 return;
1042 }
1043
[email protected]616ed5a2008-11-21 22:27:241044 std::vector<InfoBarDelegate*>::iterator it =
1045 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1046 if (it != infobar_delegates_.end()) {
1047 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561048 NotificationService::current()->Notify(
1049 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1050 Source<TabContents>(this),
1051 Details<InfoBarDelegate>(delegate));
[email protected]f86a07022008-11-25 01:06:051052 infobar_delegates_.erase(it);
[email protected]616ed5a2008-11-21 22:27:241053
[email protected]6a02963e2009-01-06 16:58:031054 // Remove ourselves as an observer if we are tracking no more InfoBars.
1055 if (infobar_delegates_.empty()) {
[email protected]bfd04a62009-02-01 18:16:561056 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571057 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031058 }
[email protected]616ed5a2008-11-21 22:27:241059 }
1060}
[email protected]3edd9522009-03-04 22:19:411061
[email protected]f81821c2009-08-07 01:29:471062void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1063 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321064 if (delegate_ && !delegate_->infobars_enabled()) {
1065 new_delegate->InfoBarClosed();
1066 return;
1067 }
1068
[email protected]f81821c2009-08-07 01:29:471069 std::vector<InfoBarDelegate*>::iterator it =
1070 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1071 DCHECK(it != infobar_delegates_.end());
1072
1073 // Notify the container about the change of plans.
1074 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1075 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1076 old_delegate, new_delegate));
1077 NotificationService::current()->Notify(
1078 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1079 Source<TabContents>(this),
1080 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1081
1082 // Remove the old one.
1083 infobar_delegates_.erase(it);
1084
1085 // Add the new one.
1086 infobar_delegates_.push_back(new_delegate);
1087}
1088
[email protected]20ede072009-10-06 00:28:351089bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271090 if (showing_interstitial_page())
1091 return false;
1092
[email protected]96d185d2009-04-24 03:28:541093 // See GetDOMUIForCurrentState() comment for more info. This case is very
1094 // similar, but for non-first loads, we want to use the committed entry. This
1095 // is so the bookmarks bar disappears at the same time the page does.
1096 if (controller_.GetLastCommittedEntry()) {
1097 // Not the first load, always use the committed DOM UI.
1098 if (render_manager_.dom_ui())
1099 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1100 return false; // Default.
1101 }
1102
1103 // When it's the first load, we know either the pending one or the committed
1104 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1105 // of them will be valid, so we can just check both.
1106 if (render_manager_.pending_dom_ui())
1107 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1108 if (render_manager_.dom_ui())
1109 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1110 return false; // Default.
1111}
1112
[email protected]d8f16ae2009-08-30 03:47:261113bool TabContents::IsExtensionShelfAlwaysVisible() {
1114 // See GetDOMUIForCurrentState() comment for more info. This case is very
1115 // similar, but for non-first loads, we want to use the committed entry. This
1116 // is so the bookmarks bar disappears at the same time the page does.
1117 if (controller_.GetLastCommittedEntry()) {
1118 // Not the first load, always use the committed DOM UI.
1119 if (render_manager_.dom_ui())
1120 return render_manager_.dom_ui()->force_extension_shelf_visible();
1121 return false; // Default.
1122 }
1123
1124 // When it's the first load, we know either the pending one or the committed
1125 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1126 // of them will be valid, so we can just check both.
1127 if (render_manager_.pending_dom_ui())
1128 return render_manager_.pending_dom_ui()->force_extension_shelf_visible();
1129 if (render_manager_.dom_ui())
1130 return render_manager_.dom_ui()->force_extension_shelf_visible();
1131 return false; // Default.
1132}
1133
[email protected]3edd9522009-03-04 22:19:411134void TabContents::ToolbarSizeChanged(bool is_animating) {
1135 TabContentsDelegate* d = delegate();
1136 if (d)
1137 d->ToolbarSizeChanged(this, is_animating);
1138}
[email protected]616ed5a2008-11-21 22:27:241139
[email protected]fc6fb7fb2009-11-07 02:35:041140bool TabContents::CanDownload(int request_id) {
1141 TabContentsDelegate* d = delegate();
1142 if (d)
1143 return d->CanDownload(request_id);
1144 return true;
1145}
1146
[email protected]d5f942ba2008-09-26 19:30:341147void TabContents::OnStartDownload(DownloadItem* download) {
1148 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341149
1150 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311151 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341152
[email protected]c70f9b82010-04-21 07:31:111153 if (tab_contents && tab_contents->delegate()) {
[email protected]59560e0b2009-06-04 03:30:221154 tab_contents->delegate()->OnStartDownload(download);
[email protected]c70f9b82010-04-21 07:31:111155 // If the download occurs in a new tab, close it
1156 if (controller_.IsInitialNavigation() && (tab_contents == this))
1157 delegate()->CloseContents(this);
1158 }
[email protected]3edd9522009-03-04 22:19:411159}
[email protected]3edd9522009-03-04 22:19:411160
[email protected]d5f942ba2008-09-26 19:30:341161void TabContents::WillClose(ConstrainedWindow* window) {
1162 ConstrainedWindowList::iterator it =
1163 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441164 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341165 if (it != child_windows_.end())
1166 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371167 if (child_windows_.size() > 0) {
1168 if (removed_topmost_window) {
1169 child_windows_[0]->ShowConstrainedWindow();
1170 }
[email protected]fa1cf0b82010-01-15 21:49:441171 BlockTabContent(true);
1172 } else {
1173 BlockTabContent(false);
1174 }
[email protected]66ba4932009-06-04 19:22:131175}
[email protected]d5f942ba2008-09-26 19:30:341176
[email protected]66ba4932009-06-04 19:22:131177void TabContents::WillCloseBlockedPopupContainer(
1178 BlockedPopupContainer* container) {
1179 DCHECK(blocked_popups_ == container);
1180 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491181 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341182}
1183
[email protected]d5f942ba2008-09-26 19:30:341184void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351185#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061186 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351187#endif
[email protected]d5f942ba2008-09-26 19:30:341188}
1189
[email protected]c1dc9f132009-11-20 23:13:211190void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121191 bool forward_direction,
1192 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211193 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011194 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211195 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531196 string16 last_search_prepopulate_text =
1197 FindBarState::GetLastPrepopulateText(profile());
1198
[email protected]87fae512009-12-11 02:20:211199 // Try the last thing we searched for on this tab, then the last thing
1200 // searched for on any tab.
1201 if (!previous_find_text_.empty())
1202 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531203 else if (!last_search_prepopulate_text.empty())
1204 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211205 else
[email protected]e491f1c2009-05-22 20:28:121206 return;
[email protected]e491f1c2009-05-22 20:28:121207 }
[email protected]6e95706d2009-04-23 22:55:011208
[email protected]101c90e2009-10-26 21:14:441209 // Keep track of the previous search.
1210 previous_find_text_ = find_text_;
1211
[email protected]6e95706d2009-04-23 22:55:011212 // This is a FindNext operation if we are searching for the same text again,
1213 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1214 // exception to this is if the Find was aborted (then we don't want FindNext
1215 // because the highlighting has been cleared and we need it to reappear). We
1216 // therefore treat FindNext after an aborted Find operation as a full fledged
1217 // Find.
[email protected]c1dc9f132009-11-20 23:13:211218 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121219 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011220 !find_op_aborted_;
1221 if (!find_next)
1222 current_find_request_id_ = find_request_id_counter_++;
1223
[email protected]c1dc9f132009-11-20 23:13:211224 if (!search_string.empty())
1225 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121226 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011227
1228 find_op_aborted_ = false;
1229
1230 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531231 FindBarState* find_bar_state = profile()->GetFindBarState();
1232 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011233 render_view_host()->StartFinding(current_find_request_id_,
1234 find_text_,
1235 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121236 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011237 find_next);
1238}
1239
[email protected]5bc8fe92010-03-11 18:19:001240void TabContents::StopFinding(
1241 FindBarController::SelectionAction selection_action) {
1242 // When the action is kClearAction, it means the find string has been cleared
[email protected]2d2dffc2009-06-09 21:41:001243 // by the user, but the UI has not been dismissed.
[email protected]5bc8fe92010-03-11 18:19:001244 if (selection_action != FindBarController::kClearSelection)
[email protected]2d2dffc2009-06-09 21:41:001245 find_ui_active_ = false;
[email protected]726bdbd72010-04-05 17:08:071246 if (!find_text_.empty())
1247 previous_find_text_ = find_text_;
[email protected]101c90e2009-10-26 21:14:441248 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011249 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121250 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001251 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011252}
1253
[email protected]420ae012009-04-24 05:16:321254void TabContents::OnSavePage() {
1255 // If we can not save the page, try to download it.
1256 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1257 DownloadManager* dlm = profile()->GetDownloadManager();
1258 const GURL& current_page_url = GetURL();
1259 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221260 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321261 return;
1262 }
1263
1264 Stop();
1265
1266 // Create the save package and possibly prompt the user for the name to save
1267 // the page as. The user prompt is an asynchronous operation that runs on
1268 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221269 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321270 save_package_->GetSaveInfo();
1271}
1272
1273// Used in automated testing to bypass prompting the user for file names.
1274// Instead, the names and paths are hard coded rather than running them through
1275// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111276bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321277 SavePackage::SavePackageType save_type) {
1278 // Stop the page from navigating.
1279 Stop();
1280
[email protected]828cabe2009-09-26 22:47:111281 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591282 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321283}
1284
[email protected]89d6e6e2009-12-03 23:06:511285void TabContents::EmailPageLocation() {
1286 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1287 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1288 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1289 title + "&body=%0A%0A" + page_url;
1290 platform_util::OpenExternal(GURL(mailto));
1291}
1292
[email protected]420ae012009-04-24 05:16:321293void TabContents::PrintPreview() {
1294 // We don't show the print preview yet, only the print dialog.
1295 PrintNow();
1296}
1297
1298bool TabContents::PrintNow() {
1299 // We can't print interstitial page for now.
1300 if (showing_interstitial_page())
1301 return false;
1302
1303 return render_view_host()->PrintPages();
1304}
1305
[email protected]82270452009-06-19 15:58:011306void TabContents::PrintingDone(int document_cookie, bool success) {
1307 render_view_host()->PrintingDone(document_cookie, success);
1308}
1309
[email protected]420ae012009-04-24 05:16:321310bool TabContents::IsActiveEntry(int32 page_id) {
1311 NavigationEntry* active_entry = controller_.GetActiveEntry();
1312 return (active_entry != NULL &&
1313 active_entry->site_instance() == GetSiteInstance() &&
1314 active_entry->page_id() == page_id);
1315}
1316
[email protected]b2fe07d12010-02-09 14:38:081317void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161318 set_encoding(encoding);
1319 render_view_host()->SetPageEncoding(encoding);
1320}
1321
[email protected]b2fe07d12010-02-09 14:38:081322void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161323 reset_encoding();
1324 render_view_host()->ResetPageEncodingToDefault();
1325}
1326
1327void TabContents::WindowMoveOrResizeStarted() {
1328 render_view_host()->WindowMoveOrResizeStarted();
1329}
1330
[email protected]3f8eb7f2009-10-02 23:58:051331void TabContents::LogNewTabTime(const std::string& event_name) {
1332 // Not all new tab pages get timed. In those cases, we don't have a
1333 // new_tab_start_time_.
1334 if (new_tab_start_time_.is_null())
1335 return;
1336
1337 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441338 MetricEventDurationDetails details(event_name,
1339 static_cast<int>(duration.InMilliseconds()));
1340
[email protected]7ab1e7d62009-10-14 23:32:011341 if (event_name == "Tab.NewTabScriptStart") {
1342 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1343 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1344 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1345 } else if (event_name == "Tab.NewTabOnload") {
1346 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051347 // The new tab page has finished loading; reset it.
1348 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441349 } else {
1350 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051351 }
[email protected]84abba62009-10-07 17:01:441352 NotificationService::current()->Notify(
1353 NotificationType::METRIC_EVENT_DURATION,
1354 Source<TabContents>(this),
1355 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051356}
1357
[email protected]7ab1e7d62009-10-14 23:32:011358void TabContents::OnCloseStarted() {
1359 if (tab_close_start_time_.is_null())
1360 tab_close_start_time_ = base::TimeTicks::Now();
1361}
1362
[email protected]c37e3b62010-01-22 00:15:171363TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171364 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161365
1366 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081367 if (extension_app_)
1368 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161369 else if (entry)
1370 tab_nav.SetFromNavigationEntry(*entry);
1371
[email protected]c37e3b62010-01-22 00:15:171372 std::vector<TabNavigation> navigations;
1373 navigations.push_back(tab_nav);
1374
1375 TabContents* new_contents =
1376 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081377 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171378 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171379
[email protected]98aa0b52010-05-06 17:03:081380 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161381 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1382
[email protected]c37e3b62010-01-22 00:15:171383 return new_contents;
1384}
1385
[email protected]0de80162010-02-03 04:52:351386// Resets the |content_blocked_| array.
1387void TabContents::ClearBlockedContentSettings() {
[email protected]15cf526b2010-02-12 06:33:491388 for (size_t i = 0; i < arraysize(content_blocked_); ++i)
[email protected]0de80162010-02-03 04:52:351389 content_blocked_[i] = false;
1390}
1391
[email protected]96d185d2009-04-24 03:28:541392// Notifies the RenderWidgetHost instance about the fact that the page is
1393// loading, or done loading and calls the base implementation.
1394void TabContents::SetIsLoading(bool is_loading,
1395 LoadNotificationDetails* details) {
1396 if (is_loading == is_loading_)
1397 return;
1398
1399 if (!is_loading) {
1400 load_state_ = net::LOAD_STATE_IDLE;
1401 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561402 upload_size_ = 0;
1403 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541404 }
1405
1406 render_manager_.SetIsLoading(is_loading);
1407
1408 is_loading_ = is_loading;
1409 waiting_for_response_ = is_loading;
1410
1411 if (delegate_)
1412 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351413 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541414
1415 NotificationType type = is_loading ? NotificationType::LOAD_START :
1416 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111417 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541418 if (details)
1419 det = Details<LoadNotificationDetails>(details);
1420 NotificationService::current()->Notify(type,
1421 Source<NavigationController>(&controller_),
1422 det);
1423}
1424
[email protected]b6c874582009-05-08 19:38:311425void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291426 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061427 // A page can't spawn popups (or do anything else, either) until its load
1428 // commits, so when we reach here, the popup was spawned by the
1429 // NavigationController's last committed entry, not the active entry. For
1430 // example, if a page opens a popup in an onunload() handler, then the active
1431 // entry is the page to be loaded as we navigate away from the unloading
1432 // page. For this reason, we can't use GetURL() to get the opener URL,
1433 // because it returns the active entry.
1434 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1435 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1436
1437 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491438 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]57eda82a2010-05-05 21:28:061439 creator, CONTENT_SETTINGS_TYPE_POPUPS) == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491440 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1441 } else {
1442 if (!blocked_popups_)
1443 blocked_popups_ = new BlockedPopupContainer(this);
1444 blocked_popups_->AddTabContents(new_contents, initial_pos);
1445 }
[email protected]b9681312008-11-07 00:08:261446}
[email protected]616ed5a2008-11-21 22:27:241447
1448namespace {
1449bool TransitionIsReload(PageTransition::Type transition) {
1450 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1451}
1452}
1453
1454void TabContents::ExpireInfoBars(
1455 const NavigationController::LoadCommittedDetails& details) {
1456 // Only hide InfoBars when the user has done something that makes the main
1457 // frame load. We don't want various automatic or subframe navigations making
1458 // it disappear.
1459 if (!details.is_user_initiated_main_frame_load())
1460 return;
1461
[email protected]f86a07022008-11-25 01:06:051462 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241463 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:051464 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241465 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241466 }
1467}
[email protected]fdd61c62009-04-22 19:22:571468
[email protected]96d185d2009-04-24 03:28:541469DOMUI* TabContents::GetDOMUIForCurrentState() {
1470 // When there is a pending navigation entry, we want to use the pending DOMUI
1471 // that goes along with it to control the basic flags. For example, we want to
1472 // show the pending URL in the URL bar, so we want the display_url flag to
1473 // be from the pending entry.
1474 //
1475 // The confusion comes because there are multiple possibilities for the
1476 // initial load in a tab as a side effect of the way the RenderViewHostManager
1477 // works.
1478 //
1479 // - For the very first tab the load looks "normal". The new tab DOM UI is
1480 // the pending one, and we want it to apply here.
1481 //
1482 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1483 // get switched to the one previously associated with the new tab pages.
1484 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1485 // have a committed DOM UI in this case.
1486 //
1487 // This condition handles all of these cases:
1488 //
1489 // - First load in first tab: no committed nav entry + pending nav entry +
1490 // pending dom ui:
1491 // -> Use pending DOM UI if any.
1492 //
1493 // - First load in second tab: no committed nav entry + pending nav entry +
1494 // no pending DOM UI:
1495 // -> Use the committed DOM UI if any.
1496 //
1497 // - Second navigation in any tab: committed nav entry + pending nav entry:
1498 // -> Use pending DOM UI if any.
1499 //
1500 // - Normal state with no load: committed nav entry + no pending nav entry:
1501 // -> Use committed DOM UI.
1502 if (controller_.pending_entry() &&
1503 (controller_.GetLastCommittedEntry() ||
1504 render_manager_.pending_dom_ui()))
1505 return render_manager_.pending_dom_ui();
1506 return render_manager_.dom_ui();
1507}
[email protected]420ae012009-04-24 05:16:321508
1509void TabContents::DidNavigateMainFramePostCommit(
1510 const NavigationController::LoadCommittedDetails& details,
1511 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441512 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1513 // If this is a window.open navigation, use the same DOMUI as the renderer
1514 // that opened the window, as long as both renderers have the same
1515 // privileges.
1516 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1517 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1518 // dom_ui might be NULL if the URL refers to a non-existent extension.
1519 if (dom_ui) {
1520 render_manager_.SetDOMUIPostCommit(dom_ui);
1521 dom_ui->RenderViewCreated(render_view_host());
1522 }
1523 }
1524 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1525 }
1526
[email protected]420ae012009-04-24 05:16:321527 if (details.is_user_initiated_main_frame_load()) {
1528 // Clear the status bubble. This is a workaround for a bug where WebKit
1529 // doesn't let us know that the cursor left an element during a
1530 // transition (this is also why the mouse cursor remains as a hand after
1531 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1532 // clear the bubble when a user navigates to a named anchor in the same
1533 // page.
1534 UpdateTargetURL(details.entry->page_id(), GURL());
1535
1536 // UpdateHelpersForDidNavigate will handle the case where the password_form
1537 // origin is valid.
1538 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1539 // cleaned up and covered by tests.
1540 if (!params.password_form.origin.is_valid())
1541 GetPasswordManager()->DidNavigate();
1542 }
1543
1544 // The keyword generator uses the navigation entries, so must be called after
1545 // the commit.
1546 GenerateKeywordIfNecessary(params);
1547
1548 // Allow the new page to set the title again.
1549 received_page_title_ = false;
1550
1551 // Get the favicon, either from history or request it from the net.
1552 fav_icon_helper_.FetchFavIcon(details.entry->url());
1553
[email protected]0de80162010-02-03 04:52:351554 // Clear all page actions, blocked content notifications and browser actions
1555 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141556 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081557 ExtensionsService* service = profile()->GetExtensionsService();
1558 if (service) {
1559 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571560 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081561 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521562 if (browser_action) {
1563 browser_action->ClearAllValuesForTab(controller().session_id().id());
1564 NotificationService::current()->Notify(
1565 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571566 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521567 NotificationService::NoDetails());
1568 }
[email protected]92c6f9b92009-10-24 04:35:081569
[email protected]5d246db22009-10-27 06:17:571570 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521571 service->extensions()->at(i)->page_action();
1572 if (page_action) {
1573 page_action->ClearAllValuesForTab(controller().session_id().id());
1574 PageActionStateChanged();
1575 }
[email protected]92c6f9b92009-10-24 04:35:081576 }
[email protected]aece2c7f2009-08-27 20:43:171577 }
[email protected]0de80162010-02-03 04:52:351578
1579 // Close blocked popups.
1580 if (blocked_popups_) {
1581 AutoReset auto_reset(&dont_notify_render_view_, true);
1582 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461583 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351584 }
1585
1586 // Clear "blocked" flags.
1587 ClearBlockedContentSettings();
[email protected]777a7b62010-05-11 13:28:161588 geolocation_settings_state_.DidNavigate(details);
[email protected]0de80162010-02-03 04:52:351589 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:241590 delegate_->OnContentSettingsChange(this);
[email protected]f17a0ee2010-05-17 17:38:471591
1592 // Once the main frame is navigated, we're no longer considered to have
1593 // displayed insecure content.
1594 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171595 }
[email protected]ce5c4502009-05-06 16:46:111596
[email protected]8cc8d492010-02-02 10:40:491597 // Close constrained windows if necessary.
1598 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1599 details.previous_url, details.entry->url()))
1600 CloseConstrainedWindows();
1601
[email protected]420ae012009-04-24 05:16:321602 // Update the starred state.
1603 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531604
1605 // Clear the cache of forms in AutoFill.
1606 if (autofill_manager_.get())
1607 autofill_manager_->Reset();
[email protected]a888b29e62010-04-01 13:38:571608
1609 // The url likely changed, see if there is an extension whose extent contains
1610 // the current page.
[email protected]98aa0b52010-05-06 17:03:081611 UpdateExtensionAppForCurrentPage();
[email protected]420ae012009-04-24 05:16:321612}
1613
1614void TabContents::DidNavigateAnyFramePostCommit(
1615 RenderViewHost* render_view_host,
1616 const NavigationController::LoadCommittedDetails& details,
1617 const ViewHostMsg_FrameNavigate_Params& params) {
1618 // If we navigate, start showing messages again. This does nothing to prevent
1619 // a malicious script from spamming messages, since the script could just
1620 // reload the page to stop blocking.
1621 suppress_javascript_messages_ = false;
1622
[email protected]420ae012009-04-24 05:16:321623 // Notify the password manager of the navigation or form submit.
1624 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1625 // cleaned up and covered by tests.
1626 if (params.password_form.origin.is_valid())
1627 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551628
1629 // Let the LanguageState clear its state.
[email protected]34cec8d82010-03-05 18:27:011630 bool reload = details.entry->transition_type() == PageTransition::RELOAD ||
1631 details.type == NavigationType::SAME_PAGE;
1632 language_state_.DidNavigate(reload, details.is_in_page);
[email protected]420ae012009-04-24 05:16:321633}
1634
[email protected]8cc8d492010-02-02 10:40:491635void TabContents::CloseConstrainedWindows() {
1636 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321637 // We use indices instead of iterators in case CloseWindow does something
1638 // that may invalidate an iterator.
1639 int size = static_cast<int>(child_windows_.size());
1640 for (int i = size - 1; i >= 0; --i) {
1641 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441642 if (window) {
[email protected]420ae012009-04-24 05:16:321643 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441644 BlockTabContent(false);
1645 }
[email protected]420ae012009-04-24 05:16:321646 }
1647}
1648
1649void TabContents::UpdateStarredStateForCurrentURL() {
1650 BookmarkModel* model = profile()->GetBookmarkModel();
1651 const bool old_state = is_starred_;
1652 is_starred_ = (model && model->IsBookmarked(GetURL()));
1653
1654 if (is_starred_ != old_state && delegate())
1655 delegate()->URLStarredChanged(this, is_starred_);
1656}
1657
1658void TabContents::UpdateAlternateErrorPageURL() {
1659 GURL url = GetAlternateErrorPageURL();
1660 render_view_host()->SetAlternateErrorPageURL(url);
1661}
1662
1663void TabContents::UpdateWebPreferences() {
1664 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1665}
1666
1667void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1668 RenderViewHost* rvh) {
1669 // If we are creating a RVH for a restored controller, then we might
1670 // have more page IDs than the SiteInstance's current max page ID. We must
1671 // make sure that the max page ID is larger than any restored page ID.
1672 // Note that it is ok for conflicting page IDs to exist in another tab
1673 // (i.e., NavigationController), but if any page ID is larger than the max,
1674 // the back/forward list will get confused.
1675 int max_restored_page_id = controller_.max_restored_page_id();
1676 if (max_restored_page_id > 0) {
1677 int curr_max_page_id = site_instance->max_page_id();
1678 if (max_restored_page_id > curr_max_page_id) {
1679 // Need to update the site instance immediately.
1680 site_instance->UpdateMaxPageID(max_restored_page_id);
1681
1682 // Also tell the renderer to update its internal representation. We
1683 // need to reserve enough IDs to make all restored page IDs less than
1684 // the max.
1685 if (curr_max_page_id < 0)
1686 curr_max_page_id = 0;
1687 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1688 }
1689 }
1690}
1691
1692void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541693 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471694 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321695 const ViewHostMsg_FrameNavigate_Params& params) {
1696 if (profile()->IsOffTheRecord())
1697 return;
1698
1699 // Add to history service.
1700 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1701 if (hs) {
1702 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541703 virtual_url != params.url) {
1704 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321705 // types of URLs, we will display a magic URL that is different from where
1706 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541707 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1708 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321709 // to sub-frames.
1710 std::vector<GURL> redirects = params.redirects;
1711 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541712 redirects.back() = virtual_url;
1713 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471714 params.transition, redirects, details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321715 } else {
1716 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]befd8d822009-07-01 04:51:471717 params.transition, params.redirects,
1718 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321719 }
1720 }
1721}
1722
1723bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1724 const std::wstring& title) {
1725 // For file URLs without a title, use the pathname instead. In the case of a
1726 // synthesized title, we don't want the update to count toward the "one set
1727 // per page of the title to history."
1728 std::wstring final_title;
1729 bool explicit_set;
1730 if (entry->url().SchemeIsFile() && title.empty()) {
1731 final_title = UTF8ToWide(entry->url().ExtractFileName());
1732 explicit_set = false; // Don't count synthetic titles toward the set limit.
1733 } else {
1734 TrimWhitespace(title, TRIM_ALL, &final_title);
1735 explicit_set = true;
1736 }
1737
1738 if (final_title == UTF16ToWideHack(entry->title()))
1739 return false; // Nothing changed, don't bother.
1740
1741 entry->set_title(WideToUTF16Hack(final_title));
1742
1743 // Update the history system for this page.
1744 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1745 HistoryService* hs =
1746 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1747 if (hs)
[email protected]ebe89e062009-08-13 23:16:541748 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321749
1750 // Don't allow the title to be saved again for explicitly set ones.
1751 received_page_title_ = explicit_set;
1752 }
1753
1754 // Lastly, set the title for the view.
1755 view_->SetPageTitle(final_title);
1756
[email protected]cbc0e1b2010-04-12 18:33:041757 NotificationService::current()->Notify(
1758 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1759 Source<TabContents>(this),
1760 NotificationService::NoDetails());
1761
[email protected]420ae012009-04-24 05:16:321762 return true;
1763}
1764
1765void TabContents::NotifySwapped() {
1766 // After sending out a swap notification, we need to send a disconnect
1767 // notification so that clients that pick up a pointer to |this| can NULL the
1768 // pointer. See Bug 1230284.
1769 notify_disconnection_ = true;
1770 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341771 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221772 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321773 NotificationService::NoDetails());
1774}
1775
1776void TabContents::NotifyConnected() {
1777 notify_disconnection_ = true;
1778 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341779 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221780 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321781 NotificationService::NoDetails());
1782}
1783
1784void TabContents::NotifyDisconnected() {
1785 if (!notify_disconnection_)
1786 return;
1787
1788 notify_disconnection_ = false;
1789 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341790 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221791 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321792 NotificationService::NoDetails());
1793}
1794
1795void TabContents::GenerateKeywordIfNecessary(
1796 const ViewHostMsg_FrameNavigate_Params& params) {
1797 if (!params.searchable_form_url.is_valid())
1798 return;
1799
1800 if (profile()->IsOffTheRecord())
1801 return;
1802
1803 int last_index = controller_.last_committed_entry_index();
1804 // When there was no previous page, the last index will be 0. This is
1805 // normally due to a form submit that opened in a new tab.
1806 // TODO(brettw) bug 916126: we should support keywords when form submits
1807 // happen in new tabs.
1808 if (last_index <= 0)
1809 return;
1810 const NavigationEntry* previous_entry =
1811 controller_.GetEntryAtIndex(last_index - 1);
1812 if (IsFormSubmit(previous_entry)) {
1813 // Only generate a keyword if the previous page wasn't itself a form
1814 // submit.
1815 return;
1816 }
1817
1818 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1819 previous_entry->user_typed_url() : previous_entry->url();
1820 std::wstring keyword =
1821 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1822 if (keyword.empty())
1823 return;
1824
1825 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1826 if (!url_model)
1827 return;
1828
1829 if (!url_model->loaded()) {
1830 url_model->Load();
1831 return;
1832 }
1833
1834 const TemplateURL* current_url;
1835 std::wstring url = UTF8ToWide(params.searchable_form_url.spec());
1836 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1837 return;
1838
1839 if (current_url) {
1840 if (current_url->originating_url().is_valid()) {
1841 // The existing keyword was generated from an OpenSearch description
1842 // document, don't regenerate.
1843 return;
1844 }
1845 url_model->Remove(current_url);
1846 }
1847 TemplateURL* new_url = new TemplateURL();
1848 new_url->set_keyword(keyword);
1849 new_url->set_short_name(keyword);
1850 new_url->SetURL(url, 0, 0);
1851 new_url->add_input_encoding(params.searchable_form_encoding);
1852 DCHECK(controller_.GetLastCommittedEntry());
1853 const GURL& favicon_url =
1854 controller_.GetLastCommittedEntry()->favicon().url();
1855 if (favicon_url.is_valid()) {
1856 new_url->SetFavIconURL(favicon_url);
1857 } else {
1858 // The favicon url isn't valid. This means there really isn't a favicon,
1859 // or the favicon url wasn't obtained before the load started. This assumes
1860 // the later.
1861 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1862 // its url.
1863 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1864 }
1865 new_url->set_safe_for_autoreplace(true);
1866 url_model->Add(new_url);
1867}
1868
[email protected]bf5c2ff392009-07-08 16:24:331869void TabContents::OnUserGesture() {
1870 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
1871 DownloadRequestManager* drm = g_browser_process->download_request_manager();
1872 if (drm)
1873 drm->OnUserGesture(this);
[email protected]e7eaedde2009-09-25 20:09:491874 ExternalProtocolHandler::OnUserGesture();
[email protected]bf5c2ff392009-07-08 16:24:331875 controller_.OnUserGesture();
1876}
1877
1878void TabContents::OnFindReply(int request_id,
1879 int number_of_matches,
1880 const gfx::Rect& selection_rect,
1881 int active_match_ordinal,
1882 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421883 // Ignore responses for requests that have been aborted.
1884 if (find_op_aborted_)
1885 return;
1886
[email protected]bf5c2ff392009-07-08 16:24:331887 // Ignore responses for requests other than the one we have most recently
1888 // issued. That way we won't act on stale results when the user has
1889 // already typed in another query.
1890 if (request_id != current_find_request_id_)
1891 return;
1892
1893 if (number_of_matches == -1)
1894 number_of_matches = last_search_result_.number_of_matches();
1895 if (active_match_ordinal == -1)
1896 active_match_ordinal = last_search_result_.active_match_ordinal();
1897
1898 gfx::Rect selection = selection_rect;
1899 if (selection.IsEmpty())
1900 selection = last_search_result_.selection_rect();
1901
1902 // Notify the UI, automation and any other observers that a find result was
1903 // found.
1904 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1905 selection, active_match_ordinal,
1906 final_update);
1907 NotificationService::current()->Notify(
1908 NotificationType::FIND_RESULT_AVAILABLE,
1909 Source<TabContents>(this),
1910 Details<FindNotificationDetails>(&last_search_result_));
1911}
1912
1913void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381914 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1915 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331916}
1917
[email protected]bf5c2ff392009-07-08 16:24:331918void TabContents::OnMissingPluginStatus(int status) {
1919#if defined(OS_WIN)
1920// TODO(PORT): pull in when plug-ins work
1921 GetPluginInstaller()->OnMissingPluginStatus(status);
1922#endif
1923}
1924
1925void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331926 DCHECK(!plugin_path.value().empty());
1927
1928 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351929#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331930 scoped_ptr<FileVersionInfo> version_info(
1931 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1932 if (version_info.get()) {
1933 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371934 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331935 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371936#if defined(OS_MACOSX)
1937 // Many plugins on the Mac have .plugin in the actual name, which looks
1938 // terrible, so look for that and strip it off if present.
1939 const std::wstring plugin_extension(L".plugin");
1940 if (EndsWith(plugin_name, plugin_extension, true))
1941 plugin_name.erase(plugin_name.length() - plugin_extension.length());
1942#endif // OS_MACOSX
1943 }
[email protected]bf5c2ff392009-07-08 16:24:331944 }
[email protected]4a560ed2009-07-13 23:35:261945#else
1946 NOTIMPLEMENTED() << " convert plugin path to plugin name";
1947#endif
[email protected]bf5c2ff392009-07-08 16:24:331948 AddInfoBar(new SimpleAlertInfoBarDelegate(
1949 this, l10n_util::GetStringF(IDS_PLUGIN_CRASHED_PROMPT, plugin_name),
[email protected]938e1f92010-04-01 18:09:421950 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331951}
1952
1953void TabContents::OnCrashedWorker() {
1954 AddInfoBar(new SimpleAlertInfoBarDelegate(
1955 this, l10n_util::GetString(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:421956 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:331957}
1958
1959void TabContents::OnDidGetApplicationInfo(
1960 int32 page_id,
1961 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:511962 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:331963
[email protected]ed5431872009-11-17 08:39:511964 if (delegate())
1965 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:331966}
1967
[email protected]a2cf65eb2010-01-18 08:20:381968void TabContents::OnPageContents(const GURL& url,
1969 int renderer_process_id,
1970 int32 page_id,
[email protected]a8a81292010-01-21 00:32:451971 const std::wstring& contents,
1972 const std::string& language) {
[email protected]a2cf65eb2010-01-18 08:20:381973 // Don't index any https pages. People generally don't want their bank
1974 // accounts, etc. indexed on their computer, especially since some of these
1975 // things are not marked cachable.
1976 // TODO(brettw) we may want to consider more elaborate heuristics such as
1977 // the cachability of the page. We may also want to consider subframes (this
1978 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:271979 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
1980 // content indexing for chromeos in some future releases.
1981#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:381982 if (!url.SchemeIsSecure()) {
1983 Profile* p = profile();
1984 if (p && !p->IsOffTheRecord()) {
1985 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
1986 if (hs)
1987 hs->SetPageContents(url, contents);
1988 }
1989 }
[email protected]ccd40a52010-05-11 16:15:271990#endif
[email protected]a8a81292010-01-21 00:32:451991
[email protected]3b1c1812010-02-12 21:53:551992 language_state_.LanguageDetermined(language);
[email protected]a8a81292010-01-21 00:32:451993
1994 std::string lang = language;
1995 NotificationService::current()->Notify(
1996 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:151997 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:451998 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:381999}
2000
[email protected]7e0831b2010-02-01 08:45:152001void TabContents::OnPageTranslated(int32 page_id,
2002 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162003 const std::string& translated_lang,
2004 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552005 language_state_.set_current_language(translated_lang);
2006 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162007 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152008 NotificationService::current()->Notify(
2009 NotificationType::PAGE_TRANSLATED,
2010 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162011 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152012}
2013
[email protected]bf5c2ff392009-07-08 16:24:332014void TabContents::DidStartProvisionalLoadForFrame(
2015 RenderViewHost* render_view_host,
2016 bool is_main_frame,
2017 const GURL& url) {
2018 ProvisionalLoadDetails details(is_main_frame,
2019 controller_.IsURLInPageNavigation(url),
2020 url, std::string(), false);
2021 NotificationService::current()->Notify(
2022 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2023 Source<NavigationController>(&controller_),
2024 Details<ProvisionalLoadDetails>(&details));
2025}
2026
2027void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202028 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332029 NotificationService::current()->Notify(
2030 NotificationType::RESOURCE_RESPONSE_STARTED,
2031 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202032 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332033}
2034
[email protected]3dbb80b2010-02-09 22:41:202035void TabContents::DidRedirectResource(
2036 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332037 NotificationService::current()->Notify(
2038 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2039 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202040 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332041}
2042
2043void TabContents::DidLoadResourceFromMemoryCache(
2044 const GURL& url,
2045 const std::string& frame_origin,
2046 const std::string& main_frame_origin,
2047 const std::string& security_info) {
2048 // Send out a notification that we loaded a resource from our memory cache.
2049 int cert_id = 0, cert_status = 0, security_bits = 0;
2050 SSLManager::DeserializeSecurityInfo(security_info,
2051 &cert_id, &cert_status,
2052 &security_bits);
2053 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162054 GetRenderProcessHost()->id(), cert_id,
2055 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332056
2057 NotificationService::current()->Notify(
2058 NotificationType::LOAD_FROM_MEMORY_CACHE,
2059 Source<NavigationController>(&controller_),
2060 Details<LoadFromMemoryCacheDetails>(&details));
2061}
2062
[email protected]e3d60e5d2009-09-25 21:08:292063void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472064 displayed_insecure_content_ = true;
2065 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292066}
2067
2068void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592069 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292070}
2071
[email protected]bf5c2ff392009-07-08 16:24:332072void TabContents::DidFailProvisionalLoadWithError(
2073 RenderViewHost* render_view_host,
2074 bool is_main_frame,
2075 int error_code,
2076 const GURL& url,
2077 bool showing_repost_interstitial) {
2078 if (net::ERR_ABORTED == error_code) {
2079 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2080 // This means that the interstitial won't be torn down properly, which is
2081 // bad. But if we have an interstitial, go back to another tab type, and
2082 // then load the same interstitial again, we could end up getting the first
2083 // interstitial's "failed" message (as a result of the cancel) when we're on
2084 // the second one.
2085 //
2086 // We can't tell this apart, so we think we're tearing down the current page
2087 // which will cause a crash later one. There is also some code in
2088 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2089 // out because of this problem.
2090 //
2091 // http://code.google.com/p/chromium/issues/detail?id=2855
2092 // Because this will not tear down the interstitial properly, if "back" is
2093 // back to another tab type, the interstitial will still be somewhat alive
2094 // in the previous tab type. If you navigate somewhere that activates the
2095 // tab with the interstitial again, you'll see a flash before the new load
2096 // commits of the interstitial page.
2097 if (showing_interstitial_page()) {
2098 LOG(WARNING) << "Discarding message during interstitial.";
2099 return;
2100 }
2101
2102 // This will discard our pending entry if we cancelled the load (e.g., if we
2103 // decided to download the file instead of load it). Only discard the
2104 // pending entry if the URLs match, otherwise the user initiated a navigate
2105 // before the page loaded so that the discard would discard the wrong entry.
2106 NavigationEntry* pending_entry = controller_.pending_entry();
2107 if (pending_entry && pending_entry->url() == url) {
2108 controller_.DiscardNonCommittedEntries();
2109 // Update the URL display.
2110 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2111 }
2112
2113 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2114 }
2115
2116 // Send out a notification that we failed a provisional load with an error.
2117 ProvisionalLoadDetails details(is_main_frame,
2118 controller_.IsURLInPageNavigation(url),
2119 url, std::string(), false);
2120 details.set_error_code(error_code);
2121
2122 NotificationService::current()->Notify(
2123 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2124 Source<NavigationController>(&controller_),
2125 Details<ProvisionalLoadDetails>(&details));
2126}
2127
2128void TabContents::DocumentLoadedInFrame() {
2129 controller_.DocumentLoadedInFrame();
[email protected]b3df5a42010-05-11 14:31:092130 if (renderer_accessible_ && !requested_accessibility_tree_) {
2131 render_view_host()->RequestAccessibilityTree();
2132 requested_accessibility_tree_ = true;
2133 }
[email protected]bf5c2ff392009-07-08 16:24:332134}
2135
[email protected]0de80162010-02-03 04:52:352136void TabContents::OnContentBlocked(ContentSettingsType type) {
[email protected]b1235062010-03-25 17:31:272137 // TODO(joth): remove once fully implemented.
2138 DCHECK(type != CONTENT_SETTINGS_TYPE_GEOLOCATION);
[email protected]0de80162010-02-03 04:52:352139 content_blocked_[type] = true;
2140 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242141 delegate_->OnContentSettingsChange(this);
[email protected]0de80162010-02-03 04:52:352142}
2143
[email protected]614c0e12010-03-25 10:12:562144void TabContents::OnGeolocationPermissionSet(const GURL& requesting_origin,
2145 bool allowed) {
[email protected]777a7b62010-05-11 13:28:162146 geolocation_settings_state_.OnGeolocationPermissionSet(requesting_origin,
2147 allowed);
[email protected]614c0e12010-03-25 10:12:562148 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242149 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562150}
2151
[email protected]8d3347f2009-07-09 22:00:212152RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322153 return view_.get();
2154}
2155
[email protected]8d3347f2009-07-09 22:00:212156RenderViewHostDelegate::RendererManagement*
2157TabContents::GetRendererManagementDelegate() {
2158 return &render_manager_;
2159}
2160
[email protected]bf5c2ff392009-07-08 16:24:332161RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212162 TabContents::GetBrowserIntegrationDelegate() {
2163 return this;
[email protected]bf5c2ff392009-07-08 16:24:332164}
2165
[email protected]8d3347f2009-07-09 22:00:212166RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2167 return this;
[email protected]bf5c2ff392009-07-08 16:24:332168}
2169
[email protected]8d3347f2009-07-09 22:00:212170RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322171 return save_package_.get(); // May be NULL, but we can return NULL.
2172}
2173
[email protected]8d3347f2009-07-09 22:00:212174RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
2175 return &printing_;
2176}
2177
2178RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2179 return &fav_icon_helper_;
2180}
2181
[email protected]e8dbd674b2010-03-11 18:34:402182RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452183 if (autocomplete_history_manager_.get() == NULL)
2184 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2185 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332186}
2187
[email protected]21674df2009-10-28 19:51:212188RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342189 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212190}
2191
[email protected]fd571bb2010-03-19 01:23:542192AutomationResourceRoutingDelegate*
2193TabContents::GetAutomationResourceRoutingDelegate() {
2194 return delegate();
2195}
2196
[email protected]ced90ae12010-02-20 02:06:162197RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2198 return bookmark_drag_;
2199}
2200
2201void TabContents::SetBookmarkDragDelegate(
2202 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2203 bookmark_drag_ = bookmark_drag;
2204}
2205
[email protected]93623c5d2009-12-10 21:40:322206RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462207 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512208}
2209
[email protected]57c6a652009-05-04 07:58:342210TabContents* TabContents::GetAsTabContents() {
2211 return this;
2212}
2213
[email protected]7b291f92009-08-14 05:43:532214ViewType::Type TabContents::GetRenderViewType() const {
2215 return ViewType::TAB_CONTENTS;
2216}
2217
2218int TabContents::GetBrowserWindowID() const {
2219 return controller().window_id().id();
2220}
2221
[email protected]420ae012009-04-24 05:16:322222void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062223 NotificationService::current()->Notify(
2224 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2225 Source<TabContents>(this),
2226 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322227 NavigationEntry* entry = controller_.GetActiveEntry();
2228 if (!entry)
2229 return;
2230
2231 // When we're creating views, we're still doing initial setup, so we always
2232 // use the pending DOM UI rather than any possibly existing committed one.
2233 if (render_manager_.pending_dom_ui()) {
2234 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2235 }
2236
2237 if (entry->IsViewSourceMode()) {
2238 // Put the renderer in view source mode.
2239 render_view_host->Send(
2240 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2241 }
[email protected]0666aef2009-05-13 19:48:082242
2243 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322244}
2245
2246void TabContents::RenderViewReady(RenderViewHost* rvh) {
2247 if (rvh != render_view_host()) {
2248 // Don't notify the world, since this came from a renderer in the
2249 // background.
2250 return;
2251 }
2252
2253 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302254 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322255 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302256
2257 // Restore the focus to the tab (otherwise the focus will be on the top
2258 // window).
2259 if (was_crashed && !FocusLocationBarByDefault())
2260 Focus();
[email protected]420ae012009-04-24 05:16:322261}
2262
2263void TabContents::RenderViewGone(RenderViewHost* rvh) {
2264 // Ask the print preview if this renderer was valuable.
2265 if (!printing_.OnRenderViewGone(rvh))
2266 return;
2267 if (rvh != render_view_host()) {
2268 // The pending page's RenderViewHost is gone.
2269 return;
2270 }
2271
2272 SetIsLoading(false, NULL);
2273 NotifyDisconnected();
2274 SetIsCrashed(true);
2275
[email protected]ff9efc62010-02-18 22:10:542276 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212277 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542278 RemoveInfoBar(GetInfoBarDelegateAt(i));
2279
[email protected]8e537302009-06-10 21:19:582280 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552281 // Only do this if we're not in browser shutdown, so that TabContents
2282 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2283 // visible do not flash a sad tab page.
2284 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2285 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322286
2287 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002288 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322289}
2290
[email protected]2e4633c2009-07-09 16:58:062291void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2292 NotificationService::current()->Notify(
2293 NotificationType::RENDER_VIEW_HOST_DELETED,
2294 Source<TabContents>(this),
2295 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482296 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062297}
2298
[email protected]420ae012009-04-24 05:16:322299void TabContents::DidNavigate(RenderViewHost* rvh,
2300 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372301 int extra_invalidate_flags = 0;
2302
[email protected]b3df5a42010-05-11 14:31:092303 requested_accessibility_tree_ = false;
2304
[email protected]8030f012009-09-25 18:09:372305 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352306 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372307 bool was_extension_shelf_visible = IsExtensionShelfAlwaysVisible();
2308
[email protected]420ae012009-04-24 05:16:322309 render_manager_.DidNavigateMainFrame(rvh);
2310
[email protected]20ede072009-10-06 00:28:352311 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372312 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
2313 if (was_extension_shelf_visible != IsExtensionShelfAlwaysVisible())
2314 extra_invalidate_flags |= INVALIDATE_EXTENSION_SHELF;
2315 }
2316
[email protected]420ae012009-04-24 05:16:322317 // Update the site of the SiteInstance if it doesn't have one yet.
2318 if (!GetSiteInstance()->has_site())
2319 GetSiteInstance()->SetSite(params.url);
2320
2321 // Need to update MIME type here because it's referred to in
2322 // UpdateNavigationCommands() called by RendererDidNavigate() to
2323 // determine whether or not to enable the encoding menu.
2324 // It's updated only for the main frame. For a subframe,
2325 // RenderView::UpdateURL does not set params.contents_mime_type.
2326 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2327 // TODO(jungshik): Add a test for the encoding menu to avoid
2328 // regressing it again.
2329 if (PageTransition::IsMainFrame(params.transition))
2330 contents_mime_type_ = params.contents_mime_type;
2331
2332 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372333 bool did_navigate = controller_.RendererDidNavigate(
2334 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392335
2336 // Update history. Note that this needs to happen after the entry is complete,
2337 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352338 if (params.should_update_history &&
2339 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392340 // Most of the time, the displayURL matches the loaded URL, but for about:
2341 // URLs, we use a data: URL as the real value. We actually want to save
2342 // the about: URL to the history db and keep the data: URL hidden. This is
2343 // what the TabContents' URL getter does.
2344 UpdateHistoryForNavigation(GetURL(), details, params);
2345 }
2346
[email protected]76543b92009-08-31 17:27:452347 if (!did_navigate)
2348 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322349
2350 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2351 // for the appropriate notification (best) or you can add it to
2352 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2353 // necessary, please).
2354
2355 // Run post-commit tasks.
2356 if (details.is_main_frame)
2357 DidNavigateMainFramePostCommit(details, params);
2358 DidNavigateAnyFramePostCommit(rvh, details, params);
2359}
2360
2361void TabContents::UpdateState(RenderViewHost* rvh,
2362 int32 page_id,
2363 const std::string& state) {
2364 DCHECK(rvh == render_view_host());
2365
2366 // We must be prepared to handle state updates for any page, these occur
2367 // when the user is scrolling and entering form data, as well as when we're
2368 // leaving a page, in which case our state may have already been moved to
2369 // the next page. The navigation controller will look up the appropriate
2370 // NavigationEntry and update it when it is notified via the delegate.
2371
2372 int entry_index = controller_.GetEntryIndexWithPageID(
2373 GetSiteInstance(), page_id);
2374 if (entry_index < 0)
2375 return;
2376 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2377
2378 if (state == entry->content_state())
2379 return; // Nothing to update.
2380 entry->set_content_state(state);
2381 controller_.NotifyEntryChanged(entry, entry_index);
2382}
2383
2384void TabContents::UpdateTitle(RenderViewHost* rvh,
2385 int32 page_id, const std::wstring& title) {
2386 // If we have a title, that's a pretty good indication that we've started
2387 // getting useful data.
2388 SetNotWaitingForResponse();
2389
2390 DCHECK(rvh == render_view_host());
2391 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2392 page_id);
2393 if (!entry || !UpdateTitleForEntry(entry, title))
2394 return;
2395
2396 // Broadcast notifications when the UI should be updated.
2397 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032398 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322399}
2400
[email protected]420ae012009-04-24 05:16:322401void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402402 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322403 set_encoding(encoding);
2404}
2405
2406void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2407 if (delegate())
2408 delegate()->UpdateTargetURL(this, url);
2409}
2410
2411void TabContents::UpdateThumbnail(const GURL& url,
2412 const SkBitmap& bitmap,
2413 const ThumbnailScore& score) {
2414 // Tell History about this thumbnail
[email protected]523623c2010-05-19 16:03:422415 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492416 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422417 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282418 } else {
2419 HistoryService* hs;
2420 if (!profile()->IsOffTheRecord() &&
2421 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2422 hs->SetPageThumbnail(url, bitmap, score);
2423 }
[email protected]420ae012009-04-24 05:16:322424 }
2425}
2426
[email protected]8922e1f2009-10-03 05:01:262427void TabContents::UpdateInspectorSettings(const std::string& raw_settings) {
[email protected]0df30122009-06-03 12:13:082428 profile()->GetPrefs()->SetString(prefs::kWebKitInspectorSettings,
[email protected]8922e1f2009-10-03 05:01:262429 UTF8ToWide(raw_settings));
[email protected]0df30122009-06-03 12:13:082430}
2431
[email protected]420ae012009-04-24 05:16:322432void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292433 // The UI may be in an event-tracking loop, such as between the
2434 // mouse-down and mouse-up in text selection or a button click.
2435 // Defer the close until after tracking is complete, so that we
2436 // don't free objects out from under the UI.
2437 // TODO(shess): This could probably be integrated with the
2438 // IsDoingDrag() test below. Punting for now because I need more
2439 // research to understand how this impacts platforms other than Mac.
2440 // TODO(shess): This could get more fine-grained. For instance,
2441 // closing a tab in another window while selecting text in the
2442 // current window's Omnibox should be just fine.
2443 if (view()->IsEventTracking()) {
2444 view()->CloseTabAfterEventTracking();
2445 return;
2446 }
2447
[email protected]24a4d1062009-07-10 23:10:422448 // If we close the tab while we're in the middle of a drag, we'll crash.
2449 // Instead, cancel the drag and close it as soon as the drag ends.
2450 if (view()->IsDoingDrag()) {
2451 view()->CancelDragAndCloseTab();
2452 return;
2453 }
2454
[email protected]420ae012009-04-24 05:16:322455 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2456 if (delegate() && rvh == render_view_host())
2457 delegate()->CloseContents(this);
2458}
2459
2460void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2461 if (delegate() && delegate()->IsPopup(this))
2462 delegate()->MoveContents(this, new_bounds);
2463}
2464
[email protected]7ab1e7d62009-10-14 23:32:012465void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322466 SetIsLoading(true, NULL);
2467}
2468
[email protected]7ab1e7d62009-10-14 23:32:012469void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322470 scoped_ptr<LoadNotificationDetails> details;
2471
2472 NavigationEntry* entry = controller_.GetActiveEntry();
2473 // An entry may not exist for a stop when loading an initial blank page or
2474 // if an iframe injected by script into a blank page finishes loading.
2475 if (entry) {
[email protected]420ae012009-04-24 05:16:322476 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2477
2478 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542479 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322480 entry->transition_type(),
2481 elapsed,
2482 &controller_,
2483 controller_.GetCurrentEntryIndex()));
2484 }
2485
2486 // Tell PasswordManager we've finished a page load, which serves as a
2487 // green light to save pending passwords and reset itself.
2488 GetPasswordManager()->DidStopLoading();
2489
2490 SetIsLoading(false, details.get());
2491}
2492
[email protected]420ae012009-04-24 05:16:322493void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2494 const GURL& source_url,
2495 const GURL& target_url) {
2496 NavigationEntry* entry;
2497 if (page_id == -1)
2498 entry = controller_.pending_entry();
2499 else
2500 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2501 if (!entry || entry->url() != source_url)
2502 return;
2503 entry->set_url(target_url);
2504}
2505
[email protected]420ae012009-04-24 05:16:322506void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2507 WindowOpenDisposition disposition) {
2508 if (render_manager_.dom_ui()) {
2509 // When we're a DOM UI, it will provide a page transition type for us (this
2510 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2511 // generated suggestions).
2512 //
2513 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162514 // want web sites to see a referrer of "chrome://blah" (and some
2515 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322516 // send to the site), so we send no referrer.
2517 OpenURL(url, GURL(), disposition,
2518 render_manager_.dom_ui()->link_transition_type());
2519 } else {
2520 OpenURL(url, referrer, disposition, PageTransition::LINK);
2521 }
2522}
2523
[email protected]1ee614862009-07-06 20:29:182524void TabContents::DomOperationResponse(const std::string& json_string,
2525 int automation_id) {
2526}
2527
[email protected]420ae012009-04-24 05:16:322528void TabContents::ProcessDOMUIMessage(const std::string& message,
[email protected]e4dad9fb2009-10-06 18:15:582529 const Value* content,
[email protected]bb64b512010-04-02 21:01:392530 const GURL& source_url,
[email protected]811bfe32009-07-01 08:46:252531 int request_id,
2532 bool has_callback) {
[email protected]420ae012009-04-24 05:16:322533 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442534 // This can happen if someone uses window.open() to open an extension URL
2535 // from a non-extension context.
2536 render_view_host()->BlockExtensionRequest(request_id);
[email protected]420ae012009-04-24 05:16:322537 return;
2538 }
[email protected]bb64b512010-04-02 21:01:392539 render_manager_.dom_ui()->ProcessDOMUIMessage(message, content, source_url,
2540 request_id,
[email protected]811bfe32009-07-01 08:46:252541 has_callback);
[email protected]420ae012009-04-24 05:16:322542}
2543
2544void TabContents::ProcessExternalHostMessage(const std::string& message,
2545 const std::string& origin,
2546 const std::string& target) {
2547 if (delegate())
2548 delegate()->ForwardMessageToExternalHost(message, origin, target);
2549}
2550
[email protected]cdaf8d02010-03-30 19:52:472551void TabContents::RunFileChooser(
2552 const ViewHostMsg_RunFileChooser_Params &params) {
[email protected]420ae012009-04-24 05:16:322553 if (!select_file_dialog_.get())
2554 select_file_dialog_ = SelectFileDialog::Create(this);
[email protected]cdaf8d02010-03-30 19:52:472555
2556 SelectFileDialog::Type dialog_type;
2557 switch (params.mode) {
2558 case ViewHostMsg_RunFileChooser_Params::Open:
2559 dialog_type = SelectFileDialog::SELECT_OPEN_FILE;
2560 break;
2561 case ViewHostMsg_RunFileChooser_Params::OpenMultiple:
2562 dialog_type = SelectFileDialog::SELECT_OPEN_MULTI_FILE;
2563 break;
2564 case ViewHostMsg_RunFileChooser_Params::Save:
2565 dialog_type = SelectFileDialog::SELECT_SAVEAS_FILE;
2566 break;
2567 default:
[email protected]bed31952010-03-30 20:07:592568 dialog_type = SelectFileDialog::SELECT_OPEN_FILE; // Prevent warning.
[email protected]cdaf8d02010-03-30 19:52:472569 NOTREACHED();
2570 }
2571 select_file_dialog_->SelectFile(dialog_type, params.title,
2572 params.default_file_name,
[email protected]420ae012009-04-24 05:16:322573 NULL, 0, FILE_PATH_LITERAL(""),
2574 view_->GetTopLevelNativeWindow(), NULL);
2575}
2576
2577void TabContents::RunJavaScriptMessage(
2578 const std::wstring& message,
2579 const std::wstring& default_prompt,
2580 const GURL& frame_url,
2581 const int flags,
2582 IPC::Message* reply_msg,
2583 bool* did_suppress_message) {
2584 // Suppress javascript messages when requested and when inside a constrained
2585 // popup window (because that activates them and breaks them out of the
2586 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552587 // Also suppress messages when showing an interstitial. The interstitial is
2588 // shown over the previous page, we don't want the hidden page dialogs to
2589 // interfere with the interstitial.
2590 bool suppress_this_message = suppress_javascript_messages_ ||
2591 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322592 if (delegate())
2593 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312594 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322595
2596 *did_suppress_message = suppress_this_message;
2597
2598 if (!suppress_this_message) {
2599 base::TimeDelta time_since_last_message(
2600 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2601 bool show_suppress_checkbox = false;
2602 // Show a checkbox offering to suppress further messages if this message is
2603 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2604 if (time_since_last_message <
2605 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2606 show_suppress_checkbox = true;
2607
[email protected]d82ed61e2009-06-16 02:46:222608 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322609 show_suppress_checkbox, reply_msg);
2610 } else {
2611 // If we are suppressing messages, just reply as is if the user immediately
2612 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542613 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322614 }
2615}
2616
2617void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2618 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012619 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222620 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322621}
2622
2623void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2624 const std::string& json_arguments,
2625 IPC::Message* reply_msg) {
2626 if (delegate()) {
2627 HtmlDialogUIDelegate* dialog_delegate =
2628 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222629 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322630 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2631 }
2632}
2633
[email protected]4d44a1c2010-04-28 19:20:412634void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562635 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412636 GetPasswordManager()->PasswordFormsFound(forms);
2637}
2638
2639void TabContents::PasswordFormsVisible(
2640 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2641 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322642}
2643
[email protected]420ae012009-04-24 05:16:322644// Checks to see if we should generate a keyword based on the OSDD, and if
2645// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2646void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2647 int32 page_id, const GURL& url,
2648 bool autodetected) {
2649 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2650 DCHECK(url.is_valid());
2651 if (!IsActiveEntry(page_id))
2652 return;
2653 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2654 if (!url_model)
2655 return;
2656 if (!url_model->loaded()) {
2657 url_model->Load();
2658 return;
2659 }
2660 if (!profile()->GetTemplateURLFetcher())
2661 return;
2662
2663 if (profile()->IsOffTheRecord())
2664 return;
2665
2666 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2667 DCHECK(entry);
2668
2669 const NavigationEntry* base_entry = entry;
2670 if (IsFormSubmit(base_entry)) {
2671 // If the current page is a form submit, find the last page that was not
2672 // a form submit and use its url to generate the keyword from.
2673 int index = controller_.last_committed_entry_index() - 1;
2674 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2675 index--;
2676 if (index >= 0)
2677 base_entry = controller_.GetEntryAtIndex(index);
2678 else
2679 base_entry = NULL;
2680 }
2681
2682 // We want to use the user typed URL if available since that represents what
2683 // the user typed to get here, and fall back on the regular URL if not.
2684 if (!base_entry)
2685 return;
2686 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2687 base_entry->user_typed_url() : base_entry->url();
2688 if (!keyword_url.is_valid())
2689 return;
2690 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2691 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532692
2693 // For JS added OSDD empty keyword is OK because we will generate keyword
2694 // later from OSDD content.
2695 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322696 return;
2697 const TemplateURL* template_url =
2698 url_model->GetTemplateURLForKeyword(keyword);
2699 if (template_url && (!template_url->safe_for_autoreplace() ||
2700 template_url->originating_url() == url)) {
2701 // Either there is a user created TemplateURL for this keyword, or the
2702 // keyword has the same OSDD url and we've parsed it.
2703 return;
2704 }
2705
2706 // Download the OpenSearch description document. If this is successful a
2707 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322708 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2709 keyword,
2710 url,
2711 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162712 this,
[email protected]420ae012009-04-24 05:16:322713 autodetected);
2714}
2715
[email protected]420ae012009-04-24 05:16:322716GURL TabContents::GetAlternateErrorPageURL() const {
2717 GURL url;
2718 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2719 if (profile()->IsOffTheRecord())
2720 return url;
2721
2722 PrefService* prefs = profile()->GetPrefs();
2723 DCHECK(prefs);
2724 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152725 url = google_util::AppendGoogleLocaleParam(
2726 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322727 url = google_util::AppendGoogleTLDParam(url);
2728 }
2729 return url;
2730}
2731
2732WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062733 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552734 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062735 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322736}
2737
[email protected]fa1cf0b82010-01-15 21:49:442738void TabContents::OnIgnoredUIEvent() {
2739 if (constrained_window_count()) {
2740 ConstrainedWindow* window = *constrained_window_begin();
2741 window->FocusConstrainedWindow();
2742 }
2743}
2744
[email protected]420ae012009-04-24 05:16:322745void TabContents::OnJSOutOfMemory() {
2746 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]938e1f92010-04-01 18:09:422747 this, l10n_util::GetString(IDS_JS_OUT_OF_MEMORY_PROMPT), NULL, true));
[email protected]420ae012009-04-24 05:16:322748}
2749
[email protected]420ae012009-04-24 05:16:322750void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2751 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342752 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322753 // delivered to a pending RenderViewHost. We must first run the onunload
2754 // handler of the old RenderViewHost before we can allow it to proceed.
2755 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2756 new_request_id);
2757}
2758
2759bool TabContents::CanBlur() const {
2760 return delegate() ? delegate()->CanBlur() : true;
2761}
2762
2763gfx::Rect TabContents::GetRootWindowResizerRect() const {
2764 if (delegate())
2765 return delegate()->GetRootWindowResizerRect();
2766 return gfx::Rect();
2767}
2768
2769void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2770 bool is_during_unload) {
2771 if (is_during_unload) {
2772 // Hang occurred while firing the beforeunload/unload handler.
2773 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112774 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322775
2776 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2777 return;
2778
2779 // If the tab hangs in the beforeunload/unload handler there's really
2780 // nothing we can do to recover. Pretend the unload listeners have
2781 // all fired and close the tab. If the hang is in the beforeunload handler
2782 // then the user will not have the option of cancelling the close.
2783 Close(rvh);
2784 return;
2785 }
2786
2787 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002788 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322789}
2790
2791void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002792 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322793}
2794
2795void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562796 net::LoadState load_state,
2797 uint64 upload_position,
2798 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322799 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562800 upload_position_ = upload_position;
2801 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292802 std::wstring languages =
2803 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages);
[email protected]d686e812009-06-03 19:10:292804 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532805 load_state_host_ =
2806 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322807 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2808 SetNotWaitingForResponse();
2809 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502810 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322811}
2812
[email protected]1ee614862009-07-06 20:29:182813bool TabContents::IsExternalTabContainer() const {
2814 if (!delegate())
2815 return false;
2816
2817 return delegate()->IsExternalTabContainer();
2818}
2819
[email protected]1ee614862009-07-06 20:29:182820void TabContents::DidInsertCSS() {
2821 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322822}
2823
[email protected]130efb02009-09-18 18:54:352824void TabContents::FocusedNodeChanged() {
2825 NotificationService::current()->Notify(
2826 NotificationType::FOCUS_CHANGED_IN_PAGE,
2827 Source<RenderViewHost>(render_view_host()),
2828 NotificationService::NoDetails());
2829}
2830
[email protected]420ae012009-04-24 05:16:322831void TabContents::FileSelected(const FilePath& path,
2832 int index, void* params) {
[email protected]cdaf8d02010-03-30 19:52:472833 std::vector<FilePath> files;
2834 files.push_back(path);
2835 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322836}
2837
2838void TabContents::MultiFilesSelected(const std::vector<FilePath>& files,
2839 void* params) {
[email protected]cdaf8d02010-03-30 19:52:472840 render_view_host()->FilesSelectedInChooser(files);
[email protected]420ae012009-04-24 05:16:322841}
2842
2843void TabContents::FileSelectionCanceled(void* params) {
2844 // If the user cancels choosing a file to upload we pass back an
2845 // empty vector.
[email protected]cdaf8d02010-03-30 19:52:472846 render_view_host()->FilesSelectedInChooser(std::vector<FilePath>());
[email protected]420ae012009-04-24 05:16:322847}
2848
2849void TabContents::BeforeUnloadFiredFromRenderManager(
2850 bool proceed,
2851 bool* proceed_to_fire_unload) {
2852 if (delegate())
2853 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2854}
2855
2856void TabContents::UpdateRenderViewSizeForRenderManager() {
2857 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262858 gfx::Size size = view_->GetContainerSize();
2859 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2860 // here during container initialization and normal window size will be set
2861 // later. In case of tab duplication this resizing to 0x0 prevents setting
2862 // normal size later so just ignore it.
2863 if (!size.IsEmpty())
2864 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322865}
2866
2867DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222868 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322869}
2870
2871NavigationEntry*
2872TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2873 return controller_.GetLastCommittedEntry();
2874}
2875
2876bool TabContents::CreateRenderViewForRenderManager(
2877 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322878 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522879
2880 scoped_refptr<URLRequestContextGetter> request_context = request_context_;
2881 if (!request_context.get())
2882 request_context = profile()->GetRequestContext();
2883
2884 if (!render_view_host->CreateRenderView(request_context))
[email protected]420ae012009-04-24 05:16:322885 return false;
2886
2887 // Now that the RenderView has been created, we need to tell it its size.
2888 rwh_view->SetSize(view_->GetContainerSize());
2889
2890 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2891 render_view_host);
2892 return true;
2893}
2894
2895void TabContents::Observe(NotificationType type,
2896 const NotificationSource& source,
2897 const NotificationDetails& details) {
2898 switch (type.value) {
2899 case NotificationType::BOOKMARK_MODEL_LOADED:
2900 // BookmarkModel finished loading, fall through to update starred state.
2901 case NotificationType::URLS_STARRED: {
2902 // Somewhere, a URL has been starred.
2903 // Ignore notifications for profiles other than our current one.
2904 Profile* source_profile = Source<Profile>(source).ptr();
2905 if (!source_profile || !source_profile->IsSameProfile(profile()))
2906 return;
2907
2908 UpdateStarredStateForCurrentURL();
2909 break;
2910 }
2911 case NotificationType::PREF_CHANGED: {
2912 std::wstring* pref_name_in = Details<std::wstring>(details).ptr();
2913 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2914 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2915 UpdateAlternateErrorPageURL();
2916 } else if (*pref_name_in == prefs::kDefaultCharset ||
2917 StartsWithASCII(WideToUTF8(*pref_name_in), "webkit.webprefs.", true)
2918 ) {
2919 UpdateWebPreferences();
2920 } else {
2921 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2922 }
2923 break;
2924 }
2925 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2926 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2927 break;
2928
2929 case NotificationType::NAV_ENTRY_COMMITTED: {
2930 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2931
2932 NavigationController::LoadCommittedDetails& committed_details =
2933 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2934 ExpireInfoBars(committed_details);
2935 break;
2936 }
2937
[email protected]d3ba77272009-09-03 00:06:092938#if defined(OS_LINUX)
2939 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542940 renderer_preferences_util::UpdateFromSystemSettings(
2941 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092942 render_view_host()->SyncRendererPrefs();
2943 break;
2944 }
2945#endif
2946
[email protected]6c32ce72010-03-08 05:18:062947 case NotificationType::USER_STYLE_SHEET_UPDATED:
2948 UpdateWebPreferences();
2949 break;
2950
[email protected]79580c62010-02-02 02:36:252951 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:292952 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:252953 settings_details(details);
[email protected]79580c62010-02-02 02:36:252954 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492955 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292956 if (entry)
[email protected]da0c8e92010-02-09 23:25:492957 entry_url = entry->url();
[email protected]79580c62010-02-02 02:36:252958 Source<HostContentSettingsMap> content_settings(source);
[email protected]0314ae02010-04-08 09:18:292959 if (settings_details.ptr()->update_all() ||
2960 settings_details.ptr()->pattern().Matches(entry_url)) {
2961 render_view_host()->SendContentSettings(entry_url,
[email protected]da0c8e92010-02-09 23:25:492962 content_settings.ptr()->GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252963 }
2964 break;
2965 }
2966
[email protected]a888b29e62010-04-01 13:38:572967 case NotificationType::EXTENSION_LOADED: {
[email protected]98aa0b52010-05-06 17:03:082968 if (!extension_app_ && !extension_app_for_current_page_ &&
[email protected]a888b29e62010-04-01 13:38:572969 Source<Profile>(source).ptr() == profile()) {
[email protected]98aa0b52010-05-06 17:03:082970 UpdateExtensionAppForCurrentPage();
2971 if (extension_app_for_current_page_)
[email protected]a888b29e62010-04-01 13:38:572972 NotifyNavigationStateChanged(INVALIDATE_TAB);
2973 }
2974 break;
2975 }
2976
2977 case NotificationType::EXTENSION_UNLOADED:
2978 case NotificationType::EXTENSION_UNLOADED_DISABLED: {
[email protected]98aa0b52010-05-06 17:03:082979 if (extension_app_for_current_page_ ==
[email protected]a888b29e62010-04-01 13:38:572980 Details<Extension>(details).ptr()) {
[email protected]98aa0b52010-05-06 17:03:082981 extension_app_for_current_page_ = NULL;
2982 UpdateExtensionAppForCurrentPage();
[email protected]a888b29e62010-04-01 13:38:572983 NotifyNavigationStateChanged(INVALIDATE_TAB);
2984 }
2985 break;
2986 }
2987
[email protected]420ae012009-04-24 05:16:322988 default:
2989 NOTREACHED();
2990 }
2991}
[email protected]aacd7cc2009-09-02 14:51:102992
[email protected]98aa0b52010-05-06 17:03:082993void TabContents::UpdateExtensionAppIcon(Extension* extension) {
2994 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432995
[email protected]a888b29e62010-04-01 13:38:572996 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082997 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2998 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572999 extension,
3000 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3001 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3002 Extension::EXTENSION_ICON_SMALLISH),
3003 ImageLoadingTracker::CACHE);
3004 } else {
[email protected]98aa0b52010-05-06 17:03:083005 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573006 }
3007}
3008
3009Extension* TabContents::GetExtensionContaining(const GURL& url) {
3010 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3011 if (!extensions_service)
3012 return NULL;
3013
3014 Extension* extension = extensions_service->GetExtensionByURL(url);
3015 return extension ?
3016 extension : extensions_service->GetExtensionByWebExtent(url);
3017}
3018
[email protected]98aa0b52010-05-06 17:03:083019void TabContents::UpdateExtensionAppForCurrentPage() {
3020 if (extension_app_) {
[email protected]a888b29e62010-04-01 13:38:573021 // Tab has an explicit app extension; nothing to do.
3022 return;
3023 }
3024
3025 // Check the current extension before iterating through all extensions.
[email protected]98aa0b52010-05-06 17:03:083026 if (extension_app_for_current_page_ &&
3027 extension_app_for_current_page_->web_extent().ContainsURL(GetURL())) {
[email protected]a888b29e62010-04-01 13:38:573028 return;
3029 }
3030
[email protected]98aa0b52010-05-06 17:03:083031 extension_app_for_current_page_ = GetExtensionContaining(GetURL());
3032 UpdateExtensionAppIcon(extension_app_for_current_page_);
[email protected]a888b29e62010-04-01 13:38:573033}
3034
3035void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3036 int index) {
3037 if (image) {
[email protected]98aa0b52010-05-06 17:03:083038 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573039 NotifyNavigationStateChanged(INVALIDATE_TAB);
3040 }
3041}
3042
[email protected]beb440c2009-11-06 04:08:543043std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3044 bool is_alert) {
3045 if (!frame_url.has_host())
3046 return l10n_util::GetString(
3047 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3048 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3049
3050 // We really only want the scheme, hostname, and port.
3051 GURL::Replacements replacements;
3052 replacements.ClearUsername();
3053 replacements.ClearPassword();
3054 replacements.ClearPath();
3055 replacements.ClearQuery();
3056 replacements.ClearRef();
3057 GURL clean_url = frame_url.ReplaceComponents(replacements);
3058
3059 // TODO(brettw) it should be easier than this to do the correct language
3060 // handling without getting the accept language from the profile.
3061 std::wstring base_address = gfx::ElideUrl(clean_url, gfx::Font(), 0,
3062 profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
3063 // Force URL to have LTR directionality.
[email protected]4a4afe32010-05-05 01:39:563064 base::i18n::GetDisplayStringInLTRDirectionality(&base_address);
[email protected]beb440c2009-11-06 04:08:543065
3066 return l10n_util::GetStringF(
3067 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
3068 base_address);
3069}
3070
3071gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3072 return view_->GetTopLevelNativeWindow();
3073}
3074
3075void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3076 bool success,
3077 const std::wstring& prompt) {
3078 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3079 if (is_showing_before_unload_dialog_ && !success) {
3080 // If a beforeunload dialog is canceled, we need to stop the throbber from
3081 // spinning, since we forced it to start spinning in Navigate.
3082 DidStopLoading();
3083
3084 tab_close_start_time_ = base::TimeTicks();
3085 }
3086 is_showing_before_unload_dialog_ = false;
3087 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3088}
3089
3090void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3091 set_suppress_javascript_messages(suppress_message_boxes);
3092}
3093
[email protected]41fc0322009-09-04 22:23:403094void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103095 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3096}
[email protected]f45d2a72010-03-08 23:28:353097
3098void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3099 app_icon_ = app_icon;
3100 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3101}
[email protected]ea68c06a2010-04-23 17:25:373102
3103// After a successful *new* login attempt, we take the PasswordFormManager in
3104// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3105// the user makes up their mind with the "save password" infobar. Note if the
3106// login is one we already know about, the end of the line is
3107// provisional_save_manager_ because we just update it on success and so such
3108// forms never end up in an infobar.
3109class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3110 public:
3111 SavePasswordInfoBarDelegate(TabContents* tab_contents,
3112 PasswordFormManager* form_to_save) :
3113 ConfirmInfoBarDelegate(tab_contents),
3114 form_to_save_(form_to_save) {
3115 }
3116
3117 virtual ~SavePasswordInfoBarDelegate() { }
3118
3119 // Overridden from ConfirmInfoBarDelegate:
3120 virtual void InfoBarClosed() {
3121 delete this;
3122 }
3123
3124 virtual std::wstring GetMessageText() const {
3125 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
3126 }
3127
3128 virtual SkBitmap* GetIcon() const {
3129 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3130 IDR_INFOBAR_SAVE_PASSWORD);
3131 }
3132
3133 virtual int GetButtons() const {
3134 return BUTTON_OK | BUTTON_CANCEL;
3135 }
3136
3137 virtual std::wstring GetButtonLabel(InfoBarButton button) const {
3138 if (button == BUTTON_OK)
3139 return l10n_util::GetString(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
3140 if (button == BUTTON_CANCEL)
3141 return l10n_util::GetString(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
3142 NOTREACHED();
3143 return std::wstring();
3144 }
3145
3146 virtual bool Accept() {
3147 DCHECK(form_to_save_.get());
3148 form_to_save_->Save();
3149 return true;
3150 }
3151
3152 virtual bool Cancel() {
3153 DCHECK(form_to_save_.get());
3154 form_to_save_->PermanentlyBlacklist();
3155 return true;
3156 }
3157
3158 private:
3159 // The PasswordFormManager managing the form we're asking the user about,
3160 // and should update as per her decision.
3161 scoped_ptr<PasswordFormManager> form_to_save_;
3162
3163 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3164};
3165
3166void TabContents::FillPasswordForm(
3167 const webkit_glue::PasswordFormDomManager::FillData& form_data) {
3168 render_view_host()->FillPasswordForm(form_data);
3169}
3170
3171void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3172 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3173}
3174
3175Profile* TabContents::GetProfileForPasswordManager() {
3176 return profile();
3177}
3178
3179bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3180 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3181}