blob: 605b4586ce2b68ccc968cefbac44003f7ce42d1d [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]939856a2010-08-24 20:29:0291#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1892#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5493#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3794#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2695#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3296#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0697#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3798#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:3299#include "net/base/mime_util.h"
100#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29101#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32102#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18103#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03104#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00105
[email protected]420ae012009-04-24 05:16:32106// Cross-Site Navigations
107//
108// If a TabContents is told to navigate to a different web site (as determined
109// by SiteInstance), it will replace its current RenderViewHost with a new
110// RenderViewHost dedicated to the new SiteInstance. This works as follows:
111//
112// - Navigate determines whether the destination is cross-site, and if so,
113// it creates a pending_render_view_host_ and moves into the PENDING
114// RendererState.
115// - The pending RVH is "suspended," so that no navigation messages are sent to
116// its renderer until the onbeforeunload JavaScript handler has a chance to
117// run in the current RVH.
118// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
119// that it has a pending cross-site request. ResourceDispatcherHost will
120// check for this when the response arrives.
121// - The current RVH runs its onbeforeunload handler. If it returns false, we
122// cancel all the pending logic and go back to NORMAL. Otherwise we allow
123// the pending RVH to send the navigation request to its renderer.
124// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
125// checks CrossSiteRequestManager to see that the RVH responsible has a
126// pending cross-site request, and then installs a CrossSiteEventHandler.
127// - When RDH receives a response, the BufferedEventHandler determines whether
128// it is a download. If so, it sends a message to the new renderer causing
129// it to cancel the request, and the download proceeds in the download
130// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34131// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32132// doesn't affect any functionality.
133// - After RDH receives a response and determines that it is safe and not a
134// download, it pauses the response to first run the old page's onunload
135// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34136// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32137// to the current RVH.
138// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
139// the ResourceDispatcherHost, who unpauses the response. Data is then sent
140// to the pending RVH.
141// - The pending renderer sends a FrameNavigate message that invokes the
142// DidNavigate method. This replaces the current RVH with the
143// pending RVH and goes back to the NORMAL RendererState.
144
145namespace {
146
147// Amount of time we wait between when a key event is received and the renderer
148// is queried for its state and pushed to the NavigationEntry.
149const int kQueryStateDelay = 5000;
150
151const int kSyncWaitDelay = 40;
152
[email protected]304f8792009-08-19 21:28:09153#if defined(OS_CHROMEOS)
154// If a popup window is bigger than this fraction of the screen on chrome os,
155// turn it into a tab
156const float kMaxWidthFactor = 0.5;
157const float kMaxHeightFactor = 0.6;
158#endif
159
[email protected]420ae012009-04-24 05:16:32160// If another javascript message box is displayed within
161// kJavascriptMessageExpectedDelay of a previous javascript message box being
162// dismissed, display an option to suppress future message boxes from this
163// contents.
164const int kJavascriptMessageExpectedDelay = 1000;
165
[email protected]420ae012009-04-24 05:16:32166// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51167const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32168 prefs::kAlternateErrorPagesEnabled,
169 prefs::kWebKitJavaEnabled,
170 prefs::kWebKitJavascriptEnabled,
171 prefs::kWebKitLoadsImagesAutomatically,
172 prefs::kWebKitPluginsEnabled,
173 prefs::kWebKitUsesUniversalDetector,
174 prefs::kWebKitSerifFontFamily,
175 prefs::kWebKitSansSerifFontFamily,
176 prefs::kWebKitFixedFontFamily,
177 prefs::kWebKitDefaultFontSize,
178 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36179 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32180 prefs::kDefaultCharset
181 // kWebKitStandardFontIsSerif needs to be added
182 // if we let users pick which font to use, serif or sans-serif when
183 // no font is specified or a CSS generic family (serif or sans-serif)
184 // is not specified.
185};
186
187const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
188
[email protected]420ae012009-04-24 05:16:32189// Returns true if the entry's transition type is FORM_SUBMIT.
190bool IsFormSubmit(const NavigationEntry* entry) {
191 return (PageTransition::StripQualifier(entry->transition_type()) ==
192 PageTransition::FORM_SUBMIT);
193}
194
195#if defined(OS_WIN)
196
197BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
198 // Note: erase is required to properly paint some widgets borders. This can
199 // be seen with textfields.
200 InvalidateRect(hwnd, NULL, TRUE);
201 return TRUE;
202}
203#endif
204
[email protected]5e369672009-11-03 23:48:30205ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16206 Profile* profile, const NavigationEntry& entry,
207 NavigationController::ReloadType reload_type) {
208 switch (reload_type) {
209 case NavigationController::RELOAD:
210 return ViewMsg_Navigate_Params::RELOAD;
211 case NavigationController::RELOAD_IGNORING_CACHE:
212 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
213 case NavigationController::NO_RELOAD:
214 break; // Fall through to rest of function.
215 }
[email protected]5e369672009-11-03 23:48:30216
217 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
218 profile->DidLastSessionExitCleanly())
219 return ViewMsg_Navigate_Params::RESTORE;
220
221 return ViewMsg_Navigate_Params::NORMAL;
222}
223
[email protected]3cc72b12010-03-18 23:03:00224void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16225 NavigationController::ReloadType reload_type,
226 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00227 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34228 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00229 params->pending_history_list_offset = controller.pending_entry_index();
230 params->current_history_list_offset = controller.last_committed_entry_index();
231 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34232 params->url = entry.url();
233 params->referrer = entry.referrer();
234 params->transition = entry.transition_type();
235 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00236 params->navigation_type =
237 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34238 params->request_time = base::Time::Now();
239}
240
[email protected]851b1eb2010-08-09 13:32:29241class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
242 public:
243 DisabledPluginInfoBar(TabContents* tab_contents,
244 const string16& name,
245 const GURL& update_url)
246 : ConfirmInfoBarDelegate(tab_contents),
247 tab_contents_(tab_contents),
248 name_(name),
249 update_url_(update_url) {
250 tab_contents->AddInfoBar(this);
251 }
252
253 virtual int GetButtons() const {
254 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
255 }
256
[email protected]e23d3a32010-08-13 19:39:58257 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29258 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58259 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29260 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58261 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29262 return ConfirmInfoBarDelegate::GetButtonLabel(button);
263 }
264
[email protected]e23d3a32010-08-13 19:39:58265 virtual string16 GetMessageText() const {
266 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29267 }
268
[email protected]e23d3a32010-08-13 19:39:58269 virtual string16 GetLinkText() {
270 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29271 }
272
273 virtual SkBitmap* GetIcon() const {
274 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
275 IDR_INFOBAR_PLUGIN_INSTALL);
276 }
277
278 virtual bool Accept() {
279 tab_contents_->OpenURL(update_url_, GURL(),
280 CURRENT_TAB, PageTransition::LINK);
281 return false;
282 }
283
284 virtual bool Cancel() {
285 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
286 CURRENT_TAB, PageTransition::LINK);
287 return false;
288 }
289
290 virtual bool LinkClicked(WindowOpenDisposition disposition) {
291 // TODO(bauerb): Navigate to a help page explaining why we disabled
292 // the plugin, once we have one.
293 return false;
294 }
295
296 private:
297 TabContents* tab_contents_;
298 string16 name_;
299 GURL update_url_;
300};
301
[email protected]420ae012009-04-24 05:16:32302} // namespace
303
304// -----------------------------------------------------------------------------
305
[email protected]fdd61c62009-04-22 19:22:57306// static
307int TabContents::find_request_id_counter_ = -1;
308
[email protected]420ae012009-04-24 05:16:32309
[email protected]420ae012009-04-24 05:16:32310TabContents::TabContents(Profile* profile,
311 SiteInstance* site_instance,
312 int routing_id,
[email protected]34ac70502009-09-25 17:07:23313 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42314 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13315 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
316 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22317 TabContentsView::Create(this))),
318 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57319 property_bag_(),
320 registrar_(),
[email protected]12802702010-07-09 19:43:09321 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
322 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57323 save_package_(),
[email protected]6db0def92010-03-02 19:55:45324 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21325 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57326 password_manager_(),
327 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06328 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22329 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34330 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29331 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34332 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34333 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57334 current_load_start_(),
335 load_state_(net::LOAD_STATE_IDLE),
336 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56337 upload_size_(0),
338 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57339 received_page_title_(false),
340 is_starred_(false),
341 contents_mime_type_(),
342 encoding_(),
[email protected]332af7732009-03-11 13:21:35343 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49344 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47345 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57346 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57347 find_ui_active_(false),
348 find_op_aborted_(false),
349 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12350 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12351 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08352 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57353 capturing_contents_(false),
354 is_being_destroyed_(false),
355 notify_disconnection_(false),
356 history_requests_(),
357#if defined(OS_WIN)
358 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
359#endif
360 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44361 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01362 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54363 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54364 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16365 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38366 closed_by_user_gesture_(false),
367 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54368 renderer_preferences_util::UpdateFromSystemSettings(
369 &renderer_preferences_, profile);
370
[email protected]9fb83e82010-07-02 18:24:55371 content_settings_delegate_.reset(
372 new TabSpecificContentSettings(this, profile));
373
[email protected]16779842009-07-08 23:45:29374#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02375 // Make sure the thumbnailer is started before starting the render manager.
376 // The thumbnailer will want to listen for RVH creations, one of which will
377 // happen in RVHManager::Init.
378 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
379 if (generator)
380 generator->StartThumbnailing();
381#endif
382
[email protected]12636df2009-09-28 22:32:21383 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32384
[email protected]34ac70502009-09-25 17:07:23385 // We have the initial size of the view be based on the size of the passed in
386 // tab contents (normally a tab from the same window).
387 view_->CreateView(base_tab_contents ?
388 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32389
390 // Register for notifications about all interested prefs change.
391 PrefService* prefs = profile->GetPrefs();
392 if (prefs) {
393 for (int i = 0; i < kPrefsToObserveLength; ++i)
394 prefs->AddPrefObserver(kPrefsToObserve[i], this);
395 }
396
397 // Register for notifications about URL starredness changing on any profile.
398 registrar_.Add(this, NotificationType::URLS_STARRED,
399 NotificationService::AllSources());
400 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
401 NotificationService::AllSources());
402 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
403 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09404#if defined(OS_LINUX)
405 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
406 NotificationService::AllSources());
407#endif
[email protected]420ae012009-04-24 05:16:32408
[email protected]6c32ce72010-03-08 05:18:06409 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
410 NotificationService::AllSources());
411
[email protected]79580c62010-02-02 02:36:25412 // Register for notifications about content setting changes.
413 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
414 NotificationService::AllSources());
415
[email protected]a888b29e62010-04-01 13:38:57416 // Listen for extension changes so we can update extension_for_current_page_.
417 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
418 NotificationService::AllSources());
419 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
420 NotificationService::AllSources());
421 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
422 NotificationService::AllSources());
423
[email protected]c8865482009-07-23 20:40:10424 // Set-up the showing of the omnibox search infobar if applicable.
425 if (OmniboxSearchHint::IsEnabled(profile))
426 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]fd2b9ce2010-08-11 04:03:57427
428 if (MatchPreview::IsEnabled())
429 match_preview_.reset(new MatchPreview(this));
[email protected]332af7732009-03-11 13:21:35430}
initial.commit09911bf2008-07-26 23:55:29431
432TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32433 is_being_destroyed_ = true;
434
[email protected]bfe4c1582009-10-02 18:11:09435 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32436 registrar_.RemoveAll();
437
438 // Unregister the notifications of all observed prefs change.
439 PrefService* prefs = profile()->GetPrefs();
440 if (prefs) {
441 for (int i = 0; i < kPrefsToObserveLength; ++i)
442 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
443 }
444
[email protected]420ae012009-04-24 05:16:32445 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00446 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32447
[email protected]420ae012009-04-24 05:16:32448 // First cleanly close all child windows.
449 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
450 // some of these to close. CloseWindows is async, so it might get called
451 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49452 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32453
[email protected]8cc8d492010-02-02 10:40:49454 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13455 if (blocked_popups_)
456 blocked_popups_->Destroy();
457
[email protected]420ae012009-04-24 05:16:32458 // Notify any observer that have a reference on this tab contents.
459 NotificationService::current()->Notify(
460 NotificationType::TAB_CONTENTS_DESTROYED,
461 Source<TabContents>(this),
462 NotificationService::NoDetails());
463
[email protected]1e5e74f2009-05-27 20:55:12464 // Notify any lasting InfobarDelegates that have not yet been removed that
465 // whatever infobar they were handling in this TabContents has closed,
466 // because the TabContents is going away entirely.
467 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
468 // notification may trigger infobars calls that access their delegate. (and
469 // some implementations of InfoBarDelegate do delete themselves on
470 // InfoBarClosed()).
471 for (int i = 0; i < infobar_delegate_count(); ++i) {
472 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
473 delegate->InfoBarClosed();
474 }
475 infobar_delegates_.clear();
476
[email protected]420ae012009-04-24 05:16:32477 // TODO(brettw) this should be moved to the view.
478#if defined(OS_WIN)
479 // If we still have a window handle, destroy it. GetNativeView can return
480 // NULL if this contents was part of a window that closed.
481 if (GetNativeView())
482 ::DestroyWindow(GetNativeView());
483#endif
[email protected]7ab1e7d62009-10-14 23:32:01484
485 // OnCloseStarted isn't called in unit tests.
486 if (!tab_close_start_time_.is_null()) {
487 UMA_HISTOGRAM_TIMES("Tab.Close",
488 base::TimeTicks::Now() - tab_close_start_time_);
489 }
initial.commit09911bf2008-07-26 23:55:29490}
491
[email protected]d5f942ba2008-09-26 19:30:34492// static
493void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32494 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
495
496 WebPreferences pref_defaults;
497 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
498 pref_defaults.javascript_enabled);
499 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
500 pref_defaults.web_security_enabled);
501 prefs->RegisterBooleanPref(
502 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
503 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
504 pref_defaults.loads_images_automatically);
505 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
506 pref_defaults.plugins_enabled);
507 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
508 pref_defaults.dom_paste_enabled);
509 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
510 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14511 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32512 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
513 pref_defaults.text_areas_are_resizable);
514 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
515 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36516 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
517 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32518
519 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
520 IDS_ACCEPT_LANGUAGES);
521 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
522 IDS_DEFAULT_ENCODING);
523 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
524 IDS_STANDARD_FONT_IS_SERIF);
525 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
526 IDS_FIXED_FONT_FAMILY);
527 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
528 IDS_SERIF_FONT_FAMILY);
529 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
530 IDS_SANS_SERIF_FONT_FAMILY);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
532 IDS_CURSIVE_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
534 IDS_FANTASY_FONT_FAMILY);
535 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
536 IDS_DEFAULT_FONT_SIZE);
537 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
538 IDS_DEFAULT_FIXED_FONT_SIZE);
539 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
540 IDS_MINIMUM_FONT_SIZE);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
542 IDS_MINIMUM_LOGICAL_FONT_SIZE);
543 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
544 IDS_USES_UNIVERSAL_DETECTOR);
545 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
546 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29547}
548
[email protected]13367f72009-07-08 16:39:02549// Returns true if contains content rendered by an extension.
550bool TabContents::HostsExtension() const {
551 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34552}
553
[email protected]cf28ec52010-04-09 22:56:34554AutoFillManager* TabContents::GetAutoFillManager() {
555 if (autofill_manager_.get() == NULL)
556 autofill_manager_.reset(new AutoFillManager(this));
557 return autofill_manager_.get();
558}
559
[email protected]6e95706d2009-04-23 22:55:01560PasswordManager* TabContents::GetPasswordManager() {
561 if (password_manager_.get() == NULL)
562 password_manager_.reset(new PasswordManager(this));
563 return password_manager_.get();
564}
565
566PluginInstaller* TabContents::GetPluginInstaller() {
567 if (plugin_installer_.get() == NULL)
568 plugin_installer_.reset(new PluginInstaller(this));
569 return plugin_installer_.get();
570}
571
[email protected]1f18184a2010-07-21 19:34:49572TabContentsSSLHelper* TabContents::GetSSLHelper() {
573 if (ssl_helper_.get() == NULL)
574 ssl_helper_.reset(new TabContentsSSLHelper(this));
575 return ssl_helper_.get();
576}
577
[email protected]8cb5d5b2010-02-09 11:36:16578RenderProcessHost* TabContents::GetRenderProcessHost() const {
579 return render_manager_.current_host()->process();
580}
581
[email protected]98aa0b52010-05-06 17:03:08582void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46583 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08584 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10585
[email protected]98aa0b52010-05-06 17:03:08586 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57587
[email protected]fca656c2010-02-10 20:30:10588 NotificationService::current()->Notify(
589 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
590 Source<TabContents>(this),
591 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49592}
593
[email protected]98aa0b52010-05-06 17:03:08594void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
595 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40596 return;
597
598 ExtensionsService* extension_service = profile()->GetExtensionsService();
599 if (extension_service && extension_service->is_ready()) {
600 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08601 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40602 if (extension)
[email protected]98aa0b52010-05-06 17:03:08603 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40604 }
605}
606
[email protected]98aa0b52010-05-06 17:03:08607SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08608 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51609 return NULL;
610
[email protected]98aa0b52010-05-06 17:03:08611 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51612}
613
[email protected]d5f942ba2008-09-26 19:30:34614const GURL& TabContents::GetURL() const {
615 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57616 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54617 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34618}
619
[email protected]96d185d2009-04-24 03:28:54620const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55621 // Transient entries take precedence. They are used for interstitial pages
622 // that are shown on top of existing pages.
623 NavigationEntry* entry = controller_.GetTransientEntry();
624 if (entry)
625 return entry->GetTitleForDisplay(&controller_);
626
[email protected]96d185d2009-04-24 03:28:54627 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
628 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
629 if (our_dom_ui) {
630 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55631 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54632 if (!(entry && entry->IsViewSourceMode())) {
633 // Give the DOM UI the chance to override our title.
634 const string16& title = our_dom_ui->overridden_title();
635 if (!title.empty())
636 return title;
637 }
638 }
639
640 // We use the title for the last committed entry rather than a pending
641 // navigation entry. For example, when the user types in a URL, we want to
642 // keep the old page's title until the new load has committed and we get a new
643 // title.
[email protected]96d185d2009-04-24 03:28:54644 entry = controller_.GetLastCommittedEntry();
645 if (entry)
646 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54647 return EmptyString16();
648}
649
[email protected]bbbc1ef2010-02-12 18:03:41650// static
651string16 TabContents::GetDefaultTitle() {
652 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
653}
654
[email protected]d5f942ba2008-09-26 19:30:34655int32 TabContents::GetMaxPageID() {
656 if (GetSiteInstance())
657 return GetSiteInstance()->max_page_id();
658 else
659 return max_page_id_;
660}
661
662void TabContents::UpdateMaxPageID(int32 page_id) {
663 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34664 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34665 // testing.
666 if (GetSiteInstance())
667 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16668 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34669}
670
[email protected]96d185d2009-04-24 03:28:54671SiteInstance* TabContents::GetSiteInstance() const {
672 return render_manager_.current_host()->site_instance();
673}
674
[email protected]96d185d2009-04-24 03:28:54675bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15676 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54677 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15678 if (entry && (entry->IsViewSourceMode() ||
679 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54680 return true;
[email protected]8ab24cc2009-11-13 20:56:15681 }
[email protected]83e3895b2009-06-11 00:07:16682
[email protected]96d185d2009-04-24 03:28:54683 DOMUI* dom_ui = GetDOMUIForCurrentState();
684 if (dom_ui)
685 return !dom_ui->should_hide_url();
686 return true;
687}
688
[email protected]d5f942ba2008-09-26 19:30:34689SkBitmap TabContents::GetFavIcon() const {
690 // Like GetTitle(), we also want to use the favicon for the last committed
691 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57692 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47693 if (entry)
694 return entry->favicon().bitmap();
695
[email protected]ce3fa3c2009-04-20 19:55:57696 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34697 if (entry)
698 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34699 return SkBitmap();
700}
701
[email protected]0b303cc2009-09-28 22:35:15702bool TabContents::FavIconIsValid() const {
703 NavigationEntry* entry = controller_.GetTransientEntry();
704 if (entry)
705 return entry->favicon().is_valid();
706
707 entry = controller_.GetLastCommittedEntry();
708 if (entry)
709 return entry->favicon().is_valid();
710
711 return false;
712}
713
[email protected]96d185d2009-04-24 03:28:54714bool TabContents::ShouldDisplayFavIcon() {
715 // Always display a throbber during pending loads.
716 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
717 return true;
718
719 DOMUI* dom_ui = GetDOMUIForCurrentState();
720 if (dom_ui)
721 return !dom_ui->hide_favicon();
722 return true;
723}
724
[email protected]96d185d2009-04-24 03:28:54725std::wstring TabContents::GetStatusText() const {
726 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
727 return std::wstring();
728
729 switch (load_state_) {
730 case net::LOAD_STATE_WAITING_FOR_CACHE:
731 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04732 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
733 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54734 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
735 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
736 case net::LOAD_STATE_RESOLVING_HOST:
737 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
738 case net::LOAD_STATE_CONNECTING:
739 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06740 case net::LOAD_STATE_SSL_HANDSHAKE:
741 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54742 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56743 if (upload_size_)
744 return l10n_util::GetStringF(
745 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
746 static_cast<int>((100 * upload_position_) / upload_size_));
747 else
748 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54749 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
750 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
751 load_state_host_);
752 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
753 case net::LOAD_STATE_IDLE:
754 case net::LOAD_STATE_READING_RESPONSE:
755 break;
756 }
757
758 return std::wstring();
759}
760
[email protected]d5f942ba2008-09-26 19:30:34761void TabContents::SetIsCrashed(bool state) {
762 if (state == is_crashed_)
763 return;
764
765 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50766 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34767}
768
[email protected]744ef172009-10-16 21:53:46769void TabContents::PageActionStateChanged() {
770 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00771}
[email protected]ce5c4502009-05-06 16:46:11772
[email protected]d5f942ba2008-09-26 19:30:34773void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
774 if (delegate_)
775 delegate_->NavigationStateChanged(this, changed_flags);
776}
777
[email protected]96d185d2009-04-24 03:28:54778void TabContents::DidBecomeSelected() {
779 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16780 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
781 if (rwhv) {
782 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43783#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16784 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43785#endif
786 }
[email protected]96d185d2009-04-24 03:28:54787
[email protected]8cb5d5b2010-02-09 11:36:16788 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54789}
790
791void TabContents::WasHidden() {
792 if (!capturing_contents()) {
793 // |render_view_host()| can be NULL if the user middle clicks a link to open
794 // a tab in then background, then closes the tab before selecting it. This
795 // is because closing the tab calls TabContents::Destroy(), which removes
796 // the |render_view_host()|; then when we actually destroy the window,
797 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16798 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
799 if (rwhv)
800 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54801 }
802
803 NotificationService::current()->Notify(
804 NotificationType::TAB_CONTENTS_HIDDEN,
805 Source<TabContents>(this),
806 NotificationService::NoDetails());
807}
808
[email protected]d5f942ba2008-09-26 19:30:34809void TabContents::Activate() {
810 if (delegate_)
811 delegate_->ActivateContents(this);
812}
813
[email protected]ea42e7782010-08-23 23:58:12814void TabContents::Deactivate() {
815 if (delegate_)
816 delegate_->DeactivateContents(this);
817}
818
[email protected]96d185d2009-04-24 03:28:54819void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16820 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
821 if (rwhv)
822 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54823}
824
825void TabContents::HideContents() {
826 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
827 // our superclass HideContents(), because some callers want to be very picky
828 // about the order in which these get called. In addition to making the code
829 // here practically impossible to understand, this also means we end up
830 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34831 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54832 WasHidden();
833}
834
[email protected]c0588052008-10-27 23:01:50835void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34836 WindowOpenDisposition disposition,
837 PageTransition::Type transition) {
838 if (delegate_)
[email protected]c0588052008-10-27 23:01:50839 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34840}
841
[email protected]1ccb3568d2010-02-19 10:51:16842bool TabContents::NavigateToPendingEntry(
843 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54844 const NavigationEntry& entry = *controller_.pending_entry();
845
846 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
847 if (!dest_render_view_host)
848 return false; // Unable to create the desired render view host.
849
[email protected]770dd8b2010-05-24 18:11:39850 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
851 dest_render_view_host->EnablePreferredSizeChangedMode(
852 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
853 }
[email protected]9fb325e2010-05-06 18:23:24854
[email protected]0352e5472010-04-29 00:11:40855 // For security, we should never send non-DOM-UI URLs (other than about:blank)
856 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58857 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40858 bool is_allowed_in_dom_ui_renderer =
859 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
860 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58861 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40862 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58863
[email protected]96d185d2009-04-24 03:28:54864 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12865 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32866 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00867 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
868 dest_render_view_host,
869 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32870 }
[email protected]96d185d2009-04-24 03:28:54871
872 // Used for page load time metrics.
873 current_load_start_ = base::TimeTicks::Now();
874
875 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34876 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00877 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34878 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54879
880 if (entry.page_id() == -1) {
881 // HACK!! This code suppresses javascript: URLs from being added to
882 // session history, which is what we want to do for javascript: URLs that
883 // do not generate content. What we really need is a message from the
884 // renderer telling us that a new page was not created. The same message
885 // could be used for mailto: URLs and the like.
886 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
887 return false;
888 }
889
890 // Clear any provisional password saves - this stops password infobars
891 // showing up on pages the user navigates to while the right page is
892 // loading.
893 GetPasswordManager()->ClearProvisionalSave();
894
[email protected]1ccb3568d2010-02-19 10:51:16895 if (reload_type != NavigationController::NO_RELOAD &&
896 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48897 FaviconService* favicon_service =
898 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
899 if (favicon_service)
900 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54901 }
902
[email protected]d5f942ba2008-09-26 19:30:34903 return true;
904}
905
[email protected]96d185d2009-04-24 03:28:54906void TabContents::Stop() {
907 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09908 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54909}
910
[email protected]96d185d2009-04-24 03:28:54911void TabContents::DisassociateFromPopupCount() {
912 render_view_host()->DisassociateFromPopupCount();
913}
914
915TabContents* TabContents::Clone() {
916 // We create a new SiteInstance so that the new tab won't share processes
917 // with the old one. This can be changed in the future if we need it to share
918 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32919 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54920 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21921 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54922 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08923 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08924 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54925 return tc;
926}
927
[email protected]4d677202009-07-19 07:37:12928void TabContents::ShowPageInfo(const GURL& url,
929 const NavigationEntry::SSLStatus& ssl,
930 bool show_history) {
931 if (!delegate_)
932 return;
933
[email protected]bb678332009-07-21 00:15:50934 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12935}
936
initial.commit09911bf2008-07-26 23:55:29937ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28938 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29939 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28940 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29941 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44942
943 if (child_windows_.size() == 1) {
944 window->ShowConstrainedWindow();
945 BlockTabContent(true);
946 }
947
initial.commit09911bf2008-07-26 23:55:29948 return window;
949}
950
[email protected]fa1cf0b82010-01-15 21:49:44951void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55952 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
953 if (rwhv)
954 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44955 render_view_host()->set_ignore_input_events(blocked);
956 if (delegate_)
957 delegate_->SetTabContentBlocked(this, blocked);
958}
959
initial.commit09911bf2008-07-26 23:55:29960void TabContents::AddNewContents(TabContents* new_contents,
961 WindowOpenDisposition disposition,
962 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29963 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29964 if (!delegate_)
965 return;
966
[email protected]35f7d212009-04-29 21:19:27967 if ((disposition == NEW_POPUP) && !user_gesture &&
968 !CommandLine::ForCurrentProcess()->HasSwitch(
969 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22970 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31971 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29972 delegate_->GetConstrainingContents(this)->AddPopup(
973 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31974 } else {
[email protected]304f8792009-08-19 21:28:09975#if defined(OS_CHROMEOS)
976 if (disposition == NEW_POPUP) {
977 // If the popup is bigger than a given factor of the screen, then
978 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11979 // Also check for width or height == 0, which would otherwise indicate
980 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09981 GdkScreen* screen = gdk_screen_get_default();
982 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
983 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11984 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
985 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09986 disposition = NEW_FOREGROUND_TAB;
987 }
988 }
989#endif
990
[email protected]0aa55312008-10-17 21:53:08991 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29992 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
993 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49994 NotificationService::current()->Notify(
995 NotificationType::TAB_ADDED,
996 Source<TabContentsDelegate>(delegate_),
997 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29998 }
initial.commit09911bf2008-07-26 23:55:29999
[email protected]8cc8d492010-02-02 10:40:491000 // TODO(pkasting): Why is this necessary?
1001 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:291002}
1003
[email protected]bcd9dc42010-01-23 16:38:181004bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:201005 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:201006 bool is_js_code, const std::string& code_string,
1007 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511008 RenderViewHost* host = render_view_host();
1009 if (!host)
1010 return false;
1011
1012 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
1013 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
1014 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351015}
1016
[email protected]96d185d2009-04-24 03:28:541017void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491018 if (is_being_destroyed_)
1019 return;
[email protected]9fb83e82010-07-02 18:24:551020 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491021 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401022 render_view_host()->AllowScriptToClose(!visible);
[email protected]8e0bbf12010-07-20 00:03:431023 if (visible)
1024 PopupBlockedAnimation::Show(this);
[email protected]96d185d2009-04-24 03:28:541025}
1026
[email protected]5c9e97a2009-09-09 23:48:301027gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541028 return view_->GetContentNativeView();
1029}
1030
1031gfx::NativeView TabContents::GetNativeView() const {
1032 return view_->GetNativeView();
1033}
1034
1035void TabContents::GetContainerBounds(gfx::Rect *out) const {
1036 view_->GetContainerBounds(out);
1037}
1038
1039void TabContents::Focus() {
1040 view_->Focus();
1041}
1042
[email protected]90daadb42009-06-08 21:27:281043void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541044 if (showing_interstitial_page()) {
1045 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1046 return;
1047 }
[email protected]96d185d2009-04-24 03:28:541048 render_view_host()->SetInitialFocus(reverse);
1049}
1050
1051bool TabContents::FocusLocationBarByDefault() {
1052 DOMUI* dom_ui = GetDOMUIForCurrentState();
1053 if (dom_ui)
1054 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431055 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251056 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431057 return true;
[email protected]96d185d2009-04-24 03:28:541058 return false;
1059}
1060
[email protected]a26dc362010-04-23 01:48:581061void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381062 if (delegate())
[email protected]a26dc362010-04-23 01:48:581063 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381064}
1065
[email protected]616ed5a2008-11-21 22:27:241066void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321067 if (delegate_ && !delegate_->infobars_enabled()) {
1068 delegate->InfoBarClosed();
1069 return;
1070 }
1071
[email protected]616ed5a2008-11-21 22:27:241072 // Look through the existing InfoBarDelegates we have for a match. If we've
1073 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051074 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451075 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1076 // Tell the new infobar to close so that it can clean itself up.
1077 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241078 return;
[email protected]6d27a7b2009-12-18 23:25:451079 }
[email protected]616ed5a2008-11-21 22:27:241080 }
1081
1082 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561083 NotificationService::current()->Notify(
1084 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1085 Source<TabContents>(this),
1086 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241087
1088 // Add ourselves as an observer for navigations the first time a delegate is
1089 // added. We use this notification to expire InfoBars that need to expire on
1090 // page transitions.
1091 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561092 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571093 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241094 }
1095}
1096
1097void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321098 if (delegate_ && !delegate_->infobars_enabled()) {
1099 return;
1100 }
1101
[email protected]616ed5a2008-11-21 22:27:241102 std::vector<InfoBarDelegate*>::iterator it =
1103 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1104 if (it != infobar_delegates_.end()) {
1105 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561106 NotificationService::current()->Notify(
1107 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1108 Source<TabContents>(this),
1109 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241110
[email protected]cdadf6f2010-08-20 16:36:081111 // Just to be safe, make sure the delegate was not removed by an observer.
1112 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1113 if (it != infobar_delegates_.end()) {
1114 infobar_delegates_.erase(it);
1115 // Remove ourselves as an observer if we are tracking no more InfoBars.
1116 if (infobar_delegates_.empty()) {
1117 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1118 Source<NavigationController>(&controller_));
1119 }
1120 } else {
1121 // If you hit this NOTREACHED, please comment in bug
1122 // http://crbug.com/50428 how you got there.
1123 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031124 }
[email protected]616ed5a2008-11-21 22:27:241125 }
1126}
[email protected]3edd9522009-03-04 22:19:411127
[email protected]f81821c2009-08-07 01:29:471128void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1129 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321130 if (delegate_ && !delegate_->infobars_enabled()) {
1131 new_delegate->InfoBarClosed();
1132 return;
1133 }
1134
[email protected]f81821c2009-08-07 01:29:471135 std::vector<InfoBarDelegate*>::iterator it =
1136 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1137 DCHECK(it != infobar_delegates_.end());
1138
1139 // Notify the container about the change of plans.
1140 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1141 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1142 old_delegate, new_delegate));
1143 NotificationService::current()->Notify(
1144 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1145 Source<TabContents>(this),
1146 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1147
[email protected]cdadf6f2010-08-20 16:36:081148 // Just to be safe, make sure the delegate was not removed by an observer.
1149 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1150 if (it != infobar_delegates_.end()) {
1151 // Remove the old one.
1152 infobar_delegates_.erase(it);
1153 } else {
1154 // If you hit this NOTREACHED, please comment in bug
1155 // http://crbug.com/50428 how you got there.
1156 NOTREACHED();
1157 }
[email protected]f81821c2009-08-07 01:29:471158
1159 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081160 DCHECK(find(infobar_delegates_.begin(),
1161 infobar_delegates_.end(), new_delegate) ==
1162 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471163 infobar_delegates_.push_back(new_delegate);
1164}
1165
[email protected]20ede072009-10-06 00:28:351166bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271167 if (showing_interstitial_page())
1168 return false;
1169
[email protected]96d185d2009-04-24 03:28:541170 // See GetDOMUIForCurrentState() comment for more info. This case is very
1171 // similar, but for non-first loads, we want to use the committed entry. This
1172 // is so the bookmarks bar disappears at the same time the page does.
1173 if (controller_.GetLastCommittedEntry()) {
1174 // Not the first load, always use the committed DOM UI.
1175 if (render_manager_.dom_ui())
1176 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1177 return false; // Default.
1178 }
1179
1180 // When it's the first load, we know either the pending one or the committed
1181 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1182 // of them will be valid, so we can just check both.
1183 if (render_manager_.pending_dom_ui())
1184 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1185 if (render_manager_.dom_ui())
1186 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1187 return false; // Default.
1188}
1189
[email protected]3edd9522009-03-04 22:19:411190void TabContents::ToolbarSizeChanged(bool is_animating) {
1191 TabContentsDelegate* d = delegate();
1192 if (d)
1193 d->ToolbarSizeChanged(this, is_animating);
1194}
[email protected]616ed5a2008-11-21 22:27:241195
[email protected]fc6fb7fb2009-11-07 02:35:041196bool TabContents::CanDownload(int request_id) {
1197 TabContentsDelegate* d = delegate();
1198 if (d)
1199 return d->CanDownload(request_id);
1200 return true;
1201}
1202
[email protected]d5f942ba2008-09-26 19:30:341203void TabContents::OnStartDownload(DownloadItem* download) {
1204 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341205
1206 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311207 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341208
[email protected]5b928b62010-08-03 11:46:511209 if (tab_contents && tab_contents->delegate())
1210 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411211}
[email protected]3edd9522009-03-04 22:19:411212
[email protected]d5f942ba2008-09-26 19:30:341213void TabContents::WillClose(ConstrainedWindow* window) {
1214 ConstrainedWindowList::iterator it =
1215 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441216 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341217 if (it != child_windows_.end())
1218 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371219 if (child_windows_.size() > 0) {
1220 if (removed_topmost_window) {
1221 child_windows_[0]->ShowConstrainedWindow();
1222 }
[email protected]fa1cf0b82010-01-15 21:49:441223 BlockTabContent(true);
1224 } else {
1225 BlockTabContent(false);
1226 }
[email protected]66ba4932009-06-04 19:22:131227}
[email protected]d5f942ba2008-09-26 19:30:341228
[email protected]66ba4932009-06-04 19:22:131229void TabContents::WillCloseBlockedPopupContainer(
1230 BlockedPopupContainer* container) {
1231 DCHECK(blocked_popups_ == container);
1232 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491233 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341234}
1235
[email protected]d5f942ba2008-09-26 19:30:341236void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351237#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061238 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351239#endif
[email protected]d5f942ba2008-09-26 19:30:341240}
1241
[email protected]c1dc9f132009-11-20 23:13:211242void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121243 bool forward_direction,
1244 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211245 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011246 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211247 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531248 string16 last_search_prepopulate_text =
1249 FindBarState::GetLastPrepopulateText(profile());
1250
[email protected]87fae512009-12-11 02:20:211251 // Try the last thing we searched for on this tab, then the last thing
1252 // searched for on any tab.
1253 if (!previous_find_text_.empty())
1254 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531255 else if (!last_search_prepopulate_text.empty())
1256 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211257 else
[email protected]e491f1c2009-05-22 20:28:121258 return;
[email protected]e491f1c2009-05-22 20:28:121259 }
[email protected]6e95706d2009-04-23 22:55:011260
[email protected]101c90e2009-10-26 21:14:441261 // Keep track of the previous search.
1262 previous_find_text_ = find_text_;
1263
[email protected]6e95706d2009-04-23 22:55:011264 // This is a FindNext operation if we are searching for the same text again,
1265 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1266 // exception to this is if the Find was aborted (then we don't want FindNext
1267 // because the highlighting has been cleared and we need it to reappear). We
1268 // therefore treat FindNext after an aborted Find operation as a full fledged
1269 // Find.
[email protected]c1dc9f132009-11-20 23:13:211270 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121271 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011272 !find_op_aborted_;
1273 if (!find_next)
1274 current_find_request_id_ = find_request_id_counter_++;
1275
[email protected]c1dc9f132009-11-20 23:13:211276 if (!search_string.empty())
1277 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121278 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011279
1280 find_op_aborted_ = false;
1281
1282 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531283 FindBarState* find_bar_state = profile()->GetFindBarState();
1284 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011285 render_view_host()->StartFinding(current_find_request_id_,
1286 find_text_,
1287 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121288 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011289 find_next);
1290}
1291
[email protected]5bc8fe92010-03-11 18:19:001292void TabContents::StopFinding(
1293 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011294 if (selection_action == FindBarController::kClearSelection) {
1295 // kClearSelection means the find string has been cleared by the user, but
1296 // the UI has not been dismissed. In that case we want to clear the
1297 // previously remembered search (http://crbug.com/42639).
1298 previous_find_text_ = string16();
1299 } else {
[email protected]2d2dffc2009-06-09 21:41:001300 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011301 if (!find_text_.empty())
1302 previous_find_text_ = find_text_;
1303 }
[email protected]101c90e2009-10-26 21:14:441304 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011305 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121306 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001307 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011308}
1309
[email protected]420ae012009-04-24 05:16:321310void TabContents::OnSavePage() {
1311 // If we can not save the page, try to download it.
1312 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1313 DownloadManager* dlm = profile()->GetDownloadManager();
1314 const GURL& current_page_url = GetURL();
1315 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221316 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321317 return;
1318 }
1319
1320 Stop();
1321
1322 // Create the save package and possibly prompt the user for the name to save
1323 // the page as. The user prompt is an asynchronous operation that runs on
1324 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221325 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321326 save_package_->GetSaveInfo();
1327}
1328
1329// Used in automated testing to bypass prompting the user for file names.
1330// Instead, the names and paths are hard coded rather than running them through
1331// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111332bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321333 SavePackage::SavePackageType save_type) {
1334 // Stop the page from navigating.
1335 Stop();
1336
[email protected]828cabe2009-09-26 22:47:111337 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591338 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321339}
1340
[email protected]89d6e6e2009-12-03 23:06:511341void TabContents::EmailPageLocation() {
1342 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1343 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1344 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1345 title + "&body=%0A%0A" + page_url;
1346 platform_util::OpenExternal(GURL(mailto));
1347}
1348
[email protected]420ae012009-04-24 05:16:321349void TabContents::PrintPreview() {
1350 // We don't show the print preview yet, only the print dialog.
1351 PrintNow();
1352}
1353
1354bool TabContents::PrintNow() {
1355 // We can't print interstitial page for now.
1356 if (showing_interstitial_page())
1357 return false;
1358
1359 return render_view_host()->PrintPages();
1360}
1361
[email protected]82270452009-06-19 15:58:011362void TabContents::PrintingDone(int document_cookie, bool success) {
1363 render_view_host()->PrintingDone(document_cookie, success);
1364}
1365
[email protected]420ae012009-04-24 05:16:321366bool TabContents::IsActiveEntry(int32 page_id) {
1367 NavigationEntry* active_entry = controller_.GetActiveEntry();
1368 return (active_entry != NULL &&
1369 active_entry->site_instance() == GetSiteInstance() &&
1370 active_entry->page_id() == page_id);
1371}
1372
[email protected]b2fe07d12010-02-09 14:38:081373void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161374 set_encoding(encoding);
1375 render_view_host()->SetPageEncoding(encoding);
1376}
1377
[email protected]b2fe07d12010-02-09 14:38:081378void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161379 reset_encoding();
1380 render_view_host()->ResetPageEncodingToDefault();
1381}
1382
1383void TabContents::WindowMoveOrResizeStarted() {
1384 render_view_host()->WindowMoveOrResizeStarted();
1385}
1386
[email protected]3f8eb7f2009-10-02 23:58:051387void TabContents::LogNewTabTime(const std::string& event_name) {
1388 // Not all new tab pages get timed. In those cases, we don't have a
1389 // new_tab_start_time_.
1390 if (new_tab_start_time_.is_null())
1391 return;
1392
1393 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441394 MetricEventDurationDetails details(event_name,
1395 static_cast<int>(duration.InMilliseconds()));
1396
[email protected]7ab1e7d62009-10-14 23:32:011397 if (event_name == "Tab.NewTabScriptStart") {
1398 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1399 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1400 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1401 } else if (event_name == "Tab.NewTabOnload") {
1402 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051403 // The new tab page has finished loading; reset it.
1404 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441405 } else {
1406 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051407 }
[email protected]84abba62009-10-07 17:01:441408 NotificationService::current()->Notify(
1409 NotificationType::METRIC_EVENT_DURATION,
1410 Source<TabContents>(this),
1411 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051412}
1413
[email protected]7ab1e7d62009-10-14 23:32:011414void TabContents::OnCloseStarted() {
1415 if (tab_close_start_time_.is_null())
1416 tab_close_start_time_ = base::TimeTicks::Now();
1417}
1418
[email protected]46624bf2010-06-09 16:04:191419bool TabContents::ShouldAcceptDragAndDrop() const {
1420#if defined(OS_CHROMEOS)
1421 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1422 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561423 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191424#else
1425 return true;
1426#endif
1427}
1428
[email protected]c37e3b62010-01-22 00:15:171429TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171430 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161431
1432 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081433 if (extension_app_)
1434 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161435 else if (entry)
1436 tab_nav.SetFromNavigationEntry(*entry);
1437
[email protected]c37e3b62010-01-22 00:15:171438 std::vector<TabNavigation> navigations;
1439 navigations.push_back(tab_nav);
1440
1441 TabContents* new_contents =
1442 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081443 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171444 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171445
[email protected]98aa0b52010-05-06 17:03:081446 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161447 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1448
[email protected]c37e3b62010-01-22 00:15:171449 return new_contents;
1450}
1451
[email protected]96d185d2009-04-24 03:28:541452// Notifies the RenderWidgetHost instance about the fact that the page is
1453// loading, or done loading and calls the base implementation.
1454void TabContents::SetIsLoading(bool is_loading,
1455 LoadNotificationDetails* details) {
1456 if (is_loading == is_loading_)
1457 return;
1458
1459 if (!is_loading) {
1460 load_state_ = net::LOAD_STATE_IDLE;
1461 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561462 upload_size_ = 0;
1463 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541464 }
1465
1466 render_manager_.SetIsLoading(is_loading);
1467
1468 is_loading_ = is_loading;
1469 waiting_for_response_ = is_loading;
1470
1471 if (delegate_)
1472 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351473 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541474
1475 NotificationType type = is_loading ? NotificationType::LOAD_START :
1476 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111477 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541478 if (details)
1479 det = Details<LoadNotificationDetails>(details);
1480 NotificationService::current()->Notify(type,
1481 Source<NavigationController>(&controller_),
1482 det);
1483}
1484
[email protected]b6c874582009-05-08 19:38:311485void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291486 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061487 // A page can't spawn popups (or do anything else, either) until its load
1488 // commits, so when we reach here, the popup was spawned by the
1489 // NavigationController's last committed entry, not the active entry. For
1490 // example, if a page opens a popup in an onunload() handler, then the active
1491 // entry is the page to be loaded as we navigate away from the unloading
1492 // page. For this reason, we can't use GetURL() to get the opener URL,
1493 // because it returns the active entry.
1494 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1495 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1496
1497 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491498 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091499 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491500 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1501 } else {
1502 if (!blocked_popups_)
1503 blocked_popups_ = new BlockedPopupContainer(this);
1504 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]55126132010-08-19 14:53:281505 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1506 std::string());
[email protected]8cc8d492010-02-02 10:40:491507 }
[email protected]b9681312008-11-07 00:08:261508}
[email protected]616ed5a2008-11-21 22:27:241509
1510namespace {
1511bool TransitionIsReload(PageTransition::Type transition) {
1512 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1513}
1514}
1515
1516void TabContents::ExpireInfoBars(
1517 const NavigationController::LoadCommittedDetails& details) {
1518 // Only hide InfoBars when the user has done something that makes the main
1519 // frame load. We don't want various automatic or subframe navigations making
1520 // it disappear.
1521 if (!details.is_user_initiated_main_frame_load())
1522 return;
1523
[email protected]f86a07022008-11-25 01:06:051524 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241525 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081526 if (!delegate) {
1527 // If you hit this NOTREACHED, please comment in bug
1528 // http://crbug.com/50428 how you got there.
1529 NOTREACHED();
1530 continue;
1531 }
1532
[email protected]f86a07022008-11-25 01:06:051533 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241534 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241535 }
1536}
[email protected]fdd61c62009-04-22 19:22:571537
[email protected]96d185d2009-04-24 03:28:541538DOMUI* TabContents::GetDOMUIForCurrentState() {
1539 // When there is a pending navigation entry, we want to use the pending DOMUI
1540 // that goes along with it to control the basic flags. For example, we want to
1541 // show the pending URL in the URL bar, so we want the display_url flag to
1542 // be from the pending entry.
1543 //
1544 // The confusion comes because there are multiple possibilities for the
1545 // initial load in a tab as a side effect of the way the RenderViewHostManager
1546 // works.
1547 //
1548 // - For the very first tab the load looks "normal". The new tab DOM UI is
1549 // the pending one, and we want it to apply here.
1550 //
1551 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1552 // get switched to the one previously associated with the new tab pages.
1553 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1554 // have a committed DOM UI in this case.
1555 //
1556 // This condition handles all of these cases:
1557 //
1558 // - First load in first tab: no committed nav entry + pending nav entry +
1559 // pending dom ui:
1560 // -> Use pending DOM UI if any.
1561 //
1562 // - First load in second tab: no committed nav entry + pending nav entry +
1563 // no pending DOM UI:
1564 // -> Use the committed DOM UI if any.
1565 //
1566 // - Second navigation in any tab: committed nav entry + pending nav entry:
1567 // -> Use pending DOM UI if any.
1568 //
1569 // - Normal state with no load: committed nav entry + no pending nav entry:
1570 // -> Use committed DOM UI.
1571 if (controller_.pending_entry() &&
1572 (controller_.GetLastCommittedEntry() ||
1573 render_manager_.pending_dom_ui()))
1574 return render_manager_.pending_dom_ui();
1575 return render_manager_.dom_ui();
1576}
[email protected]420ae012009-04-24 05:16:321577
1578void TabContents::DidNavigateMainFramePostCommit(
1579 const NavigationController::LoadCommittedDetails& details,
1580 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441581 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1582 // If this is a window.open navigation, use the same DOMUI as the renderer
1583 // that opened the window, as long as both renderers have the same
1584 // privileges.
1585 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1586 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1587 // dom_ui might be NULL if the URL refers to a non-existent extension.
1588 if (dom_ui) {
1589 render_manager_.SetDOMUIPostCommit(dom_ui);
1590 dom_ui->RenderViewCreated(render_view_host());
1591 }
1592 }
1593 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1594 }
1595
[email protected]420ae012009-04-24 05:16:321596 if (details.is_user_initiated_main_frame_load()) {
1597 // Clear the status bubble. This is a workaround for a bug where WebKit
1598 // doesn't let us know that the cursor left an element during a
1599 // transition (this is also why the mouse cursor remains as a hand after
1600 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1601 // clear the bubble when a user navigates to a named anchor in the same
1602 // page.
1603 UpdateTargetURL(details.entry->page_id(), GURL());
1604
1605 // UpdateHelpersForDidNavigate will handle the case where the password_form
1606 // origin is valid.
1607 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1608 // cleaned up and covered by tests.
1609 if (!params.password_form.origin.is_valid())
1610 GetPasswordManager()->DidNavigate();
1611 }
1612
1613 // The keyword generator uses the navigation entries, so must be called after
1614 // the commit.
1615 GenerateKeywordIfNecessary(params);
1616
1617 // Allow the new page to set the title again.
1618 received_page_title_ = false;
1619
1620 // Get the favicon, either from history or request it from the net.
1621 fav_icon_helper_.FetchFavIcon(details.entry->url());
1622
[email protected]0de80162010-02-03 04:52:351623 // Clear all page actions, blocked content notifications and browser actions
1624 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141625 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081626 ExtensionsService* service = profile()->GetExtensionsService();
1627 if (service) {
1628 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571629 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081630 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521631 if (browser_action) {
1632 browser_action->ClearAllValuesForTab(controller().session_id().id());
1633 NotificationService::current()->Notify(
1634 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571635 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521636 NotificationService::NoDetails());
1637 }
[email protected]92c6f9b92009-10-24 04:35:081638
[email protected]5d246db22009-10-27 06:17:571639 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521640 service->extensions()->at(i)->page_action();
1641 if (page_action) {
1642 page_action->ClearAllValuesForTab(controller().session_id().id());
1643 PageActionStateChanged();
1644 }
[email protected]92c6f9b92009-10-24 04:35:081645 }
[email protected]aece2c7f2009-08-27 20:43:171646 }
[email protected]0de80162010-02-03 04:52:351647
1648 // Close blocked popups.
1649 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341650 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351651 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461652 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351653 }
1654
1655 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411656 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551657 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471658
1659 // Once the main frame is navigated, we're no longer considered to have
1660 // displayed insecure content.
1661 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171662 }
[email protected]ce5c4502009-05-06 16:46:111663
[email protected]8cc8d492010-02-02 10:40:491664 // Close constrained windows if necessary.
1665 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1666 details.previous_url, details.entry->url()))
1667 CloseConstrainedWindows();
1668
[email protected]420ae012009-04-24 05:16:321669 // Update the starred state.
1670 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531671
1672 // Clear the cache of forms in AutoFill.
1673 if (autofill_manager_.get())
1674 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321675}
1676
1677void TabContents::DidNavigateAnyFramePostCommit(
1678 RenderViewHost* render_view_host,
1679 const NavigationController::LoadCommittedDetails& details,
1680 const ViewHostMsg_FrameNavigate_Params& params) {
1681 // If we navigate, start showing messages again. This does nothing to prevent
1682 // a malicious script from spamming messages, since the script could just
1683 // reload the page to stop blocking.
1684 suppress_javascript_messages_ = false;
1685
[email protected]420ae012009-04-24 05:16:321686 // Notify the password manager of the navigation or form submit.
1687 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1688 // cleaned up and covered by tests.
1689 if (params.password_form.origin.is_valid())
1690 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551691
1692 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581693 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321694}
1695
[email protected]8cc8d492010-02-02 10:40:491696void TabContents::CloseConstrainedWindows() {
1697 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321698 // We use indices instead of iterators in case CloseWindow does something
1699 // that may invalidate an iterator.
1700 int size = static_cast<int>(child_windows_.size());
1701 for (int i = size - 1; i >= 0; --i) {
1702 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441703 if (window) {
[email protected]420ae012009-04-24 05:16:321704 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441705 BlockTabContent(false);
1706 }
[email protected]420ae012009-04-24 05:16:321707 }
1708}
1709
1710void TabContents::UpdateStarredStateForCurrentURL() {
1711 BookmarkModel* model = profile()->GetBookmarkModel();
1712 const bool old_state = is_starred_;
1713 is_starred_ = (model && model->IsBookmarked(GetURL()));
1714
1715 if (is_starred_ != old_state && delegate())
1716 delegate()->URLStarredChanged(this, is_starred_);
1717}
1718
1719void TabContents::UpdateAlternateErrorPageURL() {
1720 GURL url = GetAlternateErrorPageURL();
1721 render_view_host()->SetAlternateErrorPageURL(url);
1722}
1723
1724void TabContents::UpdateWebPreferences() {
1725 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1726}
1727
1728void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1729 RenderViewHost* rvh) {
1730 // If we are creating a RVH for a restored controller, then we might
1731 // have more page IDs than the SiteInstance's current max page ID. We must
1732 // make sure that the max page ID is larger than any restored page ID.
1733 // Note that it is ok for conflicting page IDs to exist in another tab
1734 // (i.e., NavigationController), but if any page ID is larger than the max,
1735 // the back/forward list will get confused.
1736 int max_restored_page_id = controller_.max_restored_page_id();
1737 if (max_restored_page_id > 0) {
1738 int curr_max_page_id = site_instance->max_page_id();
1739 if (max_restored_page_id > curr_max_page_id) {
1740 // Need to update the site instance immediately.
1741 site_instance->UpdateMaxPageID(max_restored_page_id);
1742
1743 // Also tell the renderer to update its internal representation. We
1744 // need to reserve enough IDs to make all restored page IDs less than
1745 // the max.
1746 if (curr_max_page_id < 0)
1747 curr_max_page_id = 0;
1748 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1749 }
1750 }
1751}
1752
1753void TabContents::UpdateHistoryForNavigation(
[email protected]ebe89e062009-08-13 23:16:541754 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471755 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321756 const ViewHostMsg_FrameNavigate_Params& params) {
1757 if (profile()->IsOffTheRecord())
1758 return;
1759
1760 // Add to history service.
1761 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1762 if (hs) {
1763 if (PageTransition::IsMainFrame(params.transition) &&
[email protected]ebe89e062009-08-13 23:16:541764 virtual_url != params.url) {
1765 // Hack on the "virtual" URL so that it will appear in history. For some
[email protected]420ae012009-04-24 05:16:321766 // types of URLs, we will display a magic URL that is different from where
1767 // the page is actually navigated. We want the user to see in history
[email protected]ebe89e062009-08-13 23:16:541768 // what they saw in the URL bar, so we add the virtual URL as a redirect.
1769 // This only applies to the main frame, as the virtual URL doesn't apply
[email protected]420ae012009-04-24 05:16:321770 // to sub-frames.
1771 std::vector<GURL> redirects = params.redirects;
1772 if (!redirects.empty())
[email protected]ebe89e062009-08-13 23:16:541773 redirects.back() = virtual_url;
1774 hs->AddPage(virtual_url, this, params.page_id, params.referrer,
[email protected]5989f1a2010-08-21 02:21:111775 params.transition, redirects, history::SOURCE_BROWSED,
1776 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321777 } else {
1778 hs->AddPage(params.url, this, params.page_id, params.referrer,
[email protected]5989f1a2010-08-21 02:21:111779 params.transition, params.redirects, history::SOURCE_BROWSED,
[email protected]befd8d822009-07-01 04:51:471780 details.did_replace_entry);
[email protected]420ae012009-04-24 05:16:321781 }
1782 }
1783}
1784
1785bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1786 const std::wstring& title) {
1787 // For file URLs without a title, use the pathname instead. In the case of a
1788 // synthesized title, we don't want the update to count toward the "one set
1789 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251790 string16 final_title;
[email protected]420ae012009-04-24 05:16:321791 bool explicit_set;
1792 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251793 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321794 explicit_set = false; // Don't count synthetic titles toward the set limit.
1795 } else {
[email protected]e53668962010-06-23 15:35:251796 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321797 explicit_set = true;
1798 }
1799
[email protected]e53668962010-06-23 15:35:251800 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321801 return false; // Nothing changed, don't bother.
1802
[email protected]e53668962010-06-23 15:35:251803 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321804
1805 // Update the history system for this page.
1806 if (!profile()->IsOffTheRecord() && !received_page_title_) {
1807 HistoryService* hs =
1808 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1809 if (hs)
[email protected]ebe89e062009-08-13 23:16:541810 hs->SetPageTitle(entry->virtual_url(), final_title);
[email protected]420ae012009-04-24 05:16:321811
1812 // Don't allow the title to be saved again for explicitly set ones.
1813 received_page_title_ = explicit_set;
1814 }
1815
1816 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251817 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321818
[email protected]cbc0e1b2010-04-12 18:33:041819 NotificationService::current()->Notify(
1820 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1821 Source<TabContents>(this),
1822 NotificationService::NoDetails());
1823
[email protected]420ae012009-04-24 05:16:321824 return true;
1825}
1826
1827void TabContents::NotifySwapped() {
1828 // After sending out a swap notification, we need to send a disconnect
1829 // notification so that clients that pick up a pointer to |this| can NULL the
1830 // pointer. See Bug 1230284.
1831 notify_disconnection_ = true;
1832 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341833 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221834 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321835 NotificationService::NoDetails());
1836}
1837
1838void TabContents::NotifyConnected() {
1839 notify_disconnection_ = true;
1840 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341841 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221842 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321843 NotificationService::NoDetails());
1844}
1845
1846void TabContents::NotifyDisconnected() {
1847 if (!notify_disconnection_)
1848 return;
1849
1850 notify_disconnection_ = false;
1851 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341852 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221853 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321854 NotificationService::NoDetails());
1855}
1856
1857void TabContents::GenerateKeywordIfNecessary(
1858 const ViewHostMsg_FrameNavigate_Params& params) {
1859 if (!params.searchable_form_url.is_valid())
1860 return;
1861
1862 if (profile()->IsOffTheRecord())
1863 return;
1864
1865 int last_index = controller_.last_committed_entry_index();
1866 // When there was no previous page, the last index will be 0. This is
1867 // normally due to a form submit that opened in a new tab.
1868 // TODO(brettw) bug 916126: we should support keywords when form submits
1869 // happen in new tabs.
1870 if (last_index <= 0)
1871 return;
1872 const NavigationEntry* previous_entry =
1873 controller_.GetEntryAtIndex(last_index - 1);
1874 if (IsFormSubmit(previous_entry)) {
1875 // Only generate a keyword if the previous page wasn't itself a form
1876 // submit.
1877 return;
1878 }
1879
1880 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1881 previous_entry->user_typed_url() : previous_entry->url();
1882 std::wstring keyword =
1883 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1884 if (keyword.empty())
1885 return;
1886
1887 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1888 if (!url_model)
1889 return;
1890
1891 if (!url_model->loaded()) {
1892 url_model->Load();
1893 return;
1894 }
1895
1896 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191897 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321898 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1899 return;
1900
1901 if (current_url) {
1902 if (current_url->originating_url().is_valid()) {
1903 // The existing keyword was generated from an OpenSearch description
1904 // document, don't regenerate.
1905 return;
1906 }
1907 url_model->Remove(current_url);
1908 }
1909 TemplateURL* new_url = new TemplateURL();
1910 new_url->set_keyword(keyword);
1911 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191912 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321913 new_url->add_input_encoding(params.searchable_form_encoding);
1914 DCHECK(controller_.GetLastCommittedEntry());
1915 const GURL& favicon_url =
1916 controller_.GetLastCommittedEntry()->favicon().url();
1917 if (favicon_url.is_valid()) {
1918 new_url->SetFavIconURL(favicon_url);
1919 } else {
1920 // The favicon url isn't valid. This means there really isn't a favicon,
1921 // or the favicon url wasn't obtained before the load started. This assumes
1922 // the later.
1923 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1924 // its url.
1925 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1926 }
1927 new_url->set_safe_for_autoreplace(true);
1928 url_model->Add(new_url);
1929}
1930
[email protected]bf5c2ff392009-07-08 16:24:331931void TabContents::OnUserGesture() {
1932 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011933 DownloadRequestLimiter* limiter =
1934 g_browser_process->download_request_limiter();
1935 if (limiter)
1936 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261937 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331938}
1939
1940void TabContents::OnFindReply(int request_id,
1941 int number_of_matches,
1942 const gfx::Rect& selection_rect,
1943 int active_match_ordinal,
1944 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421945 // Ignore responses for requests that have been aborted.
1946 if (find_op_aborted_)
1947 return;
1948
[email protected]bf5c2ff392009-07-08 16:24:331949 // Ignore responses for requests other than the one we have most recently
1950 // issued. That way we won't act on stale results when the user has
1951 // already typed in another query.
1952 if (request_id != current_find_request_id_)
1953 return;
1954
1955 if (number_of_matches == -1)
1956 number_of_matches = last_search_result_.number_of_matches();
1957 if (active_match_ordinal == -1)
1958 active_match_ordinal = last_search_result_.active_match_ordinal();
1959
1960 gfx::Rect selection = selection_rect;
1961 if (selection.IsEmpty())
1962 selection = last_search_result_.selection_rect();
1963
1964 // Notify the UI, automation and any other observers that a find result was
1965 // found.
1966 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1967 selection, active_match_ordinal,
1968 final_update);
1969 NotificationService::current()->Notify(
1970 NotificationType::FIND_RESULT_AVAILABLE,
1971 Source<TabContents>(this),
1972 Details<FindNotificationDetails>(&last_search_result_));
1973}
1974
1975void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381976 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1977 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331978}
1979
[email protected]bf5c2ff392009-07-08 16:24:331980void TabContents::OnMissingPluginStatus(int status) {
1981#if defined(OS_WIN)
1982// TODO(PORT): pull in when plug-ins work
1983 GetPluginInstaller()->OnMissingPluginStatus(status);
1984#endif
1985}
1986
1987void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331988 DCHECK(!plugin_path.value().empty());
1989
1990 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351991#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:331992 scoped_ptr<FileVersionInfo> version_info(
1993 FileVersionInfo::CreateFileVersionInfo(plugin_path));
1994 if (version_info.get()) {
1995 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:371996 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:331997 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:371998#if defined(OS_MACOSX)
1999 // Many plugins on the Mac have .plugin in the actual name, which looks
2000 // terrible, so look for that and strip it off if present.
2001 const std::wstring plugin_extension(L".plugin");
2002 if (EndsWith(plugin_name, plugin_extension, true))
2003 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2004#endif // OS_MACOSX
2005 }
[email protected]bf5c2ff392009-07-08 16:24:332006 }
[email protected]4a560ed2009-07-13 23:35:262007#else
2008 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2009#endif
[email protected]2ae8a922010-06-28 20:27:532010 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2011 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332012 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582013 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2014 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532015 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332016}
2017
2018void TabContents::OnCrashedWorker() {
2019 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582020 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422021 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332022}
2023
2024void TabContents::OnDidGetApplicationInfo(
2025 int32 page_id,
2026 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512027 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332028
[email protected]ed5431872009-11-17 08:39:512029 if (delegate())
2030 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332031}
2032
[email protected]851b1eb2010-08-09 13:32:292033void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2034 const GURL& update_url) {
2035 new DisabledPluginInfoBar(this, name, update_url);
2036}
2037
[email protected]a2cf65eb2010-01-18 08:20:382038void TabContents::OnPageContents(const GURL& url,
2039 int renderer_process_id,
2040 int32 page_id,
[email protected]e5106202010-06-11 21:12:362041 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102042 const std::string& language,
2043 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382044 // Don't index any https pages. People generally don't want their bank
2045 // accounts, etc. indexed on their computer, especially since some of these
2046 // things are not marked cachable.
2047 // TODO(brettw) we may want to consider more elaborate heuristics such as
2048 // the cachability of the page. We may also want to consider subframes (this
2049 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272050 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2051 // content indexing for chromeos in some future releases.
2052#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382053 if (!url.SchemeIsSecure()) {
2054 Profile* p = profile();
2055 if (p && !p->IsOffTheRecord()) {
2056 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2057 if (hs)
2058 hs->SetPageContents(url, contents);
2059 }
2060 }
[email protected]ccd40a52010-05-11 16:15:272061#endif
[email protected]a8a81292010-01-21 00:32:452062
[email protected]1c57b7b2010-07-12 17:38:102063 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452064
2065 std::string lang = language;
2066 NotificationService::current()->Notify(
2067 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152068 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452069 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382070}
2071
[email protected]7e0831b2010-02-01 08:45:152072void TabContents::OnPageTranslated(int32 page_id,
2073 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162074 const std::string& translated_lang,
2075 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552076 language_state_.set_current_language(translated_lang);
2077 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162078 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152079 NotificationService::current()->Notify(
2080 NotificationType::PAGE_TRANSLATED,
2081 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162082 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152083}
2084
[email protected]bf5c2ff392009-07-08 16:24:332085void TabContents::DidStartProvisionalLoadForFrame(
2086 RenderViewHost* render_view_host,
2087 bool is_main_frame,
2088 const GURL& url) {
2089 ProvisionalLoadDetails details(is_main_frame,
2090 controller_.IsURLInPageNavigation(url),
2091 url, std::string(), false);
2092 NotificationService::current()->Notify(
2093 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2094 Source<NavigationController>(&controller_),
2095 Details<ProvisionalLoadDetails>(&details));
[email protected]da4f8a12010-08-19 08:33:412096 if (is_main_frame)
2097 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]bf5c2ff392009-07-08 16:24:332098}
2099
2100void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202101 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332102 NotificationService::current()->Notify(
2103 NotificationType::RESOURCE_RESPONSE_STARTED,
2104 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202105 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332106}
2107
[email protected]3dbb80b2010-02-09 22:41:202108void TabContents::DidRedirectResource(
2109 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332110 NotificationService::current()->Notify(
2111 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2112 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202113 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332114}
2115
2116void TabContents::DidLoadResourceFromMemoryCache(
2117 const GURL& url,
2118 const std::string& frame_origin,
2119 const std::string& main_frame_origin,
2120 const std::string& security_info) {
2121 // Send out a notification that we loaded a resource from our memory cache.
[email protected]fc7de492010-07-12 14:49:042122 int cert_id = 0, cert_status = 0, security_bits = 0, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332123 SSLManager::DeserializeSecurityInfo(security_info,
2124 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042125 &security_bits,
2126 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332127 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162128 GetRenderProcessHost()->id(), cert_id,
2129 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332130
2131 NotificationService::current()->Notify(
2132 NotificationType::LOAD_FROM_MEMORY_CACHE,
2133 Source<NavigationController>(&controller_),
2134 Details<LoadFromMemoryCacheDetails>(&details));
2135}
2136
[email protected]e3d60e5d2009-09-25 21:08:292137void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472138 displayed_insecure_content_ = true;
2139 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292140}
2141
2142void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592143 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292144}
2145
[email protected]bf5c2ff392009-07-08 16:24:332146void TabContents::DidFailProvisionalLoadWithError(
2147 RenderViewHost* render_view_host,
2148 bool is_main_frame,
2149 int error_code,
2150 const GURL& url,
2151 bool showing_repost_interstitial) {
2152 if (net::ERR_ABORTED == error_code) {
2153 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2154 // This means that the interstitial won't be torn down properly, which is
2155 // bad. But if we have an interstitial, go back to another tab type, and
2156 // then load the same interstitial again, we could end up getting the first
2157 // interstitial's "failed" message (as a result of the cancel) when we're on
2158 // the second one.
2159 //
2160 // We can't tell this apart, so we think we're tearing down the current page
2161 // which will cause a crash later one. There is also some code in
2162 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2163 // out because of this problem.
2164 //
2165 // http://code.google.com/p/chromium/issues/detail?id=2855
2166 // Because this will not tear down the interstitial properly, if "back" is
2167 // back to another tab type, the interstitial will still be somewhat alive
2168 // in the previous tab type. If you navigate somewhere that activates the
2169 // tab with the interstitial again, you'll see a flash before the new load
2170 // commits of the interstitial page.
2171 if (showing_interstitial_page()) {
2172 LOG(WARNING) << "Discarding message during interstitial.";
2173 return;
2174 }
2175
2176 // This will discard our pending entry if we cancelled the load (e.g., if we
2177 // decided to download the file instead of load it). Only discard the
2178 // pending entry if the URLs match, otherwise the user initiated a navigate
2179 // before the page loaded so that the discard would discard the wrong entry.
2180 NavigationEntry* pending_entry = controller_.pending_entry();
2181 if (pending_entry && pending_entry->url() == url) {
2182 controller_.DiscardNonCommittedEntries();
2183 // Update the URL display.
2184 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2185 }
2186
2187 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2188 }
2189
2190 // Send out a notification that we failed a provisional load with an error.
2191 ProvisionalLoadDetails details(is_main_frame,
2192 controller_.IsURLInPageNavigation(url),
2193 url, std::string(), false);
2194 details.set_error_code(error_code);
2195
2196 NotificationService::current()->Notify(
2197 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2198 Source<NavigationController>(&controller_),
2199 Details<ProvisionalLoadDetails>(&details));
2200}
2201
2202void TabContents::DocumentLoadedInFrame() {
2203 controller_.DocumentLoadedInFrame();
2204}
2205
[email protected]dcd5b332010-08-11 08:55:182206void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562207 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242208 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562209}
2210
[email protected]8d3347f2009-07-09 22:00:212211RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322212 return view_.get();
2213}
2214
[email protected]8d3347f2009-07-09 22:00:212215RenderViewHostDelegate::RendererManagement*
2216TabContents::GetRendererManagementDelegate() {
2217 return &render_manager_;
2218}
2219
[email protected]bf5c2ff392009-07-08 16:24:332220RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212221 TabContents::GetBrowserIntegrationDelegate() {
2222 return this;
[email protected]bf5c2ff392009-07-08 16:24:332223}
2224
[email protected]8d3347f2009-07-09 22:00:212225RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2226 return this;
[email protected]bf5c2ff392009-07-08 16:24:332227}
2228
[email protected]46ba9082010-06-22 10:00:582229RenderViewHostDelegate::ContentSettings*
2230TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552231 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582232}
2233
[email protected]8d3347f2009-07-09 22:00:212234RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322235 return save_package_.get(); // May be NULL, but we can return NULL.
2236}
2237
[email protected]8d3347f2009-07-09 22:00:212238RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092239 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212240}
2241
2242RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2243 return &fav_icon_helper_;
2244}
2245
[email protected]e8dbd674b2010-03-11 18:34:402246RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452247 if (autocomplete_history_manager_.get() == NULL)
2248 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2249 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332250}
2251
[email protected]21674df2009-10-28 19:51:212252RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342253 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212254}
2255
[email protected]aad51d1c2010-08-05 08:38:092256RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2257 if (blocked_plugin_manager_.get() == NULL)
2258 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2259 return blocked_plugin_manager_.get();
2260}
2261
[email protected]1f18184a2010-07-21 19:34:492262RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2263 return GetSSLHelper();
2264}
2265
[email protected]b5977a0c2010-08-24 19:46:262266RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2267 if (file_select_helper_.get() == NULL)
2268 file_select_helper_.reset(new TabContentsFileSelectHelper(this));
2269 return file_select_helper_.get();
2270}
2271
[email protected]fd571bb2010-03-19 01:23:542272AutomationResourceRoutingDelegate*
2273TabContents::GetAutomationResourceRoutingDelegate() {
2274 return delegate();
2275}
2276
[email protected]ced90ae12010-02-20 02:06:162277RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2278 return bookmark_drag_;
2279}
2280
2281void TabContents::SetBookmarkDragDelegate(
2282 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2283 bookmark_drag_ = bookmark_drag;
2284}
2285
[email protected]9fb83e82010-07-02 18:24:552286TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2287 return content_settings_delegate_.get();
2288}
2289
[email protected]93623c5d2009-12-10 21:40:322290RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462291 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512292}
2293
[email protected]57c6a652009-05-04 07:58:342294TabContents* TabContents::GetAsTabContents() {
2295 return this;
2296}
2297
[email protected]7b291f92009-08-14 05:43:532298ViewType::Type TabContents::GetRenderViewType() const {
2299 return ViewType::TAB_CONTENTS;
2300}
2301
2302int TabContents::GetBrowserWindowID() const {
2303 return controller().window_id().id();
2304}
2305
[email protected]420ae012009-04-24 05:16:322306void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062307 NotificationService::current()->Notify(
2308 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2309 Source<TabContents>(this),
2310 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322311 NavigationEntry* entry = controller_.GetActiveEntry();
2312 if (!entry)
2313 return;
2314
2315 // When we're creating views, we're still doing initial setup, so we always
2316 // use the pending DOM UI rather than any possibly existing committed one.
2317 if (render_manager_.pending_dom_ui()) {
2318 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2319 }
2320
2321 if (entry->IsViewSourceMode()) {
2322 // Put the renderer in view source mode.
2323 render_view_host->Send(
2324 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2325 }
[email protected]0666aef2009-05-13 19:48:082326
2327 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322328}
2329
2330void TabContents::RenderViewReady(RenderViewHost* rvh) {
2331 if (rvh != render_view_host()) {
2332 // Don't notify the world, since this came from a renderer in the
2333 // background.
2334 return;
2335 }
2336
2337 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302338 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322339 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302340
2341 // Restore the focus to the tab (otherwise the focus will be on the top
2342 // window).
2343 if (was_crashed && !FocusLocationBarByDefault())
2344 Focus();
[email protected]420ae012009-04-24 05:16:322345}
2346
2347void TabContents::RenderViewGone(RenderViewHost* rvh) {
2348 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092349 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322350 return;
2351 if (rvh != render_view_host()) {
2352 // The pending page's RenderViewHost is gone.
2353 return;
2354 }
2355
2356 SetIsLoading(false, NULL);
2357 NotifyDisconnected();
2358 SetIsCrashed(true);
2359
[email protected]ff9efc62010-02-18 22:10:542360 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212361 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542362 RemoveInfoBar(GetInfoBarDelegateAt(i));
2363
[email protected]8e537302009-06-10 21:19:582364 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552365 // Only do this if we're not in browser shutdown, so that TabContents
2366 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2367 // visible do not flash a sad tab page.
2368 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2369 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322370
2371 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002372 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322373}
2374
[email protected]2e4633c2009-07-09 16:58:062375void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2376 NotificationService::current()->Notify(
2377 NotificationType::RENDER_VIEW_HOST_DELETED,
2378 Source<TabContents>(this),
2379 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482380 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062381}
2382
[email protected]420ae012009-04-24 05:16:322383void TabContents::DidNavigate(RenderViewHost* rvh,
2384 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372385 int extra_invalidate_flags = 0;
2386
2387 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352388 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372389
[email protected]420ae012009-04-24 05:16:322390 render_manager_.DidNavigateMainFrame(rvh);
2391
[email protected]20ede072009-10-06 00:28:352392 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372393 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372394 }
2395
[email protected]420ae012009-04-24 05:16:322396 // Update the site of the SiteInstance if it doesn't have one yet.
2397 if (!GetSiteInstance()->has_site())
2398 GetSiteInstance()->SetSite(params.url);
2399
2400 // Need to update MIME type here because it's referred to in
2401 // UpdateNavigationCommands() called by RendererDidNavigate() to
2402 // determine whether or not to enable the encoding menu.
2403 // It's updated only for the main frame. For a subframe,
2404 // RenderView::UpdateURL does not set params.contents_mime_type.
2405 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2406 // TODO(jungshik): Add a test for the encoding menu to avoid
2407 // regressing it again.
2408 if (PageTransition::IsMainFrame(params.transition))
2409 contents_mime_type_ = params.contents_mime_type;
2410
2411 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372412 bool did_navigate = controller_.RendererDidNavigate(
2413 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392414
2415 // Update history. Note that this needs to happen after the entry is complete,
2416 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]2e29d922009-10-22 22:13:352417 if (params.should_update_history &&
2418 (!delegate() || delegate()->ShouldAddNavigationsToHistory())) {
[email protected]3e90d4a2009-07-03 17:38:392419 // Most of the time, the displayURL matches the loaded URL, but for about:
2420 // URLs, we use a data: URL as the real value. We actually want to save
2421 // the about: URL to the history db and keep the data: URL hidden. This is
2422 // what the TabContents' URL getter does.
2423 UpdateHistoryForNavigation(GetURL(), details, params);
2424 }
2425
[email protected]76543b92009-08-31 17:27:452426 if (!did_navigate)
2427 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322428
2429 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2430 // for the appropriate notification (best) or you can add it to
2431 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2432 // necessary, please).
2433
2434 // Run post-commit tasks.
2435 if (details.is_main_frame)
2436 DidNavigateMainFramePostCommit(details, params);
2437 DidNavigateAnyFramePostCommit(rvh, details, params);
2438}
2439
2440void TabContents::UpdateState(RenderViewHost* rvh,
2441 int32 page_id,
2442 const std::string& state) {
2443 DCHECK(rvh == render_view_host());
2444
2445 // We must be prepared to handle state updates for any page, these occur
2446 // when the user is scrolling and entering form data, as well as when we're
2447 // leaving a page, in which case our state may have already been moved to
2448 // the next page. The navigation controller will look up the appropriate
2449 // NavigationEntry and update it when it is notified via the delegate.
2450
2451 int entry_index = controller_.GetEntryIndexWithPageID(
2452 GetSiteInstance(), page_id);
2453 if (entry_index < 0)
2454 return;
2455 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2456
2457 if (state == entry->content_state())
2458 return; // Nothing to update.
2459 entry->set_content_state(state);
2460 controller_.NotifyEntryChanged(entry, entry_index);
2461}
2462
2463void TabContents::UpdateTitle(RenderViewHost* rvh,
2464 int32 page_id, const std::wstring& title) {
2465 // If we have a title, that's a pretty good indication that we've started
2466 // getting useful data.
2467 SetNotWaitingForResponse();
2468
2469 DCHECK(rvh == render_view_host());
2470 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
2471 page_id);
2472 if (!entry || !UpdateTitleForEntry(entry, title))
2473 return;
2474
2475 // Broadcast notifications when the UI should be updated.
2476 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032477 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322478}
2479
[email protected]420ae012009-04-24 05:16:322480void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402481 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322482 set_encoding(encoding);
2483}
2484
2485void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2486 if (delegate())
2487 delegate()->UpdateTargetURL(this, url);
2488}
2489
2490void TabContents::UpdateThumbnail(const GURL& url,
2491 const SkBitmap& bitmap,
2492 const ThumbnailScore& score) {
2493 // Tell History about this thumbnail
[email protected]9ba208092010-08-10 20:02:082494 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492495 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422496 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282497 } else {
2498 HistoryService* hs;
2499 if (!profile()->IsOffTheRecord() &&
2500 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2501 hs->SetPageThumbnail(url, bitmap, score);
2502 }
[email protected]420ae012009-04-24 05:16:322503 }
2504}
2505
[email protected]c4e98902010-06-01 10:20:142506void TabContents::UpdateInspectorSetting(const std::string& key,
2507 const std::string& value) {
2508 DictionaryValue* inspector_settings =
2509 profile()->GetPrefs()->GetMutableDictionary(
2510 prefs::kWebKitInspectorSettings);
[email protected]8b6e84a2010-08-14 03:32:172511 inspector_settings->SetWithoutPathExpansion(key,
[email protected]628cf5a52010-06-07 14:25:332512 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082513}
2514
[email protected]45aafc92010-06-07 14:18:532515void TabContents::ClearInspectorSettings() {
2516 DictionaryValue* inspector_settings =
2517 profile()->GetPrefs()->GetMutableDictionary(
2518 prefs::kWebKitInspectorSettings);
2519 inspector_settings->Clear();
2520}
2521
[email protected]420ae012009-04-24 05:16:322522void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292523 // The UI may be in an event-tracking loop, such as between the
2524 // mouse-down and mouse-up in text selection or a button click.
2525 // Defer the close until after tracking is complete, so that we
2526 // don't free objects out from under the UI.
2527 // TODO(shess): This could probably be integrated with the
2528 // IsDoingDrag() test below. Punting for now because I need more
2529 // research to understand how this impacts platforms other than Mac.
2530 // TODO(shess): This could get more fine-grained. For instance,
2531 // closing a tab in another window while selecting text in the
2532 // current window's Omnibox should be just fine.
2533 if (view()->IsEventTracking()) {
2534 view()->CloseTabAfterEventTracking();
2535 return;
2536 }
2537
[email protected]24a4d1062009-07-10 23:10:422538 // If we close the tab while we're in the middle of a drag, we'll crash.
2539 // Instead, cancel the drag and close it as soon as the drag ends.
2540 if (view()->IsDoingDrag()) {
2541 view()->CancelDragAndCloseTab();
2542 return;
2543 }
2544
[email protected]420ae012009-04-24 05:16:322545 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2546 if (delegate() && rvh == render_view_host())
2547 delegate()->CloseContents(this);
2548}
2549
2550void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2551 if (delegate() && delegate()->IsPopup(this))
2552 delegate()->MoveContents(this, new_bounds);
2553}
2554
[email protected]7ab1e7d62009-10-14 23:32:012555void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382556 // By default, we assume that the content is not PDF. The renderer
2557 // will tell us if this is not the case.
2558 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322559 SetIsLoading(true, NULL);
2560}
2561
[email protected]7ab1e7d62009-10-14 23:32:012562void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322563 scoped_ptr<LoadNotificationDetails> details;
2564
2565 NavigationEntry* entry = controller_.GetActiveEntry();
2566 // An entry may not exist for a stop when loading an initial blank page or
2567 // if an iframe injected by script into a blank page finishes loading.
2568 if (entry) {
[email protected]420ae012009-04-24 05:16:322569 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2570
2571 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542572 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322573 entry->transition_type(),
2574 elapsed,
2575 &controller_,
2576 controller_.GetCurrentEntryIndex()));
2577 }
2578
2579 // Tell PasswordManager we've finished a page load, which serves as a
2580 // green light to save pending passwords and reset itself.
2581 GetPasswordManager()->DidStopLoading();
2582
2583 SetIsLoading(false, details.get());
2584}
2585
[email protected]420ae012009-04-24 05:16:322586void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2587 const GURL& source_url,
2588 const GURL& target_url) {
2589 NavigationEntry* entry;
2590 if (page_id == -1)
2591 entry = controller_.pending_entry();
2592 else
2593 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2594 if (!entry || entry->url() != source_url)
2595 return;
2596 entry->set_url(target_url);
2597}
2598
[email protected]420ae012009-04-24 05:16:322599void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2600 WindowOpenDisposition disposition) {
2601 if (render_manager_.dom_ui()) {
2602 // When we're a DOM UI, it will provide a page transition type for us (this
2603 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2604 // generated suggestions).
2605 //
2606 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162607 // want web sites to see a referrer of "chrome://blah" (and some
2608 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322609 // send to the site), so we send no referrer.
2610 OpenURL(url, GURL(), disposition,
2611 render_manager_.dom_ui()->link_transition_type());
2612 } else {
2613 OpenURL(url, referrer, disposition, PageTransition::LINK);
2614 }
2615}
2616
[email protected]1ee614862009-07-06 20:29:182617void TabContents::DomOperationResponse(const std::string& json_string,
2618 int automation_id) {
2619}
2620
[email protected]8b8e7c92010-08-19 18:05:562621void TabContents::ProcessDOMUIMessage(
2622 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322623 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442624 // This can happen if someone uses window.open() to open an extension URL
2625 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562626 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322627 return;
2628 }
[email protected]8b8e7c92010-08-19 18:05:562629 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322630}
2631
2632void TabContents::ProcessExternalHostMessage(const std::string& message,
2633 const std::string& origin,
2634 const std::string& target) {
2635 if (delegate())
2636 delegate()->ForwardMessageToExternalHost(message, origin, target);
2637}
2638
[email protected]420ae012009-04-24 05:16:322639void TabContents::RunJavaScriptMessage(
2640 const std::wstring& message,
2641 const std::wstring& default_prompt,
2642 const GURL& frame_url,
2643 const int flags,
2644 IPC::Message* reply_msg,
2645 bool* did_suppress_message) {
2646 // Suppress javascript messages when requested and when inside a constrained
2647 // popup window (because that activates them and breaks them out of the
2648 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552649 // Also suppress messages when showing an interstitial. The interstitial is
2650 // shown over the previous page, we don't want the hidden page dialogs to
2651 // interfere with the interstitial.
2652 bool suppress_this_message = suppress_javascript_messages_ ||
2653 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322654 if (delegate())
2655 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312656 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322657
2658 *did_suppress_message = suppress_this_message;
2659
2660 if (!suppress_this_message) {
2661 base::TimeDelta time_since_last_message(
2662 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2663 bool show_suppress_checkbox = false;
2664 // Show a checkbox offering to suppress further messages if this message is
2665 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2666 if (time_since_last_message <
2667 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2668 show_suppress_checkbox = true;
2669
[email protected]d82ed61e2009-06-16 02:46:222670 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322671 show_suppress_checkbox, reply_msg);
2672 } else {
2673 // If we are suppressing messages, just reply as is if the user immediately
2674 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542675 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322676 }
2677}
2678
2679void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2680 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012681 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222682 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322683}
2684
2685void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2686 const std::string& json_arguments,
2687 IPC::Message* reply_msg) {
2688 if (delegate()) {
2689 HtmlDialogUIDelegate* dialog_delegate =
2690 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222691 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322692 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2693 }
2694}
2695
[email protected]4d44a1c2010-04-28 19:20:412696void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562697 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412698 GetPasswordManager()->PasswordFormsFound(forms);
2699}
2700
2701void TabContents::PasswordFormsVisible(
2702 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2703 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322704}
2705
[email protected]420ae012009-04-24 05:16:322706// Checks to see if we should generate a keyword based on the OSDD, and if
2707// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2708void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2709 int32 page_id, const GURL& url,
2710 bool autodetected) {
2711 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2712 DCHECK(url.is_valid());
2713 if (!IsActiveEntry(page_id))
2714 return;
2715 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2716 if (!url_model)
2717 return;
2718 if (!url_model->loaded()) {
2719 url_model->Load();
2720 return;
2721 }
2722 if (!profile()->GetTemplateURLFetcher())
2723 return;
2724
2725 if (profile()->IsOffTheRecord())
2726 return;
2727
2728 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2729 DCHECK(entry);
2730
2731 const NavigationEntry* base_entry = entry;
2732 if (IsFormSubmit(base_entry)) {
2733 // If the current page is a form submit, find the last page that was not
2734 // a form submit and use its url to generate the keyword from.
2735 int index = controller_.last_committed_entry_index() - 1;
2736 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2737 index--;
2738 if (index >= 0)
2739 base_entry = controller_.GetEntryAtIndex(index);
2740 else
2741 base_entry = NULL;
2742 }
2743
2744 // We want to use the user typed URL if available since that represents what
2745 // the user typed to get here, and fall back on the regular URL if not.
2746 if (!base_entry)
2747 return;
2748 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2749 base_entry->user_typed_url() : base_entry->url();
2750 if (!keyword_url.is_valid())
2751 return;
2752 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2753 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532754
2755 // For JS added OSDD empty keyword is OK because we will generate keyword
2756 // later from OSDD content.
2757 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322758 return;
2759 const TemplateURL* template_url =
2760 url_model->GetTemplateURLForKeyword(keyword);
2761 if (template_url && (!template_url->safe_for_autoreplace() ||
2762 template_url->originating_url() == url)) {
2763 // Either there is a user created TemplateURL for this keyword, or the
2764 // keyword has the same OSDD url and we've parsed it.
2765 return;
2766 }
2767
2768 // Download the OpenSearch description document. If this is successful a
2769 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322770 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2771 keyword,
2772 url,
2773 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162774 this,
[email protected]420ae012009-04-24 05:16:322775 autodetected);
2776}
2777
[email protected]420ae012009-04-24 05:16:322778GURL TabContents::GetAlternateErrorPageURL() const {
2779 GURL url;
2780 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2781 if (profile()->IsOffTheRecord())
2782 return url;
2783
2784 PrefService* prefs = profile()->GetPrefs();
2785 DCHECK(prefs);
2786 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152787 url = google_util::AppendGoogleLocaleParam(
2788 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322789 url = google_util::AppendGoogleTLDParam(url);
2790 }
2791 return url;
2792}
2793
2794WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062795 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552796 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062797 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322798}
2799
[email protected]fa1cf0b82010-01-15 21:49:442800void TabContents::OnIgnoredUIEvent() {
2801 if (constrained_window_count()) {
2802 ConstrainedWindow* window = *constrained_window_begin();
2803 window->FocusConstrainedWindow();
2804 }
2805}
2806
[email protected]420ae012009-04-24 05:16:322807void TabContents::OnJSOutOfMemory() {
2808 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582809 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2810 NULL, true));
[email protected]420ae012009-04-24 05:16:322811}
2812
[email protected]420ae012009-04-24 05:16:322813void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2814 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342815 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322816 // delivered to a pending RenderViewHost. We must first run the onunload
2817 // handler of the old RenderViewHost before we can allow it to proceed.
2818 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2819 new_request_id);
2820}
2821
[email protected]420ae012009-04-24 05:16:322822gfx::Rect TabContents::GetRootWindowResizerRect() const {
2823 if (delegate())
2824 return delegate()->GetRootWindowResizerRect();
2825 return gfx::Rect();
2826}
2827
2828void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2829 bool is_during_unload) {
2830 if (is_during_unload) {
2831 // Hang occurred while firing the beforeunload/unload handler.
2832 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112833 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322834
2835 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2836 return;
2837
2838 // If the tab hangs in the beforeunload/unload handler there's really
2839 // nothing we can do to recover. Pretend the unload listeners have
2840 // all fired and close the tab. If the hang is in the beforeunload handler
2841 // then the user will not have the option of cancelling the close.
2842 Close(rvh);
2843 return;
2844 }
2845
2846 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002847 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322848}
2849
2850void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002851 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322852}
2853
2854void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562855 net::LoadState load_state,
2856 uint64 upload_position,
2857 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322858 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562859 upload_position_ = upload_position;
2860 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292861 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192862 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292863 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532864 load_state_host_ =
2865 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322866 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2867 SetNotWaitingForResponse();
2868 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502869 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322870}
2871
[email protected]1ee614862009-07-06 20:29:182872bool TabContents::IsExternalTabContainer() const {
2873 if (!delegate())
2874 return false;
2875
2876 return delegate()->IsExternalTabContainer();
2877}
2878
[email protected]1ee614862009-07-06 20:29:182879void TabContents::DidInsertCSS() {
2880 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322881}
2882
[email protected]130efb02009-09-18 18:54:352883void TabContents::FocusedNodeChanged() {
2884 NotificationService::current()->Notify(
2885 NotificationType::FOCUS_CHANGED_IN_PAGE,
2886 Source<RenderViewHost>(render_view_host()),
2887 NotificationService::NoDetails());
2888}
2889
[email protected]ebf40a72010-07-22 01:46:382890void TabContents::SetDisplayingPDFContent() {
2891 displaying_pdf_content_ = true;
2892 if (delegate())
2893 delegate()->ContentTypeChanged(this);
2894}
2895
[email protected]420ae012009-04-24 05:16:322896void TabContents::BeforeUnloadFiredFromRenderManager(
2897 bool proceed,
2898 bool* proceed_to_fire_unload) {
2899 if (delegate())
2900 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2901}
2902
[email protected]3a3d47472010-07-15 21:03:542903void TabContents::DidStartLoadingFromRenderManager(
2904 RenderViewHost* render_view_host) {
2905 DidStartLoading();
2906}
2907
2908void TabContents::RenderViewGoneFromRenderManager(
2909 RenderViewHost* render_view_host) {
2910 RenderViewGone(render_view_host);
2911}
2912
[email protected]420ae012009-04-24 05:16:322913void TabContents::UpdateRenderViewSizeForRenderManager() {
2914 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262915 gfx::Size size = view_->GetContainerSize();
2916 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2917 // here during container initialization and normal window size will be set
2918 // later. In case of tab duplication this resizing to 0x0 prevents setting
2919 // normal size later so just ignore it.
2920 if (!size.IsEmpty())
2921 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322922}
2923
[email protected]3a3d47472010-07-15 21:03:542924void TabContents::NotifySwappedFromRenderManager() {
2925 NotifySwapped();
2926}
2927
2928NavigationController& TabContents::GetControllerForRenderManager() {
2929 return controller();
2930}
2931
[email protected]420ae012009-04-24 05:16:322932DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222933 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322934}
2935
2936NavigationEntry*
2937TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2938 return controller_.GetLastCommittedEntry();
2939}
2940
2941bool TabContents::CreateRenderViewForRenderManager(
2942 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322943 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522944
[email protected]674b3822010-08-04 04:02:512945 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322946 return false;
2947
2948 // Now that the RenderView has been created, we need to tell it its size.
2949 rwh_view->SetSize(view_->GetContainerSize());
2950
2951 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2952 render_view_host);
2953 return true;
2954}
2955
2956void TabContents::Observe(NotificationType type,
2957 const NotificationSource& source,
2958 const NotificationDetails& details) {
2959 switch (type.value) {
2960 case NotificationType::BOOKMARK_MODEL_LOADED:
2961 // BookmarkModel finished loading, fall through to update starred state.
2962 case NotificationType::URLS_STARRED: {
2963 // Somewhere, a URL has been starred.
2964 // Ignore notifications for profiles other than our current one.
2965 Profile* source_profile = Source<Profile>(source).ptr();
2966 if (!source_profile || !source_profile->IsSameProfile(profile()))
2967 return;
2968
2969 UpdateStarredStateForCurrentURL();
2970 break;
2971 }
2972 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512973 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322974 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2975 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2976 UpdateAlternateErrorPageURL();
2977 } else if (*pref_name_in == prefs::kDefaultCharset ||
[email protected]57ecc4b2010-08-11 03:02:512978 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)
[email protected]420ae012009-04-24 05:16:322979 ) {
2980 UpdateWebPreferences();
2981 } else {
2982 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2983 }
2984 break;
2985 }
2986 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2987 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2988 break;
2989
2990 case NotificationType::NAV_ENTRY_COMMITTED: {
2991 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2992
2993 NavigationController::LoadCommittedDetails& committed_details =
2994 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2995 ExpireInfoBars(committed_details);
2996 break;
2997 }
2998
[email protected]d3ba77272009-09-03 00:06:092999#if defined(OS_LINUX)
3000 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543001 renderer_preferences_util::UpdateFromSystemSettings(
3002 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093003 render_view_host()->SyncRendererPrefs();
3004 break;
3005 }
3006#endif
3007
[email protected]6c32ce72010-03-08 05:18:063008 case NotificationType::USER_STYLE_SHEET_UPDATED:
3009 UpdateWebPreferences();
3010 break;
3011
[email protected]79580c62010-02-02 02:36:253012 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293013 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253014 settings_details(details);
[email protected]79580c62010-02-02 02:36:253015 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493016 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293017 if (entry)
[email protected]da0c8e92010-02-09 23:25:493018 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293019 if (settings_details.ptr()->update_all() ||
3020 settings_details.ptr()->pattern().Matches(entry_url)) {
3021 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233022 profile()->GetHostContentSettingsMap()->
3023 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253024 }
3025 break;
3026 }
3027
[email protected]e5adff72010-06-14 18:13:063028 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573029 break;
[email protected]a888b29e62010-04-01 13:38:573030
3031 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063032 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573033 break;
[email protected]a888b29e62010-04-01 13:38:573034
[email protected]420ae012009-04-24 05:16:323035 default:
3036 NOTREACHED();
3037 }
3038}
[email protected]aacd7cc2009-09-02 14:51:103039
[email protected]98aa0b52010-05-06 17:03:083040void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3041 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433042
[email protected]a888b29e62010-04-01 13:38:573043 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083044 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3045 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573046 extension,
3047 extension->GetIconPath(Extension::EXTENSION_ICON_SMALLISH),
3048 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3049 Extension::EXTENSION_ICON_SMALLISH),
3050 ImageLoadingTracker::CACHE);
3051 } else {
[email protected]98aa0b52010-05-06 17:03:083052 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573053 }
3054}
3055
3056Extension* TabContents::GetExtensionContaining(const GURL& url) {
3057 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3058 if (!extensions_service)
3059 return NULL;
3060
3061 Extension* extension = extensions_service->GetExtensionByURL(url);
3062 return extension ?
3063 extension : extensions_service->GetExtensionByWebExtent(url);
3064}
3065
[email protected]a888b29e62010-04-01 13:38:573066void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3067 int index) {
3068 if (image) {
[email protected]98aa0b52010-05-06 17:03:083069 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573070 NotifyNavigationStateChanged(INVALIDATE_TAB);
3071 }
3072}
3073
[email protected]beb440c2009-11-06 04:08:543074std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3075 bool is_alert) {
3076 if (!frame_url.has_host())
3077 return l10n_util::GetString(
3078 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3079 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3080
3081 // We really only want the scheme, hostname, and port.
3082 GURL::Replacements replacements;
3083 replacements.ClearUsername();
3084 replacements.ClearPassword();
3085 replacements.ClearPath();
3086 replacements.ClearQuery();
3087 replacements.ClearRef();
3088 GURL clean_url = frame_url.ReplaceComponents(replacements);
3089
3090 // TODO(brettw) it should be easier than this to do the correct language
3091 // handling without getting the accept language from the profile.
[email protected]70edb862010-08-18 16:23:183092 string16 base_address = WideToUTF16(gfx::ElideUrl(clean_url, gfx::Font(), 0,
3093 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages))));
[email protected]beb440c2009-11-06 04:08:543094 // Force URL to have LTR directionality.
[email protected]70edb862010-08-18 16:23:183095 base_address = base::i18n::GetDisplayStringInLTRDirectionality(base_address);
[email protected]beb440c2009-11-06 04:08:543096
[email protected]70edb862010-08-18 16:23:183097 return UTF16ToWide(l10n_util::GetStringFUTF16(
[email protected]beb440c2009-11-06 04:08:543098 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
[email protected]70edb862010-08-18 16:23:183099 base_address));
[email protected]beb440c2009-11-06 04:08:543100}
3101
3102gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3103 return view_->GetTopLevelNativeWindow();
3104}
3105
3106void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3107 bool success,
3108 const std::wstring& prompt) {
3109 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3110 if (is_showing_before_unload_dialog_ && !success) {
3111 // If a beforeunload dialog is canceled, we need to stop the throbber from
3112 // spinning, since we forced it to start spinning in Navigate.
3113 DidStopLoading();
3114
3115 tab_close_start_time_ = base::TimeTicks();
3116 }
3117 is_showing_before_unload_dialog_ = false;
3118 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3119}
3120
3121void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3122 set_suppress_javascript_messages(suppress_message_boxes);
3123}
3124
[email protected]3a3d47472010-07-15 21:03:543125TabContents* TabContents::AsTabContents() {
3126 return this;
3127}
3128
3129ExtensionHost* TabContents::AsExtensionHost() {
3130 return NULL;
3131}
3132
[email protected]41fc0322009-09-04 22:23:403133void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103134 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3135}
[email protected]f45d2a72010-03-08 23:28:353136
3137void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3138 app_icon_ = app_icon;
3139 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3140}
[email protected]ea68c06a2010-04-23 17:25:373141
3142// After a successful *new* login attempt, we take the PasswordFormManager in
3143// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3144// the user makes up their mind with the "save password" infobar. Note if the
3145// login is one we already know about, the end of the line is
3146// provisional_save_manager_ because we just update it on success and so such
3147// forms never end up in an infobar.
3148class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3149 public:
3150 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463151 PasswordFormManager* form_to_save)
3152 : ConfirmInfoBarDelegate(tab_contents),
3153 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583154 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373155
[email protected]d75aba1d2010-08-02 23:35:583156 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373157
[email protected]d75aba1d2010-08-02 23:35:583158 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373159 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463160 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583161 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373162 delete this;
3163 }
3164
[email protected]d75aba1d2010-08-02 23:35:583165 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3166
[email protected]e23d3a32010-08-13 19:39:583167 virtual string16 GetMessageText() const {
3168 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373169 }
3170
3171 virtual SkBitmap* GetIcon() const {
3172 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3173 IDR_INFOBAR_SAVE_PASSWORD);
3174 }
3175
3176 virtual int GetButtons() const {
3177 return BUTTON_OK | BUTTON_CANCEL;
3178 }
3179
[email protected]e23d3a32010-08-13 19:39:583180 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373181 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583182 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373183 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583184 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373185 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583186 return string16();
[email protected]ea68c06a2010-04-23 17:25:373187 }
3188
3189 virtual bool Accept() {
3190 DCHECK(form_to_save_.get());
3191 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583192 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373193 return true;
3194 }
3195
3196 virtual bool Cancel() {
3197 DCHECK(form_to_save_.get());
3198 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583199 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373200 return true;
3201 }
[email protected]d75aba1d2010-08-02 23:35:583202 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373203
3204 private:
3205 // The PasswordFormManager managing the form we're asking the user about,
3206 // and should update as per her decision.
3207 scoped_ptr<PasswordFormManager> form_to_save_;
3208
[email protected]12bb6822010-06-16 02:00:463209 // Used to track the results we get from the info bar.
3210 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583211 NO_RESPONSE = 0,
3212 REMEMBER_PASSWORD,
3213 DONT_REMEMBER_PASSWORD,
3214 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463215 };
3216 ResponseType infobar_response_;
3217
[email protected]ea68c06a2010-04-23 17:25:373218 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3219};
3220
3221void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163222 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373223 render_view_host()->FillPasswordForm(form_data);
3224}
3225
3226void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3227 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3228}
3229
3230Profile* TabContents::GetProfileForPasswordManager() {
3231 return profile();
3232}
3233
3234bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3235 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3236}