blob: 92c23ffd3495479ccd6010026a9b976b51f4e6a7 [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]aad51d1c2010-08-05 08:38:0924#include "chrome/browser/blocked_plugin_manager.h"
[email protected]66ba4932009-06-04 19:22:1325#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3226#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5427#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5528#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2929#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1030#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5431#include "chrome/browser/debugger/devtools_manager.h"
[email protected]420ae012009-04-24 05:16:3232#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/dom_ui/dom_ui.h"
34#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0235#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0137#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4938#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0839#include "chrome/browser/extensions/extensions_service.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4841#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5342#include "chrome/browser/find_bar_state.h"
[email protected]420ae012009-04-24 05:16:3243#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2544#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2645#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1446#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3247#include "chrome/browser/load_from_memory_cache_details.h"
48#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4449#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0550#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1051#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5752#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2453#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5754#include "chrome/browser/plugin_installer.h"
[email protected]8e0bbf12010-07-20 00:03:4355#include "chrome/browser/popup_blocked_animation.h"
[email protected]052313b2010-02-19 09:43:0856#include "chrome/browser/pref_service.h"
[email protected]12802702010-07-09 19:43:0957#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4458#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0759#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1660#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5461#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3762#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0763#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5464#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3265#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1666#include "chrome/browser/search_engines/template_url_fetcher.h"
67#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1768#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1769#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5470#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]fd2b9ce2010-08-11 04:03:5771#include "chrome/browser/tab_contents/match_preview.h"
[email protected]f3ec7742009-01-15 00:59:1672#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4373#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1674#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]b5977a0c2010-08-24 19:46:2675#include "chrome/browser/tab_contents/tab_contents_file_select_helper.h"
[email protected]1f18184a2010-07-21 19:34:4976#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5777#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0278#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1679#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5880#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2781#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4982#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5783#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1484#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0985#include "chrome/common/extensions/url_pattern.h"
86#include "chrome/common/navigation_types.h"
87#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5688#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2989#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3290#include "chrome/common/render_messages.h"
[email protected]1ee614862009-07-06 20:29:1891#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5492#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3793#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2694#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3295#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0696#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3797#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3298#include "net/base/mime_util.h"
99#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29100#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32101#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18102#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03103#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00104
[email protected]420ae012009-04-24 05:16:32105// Cross-Site Navigations
106//
107// If a TabContents is told to navigate to a different web site (as determined
108// by SiteInstance), it will replace its current RenderViewHost with a new
109// RenderViewHost dedicated to the new SiteInstance. This works as follows:
110//
111// - Navigate determines whether the destination is cross-site, and if so,
112// it creates a pending_render_view_host_ and moves into the PENDING
113// RendererState.
114// - The pending RVH is "suspended," so that no navigation messages are sent to
115// its renderer until the onbeforeunload JavaScript handler has a chance to
116// run in the current RVH.
117// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
118// that it has a pending cross-site request. ResourceDispatcherHost will
119// check for this when the response arrives.
120// - The current RVH runs its onbeforeunload handler. If it returns false, we
121// cancel all the pending logic and go back to NORMAL. Otherwise we allow
122// the pending RVH to send the navigation request to its renderer.
123// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
124// checks CrossSiteRequestManager to see that the RVH responsible has a
125// pending cross-site request, and then installs a CrossSiteEventHandler.
126// - When RDH receives a response, the BufferedEventHandler determines whether
127// it is a download. If so, it sends a message to the new renderer causing
128// it to cancel the request, and the download proceeds in the download
129// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34130// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32131// doesn't affect any functionality.
132// - After RDH receives a response and determines that it is safe and not a
133// download, it pauses the response to first run the old page's onunload
134// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34135// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32136// to the current RVH.
137// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
138// the ResourceDispatcherHost, who unpauses the response. Data is then sent
139// to the pending RVH.
140// - The pending renderer sends a FrameNavigate message that invokes the
141// DidNavigate method. This replaces the current RVH with the
142// pending RVH and goes back to the NORMAL RendererState.
143
144namespace {
145
146// Amount of time we wait between when a key event is received and the renderer
147// is queried for its state and pushed to the NavigationEntry.
148const int kQueryStateDelay = 5000;
149
150const int kSyncWaitDelay = 40;
151
[email protected]304f8792009-08-19 21:28:09152#if defined(OS_CHROMEOS)
153// If a popup window is bigger than this fraction of the screen on chrome os,
154// turn it into a tab
155const float kMaxWidthFactor = 0.5;
156const float kMaxHeightFactor = 0.6;
157#endif
158
[email protected]420ae012009-04-24 05:16:32159// If another javascript message box is displayed within
160// kJavascriptMessageExpectedDelay of a previous javascript message box being
161// dismissed, display an option to suppress future message boxes from this
162// contents.
163const int kJavascriptMessageExpectedDelay = 1000;
164
[email protected]420ae012009-04-24 05:16:32165// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51166const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32167 prefs::kAlternateErrorPagesEnabled,
168 prefs::kWebKitJavaEnabled,
169 prefs::kWebKitJavascriptEnabled,
170 prefs::kWebKitLoadsImagesAutomatically,
171 prefs::kWebKitPluginsEnabled,
172 prefs::kWebKitUsesUniversalDetector,
173 prefs::kWebKitSerifFontFamily,
174 prefs::kWebKitSansSerifFontFamily,
175 prefs::kWebKitFixedFontFamily,
176 prefs::kWebKitDefaultFontSize,
177 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36178 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32179 prefs::kDefaultCharset
180 // kWebKitStandardFontIsSerif needs to be added
181 // if we let users pick which font to use, serif or sans-serif when
182 // no font is specified or a CSS generic family (serif or sans-serif)
183 // is not specified.
184};
185
186const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
187
[email protected]420ae012009-04-24 05:16:32188// Returns true if the entry's transition type is FORM_SUBMIT.
189bool IsFormSubmit(const NavigationEntry* entry) {
190 return (PageTransition::StripQualifier(entry->transition_type()) ==
191 PageTransition::FORM_SUBMIT);
192}
193
194#if defined(OS_WIN)
195
196BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
197 // Note: erase is required to properly paint some widgets borders. This can
198 // be seen with textfields.
199 InvalidateRect(hwnd, NULL, TRUE);
200 return TRUE;
201}
202#endif
203
[email protected]5e369672009-11-03 23:48:30204ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16205 Profile* profile, const NavigationEntry& entry,
206 NavigationController::ReloadType reload_type) {
207 switch (reload_type) {
208 case NavigationController::RELOAD:
209 return ViewMsg_Navigate_Params::RELOAD;
210 case NavigationController::RELOAD_IGNORING_CACHE:
211 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
212 case NavigationController::NO_RELOAD:
213 break; // Fall through to rest of function.
214 }
[email protected]5e369672009-11-03 23:48:30215
216 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
217 profile->DidLastSessionExitCleanly())
218 return ViewMsg_Navigate_Params::RESTORE;
219
220 return ViewMsg_Navigate_Params::NORMAL;
221}
222
[email protected]3cc72b12010-03-18 23:03:00223void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16224 NavigationController::ReloadType reload_type,
225 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00226 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34227 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00228 params->pending_history_list_offset = controller.pending_entry_index();
229 params->current_history_list_offset = controller.last_committed_entry_index();
230 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34231 params->url = entry.url();
232 params->referrer = entry.referrer();
233 params->transition = entry.transition_type();
234 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00235 params->navigation_type =
236 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34237 params->request_time = base::Time::Now();
238}
239
[email protected]851b1eb2010-08-09 13:32:29240class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
241 public:
242 DisabledPluginInfoBar(TabContents* tab_contents,
243 const string16& name,
244 const GURL& update_url)
245 : ConfirmInfoBarDelegate(tab_contents),
246 tab_contents_(tab_contents),
247 name_(name),
248 update_url_(update_url) {
249 tab_contents->AddInfoBar(this);
250 }
251
252 virtual int GetButtons() const {
253 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
254 }
255
[email protected]e23d3a32010-08-13 19:39:58256 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29257 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58258 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29259 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58260 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29261 return ConfirmInfoBarDelegate::GetButtonLabel(button);
262 }
263
[email protected]e23d3a32010-08-13 19:39:58264 virtual string16 GetMessageText() const {
265 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29266 }
267
[email protected]e23d3a32010-08-13 19:39:58268 virtual string16 GetLinkText() {
269 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29270 }
271
272 virtual SkBitmap* GetIcon() const {
273 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
274 IDR_INFOBAR_PLUGIN_INSTALL);
275 }
276
277 virtual bool Accept() {
278 tab_contents_->OpenURL(update_url_, GURL(),
279 CURRENT_TAB, PageTransition::LINK);
280 return false;
281 }
282
283 virtual bool Cancel() {
284 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
285 CURRENT_TAB, PageTransition::LINK);
286 return false;
287 }
288
289 virtual bool LinkClicked(WindowOpenDisposition disposition) {
290 // TODO(bauerb): Navigate to a help page explaining why we disabled
291 // the plugin, once we have one.
292 return false;
293 }
294
295 private:
296 TabContents* tab_contents_;
297 string16 name_;
298 GURL update_url_;
299};
300
[email protected]420ae012009-04-24 05:16:32301} // namespace
302
303// -----------------------------------------------------------------------------
304
[email protected]fdd61c62009-04-22 19:22:57305// static
306int TabContents::find_request_id_counter_ = -1;
307
[email protected]420ae012009-04-24 05:16:32308
[email protected]420ae012009-04-24 05:16:32309TabContents::TabContents(Profile* profile,
310 SiteInstance* site_instance,
311 int routing_id,
[email protected]34ac70502009-09-25 17:07:23312 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42313 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13314 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
315 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22316 TabContentsView::Create(this))),
317 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57318 property_bag_(),
319 registrar_(),
[email protected]12802702010-07-09 19:43:09320 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
321 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57322 save_package_(),
[email protected]6db0def92010-03-02 19:55:45323 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21324 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57325 password_manager_(),
326 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06327 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22328 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34329 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29330 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34331 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34332 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57333 current_load_start_(),
334 load_state_(net::LOAD_STATE_IDLE),
335 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56336 upload_size_(0),
337 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57338 received_page_title_(false),
339 is_starred_(false),
340 contents_mime_type_(),
341 encoding_(),
[email protected]332af7732009-03-11 13:21:35342 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49343 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47344 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57345 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57346 find_ui_active_(false),
347 find_op_aborted_(false),
348 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12349 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12350 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08351 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57352 capturing_contents_(false),
353 is_being_destroyed_(false),
354 notify_disconnection_(false),
355 history_requests_(),
356#if defined(OS_WIN)
357 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
358#endif
359 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44360 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01361 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54362 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54363 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16364 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38365 closed_by_user_gesture_(false),
366 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54367 renderer_preferences_util::UpdateFromSystemSettings(
368 &renderer_preferences_, profile);
369
[email protected]9fb83e82010-07-02 18:24:55370 content_settings_delegate_.reset(
371 new TabSpecificContentSettings(this, profile));
372
[email protected]16779842009-07-08 23:45:29373#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02374 // Make sure the thumbnailer is started before starting the render manager.
375 // The thumbnailer will want to listen for RVH creations, one of which will
376 // happen in RVHManager::Init.
377 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
378 if (generator)
379 generator->StartThumbnailing();
380#endif
381
[email protected]12636df2009-09-28 22:32:21382 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32383
[email protected]34ac70502009-09-25 17:07:23384 // We have the initial size of the view be based on the size of the passed in
385 // tab contents (normally a tab from the same window).
386 view_->CreateView(base_tab_contents ?
387 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32388
389 // Register for notifications about all interested prefs change.
390 PrefService* prefs = profile->GetPrefs();
391 if (prefs) {
392 for (int i = 0; i < kPrefsToObserveLength; ++i)
393 prefs->AddPrefObserver(kPrefsToObserve[i], this);
394 }
395
396 // Register for notifications about URL starredness changing on any profile.
397 registrar_.Add(this, NotificationType::URLS_STARRED,
398 NotificationService::AllSources());
399 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
400 NotificationService::AllSources());
401 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
402 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09403#if defined(OS_LINUX)
404 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
405 NotificationService::AllSources());
406#endif
[email protected]420ae012009-04-24 05:16:32407
[email protected]6c32ce72010-03-08 05:18:06408 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
409 NotificationService::AllSources());
410
[email protected]79580c62010-02-02 02:36:25411 // Register for notifications about content setting changes.
412 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
413 NotificationService::AllSources());
414
[email protected]a888b29e62010-04-01 13:38:57415 // Listen for extension changes so we can update extension_for_current_page_.
416 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
417 NotificationService::AllSources());
418 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
419 NotificationService::AllSources());
420 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
421 NotificationService::AllSources());
422
[email protected]c8865482009-07-23 20:40:10423 // Set-up the showing of the omnibox search infobar if applicable.
424 if (OmniboxSearchHint::IsEnabled(profile))
425 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]fd2b9ce2010-08-11 04:03:57426
427 if (MatchPreview::IsEnabled())
428 match_preview_.reset(new MatchPreview(this));
[email protected]332af7732009-03-11 13:21:35429}
initial.commit09911bf2008-07-26 23:55:29430
431TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32432 is_being_destroyed_ = true;
433
[email protected]bfe4c1582009-10-02 18:11:09434 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32435 registrar_.RemoveAll();
436
437 // Unregister the notifications of all observed prefs change.
438 PrefService* prefs = profile()->GetPrefs();
439 if (prefs) {
440 for (int i = 0; i < kPrefsToObserveLength; ++i)
441 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
442 }
443
[email protected]420ae012009-04-24 05:16:32444 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00445 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32446
[email protected]420ae012009-04-24 05:16:32447 // First cleanly close all child windows.
448 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
449 // some of these to close. CloseWindows is async, so it might get called
450 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49451 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32452
[email protected]8cc8d492010-02-02 10:40:49453 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13454 if (blocked_popups_)
455 blocked_popups_->Destroy();
456
[email protected]420ae012009-04-24 05:16:32457 // Notify any observer that have a reference on this tab contents.
458 NotificationService::current()->Notify(
459 NotificationType::TAB_CONTENTS_DESTROYED,
460 Source<TabContents>(this),
461 NotificationService::NoDetails());
462
[email protected]1e5e74f2009-05-27 20:55:12463 // Notify any lasting InfobarDelegates that have not yet been removed that
464 // whatever infobar they were handling in this TabContents has closed,
465 // because the TabContents is going away entirely.
466 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
467 // notification may trigger infobars calls that access their delegate. (and
468 // some implementations of InfoBarDelegate do delete themselves on
469 // InfoBarClosed()).
470 for (int i = 0; i < infobar_delegate_count(); ++i) {
471 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
472 delegate->InfoBarClosed();
473 }
474 infobar_delegates_.clear();
475
[email protected]420ae012009-04-24 05:16:32476 // TODO(brettw) this should be moved to the view.
477#if defined(OS_WIN)
478 // If we still have a window handle, destroy it. GetNativeView can return
479 // NULL if this contents was part of a window that closed.
480 if (GetNativeView())
481 ::DestroyWindow(GetNativeView());
482#endif
[email protected]7ab1e7d62009-10-14 23:32:01483
484 // OnCloseStarted isn't called in unit tests.
485 if (!tab_close_start_time_.is_null()) {
486 UMA_HISTOGRAM_TIMES("Tab.Close",
487 base::TimeTicks::Now() - tab_close_start_time_);
488 }
initial.commit09911bf2008-07-26 23:55:29489}
490
[email protected]d5f942ba2008-09-26 19:30:34491// static
492void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32493 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
494
495 WebPreferences pref_defaults;
496 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
497 pref_defaults.javascript_enabled);
498 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
499 pref_defaults.web_security_enabled);
500 prefs->RegisterBooleanPref(
501 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
502 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
503 pref_defaults.loads_images_automatically);
504 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
505 pref_defaults.plugins_enabled);
506 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
507 pref_defaults.dom_paste_enabled);
508 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
509 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14510 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32511 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
512 pref_defaults.text_areas_are_resizable);
513 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
514 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36515 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
516 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32517
518 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
519 IDS_ACCEPT_LANGUAGES);
520 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
521 IDS_DEFAULT_ENCODING);
522 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
523 IDS_STANDARD_FONT_IS_SERIF);
524 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
525 IDS_FIXED_FONT_FAMILY);
526 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
527 IDS_SERIF_FONT_FAMILY);
528 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
529 IDS_SANS_SERIF_FONT_FAMILY);
530 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
531 IDS_CURSIVE_FONT_FAMILY);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
533 IDS_FANTASY_FONT_FAMILY);
534 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
535 IDS_DEFAULT_FONT_SIZE);
536 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
537 IDS_DEFAULT_FIXED_FONT_SIZE);
538 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
539 IDS_MINIMUM_FONT_SIZE);
540 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
541 IDS_MINIMUM_LOGICAL_FONT_SIZE);
542 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
543 IDS_USES_UNIVERSAL_DETECTOR);
544 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
545 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29546}
547
[email protected]13367f72009-07-08 16:39:02548// Returns true if contains content rendered by an extension.
549bool TabContents::HostsExtension() const {
550 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34551}
552
[email protected]cf28ec52010-04-09 22:56:34553AutoFillManager* TabContents::GetAutoFillManager() {
554 if (autofill_manager_.get() == NULL)
555 autofill_manager_.reset(new AutoFillManager(this));
556 return autofill_manager_.get();
557}
558
[email protected]6e95706d2009-04-23 22:55:01559PasswordManager* TabContents::GetPasswordManager() {
560 if (password_manager_.get() == NULL)
561 password_manager_.reset(new PasswordManager(this));
562 return password_manager_.get();
563}
564
565PluginInstaller* TabContents::GetPluginInstaller() {
566 if (plugin_installer_.get() == NULL)
567 plugin_installer_.reset(new PluginInstaller(this));
568 return plugin_installer_.get();
569}
570
[email protected]1f18184a2010-07-21 19:34:49571TabContentsSSLHelper* TabContents::GetSSLHelper() {
572 if (ssl_helper_.get() == NULL)
573 ssl_helper_.reset(new TabContentsSSLHelper(this));
574 return ssl_helper_.get();
575}
576
[email protected]8cb5d5b2010-02-09 11:36:16577RenderProcessHost* TabContents::GetRenderProcessHost() const {
578 return render_manager_.current_host()->process();
579}
580
[email protected]98aa0b52010-05-06 17:03:08581void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46582 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08583 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10584
[email protected]98aa0b52010-05-06 17:03:08585 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57586
[email protected]fca656c2010-02-10 20:30:10587 NotificationService::current()->Notify(
588 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
589 Source<TabContents>(this),
590 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49591}
592
[email protected]98aa0b52010-05-06 17:03:08593void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
594 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40595 return;
596
597 ExtensionsService* extension_service = profile()->GetExtensionsService();
598 if (extension_service && extension_service->is_ready()) {
599 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08600 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40601 if (extension)
[email protected]98aa0b52010-05-06 17:03:08602 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40603 }
604}
605
[email protected]98aa0b52010-05-06 17:03:08606SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08607 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51608 return NULL;
609
[email protected]98aa0b52010-05-06 17:03:08610 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51611}
612
[email protected]d5f942ba2008-09-26 19:30:34613const GURL& TabContents::GetURL() const {
614 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57615 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54616 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34617}
618
[email protected]96d185d2009-04-24 03:28:54619const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55620 // Transient entries take precedence. They are used for interstitial pages
621 // that are shown on top of existing pages.
622 NavigationEntry* entry = controller_.GetTransientEntry();
623 if (entry)
624 return entry->GetTitleForDisplay(&controller_);
625
[email protected]96d185d2009-04-24 03:28:54626 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
627 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
628 if (our_dom_ui) {
629 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55630 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54631 if (!(entry && entry->IsViewSourceMode())) {
632 // Give the DOM UI the chance to override our title.
633 const string16& title = our_dom_ui->overridden_title();
634 if (!title.empty())
635 return title;
636 }
637 }
638
639 // We use the title for the last committed entry rather than a pending
640 // navigation entry. For example, when the user types in a URL, we want to
641 // keep the old page's title until the new load has committed and we get a new
642 // title.
[email protected]96d185d2009-04-24 03:28:54643 entry = controller_.GetLastCommittedEntry();
644 if (entry)
645 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54646 return EmptyString16();
647}
648
[email protected]bbbc1ef2010-02-12 18:03:41649// static
650string16 TabContents::GetDefaultTitle() {
651 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
652}
653
[email protected]d5f942ba2008-09-26 19:30:34654int32 TabContents::GetMaxPageID() {
655 if (GetSiteInstance())
656 return GetSiteInstance()->max_page_id();
657 else
658 return max_page_id_;
659}
660
661void TabContents::UpdateMaxPageID(int32 page_id) {
662 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34663 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34664 // testing.
665 if (GetSiteInstance())
666 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16667 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34668}
669
[email protected]96d185d2009-04-24 03:28:54670SiteInstance* TabContents::GetSiteInstance() const {
671 return render_manager_.current_host()->site_instance();
672}
673
[email protected]96d185d2009-04-24 03:28:54674bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15675 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54676 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15677 if (entry && (entry->IsViewSourceMode() ||
678 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54679 return true;
[email protected]8ab24cc2009-11-13 20:56:15680 }
[email protected]83e3895b2009-06-11 00:07:16681
[email protected]96d185d2009-04-24 03:28:54682 DOMUI* dom_ui = GetDOMUIForCurrentState();
683 if (dom_ui)
684 return !dom_ui->should_hide_url();
685 return true;
686}
687
[email protected]d5f942ba2008-09-26 19:30:34688SkBitmap TabContents::GetFavIcon() const {
689 // Like GetTitle(), we also want to use the favicon for the last committed
690 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57691 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47692 if (entry)
693 return entry->favicon().bitmap();
694
[email protected]ce3fa3c2009-04-20 19:55:57695 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34696 if (entry)
697 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34698 return SkBitmap();
699}
700
[email protected]0b303cc2009-09-28 22:35:15701bool TabContents::FavIconIsValid() const {
702 NavigationEntry* entry = controller_.GetTransientEntry();
703 if (entry)
704 return entry->favicon().is_valid();
705
706 entry = controller_.GetLastCommittedEntry();
707 if (entry)
708 return entry->favicon().is_valid();
709
710 return false;
711}
712
[email protected]96d185d2009-04-24 03:28:54713bool TabContents::ShouldDisplayFavIcon() {
714 // Always display a throbber during pending loads.
715 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
716 return true;
717
718 DOMUI* dom_ui = GetDOMUIForCurrentState();
719 if (dom_ui)
720 return !dom_ui->hide_favicon();
721 return true;
722}
723
[email protected]96d185d2009-04-24 03:28:54724std::wstring TabContents::GetStatusText() const {
725 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
726 return std::wstring();
727
728 switch (load_state_) {
729 case net::LOAD_STATE_WAITING_FOR_CACHE:
730 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04731 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
732 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54733 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
734 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
735 case net::LOAD_STATE_RESOLVING_HOST:
736 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
737 case net::LOAD_STATE_CONNECTING:
738 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06739 case net::LOAD_STATE_SSL_HANDSHAKE:
740 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54741 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56742 if (upload_size_)
743 return l10n_util::GetStringF(
744 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
745 static_cast<int>((100 * upload_position_) / upload_size_));
746 else
747 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54748 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
749 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
750 load_state_host_);
751 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
752 case net::LOAD_STATE_IDLE:
753 case net::LOAD_STATE_READING_RESPONSE:
754 break;
755 }
756
757 return std::wstring();
758}
759
[email protected]d5f942ba2008-09-26 19:30:34760void TabContents::SetIsCrashed(bool state) {
761 if (state == is_crashed_)
762 return;
763
764 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50765 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34766}
767
[email protected]744ef172009-10-16 21:53:46768void TabContents::PageActionStateChanged() {
769 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00770}
[email protected]ce5c4502009-05-06 16:46:11771
[email protected]d5f942ba2008-09-26 19:30:34772void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
773 if (delegate_)
774 delegate_->NavigationStateChanged(this, changed_flags);
775}
776
[email protected]96d185d2009-04-24 03:28:54777void TabContents::DidBecomeSelected() {
778 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16779 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
780 if (rwhv) {
781 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43782#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16783 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43784#endif
785 }
[email protected]96d185d2009-04-24 03:28:54786
[email protected]8cb5d5b2010-02-09 11:36:16787 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54788}
789
790void TabContents::WasHidden() {
791 if (!capturing_contents()) {
792 // |render_view_host()| can be NULL if the user middle clicks a link to open
793 // a tab in then background, then closes the tab before selecting it. This
794 // is because closing the tab calls TabContents::Destroy(), which removes
795 // the |render_view_host()|; then when we actually destroy the window,
796 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16797 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
798 if (rwhv)
799 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54800 }
801
802 NotificationService::current()->Notify(
803 NotificationType::TAB_CONTENTS_HIDDEN,
804 Source<TabContents>(this),
805 NotificationService::NoDetails());
806}
807
[email protected]d5f942ba2008-09-26 19:30:34808void TabContents::Activate() {
809 if (delegate_)
810 delegate_->ActivateContents(this);
811}
812
[email protected]ea42e7782010-08-23 23:58:12813void TabContents::Deactivate() {
814 if (delegate_)
815 delegate_->DeactivateContents(this);
816}
817
[email protected]96d185d2009-04-24 03:28:54818void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16819 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
820 if (rwhv)
821 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54822}
823
824void TabContents::HideContents() {
825 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
826 // our superclass HideContents(), because some callers want to be very picky
827 // about the order in which these get called. In addition to making the code
828 // here practically impossible to understand, this also means we end up
829 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34830 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54831 WasHidden();
832}
833
[email protected]c0588052008-10-27 23:01:50834void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34835 WindowOpenDisposition disposition,
836 PageTransition::Type transition) {
837 if (delegate_)
[email protected]c0588052008-10-27 23:01:50838 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34839}
840
[email protected]1ccb3568d2010-02-19 10:51:16841bool TabContents::NavigateToPendingEntry(
842 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54843 const NavigationEntry& entry = *controller_.pending_entry();
844
845 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
846 if (!dest_render_view_host)
847 return false; // Unable to create the desired render view host.
848
[email protected]770dd8b2010-05-24 18:11:39849 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
850 dest_render_view_host->EnablePreferredSizeChangedMode(
851 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
852 }
[email protected]9fb325e2010-05-06 18:23:24853
[email protected]0352e5472010-04-29 00:11:40854 // For security, we should never send non-DOM-UI URLs (other than about:blank)
855 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58856 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40857 bool is_allowed_in_dom_ui_renderer =
858 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
859 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58860 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40861 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58862
[email protected]96d185d2009-04-24 03:28:54863 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12864 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32865 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00866 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
867 dest_render_view_host,
868 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32869 }
[email protected]96d185d2009-04-24 03:28:54870
871 // Used for page load time metrics.
872 current_load_start_ = base::TimeTicks::Now();
873
874 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34875 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00876 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34877 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54878
879 if (entry.page_id() == -1) {
880 // HACK!! This code suppresses javascript: URLs from being added to
881 // session history, which is what we want to do for javascript: URLs that
882 // do not generate content. What we really need is a message from the
883 // renderer telling us that a new page was not created. The same message
884 // could be used for mailto: URLs and the like.
885 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
886 return false;
887 }
888
889 // Clear any provisional password saves - this stops password infobars
890 // showing up on pages the user navigates to while the right page is
891 // loading.
892 GetPasswordManager()->ClearProvisionalSave();
893
[email protected]1ccb3568d2010-02-19 10:51:16894 if (reload_type != NavigationController::NO_RELOAD &&
895 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48896 FaviconService* favicon_service =
897 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
898 if (favicon_service)
899 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54900 }
901
[email protected]d5f942ba2008-09-26 19:30:34902 return true;
903}
904
[email protected]96d185d2009-04-24 03:28:54905void TabContents::Stop() {
906 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09907 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54908}
909
[email protected]96d185d2009-04-24 03:28:54910void TabContents::DisassociateFromPopupCount() {
911 render_view_host()->DisassociateFromPopupCount();
912}
913
914TabContents* TabContents::Clone() {
915 // We create a new SiteInstance so that the new tab won't share processes
916 // with the old one. This can be changed in the future if we need it to share
917 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32918 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54919 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21920 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54921 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08922 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08923 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54924 return tc;
925}
926
[email protected]4d677202009-07-19 07:37:12927void TabContents::ShowPageInfo(const GURL& url,
928 const NavigationEntry::SSLStatus& ssl,
929 bool show_history) {
930 if (!delegate_)
931 return;
932
[email protected]bb678332009-07-21 00:15:50933 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12934}
935
initial.commit09911bf2008-07-26 23:55:29936ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28937 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29938 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28939 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29940 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44941
942 if (child_windows_.size() == 1) {
943 window->ShowConstrainedWindow();
944 BlockTabContent(true);
945 }
946
initial.commit09911bf2008-07-26 23:55:29947 return window;
948}
949
[email protected]fa1cf0b82010-01-15 21:49:44950void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55951 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
952 if (rwhv)
953 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44954 render_view_host()->set_ignore_input_events(blocked);
955 if (delegate_)
956 delegate_->SetTabContentBlocked(this, blocked);
957}
958
initial.commit09911bf2008-07-26 23:55:29959void TabContents::AddNewContents(TabContents* new_contents,
960 WindowOpenDisposition disposition,
961 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29962 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29963 if (!delegate_)
964 return;
965
[email protected]35f7d212009-04-29 21:19:27966 if ((disposition == NEW_POPUP) && !user_gesture &&
967 !CommandLine::ForCurrentProcess()->HasSwitch(
968 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22969 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31970 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29971 delegate_->GetConstrainingContents(this)->AddPopup(
972 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31973 } else {
[email protected]304f8792009-08-19 21:28:09974#if defined(OS_CHROMEOS)
975 if (disposition == NEW_POPUP) {
976 // If the popup is bigger than a given factor of the screen, then
977 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11978 // Also check for width or height == 0, which would otherwise indicate
979 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09980 GdkScreen* screen = gdk_screen_get_default();
981 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
982 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11983 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
984 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09985 disposition = NEW_FOREGROUND_TAB;
986 }
987 }
988#endif
989
[email protected]0aa55312008-10-17 21:53:08990 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29991 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
992 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49993 NotificationService::current()->Notify(
994 NotificationType::TAB_ADDED,
995 Source<TabContentsDelegate>(delegate_),
996 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29997 }
initial.commit09911bf2008-07-26 23:55:29998
[email protected]8cc8d492010-02-02 10:40:49999 // TODO(pkasting): Why is this necessary?
1000 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:291001}
1002
[email protected]bcd9dc42010-01-23 16:38:181003bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:201004 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:201005 bool is_js_code, const std::string& code_string,
1006 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511007 RenderViewHost* host = render_view_host();
1008 if (!host)
1009 return false;
1010
1011 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
1012 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
1013 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351014}
1015
[email protected]96d185d2009-04-24 03:28:541016void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491017 if (is_being_destroyed_)
1018 return;
[email protected]9fb83e82010-07-02 18:24:551019 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491020 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401021 render_view_host()->AllowScriptToClose(!visible);
[email protected]8e0bbf12010-07-20 00:03:431022 if (visible)
1023 PopupBlockedAnimation::Show(this);
[email protected]96d185d2009-04-24 03:28:541024}
1025
[email protected]5c9e97a2009-09-09 23:48:301026gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541027 return view_->GetContentNativeView();
1028}
1029
1030gfx::NativeView TabContents::GetNativeView() const {
1031 return view_->GetNativeView();
1032}
1033
1034void TabContents::GetContainerBounds(gfx::Rect *out) const {
1035 view_->GetContainerBounds(out);
1036}
1037
1038void TabContents::Focus() {
1039 view_->Focus();
1040}
1041
[email protected]90daadb42009-06-08 21:27:281042void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541043 if (showing_interstitial_page()) {
1044 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1045 return;
1046 }
[email protected]96d185d2009-04-24 03:28:541047 render_view_host()->SetInitialFocus(reverse);
1048}
1049
1050bool TabContents::FocusLocationBarByDefault() {
1051 DOMUI* dom_ui = GetDOMUIForCurrentState();
1052 if (dom_ui)
1053 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431054 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251055 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431056 return true;
[email protected]96d185d2009-04-24 03:28:541057 return false;
1058}
1059
[email protected]a26dc362010-04-23 01:48:581060void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381061 if (delegate())
[email protected]a26dc362010-04-23 01:48:581062 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381063}
1064
[email protected]616ed5a2008-11-21 22:27:241065void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321066 if (delegate_ && !delegate_->infobars_enabled()) {
1067 delegate->InfoBarClosed();
1068 return;
1069 }
1070
[email protected]616ed5a2008-11-21 22:27:241071 // Look through the existing InfoBarDelegates we have for a match. If we've
1072 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051073 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451074 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1075 // Tell the new infobar to close so that it can clean itself up.
1076 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241077 return;
[email protected]6d27a7b2009-12-18 23:25:451078 }
[email protected]616ed5a2008-11-21 22:27:241079 }
1080
1081 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561082 NotificationService::current()->Notify(
1083 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1084 Source<TabContents>(this),
1085 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241086
1087 // Add ourselves as an observer for navigations the first time a delegate is
1088 // added. We use this notification to expire InfoBars that need to expire on
1089 // page transitions.
1090 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561091 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571092 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241093 }
1094}
1095
1096void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321097 if (delegate_ && !delegate_->infobars_enabled()) {
1098 return;
1099 }
1100
[email protected]616ed5a2008-11-21 22:27:241101 std::vector<InfoBarDelegate*>::iterator it =
1102 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1103 if (it != infobar_delegates_.end()) {
1104 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561105 NotificationService::current()->Notify(
1106 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1107 Source<TabContents>(this),
1108 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241109
[email protected]cdadf6f2010-08-20 16:36:081110 // Just to be safe, make sure the delegate was not removed by an observer.
1111 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1112 if (it != infobar_delegates_.end()) {
1113 infobar_delegates_.erase(it);
1114 // Remove ourselves as an observer if we are tracking no more InfoBars.
1115 if (infobar_delegates_.empty()) {
1116 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1117 Source<NavigationController>(&controller_));
1118 }
1119 } else {
1120 // If you hit this NOTREACHED, please comment in bug
1121 // http://crbug.com/50428 how you got there.
1122 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031123 }
[email protected]616ed5a2008-11-21 22:27:241124 }
1125}
[email protected]3edd9522009-03-04 22:19:411126
[email protected]f81821c2009-08-07 01:29:471127void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1128 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321129 if (delegate_ && !delegate_->infobars_enabled()) {
1130 new_delegate->InfoBarClosed();
1131 return;
1132 }
1133
[email protected]f81821c2009-08-07 01:29:471134 std::vector<InfoBarDelegate*>::iterator it =
1135 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1136 DCHECK(it != infobar_delegates_.end());
1137
1138 // Notify the container about the change of plans.
1139 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1140 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1141 old_delegate, new_delegate));
1142 NotificationService::current()->Notify(
1143 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1144 Source<TabContents>(this),
1145 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1146
[email protected]cdadf6f2010-08-20 16:36:081147 // Just to be safe, make sure the delegate was not removed by an observer.
1148 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1149 if (it != infobar_delegates_.end()) {
1150 // Remove the old one.
1151 infobar_delegates_.erase(it);
1152 } else {
1153 // If you hit this NOTREACHED, please comment in bug
1154 // http://crbug.com/50428 how you got there.
1155 NOTREACHED();
1156 }
[email protected]f81821c2009-08-07 01:29:471157
1158 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081159 DCHECK(find(infobar_delegates_.begin(),
1160 infobar_delegates_.end(), new_delegate) ==
1161 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471162 infobar_delegates_.push_back(new_delegate);
1163}
1164
[email protected]20ede072009-10-06 00:28:351165bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271166 if (showing_interstitial_page())
1167 return false;
1168
[email protected]96d185d2009-04-24 03:28:541169 // See GetDOMUIForCurrentState() comment for more info. This case is very
1170 // similar, but for non-first loads, we want to use the committed entry. This
1171 // is so the bookmarks bar disappears at the same time the page does.
1172 if (controller_.GetLastCommittedEntry()) {
1173 // Not the first load, always use the committed DOM UI.
1174 if (render_manager_.dom_ui())
1175 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1176 return false; // Default.
1177 }
1178
1179 // When it's the first load, we know either the pending one or the committed
1180 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1181 // of them will be valid, so we can just check both.
1182 if (render_manager_.pending_dom_ui())
1183 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1184 if (render_manager_.dom_ui())
1185 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1186 return false; // Default.
1187}
1188
[email protected]3edd9522009-03-04 22:19:411189void TabContents::ToolbarSizeChanged(bool is_animating) {
1190 TabContentsDelegate* d = delegate();
1191 if (d)
1192 d->ToolbarSizeChanged(this, is_animating);
1193}
[email protected]616ed5a2008-11-21 22:27:241194
[email protected]fc6fb7fb2009-11-07 02:35:041195bool TabContents::CanDownload(int request_id) {
1196 TabContentsDelegate* d = delegate();
1197 if (d)
1198 return d->CanDownload(request_id);
1199 return true;
1200}
1201
[email protected]d5f942ba2008-09-26 19:30:341202void TabContents::OnStartDownload(DownloadItem* download) {
1203 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341204
1205 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311206 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341207
[email protected]5b928b62010-08-03 11:46:511208 if (tab_contents && tab_contents->delegate())
1209 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411210}
[email protected]3edd9522009-03-04 22:19:411211
[email protected]d5f942ba2008-09-26 19:30:341212void TabContents::WillClose(ConstrainedWindow* window) {
1213 ConstrainedWindowList::iterator it =
1214 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441215 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341216 if (it != child_windows_.end())
1217 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371218 if (child_windows_.size() > 0) {
1219 if (removed_topmost_window) {
1220 child_windows_[0]->ShowConstrainedWindow();
1221 }
[email protected]fa1cf0b82010-01-15 21:49:441222 BlockTabContent(true);
1223 } else {
1224 BlockTabContent(false);
1225 }
[email protected]66ba4932009-06-04 19:22:131226}
[email protected]d5f942ba2008-09-26 19:30:341227
[email protected]66ba4932009-06-04 19:22:131228void TabContents::WillCloseBlockedPopupContainer(
1229 BlockedPopupContainer* container) {
1230 DCHECK(blocked_popups_ == container);
1231 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491232 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341233}
1234
[email protected]d5f942ba2008-09-26 19:30:341235void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351236#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061237 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351238#endif
[email protected]d5f942ba2008-09-26 19:30:341239}
1240
[email protected]c1dc9f132009-11-20 23:13:211241void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121242 bool forward_direction,
1243 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211244 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011245 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211246 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531247 string16 last_search_prepopulate_text =
1248 FindBarState::GetLastPrepopulateText(profile());
1249
[email protected]87fae512009-12-11 02:20:211250 // Try the last thing we searched for on this tab, then the last thing
1251 // searched for on any tab.
1252 if (!previous_find_text_.empty())
1253 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531254 else if (!last_search_prepopulate_text.empty())
1255 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211256 else
[email protected]e491f1c2009-05-22 20:28:121257 return;
[email protected]e491f1c2009-05-22 20:28:121258 }
[email protected]6e95706d2009-04-23 22:55:011259
[email protected]101c90e2009-10-26 21:14:441260 // Keep track of the previous search.
1261 previous_find_text_ = find_text_;
1262
[email protected]6e95706d2009-04-23 22:55:011263 // This is a FindNext operation if we are searching for the same text again,
1264 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1265 // exception to this is if the Find was aborted (then we don't want FindNext
1266 // because the highlighting has been cleared and we need it to reappear). We
1267 // therefore treat FindNext after an aborted Find operation as a full fledged
1268 // Find.
[email protected]c1dc9f132009-11-20 23:13:211269 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121270 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011271 !find_op_aborted_;
1272 if (!find_next)
1273 current_find_request_id_ = find_request_id_counter_++;
1274
[email protected]c1dc9f132009-11-20 23:13:211275 if (!search_string.empty())
1276 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121277 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011278
1279 find_op_aborted_ = false;
1280
1281 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531282 FindBarState* find_bar_state = profile()->GetFindBarState();
1283 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011284 render_view_host()->StartFinding(current_find_request_id_,
1285 find_text_,
1286 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121287 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011288 find_next);
1289}
1290
[email protected]5bc8fe92010-03-11 18:19:001291void TabContents::StopFinding(
1292 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011293 if (selection_action == FindBarController::kClearSelection) {
1294 // kClearSelection means the find string has been cleared by the user, but
1295 // the UI has not been dismissed. In that case we want to clear the
1296 // previously remembered search (http://crbug.com/42639).
1297 previous_find_text_ = string16();
1298 } else {
[email protected]2d2dffc2009-06-09 21:41:001299 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011300 if (!find_text_.empty())
1301 previous_find_text_ = find_text_;
1302 }
[email protected]101c90e2009-10-26 21:14:441303 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011304 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121305 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001306 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011307}
1308
[email protected]420ae012009-04-24 05:16:321309void TabContents::OnSavePage() {
1310 // If we can not save the page, try to download it.
1311 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1312 DownloadManager* dlm = profile()->GetDownloadManager();
1313 const GURL& current_page_url = GetURL();
1314 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221315 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321316 return;
1317 }
1318
1319 Stop();
1320
1321 // Create the save package and possibly prompt the user for the name to save
1322 // the page as. The user prompt is an asynchronous operation that runs on
1323 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221324 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321325 save_package_->GetSaveInfo();
1326}
1327
1328// Used in automated testing to bypass prompting the user for file names.
1329// Instead, the names and paths are hard coded rather than running them through
1330// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111331bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321332 SavePackage::SavePackageType save_type) {
1333 // Stop the page from navigating.
1334 Stop();
1335
[email protected]828cabe2009-09-26 22:47:111336 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591337 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321338}
1339
[email protected]89d6e6e2009-12-03 23:06:511340void TabContents::EmailPageLocation() {
1341 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1342 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1343 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1344 title + "&body=%0A%0A" + page_url;
1345 platform_util::OpenExternal(GURL(mailto));
1346}
1347
[email protected]420ae012009-04-24 05:16:321348void TabContents::PrintPreview() {
1349 // We don't show the print preview yet, only the print dialog.
1350 PrintNow();
1351}
1352
1353bool TabContents::PrintNow() {
1354 // We can't print interstitial page for now.
1355 if (showing_interstitial_page())
1356 return false;
1357
1358 return render_view_host()->PrintPages();
1359}
1360
[email protected]82270452009-06-19 15:58:011361void TabContents::PrintingDone(int document_cookie, bool success) {
1362 render_view_host()->PrintingDone(document_cookie, success);
1363}
1364
[email protected]420ae012009-04-24 05:16:321365bool TabContents::IsActiveEntry(int32 page_id) {
1366 NavigationEntry* active_entry = controller_.GetActiveEntry();
1367 return (active_entry != NULL &&
1368 active_entry->site_instance() == GetSiteInstance() &&
1369 active_entry->page_id() == page_id);
1370}
1371
[email protected]b2fe07d12010-02-09 14:38:081372void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161373 set_encoding(encoding);
1374 render_view_host()->SetPageEncoding(encoding);
1375}
1376
[email protected]b2fe07d12010-02-09 14:38:081377void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161378 reset_encoding();
1379 render_view_host()->ResetPageEncodingToDefault();
1380}
1381
1382void TabContents::WindowMoveOrResizeStarted() {
1383 render_view_host()->WindowMoveOrResizeStarted();
1384}
1385
[email protected]3f8eb7f2009-10-02 23:58:051386void TabContents::LogNewTabTime(const std::string& event_name) {
1387 // Not all new tab pages get timed. In those cases, we don't have a
1388 // new_tab_start_time_.
1389 if (new_tab_start_time_.is_null())
1390 return;
1391
1392 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441393 MetricEventDurationDetails details(event_name,
1394 static_cast<int>(duration.InMilliseconds()));
1395
[email protected]7ab1e7d62009-10-14 23:32:011396 if (event_name == "Tab.NewTabScriptStart") {
1397 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1398 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1399 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1400 } else if (event_name == "Tab.NewTabOnload") {
1401 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051402 // The new tab page has finished loading; reset it.
1403 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441404 } else {
1405 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051406 }
[email protected]84abba62009-10-07 17:01:441407 NotificationService::current()->Notify(
1408 NotificationType::METRIC_EVENT_DURATION,
1409 Source<TabContents>(this),
1410 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051411}
1412
[email protected]7ab1e7d62009-10-14 23:32:011413void TabContents::OnCloseStarted() {
1414 if (tab_close_start_time_.is_null())
1415 tab_close_start_time_ = base::TimeTicks::Now();
1416}
1417
[email protected]46624bf2010-06-09 16:04:191418bool TabContents::ShouldAcceptDragAndDrop() const {
1419#if defined(OS_CHROMEOS)
1420 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1421 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561422 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191423#else
1424 return true;
1425#endif
1426}
1427
[email protected]c37e3b62010-01-22 00:15:171428TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171429 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161430
1431 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081432 if (extension_app_)
1433 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161434 else if (entry)
1435 tab_nav.SetFromNavigationEntry(*entry);
1436
[email protected]c37e3b62010-01-22 00:15:171437 std::vector<TabNavigation> navigations;
1438 navigations.push_back(tab_nav);
1439
1440 TabContents* new_contents =
1441 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081442 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171443 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171444
[email protected]98aa0b52010-05-06 17:03:081445 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161446 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1447
[email protected]c37e3b62010-01-22 00:15:171448 return new_contents;
1449}
1450
[email protected]96d185d2009-04-24 03:28:541451// Notifies the RenderWidgetHost instance about the fact that the page is
1452// loading, or done loading and calls the base implementation.
1453void TabContents::SetIsLoading(bool is_loading,
1454 LoadNotificationDetails* details) {
1455 if (is_loading == is_loading_)
1456 return;
1457
1458 if (!is_loading) {
1459 load_state_ = net::LOAD_STATE_IDLE;
1460 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561461 upload_size_ = 0;
1462 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541463 }
1464
1465 render_manager_.SetIsLoading(is_loading);
1466
1467 is_loading_ = is_loading;
1468 waiting_for_response_ = is_loading;
1469
1470 if (delegate_)
1471 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351472 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541473
1474 NotificationType type = is_loading ? NotificationType::LOAD_START :
1475 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111476 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541477 if (details)
1478 det = Details<LoadNotificationDetails>(details);
1479 NotificationService::current()->Notify(type,
1480 Source<NavigationController>(&controller_),
1481 det);
1482}
1483
[email protected]b6c874582009-05-08 19:38:311484void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291485 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061486 // A page can't spawn popups (or do anything else, either) until its load
1487 // commits, so when we reach here, the popup was spawned by the
1488 // NavigationController's last committed entry, not the active entry. For
1489 // example, if a page opens a popup in an onunload() handler, then the active
1490 // entry is the page to be loaded as we navigate away from the unloading
1491 // page. For this reason, we can't use GetURL() to get the opener URL,
1492 // because it returns the active entry.
1493 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1494 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1495
1496 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491497 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091498 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491499 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1500 } else {
1501 if (!blocked_popups_)
1502 blocked_popups_ = new BlockedPopupContainer(this);
1503 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]55126132010-08-19 14:53:281504 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1505 std::string());
[email protected]8cc8d492010-02-02 10:40:491506 }
[email protected]b9681312008-11-07 00:08:261507}
[email protected]616ed5a2008-11-21 22:27:241508
1509namespace {
1510bool TransitionIsReload(PageTransition::Type transition) {
1511 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1512}
1513}
1514
1515void TabContents::ExpireInfoBars(
1516 const NavigationController::LoadCommittedDetails& details) {
1517 // Only hide InfoBars when the user has done something that makes the main
1518 // frame load. We don't want various automatic or subframe navigations making
1519 // it disappear.
1520 if (!details.is_user_initiated_main_frame_load())
1521 return;
1522
[email protected]f86a07022008-11-25 01:06:051523 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241524 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081525 if (!delegate) {
1526 // If you hit this NOTREACHED, please comment in bug
1527 // http://crbug.com/50428 how you got there.
1528 NOTREACHED();
1529 continue;
1530 }
1531
[email protected]f86a07022008-11-25 01:06:051532 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241533 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241534 }
1535}
[email protected]fdd61c62009-04-22 19:22:571536
[email protected]96d185d2009-04-24 03:28:541537DOMUI* TabContents::GetDOMUIForCurrentState() {
1538 // When there is a pending navigation entry, we want to use the pending DOMUI
1539 // that goes along with it to control the basic flags. For example, we want to
1540 // show the pending URL in the URL bar, so we want the display_url flag to
1541 // be from the pending entry.
1542 //
1543 // The confusion comes because there are multiple possibilities for the
1544 // initial load in a tab as a side effect of the way the RenderViewHostManager
1545 // works.
1546 //
1547 // - For the very first tab the load looks "normal". The new tab DOM UI is
1548 // the pending one, and we want it to apply here.
1549 //
1550 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1551 // get switched to the one previously associated with the new tab pages.
1552 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1553 // have a committed DOM UI in this case.
1554 //
1555 // This condition handles all of these cases:
1556 //
1557 // - First load in first tab: no committed nav entry + pending nav entry +
1558 // pending dom ui:
1559 // -> Use pending DOM UI if any.
1560 //
1561 // - First load in second tab: no committed nav entry + pending nav entry +
1562 // no pending DOM UI:
1563 // -> Use the committed DOM UI if any.
1564 //
1565 // - Second navigation in any tab: committed nav entry + pending nav entry:
1566 // -> Use pending DOM UI if any.
1567 //
1568 // - Normal state with no load: committed nav entry + no pending nav entry:
1569 // -> Use committed DOM UI.
1570 if (controller_.pending_entry() &&
1571 (controller_.GetLastCommittedEntry() ||
1572 render_manager_.pending_dom_ui()))
1573 return render_manager_.pending_dom_ui();
1574 return render_manager_.dom_ui();
1575}
[email protected]420ae012009-04-24 05:16:321576
1577void TabContents::DidNavigateMainFramePostCommit(
1578 const NavigationController::LoadCommittedDetails& details,
1579 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441580 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1581 // If this is a window.open navigation, use the same DOMUI as the renderer
1582 // that opened the window, as long as both renderers have the same
1583 // privileges.
1584 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1585 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1586 // dom_ui might be NULL if the URL refers to a non-existent extension.
1587 if (dom_ui) {
1588 render_manager_.SetDOMUIPostCommit(dom_ui);
1589 dom_ui->RenderViewCreated(render_view_host());
1590 }
1591 }
1592 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1593 }
1594
[email protected]420ae012009-04-24 05:16:321595 if (details.is_user_initiated_main_frame_load()) {
1596 // Clear the status bubble. This is a workaround for a bug where WebKit
1597 // doesn't let us know that the cursor left an element during a
1598 // transition (this is also why the mouse cursor remains as a hand after
1599 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1600 // clear the bubble when a user navigates to a named anchor in the same
1601 // page.
1602 UpdateTargetURL(details.entry->page_id(), GURL());
1603
1604 // UpdateHelpersForDidNavigate will handle the case where the password_form
1605 // origin is valid.
1606 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1607 // cleaned up and covered by tests.
1608 if (!params.password_form.origin.is_valid())
1609 GetPasswordManager()->DidNavigate();
1610 }
1611
1612 // The keyword generator uses the navigation entries, so must be called after
1613 // the commit.
1614 GenerateKeywordIfNecessary(params);
1615
1616 // Allow the new page to set the title again.
1617 received_page_title_ = false;
1618
1619 // Get the favicon, either from history or request it from the net.
1620 fav_icon_helper_.FetchFavIcon(details.entry->url());
1621
[email protected]0de80162010-02-03 04:52:351622 // Clear all page actions, blocked content notifications and browser actions
1623 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141624 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081625 ExtensionsService* service = profile()->GetExtensionsService();
1626 if (service) {
1627 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571628 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081629 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521630 if (browser_action) {
1631 browser_action->ClearAllValuesForTab(controller().session_id().id());
1632 NotificationService::current()->Notify(
1633 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571634 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521635 NotificationService::NoDetails());
1636 }
[email protected]92c6f9b92009-10-24 04:35:081637
[email protected]5d246db22009-10-27 06:17:571638 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521639 service->extensions()->at(i)->page_action();
1640 if (page_action) {
1641 page_action->ClearAllValuesForTab(controller().session_id().id());
1642 PageActionStateChanged();
1643 }
[email protected]92c6f9b92009-10-24 04:35:081644 }
[email protected]aece2c7f2009-08-27 20:43:171645 }
[email protected]0de80162010-02-03 04:52:351646
1647 // Close blocked popups.
1648 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341649 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351650 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461651 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351652 }
1653
1654 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411655 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551656 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471657
1658 // Once the main frame is navigated, we're no longer considered to have
1659 // displayed insecure content.
1660 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171661 }
[email protected]ce5c4502009-05-06 16:46:111662
[email protected]8cc8d492010-02-02 10:40:491663 // Close constrained windows if necessary.
1664 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1665 details.previous_url, details.entry->url()))
1666 CloseConstrainedWindows();
1667
[email protected]420ae012009-04-24 05:16:321668 // Update the starred state.
1669 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531670
1671 // Clear the cache of forms in AutoFill.
1672 if (autofill_manager_.get())
1673 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321674}
1675
1676void TabContents::DidNavigateAnyFramePostCommit(
1677 RenderViewHost* render_view_host,
1678 const NavigationController::LoadCommittedDetails& details,
1679 const ViewHostMsg_FrameNavigate_Params& params) {
1680 // If we navigate, start showing messages again. This does nothing to prevent
1681 // a malicious script from spamming messages, since the script could just
1682 // reload the page to stop blocking.
1683 suppress_javascript_messages_ = false;
1684
[email protected]420ae012009-04-24 05:16:321685 // Notify the password manager of the navigation or form submit.
1686 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1687 // cleaned up and covered by tests.
1688 if (params.password_form.origin.is_valid())
1689 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551690
1691 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581692 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321693}
1694
[email protected]8cc8d492010-02-02 10:40:491695void TabContents::CloseConstrainedWindows() {
1696 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321697 // We use indices instead of iterators in case CloseWindow does something
1698 // that may invalidate an iterator.
1699 int size = static_cast<int>(child_windows_.size());
1700 for (int i = size - 1; i >= 0; --i) {
1701 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441702 if (window) {
[email protected]420ae012009-04-24 05:16:321703 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441704 BlockTabContent(false);
1705 }
[email protected]420ae012009-04-24 05:16:321706 }
1707}
1708
1709void TabContents::UpdateStarredStateForCurrentURL() {
1710 BookmarkModel* model = profile()->GetBookmarkModel();
1711 const bool old_state = is_starred_;
1712 is_starred_ = (model && model->IsBookmarked(GetURL()));
1713
1714 if (is_starred_ != old_state && delegate())
1715 delegate()->URLStarredChanged(this, is_starred_);
1716}
1717
1718void TabContents::UpdateAlternateErrorPageURL() {
1719 GURL url = GetAlternateErrorPageURL();
1720 render_view_host()->SetAlternateErrorPageURL(url);
1721}
1722
1723void TabContents::UpdateWebPreferences() {
1724 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1725}
1726
1727void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1728 RenderViewHost* rvh) {
1729 // If we are creating a RVH for a restored controller, then we might
1730 // have more page IDs than the SiteInstance's current max page ID. We must
1731 // make sure that the max page ID is larger than any restored page ID.
1732 // Note that it is ok for conflicting page IDs to exist in another tab
1733 // (i.e., NavigationController), but if any page ID is larger than the max,
1734 // the back/forward list will get confused.
1735 int max_restored_page_id = controller_.max_restored_page_id();
1736 if (max_restored_page_id > 0) {
1737 int curr_max_page_id = site_instance->max_page_id();
1738 if (max_restored_page_id > curr_max_page_id) {
1739 // Need to update the site instance immediately.
1740 site_instance->UpdateMaxPageID(max_restored_page_id);
1741
1742 // Also tell the renderer to update its internal representation. We
1743 // need to reserve enough IDs to make all restored page IDs less than
1744 // the max.
1745 if (curr_max_page_id < 0)
1746 curr_max_page_id = 0;
1747 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1748 }
1749 }
1750}
1751
1752void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541753 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471754 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321755 const ViewHostMsg_FrameNavigate_Params& params) {
1756 if (profile()->IsOffTheRecord())
1757 return;
1758
1759 // Add to history service.
1760 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1761 if (hs) {
1762 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541763 virtual_url != params.url) {
1764 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321765 // types of URLs, we will display a magic URL that is different from where
1766 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541767 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1768 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321769 // to sub-frames.
1770 std::vector<GURL> redirects = params.redirects;
1771 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541772 redirects.back() = virtual_url;
1773 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]5989f1a2010-08-21 02:21:111774 params.transition, redirects, history::SOURCE_BROWSED,
1775 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321776 } else {
1777 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]5989f1a2010-08-21 02:21:111778 params.transition, params.redirects, history::SOURCE_BROWSED,
[email protected]befd8d822009-07-01 04:51:471779 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321780 }
1781 }
1782}
1783
1784bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1785 const std::wstring& title) {
1786 // For file URLs without a title, use the pathname instead. In the case of a
1787 // synthesized title, we don't want the update to count toward the "one set
1788 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251789 string16 final_title;
[email protected]420ae012009-04-24 05:16:321790 bool explicit_set;
1791 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251792 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321793 explicit_set = false; // Don't count synthetic titles toward the set limit.
1794 } else {
[email protected]e53668962010-06-23 15:35:251795 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321796 explicit_set = true;
1797 }
1798
[email protected]e53668962010-06-23 15:35:251799 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321800 return false; // Nothing changed, don't bother.
1801
[email protected]e53668962010-06-23 15:35:251802 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321803
1804 // Update the history system for this page.
1805 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1806 HistoryService* hs =
1807 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1808 if (hs)
[email protected]ebe89e062009-08-13 23:16:541809 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321810
1811 // Don't allow the title to be saved again for explicitly set ones.
1812 received_page_title_ = explicit_set;
1813 }
1814
1815 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251816 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321817
[email protected]cbc0e1b2010-04-12 18:33:041818 NotificationService::current()->Notify(
1819 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1820 Source<TabContents>(this),
1821 NotificationService::NoDetails());
1822
[email protected]420ae012009-04-24 05:16:321823 return true;
1824}
1825
1826void TabContents::NotifySwapped() {
1827 // After sending out a swap notification, we need to send a disconnect
1828 // notification so that clients that pick up a pointer to |this| can NULL the
1829 // pointer. See Bug 1230284.
1830 notify_disconnection_ = true;
1831 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341832 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221833 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321834 NotificationService::NoDetails());
1835}
1836
1837void TabContents::NotifyConnected() {
1838 notify_disconnection_ = true;
1839 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341840 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221841 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321842 NotificationService::NoDetails());
1843}
1844
1845void TabContents::NotifyDisconnected() {
1846 if (!notify_disconnection_)
1847 return;
1848
1849 notify_disconnection_ = false;
1850 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341851 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221852 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321853 NotificationService::NoDetails());
1854}
1855
1856void TabContents::GenerateKeywordIfNecessary(
1857 const ViewHostMsg_FrameNavigate_Params& params) {
1858 if (!params.searchable_form_url.is_valid())
1859 return;
1860
1861 if (profile()->IsOffTheRecord())
1862 return;
1863
1864 int last_index = controller_.last_committed_entry_index();
1865 // When there was no previous page, the last index will be 0. This is
1866 // normally due to a form submit that opened in a new tab.
1867 // TODO(brettw) bug 916126: we should support keywords when form submits
1868 // happen in new tabs.
1869 if (last_index <= 0)
1870 return;
1871 const NavigationEntry* previous_entry =
1872 controller_.GetEntryAtIndex(last_index - 1);
1873 if (IsFormSubmit(previous_entry)) {
1874 // Only generate a keyword if the previous page wasn't itself a form
1875 // submit.
1876 return;
1877 }
1878
1879 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1880 previous_entry->user_typed_url() : previous_entry->url();
1881 std::wstring keyword =
1882 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1883 if (keyword.empty())
1884 return;
1885
1886 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1887 if (!url_model)
1888 return;
1889
1890 if (!url_model->loaded()) {
1891 url_model->Load();
1892 return;
1893 }
1894
1895 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191896 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321897 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1898 return;
1899
1900 if (current_url) {
1901 if (current_url->originating_url().is_valid()) {
1902 // The existing keyword was generated from an OpenSearch description
1903 // document, don't regenerate.
1904 return;
1905 }
1906 url_model->Remove(current_url);
1907 }
1908 TemplateURL* new_url = new TemplateURL();
1909 new_url->set_keyword(keyword);
1910 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191911 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321912 new_url->add_input_encoding(params.searchable_form_encoding);
1913 DCHECK(controller_.GetLastCommittedEntry());
1914 const GURL& favicon_url =
1915 controller_.GetLastCommittedEntry()->favicon().url();
1916 if (favicon_url.is_valid()) {
1917 new_url->SetFavIconURL(favicon_url);
1918 } else {
1919 // The favicon url isn't valid. This means there really isn't a favicon,
1920 // or the favicon url wasn't obtained before the load started. This assumes
1921 // the later.
1922 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1923 // its url.
1924 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1925 }
1926 new_url->set_safe_for_autoreplace(true);
1927 url_model->Add(new_url);
1928}
1929
[email protected]bf5c2ff392009-07-08 16:24:331930void TabContents::OnUserGesture() {
1931 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011932 DownloadRequestLimiter* limiter =
1933 g_browser_process->download_request_limiter();
1934 if (limiter)
1935 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261936 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331937}
1938
1939void TabContents::OnFindReply(int request_id,
1940 int number_of_matches,
1941 const gfx::Rect& selection_rect,
1942 int active_match_ordinal,
1943 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421944 // Ignore responses for requests that have been aborted.
1945 if (find_op_aborted_)
1946 return;
1947
[email protected]bf5c2ff392009-07-08 16:24:331948 // Ignore responses for requests other than the one we have most recently
1949 // issued. That way we won't act on stale results when the user has
1950 // already typed in another query.
1951 if (request_id != current_find_request_id_)
1952 return;
1953
1954 if (number_of_matches == -1)
1955 number_of_matches = last_search_result_.number_of_matches();
1956 if (active_match_ordinal == -1)
1957 active_match_ordinal = last_search_result_.active_match_ordinal();
1958
1959 gfx::Rect selection = selection_rect;
1960 if (selection.IsEmpty())
1961 selection = last_search_result_.selection_rect();
1962
1963 // Notify the UI, automation and any other observers that a find result was
1964 // found.
1965 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1966 selection, active_match_ordinal,
1967 final_update);
1968 NotificationService::current()->Notify(
1969 NotificationType::FIND_RESULT_AVAILABLE,
1970 Source<TabContents>(this),
1971 Details<FindNotificationDetails>(&last_search_result_));
1972}
1973
1974void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381975 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1976 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331977}
1978
[email protected]bf5c2ff392009-07-08 16:24:331979void TabContents::OnMissingPluginStatus(int status) {
1980#if defined(OS_WIN)
1981// TODO(PORT): pull in when plug-ins work
1982 GetPluginInstaller()->OnMissingPluginStatus(status);
1983#endif
1984}
1985
1986void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331987 DCHECK(!plugin_path.value().empty());
1988
1989 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351990#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331991 scoped_ptr<FileVersionInfo> version_info(
1992 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1993 if (version_info.get()) {
1994 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371995 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331996 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371997#if defined(OS_MACOSX)
1998 // Many plugins on the Mac have .plugin in the actual name, which looks
1999 // terrible, so look for that and strip it off if present.
2000 const std::wstring plugin_extension(L".plugin");
2001 if (EndsWith(plugin_name, plugin_extension, true))
2002 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2003#endif // OS_MACOSX
2004 }
[email protected]bf5c2ff392009-07-08 16:24:332005 }
[email protected]4a560ed2009-07-13 23:35:262006#else
2007 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2008#endif
[email protected]2ae8a922010-06-28 20:27:532009 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2010 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332011 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582012 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2013 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532014 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332015}
2016
2017void TabContents::OnCrashedWorker() {
2018 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582019 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422020 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332021}
2022
2023void TabContents::OnDidGetApplicationInfo(
2024 int32 page_id,
2025 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512026 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332027
[email protected]ed5431872009-11-17 08:39:512028 if (delegate())
2029 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332030}
2031
[email protected]851b1eb2010-08-09 13:32:292032void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2033 const GURL& update_url) {
2034 new DisabledPluginInfoBar(this, name, update_url);
2035}
2036
[email protected]a2cf65eb2010-01-18 08:20:382037void TabContents::OnPageContents(const GURL& url,
2038 int renderer_process_id,
2039 int32 page_id,
[email protected]e5106202010-06-11 21:12:362040 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102041 const std::string& language,
2042 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382043 // Don't index any https pages. People generally don't want their bank
2044 // accounts, etc. indexed on their computer, especially since some of these
2045 // things are not marked cachable.
2046 // TODO(brettw) we may want to consider more elaborate heuristics such as
2047 // the cachability of the page. We may also want to consider subframes (this
2048 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272049 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2050 // content indexing for chromeos in some future releases.
2051#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382052 if (!url.SchemeIsSecure()) {
2053 Profile* p = profile();
2054 if (p && !p->IsOffTheRecord()) {
2055 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2056 if (hs)
2057 hs->SetPageContents(url, contents);
2058 }
2059 }
[email protected]ccd40a52010-05-11 16:15:272060#endif
[email protected]a8a81292010-01-21 00:32:452061
[email protected]1c57b7b2010-07-12 17:38:102062 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452063
2064 std::string lang = language;
2065 NotificationService::current()->Notify(
2066 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152067 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452068 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382069}
2070
[email protected]7e0831b2010-02-01 08:45:152071void TabContents::OnPageTranslated(int32 page_id,
2072 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162073 const std::string& translated_lang,
2074 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552075 language_state_.set_current_language(translated_lang);
2076 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162077 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152078 NotificationService::current()->Notify(
2079 NotificationType::PAGE_TRANSLATED,
2080 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162081 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152082}
2083
[email protected]bf5c2ff392009-07-08 16:24:332084void TabContents::DidStartProvisionalLoadForFrame(
2085 RenderViewHost* render_view_host,
2086 bool is_main_frame,
2087 const GURL& url) {
2088 ProvisionalLoadDetails details(is_main_frame,
2089 controller_.IsURLInPageNavigation(url),
2090 url, std::string(), false);
2091 NotificationService::current()->Notify(
2092 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2093 Source<NavigationController>(&controller_),
2094 Details<ProvisionalLoadDetails>(&details));
[email protected]da4f8a12010-08-19 08:33:412095 if (is_main_frame)
2096 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]bf5c2ff392009-07-08 16:24:332097}
2098
2099void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202100 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332101 NotificationService::current()->Notify(
2102 NotificationType::RESOURCE_RESPONSE_STARTED,
2103 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202104 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332105}
2106
[email protected]3dbb80b2010-02-09 22:41:202107void TabContents::DidRedirectResource(
2108 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332109 NotificationService::current()->Notify(
2110 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2111 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202112 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332113}
2114
2115void TabContents::DidLoadResourceFromMemoryCache(
2116 const GURL& url,
2117 const std::string& frame_origin,
2118 const std::string& main_frame_origin,
2119 const std::string& security_info) {
2120 // Send out a notification that we loaded a resource from our memory cache.
[email protected]fc7de492010-07-12 14:49:042121 int cert_id = 0, cert_status = 0, security_bits = 0, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332122 SSLManager::DeserializeSecurityInfo(security_info,
2123 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042124 &security_bits,
2125 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332126 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162127 GetRenderProcessHost()->id(), cert_id,
2128 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332129
2130 NotificationService::current()->Notify(
2131 NotificationType::LOAD_FROM_MEMORY_CACHE,
2132 Source<NavigationController>(&controller_),
2133 Details<LoadFromMemoryCacheDetails>(&details));
2134}
2135
[email protected]e3d60e5d2009-09-25 21:08:292136void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472137 displayed_insecure_content_ = true;
2138 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292139}
2140
2141void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592142 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292143}
2144
[email protected]bf5c2ff392009-07-08 16:24:332145void TabContents::DidFailProvisionalLoadWithError(
2146 RenderViewHost* render_view_host,
2147 bool is_main_frame,
2148 int error_code,
2149 const GURL& url,
2150 bool showing_repost_interstitial) {
2151 if (net::ERR_ABORTED == error_code) {
2152 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2153 // This means that the interstitial won't be torn down properly, which is
2154 // bad. But if we have an interstitial, go back to another tab type, and
2155 // then load the same interstitial again, we could end up getting the first
2156 // interstitial's "failed" message (as a result of the cancel) when we're on
2157 // the second one.
2158 //
2159 // We can't tell this apart, so we think we're tearing down the current page
2160 // which will cause a crash later one. There is also some code in
2161 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2162 // out because of this problem.
2163 //
2164 // http://code.google.com/p/chromium/issues/detail?id=2855
2165 // Because this will not tear down the interstitial properly, if "back" is
2166 // back to another tab type, the interstitial will still be somewhat alive
2167 // in the previous tab type. If you navigate somewhere that activates the
2168 // tab with the interstitial again, you'll see a flash before the new load
2169 // commits of the interstitial page.
2170 if (showing_interstitial_page()) {
2171 LOG(WARNING) << "Discarding message during interstitial.";
2172 return;
2173 }
2174
2175 // This will discard our pending entry if we cancelled the load (e.g., if we
2176 // decided to download the file instead of load it). Only discard the
2177 // pending entry if the URLs match, otherwise the user initiated a navigate
2178 // before the page loaded so that the discard would discard the wrong entry.
2179 NavigationEntry* pending_entry = controller_.pending_entry();
2180 if (pending_entry && pending_entry->url() == url) {
2181 controller_.DiscardNonCommittedEntries();
2182 // Update the URL display.
2183 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2184 }
2185
2186 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2187 }
2188
2189 // Send out a notification that we failed a provisional load with an error.
2190 ProvisionalLoadDetails details(is_main_frame,
2191 controller_.IsURLInPageNavigation(url),
2192 url, std::string(), false);
2193 details.set_error_code(error_code);
2194
2195 NotificationService::current()->Notify(
2196 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2197 Source<NavigationController>(&controller_),
2198 Details<ProvisionalLoadDetails>(&details));
2199}
2200
2201void TabContents::DocumentLoadedInFrame() {
2202 controller_.DocumentLoadedInFrame();
2203}
2204
[email protected]dcd5b332010-08-11 08:55:182205void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562206 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242207 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562208}
2209
[email protected]8d3347f2009-07-09 22:00:212210RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322211 return view_.get();
2212}
2213
[email protected]8d3347f2009-07-09 22:00:212214RenderViewHostDelegate::RendererManagement*
2215TabContents::GetRendererManagementDelegate() {
2216 return &render_manager_;
2217}
2218
[email protected]bf5c2ff392009-07-08 16:24:332219RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212220 TabContents::GetBrowserIntegrationDelegate() {
2221 return this;
[email protected]bf5c2ff392009-07-08 16:24:332222}
2223
[email protected]8d3347f2009-07-09 22:00:212224RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2225 return this;
[email protected]bf5c2ff392009-07-08 16:24:332226}
2227
[email protected]46ba9082010-06-22 10:00:582228RenderViewHostDelegate::ContentSettings*
2229TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552230 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582231}
2232
[email protected]8d3347f2009-07-09 22:00:212233RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322234 return save_package_.get(); // May be NULL, but we can return NULL.
2235}
2236
[email protected]8d3347f2009-07-09 22:00:212237RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092238 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212239}
2240
2241RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2242 return &fav_icon_helper_;
2243}
2244
[email protected]e8dbd674b2010-03-11 18:34:402245RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452246 if (autocomplete_history_manager_.get() == NULL)
2247 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2248 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332249}
2250
[email protected]21674df2009-10-28 19:51:212251RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342252 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212253}
2254
[email protected]aad51d1c2010-08-05 08:38:092255RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2256 if (blocked_plugin_manager_.get() == NULL)
2257 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2258 return blocked_plugin_manager_.get();
2259}
2260
[email protected]1f18184a2010-07-21 19:34:492261RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2262 return GetSSLHelper();
2263}
2264
[email protected]b5977a0c2010-08-24 19:46:262265RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2266 if (file_select_helper_.get() == NULL)
2267 file_select_helper_.reset(new TabContentsFileSelectHelper(this));
2268 return file_select_helper_.get();
2269}
2270
[email protected]fd571bb2010-03-19 01:23:542271AutomationResourceRoutingDelegate*
2272TabContents::GetAutomationResourceRoutingDelegate() {
2273 return delegate();
2274}
2275
[email protected]ced90ae12010-02-20 02:06:162276RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2277 return bookmark_drag_;
2278}
2279
2280void TabContents::SetBookmarkDragDelegate(
2281 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2282 bookmark_drag_ = bookmark_drag;
2283}
2284
[email protected]9fb83e82010-07-02 18:24:552285TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2286 return content_settings_delegate_.get();
2287}
2288
[email protected]93623c5d2009-12-10 21:40:322289RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462290 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512291}
2292
[email protected]57c6a652009-05-04 07:58:342293TabContents* TabContents::GetAsTabContents() {
2294 return this;
2295}
2296
[email protected]7b291f92009-08-14 05:43:532297ViewType::Type TabContents::GetRenderViewType() const {
2298 return ViewType::TAB_CONTENTS;
2299}
2300
2301int TabContents::GetBrowserWindowID() const {
2302 return controller().window_id().id();
2303}
2304
[email protected]420ae012009-04-24 05:16:322305void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062306 NotificationService::current()->Notify(
2307 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2308 Source<TabContents>(this),
2309 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322310 NavigationEntry* entry = controller_.GetActiveEntry();
2311 if (!entry)
2312 return;
2313
2314 // When we're creating views, we're still doing initial setup, so we always
2315 // use the pending DOM UI rather than any possibly existing committed one.
2316 if (render_manager_.pending_dom_ui()) {
2317 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2318 }
2319
2320 if (entry->IsViewSourceMode()) {
2321 // Put the renderer in view source mode.
2322 render_view_host->Send(
2323 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2324 }
[email protected]0666aef2009-05-13 19:48:082325
2326 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322327}
2328
2329void TabContents::RenderViewReady(RenderViewHost* rvh) {
2330 if (rvh != render_view_host()) {
2331 // Don't notify the world, since this came from a renderer in the
2332 // background.
2333 return;
2334 }
2335
2336 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302337 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322338 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302339
2340 // Restore the focus to the tab (otherwise the focus will be on the top
2341 // window).
2342 if (was_crashed && !FocusLocationBarByDefault())
2343 Focus();
[email protected]420ae012009-04-24 05:16:322344}
2345
2346void TabContents::RenderViewGone(RenderViewHost* rvh) {
2347 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092348 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322349 return;
2350 if (rvh != render_view_host()) {
2351 // The pending page's RenderViewHost is gone.
2352 return;
2353 }
2354
2355 SetIsLoading(false, NULL);
2356 NotifyDisconnected();
2357 SetIsCrashed(true);
2358
[email protected]ff9efc62010-02-18 22:10:542359 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212360 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542361 RemoveInfoBar(GetInfoBarDelegateAt(i));
2362
[email protected]8e537302009-06-10 21:19:582363 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552364 // Only do this if we're not in browser shutdown, so that TabContents
2365 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2366 // visible do not flash a sad tab page.
2367 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2368 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322369
2370 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002371 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322372}
2373
[email protected]2e4633c2009-07-09 16:58:062374void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2375 NotificationService::current()->Notify(
2376 NotificationType::RENDER_VIEW_HOST_DELETED,
2377 Source<TabContents>(this),
2378 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482379 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062380}
2381
[email protected]420ae012009-04-24 05:16:322382void TabContents::DidNavigate(RenderViewHost* rvh,
2383 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372384 int extra_invalidate_flags = 0;
2385
2386 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352387 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372388
[email protected]420ae012009-04-24 05:16:322389 render_manager_.DidNavigateMainFrame(rvh);
2390
[email protected]20ede072009-10-06 00:28:352391 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372392 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372393 }
2394
[email protected]420ae012009-04-24 05:16:322395 // Update the site of the SiteInstance if it doesn't have one yet.
2396 if (!GetSiteInstance()->has_site())
2397 GetSiteInstance()->SetSite(params.url);
2398
2399 // Need to update MIME type here because it's referred to in
2400 // UpdateNavigationCommands() called by RendererDidNavigate() to
2401 // determine whether or not to enable the encoding menu.
2402 // It's updated only for the main frame. For a subframe,
2403 // RenderView::UpdateURL does not set params.contents_mime_type.
2404 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2405 // TODO(jungshik): Add a test for the encoding menu to avoid
2406 // regressing it again.
2407 if (PageTransition::IsMainFrame(params.transition))
2408 contents_mime_type_ = params.contents_mime_type;
2409
2410 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372411 bool did_navigate = controller_.RendererDidNavigate(
2412 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392413
2414 // Update history. Note that this needs to happen after the entry is complete,
2415 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352416 if (params.should_update_history &&
2417 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392418 // Most of the time, the displayURL matches the loaded URL, but for about:
2419 // URLs, we use a data: URL as the real value. We actually want to save
2420 // the about: URL to the history db and keep the data: URL hidden. This is
2421 // what the TabContents' URL getter does.
2422 UpdateHistoryForNavigation(GetURL(), details, params);
2423 }
2424
[email protected]76543b92009-08-31 17:27:452425 if (!did_navigate)
2426 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322427
2428 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2429 // for the appropriate notification (best) or you can add it to
2430 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2431 // necessary, please).
2432
2433 // Run post-commit tasks.
2434 if (details.is_main_frame)
2435 DidNavigateMainFramePostCommit(details, params);
2436 DidNavigateAnyFramePostCommit(rvh, details, params);
2437}
2438
2439void TabContents::UpdateState(RenderViewHost* rvh,
2440 int32 page_id,
2441 const std::string& state) {
2442 DCHECK(rvh == render_view_host());
2443
2444 // We must be prepared to handle state updates for any page, these occur
2445 // when the user is scrolling and entering form data, as well as when we're
2446 // leaving a page, in which case our state may have already been moved to
2447 // the next page. The navigation controller will look up the appropriate
2448 // NavigationEntry and update it when it is notified via the delegate.
2449
2450 int entry_index = controller_.GetEntryIndexWithPageID(
2451 GetSiteInstance(), page_id);
2452 if (entry_index < 0)
2453 return;
2454 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2455
2456 if (state == entry->content_state())
2457 return; // Nothing to update.
2458 entry->set_content_state(state);
2459 controller_.NotifyEntryChanged(entry, entry_index);
2460}
2461
2462void TabContents::UpdateTitle(RenderViewHost* rvh,
2463 int32 page_id, const std::wstring& title) {
2464 // If we have a title, that's a pretty good indication that we've started
2465 // getting useful data.
2466 SetNotWaitingForResponse();
2467
2468 DCHECK(rvh == render_view_host());
2469 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2470 page_id);
2471 if (!entry || !UpdateTitleForEntry(entry, title))
2472 return;
2473
2474 // Broadcast notifications when the UI should be updated.
2475 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032476 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322477}
2478
[email protected]420ae012009-04-24 05:16:322479void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402480 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322481 set_encoding(encoding);
2482}
2483
2484void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2485 if (delegate())
2486 delegate()->UpdateTargetURL(this, url);
2487}
2488
2489void TabContents::UpdateThumbnail(const GURL& url,
2490 const SkBitmap& bitmap,
2491 const ThumbnailScore& score) {
2492 // Tell History about this thumbnail
[email protected]9ba208092010-08-10 20:02:082493 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492494 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422495 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282496 } else {
2497 HistoryService* hs;
2498 if (!profile()->IsOffTheRecord() &&
2499 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2500 hs->SetPageThumbnail(url, bitmap, score);
2501 }
[email protected]420ae012009-04-24 05:16:322502 }
2503}
2504
[email protected]c4e98902010-06-01 10:20:142505void TabContents::UpdateInspectorSetting(const std::string& key,
2506 const std::string& value) {
2507 DictionaryValue* inspector_settings =
2508 profile()->GetPrefs()->GetMutableDictionary(
2509 prefs::kWebKitInspectorSettings);
[email protected]8b6e84a2010-08-14 03:32:172510 inspector_settings->SetWithoutPathExpansion(key,
[email protected]628cf5a52010-06-07 14:25:332511 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082512}
2513
[email protected]45aafc92010-06-07 14:18:532514void TabContents::ClearInspectorSettings() {
2515 DictionaryValue* inspector_settings =
2516 profile()->GetPrefs()->GetMutableDictionary(
2517 prefs::kWebKitInspectorSettings);
2518 inspector_settings->Clear();
2519}
2520
[email protected]420ae012009-04-24 05:16:322521void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292522 // The UI may be in an event-tracking loop, such as between the
2523 // mouse-down and mouse-up in text selection or a button click.
2524 // Defer the close until after tracking is complete, so that we
2525 // don't free objects out from under the UI.
2526 // TODO(shess): This could probably be integrated with the
2527 // IsDoingDrag() test below. Punting for now because I need more
2528 // research to understand how this impacts platforms other than Mac.
2529 // TODO(shess): This could get more fine-grained. For instance,
2530 // closing a tab in another window while selecting text in the
2531 // current window's Omnibox should be just fine.
2532 if (view()->IsEventTracking()) {
2533 view()->CloseTabAfterEventTracking();
2534 return;
2535 }
2536
[email protected]24a4d1062009-07-10 23:10:422537 // If we close the tab while we're in the middle of a drag, we'll crash.
2538 // Instead, cancel the drag and close it as soon as the drag ends.
2539 if (view()->IsDoingDrag()) {
2540 view()->CancelDragAndCloseTab();
2541 return;
2542 }
2543
[email protected]420ae012009-04-24 05:16:322544 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2545 if (delegate() && rvh == render_view_host())
2546 delegate()->CloseContents(this);
2547}
2548
2549void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2550 if (delegate() && delegate()->IsPopup(this))
2551 delegate()->MoveContents(this, new_bounds);
2552}
2553
[email protected]7ab1e7d62009-10-14 23:32:012554void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382555 // By default, we assume that the content is not PDF. The renderer
2556 // will tell us if this is not the case.
2557 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322558 SetIsLoading(true, NULL);
2559}
2560
[email protected]7ab1e7d62009-10-14 23:32:012561void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322562 scoped_ptr<LoadNotificationDetails> details;
2563
2564 NavigationEntry* entry = controller_.GetActiveEntry();
2565 // An entry may not exist for a stop when loading an initial blank page or
2566 // if an iframe injected by script into a blank page finishes loading.
2567 if (entry) {
[email protected]420ae012009-04-24 05:16:322568 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2569
2570 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542571 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322572 entry->transition_type(),
2573 elapsed,
2574 &controller_,
2575 controller_.GetCurrentEntryIndex()));
2576 }
2577
2578 // Tell PasswordManager we've finished a page load, which serves as a
2579 // green light to save pending passwords and reset itself.
2580 GetPasswordManager()->DidStopLoading();
2581
2582 SetIsLoading(false, details.get());
2583}
2584
[email protected]420ae012009-04-24 05:16:322585void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2586 const GURL& source_url,
2587 const GURL& target_url) {
2588 NavigationEntry* entry;
2589 if (page_id == -1)
2590 entry = controller_.pending_entry();
2591 else
2592 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2593 if (!entry || entry->url() != source_url)
2594 return;
2595 entry->set_url(target_url);
2596}
2597
[email protected]420ae012009-04-24 05:16:322598void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2599 WindowOpenDisposition disposition) {
2600 if (render_manager_.dom_ui()) {
2601 // When we're a DOM UI, it will provide a page transition type for us (this
2602 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2603 // generated suggestions).
2604 //
2605 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162606 // want web sites to see a referrer of "chrome://blah" (and some
2607 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322608 // send to the site), so we send no referrer.
2609 OpenURL(url, GURL(), disposition,
2610 render_manager_.dom_ui()->link_transition_type());
2611 } else {
2612 OpenURL(url, referrer, disposition, PageTransition::LINK);
2613 }
2614}
2615
[email protected]1ee614862009-07-06 20:29:182616void TabContents::DomOperationResponse(const std::string& json_string,
2617 int automation_id) {
2618}
2619
[email protected]8b8e7c92010-08-19 18:05:562620void TabContents::ProcessDOMUIMessage(
2621 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322622 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442623 // This can happen if someone uses window.open() to open an extension URL
2624 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562625 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322626 return;
2627 }
[email protected]8b8e7c92010-08-19 18:05:562628 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322629}
2630
2631void TabContents::ProcessExternalHostMessage(const std::string& message,
2632 const std::string& origin,
2633 const std::string& target) {
2634 if (delegate())
2635 delegate()->ForwardMessageToExternalHost(message, origin, target);
2636}
2637
[email protected]420ae012009-04-24 05:16:322638void TabContents::RunJavaScriptMessage(
2639 const std::wstring& message,
2640 const std::wstring& default_prompt,
2641 const GURL& frame_url,
2642 const int flags,
2643 IPC::Message* reply_msg,
2644 bool* did_suppress_message) {
2645 // Suppress javascript messages when requested and when inside a constrained
2646 // popup window (because that activates them and breaks them out of the
2647 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552648 // Also suppress messages when showing an interstitial. The interstitial is
2649 // shown over the previous page, we don't want the hidden page dialogs to
2650 // interfere with the interstitial.
2651 bool suppress_this_message = suppress_javascript_messages_ ||
2652 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322653 if (delegate())
2654 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312655 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322656
2657 *did_suppress_message = suppress_this_message;
2658
2659 if (!suppress_this_message) {
2660 base::TimeDelta time_since_last_message(
2661 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2662 bool show_suppress_checkbox = false;
2663 // Show a checkbox offering to suppress further messages if this message is
2664 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2665 if (time_since_last_message <
2666 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2667 show_suppress_checkbox = true;
2668
[email protected]d82ed61e2009-06-16 02:46:222669 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322670 show_suppress_checkbox, reply_msg);
2671 } else {
2672 // If we are suppressing messages, just reply as is if the user immediately
2673 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542674 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322675 }
2676}
2677
2678void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2679 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012680 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222681 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322682}
2683
2684void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2685 const std::string& json_arguments,
2686 IPC::Message* reply_msg) {
2687 if (delegate()) {
2688 HtmlDialogUIDelegate* dialog_delegate =
2689 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222690 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322691 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2692 }
2693}
2694
[email protected]4d44a1c2010-04-28 19:20:412695void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562696 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412697 GetPasswordManager()->PasswordFormsFound(forms);
2698}
2699
2700void TabContents::PasswordFormsVisible(
2701 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2702 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322703}
2704
[email protected]420ae012009-04-24 05:16:322705// Checks to see if we should generate a keyword based on the OSDD, and if
2706// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2707void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2708 int32 page_id, const GURL& url,
2709 bool autodetected) {
2710 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2711 DCHECK(url.is_valid());
2712 if (!IsActiveEntry(page_id))
2713 return;
2714 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2715 if (!url_model)
2716 return;
2717 if (!url_model->loaded()) {
2718 url_model->Load();
2719 return;
2720 }
2721 if (!profile()->GetTemplateURLFetcher())
2722 return;
2723
2724 if (profile()->IsOffTheRecord())
2725 return;
2726
2727 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2728 DCHECK(entry);
2729
2730 const NavigationEntry* base_entry = entry;
2731 if (IsFormSubmit(base_entry)) {
2732 // If the current page is a form submit, find the last page that was not
2733 // a form submit and use its url to generate the keyword from.
2734 int index = controller_.last_committed_entry_index() - 1;
2735 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2736 index--;
2737 if (index >= 0)
2738 base_entry = controller_.GetEntryAtIndex(index);
2739 else
2740 base_entry = NULL;
2741 }
2742
2743 // We want to use the user typed URL if available since that represents what
2744 // the user typed to get here, and fall back on the regular URL if not.
2745 if (!base_entry)
2746 return;
2747 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2748 base_entry->user_typed_url() : base_entry->url();
2749 if (!keyword_url.is_valid())
2750 return;
2751 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2752 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532753
2754 // For JS added OSDD empty keyword is OK because we will generate keyword
2755 // later from OSDD content.
2756 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322757 return;
2758 const TemplateURL* template_url =
2759 url_model->GetTemplateURLForKeyword(keyword);
2760 if (template_url && (!template_url->safe_for_autoreplace() ||
2761 template_url->originating_url() == url)) {
2762 // Either there is a user created TemplateURL for this keyword, or the
2763 // keyword has the same OSDD url and we've parsed it.
2764 return;
2765 }
2766
2767 // Download the OpenSearch description document. If this is successful a
2768 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322769 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2770 keyword,
2771 url,
2772 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162773 this,
[email protected]420ae012009-04-24 05:16:322774 autodetected);
2775}
2776
[email protected]420ae012009-04-24 05:16:322777GURL TabContents::GetAlternateErrorPageURL() const {
2778 GURL url;
2779 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2780 if (profile()->IsOffTheRecord())
2781 return url;
2782
2783 PrefService* prefs = profile()->GetPrefs();
2784 DCHECK(prefs);
2785 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152786 url = google_util::AppendGoogleLocaleParam(
2787 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322788 url = google_util::AppendGoogleTLDParam(url);
2789 }
2790 return url;
2791}
2792
2793WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062794 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552795 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062796 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322797}
2798
[email protected]fa1cf0b82010-01-15 21:49:442799void TabContents::OnIgnoredUIEvent() {
2800 if (constrained_window_count()) {
2801 ConstrainedWindow* window = *constrained_window_begin();
2802 window->FocusConstrainedWindow();
2803 }
2804}
2805
[email protected]420ae012009-04-24 05:16:322806void TabContents::OnJSOutOfMemory() {
2807 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582808 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2809 NULL, true));
[email protected]420ae012009-04-24 05:16:322810}
2811
[email protected]420ae012009-04-24 05:16:322812void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2813 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342814 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322815 // delivered to a pending RenderViewHost. We must first run the onunload
2816 // handler of the old RenderViewHost before we can allow it to proceed.
2817 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2818 new_request_id);
2819}
2820
[email protected]420ae012009-04-24 05:16:322821gfx::Rect TabContents::GetRootWindowResizerRect() const {
2822 if (delegate())
2823 return delegate()->GetRootWindowResizerRect();
2824 return gfx::Rect();
2825}
2826
2827void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2828 bool is_during_unload) {
2829 if (is_during_unload) {
2830 // Hang occurred while firing the beforeunload/unload handler.
2831 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112832 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322833
2834 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2835 return;
2836
2837 // If the tab hangs in the beforeunload/unload handler there's really
2838 // nothing we can do to recover. Pretend the unload listeners have
2839 // all fired and close the tab. If the hang is in the beforeunload handler
2840 // then the user will not have the option of cancelling the close.
2841 Close(rvh);
2842 return;
2843 }
2844
2845 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002846 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322847}
2848
2849void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002850 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322851}
2852
2853void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562854 net::LoadState load_state,
2855 uint64 upload_position,
2856 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322857 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562858 upload_position_ = upload_position;
2859 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292860 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192861 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292862 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532863 load_state_host_ =
2864 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322865 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2866 SetNotWaitingForResponse();
2867 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502868 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322869}
2870
[email protected]1ee614862009-07-06 20:29:182871bool TabContents::IsExternalTabContainer() const {
2872 if (!delegate())
2873 return false;
2874
2875 return delegate()->IsExternalTabContainer();
2876}
2877
[email protected]1ee614862009-07-06 20:29:182878void TabContents::DidInsertCSS() {
2879 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322880}
2881
[email protected]130efb02009-09-18 18:54:352882void TabContents::FocusedNodeChanged() {
2883 NotificationService::current()->Notify(
2884 NotificationType::FOCUS_CHANGED_IN_PAGE,
2885 Source<RenderViewHost>(render_view_host()),
2886 NotificationService::NoDetails());
2887}
2888
[email protected]ebf40a72010-07-22 01:46:382889void TabContents::SetDisplayingPDFContent() {
2890 displaying_pdf_content_ = true;
2891 if (delegate())
2892 delegate()->ContentTypeChanged(this);
2893}
2894
[email protected]420ae012009-04-24 05:16:322895void TabContents::BeforeUnloadFiredFromRenderManager(
2896 bool proceed,
2897 bool* proceed_to_fire_unload) {
2898 if (delegate())
2899 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2900}
2901
[email protected]3a3d47472010-07-15 21:03:542902void TabContents::DidStartLoadingFromRenderManager(
2903 RenderViewHost* render_view_host) {
2904 DidStartLoading();
2905}
2906
2907void TabContents::RenderViewGoneFromRenderManager(
2908 RenderViewHost* render_view_host) {
2909 RenderViewGone(render_view_host);
2910}
2911
[email protected]420ae012009-04-24 05:16:322912void TabContents::UpdateRenderViewSizeForRenderManager() {
2913 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262914 gfx::Size size = view_->GetContainerSize();
2915 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2916 // here during container initialization and normal window size will be set
2917 // later. In case of tab duplication this resizing to 0x0 prevents setting
2918 // normal size later so just ignore it.
2919 if (!size.IsEmpty())
2920 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322921}
2922
[email protected]3a3d47472010-07-15 21:03:542923void TabContents::NotifySwappedFromRenderManager() {
2924 NotifySwapped();
2925}
2926
2927NavigationController& TabContents::GetControllerForRenderManager() {
2928 return controller();
2929}
2930
[email protected]420ae012009-04-24 05:16:322931DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222932 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322933}
2934
2935NavigationEntry*
2936TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2937 return controller_.GetLastCommittedEntry();
2938}
2939
2940bool TabContents::CreateRenderViewForRenderManager(
2941 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322942 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522943
[email protected]674b3822010-08-04 04:02:512944 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322945 return false;
2946
2947 // Now that the RenderView has been created, we need to tell it its size.
2948 rwh_view->SetSize(view_->GetContainerSize());
2949
2950 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2951 render_view_host);
2952 return true;
2953}
2954
2955void TabContents::Observe(NotificationType type,
2956 const NotificationSource& source,
2957 const NotificationDetails& details) {
2958 switch (type.value) {
2959 case NotificationType::BOOKMARK_MODEL_LOADED:
2960 // BookmarkModel finished loading, fall through to update starred state.
2961 case NotificationType::URLS_STARRED: {
2962 // Somewhere, a URL has been starred.
2963 // Ignore notifications for profiles other than our current one.
2964 Profile* source_profile = Source<Profile>(source).ptr();
2965 if (!source_profile || !source_profile->IsSameProfile(profile()))
2966 return;
2967
2968 UpdateStarredStateForCurrentURL();
2969 break;
2970 }
2971 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512972 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322973 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2974 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2975 UpdateAlternateErrorPageURL();
2976 } else if (*pref_name_in == prefs::kDefaultCharset ||
[email protected]57ecc4b2010-08-11 03:02:512977 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)
[email protected]420ae012009-04-24 05:16:322978 ) {
2979 UpdateWebPreferences();
2980 } else {
2981 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2982 }
2983 break;
2984 }
2985 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2986 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2987 break;
2988
2989 case NotificationType::NAV_ENTRY_COMMITTED: {
2990 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2991
2992 NavigationController::LoadCommittedDetails& committed_details =
2993 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2994 ExpireInfoBars(committed_details);
2995 break;
2996 }
2997
[email protected]d3ba77272009-09-03 00:06:092998#if defined(OS_LINUX)
2999 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543000 renderer_preferences_util::UpdateFromSystemSettings(
3001 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093002 render_view_host()->SyncRendererPrefs();
3003 break;
3004 }
3005#endif
3006
[email protected]6c32ce72010-03-08 05:18:063007 case NotificationType::USER_STYLE_SHEET_UPDATED:
3008 UpdateWebPreferences();
3009 break;
3010
[email protected]79580c62010-02-02 02:36:253011 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293012 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253013 settings_details(details);
[email protected]79580c62010-02-02 02:36:253014 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493015 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293016 if (entry)
[email protected]da0c8e92010-02-09 23:25:493017 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293018 if (settings_details.ptr()->update_all() ||
3019 settings_details.ptr()->pattern().Matches(entry_url)) {
3020 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233021 profile()->GetHostContentSettingsMap()->
3022 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253023 }
3024 break;
3025 }
3026
[email protected]e5adff72010-06-14 18:13:063027 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573028 break;
[email protected]a888b29e62010-04-01 13:38:573029
3030 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063031 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573032 break;
[email protected]a888b29e62010-04-01 13:38:573033
[email protected]420ae012009-04-24 05:16:323034 default:
3035 NOTREACHED();
3036 }
3037}
[email protected]aacd7cc2009-09-02 14:51:103038
[email protected]98aa0b52010-05-06 17:03:083039void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3040 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433041
[email protected]a888b29e62010-04-01 13:38:573042 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083043 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3044 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573045 extension,
3046 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3047 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3048 Extension::EXTENSION_ICON_SMALLISH),
3049 ImageLoadingTracker::CACHE);
3050 } else {
[email protected]98aa0b52010-05-06 17:03:083051 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573052 }
3053}
3054
3055Extension* TabContents::GetExtensionContaining(const GURL& url) {
3056 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3057 if (!extensions_service)
3058 return NULL;
3059
3060 Extension* extension = extensions_service->GetExtensionByURL(url);
3061 return extension ?
3062 extension : extensions_service->GetExtensionByWebExtent(url);
3063}
3064
[email protected]a888b29e62010-04-01 13:38:573065void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3066 int index) {
3067 if (image) {
[email protected]98aa0b52010-05-06 17:03:083068 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573069 NotifyNavigationStateChanged(INVALIDATE_TAB);
3070 }
3071}
3072
[email protected]beb440c2009-11-06 04:08:543073std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3074 bool is_alert) {
3075 if (!frame_url.has_host())
3076 return l10n_util::GetString(
3077 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3078 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3079
3080 // We really only want the scheme, hostname, and port.
3081 GURL::Replacements replacements;
3082 replacements.ClearUsername();
3083 replacements.ClearPassword();
3084 replacements.ClearPath();
3085 replacements.ClearQuery();
3086 replacements.ClearRef();
3087 GURL clean_url = frame_url.ReplaceComponents(replacements);
3088
3089 // TODO(brettw) it should be easier than this to do the correct language
3090 // handling without getting the accept language from the profile.
[email protected]70edb862010-08-18 16:23:183091 string16 base_address = WideToUTF16(gfx::ElideUrl(clean_url, gfx::Font(), 0,
3092 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages))));
[email protected]beb440c2009-11-06 04:08:543093 // Force URL to have LTR directionality.
[email protected]70edb862010-08-18 16:23:183094 base_address = base::i18n::GetDisplayStringInLTRDirectionality(base_address);
[email protected]beb440c2009-11-06 04:08:543095
[email protected]70edb862010-08-18 16:23:183096 return UTF16ToWide(l10n_util::GetStringFUTF16(
[email protected]beb440c2009-11-06 04:08:543097 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
[email protected]70edb862010-08-18 16:23:183098 base_address));
[email protected]beb440c2009-11-06 04:08:543099}
3100
3101gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3102 return view_->GetTopLevelNativeWindow();
3103}
3104
3105void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3106 bool success,
3107 const std::wstring& prompt) {
3108 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3109 if (is_showing_before_unload_dialog_ && !success) {
3110 // If a beforeunload dialog is canceled, we need to stop the throbber from
3111 // spinning, since we forced it to start spinning in Navigate.
3112 DidStopLoading();
3113
3114 tab_close_start_time_ = base::TimeTicks();
3115 }
3116 is_showing_before_unload_dialog_ = false;
3117 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3118}
3119
3120void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3121 set_suppress_javascript_messages(suppress_message_boxes);
3122}
3123
[email protected]3a3d47472010-07-15 21:03:543124TabContents* TabContents::AsTabContents() {
3125 return this;
3126}
3127
3128ExtensionHost* TabContents::AsExtensionHost() {
3129 return NULL;
3130}
3131
[email protected]41fc0322009-09-04 22:23:403132void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103133 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3134}
[email protected]f45d2a72010-03-08 23:28:353135
3136void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3137 app_icon_ = app_icon;
3138 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3139}
[email protected]ea68c06a2010-04-23 17:25:373140
3141// After a successful *new* login attempt, we take the PasswordFormManager in
3142// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3143// the user makes up their mind with the "save password" infobar. Note if the
3144// login is one we already know about, the end of the line is
3145// provisional_save_manager_ because we just update it on success and so such
3146// forms never end up in an infobar.
3147class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3148 public:
3149 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463150 PasswordFormManager* form_to_save)
3151 : ConfirmInfoBarDelegate(tab_contents),
3152 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583153 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373154
[email protected]d75aba1d2010-08-02 23:35:583155 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373156
[email protected]d75aba1d2010-08-02 23:35:583157 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373158 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463159 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583160 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373161 delete this;
3162 }
3163
[email protected]d75aba1d2010-08-02 23:35:583164 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3165
[email protected]e23d3a32010-08-13 19:39:583166 virtual string16 GetMessageText() const {
3167 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373168 }
3169
3170 virtual SkBitmap* GetIcon() const {
3171 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3172 IDR_INFOBAR_SAVE_PASSWORD);
3173 }
3174
3175 virtual int GetButtons() const {
3176 return BUTTON_OK | BUTTON_CANCEL;
3177 }
3178
[email protected]e23d3a32010-08-13 19:39:583179 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373180 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583181 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373182 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583183 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373184 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583185 return string16();
[email protected]ea68c06a2010-04-23 17:25:373186 }
3187
3188 virtual bool Accept() {
3189 DCHECK(form_to_save_.get());
3190 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583191 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373192 return true;
3193 }
3194
3195 virtual bool Cancel() {
3196 DCHECK(form_to_save_.get());
3197 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583198 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373199 return true;
3200 }
[email protected]d75aba1d2010-08-02 23:35:583201 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373202
3203 private:
3204 // The PasswordFormManager managing the form we're asking the user about,
3205 // and should update as per her decision.
3206 scoped_ptr<PasswordFormManager> form_to_save_;
3207
[email protected]12bb6822010-06-16 02:00:463208 // Used to track the results we get from the info bar.
3209 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583210 NO_RESPONSE = 0,
3211 REMEMBER_PASSWORD,
3212 DONT_REMEMBER_PASSWORD,
3213 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463214 };
3215 ResponseType infobar_response_;
3216
[email protected]ea68c06a2010-04-23 17:25:373217 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3218};
3219
3220void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163221 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373222 render_view_host()->FillPasswordForm(form_data);
3223}
3224
3225void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3226 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3227}
3228
3229Profile* TabContents::GetProfileForPasswordManager() {
3230 return profile();
3231}
3232
3233bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3234 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3235}