blob: a21ea8f5e108173529fb7ba2572bf9b8193d142d [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]ec0b6c42010-08-26 03:16:5840#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4241#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4842#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5343#include "chrome/browser/find_bar_state.h"
[email protected]420ae012009-04-24 05:16:3244#include "chrome/browser/google_util.h"
[email protected]79580c62010-02-02 02:36:2545#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2646#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1447#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3248#include "chrome/browser/load_from_memory_cache_details.h"
49#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4450#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0551#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1052#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5753#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2454#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5755#include "chrome/browser/plugin_installer.h"
[email protected]8e0bbf12010-07-20 00:03:4356#include "chrome/browser/popup_blocked_animation.h"
[email protected]37858e52010-08-26 00:22:0257#include "chrome/browser/prefs/pref_service.h"
[email protected]12802702010-07-09 19:43:0958#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4459#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1661#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5462#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3763#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5465#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3266#include "chrome/browser/renderer_preferences_util.h"
[email protected]152b8ba32010-03-29 19:40:1667#include "chrome/browser/search_engines/template_url_fetcher.h"
68#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1769#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1770#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5471#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]fd2b9ce2010-08-11 04:03:5772#include "chrome/browser/tab_contents/match_preview.h"
[email protected]f3ec7742009-01-15 00:59:1673#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4374#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1675#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]b5977a0c2010-08-24 19:46:2676#include "chrome/browser/tab_contents/tab_contents_file_select_helper.h"
[email protected]1f18184a2010-07-21 19:34:4977#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5778#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0279#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1680#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5881#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2782#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4983#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5784#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1485#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0986#include "chrome/common/extensions/url_pattern.h"
87#include "chrome/common/navigation_types.h"
88#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5689#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2990#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3291#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0292#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1893#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5494#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3795#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2696#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3297#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0698#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3799#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32100#include "net/base/mime_util.h"
101#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29102#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32103#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18104#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03105#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00106
[email protected]420ae012009-04-24 05:16:32107// Cross-Site Navigations
108//
109// If a TabContents is told to navigate to a different web site (as determined
110// by SiteInstance), it will replace its current RenderViewHost with a new
111// RenderViewHost dedicated to the new SiteInstance. This works as follows:
112//
113// - Navigate determines whether the destination is cross-site, and if so,
114// it creates a pending_render_view_host_ and moves into the PENDING
115// RendererState.
116// - The pending RVH is "suspended," so that no navigation messages are sent to
117// its renderer until the onbeforeunload JavaScript handler has a chance to
118// run in the current RVH.
119// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
120// that it has a pending cross-site request. ResourceDispatcherHost will
121// check for this when the response arrives.
122// - The current RVH runs its onbeforeunload handler. If it returns false, we
123// cancel all the pending logic and go back to NORMAL. Otherwise we allow
124// the pending RVH to send the navigation request to its renderer.
125// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
126// checks CrossSiteRequestManager to see that the RVH responsible has a
127// pending cross-site request, and then installs a CrossSiteEventHandler.
128// - When RDH receives a response, the BufferedEventHandler determines whether
129// it is a download. If so, it sends a message to the new renderer causing
130// it to cancel the request, and the download proceeds in the download
131// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34132// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32133// doesn't affect any functionality.
134// - After RDH receives a response and determines that it is safe and not a
135// download, it pauses the response to first run the old page's onunload
136// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34137// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32138// to the current RVH.
139// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
140// the ResourceDispatcherHost, who unpauses the response. Data is then sent
141// to the pending RVH.
142// - The pending renderer sends a FrameNavigate message that invokes the
143// DidNavigate method. This replaces the current RVH with the
144// pending RVH and goes back to the NORMAL RendererState.
145
146namespace {
147
148// Amount of time we wait between when a key event is received and the renderer
149// is queried for its state and pushed to the NavigationEntry.
150const int kQueryStateDelay = 5000;
151
152const int kSyncWaitDelay = 40;
153
[email protected]304f8792009-08-19 21:28:09154#if defined(OS_CHROMEOS)
155// If a popup window is bigger than this fraction of the screen on chrome os,
156// turn it into a tab
157const float kMaxWidthFactor = 0.5;
158const float kMaxHeightFactor = 0.6;
159#endif
160
[email protected]420ae012009-04-24 05:16:32161// If another javascript message box is displayed within
162// kJavascriptMessageExpectedDelay of a previous javascript message box being
163// dismissed, display an option to suppress future message boxes from this
164// contents.
165const int kJavascriptMessageExpectedDelay = 1000;
166
[email protected]420ae012009-04-24 05:16:32167// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51168const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32169 prefs::kAlternateErrorPagesEnabled,
170 prefs::kWebKitJavaEnabled,
171 prefs::kWebKitJavascriptEnabled,
172 prefs::kWebKitLoadsImagesAutomatically,
173 prefs::kWebKitPluginsEnabled,
174 prefs::kWebKitUsesUniversalDetector,
175 prefs::kWebKitSerifFontFamily,
176 prefs::kWebKitSansSerifFontFamily,
177 prefs::kWebKitFixedFontFamily,
178 prefs::kWebKitDefaultFontSize,
179 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36180 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32181 prefs::kDefaultCharset
182 // kWebKitStandardFontIsSerif needs to be added
183 // if we let users pick which font to use, serif or sans-serif when
184 // no font is specified or a CSS generic family (serif or sans-serif)
185 // is not specified.
186};
187
188const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
189
[email protected]420ae012009-04-24 05:16:32190// Returns true if the entry's transition type is FORM_SUBMIT.
191bool IsFormSubmit(const NavigationEntry* entry) {
192 return (PageTransition::StripQualifier(entry->transition_type()) ==
193 PageTransition::FORM_SUBMIT);
194}
195
196#if defined(OS_WIN)
197
198BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
199 // Note: erase is required to properly paint some widgets borders. This can
200 // be seen with textfields.
201 InvalidateRect(hwnd, NULL, TRUE);
202 return TRUE;
203}
204#endif
205
[email protected]5e369672009-11-03 23:48:30206ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16207 Profile* profile, const NavigationEntry& entry,
208 NavigationController::ReloadType reload_type) {
209 switch (reload_type) {
210 case NavigationController::RELOAD:
211 return ViewMsg_Navigate_Params::RELOAD;
212 case NavigationController::RELOAD_IGNORING_CACHE:
213 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
214 case NavigationController::NO_RELOAD:
215 break; // Fall through to rest of function.
216 }
[email protected]5e369672009-11-03 23:48:30217
218 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
219 profile->DidLastSessionExitCleanly())
220 return ViewMsg_Navigate_Params::RESTORE;
221
222 return ViewMsg_Navigate_Params::NORMAL;
223}
224
[email protected]3cc72b12010-03-18 23:03:00225void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16226 NavigationController::ReloadType reload_type,
227 ViewMsg_Navigate_Params* params) {
[email protected]3cc72b12010-03-18 23:03:00228 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34229 params->page_id = entry.page_id();
[email protected]3cc72b12010-03-18 23:03:00230 params->pending_history_list_offset = controller.pending_entry_index();
231 params->current_history_list_offset = controller.last_committed_entry_index();
232 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34233 params->url = entry.url();
234 params->referrer = entry.referrer();
235 params->transition = entry.transition_type();
236 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00237 params->navigation_type =
238 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34239 params->request_time = base::Time::Now();
240}
241
[email protected]851b1eb2010-08-09 13:32:29242class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
243 public:
244 DisabledPluginInfoBar(TabContents* tab_contents,
245 const string16& name,
246 const GURL& update_url)
247 : ConfirmInfoBarDelegate(tab_contents),
248 tab_contents_(tab_contents),
249 name_(name),
250 update_url_(update_url) {
251 tab_contents->AddInfoBar(this);
252 }
253
254 virtual int GetButtons() const {
255 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
256 }
257
[email protected]e23d3a32010-08-13 19:39:58258 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29259 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58260 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29261 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58262 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29263 return ConfirmInfoBarDelegate::GetButtonLabel(button);
264 }
265
[email protected]e23d3a32010-08-13 19:39:58266 virtual string16 GetMessageText() const {
267 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29268 }
269
[email protected]e23d3a32010-08-13 19:39:58270 virtual string16 GetLinkText() {
271 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29272 }
273
274 virtual SkBitmap* GetIcon() const {
275 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
276 IDR_INFOBAR_PLUGIN_INSTALL);
277 }
278
279 virtual bool Accept() {
280 tab_contents_->OpenURL(update_url_, GURL(),
281 CURRENT_TAB, PageTransition::LINK);
282 return false;
283 }
284
285 virtual bool Cancel() {
286 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
287 CURRENT_TAB, PageTransition::LINK);
288 return false;
289 }
290
291 virtual bool LinkClicked(WindowOpenDisposition disposition) {
292 // TODO(bauerb): Navigate to a help page explaining why we disabled
293 // the plugin, once we have one.
294 return false;
295 }
296
297 private:
298 TabContents* tab_contents_;
299 string16 name_;
300 GURL update_url_;
301};
302
[email protected]420ae012009-04-24 05:16:32303} // namespace
304
305// -----------------------------------------------------------------------------
306
[email protected]fdd61c62009-04-22 19:22:57307// static
308int TabContents::find_request_id_counter_ = -1;
309
[email protected]420ae012009-04-24 05:16:32310
[email protected]420ae012009-04-24 05:16:32311TabContents::TabContents(Profile* profile,
312 SiteInstance* site_instance,
313 int routing_id,
[email protected]34ac70502009-09-25 17:07:23314 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42315 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13316 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
317 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22318 TabContentsView::Create(this))),
319 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57320 property_bag_(),
321 registrar_(),
[email protected]12802702010-07-09 19:43:09322 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
323 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57324 save_package_(),
[email protected]6db0def92010-03-02 19:55:45325 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21326 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57327 password_manager_(),
328 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06329 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22330 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34331 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29332 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34333 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34334 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57335 current_load_start_(),
336 load_state_(net::LOAD_STATE_IDLE),
337 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56338 upload_size_(0),
339 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57340 received_page_title_(false),
341 is_starred_(false),
342 contents_mime_type_(),
343 encoding_(),
[email protected]332af7732009-03-11 13:21:35344 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49345 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47346 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57347 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57348 find_ui_active_(false),
349 find_op_aborted_(false),
350 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12351 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12352 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08353 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57354 capturing_contents_(false),
355 is_being_destroyed_(false),
356 notify_disconnection_(false),
357 history_requests_(),
358#if defined(OS_WIN)
359 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
360#endif
361 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44362 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01363 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54364 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54365 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16366 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38367 closed_by_user_gesture_(false),
368 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54369 renderer_preferences_util::UpdateFromSystemSettings(
370 &renderer_preferences_, profile);
371
[email protected]9fb83e82010-07-02 18:24:55372 content_settings_delegate_.reset(
373 new TabSpecificContentSettings(this, profile));
374
[email protected]16779842009-07-08 23:45:29375#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02376 // Make sure the thumbnailer is started before starting the render manager.
377 // The thumbnailer will want to listen for RVH creations, one of which will
378 // happen in RVHManager::Init.
379 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
380 if (generator)
381 generator->StartThumbnailing();
382#endif
383
[email protected]12636df2009-09-28 22:32:21384 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32385
[email protected]34ac70502009-09-25 17:07:23386 // We have the initial size of the view be based on the size of the passed in
387 // tab contents (normally a tab from the same window).
388 view_->CreateView(base_tab_contents ?
389 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32390
391 // Register for notifications about all interested prefs change.
392 PrefService* prefs = profile->GetPrefs();
393 if (prefs) {
394 for (int i = 0; i < kPrefsToObserveLength; ++i)
395 prefs->AddPrefObserver(kPrefsToObserve[i], this);
396 }
397
398 // Register for notifications about URL starredness changing on any profile.
399 registrar_.Add(this, NotificationType::URLS_STARRED,
400 NotificationService::AllSources());
401 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
402 NotificationService::AllSources());
403 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
404 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09405#if defined(OS_LINUX)
406 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
407 NotificationService::AllSources());
408#endif
[email protected]420ae012009-04-24 05:16:32409
[email protected]6c32ce72010-03-08 05:18:06410 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
411 NotificationService::AllSources());
412
[email protected]79580c62010-02-02 02:36:25413 // Register for notifications about content setting changes.
414 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
415 NotificationService::AllSources());
416
[email protected]a888b29e62010-04-01 13:38:57417 // Listen for extension changes so we can update extension_for_current_page_.
418 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
419 NotificationService::AllSources());
420 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
421 NotificationService::AllSources());
422 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
423 NotificationService::AllSources());
424
[email protected]c8865482009-07-23 20:40:10425 // Set-up the showing of the omnibox search infobar if applicable.
426 if (OmniboxSearchHint::IsEnabled(profile))
427 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]fd2b9ce2010-08-11 04:03:57428
429 if (MatchPreview::IsEnabled())
430 match_preview_.reset(new MatchPreview(this));
[email protected]332af7732009-03-11 13:21:35431}
initial.commit09911bf2008-07-26 23:55:29432
433TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32434 is_being_destroyed_ = true;
435
[email protected]bfe4c1582009-10-02 18:11:09436 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32437 registrar_.RemoveAll();
438
439 // Unregister the notifications of all observed prefs change.
440 PrefService* prefs = profile()->GetPrefs();
441 if (prefs) {
442 for (int i = 0; i < kPrefsToObserveLength; ++i)
443 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
444 }
445
[email protected]420ae012009-04-24 05:16:32446 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00447 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32448
[email protected]420ae012009-04-24 05:16:32449 // First cleanly close all child windows.
450 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
451 // some of these to close. CloseWindows is async, so it might get called
452 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49453 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32454
[email protected]8cc8d492010-02-02 10:40:49455 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13456 if (blocked_popups_)
457 blocked_popups_->Destroy();
458
[email protected]420ae012009-04-24 05:16:32459 // Notify any observer that have a reference on this tab contents.
460 NotificationService::current()->Notify(
461 NotificationType::TAB_CONTENTS_DESTROYED,
462 Source<TabContents>(this),
463 NotificationService::NoDetails());
464
[email protected]1e5e74f2009-05-27 20:55:12465 // Notify any lasting InfobarDelegates that have not yet been removed that
466 // whatever infobar they were handling in this TabContents has closed,
467 // because the TabContents is going away entirely.
468 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
469 // notification may trigger infobars calls that access their delegate. (and
470 // some implementations of InfoBarDelegate do delete themselves on
471 // InfoBarClosed()).
472 for (int i = 0; i < infobar_delegate_count(); ++i) {
473 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
474 delegate->InfoBarClosed();
475 }
476 infobar_delegates_.clear();
477
[email protected]420ae012009-04-24 05:16:32478 // TODO(brettw) this should be moved to the view.
479#if defined(OS_WIN)
480 // If we still have a window handle, destroy it. GetNativeView can return
481 // NULL if this contents was part of a window that closed.
482 if (GetNativeView())
483 ::DestroyWindow(GetNativeView());
484#endif
[email protected]7ab1e7d62009-10-14 23:32:01485
486 // OnCloseStarted isn't called in unit tests.
487 if (!tab_close_start_time_.is_null()) {
488 UMA_HISTOGRAM_TIMES("Tab.Close",
489 base::TimeTicks::Now() - tab_close_start_time_);
490 }
initial.commit09911bf2008-07-26 23:55:29491}
492
[email protected]d5f942ba2008-09-26 19:30:34493// static
494void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32495 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
496
497 WebPreferences pref_defaults;
498 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
499 pref_defaults.javascript_enabled);
500 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
501 pref_defaults.web_security_enabled);
502 prefs->RegisterBooleanPref(
503 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
504 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
505 pref_defaults.loads_images_automatically);
506 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
507 pref_defaults.plugins_enabled);
508 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
509 pref_defaults.dom_paste_enabled);
510 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
511 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14512 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32513 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
514 pref_defaults.text_areas_are_resizable);
515 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
516 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36517 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
518 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32519
520 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
521 IDS_ACCEPT_LANGUAGES);
522 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
523 IDS_DEFAULT_ENCODING);
524 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
525 IDS_STANDARD_FONT_IS_SERIF);
526 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
527 IDS_FIXED_FONT_FAMILY);
528 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
529 IDS_SERIF_FONT_FAMILY);
530 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
531 IDS_SANS_SERIF_FONT_FAMILY);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
533 IDS_CURSIVE_FONT_FAMILY);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
535 IDS_FANTASY_FONT_FAMILY);
536 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
537 IDS_DEFAULT_FONT_SIZE);
538 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
539 IDS_DEFAULT_FIXED_FONT_SIZE);
540 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
541 IDS_MINIMUM_FONT_SIZE);
542 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
543 IDS_MINIMUM_LOGICAL_FONT_SIZE);
544 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
545 IDS_USES_UNIVERSAL_DETECTOR);
546 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
547 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29548}
549
[email protected]13367f72009-07-08 16:39:02550// Returns true if contains content rendered by an extension.
551bool TabContents::HostsExtension() const {
552 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34553}
554
[email protected]cf28ec52010-04-09 22:56:34555AutoFillManager* TabContents::GetAutoFillManager() {
556 if (autofill_manager_.get() == NULL)
557 autofill_manager_.reset(new AutoFillManager(this));
558 return autofill_manager_.get();
559}
560
[email protected]6e95706d2009-04-23 22:55:01561PasswordManager* TabContents::GetPasswordManager() {
562 if (password_manager_.get() == NULL)
563 password_manager_.reset(new PasswordManager(this));
564 return password_manager_.get();
565}
566
567PluginInstaller* TabContents::GetPluginInstaller() {
568 if (plugin_installer_.get() == NULL)
569 plugin_installer_.reset(new PluginInstaller(this));
570 return plugin_installer_.get();
571}
572
[email protected]1f18184a2010-07-21 19:34:49573TabContentsSSLHelper* TabContents::GetSSLHelper() {
574 if (ssl_helper_.get() == NULL)
575 ssl_helper_.reset(new TabContentsSSLHelper(this));
576 return ssl_helper_.get();
577}
578
[email protected]8cb5d5b2010-02-09 11:36:16579RenderProcessHost* TabContents::GetRenderProcessHost() const {
580 return render_manager_.current_host()->process();
581}
582
[email protected]98aa0b52010-05-06 17:03:08583void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46584 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08585 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10586
[email protected]98aa0b52010-05-06 17:03:08587 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57588
[email protected]fca656c2010-02-10 20:30:10589 NotificationService::current()->Notify(
590 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
591 Source<TabContents>(this),
592 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49593}
594
[email protected]98aa0b52010-05-06 17:03:08595void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
596 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40597 return;
598
599 ExtensionsService* extension_service = profile()->GetExtensionsService();
600 if (extension_service && extension_service->is_ready()) {
601 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08602 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40603 if (extension)
[email protected]98aa0b52010-05-06 17:03:08604 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40605 }
606}
607
[email protected]98aa0b52010-05-06 17:03:08608SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08609 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51610 return NULL;
611
[email protected]98aa0b52010-05-06 17:03:08612 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51613}
614
[email protected]d5f942ba2008-09-26 19:30:34615const GURL& TabContents::GetURL() const {
616 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57617 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54618 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34619}
620
[email protected]96d185d2009-04-24 03:28:54621const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55622 // Transient entries take precedence. They are used for interstitial pages
623 // that are shown on top of existing pages.
624 NavigationEntry* entry = controller_.GetTransientEntry();
625 if (entry)
626 return entry->GetTitleForDisplay(&controller_);
627
[email protected]96d185d2009-04-24 03:28:54628 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
629 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
630 if (our_dom_ui) {
631 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55632 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54633 if (!(entry && entry->IsViewSourceMode())) {
634 // Give the DOM UI the chance to override our title.
635 const string16& title = our_dom_ui->overridden_title();
636 if (!title.empty())
637 return title;
638 }
639 }
640
641 // We use the title for the last committed entry rather than a pending
642 // navigation entry. For example, when the user types in a URL, we want to
643 // keep the old page's title until the new load has committed and we get a new
644 // title.
[email protected]96d185d2009-04-24 03:28:54645 entry = controller_.GetLastCommittedEntry();
646 if (entry)
647 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54648 return EmptyString16();
649}
650
[email protected]bbbc1ef2010-02-12 18:03:41651// static
652string16 TabContents::GetDefaultTitle() {
653 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
654}
655
[email protected]d5f942ba2008-09-26 19:30:34656int32 TabContents::GetMaxPageID() {
657 if (GetSiteInstance())
658 return GetSiteInstance()->max_page_id();
659 else
660 return max_page_id_;
661}
662
663void TabContents::UpdateMaxPageID(int32 page_id) {
664 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34665 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34666 // testing.
667 if (GetSiteInstance())
668 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16669 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34670}
671
[email protected]96d185d2009-04-24 03:28:54672SiteInstance* TabContents::GetSiteInstance() const {
673 return render_manager_.current_host()->site_instance();
674}
675
[email protected]96d185d2009-04-24 03:28:54676bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15677 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54678 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15679 if (entry && (entry->IsViewSourceMode() ||
680 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54681 return true;
[email protected]8ab24cc2009-11-13 20:56:15682 }
[email protected]83e3895b2009-06-11 00:07:16683
[email protected]96d185d2009-04-24 03:28:54684 DOMUI* dom_ui = GetDOMUIForCurrentState();
685 if (dom_ui)
686 return !dom_ui->should_hide_url();
687 return true;
688}
689
[email protected]d5f942ba2008-09-26 19:30:34690SkBitmap TabContents::GetFavIcon() const {
691 // Like GetTitle(), we also want to use the favicon for the last committed
692 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57693 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47694 if (entry)
695 return entry->favicon().bitmap();
696
[email protected]ce3fa3c2009-04-20 19:55:57697 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34698 if (entry)
699 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34700 return SkBitmap();
701}
702
[email protected]0b303cc2009-09-28 22:35:15703bool TabContents::FavIconIsValid() const {
704 NavigationEntry* entry = controller_.GetTransientEntry();
705 if (entry)
706 return entry->favicon().is_valid();
707
708 entry = controller_.GetLastCommittedEntry();
709 if (entry)
710 return entry->favicon().is_valid();
711
712 return false;
713}
714
[email protected]96d185d2009-04-24 03:28:54715bool TabContents::ShouldDisplayFavIcon() {
716 // Always display a throbber during pending loads.
717 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
718 return true;
719
720 DOMUI* dom_ui = GetDOMUIForCurrentState();
721 if (dom_ui)
722 return !dom_ui->hide_favicon();
723 return true;
724}
725
[email protected]96d185d2009-04-24 03:28:54726std::wstring TabContents::GetStatusText() const {
727 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
728 return std::wstring();
729
730 switch (load_state_) {
731 case net::LOAD_STATE_WAITING_FOR_CACHE:
732 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04733 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
734 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54735 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
736 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
737 case net::LOAD_STATE_RESOLVING_HOST:
738 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
739 case net::LOAD_STATE_CONNECTING:
740 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06741 case net::LOAD_STATE_SSL_HANDSHAKE:
742 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54743 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56744 if (upload_size_)
745 return l10n_util::GetStringF(
746 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
747 static_cast<int>((100 * upload_position_) / upload_size_));
748 else
749 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54750 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
751 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
752 load_state_host_);
753 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
754 case net::LOAD_STATE_IDLE:
755 case net::LOAD_STATE_READING_RESPONSE:
756 break;
757 }
758
759 return std::wstring();
760}
761
[email protected]d5f942ba2008-09-26 19:30:34762void TabContents::SetIsCrashed(bool state) {
763 if (state == is_crashed_)
764 return;
765
766 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50767 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34768}
769
[email protected]744ef172009-10-16 21:53:46770void TabContents::PageActionStateChanged() {
771 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00772}
[email protected]ce5c4502009-05-06 16:46:11773
[email protected]d5f942ba2008-09-26 19:30:34774void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
775 if (delegate_)
776 delegate_->NavigationStateChanged(this, changed_flags);
777}
778
[email protected]96d185d2009-04-24 03:28:54779void TabContents::DidBecomeSelected() {
780 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16781 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
782 if (rwhv) {
783 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43784#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16785 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43786#endif
787 }
[email protected]96d185d2009-04-24 03:28:54788
[email protected]8cb5d5b2010-02-09 11:36:16789 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54790}
791
792void TabContents::WasHidden() {
793 if (!capturing_contents()) {
794 // |render_view_host()| can be NULL if the user middle clicks a link to open
795 // a tab in then background, then closes the tab before selecting it. This
796 // is because closing the tab calls TabContents::Destroy(), which removes
797 // the |render_view_host()|; then when we actually destroy the window,
798 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16799 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
800 if (rwhv)
801 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54802 }
803
804 NotificationService::current()->Notify(
805 NotificationType::TAB_CONTENTS_HIDDEN,
806 Source<TabContents>(this),
807 NotificationService::NoDetails());
808}
809
[email protected]d5f942ba2008-09-26 19:30:34810void TabContents::Activate() {
811 if (delegate_)
812 delegate_->ActivateContents(this);
813}
814
[email protected]ea42e7782010-08-23 23:58:12815void TabContents::Deactivate() {
816 if (delegate_)
817 delegate_->DeactivateContents(this);
818}
819
[email protected]96d185d2009-04-24 03:28:54820void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16821 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
822 if (rwhv)
823 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54824}
825
826void TabContents::HideContents() {
827 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
828 // our superclass HideContents(), because some callers want to be very picky
829 // about the order in which these get called. In addition to making the code
830 // here practically impossible to understand, this also means we end up
831 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34832 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54833 WasHidden();
834}
835
[email protected]c0588052008-10-27 23:01:50836void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34837 WindowOpenDisposition disposition,
838 PageTransition::Type transition) {
839 if (delegate_)
[email protected]c0588052008-10-27 23:01:50840 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34841}
842
[email protected]1ccb3568d2010-02-19 10:51:16843bool TabContents::NavigateToPendingEntry(
844 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54845 const NavigationEntry& entry = *controller_.pending_entry();
846
847 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
848 if (!dest_render_view_host)
849 return false; // Unable to create the desired render view host.
850
[email protected]770dd8b2010-05-24 18:11:39851 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
852 dest_render_view_host->EnablePreferredSizeChangedMode(
853 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
854 }
[email protected]9fb325e2010-05-06 18:23:24855
[email protected]0352e5472010-04-29 00:11:40856 // For security, we should never send non-DOM-UI URLs (other than about:blank)
857 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58858 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40859 bool is_allowed_in_dom_ui_renderer =
860 DOMUIFactory::UseDOMUIForURL(entry.url()) ||
861 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58862 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40863 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58864
[email protected]96d185d2009-04-24 03:28:54865 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12866 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32867 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00868 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
869 dest_render_view_host,
870 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32871 }
[email protected]96d185d2009-04-24 03:28:54872
873 // Used for page load time metrics.
874 current_load_start_ = base::TimeTicks::Now();
875
876 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34877 ViewMsg_Navigate_Params navigate_params;
[email protected]3cc72b12010-03-18 23:03:00878 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34879 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54880
881 if (entry.page_id() == -1) {
882 // HACK!! This code suppresses javascript: URLs from being added to
883 // session history, which is what we want to do for javascript: URLs that
884 // do not generate content. What we really need is a message from the
885 // renderer telling us that a new page was not created. The same message
886 // could be used for mailto: URLs and the like.
887 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
888 return false;
889 }
890
891 // Clear any provisional password saves - this stops password infobars
892 // showing up on pages the user navigates to while the right page is
893 // loading.
894 GetPasswordManager()->ClearProvisionalSave();
895
[email protected]1ccb3568d2010-02-19 10:51:16896 if (reload_type != NavigationController::NO_RELOAD &&
897 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48898 FaviconService* favicon_service =
899 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
900 if (favicon_service)
901 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54902 }
903
[email protected]d5f942ba2008-09-26 19:30:34904 return true;
905}
906
[email protected]96d185d2009-04-24 03:28:54907void TabContents::Stop() {
908 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09909 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54910}
911
[email protected]96d185d2009-04-24 03:28:54912void TabContents::DisassociateFromPopupCount() {
913 render_view_host()->DisassociateFromPopupCount();
914}
915
916TabContents* TabContents::Clone() {
917 // We create a new SiteInstance so that the new tab won't share processes
918 // with the old one. This can be changed in the future if we need it to share
919 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32920 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54921 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21922 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54923 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08924 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08925 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54926 return tc;
927}
928
[email protected]4d677202009-07-19 07:37:12929void TabContents::ShowPageInfo(const GURL& url,
930 const NavigationEntry::SSLStatus& ssl,
931 bool show_history) {
932 if (!delegate_)
933 return;
934
[email protected]bb678332009-07-21 00:15:50935 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12936}
937
initial.commit09911bf2008-07-26 23:55:29938ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28939 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29940 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28941 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29942 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44943
944 if (child_windows_.size() == 1) {
945 window->ShowConstrainedWindow();
946 BlockTabContent(true);
947 }
948
initial.commit09911bf2008-07-26 23:55:29949 return window;
950}
951
[email protected]fa1cf0b82010-01-15 21:49:44952void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55953 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
954 if (rwhv)
955 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44956 render_view_host()->set_ignore_input_events(blocked);
957 if (delegate_)
958 delegate_->SetTabContentBlocked(this, blocked);
959}
960
initial.commit09911bf2008-07-26 23:55:29961void TabContents::AddNewContents(TabContents* new_contents,
962 WindowOpenDisposition disposition,
963 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29964 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29965 if (!delegate_)
966 return;
967
[email protected]35f7d212009-04-29 21:19:27968 if ((disposition == NEW_POPUP) && !user_gesture &&
969 !CommandLine::ForCurrentProcess()->HasSwitch(
970 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22971 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31972 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29973 delegate_->GetConstrainingContents(this)->AddPopup(
974 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31975 } else {
[email protected]304f8792009-08-19 21:28:09976#if defined(OS_CHROMEOS)
977 if (disposition == NEW_POPUP) {
978 // If the popup is bigger than a given factor of the screen, then
979 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11980 // Also check for width or height == 0, which would otherwise indicate
981 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09982 GdkScreen* screen = gdk_screen_get_default();
983 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
984 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11985 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
986 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09987 disposition = NEW_FOREGROUND_TAB;
988 }
989 }
990#endif
991
[email protected]0aa55312008-10-17 21:53:08992 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29993 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
994 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49995 NotificationService::current()->Notify(
996 NotificationType::TAB_ADDED,
997 Source<TabContentsDelegate>(delegate_),
998 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:29999 }
initial.commit09911bf2008-07-26 23:55:291000
[email protected]8cc8d492010-02-02 10:40:491001 // TODO(pkasting): Why is this necessary?
1002 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:291003}
1004
[email protected]bcd9dc42010-01-23 16:38:181005bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:201006 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:201007 bool is_js_code, const std::string& code_string,
1008 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511009 RenderViewHost* host = render_view_host();
1010 if (!host)
1011 return false;
1012
1013 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
1014 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
1015 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351016}
1017
[email protected]96d185d2009-04-24 03:28:541018void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491019 if (is_being_destroyed_)
1020 return;
[email protected]9fb83e82010-07-02 18:24:551021 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491022 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401023 render_view_host()->AllowScriptToClose(!visible);
[email protected]8e0bbf12010-07-20 00:03:431024 if (visible)
1025 PopupBlockedAnimation::Show(this);
[email protected]96d185d2009-04-24 03:28:541026}
1027
[email protected]5c9e97a2009-09-09 23:48:301028gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541029 return view_->GetContentNativeView();
1030}
1031
1032gfx::NativeView TabContents::GetNativeView() const {
1033 return view_->GetNativeView();
1034}
1035
1036void TabContents::GetContainerBounds(gfx::Rect *out) const {
1037 view_->GetContainerBounds(out);
1038}
1039
1040void TabContents::Focus() {
1041 view_->Focus();
1042}
1043
[email protected]90daadb42009-06-08 21:27:281044void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541045 if (showing_interstitial_page()) {
1046 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1047 return;
1048 }
[email protected]96d185d2009-04-24 03:28:541049 render_view_host()->SetInitialFocus(reverse);
1050}
1051
1052bool TabContents::FocusLocationBarByDefault() {
1053 DOMUI* dom_ui = GetDOMUIForCurrentState();
1054 if (dom_ui)
1055 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431056 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251057 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431058 return true;
[email protected]96d185d2009-04-24 03:28:541059 return false;
1060}
1061
[email protected]a26dc362010-04-23 01:48:581062void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381063 if (delegate())
[email protected]a26dc362010-04-23 01:48:581064 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381065}
1066
[email protected]616ed5a2008-11-21 22:27:241067void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321068 if (delegate_ && !delegate_->infobars_enabled()) {
1069 delegate->InfoBarClosed();
1070 return;
1071 }
1072
[email protected]616ed5a2008-11-21 22:27:241073 // Look through the existing InfoBarDelegates we have for a match. If we've
1074 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051075 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451076 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1077 // Tell the new infobar to close so that it can clean itself up.
1078 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241079 return;
[email protected]6d27a7b2009-12-18 23:25:451080 }
[email protected]616ed5a2008-11-21 22:27:241081 }
1082
1083 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561084 NotificationService::current()->Notify(
1085 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1086 Source<TabContents>(this),
1087 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241088
1089 // Add ourselves as an observer for navigations the first time a delegate is
1090 // added. We use this notification to expire InfoBars that need to expire on
1091 // page transitions.
1092 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561093 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571094 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241095 }
1096}
1097
1098void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321099 if (delegate_ && !delegate_->infobars_enabled()) {
1100 return;
1101 }
1102
[email protected]616ed5a2008-11-21 22:27:241103 std::vector<InfoBarDelegate*>::iterator it =
1104 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1105 if (it != infobar_delegates_.end()) {
1106 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561107 NotificationService::current()->Notify(
1108 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1109 Source<TabContents>(this),
1110 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241111
[email protected]cdadf6f2010-08-20 16:36:081112 // Just to be safe, make sure the delegate was not removed by an observer.
1113 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1114 if (it != infobar_delegates_.end()) {
1115 infobar_delegates_.erase(it);
1116 // Remove ourselves as an observer if we are tracking no more InfoBars.
1117 if (infobar_delegates_.empty()) {
1118 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1119 Source<NavigationController>(&controller_));
1120 }
1121 } else {
1122 // If you hit this NOTREACHED, please comment in bug
1123 // http://crbug.com/50428 how you got there.
1124 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031125 }
[email protected]616ed5a2008-11-21 22:27:241126 }
1127}
[email protected]3edd9522009-03-04 22:19:411128
[email protected]f81821c2009-08-07 01:29:471129void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1130 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321131 if (delegate_ && !delegate_->infobars_enabled()) {
1132 new_delegate->InfoBarClosed();
1133 return;
1134 }
1135
[email protected]f81821c2009-08-07 01:29:471136 std::vector<InfoBarDelegate*>::iterator it =
1137 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1138 DCHECK(it != infobar_delegates_.end());
1139
1140 // Notify the container about the change of plans.
1141 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1142 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1143 old_delegate, new_delegate));
1144 NotificationService::current()->Notify(
1145 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1146 Source<TabContents>(this),
1147 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1148
[email protected]cdadf6f2010-08-20 16:36:081149 // Just to be safe, make sure the delegate was not removed by an observer.
1150 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1151 if (it != infobar_delegates_.end()) {
1152 // Remove the old one.
1153 infobar_delegates_.erase(it);
1154 } else {
1155 // If you hit this NOTREACHED, please comment in bug
1156 // http://crbug.com/50428 how you got there.
1157 NOTREACHED();
1158 }
[email protected]f81821c2009-08-07 01:29:471159
1160 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081161 DCHECK(find(infobar_delegates_.begin(),
1162 infobar_delegates_.end(), new_delegate) ==
1163 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471164 infobar_delegates_.push_back(new_delegate);
1165}
1166
[email protected]20ede072009-10-06 00:28:351167bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271168 if (showing_interstitial_page())
1169 return false;
1170
[email protected]96d185d2009-04-24 03:28:541171 // See GetDOMUIForCurrentState() comment for more info. This case is very
1172 // similar, but for non-first loads, we want to use the committed entry. This
1173 // is so the bookmarks bar disappears at the same time the page does.
1174 if (controller_.GetLastCommittedEntry()) {
1175 // Not the first load, always use the committed DOM UI.
1176 if (render_manager_.dom_ui())
1177 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1178 return false; // Default.
1179 }
1180
1181 // When it's the first load, we know either the pending one or the committed
1182 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1183 // of them will be valid, so we can just check both.
1184 if (render_manager_.pending_dom_ui())
1185 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1186 if (render_manager_.dom_ui())
1187 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1188 return false; // Default.
1189}
1190
[email protected]3edd9522009-03-04 22:19:411191void TabContents::ToolbarSizeChanged(bool is_animating) {
1192 TabContentsDelegate* d = delegate();
1193 if (d)
1194 d->ToolbarSizeChanged(this, is_animating);
1195}
[email protected]616ed5a2008-11-21 22:27:241196
[email protected]fc6fb7fb2009-11-07 02:35:041197bool TabContents::CanDownload(int request_id) {
1198 TabContentsDelegate* d = delegate();
1199 if (d)
1200 return d->CanDownload(request_id);
1201 return true;
1202}
1203
[email protected]d5f942ba2008-09-26 19:30:341204void TabContents::OnStartDownload(DownloadItem* download) {
1205 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341206
1207 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311208 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341209
[email protected]5b928b62010-08-03 11:46:511210 if (tab_contents && tab_contents->delegate())
1211 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411212}
[email protected]3edd9522009-03-04 22:19:411213
[email protected]d5f942ba2008-09-26 19:30:341214void TabContents::WillClose(ConstrainedWindow* window) {
1215 ConstrainedWindowList::iterator it =
1216 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441217 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341218 if (it != child_windows_.end())
1219 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371220 if (child_windows_.size() > 0) {
1221 if (removed_topmost_window) {
1222 child_windows_[0]->ShowConstrainedWindow();
1223 }
[email protected]fa1cf0b82010-01-15 21:49:441224 BlockTabContent(true);
1225 } else {
1226 BlockTabContent(false);
1227 }
[email protected]66ba4932009-06-04 19:22:131228}
[email protected]d5f942ba2008-09-26 19:30:341229
[email protected]66ba4932009-06-04 19:22:131230void TabContents::WillCloseBlockedPopupContainer(
1231 BlockedPopupContainer* container) {
1232 DCHECK(blocked_popups_ == container);
1233 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491234 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341235}
1236
[email protected]d5f942ba2008-09-26 19:30:341237void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351238#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061239 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351240#endif
[email protected]d5f942ba2008-09-26 19:30:341241}
1242
[email protected]c1dc9f132009-11-20 23:13:211243void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121244 bool forward_direction,
1245 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211246 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011247 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211248 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531249 string16 last_search_prepopulate_text =
1250 FindBarState::GetLastPrepopulateText(profile());
1251
[email protected]87fae512009-12-11 02:20:211252 // Try the last thing we searched for on this tab, then the last thing
1253 // searched for on any tab.
1254 if (!previous_find_text_.empty())
1255 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531256 else if (!last_search_prepopulate_text.empty())
1257 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211258 else
[email protected]e491f1c2009-05-22 20:28:121259 return;
[email protected]e491f1c2009-05-22 20:28:121260 }
[email protected]6e95706d2009-04-23 22:55:011261
[email protected]101c90e2009-10-26 21:14:441262 // Keep track of the previous search.
1263 previous_find_text_ = find_text_;
1264
[email protected]6e95706d2009-04-23 22:55:011265 // This is a FindNext operation if we are searching for the same text again,
1266 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1267 // exception to this is if the Find was aborted (then we don't want FindNext
1268 // because the highlighting has been cleared and we need it to reappear). We
1269 // therefore treat FindNext after an aborted Find operation as a full fledged
1270 // Find.
[email protected]c1dc9f132009-11-20 23:13:211271 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121272 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011273 !find_op_aborted_;
1274 if (!find_next)
1275 current_find_request_id_ = find_request_id_counter_++;
1276
[email protected]c1dc9f132009-11-20 23:13:211277 if (!search_string.empty())
1278 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121279 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011280
1281 find_op_aborted_ = false;
1282
1283 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531284 FindBarState* find_bar_state = profile()->GetFindBarState();
1285 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011286 render_view_host()->StartFinding(current_find_request_id_,
1287 find_text_,
1288 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121289 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011290 find_next);
1291}
1292
[email protected]5bc8fe92010-03-11 18:19:001293void TabContents::StopFinding(
1294 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011295 if (selection_action == FindBarController::kClearSelection) {
1296 // kClearSelection means the find string has been cleared by the user, but
1297 // the UI has not been dismissed. In that case we want to clear the
1298 // previously remembered search (http://crbug.com/42639).
1299 previous_find_text_ = string16();
1300 } else {
[email protected]2d2dffc2009-06-09 21:41:001301 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011302 if (!find_text_.empty())
1303 previous_find_text_ = find_text_;
1304 }
[email protected]101c90e2009-10-26 21:14:441305 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011306 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121307 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001308 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011309}
1310
[email protected]420ae012009-04-24 05:16:321311void TabContents::OnSavePage() {
1312 // If we can not save the page, try to download it.
1313 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1314 DownloadManager* dlm = profile()->GetDownloadManager();
1315 const GURL& current_page_url = GetURL();
1316 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221317 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321318 return;
1319 }
1320
1321 Stop();
1322
1323 // Create the save package and possibly prompt the user for the name to save
1324 // the page as. The user prompt is an asynchronous operation that runs on
1325 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221326 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321327 save_package_->GetSaveInfo();
1328}
1329
1330// Used in automated testing to bypass prompting the user for file names.
1331// Instead, the names and paths are hard coded rather than running them through
1332// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111333bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321334 SavePackage::SavePackageType save_type) {
1335 // Stop the page from navigating.
1336 Stop();
1337
[email protected]828cabe2009-09-26 22:47:111338 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591339 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321340}
1341
[email protected]89d6e6e2009-12-03 23:06:511342void TabContents::EmailPageLocation() {
1343 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1344 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1345 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1346 title + "&body=%0A%0A" + page_url;
1347 platform_util::OpenExternal(GURL(mailto));
1348}
1349
[email protected]420ae012009-04-24 05:16:321350void TabContents::PrintPreview() {
1351 // We don't show the print preview yet, only the print dialog.
1352 PrintNow();
1353}
1354
1355bool TabContents::PrintNow() {
1356 // We can't print interstitial page for now.
1357 if (showing_interstitial_page())
1358 return false;
1359
1360 return render_view_host()->PrintPages();
1361}
1362
[email protected]82270452009-06-19 15:58:011363void TabContents::PrintingDone(int document_cookie, bool success) {
1364 render_view_host()->PrintingDone(document_cookie, success);
1365}
1366
[email protected]420ae012009-04-24 05:16:321367bool TabContents::IsActiveEntry(int32 page_id) {
1368 NavigationEntry* active_entry = controller_.GetActiveEntry();
1369 return (active_entry != NULL &&
1370 active_entry->site_instance() == GetSiteInstance() &&
1371 active_entry->page_id() == page_id);
1372}
1373
[email protected]b2fe07d12010-02-09 14:38:081374void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161375 set_encoding(encoding);
1376 render_view_host()->SetPageEncoding(encoding);
1377}
1378
[email protected]b2fe07d12010-02-09 14:38:081379void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161380 reset_encoding();
1381 render_view_host()->ResetPageEncodingToDefault();
1382}
1383
1384void TabContents::WindowMoveOrResizeStarted() {
1385 render_view_host()->WindowMoveOrResizeStarted();
1386}
1387
[email protected]3f8eb7f2009-10-02 23:58:051388void TabContents::LogNewTabTime(const std::string& event_name) {
1389 // Not all new tab pages get timed. In those cases, we don't have a
1390 // new_tab_start_time_.
1391 if (new_tab_start_time_.is_null())
1392 return;
1393
1394 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441395 MetricEventDurationDetails details(event_name,
1396 static_cast<int>(duration.InMilliseconds()));
1397
[email protected]7ab1e7d62009-10-14 23:32:011398 if (event_name == "Tab.NewTabScriptStart") {
1399 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1400 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1401 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1402 } else if (event_name == "Tab.NewTabOnload") {
1403 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051404 // The new tab page has finished loading; reset it.
1405 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441406 } else {
1407 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051408 }
[email protected]84abba62009-10-07 17:01:441409 NotificationService::current()->Notify(
1410 NotificationType::METRIC_EVENT_DURATION,
1411 Source<TabContents>(this),
1412 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051413}
1414
[email protected]7ab1e7d62009-10-14 23:32:011415void TabContents::OnCloseStarted() {
1416 if (tab_close_start_time_.is_null())
1417 tab_close_start_time_ = base::TimeTicks::Now();
1418}
1419
[email protected]46624bf2010-06-09 16:04:191420bool TabContents::ShouldAcceptDragAndDrop() const {
1421#if defined(OS_CHROMEOS)
1422 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1423 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561424 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191425#else
1426 return true;
1427#endif
1428}
1429
[email protected]c37e3b62010-01-22 00:15:171430TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171431 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161432
1433 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081434 if (extension_app_)
1435 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161436 else if (entry)
1437 tab_nav.SetFromNavigationEntry(*entry);
1438
[email protected]c37e3b62010-01-22 00:15:171439 std::vector<TabNavigation> navigations;
1440 navigations.push_back(tab_nav);
1441
1442 TabContents* new_contents =
1443 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081444 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171445 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171446
[email protected]98aa0b52010-05-06 17:03:081447 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161448 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1449
[email protected]c37e3b62010-01-22 00:15:171450 return new_contents;
1451}
1452
[email protected]ec0b6c42010-08-26 03:16:581453void TabContents::UpdateHistoryForNavigation(
1454 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1455 if (profile()->IsOffTheRecord())
1456 return;
1457
1458 // Add to history service.
1459 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1460 if (hs)
1461 hs->AddPage(*add_page_args);
1462}
1463
1464void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1465 if (profile()->IsOffTheRecord())
1466 return;
1467
1468 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1469 if (hs)
1470 hs->SetPageTitle(entry.virtual_url(), entry.title());
1471}
1472
[email protected]96d185d2009-04-24 03:28:541473// Notifies the RenderWidgetHost instance about the fact that the page is
1474// loading, or done loading and calls the base implementation.
1475void TabContents::SetIsLoading(bool is_loading,
1476 LoadNotificationDetails* details) {
1477 if (is_loading == is_loading_)
1478 return;
1479
1480 if (!is_loading) {
1481 load_state_ = net::LOAD_STATE_IDLE;
1482 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561483 upload_size_ = 0;
1484 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541485 }
1486
1487 render_manager_.SetIsLoading(is_loading);
1488
1489 is_loading_ = is_loading;
1490 waiting_for_response_ = is_loading;
1491
1492 if (delegate_)
1493 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351494 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541495
1496 NotificationType type = is_loading ? NotificationType::LOAD_START :
1497 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111498 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541499 if (details)
1500 det = Details<LoadNotificationDetails>(details);
1501 NotificationService::current()->Notify(type,
1502 Source<NavigationController>(&controller_),
1503 det);
1504}
1505
[email protected]b6c874582009-05-08 19:38:311506void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291507 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061508 // A page can't spawn popups (or do anything else, either) until its load
1509 // commits, so when we reach here, the popup was spawned by the
1510 // NavigationController's last committed entry, not the active entry. For
1511 // example, if a page opens a popup in an onunload() handler, then the active
1512 // entry is the page to be loaded as we navigate away from the unloading
1513 // page. For this reason, we can't use GetURL() to get the opener URL,
1514 // because it returns the active entry.
1515 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1516 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1517
1518 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491519 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091520 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491521 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1522 } else {
1523 if (!blocked_popups_)
1524 blocked_popups_ = new BlockedPopupContainer(this);
1525 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]55126132010-08-19 14:53:281526 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1527 std::string());
[email protected]8cc8d492010-02-02 10:40:491528 }
[email protected]b9681312008-11-07 00:08:261529}
[email protected]616ed5a2008-11-21 22:27:241530
1531namespace {
1532bool TransitionIsReload(PageTransition::Type transition) {
1533 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1534}
1535}
1536
1537void TabContents::ExpireInfoBars(
1538 const NavigationController::LoadCommittedDetails& details) {
1539 // Only hide InfoBars when the user has done something that makes the main
1540 // frame load. We don't want various automatic or subframe navigations making
1541 // it disappear.
1542 if (!details.is_user_initiated_main_frame_load())
1543 return;
1544
[email protected]f86a07022008-11-25 01:06:051545 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241546 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081547 if (!delegate) {
1548 // If you hit this NOTREACHED, please comment in bug
1549 // http://crbug.com/50428 how you got there.
1550 NOTREACHED();
1551 continue;
1552 }
1553
[email protected]f86a07022008-11-25 01:06:051554 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241555 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241556 }
1557}
[email protected]fdd61c62009-04-22 19:22:571558
[email protected]96d185d2009-04-24 03:28:541559DOMUI* TabContents::GetDOMUIForCurrentState() {
1560 // When there is a pending navigation entry, we want to use the pending DOMUI
1561 // that goes along with it to control the basic flags. For example, we want to
1562 // show the pending URL in the URL bar, so we want the display_url flag to
1563 // be from the pending entry.
1564 //
1565 // The confusion comes because there are multiple possibilities for the
1566 // initial load in a tab as a side effect of the way the RenderViewHostManager
1567 // works.
1568 //
1569 // - For the very first tab the load looks "normal". The new tab DOM UI is
1570 // the pending one, and we want it to apply here.
1571 //
1572 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1573 // get switched to the one previously associated with the new tab pages.
1574 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1575 // have a committed DOM UI in this case.
1576 //
1577 // This condition handles all of these cases:
1578 //
1579 // - First load in first tab: no committed nav entry + pending nav entry +
1580 // pending dom ui:
1581 // -> Use pending DOM UI if any.
1582 //
1583 // - First load in second tab: no committed nav entry + pending nav entry +
1584 // no pending DOM UI:
1585 // -> Use the committed DOM UI if any.
1586 //
1587 // - Second navigation in any tab: committed nav entry + pending nav entry:
1588 // -> Use pending DOM UI if any.
1589 //
1590 // - Normal state with no load: committed nav entry + no pending nav entry:
1591 // -> Use committed DOM UI.
1592 if (controller_.pending_entry() &&
1593 (controller_.GetLastCommittedEntry() ||
1594 render_manager_.pending_dom_ui()))
1595 return render_manager_.pending_dom_ui();
1596 return render_manager_.dom_ui();
1597}
[email protected]420ae012009-04-24 05:16:321598
1599void TabContents::DidNavigateMainFramePostCommit(
1600 const NavigationController::LoadCommittedDetails& details,
1601 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441602 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1603 // If this is a window.open navigation, use the same DOMUI as the renderer
1604 // that opened the window, as long as both renderers have the same
1605 // privileges.
1606 if (opener_dom_ui_type_ == DOMUIFactory::GetDOMUIType(GetURL())) {
1607 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1608 // dom_ui might be NULL if the URL refers to a non-existent extension.
1609 if (dom_ui) {
1610 render_manager_.SetDOMUIPostCommit(dom_ui);
1611 dom_ui->RenderViewCreated(render_view_host());
1612 }
1613 }
1614 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1615 }
1616
[email protected]420ae012009-04-24 05:16:321617 if (details.is_user_initiated_main_frame_load()) {
1618 // Clear the status bubble. This is a workaround for a bug where WebKit
1619 // doesn't let us know that the cursor left an element during a
1620 // transition (this is also why the mouse cursor remains as a hand after
1621 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1622 // clear the bubble when a user navigates to a named anchor in the same
1623 // page.
1624 UpdateTargetURL(details.entry->page_id(), GURL());
1625
1626 // UpdateHelpersForDidNavigate will handle the case where the password_form
1627 // origin is valid.
1628 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1629 // cleaned up and covered by tests.
1630 if (!params.password_form.origin.is_valid())
1631 GetPasswordManager()->DidNavigate();
1632 }
1633
1634 // The keyword generator uses the navigation entries, so must be called after
1635 // the commit.
1636 GenerateKeywordIfNecessary(params);
1637
1638 // Allow the new page to set the title again.
1639 received_page_title_ = false;
1640
1641 // Get the favicon, either from history or request it from the net.
1642 fav_icon_helper_.FetchFavIcon(details.entry->url());
1643
[email protected]0de80162010-02-03 04:52:351644 // Clear all page actions, blocked content notifications and browser actions
1645 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141646 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081647 ExtensionsService* service = profile()->GetExtensionsService();
1648 if (service) {
1649 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571650 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081651 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521652 if (browser_action) {
1653 browser_action->ClearAllValuesForTab(controller().session_id().id());
1654 NotificationService::current()->Notify(
1655 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571656 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521657 NotificationService::NoDetails());
1658 }
[email protected]92c6f9b92009-10-24 04:35:081659
[email protected]5d246db22009-10-27 06:17:571660 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521661 service->extensions()->at(i)->page_action();
1662 if (page_action) {
1663 page_action->ClearAllValuesForTab(controller().session_id().id());
1664 PageActionStateChanged();
1665 }
[email protected]92c6f9b92009-10-24 04:35:081666 }
[email protected]aece2c7f2009-08-27 20:43:171667 }
[email protected]0de80162010-02-03 04:52:351668
1669 // Close blocked popups.
1670 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341671 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351672 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461673 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351674 }
1675
1676 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411677 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551678 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471679
1680 // Once the main frame is navigated, we're no longer considered to have
1681 // displayed insecure content.
1682 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171683 }
[email protected]ce5c4502009-05-06 16:46:111684
[email protected]8cc8d492010-02-02 10:40:491685 // Close constrained windows if necessary.
1686 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1687 details.previous_url, details.entry->url()))
1688 CloseConstrainedWindows();
1689
[email protected]420ae012009-04-24 05:16:321690 // Update the starred state.
1691 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531692
1693 // Clear the cache of forms in AutoFill.
1694 if (autofill_manager_.get())
1695 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321696}
1697
1698void TabContents::DidNavigateAnyFramePostCommit(
1699 RenderViewHost* render_view_host,
1700 const NavigationController::LoadCommittedDetails& details,
1701 const ViewHostMsg_FrameNavigate_Params& params) {
1702 // If we navigate, start showing messages again. This does nothing to prevent
1703 // a malicious script from spamming messages, since the script could just
1704 // reload the page to stop blocking.
1705 suppress_javascript_messages_ = false;
1706
[email protected]420ae012009-04-24 05:16:321707 // Notify the password manager of the navigation or form submit.
1708 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1709 // cleaned up and covered by tests.
1710 if (params.password_form.origin.is_valid())
1711 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551712
1713 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581714 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321715}
1716
[email protected]8cc8d492010-02-02 10:40:491717void TabContents::CloseConstrainedWindows() {
1718 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321719 // We use indices instead of iterators in case CloseWindow does something
1720 // that may invalidate an iterator.
1721 int size = static_cast<int>(child_windows_.size());
1722 for (int i = size - 1; i >= 0; --i) {
1723 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441724 if (window) {
[email protected]420ae012009-04-24 05:16:321725 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441726 BlockTabContent(false);
1727 }
[email protected]420ae012009-04-24 05:16:321728 }
1729}
1730
1731void TabContents::UpdateStarredStateForCurrentURL() {
1732 BookmarkModel* model = profile()->GetBookmarkModel();
1733 const bool old_state = is_starred_;
1734 is_starred_ = (model && model->IsBookmarked(GetURL()));
1735
1736 if (is_starred_ != old_state && delegate())
1737 delegate()->URLStarredChanged(this, is_starred_);
1738}
1739
1740void TabContents::UpdateAlternateErrorPageURL() {
1741 GURL url = GetAlternateErrorPageURL();
1742 render_view_host()->SetAlternateErrorPageURL(url);
1743}
1744
1745void TabContents::UpdateWebPreferences() {
1746 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1747}
1748
1749void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1750 RenderViewHost* rvh) {
1751 // If we are creating a RVH for a restored controller, then we might
1752 // have more page IDs than the SiteInstance's current max page ID. We must
1753 // make sure that the max page ID is larger than any restored page ID.
1754 // Note that it is ok for conflicting page IDs to exist in another tab
1755 // (i.e., NavigationController), but if any page ID is larger than the max,
1756 // the back/forward list will get confused.
1757 int max_restored_page_id = controller_.max_restored_page_id();
1758 if (max_restored_page_id > 0) {
1759 int curr_max_page_id = site_instance->max_page_id();
1760 if (max_restored_page_id > curr_max_page_id) {
1761 // Need to update the site instance immediately.
1762 site_instance->UpdateMaxPageID(max_restored_page_id);
1763
1764 // Also tell the renderer to update its internal representation. We
1765 // need to reserve enough IDs to make all restored page IDs less than
1766 // the max.
1767 if (curr_max_page_id < 0)
1768 curr_max_page_id = 0;
1769 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1770 }
1771 }
1772}
1773
[email protected]ec0b6c42010-08-26 03:16:581774scoped_refptr<history::HistoryAddPageArgs>
1775TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541776 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471777 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321778 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581779 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1780 new history::HistoryAddPageArgs(
1781 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1782 params.redirects, params.transition, history::SOURCE_BROWSED,
1783 details.did_replace_entry));
1784 if (PageTransition::IsMainFrame(params.transition) &&
1785 virtual_url != params.url) {
1786 // Hack on the "virtual" URL so that it will appear in history. For some
1787 // types of URLs, we will display a magic URL that is different from where
1788 // the page is actually navigated. We want the user to see in history what
1789 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1790 // only applies to the main frame, as the virtual URL doesn't apply to
1791 // sub-frames.
1792 add_page_args->url = virtual_url;
1793 if (!add_page_args->redirects.empty())
1794 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321795 }
[email protected]ec0b6c42010-08-26 03:16:581796 return add_page_args;
[email protected]420ae012009-04-24 05:16:321797}
1798
1799bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1800 const std::wstring& title) {
1801 // For file URLs without a title, use the pathname instead. In the case of a
1802 // synthesized title, we don't want the update to count toward the "one set
1803 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251804 string16 final_title;
[email protected]420ae012009-04-24 05:16:321805 bool explicit_set;
1806 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251807 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321808 explicit_set = false; // Don't count synthetic titles toward the set limit.
1809 } else {
[email protected]e53668962010-06-23 15:35:251810 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321811 explicit_set = true;
1812 }
1813
[email protected]e53668962010-06-23 15:35:251814 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321815 return false; // Nothing changed, don't bother.
1816
[email protected]e53668962010-06-23 15:35:251817 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321818
[email protected]ec0b6c42010-08-26 03:16:581819 if (!received_page_title_) {
1820 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321821 received_page_title_ = explicit_set;
1822 }
1823
1824 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251825 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321826
[email protected]cbc0e1b2010-04-12 18:33:041827 NotificationService::current()->Notify(
1828 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1829 Source<TabContents>(this),
1830 NotificationService::NoDetails());
1831
[email protected]420ae012009-04-24 05:16:321832 return true;
1833}
1834
1835void TabContents::NotifySwapped() {
1836 // After sending out a swap notification, we need to send a disconnect
1837 // notification so that clients that pick up a pointer to |this| can NULL the
1838 // pointer. See Bug 1230284.
1839 notify_disconnection_ = true;
1840 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341841 NotificationType::TAB_CONTENTS_SWAPPED,
[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::NotifyConnected() {
1847 notify_disconnection_ = true;
1848 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341849 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221850 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321851 NotificationService::NoDetails());
1852}
1853
1854void TabContents::NotifyDisconnected() {
1855 if (!notify_disconnection_)
1856 return;
1857
1858 notify_disconnection_ = false;
1859 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341860 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221861 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321862 NotificationService::NoDetails());
1863}
1864
1865void TabContents::GenerateKeywordIfNecessary(
1866 const ViewHostMsg_FrameNavigate_Params& params) {
1867 if (!params.searchable_form_url.is_valid())
1868 return;
1869
1870 if (profile()->IsOffTheRecord())
1871 return;
1872
1873 int last_index = controller_.last_committed_entry_index();
1874 // When there was no previous page, the last index will be 0. This is
1875 // normally due to a form submit that opened in a new tab.
1876 // TODO(brettw) bug 916126: we should support keywords when form submits
1877 // happen in new tabs.
1878 if (last_index <= 0)
1879 return;
1880 const NavigationEntry* previous_entry =
1881 controller_.GetEntryAtIndex(last_index - 1);
1882 if (IsFormSubmit(previous_entry)) {
1883 // Only generate a keyword if the previous page wasn't itself a form
1884 // submit.
1885 return;
1886 }
1887
1888 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1889 previous_entry->user_typed_url() : previous_entry->url();
1890 std::wstring keyword =
1891 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1892 if (keyword.empty())
1893 return;
1894
1895 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1896 if (!url_model)
1897 return;
1898
1899 if (!url_model->loaded()) {
1900 url_model->Load();
1901 return;
1902 }
1903
1904 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191905 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321906 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1907 return;
1908
1909 if (current_url) {
1910 if (current_url->originating_url().is_valid()) {
1911 // The existing keyword was generated from an OpenSearch description
1912 // document, don't regenerate.
1913 return;
1914 }
1915 url_model->Remove(current_url);
1916 }
1917 TemplateURL* new_url = new TemplateURL();
1918 new_url->set_keyword(keyword);
1919 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191920 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321921 new_url->add_input_encoding(params.searchable_form_encoding);
1922 DCHECK(controller_.GetLastCommittedEntry());
1923 const GURL& favicon_url =
1924 controller_.GetLastCommittedEntry()->favicon().url();
1925 if (favicon_url.is_valid()) {
1926 new_url->SetFavIconURL(favicon_url);
1927 } else {
1928 // The favicon url isn't valid. This means there really isn't a favicon,
1929 // or the favicon url wasn't obtained before the load started. This assumes
1930 // the later.
1931 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1932 // its url.
1933 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1934 }
1935 new_url->set_safe_for_autoreplace(true);
1936 url_model->Add(new_url);
1937}
1938
[email protected]bf5c2ff392009-07-08 16:24:331939void TabContents::OnUserGesture() {
1940 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011941 DownloadRequestLimiter* limiter =
1942 g_browser_process->download_request_limiter();
1943 if (limiter)
1944 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261945 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331946}
1947
1948void TabContents::OnFindReply(int request_id,
1949 int number_of_matches,
1950 const gfx::Rect& selection_rect,
1951 int active_match_ordinal,
1952 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421953 // Ignore responses for requests that have been aborted.
1954 if (find_op_aborted_)
1955 return;
1956
[email protected]bf5c2ff392009-07-08 16:24:331957 // Ignore responses for requests other than the one we have most recently
1958 // issued. That way we won't act on stale results when the user has
1959 // already typed in another query.
1960 if (request_id != current_find_request_id_)
1961 return;
1962
1963 if (number_of_matches == -1)
1964 number_of_matches = last_search_result_.number_of_matches();
1965 if (active_match_ordinal == -1)
1966 active_match_ordinal = last_search_result_.active_match_ordinal();
1967
1968 gfx::Rect selection = selection_rect;
1969 if (selection.IsEmpty())
1970 selection = last_search_result_.selection_rect();
1971
1972 // Notify the UI, automation and any other observers that a find result was
1973 // found.
1974 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1975 selection, active_match_ordinal,
1976 final_update);
1977 NotificationService::current()->Notify(
1978 NotificationType::FIND_RESULT_AVAILABLE,
1979 Source<TabContents>(this),
1980 Details<FindNotificationDetails>(&last_search_result_));
1981}
1982
1983void TabContents::GoToEntryAtOffset(int offset) {
[email protected]f9cc4c452009-10-13 14:56:381984 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1985 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331986}
1987
[email protected]bf5c2ff392009-07-08 16:24:331988void TabContents::OnMissingPluginStatus(int status) {
1989#if defined(OS_WIN)
1990// TODO(PORT): pull in when plug-ins work
1991 GetPluginInstaller()->OnMissingPluginStatus(status);
1992#endif
1993}
1994
1995void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:331996 DCHECK(!plugin_path.value().empty());
1997
1998 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:351999#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:332000 scoped_ptr<FileVersionInfo> version_info(
2001 FileVersionInfo::CreateFileVersionInfo(plugin_path));
2002 if (version_info.get()) {
2003 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:372004 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:332005 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:372006#if defined(OS_MACOSX)
2007 // Many plugins on the Mac have .plugin in the actual name, which looks
2008 // terrible, so look for that and strip it off if present.
2009 const std::wstring plugin_extension(L".plugin");
2010 if (EndsWith(plugin_name, plugin_extension, true))
2011 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2012#endif // OS_MACOSX
2013 }
[email protected]bf5c2ff392009-07-08 16:24:332014 }
[email protected]4a560ed2009-07-13 23:35:262015#else
2016 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2017#endif
[email protected]2ae8a922010-06-28 20:27:532018 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2019 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332020 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582021 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2022 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532023 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332024}
2025
2026void TabContents::OnCrashedWorker() {
2027 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582028 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422029 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332030}
2031
2032void TabContents::OnDidGetApplicationInfo(
2033 int32 page_id,
2034 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512035 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332036
[email protected]ed5431872009-11-17 08:39:512037 if (delegate())
2038 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332039}
2040
[email protected]851b1eb2010-08-09 13:32:292041void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2042 const GURL& update_url) {
2043 new DisabledPluginInfoBar(this, name, update_url);
2044}
2045
[email protected]a2cf65eb2010-01-18 08:20:382046void TabContents::OnPageContents(const GURL& url,
2047 int renderer_process_id,
2048 int32 page_id,
[email protected]e5106202010-06-11 21:12:362049 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102050 const std::string& language,
2051 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382052 // Don't index any https pages. People generally don't want their bank
2053 // accounts, etc. indexed on their computer, especially since some of these
2054 // things are not marked cachable.
2055 // TODO(brettw) we may want to consider more elaborate heuristics such as
2056 // the cachability of the page. We may also want to consider subframes (this
2057 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272058 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2059 // content indexing for chromeos in some future releases.
2060#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382061 if (!url.SchemeIsSecure()) {
2062 Profile* p = profile();
2063 if (p && !p->IsOffTheRecord()) {
2064 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2065 if (hs)
2066 hs->SetPageContents(url, contents);
2067 }
2068 }
[email protected]ccd40a52010-05-11 16:15:272069#endif
[email protected]a8a81292010-01-21 00:32:452070
[email protected]1c57b7b2010-07-12 17:38:102071 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452072
2073 std::string lang = language;
2074 NotificationService::current()->Notify(
2075 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152076 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452077 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382078}
2079
[email protected]7e0831b2010-02-01 08:45:152080void TabContents::OnPageTranslated(int32 page_id,
2081 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162082 const std::string& translated_lang,
2083 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552084 language_state_.set_current_language(translated_lang);
2085 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162086 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152087 NotificationService::current()->Notify(
2088 NotificationType::PAGE_TRANSLATED,
2089 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162090 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152091}
2092
[email protected]bf5c2ff392009-07-08 16:24:332093void TabContents::DidStartProvisionalLoadForFrame(
2094 RenderViewHost* render_view_host,
2095 bool is_main_frame,
2096 const GURL& url) {
2097 ProvisionalLoadDetails details(is_main_frame,
2098 controller_.IsURLInPageNavigation(url),
2099 url, std::string(), false);
2100 NotificationService::current()->Notify(
2101 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2102 Source<NavigationController>(&controller_),
2103 Details<ProvisionalLoadDetails>(&details));
[email protected]da4f8a12010-08-19 08:33:412104 if (is_main_frame)
2105 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]bf5c2ff392009-07-08 16:24:332106}
2107
2108void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202109 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332110 NotificationService::current()->Notify(
2111 NotificationType::RESOURCE_RESPONSE_STARTED,
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
[email protected]3dbb80b2010-02-09 22:41:202116void TabContents::DidRedirectResource(
2117 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332118 NotificationService::current()->Notify(
2119 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2120 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202121 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332122}
2123
2124void TabContents::DidLoadResourceFromMemoryCache(
2125 const GURL& url,
2126 const std::string& frame_origin,
2127 const std::string& main_frame_origin,
2128 const std::string& security_info) {
2129 // Send out a notification that we loaded a resource from our memory cache.
[email protected]fc7de492010-07-12 14:49:042130 int cert_id = 0, cert_status = 0, security_bits = 0, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332131 SSLManager::DeserializeSecurityInfo(security_info,
2132 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042133 &security_bits,
2134 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332135 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162136 GetRenderProcessHost()->id(), cert_id,
2137 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332138
2139 NotificationService::current()->Notify(
2140 NotificationType::LOAD_FROM_MEMORY_CACHE,
2141 Source<NavigationController>(&controller_),
2142 Details<LoadFromMemoryCacheDetails>(&details));
2143}
2144
[email protected]e3d60e5d2009-09-25 21:08:292145void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472146 displayed_insecure_content_ = true;
2147 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292148}
2149
2150void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592151 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292152}
2153
[email protected]bf5c2ff392009-07-08 16:24:332154void TabContents::DidFailProvisionalLoadWithError(
2155 RenderViewHost* render_view_host,
2156 bool is_main_frame,
2157 int error_code,
2158 const GURL& url,
2159 bool showing_repost_interstitial) {
2160 if (net::ERR_ABORTED == error_code) {
2161 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2162 // This means that the interstitial won't be torn down properly, which is
2163 // bad. But if we have an interstitial, go back to another tab type, and
2164 // then load the same interstitial again, we could end up getting the first
2165 // interstitial's "failed" message (as a result of the cancel) when we're on
2166 // the second one.
2167 //
2168 // We can't tell this apart, so we think we're tearing down the current page
2169 // which will cause a crash later one. There is also some code in
2170 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2171 // out because of this problem.
2172 //
2173 // http://code.google.com/p/chromium/issues/detail?id=2855
2174 // Because this will not tear down the interstitial properly, if "back" is
2175 // back to another tab type, the interstitial will still be somewhat alive
2176 // in the previous tab type. If you navigate somewhere that activates the
2177 // tab with the interstitial again, you'll see a flash before the new load
2178 // commits of the interstitial page.
2179 if (showing_interstitial_page()) {
2180 LOG(WARNING) << "Discarding message during interstitial.";
2181 return;
2182 }
2183
2184 // This will discard our pending entry if we cancelled the load (e.g., if we
2185 // decided to download the file instead of load it). Only discard the
2186 // pending entry if the URLs match, otherwise the user initiated a navigate
2187 // before the page loaded so that the discard would discard the wrong entry.
2188 NavigationEntry* pending_entry = controller_.pending_entry();
2189 if (pending_entry && pending_entry->url() == url) {
2190 controller_.DiscardNonCommittedEntries();
2191 // Update the URL display.
2192 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2193 }
2194
2195 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2196 }
2197
2198 // Send out a notification that we failed a provisional load with an error.
2199 ProvisionalLoadDetails details(is_main_frame,
2200 controller_.IsURLInPageNavigation(url),
2201 url, std::string(), false);
2202 details.set_error_code(error_code);
2203
2204 NotificationService::current()->Notify(
2205 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2206 Source<NavigationController>(&controller_),
2207 Details<ProvisionalLoadDetails>(&details));
2208}
2209
2210void TabContents::DocumentLoadedInFrame() {
2211 controller_.DocumentLoadedInFrame();
2212}
2213
[email protected]dcd5b332010-08-11 08:55:182214void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562215 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242216 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562217}
2218
[email protected]8d3347f2009-07-09 22:00:212219RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322220 return view_.get();
2221}
2222
[email protected]8d3347f2009-07-09 22:00:212223RenderViewHostDelegate::RendererManagement*
2224TabContents::GetRendererManagementDelegate() {
2225 return &render_manager_;
2226}
2227
[email protected]bf5c2ff392009-07-08 16:24:332228RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212229 TabContents::GetBrowserIntegrationDelegate() {
2230 return this;
[email protected]bf5c2ff392009-07-08 16:24:332231}
2232
[email protected]8d3347f2009-07-09 22:00:212233RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2234 return this;
[email protected]bf5c2ff392009-07-08 16:24:332235}
2236
[email protected]46ba9082010-06-22 10:00:582237RenderViewHostDelegate::ContentSettings*
2238TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552239 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582240}
2241
[email protected]8d3347f2009-07-09 22:00:212242RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322243 return save_package_.get(); // May be NULL, but we can return NULL.
2244}
2245
[email protected]8d3347f2009-07-09 22:00:212246RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092247 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212248}
2249
2250RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2251 return &fav_icon_helper_;
2252}
2253
[email protected]e8dbd674b2010-03-11 18:34:402254RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452255 if (autocomplete_history_manager_.get() == NULL)
2256 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2257 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332258}
2259
[email protected]21674df2009-10-28 19:51:212260RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342261 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212262}
2263
[email protected]aad51d1c2010-08-05 08:38:092264RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2265 if (blocked_plugin_manager_.get() == NULL)
2266 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2267 return blocked_plugin_manager_.get();
2268}
2269
[email protected]1f18184a2010-07-21 19:34:492270RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2271 return GetSSLHelper();
2272}
2273
[email protected]b5977a0c2010-08-24 19:46:262274RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2275 if (file_select_helper_.get() == NULL)
2276 file_select_helper_.reset(new TabContentsFileSelectHelper(this));
2277 return file_select_helper_.get();
2278}
2279
[email protected]fd571bb2010-03-19 01:23:542280AutomationResourceRoutingDelegate*
2281TabContents::GetAutomationResourceRoutingDelegate() {
2282 return delegate();
2283}
2284
[email protected]ced90ae12010-02-20 02:06:162285RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2286 return bookmark_drag_;
2287}
2288
2289void TabContents::SetBookmarkDragDelegate(
2290 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2291 bookmark_drag_ = bookmark_drag;
2292}
2293
[email protected]9fb83e82010-07-02 18:24:552294TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2295 return content_settings_delegate_.get();
2296}
2297
[email protected]93623c5d2009-12-10 21:40:322298RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462299 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512300}
2301
[email protected]57c6a652009-05-04 07:58:342302TabContents* TabContents::GetAsTabContents() {
2303 return this;
2304}
2305
[email protected]7b291f92009-08-14 05:43:532306ViewType::Type TabContents::GetRenderViewType() const {
2307 return ViewType::TAB_CONTENTS;
2308}
2309
2310int TabContents::GetBrowserWindowID() const {
2311 return controller().window_id().id();
2312}
2313
[email protected]420ae012009-04-24 05:16:322314void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062315 NotificationService::current()->Notify(
2316 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2317 Source<TabContents>(this),
2318 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322319 NavigationEntry* entry = controller_.GetActiveEntry();
2320 if (!entry)
2321 return;
2322
2323 // When we're creating views, we're still doing initial setup, so we always
2324 // use the pending DOM UI rather than any possibly existing committed one.
2325 if (render_manager_.pending_dom_ui()) {
2326 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2327 }
2328
2329 if (entry->IsViewSourceMode()) {
2330 // Put the renderer in view source mode.
2331 render_view_host->Send(
2332 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2333 }
[email protected]0666aef2009-05-13 19:48:082334
2335 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322336}
2337
2338void TabContents::RenderViewReady(RenderViewHost* rvh) {
2339 if (rvh != render_view_host()) {
2340 // Don't notify the world, since this came from a renderer in the
2341 // background.
2342 return;
2343 }
2344
2345 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302346 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322347 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302348
2349 // Restore the focus to the tab (otherwise the focus will be on the top
2350 // window).
2351 if (was_crashed && !FocusLocationBarByDefault())
2352 Focus();
[email protected]420ae012009-04-24 05:16:322353}
2354
2355void TabContents::RenderViewGone(RenderViewHost* rvh) {
2356 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092357 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322358 return;
2359 if (rvh != render_view_host()) {
2360 // The pending page's RenderViewHost is gone.
2361 return;
2362 }
2363
2364 SetIsLoading(false, NULL);
2365 NotifyDisconnected();
2366 SetIsCrashed(true);
2367
[email protected]ff9efc62010-02-18 22:10:542368 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212369 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542370 RemoveInfoBar(GetInfoBarDelegateAt(i));
2371
[email protected]8e537302009-06-10 21:19:582372 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552373 // Only do this if we're not in browser shutdown, so that TabContents
2374 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2375 // visible do not flash a sad tab page.
2376 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2377 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322378
2379 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002380 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322381}
2382
[email protected]2e4633c2009-07-09 16:58:062383void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2384 NotificationService::current()->Notify(
2385 NotificationType::RENDER_VIEW_HOST_DELETED,
2386 Source<TabContents>(this),
2387 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482388 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062389}
2390
[email protected]420ae012009-04-24 05:16:322391void TabContents::DidNavigate(RenderViewHost* rvh,
2392 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372393 int extra_invalidate_flags = 0;
2394
2395 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352396 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372397
[email protected]420ae012009-04-24 05:16:322398 render_manager_.DidNavigateMainFrame(rvh);
2399
[email protected]20ede072009-10-06 00:28:352400 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372401 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372402 }
2403
[email protected]420ae012009-04-24 05:16:322404 // Update the site of the SiteInstance if it doesn't have one yet.
2405 if (!GetSiteInstance()->has_site())
2406 GetSiteInstance()->SetSite(params.url);
2407
2408 // Need to update MIME type here because it's referred to in
2409 // UpdateNavigationCommands() called by RendererDidNavigate() to
2410 // determine whether or not to enable the encoding menu.
2411 // It's updated only for the main frame. For a subframe,
2412 // RenderView::UpdateURL does not set params.contents_mime_type.
2413 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2414 // TODO(jungshik): Add a test for the encoding menu to avoid
2415 // regressing it again.
2416 if (PageTransition::IsMainFrame(params.transition))
2417 contents_mime_type_ = params.contents_mime_type;
2418
2419 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372420 bool did_navigate = controller_.RendererDidNavigate(
2421 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392422
2423 // Update history. Note that this needs to happen after the entry is complete,
2424 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582425 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392426 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582427 // URLs, we use a data: URL as the real value. We actually want to save the
2428 // about: URL to the history db and keep the data: URL hidden. This is what
2429 // the TabContents' URL getter does.
2430 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2431 CreateHistoryAddPageArgs(GetURL(), details, params));
2432 if (!delegate() ||
2433 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2434 details.type)) {
2435 UpdateHistoryForNavigation(add_page_args);
2436 }
[email protected]3e90d4a2009-07-03 17:38:392437 }
2438
[email protected]76543b92009-08-31 17:27:452439 if (!did_navigate)
2440 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322441
2442 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2443 // for the appropriate notification (best) or you can add it to
2444 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2445 // necessary, please).
2446
2447 // Run post-commit tasks.
2448 if (details.is_main_frame)
2449 DidNavigateMainFramePostCommit(details, params);
2450 DidNavigateAnyFramePostCommit(rvh, details, params);
2451}
2452
2453void TabContents::UpdateState(RenderViewHost* rvh,
2454 int32 page_id,
2455 const std::string& state) {
2456 DCHECK(rvh == render_view_host());
2457
2458 // We must be prepared to handle state updates for any page, these occur
2459 // when the user is scrolling and entering form data, as well as when we're
2460 // leaving a page, in which case our state may have already been moved to
2461 // the next page. The navigation controller will look up the appropriate
2462 // NavigationEntry and update it when it is notified via the delegate.
2463
2464 int entry_index = controller_.GetEntryIndexWithPageID(
2465 GetSiteInstance(), page_id);
2466 if (entry_index < 0)
2467 return;
2468 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2469
2470 if (state == entry->content_state())
2471 return; // Nothing to update.
2472 entry->set_content_state(state);
2473 controller_.NotifyEntryChanged(entry, entry_index);
2474}
2475
2476void TabContents::UpdateTitle(RenderViewHost* rvh,
2477 int32 page_id, const std::wstring& title) {
2478 // If we have a title, that's a pretty good indication that we've started
2479 // getting useful data.
2480 SetNotWaitingForResponse();
2481
2482 DCHECK(rvh == render_view_host());
2483 NavigationEntry* entry = controller_.GetEntryWithPageID(GetSiteInstance(),
[email protected]ec0b6c42010-08-26 03:16:582484 page_id);
[email protected]420ae012009-04-24 05:16:322485 if (!entry || !UpdateTitleForEntry(entry, title))
2486 return;
2487
2488 // Broadcast notifications when the UI should be updated.
2489 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032490 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322491}
2492
[email protected]420ae012009-04-24 05:16:322493void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402494 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322495 set_encoding(encoding);
2496}
2497
2498void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2499 if (delegate())
2500 delegate()->UpdateTargetURL(this, url);
2501}
2502
2503void TabContents::UpdateThumbnail(const GURL& url,
2504 const SkBitmap& bitmap,
2505 const ThumbnailScore& score) {
2506 // Tell History about this thumbnail
[email protected]9ba208092010-08-10 20:02:082507 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492508 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422509 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282510 } else {
2511 HistoryService* hs;
2512 if (!profile()->IsOffTheRecord() &&
2513 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2514 hs->SetPageThumbnail(url, bitmap, score);
2515 }
[email protected]420ae012009-04-24 05:16:322516 }
2517}
2518
[email protected]c4e98902010-06-01 10:20:142519void TabContents::UpdateInspectorSetting(const std::string& key,
2520 const std::string& value) {
2521 DictionaryValue* inspector_settings =
2522 profile()->GetPrefs()->GetMutableDictionary(
2523 prefs::kWebKitInspectorSettings);
[email protected]8b6e84a2010-08-14 03:32:172524 inspector_settings->SetWithoutPathExpansion(key,
[email protected]628cf5a52010-06-07 14:25:332525 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082526}
2527
[email protected]45aafc92010-06-07 14:18:532528void TabContents::ClearInspectorSettings() {
2529 DictionaryValue* inspector_settings =
2530 profile()->GetPrefs()->GetMutableDictionary(
2531 prefs::kWebKitInspectorSettings);
2532 inspector_settings->Clear();
2533}
2534
[email protected]420ae012009-04-24 05:16:322535void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292536 // The UI may be in an event-tracking loop, such as between the
2537 // mouse-down and mouse-up in text selection or a button click.
2538 // Defer the close until after tracking is complete, so that we
2539 // don't free objects out from under the UI.
2540 // TODO(shess): This could probably be integrated with the
2541 // IsDoingDrag() test below. Punting for now because I need more
2542 // research to understand how this impacts platforms other than Mac.
2543 // TODO(shess): This could get more fine-grained. For instance,
2544 // closing a tab in another window while selecting text in the
2545 // current window's Omnibox should be just fine.
2546 if (view()->IsEventTracking()) {
2547 view()->CloseTabAfterEventTracking();
2548 return;
2549 }
2550
[email protected]24a4d1062009-07-10 23:10:422551 // If we close the tab while we're in the middle of a drag, we'll crash.
2552 // Instead, cancel the drag and close it as soon as the drag ends.
2553 if (view()->IsDoingDrag()) {
2554 view()->CancelDragAndCloseTab();
2555 return;
2556 }
2557
[email protected]420ae012009-04-24 05:16:322558 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2559 if (delegate() && rvh == render_view_host())
2560 delegate()->CloseContents(this);
2561}
2562
2563void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2564 if (delegate() && delegate()->IsPopup(this))
2565 delegate()->MoveContents(this, new_bounds);
2566}
2567
[email protected]7ab1e7d62009-10-14 23:32:012568void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382569 // By default, we assume that the content is not PDF. The renderer
2570 // will tell us if this is not the case.
2571 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322572 SetIsLoading(true, NULL);
2573}
2574
[email protected]7ab1e7d62009-10-14 23:32:012575void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322576 scoped_ptr<LoadNotificationDetails> details;
2577
2578 NavigationEntry* entry = controller_.GetActiveEntry();
2579 // An entry may not exist for a stop when loading an initial blank page or
2580 // if an iframe injected by script into a blank page finishes loading.
2581 if (entry) {
[email protected]420ae012009-04-24 05:16:322582 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2583
2584 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542585 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322586 entry->transition_type(),
2587 elapsed,
2588 &controller_,
2589 controller_.GetCurrentEntryIndex()));
2590 }
2591
2592 // Tell PasswordManager we've finished a page load, which serves as a
2593 // green light to save pending passwords and reset itself.
2594 GetPasswordManager()->DidStopLoading();
2595
2596 SetIsLoading(false, details.get());
2597}
2598
[email protected]420ae012009-04-24 05:16:322599void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2600 const GURL& source_url,
2601 const GURL& target_url) {
2602 NavigationEntry* entry;
2603 if (page_id == -1)
2604 entry = controller_.pending_entry();
2605 else
2606 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2607 if (!entry || entry->url() != source_url)
2608 return;
2609 entry->set_url(target_url);
2610}
2611
[email protected]420ae012009-04-24 05:16:322612void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2613 WindowOpenDisposition disposition) {
2614 if (render_manager_.dom_ui()) {
2615 // When we're a DOM UI, it will provide a page transition type for us (this
2616 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2617 // generated suggestions).
2618 //
2619 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162620 // want web sites to see a referrer of "chrome://blah" (and some
2621 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322622 // send to the site), so we send no referrer.
2623 OpenURL(url, GURL(), disposition,
2624 render_manager_.dom_ui()->link_transition_type());
2625 } else {
2626 OpenURL(url, referrer, disposition, PageTransition::LINK);
2627 }
2628}
2629
[email protected]1ee614862009-07-06 20:29:182630void TabContents::DomOperationResponse(const std::string& json_string,
2631 int automation_id) {
2632}
2633
[email protected]8b8e7c92010-08-19 18:05:562634void TabContents::ProcessDOMUIMessage(
2635 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322636 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442637 // This can happen if someone uses window.open() to open an extension URL
2638 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562639 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322640 return;
2641 }
[email protected]8b8e7c92010-08-19 18:05:562642 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322643}
2644
2645void TabContents::ProcessExternalHostMessage(const std::string& message,
2646 const std::string& origin,
2647 const std::string& target) {
2648 if (delegate())
2649 delegate()->ForwardMessageToExternalHost(message, origin, target);
2650}
2651
[email protected]420ae012009-04-24 05:16:322652void TabContents::RunJavaScriptMessage(
2653 const std::wstring& message,
2654 const std::wstring& default_prompt,
2655 const GURL& frame_url,
2656 const int flags,
2657 IPC::Message* reply_msg,
2658 bool* did_suppress_message) {
2659 // Suppress javascript messages when requested and when inside a constrained
2660 // popup window (because that activates them and breaks them out of the
2661 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552662 // Also suppress messages when showing an interstitial. The interstitial is
2663 // shown over the previous page, we don't want the hidden page dialogs to
2664 // interfere with the interstitial.
2665 bool suppress_this_message = suppress_javascript_messages_ ||
2666 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322667 if (delegate())
2668 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312669 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322670
2671 *did_suppress_message = suppress_this_message;
2672
2673 if (!suppress_this_message) {
2674 base::TimeDelta time_since_last_message(
2675 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2676 bool show_suppress_checkbox = false;
2677 // Show a checkbox offering to suppress further messages if this message is
2678 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2679 if (time_since_last_message <
2680 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2681 show_suppress_checkbox = true;
2682
[email protected]d82ed61e2009-06-16 02:46:222683 RunJavascriptMessageBox(this, frame_url, flags, message, default_prompt,
[email protected]420ae012009-04-24 05:16:322684 show_suppress_checkbox, reply_msg);
2685 } else {
2686 // If we are suppressing messages, just reply as is if the user immediately
2687 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542688 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322689 }
2690}
2691
2692void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2693 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012694 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222695 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322696}
2697
2698void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2699 const std::string& json_arguments,
2700 IPC::Message* reply_msg) {
2701 if (delegate()) {
2702 HtmlDialogUIDelegate* dialog_delegate =
2703 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222704 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322705 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2706 }
2707}
2708
[email protected]4d44a1c2010-04-28 19:20:412709void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562710 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412711 GetPasswordManager()->PasswordFormsFound(forms);
2712}
2713
2714void TabContents::PasswordFormsVisible(
2715 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2716 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322717}
2718
[email protected]420ae012009-04-24 05:16:322719// Checks to see if we should generate a keyword based on the OSDD, and if
2720// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2721void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2722 int32 page_id, const GURL& url,
2723 bool autodetected) {
2724 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2725 DCHECK(url.is_valid());
2726 if (!IsActiveEntry(page_id))
2727 return;
2728 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2729 if (!url_model)
2730 return;
2731 if (!url_model->loaded()) {
2732 url_model->Load();
2733 return;
2734 }
2735 if (!profile()->GetTemplateURLFetcher())
2736 return;
2737
2738 if (profile()->IsOffTheRecord())
2739 return;
2740
2741 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2742 DCHECK(entry);
2743
2744 const NavigationEntry* base_entry = entry;
2745 if (IsFormSubmit(base_entry)) {
2746 // If the current page is a form submit, find the last page that was not
2747 // a form submit and use its url to generate the keyword from.
2748 int index = controller_.last_committed_entry_index() - 1;
2749 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2750 index--;
2751 if (index >= 0)
2752 base_entry = controller_.GetEntryAtIndex(index);
2753 else
2754 base_entry = NULL;
2755 }
2756
2757 // We want to use the user typed URL if available since that represents what
2758 // the user typed to get here, and fall back on the regular URL if not.
2759 if (!base_entry)
2760 return;
2761 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2762 base_entry->user_typed_url() : base_entry->url();
2763 if (!keyword_url.is_valid())
2764 return;
2765 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2766 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532767
2768 // For JS added OSDD empty keyword is OK because we will generate keyword
2769 // later from OSDD content.
2770 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322771 return;
2772 const TemplateURL* template_url =
2773 url_model->GetTemplateURLForKeyword(keyword);
2774 if (template_url && (!template_url->safe_for_autoreplace() ||
2775 template_url->originating_url() == url)) {
2776 // Either there is a user created TemplateURL for this keyword, or the
2777 // keyword has the same OSDD url and we've parsed it.
2778 return;
2779 }
2780
2781 // Download the OpenSearch description document. If this is successful a
2782 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322783 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2784 keyword,
2785 url,
2786 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162787 this,
[email protected]420ae012009-04-24 05:16:322788 autodetected);
2789}
2790
[email protected]420ae012009-04-24 05:16:322791GURL TabContents::GetAlternateErrorPageURL() const {
2792 GURL url;
2793 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2794 if (profile()->IsOffTheRecord())
2795 return url;
2796
2797 PrefService* prefs = profile()->GetPrefs();
2798 DCHECK(prefs);
2799 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152800 url = google_util::AppendGoogleLocaleParam(
2801 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322802 url = google_util::AppendGoogleTLDParam(url);
2803 }
2804 return url;
2805}
2806
2807WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062808 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552809 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062810 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322811}
2812
[email protected]fa1cf0b82010-01-15 21:49:442813void TabContents::OnIgnoredUIEvent() {
2814 if (constrained_window_count()) {
2815 ConstrainedWindow* window = *constrained_window_begin();
2816 window->FocusConstrainedWindow();
2817 }
2818}
2819
[email protected]420ae012009-04-24 05:16:322820void TabContents::OnJSOutOfMemory() {
2821 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582822 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2823 NULL, true));
[email protected]420ae012009-04-24 05:16:322824}
2825
[email protected]420ae012009-04-24 05:16:322826void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2827 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342828 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322829 // delivered to a pending RenderViewHost. We must first run the onunload
2830 // handler of the old RenderViewHost before we can allow it to proceed.
2831 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2832 new_request_id);
2833}
2834
[email protected]420ae012009-04-24 05:16:322835gfx::Rect TabContents::GetRootWindowResizerRect() const {
2836 if (delegate())
2837 return delegate()->GetRootWindowResizerRect();
2838 return gfx::Rect();
2839}
2840
2841void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2842 bool is_during_unload) {
2843 if (is_during_unload) {
2844 // Hang occurred while firing the beforeunload/unload handler.
2845 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112846 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322847
2848 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2849 return;
2850
2851 // If the tab hangs in the beforeunload/unload handler there's really
2852 // nothing we can do to recover. Pretend the unload listeners have
2853 // all fired and close the tab. If the hang is in the beforeunload handler
2854 // then the user will not have the option of cancelling the close.
2855 Close(rvh);
2856 return;
2857 }
2858
2859 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002860 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322861}
2862
2863void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002864 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322865}
2866
2867void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562868 net::LoadState load_state,
2869 uint64 upload_position,
2870 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322871 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562872 upload_position_ = upload_position;
2873 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292874 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192875 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292876 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532877 load_state_host_ =
2878 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322879 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2880 SetNotWaitingForResponse();
2881 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502882 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322883}
2884
[email protected]1ee614862009-07-06 20:29:182885bool TabContents::IsExternalTabContainer() const {
2886 if (!delegate())
2887 return false;
2888
2889 return delegate()->IsExternalTabContainer();
2890}
2891
[email protected]1ee614862009-07-06 20:29:182892void TabContents::DidInsertCSS() {
2893 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322894}
2895
[email protected]130efb02009-09-18 18:54:352896void TabContents::FocusedNodeChanged() {
2897 NotificationService::current()->Notify(
2898 NotificationType::FOCUS_CHANGED_IN_PAGE,
2899 Source<RenderViewHost>(render_view_host()),
2900 NotificationService::NoDetails());
2901}
2902
[email protected]ebf40a72010-07-22 01:46:382903void TabContents::SetDisplayingPDFContent() {
2904 displaying_pdf_content_ = true;
2905 if (delegate())
2906 delegate()->ContentTypeChanged(this);
2907}
2908
[email protected]420ae012009-04-24 05:16:322909void TabContents::BeforeUnloadFiredFromRenderManager(
2910 bool proceed,
2911 bool* proceed_to_fire_unload) {
2912 if (delegate())
2913 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2914}
2915
[email protected]3a3d47472010-07-15 21:03:542916void TabContents::DidStartLoadingFromRenderManager(
2917 RenderViewHost* render_view_host) {
2918 DidStartLoading();
2919}
2920
2921void TabContents::RenderViewGoneFromRenderManager(
2922 RenderViewHost* render_view_host) {
2923 RenderViewGone(render_view_host);
2924}
2925
[email protected]420ae012009-04-24 05:16:322926void TabContents::UpdateRenderViewSizeForRenderManager() {
2927 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262928 gfx::Size size = view_->GetContainerSize();
2929 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2930 // here during container initialization and normal window size will be set
2931 // later. In case of tab duplication this resizing to 0x0 prevents setting
2932 // normal size later so just ignore it.
2933 if (!size.IsEmpty())
2934 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322935}
2936
[email protected]3a3d47472010-07-15 21:03:542937void TabContents::NotifySwappedFromRenderManager() {
2938 NotifySwapped();
2939}
2940
2941NavigationController& TabContents::GetControllerForRenderManager() {
2942 return controller();
2943}
2944
[email protected]420ae012009-04-24 05:16:322945DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222946 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322947}
2948
2949NavigationEntry*
2950TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2951 return controller_.GetLastCommittedEntry();
2952}
2953
2954bool TabContents::CreateRenderViewForRenderManager(
2955 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322956 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522957
[email protected]674b3822010-08-04 04:02:512958 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322959 return false;
2960
2961 // Now that the RenderView has been created, we need to tell it its size.
2962 rwh_view->SetSize(view_->GetContainerSize());
2963
2964 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2965 render_view_host);
2966 return true;
2967}
2968
2969void TabContents::Observe(NotificationType type,
2970 const NotificationSource& source,
2971 const NotificationDetails& details) {
2972 switch (type.value) {
2973 case NotificationType::BOOKMARK_MODEL_LOADED:
2974 // BookmarkModel finished loading, fall through to update starred state.
2975 case NotificationType::URLS_STARRED: {
2976 // Somewhere, a URL has been starred.
2977 // Ignore notifications for profiles other than our current one.
2978 Profile* source_profile = Source<Profile>(source).ptr();
2979 if (!source_profile || !source_profile->IsSameProfile(profile()))
2980 return;
2981
2982 UpdateStarredStateForCurrentURL();
2983 break;
2984 }
2985 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512986 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322987 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2988 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2989 UpdateAlternateErrorPageURL();
2990 } else if (*pref_name_in == prefs::kDefaultCharset ||
[email protected]57ecc4b2010-08-11 03:02:512991 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)
[email protected]420ae012009-04-24 05:16:322992 ) {
2993 UpdateWebPreferences();
2994 } else {
2995 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2996 }
2997 break;
2998 }
2999 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3000 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3001 break;
3002
3003 case NotificationType::NAV_ENTRY_COMMITTED: {
3004 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3005
3006 NavigationController::LoadCommittedDetails& committed_details =
3007 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3008 ExpireInfoBars(committed_details);
3009 break;
3010 }
3011
[email protected]d3ba77272009-09-03 00:06:093012#if defined(OS_LINUX)
3013 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543014 renderer_preferences_util::UpdateFromSystemSettings(
3015 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093016 render_view_host()->SyncRendererPrefs();
3017 break;
3018 }
3019#endif
3020
[email protected]6c32ce72010-03-08 05:18:063021 case NotificationType::USER_STYLE_SHEET_UPDATED:
3022 UpdateWebPreferences();
3023 break;
3024
[email protected]79580c62010-02-02 02:36:253025 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293026 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253027 settings_details(details);
[email protected]79580c62010-02-02 02:36:253028 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493029 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293030 if (entry)
[email protected]da0c8e92010-02-09 23:25:493031 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293032 if (settings_details.ptr()->update_all() ||
3033 settings_details.ptr()->pattern().Matches(entry_url)) {
3034 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233035 profile()->GetHostContentSettingsMap()->
3036 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253037 }
3038 break;
3039 }
3040
[email protected]e5adff72010-06-14 18:13:063041 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573042 break;
[email protected]a888b29e62010-04-01 13:38:573043
3044 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063045 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573046 break;
[email protected]a888b29e62010-04-01 13:38:573047
[email protected]420ae012009-04-24 05:16:323048 default:
3049 NOTREACHED();
3050 }
3051}
[email protected]aacd7cc2009-09-02 14:51:103052
[email protected]98aa0b52010-05-06 17:03:083053void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3054 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433055
[email protected]a888b29e62010-04-01 13:38:573056 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083057 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3058 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573059 extension,
[email protected]5351dbc2010-08-27 15:22:113060 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH),
[email protected]a888b29e62010-04-01 13:38:573061 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3062 Extension::EXTENSION_ICON_SMALLISH),
3063 ImageLoadingTracker::CACHE);
3064 } else {
[email protected]98aa0b52010-05-06 17:03:083065 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573066 }
3067}
3068
3069Extension* TabContents::GetExtensionContaining(const GURL& url) {
3070 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3071 if (!extensions_service)
3072 return NULL;
3073
3074 Extension* extension = extensions_service->GetExtensionByURL(url);
3075 return extension ?
3076 extension : extensions_service->GetExtensionByWebExtent(url);
3077}
3078
[email protected]a888b29e62010-04-01 13:38:573079void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3080 int index) {
3081 if (image) {
[email protected]98aa0b52010-05-06 17:03:083082 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573083 NotifyNavigationStateChanged(INVALIDATE_TAB);
3084 }
3085}
3086
[email protected]beb440c2009-11-06 04:08:543087std::wstring TabContents::GetMessageBoxTitle(const GURL& frame_url,
3088 bool is_alert) {
3089 if (!frame_url.has_host())
3090 return l10n_util::GetString(
3091 is_alert ? IDS_JAVASCRIPT_ALERT_DEFAULT_TITLE
3092 : IDS_JAVASCRIPT_MESSAGEBOX_DEFAULT_TITLE);
3093
3094 // We really only want the scheme, hostname, and port.
3095 GURL::Replacements replacements;
3096 replacements.ClearUsername();
3097 replacements.ClearPassword();
3098 replacements.ClearPath();
3099 replacements.ClearQuery();
3100 replacements.ClearRef();
3101 GURL clean_url = frame_url.ReplaceComponents(replacements);
3102
3103 // TODO(brettw) it should be easier than this to do the correct language
3104 // handling without getting the accept language from the profile.
[email protected]70edb862010-08-18 16:23:183105 string16 base_address = WideToUTF16(gfx::ElideUrl(clean_url, gfx::Font(), 0,
3106 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages))));
[email protected]beb440c2009-11-06 04:08:543107 // Force URL to have LTR directionality.
[email protected]70edb862010-08-18 16:23:183108 base_address = base::i18n::GetDisplayStringInLTRDirectionality(base_address);
[email protected]beb440c2009-11-06 04:08:543109
[email protected]70edb862010-08-18 16:23:183110 return UTF16ToWide(l10n_util::GetStringFUTF16(
[email protected]beb440c2009-11-06 04:08:543111 is_alert ? IDS_JAVASCRIPT_ALERT_TITLE : IDS_JAVASCRIPT_MESSAGEBOX_TITLE,
[email protected]70edb862010-08-18 16:23:183112 base_address));
[email protected]beb440c2009-11-06 04:08:543113}
3114
3115gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3116 return view_->GetTopLevelNativeWindow();
3117}
3118
3119void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3120 bool success,
3121 const std::wstring& prompt) {
3122 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3123 if (is_showing_before_unload_dialog_ && !success) {
3124 // If a beforeunload dialog is canceled, we need to stop the throbber from
3125 // spinning, since we forced it to start spinning in Navigate.
3126 DidStopLoading();
3127
3128 tab_close_start_time_ = base::TimeTicks();
3129 }
3130 is_showing_before_unload_dialog_ = false;
3131 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3132}
3133
3134void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3135 set_suppress_javascript_messages(suppress_message_boxes);
3136}
3137
[email protected]3a3d47472010-07-15 21:03:543138TabContents* TabContents::AsTabContents() {
3139 return this;
3140}
3141
3142ExtensionHost* TabContents::AsExtensionHost() {
3143 return NULL;
3144}
3145
[email protected]41fc0322009-09-04 22:23:403146void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103147 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3148}
[email protected]f45d2a72010-03-08 23:28:353149
3150void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3151 app_icon_ = app_icon;
3152 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3153}
[email protected]ea68c06a2010-04-23 17:25:373154
3155// After a successful *new* login attempt, we take the PasswordFormManager in
3156// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3157// the user makes up their mind with the "save password" infobar. Note if the
3158// login is one we already know about, the end of the line is
3159// provisional_save_manager_ because we just update it on success and so such
3160// forms never end up in an infobar.
3161class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3162 public:
3163 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463164 PasswordFormManager* form_to_save)
3165 : ConfirmInfoBarDelegate(tab_contents),
3166 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583167 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373168
[email protected]d75aba1d2010-08-02 23:35:583169 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373170
[email protected]d75aba1d2010-08-02 23:35:583171 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373172 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463173 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583174 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373175 delete this;
3176 }
3177
[email protected]d75aba1d2010-08-02 23:35:583178 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3179
[email protected]e23d3a32010-08-13 19:39:583180 virtual string16 GetMessageText() const {
3181 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373182 }
3183
3184 virtual SkBitmap* GetIcon() const {
3185 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3186 IDR_INFOBAR_SAVE_PASSWORD);
3187 }
3188
3189 virtual int GetButtons() const {
3190 return BUTTON_OK | BUTTON_CANCEL;
3191 }
3192
[email protected]e23d3a32010-08-13 19:39:583193 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373194 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583195 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373196 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583197 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373198 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583199 return string16();
[email protected]ea68c06a2010-04-23 17:25:373200 }
3201
3202 virtual bool Accept() {
3203 DCHECK(form_to_save_.get());
3204 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583205 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373206 return true;
3207 }
3208
3209 virtual bool Cancel() {
3210 DCHECK(form_to_save_.get());
3211 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583212 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373213 return true;
3214 }
[email protected]d75aba1d2010-08-02 23:35:583215 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373216
3217 private:
3218 // The PasswordFormManager managing the form we're asking the user about,
3219 // and should update as per her decision.
3220 scoped_ptr<PasswordFormManager> form_to_save_;
3221
[email protected]12bb6822010-06-16 02:00:463222 // Used to track the results we get from the info bar.
3223 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583224 NO_RESPONSE = 0,
3225 REMEMBER_PASSWORD,
3226 DONT_REMEMBER_PASSWORD,
3227 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463228 };
3229 ResponseType infobar_response_;
3230
[email protected]ea68c06a2010-04-23 17:25:373231 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3232};
3233
3234void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163235 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373236 render_view_host()->FillPasswordForm(form_data);
3237}
3238
3239void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3240 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3241}
3242
3243Profile* TabContents::GetProfileForPasswordManager() {
3244 return profile();
3245}
3246
3247bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3248 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3249}