blob: 58871bb9ac8b0ed6b0ea512fe0b131dde8309374 [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]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]8cc8d492010-02-02 10:40:4911#include "base/auto_reset.h"
[email protected]835d7c82010-10-14 04:38:3812#include "base/metrics/histogram.h"
[email protected]96d185d2009-04-24 03:28:5413#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3714#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5415#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3116#include "base/utf_string_conversions.h"
[email protected]6db0def92010-03-02 19:55:4517#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2118#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4019#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3220#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5421#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5522#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1023#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4524#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3325#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5426#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1427#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5429#include "chrome/browser/dom_ui/dom_ui.h"
[email protected]bcef0dc02009-02-28 00:35:0230#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0132#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0033#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3134#include "chrome/browser/external_protocol_handler.h"
35#include "chrome/browser/favicon_service.h"
36#include "chrome/browser/file_select_helper.h"
37#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2138#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5839#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2541#include "chrome/browser/host_zoom_map.h"
[email protected]8897c382009-05-06 17:53:2642#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0743#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3244#include "chrome/browser/load_from_memory_cache_details.h"
45#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4446#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0547#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1048#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2449#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5750#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0251#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3652#include "chrome/browser/prerender/prerender_manager.h"
[email protected]dbeebd52010-11-16 20:34:1653#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0954#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3355#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0756#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1657#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5458#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3759#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5461#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3262#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1163#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1664#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1265#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1666#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1767#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1768#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5469#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1670#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4371#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1672#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4973#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5774#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4975#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1676#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3577#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1478#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5879#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2780#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2181#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4982#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5783#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4884#include "chrome/common/extensions/extension_icon_set.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]96d185d2009-04-24 03:28:5493#include "chrome/common/url_constants.h"
[email protected]ef0d04c2010-12-15 23:34:2194#include "gfx/codec/png_codec.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]d686e812009-06-03 19:10:29100#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32101#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25102#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]d5e311b2010-07-20 17:15:03103#include "webkit/glue/password_form.h"
[email protected]191eb3f72010-12-21 06:27:50104#include "webkit/plugins/npapi/plugin_list.h"
[email protected]3c733bde2010-12-21 19:56:31105#include "webkit/glue/webpreferences.h"
106
107#if defined(OS_MACOSX)
108#include "app/surface/io_surface_support_mac.h"
109#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00110
[email protected]420ae012009-04-24 05:16:32111// Cross-Site Navigations
112//
113// If a TabContents is told to navigate to a different web site (as determined
114// by SiteInstance), it will replace its current RenderViewHost with a new
115// RenderViewHost dedicated to the new SiteInstance. This works as follows:
116//
117// - Navigate determines whether the destination is cross-site, and if so,
118// it creates a pending_render_view_host_ and moves into the PENDING
119// RendererState.
120// - The pending RVH is "suspended," so that no navigation messages are sent to
121// its renderer until the onbeforeunload JavaScript handler has a chance to
122// run in the current RVH.
123// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
124// that it has a pending cross-site request. ResourceDispatcherHost will
125// check for this when the response arrives.
126// - The current RVH runs its onbeforeunload handler. If it returns false, we
127// cancel all the pending logic and go back to NORMAL. Otherwise we allow
128// the pending RVH to send the navigation request to its renderer.
129// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
130// checks CrossSiteRequestManager to see that the RVH responsible has a
131// pending cross-site request, and then installs a CrossSiteEventHandler.
132// - When RDH receives a response, the BufferedEventHandler determines whether
133// it is a download. If so, it sends a message to the new renderer causing
134// it to cancel the request, and the download proceeds in the download
135// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34136// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32137// doesn't affect any functionality.
138// - After RDH receives a response and determines that it is safe and not a
139// download, it pauses the response to first run the old page's onunload
140// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34141// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32142// to the current RVH.
143// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
144// the ResourceDispatcherHost, who unpauses the response. Data is then sent
145// to the pending RVH.
146// - The pending renderer sends a FrameNavigate message that invokes the
147// DidNavigate method. This replaces the current RVH with the
148// pending RVH and goes back to the NORMAL RendererState.
149
150namespace {
151
152// Amount of time we wait between when a key event is received and the renderer
153// is queried for its state and pushed to the NavigationEntry.
154const int kQueryStateDelay = 5000;
155
[email protected]6ebdc9b2010-09-27 16:55:57156const int kSyncWaitDelay = 40;
157
[email protected]420ae012009-04-24 05:16:32158// If another javascript message box is displayed within
159// kJavascriptMessageExpectedDelay of a previous javascript message box being
160// dismissed, display an option to suppress future message boxes from this
161// contents.
162const int kJavascriptMessageExpectedDelay = 1000;
163
[email protected]420ae012009-04-24 05:16:32164// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51165const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32166 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17167 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32168 prefs::kWebKitJavaEnabled,
169 prefs::kWebKitJavascriptEnabled,
170 prefs::kWebKitLoadsImagesAutomatically,
171 prefs::kWebKitPluginsEnabled,
172 prefs::kWebKitUsesUniversalDetector,
173 prefs::kWebKitSerifFontFamily,
174 prefs::kWebKitSansSerifFontFamily,
175 prefs::kWebKitFixedFontFamily,
176 prefs::kWebKitDefaultFontSize,
177 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13178 prefs::kWebKitMinimumFontSize,
179 prefs::kWebKitMinimumLogicalFontSize,
[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]876bc832010-09-07 16:29:54225void MakeNavigateParams(const NavigationEntry& entry,
226 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16227 NavigationController::ReloadType reload_type,
228 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34229 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54230 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00231 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]3c2826852010-12-16 19:09:14242class OutdatedPluginInfoBar : public ConfirmInfoBarDelegate {
[email protected]851b1eb2010-08-09 13:32:29243 public:
[email protected]3c2826852010-12-16 19:09:14244 OutdatedPluginInfoBar(TabContents* tab_contents,
[email protected]851b1eb2010-08-09 13:32:29245 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(),
[email protected]57b66d02010-09-30 11:24:51281 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29282 return false;
283 }
284
285 virtual bool Cancel() {
[email protected]3c2826852010-12-16 19:09:14286 tab_contents_->render_view_host()->LoadBlockedPlugins();
287 return true;
[email protected]851b1eb2010-08-09 13:32:29288 }
289
290 virtual bool LinkClicked(WindowOpenDisposition disposition) {
291 // TODO(bauerb): Navigate to a help page explaining why we disabled
292 // the plugin, once we have one.
293 return false;
294 }
295
296 private:
297 TabContents* tab_contents_;
298 string16 name_;
299 GURL update_url_;
300};
301
[email protected]420ae012009-04-24 05:16:32302} // namespace
303
304// -----------------------------------------------------------------------------
305
[email protected]fdd61c62009-04-22 19:22:57306// static
307int TabContents::find_request_id_counter_ = -1;
308
[email protected]420ae012009-04-24 05:16:32309
[email protected]420ae012009-04-24 05:16:32310TabContents::TabContents(Profile* profile,
311 SiteInstance* site_instance,
312 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07313 const TabContents* base_tab_contents,
314 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42315 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07316 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
317 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13318 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22319 TabContentsView::Create(this))),
320 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57321 property_bag_(),
322 registrar_(),
[email protected]12802702010-07-09 19:43:09323 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
324 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57325 save_package_(),
[email protected]6db0def92010-03-02 19:55:45326 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21327 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57328 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),
[email protected]443b80e2010-12-14 00:42:23332 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
333 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34334 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34335 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57336 current_load_start_(),
337 load_state_(net::LOAD_STATE_IDLE),
338 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56339 upload_size_(0),
340 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57341 received_page_title_(false),
342 is_starred_(false),
343 contents_mime_type_(),
344 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40345 blocked_contents_(NULL),
346 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49347 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47348 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57349 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57350 find_ui_active_(false),
351 find_op_aborted_(false),
352 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12353 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12354 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08355 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57356 capturing_contents_(false),
357 is_being_destroyed_(false),
358 notify_disconnection_(false),
359 history_requests_(),
360#if defined(OS_WIN)
361 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
362#endif
363 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44364 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01365 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54366 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54367 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16368 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38369 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25370 minimum_zoom_percent_(
371 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
372 maximum_zoom_percent_(
373 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00374 temporary_zoom_settings_(false),
375 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54376 renderer_preferences_util::UpdateFromSystemSettings(
377 &renderer_preferences_, profile);
378
[email protected]9fb83e82010-07-02 18:24:55379 content_settings_delegate_.reset(
380 new TabSpecificContentSettings(this, profile));
381
[email protected]12636df2009-09-28 22:32:21382 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32383
[email protected]34ac70502009-09-25 17:07:23384 // We have the initial size of the view be based on the size of the passed in
385 // tab contents (normally a tab from the same window).
386 view_->CreateView(base_tab_contents ?
387 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32388
389 // Register for notifications about all interested prefs change.
390 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28391 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32392 if (prefs) {
393 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28394 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32395 }
396
397 // Register for notifications about URL starredness changing on any profile.
398 registrar_.Add(this, NotificationType::URLS_STARRED,
399 NotificationService::AllSources());
400 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
401 NotificationService::AllSources());
402 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
403 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09404#if defined(OS_LINUX)
405 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
406 NotificationService::AllSources());
407#endif
[email protected]420ae012009-04-24 05:16:32408
[email protected]6c32ce72010-03-08 05:18:06409 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
410 NotificationService::AllSources());
411
[email protected]79580c62010-02-02 02:36:25412 // Register for notifications about content setting changes.
413 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
414 NotificationService::AllSources());
415
[email protected]a888b29e62010-04-01 13:38:57416 // Listen for extension changes so we can update extension_for_current_page_.
417 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
418 NotificationService::AllSources());
419 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
420 NotificationService::AllSources());
421 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
422 NotificationService::AllSources());
423
[email protected]88152052010-10-01 04:05:18424 // Listen for Google URL changes
425 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
426 NotificationService::AllSources());
427
[email protected]c8865482009-07-23 20:40:10428 // Set-up the showing of the omnibox search infobar if applicable.
429 if (OmniboxSearchHint::IsEnabled(profile))
430 omnibox_search_hint_.reset(new OmniboxSearchHint(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();
[email protected]2fb7dc982010-09-29 12:24:28438 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32439
[email protected]420ae012009-04-24 05:16:32440 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00441 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32442
[email protected]420ae012009-04-24 05:16:32443 // First cleanly close all child windows.
444 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
445 // some of these to close. CloseWindows is async, so it might get called
446 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49447 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32448
[email protected]c65e2f152010-10-14 15:30:40449 // Close all blocked contents.
450 if (blocked_contents_)
451 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13452
[email protected]420ae012009-04-24 05:16:32453 // Notify any observer that have a reference on this tab contents.
454 NotificationService::current()->Notify(
455 NotificationType::TAB_CONTENTS_DESTROYED,
456 Source<TabContents>(this),
457 NotificationService::NoDetails());
458
[email protected]1e5e74f2009-05-27 20:55:12459 // Notify any lasting InfobarDelegates that have not yet been removed that
460 // whatever infobar they were handling in this TabContents has closed,
461 // because the TabContents is going away entirely.
462 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
463 // notification may trigger infobars calls that access their delegate. (and
464 // some implementations of InfoBarDelegate do delete themselves on
465 // InfoBarClosed()).
466 for (int i = 0; i < infobar_delegate_count(); ++i) {
467 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
468 delegate->InfoBarClosed();
469 }
470 infobar_delegates_.clear();
471
[email protected]420ae012009-04-24 05:16:32472 // TODO(brettw) this should be moved to the view.
473#if defined(OS_WIN)
474 // If we still have a window handle, destroy it. GetNativeView can return
475 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42476 if (GetNativeView()) {
477 RenderViewHost* host = render_view_host();
478 if (host && host->view()) {
479 host->view()->WillWmDestroy();
480 }
[email protected]420ae012009-04-24 05:16:32481 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42482 }
[email protected]420ae012009-04-24 05:16:32483#endif
[email protected]7ab1e7d62009-10-14 23:32:01484
485 // OnCloseStarted isn't called in unit tests.
486 if (!tab_close_start_time_.is_null()) {
487 UMA_HISTOGRAM_TIMES("Tab.Close",
488 base::TimeTicks::Now() - tab_close_start_time_);
489 }
initial.commit09911bf2008-07-26 23:55:29490}
491
[email protected]d5f942ba2008-09-26 19:30:34492// static
493void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32494 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
495
496 WebPreferences pref_defaults;
497 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
498 pref_defaults.javascript_enabled);
499 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
500 pref_defaults.web_security_enabled);
501 prefs->RegisterBooleanPref(
502 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
503 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
504 pref_defaults.loads_images_automatically);
505 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
506 pref_defaults.plugins_enabled);
507 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
508 pref_defaults.dom_paste_enabled);
509 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
510 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14511 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32512 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
513 pref_defaults.text_areas_are_resizable);
514 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
515 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36516 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
517 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32518
519 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
520 IDS_ACCEPT_LANGUAGES);
521 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
522 IDS_DEFAULT_ENCODING);
523 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
524 IDS_STANDARD_FONT_IS_SERIF);
525 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
526 IDS_FIXED_FONT_FAMILY);
527 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
528 IDS_SERIF_FONT_FAMILY);
529 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
530 IDS_SANS_SERIF_FONT_FAMILY);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
532 IDS_CURSIVE_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
534 IDS_FANTASY_FONT_FAMILY);
535 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
536 IDS_DEFAULT_FONT_SIZE);
537 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
538 IDS_DEFAULT_FIXED_FONT_SIZE);
539 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
540 IDS_MINIMUM_FONT_SIZE);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
542 IDS_MINIMUM_LOGICAL_FONT_SIZE);
543 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
544 IDS_USES_UNIVERSAL_DETECTOR);
545 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
546 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29547}
548
[email protected]13367f72009-07-08 16:39:02549// Returns true if contains content rendered by an extension.
550bool TabContents::HostsExtension() const {
551 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34552}
553
[email protected]cf28ec52010-04-09 22:56:34554AutoFillManager* TabContents::GetAutoFillManager() {
555 if (autofill_manager_.get() == NULL)
556 autofill_manager_.reset(new AutoFillManager(this));
557 return autofill_manager_.get();
558}
559
[email protected]6e95706d2009-04-23 22:55:01560PluginInstaller* TabContents::GetPluginInstaller() {
561 if (plugin_installer_.get() == NULL)
562 plugin_installer_.reset(new PluginInstaller(this));
563 return plugin_installer_.get();
564}
565
[email protected]1f18184a2010-07-21 19:34:49566TabContentsSSLHelper* TabContents::GetSSLHelper() {
567 if (ssl_helper_.get() == NULL)
568 ssl_helper_.reset(new TabContentsSSLHelper(this));
569 return ssl_helper_.get();
570}
571
[email protected]8cb5d5b2010-02-09 11:36:16572RenderProcessHost* TabContents::GetRenderProcessHost() const {
573 return render_manager_.current_host()->process();
574}
575
[email protected]9adb9692010-10-29 23:14:02576void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46577 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08578 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10579
[email protected]98aa0b52010-05-06 17:03:08580 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57581
[email protected]fca656c2010-02-10 20:30:10582 NotificationService::current()->Notify(
583 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
584 Source<TabContents>(this),
585 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49586}
587
[email protected]98aa0b52010-05-06 17:03:08588void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
589 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40590 return;
591
[email protected]eaa7dd182010-12-14 11:09:00592 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50593 if (!extension_service || !extension_service->is_ready())
594 return;
595
596 const Extension* extension =
597 extension_service->GetExtensionById(extension_app_id, false);
598 if (extension)
599 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40600}
601
[email protected]98aa0b52010-05-06 17:03:08602SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08603 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51604 return NULL;
605
[email protected]98aa0b52010-05-06 17:03:08606 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51607}
608
[email protected]d5f942ba2008-09-26 19:30:34609const GURL& TabContents::GetURL() const {
610 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57611 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54612 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34613}
614
[email protected]96d185d2009-04-24 03:28:54615const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55616 // Transient entries take precedence. They are used for interstitial pages
617 // that are shown on top of existing pages.
618 NavigationEntry* entry = controller_.GetTransientEntry();
619 if (entry)
620 return entry->GetTitleForDisplay(&controller_);
621
[email protected]96d185d2009-04-24 03:28:54622 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
623 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
624 if (our_dom_ui) {
625 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55626 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54627 if (!(entry && entry->IsViewSourceMode())) {
628 // Give the DOM UI the chance to override our title.
629 const string16& title = our_dom_ui->overridden_title();
630 if (!title.empty())
631 return title;
632 }
633 }
634
635 // We use the title for the last committed entry rather than a pending
636 // navigation entry. For example, when the user types in a URL, we want to
637 // keep the old page's title until the new load has committed and we get a new
638 // title.
[email protected]96d185d2009-04-24 03:28:54639 entry = controller_.GetLastCommittedEntry();
640 if (entry)
641 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54642 return EmptyString16();
643}
644
[email protected]bbbc1ef2010-02-12 18:03:41645// static
646string16 TabContents::GetDefaultTitle() {
647 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
648}
649
[email protected]d5f942ba2008-09-26 19:30:34650int32 TabContents::GetMaxPageID() {
651 if (GetSiteInstance())
652 return GetSiteInstance()->max_page_id();
653 else
654 return max_page_id_;
655}
656
657void TabContents::UpdateMaxPageID(int32 page_id) {
658 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34659 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34660 // testing.
661 if (GetSiteInstance())
662 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16663 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34664}
665
[email protected]96d185d2009-04-24 03:28:54666SiteInstance* TabContents::GetSiteInstance() const {
667 return render_manager_.current_host()->site_instance();
668}
669
[email protected]96d185d2009-04-24 03:28:54670bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15671 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54672 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15673 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01674 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54675 return true;
[email protected]8ab24cc2009-11-13 20:56:15676 }
[email protected]83e3895b2009-06-11 00:07:16677
[email protected]96d185d2009-04-24 03:28:54678 DOMUI* dom_ui = GetDOMUIForCurrentState();
679 if (dom_ui)
680 return !dom_ui->should_hide_url();
681 return true;
682}
683
[email protected]d5f942ba2008-09-26 19:30:34684SkBitmap TabContents::GetFavIcon() const {
685 // Like GetTitle(), we also want to use the favicon for the last committed
686 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57687 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47688 if (entry)
689 return entry->favicon().bitmap();
690
[email protected]ce3fa3c2009-04-20 19:55:57691 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34692 if (entry)
693 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34694 return SkBitmap();
695}
696
[email protected]0b303cc2009-09-28 22:35:15697bool TabContents::FavIconIsValid() const {
698 NavigationEntry* entry = controller_.GetTransientEntry();
699 if (entry)
700 return entry->favicon().is_valid();
701
702 entry = controller_.GetLastCommittedEntry();
703 if (entry)
704 return entry->favicon().is_valid();
705
706 return false;
707}
708
[email protected]96d185d2009-04-24 03:28:54709bool TabContents::ShouldDisplayFavIcon() {
710 // Always display a throbber during pending loads.
711 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
712 return true;
713
714 DOMUI* dom_ui = GetDOMUIForCurrentState();
715 if (dom_ui)
716 return !dom_ui->hide_favicon();
717 return true;
718}
719
[email protected]96d185d2009-04-24 03:28:54720std::wstring TabContents::GetStatusText() const {
721 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
722 return std::wstring();
723
724 switch (load_state_) {
725 case net::LOAD_STATE_WAITING_FOR_CACHE:
726 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04727 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
728 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54729 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
730 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
731 case net::LOAD_STATE_RESOLVING_HOST:
732 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
733 case net::LOAD_STATE_CONNECTING:
734 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06735 case net::LOAD_STATE_SSL_HANDSHAKE:
736 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54737 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56738 if (upload_size_)
739 return l10n_util::GetStringF(
740 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
741 static_cast<int>((100 * upload_position_) / upload_size_));
742 else
743 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54744 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
745 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
746 load_state_host_);
747 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
748 case net::LOAD_STATE_IDLE:
749 case net::LOAD_STATE_READING_RESPONSE:
750 break;
751 }
752
753 return std::wstring();
754}
755
[email protected]3c9e1872010-11-18 16:17:49756void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
757 web_navigation_observers_.AddObserver(observer);
758}
759
760void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
761 web_navigation_observers_.RemoveObserver(observer);
762}
763
[email protected]443b80e2010-12-14 00:42:23764void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
765 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34766 return;
767
[email protected]443b80e2010-12-14 00:42:23768 crashed_status_ = status;
769 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50770 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34771}
772
[email protected]744ef172009-10-16 21:53:46773void TabContents::PageActionStateChanged() {
774 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00775}
[email protected]ce5c4502009-05-06 16:46:11776
[email protected]d5f942ba2008-09-26 19:30:34777void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
778 if (delegate_)
779 delegate_->NavigationStateChanged(this, changed_flags);
780}
781
[email protected]96d185d2009-04-24 03:28:54782void TabContents::DidBecomeSelected() {
783 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16784 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
785 if (rwhv) {
786 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43787#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16788 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43789#endif
790 }
[email protected]96d185d2009-04-24 03:28:54791
[email protected]8cb5d5b2010-02-09 11:36:16792 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11793 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54794}
795
[email protected]a94454b2010-12-16 04:16:03796void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45797 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
798 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
799 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03800 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45801}
802
803void TabContents::CancelInstantFade() {
804 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
805 if (rwhv)
806 rwhv->SetVisuallyDeemphasized(NULL, false);
807}
808
[email protected]96d185d2009-04-24 03:28:54809void TabContents::WasHidden() {
810 if (!capturing_contents()) {
811 // |render_view_host()| can be NULL if the user middle clicks a link to open
812 // a tab in then background, then closes the tab before selecting it. This
813 // is because closing the tab calls TabContents::Destroy(), which removes
814 // the |render_view_host()|; then when we actually destroy the window,
815 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16816 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
817 if (rwhv)
818 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54819 }
820
821 NotificationService::current()->Notify(
822 NotificationType::TAB_CONTENTS_HIDDEN,
823 Source<TabContents>(this),
824 NotificationService::NoDetails());
825}
826
[email protected]d5f942ba2008-09-26 19:30:34827void TabContents::Activate() {
828 if (delegate_)
829 delegate_->ActivateContents(this);
830}
831
[email protected]ea42e7782010-08-23 23:58:12832void TabContents::Deactivate() {
833 if (delegate_)
834 delegate_->DeactivateContents(this);
835}
836
[email protected]96d185d2009-04-24 03:28:54837void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16838 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
839 if (rwhv)
840 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54841}
842
843void TabContents::HideContents() {
844 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
845 // our superclass HideContents(), because some callers want to be very picky
846 // about the order in which these get called. In addition to making the code
847 // here practically impossible to understand, this also means we end up
848 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34849 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54850 WasHidden();
851}
852
[email protected]5aab5e22010-12-08 22:13:29853bool TabContents::NeedToFireBeforeUnload() {
854 // TODO(creis): Should we fire even for interstitial pages?
855 return notify_disconnection() &&
856 !showing_interstitial_page() &&
857 !render_view_host()->SuddenTerminationAllowed();
858}
859
[email protected]c0588052008-10-27 23:01:50860void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34861 WindowOpenDisposition disposition,
862 PageTransition::Type transition) {
863 if (delegate_)
[email protected]c0588052008-10-27 23:01:50864 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34865}
866
[email protected]1ccb3568d2010-02-19 10:51:16867bool TabContents::NavigateToPendingEntry(
868 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54869 return NavigateToEntry(*controller_.pending_entry(), reload_type);
870}
[email protected]96d185d2009-04-24 03:28:54871
[email protected]876bc832010-09-07 16:29:54872bool TabContents::NavigateToEntry(
873 const NavigationEntry& entry,
874 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54875 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
876 if (!dest_render_view_host)
877 return false; // Unable to create the desired render view host.
878
[email protected]770dd8b2010-05-24 18:11:39879 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
880 dest_render_view_host->EnablePreferredSizeChangedMode(
881 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
882 }
[email protected]9fb325e2010-05-06 18:23:24883
[email protected]05fdd492010-11-15 17:52:07884 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
885 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58886 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40887 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07888 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58889 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40890 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58891
[email protected]96d185d2009-04-24 03:28:54892 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12893 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32894 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00895 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
896 dest_render_view_host,
897 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32898 }
[email protected]96d185d2009-04-24 03:28:54899
900 // Used for page load time metrics.
901 current_load_start_ = base::TimeTicks::Now();
902
903 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34904 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54905 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04906 if (delegate_) {
907 navigate_params.extra_headers =
908 delegate_->GetNavigationHeaders(navigate_params.url);
909 }
[email protected]056de2d2009-06-26 16:41:34910 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54911
912 if (entry.page_id() == -1) {
913 // HACK!! This code suppresses javascript: URLs from being added to
914 // session history, which is what we want to do for javascript: URLs that
915 // do not generate content. What we really need is a message from the
916 // renderer telling us that a new page was not created. The same message
917 // could be used for mailto: URLs and the like.
918 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
919 return false;
920 }
921
[email protected]3c9e1872010-11-18 16:17:49922 // Notify observers about navigation.
923 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
924 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54925
[email protected]1ccb3568d2010-02-19 10:51:16926 if (reload_type != NavigationController::NO_RELOAD &&
927 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48928 FaviconService* favicon_service =
929 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
930 if (favicon_service)
931 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54932 }
933
[email protected]d5f942ba2008-09-26 19:30:34934 return true;
935}
936
[email protected]96d185d2009-04-24 03:28:54937void TabContents::Stop() {
938 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09939 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54940}
941
[email protected]96d185d2009-04-24 03:28:54942void TabContents::DisassociateFromPopupCount() {
943 render_view_host()->DisassociateFromPopupCount();
944}
945
946TabContents* TabContents::Clone() {
947 // We create a new SiteInstance so that the new tab won't share processes
948 // with the old one. This can be changed in the future if we need it to share
949 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32950 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54951 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07952 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54953 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08954 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08955 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54956 return tc;
957}
958
[email protected]4d677202009-07-19 07:37:12959void TabContents::ShowPageInfo(const GURL& url,
960 const NavigationEntry::SSLStatus& ssl,
961 bool show_history) {
962 if (!delegate_)
963 return;
964
[email protected]bb678332009-07-21 00:15:50965 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12966}
967
[email protected]ef0d04c2010-12-15 23:34:21968void TabContents::SaveFavicon() {
969 NavigationEntry* entry = controller_.GetActiveEntry();
970 if (!entry || entry->url().is_empty())
971 return;
972
973 // Make sure the page is in history, otherwise adding the favicon does
974 // nothing.
975 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
976 Profile::IMPLICIT_ACCESS);
977 if (!history)
978 return;
979 history->AddPageNoVisitForBookmark(entry->url());
980
981 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
982 Profile::IMPLICIT_ACCESS);
983 if (!service)
984 return;
985 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
986 if (!favicon.is_valid() || favicon.url().is_empty() ||
987 favicon.bitmap().empty()) {
988 return;
989 }
990 std::vector<unsigned char> image_data;
991 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
992 service->SetFavicon(entry->url(), favicon.url(), image_data);
993}
994
initial.commit09911bf2008-07-26 23:55:29995ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28996 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29997 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28998 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29999 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:441000
1001 if (child_windows_.size() == 1) {
1002 window->ShowConstrainedWindow();
1003 BlockTabContent(true);
1004 }
1005
initial.commit09911bf2008-07-26 23:55:291006 return window;
1007}
1008
[email protected]fa1cf0b82010-01-15 21:49:441009void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:551010 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:451011 // 70% opaque grey.
1012 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:551013 if (rwhv)
[email protected]1b072562010-12-13 19:37:451014 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:441015 render_view_host()->set_ignore_input_events(blocked);
1016 if (delegate_)
1017 delegate_->SetTabContentBlocked(this, blocked);
1018}
1019
initial.commit09911bf2008-07-26 23:55:291020void TabContents::AddNewContents(TabContents* new_contents,
1021 WindowOpenDisposition disposition,
1022 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291023 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401024 if (all_contents_blocked_) {
1025 if (!blocked_contents_)
1026 blocked_contents_ = new BlockedContentContainer(this);
1027 blocked_contents_->AddTabContents(
1028 new_contents, disposition, initial_pos, user_gesture);
1029 return;
1030 }
1031
initial.commit09911bf2008-07-26 23:55:291032 if (!delegate_)
1033 return;
1034
[email protected]35f7d212009-04-29 21:19:271035 if ((disposition == NEW_POPUP) && !user_gesture &&
1036 !CommandLine::ForCurrentProcess()->HasSwitch(
1037 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221038 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311039 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291040 delegate_->GetConstrainingContents(this)->AddPopup(
1041 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311042 } else {
[email protected]0aa55312008-10-17 21:53:081043 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291044 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1045 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491046 NotificationService::current()->Notify(
1047 NotificationType::TAB_ADDED,
1048 Source<TabContentsDelegate>(delegate_),
1049 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291050 }
initial.commit09911bf2008-07-26 23:55:291051
[email protected]8cc8d492010-02-02 10:40:491052 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401053 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291054}
1055
[email protected]bcd9dc42010-01-23 16:38:181056bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201057 bool is_js_code, const std::string& code_string,
1058 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511059 RenderViewHost* host = render_view_host();
1060 if (!host)
1061 return false;
1062
1063 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171064 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511065 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351066}
1067
[email protected]96d185d2009-04-24 03:28:541068void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491069 if (is_being_destroyed_)
1070 return;
[email protected]9fb83e82010-07-02 18:24:551071 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491072 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401073 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541074}
1075
[email protected]5c9e97a2009-09-09 23:48:301076gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541077 return view_->GetContentNativeView();
1078}
1079
1080gfx::NativeView TabContents::GetNativeView() const {
1081 return view_->GetNativeView();
1082}
1083
1084void TabContents::GetContainerBounds(gfx::Rect *out) const {
1085 view_->GetContainerBounds(out);
1086}
1087
1088void TabContents::Focus() {
1089 view_->Focus();
1090}
1091
[email protected]90daadb42009-06-08 21:27:281092void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541093 if (showing_interstitial_page()) {
1094 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1095 return;
1096 }
[email protected]96d185d2009-04-24 03:28:541097 render_view_host()->SetInitialFocus(reverse);
1098}
1099
1100bool TabContents::FocusLocationBarByDefault() {
1101 DOMUI* dom_ui = GetDOMUIForCurrentState();
1102 if (dom_ui)
1103 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431104 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251105 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431106 return true;
[email protected]96d185d2009-04-24 03:28:541107 return false;
1108}
1109
[email protected]a26dc362010-04-23 01:48:581110void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381111 if (delegate())
[email protected]a26dc362010-04-23 01:48:581112 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381113}
1114
[email protected]616ed5a2008-11-21 22:27:241115void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321116 if (delegate_ && !delegate_->infobars_enabled()) {
1117 delegate->InfoBarClosed();
1118 return;
1119 }
1120
[email protected]616ed5a2008-11-21 22:27:241121 // Look through the existing InfoBarDelegates we have for a match. If we've
1122 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051123 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451124 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1125 // Tell the new infobar to close so that it can clean itself up.
1126 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241127 return;
[email protected]6d27a7b2009-12-18 23:25:451128 }
[email protected]616ed5a2008-11-21 22:27:241129 }
1130
1131 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561132 NotificationService::current()->Notify(
1133 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1134 Source<TabContents>(this),
1135 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241136
1137 // Add ourselves as an observer for navigations the first time a delegate is
1138 // added. We use this notification to expire InfoBars that need to expire on
1139 // page transitions.
1140 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561141 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571142 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241143 }
1144}
1145
1146void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321147 if (delegate_ && !delegate_->infobars_enabled()) {
1148 return;
1149 }
1150
[email protected]616ed5a2008-11-21 22:27:241151 std::vector<InfoBarDelegate*>::iterator it =
1152 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1153 if (it != infobar_delegates_.end()) {
1154 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561155 NotificationService::current()->Notify(
1156 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1157 Source<TabContents>(this),
1158 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241159
[email protected]cdadf6f2010-08-20 16:36:081160 // Just to be safe, make sure the delegate was not removed by an observer.
1161 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1162 if (it != infobar_delegates_.end()) {
1163 infobar_delegates_.erase(it);
1164 // Remove ourselves as an observer if we are tracking no more InfoBars.
1165 if (infobar_delegates_.empty()) {
1166 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1167 Source<NavigationController>(&controller_));
1168 }
1169 } else {
1170 // If you hit this NOTREACHED, please comment in bug
1171 // http://crbug.com/50428 how you got there.
1172 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031173 }
[email protected]616ed5a2008-11-21 22:27:241174 }
1175}
[email protected]3edd9522009-03-04 22:19:411176
[email protected]f81821c2009-08-07 01:29:471177void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1178 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321179 if (delegate_ && !delegate_->infobars_enabled()) {
1180 new_delegate->InfoBarClosed();
1181 return;
1182 }
1183
[email protected]f81821c2009-08-07 01:29:471184 std::vector<InfoBarDelegate*>::iterator it =
1185 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1186 DCHECK(it != infobar_delegates_.end());
1187
1188 // Notify the container about the change of plans.
1189 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1190 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1191 old_delegate, new_delegate));
1192 NotificationService::current()->Notify(
1193 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1194 Source<TabContents>(this),
1195 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1196
[email protected]cdadf6f2010-08-20 16:36:081197 // Just to be safe, make sure the delegate was not removed by an observer.
1198 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1199 if (it != infobar_delegates_.end()) {
1200 // Remove the old one.
1201 infobar_delegates_.erase(it);
1202 } else {
1203 // If you hit this NOTREACHED, please comment in bug
1204 // http://crbug.com/50428 how you got there.
1205 NOTREACHED();
1206 }
[email protected]f81821c2009-08-07 01:29:471207
1208 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081209 DCHECK(find(infobar_delegates_.begin(),
1210 infobar_delegates_.end(), new_delegate) ==
1211 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471212 infobar_delegates_.push_back(new_delegate);
1213}
1214
[email protected]20ede072009-10-06 00:28:351215bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271216 if (showing_interstitial_page())
1217 return false;
1218
[email protected]c8f74942010-09-03 10:04:141219 // Do not show bookmarks bar if bookmarks aren't enabled.
1220 if (!browser_defaults::bookmarks_enabled)
1221 return false;
1222
[email protected]96d185d2009-04-24 03:28:541223 // See GetDOMUIForCurrentState() comment for more info. This case is very
1224 // similar, but for non-first loads, we want to use the committed entry. This
1225 // is so the bookmarks bar disappears at the same time the page does.
1226 if (controller_.GetLastCommittedEntry()) {
1227 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371228 return (render_manager_.dom_ui() == NULL) ?
1229 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541230 }
1231
1232 // When it's the first load, we know either the pending one or the committed
1233 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1234 // of them will be valid, so we can just check both.
1235 if (render_manager_.pending_dom_ui())
1236 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371237 return (render_manager_.dom_ui() == NULL) ?
1238 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541239}
1240
[email protected]3edd9522009-03-04 22:19:411241void TabContents::ToolbarSizeChanged(bool is_animating) {
1242 TabContentsDelegate* d = delegate();
1243 if (d)
1244 d->ToolbarSizeChanged(this, is_animating);
1245}
[email protected]616ed5a2008-11-21 22:27:241246
[email protected]fc6fb7fb2009-11-07 02:35:041247bool TabContents::CanDownload(int request_id) {
1248 TabContentsDelegate* d = delegate();
1249 if (d)
1250 return d->CanDownload(request_id);
1251 return true;
1252}
1253
[email protected]d5f942ba2008-09-26 19:30:341254void TabContents::OnStartDownload(DownloadItem* download) {
1255 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341256
1257 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311258 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341259
[email protected]5b928b62010-08-03 11:46:511260 if (tab_contents && tab_contents->delegate())
1261 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411262}
[email protected]3edd9522009-03-04 22:19:411263
[email protected]d5f942ba2008-09-26 19:30:341264void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371265 ConstrainedWindowList::iterator i(
1266 std::find(child_windows_.begin(), child_windows_.end(), window));
1267 bool removed_topmost_window = i == child_windows_.begin();
1268 if (i != child_windows_.end())
1269 child_windows_.erase(i);
1270 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441271 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371272 } else {
1273 if (removed_topmost_window)
1274 child_windows_[0]->ShowConstrainedWindow();
1275 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441276 }
[email protected]66ba4932009-06-04 19:22:131277}
[email protected]d5f942ba2008-09-26 19:30:341278
[email protected]c65e2f152010-10-14 15:30:401279void TabContents::WillCloseBlockedContentContainer(
1280 BlockedContentContainer* container) {
1281 DCHECK(blocked_contents_ == container);
1282 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491283 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341284}
1285
[email protected]d5f942ba2008-09-26 19:30:341286void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351287#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061288 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351289#endif
[email protected]d5f942ba2008-09-26 19:30:341290}
1291
[email protected]c1dc9f132009-11-20 23:13:211292void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121293 bool forward_direction,
1294 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211295 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011296 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211297 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531298 string16 last_search_prepopulate_text =
1299 FindBarState::GetLastPrepopulateText(profile());
1300
[email protected]87fae512009-12-11 02:20:211301 // Try the last thing we searched for on this tab, then the last thing
1302 // searched for on any tab.
1303 if (!previous_find_text_.empty())
1304 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531305 else if (!last_search_prepopulate_text.empty())
1306 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211307 else
[email protected]e491f1c2009-05-22 20:28:121308 return;
[email protected]e491f1c2009-05-22 20:28:121309 }
[email protected]6e95706d2009-04-23 22:55:011310
[email protected]101c90e2009-10-26 21:14:441311 // Keep track of the previous search.
1312 previous_find_text_ = find_text_;
1313
[email protected]6e95706d2009-04-23 22:55:011314 // This is a FindNext operation if we are searching for the same text again,
1315 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1316 // exception to this is if the Find was aborted (then we don't want FindNext
1317 // because the highlighting has been cleared and we need it to reappear). We
1318 // therefore treat FindNext after an aborted Find operation as a full fledged
1319 // Find.
[email protected]c1dc9f132009-11-20 23:13:211320 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121321 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011322 !find_op_aborted_;
1323 if (!find_next)
1324 current_find_request_id_ = find_request_id_counter_++;
1325
[email protected]c1dc9f132009-11-20 23:13:211326 if (!search_string.empty())
1327 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121328 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011329
1330 find_op_aborted_ = false;
1331
1332 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531333 FindBarState* find_bar_state = profile()->GetFindBarState();
1334 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011335 render_view_host()->StartFinding(current_find_request_id_,
1336 find_text_,
1337 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121338 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011339 find_next);
1340}
1341
[email protected]5bc8fe92010-03-11 18:19:001342void TabContents::StopFinding(
1343 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011344 if (selection_action == FindBarController::kClearSelection) {
1345 // kClearSelection means the find string has been cleared by the user, but
1346 // the UI has not been dismissed. In that case we want to clear the
1347 // previously remembered search (http://crbug.com/42639).
1348 previous_find_text_ = string16();
1349 } else {
[email protected]2d2dffc2009-06-09 21:41:001350 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011351 if (!find_text_.empty())
1352 previous_find_text_ = find_text_;
1353 }
[email protected]101c90e2009-10-26 21:14:441354 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011355 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121356 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001357 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011358}
1359
[email protected]420ae012009-04-24 05:16:321360void TabContents::OnSavePage() {
1361 // If we can not save the page, try to download it.
1362 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1363 DownloadManager* dlm = profile()->GetDownloadManager();
1364 const GURL& current_page_url = GetURL();
1365 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221366 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321367 return;
1368 }
1369
1370 Stop();
1371
1372 // Create the save package and possibly prompt the user for the name to save
1373 // the page as. The user prompt is an asynchronous operation that runs on
1374 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221375 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321376 save_package_->GetSaveInfo();
1377}
1378
1379// Used in automated testing to bypass prompting the user for file names.
1380// Instead, the names and paths are hard coded rather than running them through
1381// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111382bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321383 SavePackage::SavePackageType save_type) {
1384 // Stop the page from navigating.
1385 Stop();
1386
[email protected]828cabe2009-09-26 22:47:111387 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591388 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321389}
1390
[email protected]89d6e6e2009-12-03 23:06:511391void TabContents::EmailPageLocation() {
1392 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1393 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1394 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1395 title + "&body=%0A%0A" + page_url;
1396 platform_util::OpenExternal(GURL(mailto));
1397}
1398
[email protected]420ae012009-04-24 05:16:321399void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161400 if (CommandLine::ForCurrentProcess()->HasSwitch(
1401 switches::kEnablePrintPreview)) {
1402 if (showing_interstitial_page())
1403 return;
1404 render_view_host()->PrintPreview();
1405 } else {
1406 PrintNow();
1407 }
[email protected]420ae012009-04-24 05:16:321408}
1409
1410bool TabContents::PrintNow() {
1411 // We can't print interstitial page for now.
1412 if (showing_interstitial_page())
1413 return false;
1414
1415 return render_view_host()->PrintPages();
1416}
1417
[email protected]82270452009-06-19 15:58:011418void TabContents::PrintingDone(int document_cookie, bool success) {
1419 render_view_host()->PrintingDone(document_cookie, success);
1420}
1421
[email protected]420ae012009-04-24 05:16:321422bool TabContents::IsActiveEntry(int32 page_id) {
1423 NavigationEntry* active_entry = controller_.GetActiveEntry();
1424 return (active_entry != NULL &&
1425 active_entry->site_instance() == GetSiteInstance() &&
1426 active_entry->page_id() == page_id);
1427}
1428
[email protected]b2fe07d12010-02-09 14:38:081429void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161430 set_encoding(encoding);
1431 render_view_host()->SetPageEncoding(encoding);
1432}
1433
[email protected]b2fe07d12010-02-09 14:38:081434void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161435 reset_encoding();
1436 render_view_host()->ResetPageEncodingToDefault();
1437}
1438
1439void TabContents::WindowMoveOrResizeStarted() {
1440 render_view_host()->WindowMoveOrResizeStarted();
1441}
1442
[email protected]c65e2f152010-10-14 15:30:401443void TabContents::SetAllContentsBlocked(bool value) {
1444 if (all_contents_blocked_ == value)
1445 return;
1446
1447 all_contents_blocked_ = value;
1448 if (!all_contents_blocked_ && blocked_contents_) {
1449 std::vector<TabContents*> blocked;
1450 blocked_contents_->GetBlockedContents(&blocked);
1451 for (size_t i = 0; i < blocked.size(); ++i)
1452 blocked_contents_->LaunchForContents(blocked[i]);
1453 }
1454}
1455
[email protected]3f8eb7f2009-10-02 23:58:051456void TabContents::LogNewTabTime(const std::string& event_name) {
1457 // Not all new tab pages get timed. In those cases, we don't have a
1458 // new_tab_start_time_.
1459 if (new_tab_start_time_.is_null())
1460 return;
1461
1462 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441463 MetricEventDurationDetails details(event_name,
1464 static_cast<int>(duration.InMilliseconds()));
1465
[email protected]7ab1e7d62009-10-14 23:32:011466 if (event_name == "Tab.NewTabScriptStart") {
1467 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1468 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1469 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1470 } else if (event_name == "Tab.NewTabOnload") {
1471 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051472 // The new tab page has finished loading; reset it.
1473 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441474 } else {
1475 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051476 }
[email protected]84abba62009-10-07 17:01:441477 NotificationService::current()->Notify(
1478 NotificationType::METRIC_EVENT_DURATION,
1479 Source<TabContents>(this),
1480 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051481}
1482
[email protected]7ab1e7d62009-10-14 23:32:011483void TabContents::OnCloseStarted() {
1484 if (tab_close_start_time_.is_null())
1485 tab_close_start_time_ = base::TimeTicks::Now();
1486}
1487
[email protected]46624bf2010-06-09 16:04:191488bool TabContents::ShouldAcceptDragAndDrop() const {
1489#if defined(OS_CHROMEOS)
1490 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1491 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201492 if (delegate() && delegate()->IsPopup(this))
1493 return false;
1494 return true;
[email protected]46624bf2010-06-09 16:04:191495#else
1496 return true;
1497#endif
1498}
1499
[email protected]ec0b6c42010-08-26 03:16:581500void TabContents::UpdateHistoryForNavigation(
1501 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1502 if (profile()->IsOffTheRecord())
1503 return;
1504
1505 // Add to history service.
1506 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1507 if (hs)
1508 hs->AddPage(*add_page_args);
1509}
1510
1511void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1512 if (profile()->IsOffTheRecord())
1513 return;
1514
1515 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1516 if (hs)
1517 hs->SetPageTitle(entry.virtual_url(), entry.title());
1518}
1519
[email protected]d0b8d092010-10-25 04:05:171520double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251521 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1522 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171523 return 0;
[email protected]b75b8292010-10-01 07:28:251524
1525 double zoom_level;
1526 if (temporary_zoom_settings_) {
1527 zoom_level = zoom_map->GetTemporaryZoomLevel(
1528 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1529 } else {
1530 zoom_level = zoom_map->GetZoomLevel(GetURL());
1531 }
[email protected]d0b8d092010-10-25 04:05:171532 return zoom_level;
1533}
[email protected]b75b8292010-10-01 07:28:251534
[email protected]d0b8d092010-10-25 04:05:171535int TabContents::GetZoomPercent(bool* enable_increment,
1536 bool* enable_decrement) {
1537 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251538 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171539 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251540 *enable_decrement = percent > minimum_zoom_percent_;
1541 *enable_increment = percent < maximum_zoom_percent_;
1542 return percent;
1543}
1544
[email protected]3c733bde2010-12-21 19:56:311545void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501546 if (!delegate_)
1547 return;
1548
1549 NavigationEntry* active_entry = controller().GetActiveEntry();
1550 if (!active_entry)
1551 return;
1552
1553 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121554}
1555
[email protected]96d185d2009-04-24 03:28:541556// Notifies the RenderWidgetHost instance about the fact that the page is
1557// loading, or done loading and calls the base implementation.
1558void TabContents::SetIsLoading(bool is_loading,
1559 LoadNotificationDetails* details) {
1560 if (is_loading == is_loading_)
1561 return;
1562
1563 if (!is_loading) {
1564 load_state_ = net::LOAD_STATE_IDLE;
1565 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561566 upload_size_ = 0;
1567 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541568 }
1569
1570 render_manager_.SetIsLoading(is_loading);
1571
1572 is_loading_ = is_loading;
1573 waiting_for_response_ = is_loading;
1574
[email protected]6ebdc9b2010-09-27 16:55:571575 if (delegate_)
1576 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351577 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541578
1579 NotificationType type = is_loading ? NotificationType::LOAD_START :
1580 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111581 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541582 if (details)
1583 det = Details<LoadNotificationDetails>(details);
1584 NotificationService::current()->Notify(type,
1585 Source<NavigationController>(&controller_),
1586 det);
1587}
1588
[email protected]b6c874582009-05-08 19:38:311589void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291590 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061591 // A page can't spawn popups (or do anything else, either) until its load
1592 // commits, so when we reach here, the popup was spawned by the
1593 // NavigationController's last committed entry, not the active entry. For
1594 // example, if a page opens a popup in an onunload() handler, then the active
1595 // entry is the page to be loaded as we navigate away from the unloading
1596 // page. For this reason, we can't use GetURL() to get the opener URL,
1597 // because it returns the active entry.
1598 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1599 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1600
1601 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491602 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091603 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491604 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1605 } else {
[email protected]c65e2f152010-10-14 15:30:401606 if (!blocked_contents_)
1607 blocked_contents_ = new BlockedContentContainer(this);
1608 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1609 true);
[email protected]55126132010-08-19 14:53:281610 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1611 std::string());
[email protected]8cc8d492010-02-02 10:40:491612 }
[email protected]b9681312008-11-07 00:08:261613}
[email protected]616ed5a2008-11-21 22:27:241614
[email protected]616ed5a2008-11-21 22:27:241615void TabContents::ExpireInfoBars(
1616 const NavigationController::LoadCommittedDetails& details) {
1617 // Only hide InfoBars when the user has done something that makes the main
1618 // frame load. We don't want various automatic or subframe navigations making
1619 // it disappear.
1620 if (!details.is_user_initiated_main_frame_load())
1621 return;
1622
[email protected]f86a07022008-11-25 01:06:051623 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241624 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081625 if (!delegate) {
1626 // If you hit this NOTREACHED, please comment in bug
1627 // http://crbug.com/50428 how you got there.
1628 NOTREACHED();
1629 continue;
1630 }
1631
[email protected]f86a07022008-11-25 01:06:051632 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241633 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241634 }
1635}
[email protected]fdd61c62009-04-22 19:22:571636
[email protected]96d185d2009-04-24 03:28:541637DOMUI* TabContents::GetDOMUIForCurrentState() {
1638 // When there is a pending navigation entry, we want to use the pending DOMUI
1639 // that goes along with it to control the basic flags. For example, we want to
1640 // show the pending URL in the URL bar, so we want the display_url flag to
1641 // be from the pending entry.
1642 //
1643 // The confusion comes because there are multiple possibilities for the
1644 // initial load in a tab as a side effect of the way the RenderViewHostManager
1645 // works.
1646 //
1647 // - For the very first tab the load looks "normal". The new tab DOM UI is
1648 // the pending one, and we want it to apply here.
1649 //
1650 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1651 // get switched to the one previously associated with the new tab pages.
1652 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1653 // have a committed DOM UI in this case.
1654 //
1655 // This condition handles all of these cases:
1656 //
1657 // - First load in first tab: no committed nav entry + pending nav entry +
1658 // pending dom ui:
1659 // -> Use pending DOM UI if any.
1660 //
1661 // - First load in second tab: no committed nav entry + pending nav entry +
1662 // no pending DOM UI:
1663 // -> Use the committed DOM UI if any.
1664 //
1665 // - Second navigation in any tab: committed nav entry + pending nav entry:
1666 // -> Use pending DOM UI if any.
1667 //
1668 // - Normal state with no load: committed nav entry + no pending nav entry:
1669 // -> Use committed DOM UI.
1670 if (controller_.pending_entry() &&
1671 (controller_.GetLastCommittedEntry() ||
1672 render_manager_.pending_dom_ui()))
1673 return render_manager_.pending_dom_ui();
1674 return render_manager_.dom_ui();
1675}
[email protected]420ae012009-04-24 05:16:321676
1677void TabContents::DidNavigateMainFramePostCommit(
1678 const NavigationController::LoadCommittedDetails& details,
1679 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441680 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1681 // If this is a window.open navigation, use the same DOMUI as the renderer
1682 // that opened the window, as long as both renderers have the same
1683 // privileges.
[email protected]583d45c12010-08-31 02:48:121684 if (opener_dom_ui_type_ ==
1685 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441686 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1687 // dom_ui might be NULL if the URL refers to a non-existent extension.
1688 if (dom_ui) {
1689 render_manager_.SetDOMUIPostCommit(dom_ui);
1690 dom_ui->RenderViewCreated(render_view_host());
1691 }
1692 }
1693 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1694 }
1695
[email protected]420ae012009-04-24 05:16:321696 if (details.is_user_initiated_main_frame_load()) {
1697 // Clear the status bubble. This is a workaround for a bug where WebKit
1698 // doesn't let us know that the cursor left an element during a
1699 // transition (this is also why the mouse cursor remains as a hand after
1700 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1701 // clear the bubble when a user navigates to a named anchor in the same
1702 // page.
1703 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321704 }
1705
1706 // The keyword generator uses the navigation entries, so must be called after
1707 // the commit.
1708 GenerateKeywordIfNecessary(params);
1709
1710 // Allow the new page to set the title again.
1711 received_page_title_ = false;
1712
1713 // Get the favicon, either from history or request it from the net.
1714 fav_icon_helper_.FetchFavIcon(details.entry->url());
1715
[email protected]0de80162010-02-03 04:52:351716 // Clear all page actions, blocked content notifications and browser actions
1717 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141718 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001719 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081720 if (service) {
1721 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571722 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081723 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521724 if (browser_action) {
1725 browser_action->ClearAllValuesForTab(controller().session_id().id());
1726 NotificationService::current()->Notify(
1727 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571728 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521729 NotificationService::NoDetails());
1730 }
[email protected]92c6f9b92009-10-24 04:35:081731
[email protected]5d246db22009-10-27 06:17:571732 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521733 service->extensions()->at(i)->page_action();
1734 if (page_action) {
1735 page_action->ClearAllValuesForTab(controller().session_id().id());
1736 PageActionStateChanged();
1737 }
[email protected]92c6f9b92009-10-24 04:35:081738 }
[email protected]aece2c7f2009-08-27 20:43:171739 }
[email protected]0de80162010-02-03 04:52:351740
1741 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401742 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341743 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401744 blocked_contents_->Destroy();
1745 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351746 }
1747
1748 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411749 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551750 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471751
1752 // Once the main frame is navigated, we're no longer considered to have
1753 // displayed insecure content.
1754 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171755 }
[email protected]ce5c4502009-05-06 16:46:111756
[email protected]8cc8d492010-02-02 10:40:491757 // Close constrained windows if necessary.
1758 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1759 details.previous_url, details.entry->url()))
1760 CloseConstrainedWindows();
1761
[email protected]420ae012009-04-24 05:16:321762 // Update the starred state.
1763 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531764
[email protected]3c9e1872010-11-18 16:17:491765 // Notify observers about navigation.
1766 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1767 DidNavigateMainFramePostCommit(details, params));
1768
[email protected]c07c9752010-03-12 05:57:531769 // Clear the cache of forms in AutoFill.
1770 if (autofill_manager_.get())
1771 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321772}
1773
1774void TabContents::DidNavigateAnyFramePostCommit(
1775 RenderViewHost* render_view_host,
1776 const NavigationController::LoadCommittedDetails& details,
1777 const ViewHostMsg_FrameNavigate_Params& params) {
1778 // If we navigate, start showing messages again. This does nothing to prevent
1779 // a malicious script from spamming messages, since the script could just
1780 // reload the page to stop blocking.
1781 suppress_javascript_messages_ = false;
1782
[email protected]3c9e1872010-11-18 16:17:491783 // Notify observers about navigation.
1784 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1785 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551786
1787 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581788 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321789}
1790
[email protected]8cc8d492010-02-02 10:40:491791void TabContents::CloseConstrainedWindows() {
1792 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321793 // We use indices instead of iterators in case CloseWindow does something
1794 // that may invalidate an iterator.
1795 int size = static_cast<int>(child_windows_.size());
1796 for (int i = size - 1; i >= 0; --i) {
1797 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441798 if (window) {
[email protected]420ae012009-04-24 05:16:321799 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441800 BlockTabContent(false);
1801 }
[email protected]420ae012009-04-24 05:16:321802 }
1803}
1804
1805void TabContents::UpdateStarredStateForCurrentURL() {
1806 BookmarkModel* model = profile()->GetBookmarkModel();
1807 const bool old_state = is_starred_;
1808 is_starred_ = (model && model->IsBookmarked(GetURL()));
1809
1810 if (is_starred_ != old_state && delegate())
1811 delegate()->URLStarredChanged(this, is_starred_);
1812}
1813
1814void TabContents::UpdateAlternateErrorPageURL() {
1815 GURL url = GetAlternateErrorPageURL();
1816 render_view_host()->SetAlternateErrorPageURL(url);
1817}
1818
1819void TabContents::UpdateWebPreferences() {
1820 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1821}
1822
[email protected]d0b8d092010-10-25 04:05:171823void TabContents::UpdateZoomLevel() {
1824 render_view_host()->SetZoomLevel(GetZoomLevel());
1825}
1826
[email protected]420ae012009-04-24 05:16:321827void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1828 RenderViewHost* rvh) {
1829 // If we are creating a RVH for a restored controller, then we might
1830 // have more page IDs than the SiteInstance's current max page ID. We must
1831 // make sure that the max page ID is larger than any restored page ID.
1832 // Note that it is ok for conflicting page IDs to exist in another tab
1833 // (i.e., NavigationController), but if any page ID is larger than the max,
1834 // the back/forward list will get confused.
1835 int max_restored_page_id = controller_.max_restored_page_id();
1836 if (max_restored_page_id > 0) {
1837 int curr_max_page_id = site_instance->max_page_id();
1838 if (max_restored_page_id > curr_max_page_id) {
1839 // Need to update the site instance immediately.
1840 site_instance->UpdateMaxPageID(max_restored_page_id);
1841
1842 // Also tell the renderer to update its internal representation. We
1843 // need to reserve enough IDs to make all restored page IDs less than
1844 // the max.
1845 if (curr_max_page_id < 0)
1846 curr_max_page_id = 0;
1847 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1848 }
1849 }
1850}
1851
[email protected]ec0b6c42010-08-26 03:16:581852scoped_refptr<history::HistoryAddPageArgs>
1853TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541854 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471855 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321856 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581857 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1858 new history::HistoryAddPageArgs(
1859 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1860 params.redirects, params.transition, history::SOURCE_BROWSED,
1861 details.did_replace_entry));
1862 if (PageTransition::IsMainFrame(params.transition) &&
1863 virtual_url != params.url) {
1864 // Hack on the "virtual" URL so that it will appear in history. For some
1865 // types of URLs, we will display a magic URL that is different from where
1866 // the page is actually navigated. We want the user to see in history what
1867 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1868 // only applies to the main frame, as the virtual URL doesn't apply to
1869 // sub-frames.
1870 add_page_args->url = virtual_url;
1871 if (!add_page_args->redirects.empty())
1872 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321873 }
[email protected]ec0b6c42010-08-26 03:16:581874 return add_page_args;
[email protected]420ae012009-04-24 05:16:321875}
1876
1877bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1878 const std::wstring& title) {
1879 // For file URLs without a title, use the pathname instead. In the case of a
1880 // synthesized title, we don't want the update to count toward the "one set
1881 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251882 string16 final_title;
[email protected]420ae012009-04-24 05:16:321883 bool explicit_set;
1884 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251885 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321886 explicit_set = false; // Don't count synthetic titles toward the set limit.
1887 } else {
[email protected]e53668962010-06-23 15:35:251888 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321889 explicit_set = true;
1890 }
1891
[email protected]e53668962010-06-23 15:35:251892 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321893 return false; // Nothing changed, don't bother.
1894
[email protected]e53668962010-06-23 15:35:251895 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321896
[email protected]ec0b6c42010-08-26 03:16:581897 if (!received_page_title_) {
1898 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321899 received_page_title_ = explicit_set;
1900 }
1901
1902 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251903 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321904
[email protected]cbc0e1b2010-04-12 18:33:041905 NotificationService::current()->Notify(
1906 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1907 Source<TabContents>(this),
1908 NotificationService::NoDetails());
1909
[email protected]420ae012009-04-24 05:16:321910 return true;
1911}
1912
1913void TabContents::NotifySwapped() {
1914 // After sending out a swap notification, we need to send a disconnect
1915 // notification so that clients that pick up a pointer to |this| can NULL the
1916 // pointer. See Bug 1230284.
1917 notify_disconnection_ = true;
1918 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341919 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221920 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321921 NotificationService::NoDetails());
1922}
1923
1924void TabContents::NotifyConnected() {
1925 notify_disconnection_ = true;
1926 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341927 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221928 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321929 NotificationService::NoDetails());
1930}
1931
1932void TabContents::NotifyDisconnected() {
1933 if (!notify_disconnection_)
1934 return;
1935
1936 notify_disconnection_ = false;
1937 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341938 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221939 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321940 NotificationService::NoDetails());
1941}
1942
1943void TabContents::GenerateKeywordIfNecessary(
1944 const ViewHostMsg_FrameNavigate_Params& params) {
1945 if (!params.searchable_form_url.is_valid())
1946 return;
1947
1948 if (profile()->IsOffTheRecord())
1949 return;
1950
1951 int last_index = controller_.last_committed_entry_index();
1952 // When there was no previous page, the last index will be 0. This is
1953 // normally due to a form submit that opened in a new tab.
1954 // TODO(brettw) bug 916126: we should support keywords when form submits
1955 // happen in new tabs.
1956 if (last_index <= 0)
1957 return;
1958 const NavigationEntry* previous_entry =
1959 controller_.GetEntryAtIndex(last_index - 1);
1960 if (IsFormSubmit(previous_entry)) {
1961 // Only generate a keyword if the previous page wasn't itself a form
1962 // submit.
1963 return;
1964 }
1965
1966 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1967 previous_entry->user_typed_url() : previous_entry->url();
1968 std::wstring keyword =
1969 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1970 if (keyword.empty())
1971 return;
1972
1973 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1974 if (!url_model)
1975 return;
1976
1977 if (!url_model->loaded()) {
1978 url_model->Load();
1979 return;
1980 }
1981
1982 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191983 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321984 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1985 return;
1986
1987 if (current_url) {
1988 if (current_url->originating_url().is_valid()) {
1989 // The existing keyword was generated from an OpenSearch description
1990 // document, don't regenerate.
1991 return;
1992 }
1993 url_model->Remove(current_url);
1994 }
1995 TemplateURL* new_url = new TemplateURL();
1996 new_url->set_keyword(keyword);
1997 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191998 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321999 new_url->add_input_encoding(params.searchable_form_encoding);
2000 DCHECK(controller_.GetLastCommittedEntry());
2001 const GURL& favicon_url =
2002 controller_.GetLastCommittedEntry()->favicon().url();
2003 if (favicon_url.is_valid()) {
2004 new_url->SetFavIconURL(favicon_url);
2005 } else {
2006 // The favicon url isn't valid. This means there really isn't a favicon,
2007 // or the favicon url wasn't obtained before the load started. This assumes
2008 // the later.
2009 // TODO(sky): Need a way to set the favicon that doesn't involve generating
2010 // its url.
2011 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
2012 }
2013 new_url->set_safe_for_autoreplace(true);
2014 url_model->Add(new_url);
2015}
2016
[email protected]bf5c2ff392009-07-08 16:24:332017void TabContents::OnUserGesture() {
2018 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:012019 DownloadRequestLimiter* limiter =
2020 g_browser_process->download_request_limiter();
2021 if (limiter)
2022 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:262023 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:332024}
2025
2026void TabContents::OnFindReply(int request_id,
2027 int number_of_matches,
2028 const gfx::Rect& selection_rect,
2029 int active_match_ordinal,
2030 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:422031 // Ignore responses for requests that have been aborted.
2032 if (find_op_aborted_)
2033 return;
2034
[email protected]bf5c2ff392009-07-08 16:24:332035 // Ignore responses for requests other than the one we have most recently
2036 // issued. That way we won't act on stale results when the user has
2037 // already typed in another query.
2038 if (request_id != current_find_request_id_)
2039 return;
2040
2041 if (number_of_matches == -1)
2042 number_of_matches = last_search_result_.number_of_matches();
2043 if (active_match_ordinal == -1)
2044 active_match_ordinal = last_search_result_.active_match_ordinal();
2045
2046 gfx::Rect selection = selection_rect;
2047 if (selection.IsEmpty())
2048 selection = last_search_result_.selection_rect();
2049
2050 // Notify the UI, automation and any other observers that a find result was
2051 // found.
2052 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
2053 selection, active_match_ordinal,
2054 final_update);
2055 NotificationService::current()->Notify(
2056 NotificationType::FIND_RESULT_AVAILABLE,
2057 Source<TabContents>(this),
2058 Details<FindNotificationDetails>(&last_search_result_));
2059}
2060
2061void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542062 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2063 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2064 if (!entry)
2065 return;
2066 // Note that we don't call NavigationController::GotToOffset() as we don't
2067 // want to create a pending navigation entry (it might end up lingering
2068 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522069 entry->set_transition_type(entry->transition_type() |
2070 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542071 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2072 }
[email protected]bf5c2ff392009-07-08 16:24:332073}
2074
[email protected]bf5c2ff392009-07-08 16:24:332075void TabContents::OnMissingPluginStatus(int status) {
2076#if defined(OS_WIN)
2077// TODO(PORT): pull in when plug-ins work
2078 GetPluginInstaller()->OnMissingPluginStatus(status);
2079#endif
2080}
2081
2082void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332083 DCHECK(!plugin_path.value().empty());
2084
2085 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]191eb3f72010-12-21 06:27:502086 webkit::npapi::WebPluginInfo plugin_info;
2087 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath(
[email protected]45446a52010-11-04 17:41:002088 plugin_path, &plugin_info) &&
2089 !plugin_info.name.empty()) {
2090 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372091#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002092 // Many plugins on the Mac have .plugin in the actual name, which looks
2093 // terrible, so look for that and strip it off if present.
2094 const std::wstring plugin_extension(L".plugin");
2095 if (EndsWith(plugin_name, plugin_extension, true))
2096 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372097#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332098 }
[email protected]2ae8a922010-06-28 20:27:532099 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2100 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332101 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582102 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2103 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532104 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332105}
2106
2107void TabContents::OnCrashedWorker() {
2108 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582109 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422110 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332111}
2112
[email protected]38789d82010-11-17 06:03:442113void TabContents::OnDidGetApplicationInfo(int32 page_id,
2114 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512115 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332116
[email protected]ed5431872009-11-17 08:39:512117 if (delegate())
2118 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332119}
2120
[email protected]bb461532010-11-26 21:50:232121void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2122 if (delegate())
2123 delegate()->OnInstallApplication(this, info);
2124}
2125
[email protected]3c2826852010-12-16 19:09:142126void TabContents::OnBlockedOutdatedPlugin(const string16& name,
2127 const GURL& update_url) {
2128 new OutdatedPluginInfoBar(this, name, update_url);
[email protected]851b1eb2010-08-09 13:32:292129}
2130
[email protected]a2cf65eb2010-01-18 08:20:382131void TabContents::OnPageContents(const GURL& url,
2132 int renderer_process_id,
2133 int32 page_id,
[email protected]e5106202010-06-11 21:12:362134 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102135 const std::string& language,
2136 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382137 // Don't index any https pages. People generally don't want their bank
2138 // accounts, etc. indexed on their computer, especially since some of these
2139 // things are not marked cachable.
2140 // TODO(brettw) we may want to consider more elaborate heuristics such as
2141 // the cachability of the page. We may also want to consider subframes (this
2142 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272143 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2144 // content indexing for chromeos in some future releases.
2145#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382146 if (!url.SchemeIsSecure()) {
2147 Profile* p = profile();
2148 if (p && !p->IsOffTheRecord()) {
2149 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2150 if (hs)
2151 hs->SetPageContents(url, contents);
2152 }
2153 }
[email protected]ccd40a52010-05-11 16:15:272154#endif
[email protected]a8a81292010-01-21 00:32:452155
[email protected]1c57b7b2010-07-12 17:38:102156 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452157
2158 std::string lang = language;
2159 NotificationService::current()->Notify(
2160 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152161 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452162 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382163}
2164
[email protected]7e0831b2010-02-01 08:45:152165void TabContents::OnPageTranslated(int32 page_id,
2166 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162167 const std::string& translated_lang,
2168 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552169 language_state_.set_current_language(translated_lang);
2170 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162171 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152172 NotificationService::current()->Notify(
2173 NotificationType::PAGE_TRANSLATED,
2174 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162175 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152176}
2177
[email protected]ce833282010-11-04 15:48:392178void TabContents::OnSetSuggestions(
2179 int32 page_id,
2180 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262181 if (delegate())
[email protected]ce833282010-11-04 15:48:392182 delegate()->OnSetSuggestions(page_id, suggestions);
2183}
2184
2185void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2186 if (delegate())
2187 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262188}
2189
[email protected]bf5c2ff392009-07-08 16:24:332190void TabContents::DidStartProvisionalLoadForFrame(
2191 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182192 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332193 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272194 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332195 const GURL& url) {
2196 ProvisionalLoadDetails details(is_main_frame,
2197 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412198 url, std::string(), false,
2199 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332200 NotificationService::current()->Notify(
2201 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2202 Source<NavigationController>(&controller_),
2203 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142204 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272205 // If we're displaying a network error page do not reset the content
2206 // settings delegate's cookies so the user has a chance to modify cookie
2207 // settings.
2208 if (!is_error_page)
2209 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142210 content_settings_delegate_->ClearGeolocationContentSettings();
2211 }
[email protected]bf5c2ff392009-07-08 16:24:332212}
2213
2214void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202215 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332216 NotificationService::current()->Notify(
2217 NotificationType::RESOURCE_RESPONSE_STARTED,
2218 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202219 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332220}
2221
[email protected]3dbb80b2010-02-09 22:41:202222void TabContents::DidRedirectResource(
2223 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332224 NotificationService::current()->Notify(
2225 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2226 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202227 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332228}
2229
2230void TabContents::DidLoadResourceFromMemoryCache(
2231 const GURL& url,
2232 const std::string& frame_origin,
2233 const std::string& main_frame_origin,
2234 const std::string& security_info) {
2235 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442236 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332237 SSLManager::DeserializeSecurityInfo(security_info,
2238 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042239 &security_bits,
2240 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332241 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162242 GetRenderProcessHost()->id(), cert_id,
2243 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332244
2245 NotificationService::current()->Notify(
2246 NotificationType::LOAD_FROM_MEMORY_CACHE,
2247 Source<NavigationController>(&controller_),
2248 Details<LoadFromMemoryCacheDetails>(&details));
2249}
2250
[email protected]e3d60e5d2009-09-25 21:08:292251void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472252 displayed_insecure_content_ = true;
2253 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292254}
2255
2256void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592257 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292258}
2259
[email protected]bf5c2ff392009-07-08 16:24:332260void TabContents::DidFailProvisionalLoadWithError(
2261 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182262 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332263 bool is_main_frame,
2264 int error_code,
2265 const GURL& url,
2266 bool showing_repost_interstitial) {
2267 if (net::ERR_ABORTED == error_code) {
2268 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2269 // This means that the interstitial won't be torn down properly, which is
2270 // bad. But if we have an interstitial, go back to another tab type, and
2271 // then load the same interstitial again, we could end up getting the first
2272 // interstitial's "failed" message (as a result of the cancel) when we're on
2273 // the second one.
2274 //
2275 // We can't tell this apart, so we think we're tearing down the current page
2276 // which will cause a crash later one. There is also some code in
2277 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2278 // out because of this problem.
2279 //
2280 // http://code.google.com/p/chromium/issues/detail?id=2855
2281 // Because this will not tear down the interstitial properly, if "back" is
2282 // back to another tab type, the interstitial will still be somewhat alive
2283 // in the previous tab type. If you navigate somewhere that activates the
2284 // tab with the interstitial again, you'll see a flash before the new load
2285 // commits of the interstitial page.
2286 if (showing_interstitial_page()) {
2287 LOG(WARNING) << "Discarding message during interstitial.";
2288 return;
2289 }
2290
2291 // This will discard our pending entry if we cancelled the load (e.g., if we
2292 // decided to download the file instead of load it). Only discard the
2293 // pending entry if the URLs match, otherwise the user initiated a navigate
2294 // before the page loaded so that the discard would discard the wrong entry.
2295 NavigationEntry* pending_entry = controller_.pending_entry();
2296 if (pending_entry && pending_entry->url() == url) {
2297 controller_.DiscardNonCommittedEntries();
2298 // Update the URL display.
2299 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2300 }
2301
2302 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2303 }
2304
2305 // Send out a notification that we failed a provisional load with an error.
2306 ProvisionalLoadDetails details(is_main_frame,
2307 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412308 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332309 details.set_error_code(error_code);
2310
2311 NotificationService::current()->Notify(
2312 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2313 Source<NavigationController>(&controller_),
2314 Details<ProvisionalLoadDetails>(&details));
2315}
2316
[email protected]4b8e2b02010-11-30 09:15:182317void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332318 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082319 NotificationService::current()->Notify(
2320 NotificationType::FRAME_DOM_CONTENT_LOADED,
2321 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182322 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332323}
2324
[email protected]4b8e2b02010-11-30 09:15:182325void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172326 NotificationService::current()->Notify(
2327 NotificationType::FRAME_DID_FINISH_LOAD,
2328 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182329 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172330}
2331
[email protected]dcd5b332010-08-11 08:55:182332void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562333 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242334 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562335}
2336
[email protected]8d3347f2009-07-09 22:00:212337RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322338 return view_.get();
2339}
2340
[email protected]8d3347f2009-07-09 22:00:212341RenderViewHostDelegate::RendererManagement*
2342TabContents::GetRendererManagementDelegate() {
2343 return &render_manager_;
2344}
2345
[email protected]bf5c2ff392009-07-08 16:24:332346RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212347 TabContents::GetBrowserIntegrationDelegate() {
2348 return this;
[email protected]bf5c2ff392009-07-08 16:24:332349}
2350
[email protected]8d3347f2009-07-09 22:00:212351RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2352 return this;
[email protected]bf5c2ff392009-07-08 16:24:332353}
2354
[email protected]46ba9082010-06-22 10:00:582355RenderViewHostDelegate::ContentSettings*
2356TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552357 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582358}
2359
[email protected]8d3347f2009-07-09 22:00:212360RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322361 return save_package_.get(); // May be NULL, but we can return NULL.
2362}
2363
[email protected]8d3347f2009-07-09 22:00:212364RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092365 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212366}
2367
2368RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2369 return &fav_icon_helper_;
2370}
2371
[email protected]e8dbd674b2010-03-11 18:34:402372RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452373 if (autocomplete_history_manager_.get() == NULL)
2374 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2375 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332376}
2377
[email protected]21674df2009-10-28 19:51:212378RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342379 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212380}
2381
[email protected]1f18184a2010-07-21 19:34:492382RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2383 return GetSSLHelper();
2384}
2385
[email protected]b5977a0c2010-08-24 19:46:262386RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2387 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492388 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262389 return file_select_helper_.get();
2390}
2391
[email protected]fd571bb2010-03-19 01:23:542392AutomationResourceRoutingDelegate*
2393TabContents::GetAutomationResourceRoutingDelegate() {
2394 return delegate();
2395}
2396
[email protected]ced90ae12010-02-20 02:06:162397RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2398 return bookmark_drag_;
2399}
2400
2401void TabContents::SetBookmarkDragDelegate(
2402 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2403 bookmark_drag_ = bookmark_drag;
2404}
2405
[email protected]9fb83e82010-07-02 18:24:552406TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2407 return content_settings_delegate_.get();
2408}
2409
[email protected]93623c5d2009-12-10 21:40:322410RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462411 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512412}
2413
[email protected]57c6a652009-05-04 07:58:342414TabContents* TabContents::GetAsTabContents() {
2415 return this;
2416}
2417
[email protected]7b291f92009-08-14 05:43:532418ViewType::Type TabContents::GetRenderViewType() const {
2419 return ViewType::TAB_CONTENTS;
2420}
2421
2422int TabContents::GetBrowserWindowID() const {
2423 return controller().window_id().id();
2424}
2425
[email protected]420ae012009-04-24 05:16:322426void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062427 NotificationService::current()->Notify(
2428 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2429 Source<TabContents>(this),
2430 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322431 NavigationEntry* entry = controller_.GetActiveEntry();
2432 if (!entry)
2433 return;
2434
2435 // When we're creating views, we're still doing initial setup, so we always
2436 // use the pending DOM UI rather than any possibly existing committed one.
2437 if (render_manager_.pending_dom_ui()) {
2438 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2439 }
2440
2441 if (entry->IsViewSourceMode()) {
2442 // Put the renderer in view source mode.
2443 render_view_host->Send(
2444 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2445 }
[email protected]0666aef2009-05-13 19:48:082446
2447 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322448}
2449
2450void TabContents::RenderViewReady(RenderViewHost* rvh) {
2451 if (rvh != render_view_host()) {
2452 // Don't notify the world, since this came from a renderer in the
2453 // background.
2454 return;
2455 }
2456
2457 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302458 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232459 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302460
2461 // Restore the focus to the tab (otherwise the focus will be on the top
2462 // window).
[email protected]484ae5912010-09-29 19:16:142463 if (was_crashed && !FocusLocationBarByDefault() &&
2464 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302465 Focus();
[email protected]484ae5912010-09-29 19:16:142466 }
[email protected]420ae012009-04-24 05:16:322467}
2468
[email protected]443b80e2010-12-14 00:42:232469void TabContents::RenderViewGone(RenderViewHost* rvh,
2470 base::TerminationStatus status,
2471 int error_code) {
[email protected]420ae012009-04-24 05:16:322472 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092473 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322474 return;
2475 if (rvh != render_view_host()) {
2476 // The pending page's RenderViewHost is gone.
2477 return;
2478 }
2479
2480 SetIsLoading(false, NULL);
2481 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232482 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322483
[email protected]ff9efc62010-02-18 22:10:542484 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212485 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542486 RemoveInfoBar(GetInfoBarDelegateAt(i));
2487
[email protected]8e537302009-06-10 21:19:582488 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552489 // Only do this if we're not in browser shutdown, so that TabContents
2490 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2491 // visible do not flash a sad tab page.
2492 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2493 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322494
2495 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002496 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322497}
2498
[email protected]2e4633c2009-07-09 16:58:062499void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2500 NotificationService::current()->Notify(
2501 NotificationType::RENDER_VIEW_HOST_DELETED,
2502 Source<TabContents>(this),
2503 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482504 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062505}
2506
[email protected]420ae012009-04-24 05:16:322507void TabContents::DidNavigate(RenderViewHost* rvh,
2508 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372509 int extra_invalidate_flags = 0;
2510
2511 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]33f74972010-12-08 16:40:362512 PrerenderManager* pm = profile()->GetPrerenderManager();
2513 if (pm != NULL) {
2514 if (pm->MaybeUsePreloadedPage(this, params.url)) {
2515 // TODO(tburkard): If the preloaded page has not finished preloading
2516 // yet, we should not do this.
2517 DidStopLoading();
2518 return;
2519 }
2520 }
2521
[email protected]20ede072009-10-06 00:28:352522 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372523
[email protected]420ae012009-04-24 05:16:322524 render_manager_.DidNavigateMainFrame(rvh);
2525
[email protected]20ede072009-10-06 00:28:352526 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372527 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372528 }
2529
[email protected]420ae012009-04-24 05:16:322530 // Update the site of the SiteInstance if it doesn't have one yet.
2531 if (!GetSiteInstance()->has_site())
2532 GetSiteInstance()->SetSite(params.url);
2533
2534 // Need to update MIME type here because it's referred to in
2535 // UpdateNavigationCommands() called by RendererDidNavigate() to
2536 // determine whether or not to enable the encoding menu.
2537 // It's updated only for the main frame. For a subframe,
2538 // RenderView::UpdateURL does not set params.contents_mime_type.
2539 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2540 // TODO(jungshik): Add a test for the encoding menu to avoid
2541 // regressing it again.
2542 if (PageTransition::IsMainFrame(params.transition))
2543 contents_mime_type_ = params.contents_mime_type;
2544
2545 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372546 bool did_navigate = controller_.RendererDidNavigate(
2547 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392548
[email protected]a9c0bfe2010-09-17 08:35:222549 // Send notification about committed provisional loads. This notification is
2550 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2551 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2552 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072553 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2554 // that is not recorded in the navigation history. For the purpose of
2555 // tracking navigation events, we treat this event as a sub frame navigation
2556 // event.
2557 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2558 ProvisionalLoadDetails load_details(
2559 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412560 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222561 load_details.set_transition_type(params.transition);
2562 // Whether or not a page transition was triggered by going backward or
2563 // forward in the history is only stored in the navigation controller's
2564 // entry list.
2565 if (did_navigate &&
2566 (controller_.GetActiveEntry()->transition_type() &
2567 PageTransition::FORWARD_BACK)) {
2568 load_details.set_transition_type(
2569 params.transition | PageTransition::FORWARD_BACK);
2570 }
2571 NotificationService::current()->Notify(
2572 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2573 Source<NavigationController>(&controller_),
2574 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222575 }
2576
[email protected]3e90d4a2009-07-03 17:38:392577 // Update history. Note that this needs to happen after the entry is complete,
2578 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582579 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392580 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582581 // URLs, we use a data: URL as the real value. We actually want to save the
2582 // about: URL to the history db and keep the data: URL hidden. This is what
2583 // the TabContents' URL getter does.
2584 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2585 CreateHistoryAddPageArgs(GetURL(), details, params));
2586 if (!delegate() ||
2587 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2588 details.type)) {
2589 UpdateHistoryForNavigation(add_page_args);
2590 }
[email protected]3e90d4a2009-07-03 17:38:392591 }
2592
[email protected]76543b92009-08-31 17:27:452593 if (!did_navigate)
2594 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322595
2596 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2597 // for the appropriate notification (best) or you can add it to
2598 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2599 // necessary, please).
2600
2601 // Run post-commit tasks.
2602 if (details.is_main_frame)
2603 DidNavigateMainFramePostCommit(details, params);
2604 DidNavigateAnyFramePostCommit(rvh, details, params);
2605}
2606
2607void TabContents::UpdateState(RenderViewHost* rvh,
2608 int32 page_id,
2609 const std::string& state) {
2610 DCHECK(rvh == render_view_host());
2611
2612 // We must be prepared to handle state updates for any page, these occur
2613 // when the user is scrolling and entering form data, as well as when we're
2614 // leaving a page, in which case our state may have already been moved to
2615 // the next page. The navigation controller will look up the appropriate
2616 // NavigationEntry and update it when it is notified via the delegate.
2617
2618 int entry_index = controller_.GetEntryIndexWithPageID(
2619 GetSiteInstance(), page_id);
2620 if (entry_index < 0)
2621 return;
2622 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2623
2624 if (state == entry->content_state())
2625 return; // Nothing to update.
2626 entry->set_content_state(state);
2627 controller_.NotifyEntryChanged(entry, entry_index);
2628}
2629
2630void TabContents::UpdateTitle(RenderViewHost* rvh,
2631 int32 page_id, const std::wstring& title) {
2632 // If we have a title, that's a pretty good indication that we've started
2633 // getting useful data.
2634 SetNotWaitingForResponse();
2635
2636 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482637 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582638 page_id);
[email protected]420ae012009-04-24 05:16:322639 if (!entry || !UpdateTitleForEntry(entry, title))
2640 return;
2641
2642 // Broadcast notifications when the UI should be updated.
2643 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032644 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322645}
2646
[email protected]420ae012009-04-24 05:16:322647void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402648 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322649 set_encoding(encoding);
2650}
2651
2652void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2653 if (delegate())
2654 delegate()->UpdateTargetURL(this, url);
2655}
2656
2657void TabContents::UpdateThumbnail(const GURL& url,
2658 const SkBitmap& bitmap,
2659 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442660 if (profile()->IsOffTheRecord())
2661 return;
2662
[email protected]420ae012009-04-24 05:16:322663 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492664 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442665 history::TopSites* ts = profile()->GetTopSites();
2666 if (ts)
2667 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282668 } else {
[email protected]e6baed562010-11-02 22:33:442669 HistoryService* hs =
2670 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2671 if (hs)
[email protected]449478302009-06-09 20:04:282672 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322673 }
2674}
2675
[email protected]c4e98902010-06-01 10:20:142676void TabContents::UpdateInspectorSetting(const std::string& key,
2677 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052678 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082679}
2680
[email protected]45aafc92010-06-07 14:18:532681void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052682 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532683}
2684
[email protected]420ae012009-04-24 05:16:322685void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292686 // The UI may be in an event-tracking loop, such as between the
2687 // mouse-down and mouse-up in text selection or a button click.
2688 // Defer the close until after tracking is complete, so that we
2689 // don't free objects out from under the UI.
2690 // TODO(shess): This could probably be integrated with the
2691 // IsDoingDrag() test below. Punting for now because I need more
2692 // research to understand how this impacts platforms other than Mac.
2693 // TODO(shess): This could get more fine-grained. For instance,
2694 // closing a tab in another window while selecting text in the
2695 // current window's Omnibox should be just fine.
2696 if (view()->IsEventTracking()) {
2697 view()->CloseTabAfterEventTracking();
2698 return;
2699 }
2700
[email protected]24a4d1062009-07-10 23:10:422701 // If we close the tab while we're in the middle of a drag, we'll crash.
2702 // Instead, cancel the drag and close it as soon as the drag ends.
2703 if (view()->IsDoingDrag()) {
2704 view()->CancelDragAndCloseTab();
2705 return;
2706 }
2707
[email protected]420ae012009-04-24 05:16:322708 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2709 if (delegate() && rvh == render_view_host())
2710 delegate()->CloseContents(this);
2711}
2712
2713void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2714 if (delegate() && delegate()->IsPopup(this))
2715 delegate()->MoveContents(this, new_bounds);
2716}
2717
[email protected]7ab1e7d62009-10-14 23:32:012718void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322719 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492720
[email protected]de4761b2010-12-07 21:05:212721 if (delegate()) {
2722 bool is_print_preview_tab =
2723 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2724 if (content_restrictions_ || is_print_preview_tab) {
2725 content_restrictions_= is_print_preview_tab ?
2726 CONTENT_RESTRICTION_PRINT : 0;
2727 delegate()->ContentRestrictionsChanged(this);
2728 }
[email protected]9e823662010-10-13 23:36:002729 }
[email protected]3c9e1872010-11-18 16:17:492730
2731 // Notify observers about navigation.
2732 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2733 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322734}
2735
[email protected]7ab1e7d62009-10-14 23:32:012736void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322737 scoped_ptr<LoadNotificationDetails> details;
2738
2739 NavigationEntry* entry = controller_.GetActiveEntry();
2740 // An entry may not exist for a stop when loading an initial blank page or
2741 // if an iframe injected by script into a blank page finishes loading.
2742 if (entry) {
[email protected]420ae012009-04-24 05:16:322743 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2744
2745 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542746 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322747 entry->transition_type(),
2748 elapsed,
2749 &controller_,
2750 controller_.GetCurrentEntryIndex()));
2751 }
2752
[email protected]420ae012009-04-24 05:16:322753 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492754
2755 // Notify observers about navigation.
2756 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2757 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322758}
2759
[email protected]1a3c3cb2010-12-16 21:03:402760void TabContents::DidChangeLoadProgress(double progress) {
2761 if (delegate())
2762 delegate()->LoadProgressChanged(progress);
2763}
2764
[email protected]25497492010-09-11 15:15:082765void TabContents::DocumentOnLoadCompletedInMainFrame(
2766 RenderViewHost* render_view_host,
2767 int32 page_id) {
2768 NotificationService::current()->Notify(
2769 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2770 Source<TabContents>(this),
2771 Details<int>(&page_id));
2772}
2773
[email protected]420ae012009-04-24 05:16:322774void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2775 const GURL& source_url,
2776 const GURL& target_url) {
2777 NavigationEntry* entry;
2778 if (page_id == -1)
2779 entry = controller_.pending_entry();
2780 else
2781 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2782 if (!entry || entry->url() != source_url)
2783 return;
2784 entry->set_url(target_url);
2785}
2786
[email protected]420ae012009-04-24 05:16:322787void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2788 WindowOpenDisposition disposition) {
2789 if (render_manager_.dom_ui()) {
2790 // When we're a DOM UI, it will provide a page transition type for us (this
2791 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2792 // generated suggestions).
2793 //
2794 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162795 // want web sites to see a referrer of "chrome://blah" (and some
2796 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322797 // send to the site), so we send no referrer.
2798 OpenURL(url, GURL(), disposition,
2799 render_manager_.dom_ui()->link_transition_type());
2800 } else {
2801 OpenURL(url, referrer, disposition, PageTransition::LINK);
2802 }
2803}
2804
[email protected]1ee614862009-07-06 20:29:182805void TabContents::DomOperationResponse(const std::string& json_string,
2806 int automation_id) {
2807}
2808
[email protected]8b8e7c92010-08-19 18:05:562809void TabContents::ProcessDOMUIMessage(
2810 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322811 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442812 // This can happen if someone uses window.open() to open an extension URL
2813 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562814 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322815 return;
2816 }
[email protected]8b8e7c92010-08-19 18:05:562817 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322818}
2819
2820void TabContents::ProcessExternalHostMessage(const std::string& message,
2821 const std::string& origin,
2822 const std::string& target) {
2823 if (delegate())
2824 delegate()->ForwardMessageToExternalHost(message, origin, target);
2825}
2826
[email protected]420ae012009-04-24 05:16:322827void TabContents::RunJavaScriptMessage(
2828 const std::wstring& message,
2829 const std::wstring& default_prompt,
2830 const GURL& frame_url,
2831 const int flags,
2832 IPC::Message* reply_msg,
2833 bool* did_suppress_message) {
2834 // Suppress javascript messages when requested and when inside a constrained
2835 // popup window (because that activates them and breaks them out of the
2836 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552837 // Also suppress messages when showing an interstitial. The interstitial is
2838 // shown over the previous page, we don't want the hidden page dialogs to
2839 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502840 bool suppress_this_message =
2841 suppress_javascript_messages_ ||
2842 showing_interstitial_page() ||
2843 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322844 if (delegate())
2845 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312846 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322847
2848 *did_suppress_message = suppress_this_message;
2849
2850 if (!suppress_this_message) {
2851 base::TimeDelta time_since_last_message(
2852 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2853 bool show_suppress_checkbox = false;
2854 // Show a checkbox offering to suppress further messages if this message is
2855 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2856 if (time_since_last_message <
2857 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2858 show_suppress_checkbox = true;
2859
[email protected]d6ad7442010-09-05 19:06:522860 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2861 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322862 } else {
2863 // If we are suppressing messages, just reply as is if the user immediately
2864 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542865 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322866 }
2867}
2868
2869void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2870 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292871 if (delegate())
2872 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502873 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2874 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2875 std::wstring());
2876 return;
2877 }
[email protected]7ab1e7d62009-10-14 23:32:012878 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222879 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322880}
2881
2882void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2883 const std::string& json_arguments,
2884 IPC::Message* reply_msg) {
2885 if (delegate()) {
2886 HtmlDialogUIDelegate* dialog_delegate =
2887 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222888 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322889 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2890 }
2891}
2892
[email protected]c4aa86962010-11-24 23:08:042893void TabContents::PasswordFormsFound(
2894 const std::vector<webkit_glue::PasswordForm>& forms) {
2895 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2896 PasswordFormsFound(forms));
2897}
2898
2899void TabContents::PasswordFormsVisible(
2900 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2901 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2902 PasswordFormsVisible(visible_forms));
2903}
2904
[email protected]420ae012009-04-24 05:16:322905// Checks to see if we should generate a keyword based on the OSDD, and if
2906// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202907void TabContents::PageHasOSDD(
2908 RenderViewHost* render_view_host,
2909 int32 page_id,
2910 const GURL& url,
2911 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122912 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322913 DCHECK(url.is_valid());
2914 if (!IsActiveEntry(page_id))
2915 return;
[email protected]420ae012009-04-24 05:16:322916 if (!profile()->GetTemplateURLFetcher())
2917 return;
[email protected]420ae012009-04-24 05:16:322918 if (profile()->IsOffTheRecord())
2919 return;
2920
[email protected]2de7e002010-10-11 22:58:202921 TemplateURLFetcher::ProviderType provider_type;
2922 switch (msg_provider_type.type) {
2923 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2924 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2925 break;
2926
2927 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2928 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2929 break;
2930
2931 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2932 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2933 break;
2934
2935 default:
2936 NOTREACHED();
2937 return;
2938 }
2939
[email protected]420ae012009-04-24 05:16:322940 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2941 DCHECK(entry);
2942
2943 const NavigationEntry* base_entry = entry;
2944 if (IsFormSubmit(base_entry)) {
2945 // If the current page is a form submit, find the last page that was not
2946 // a form submit and use its url to generate the keyword from.
2947 int index = controller_.last_committed_entry_index() - 1;
2948 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2949 index--;
2950 if (index >= 0)
2951 base_entry = controller_.GetEntryAtIndex(index);
2952 else
2953 base_entry = NULL;
2954 }
2955
2956 // We want to use the user typed URL if available since that represents what
2957 // the user typed to get here, and fall back on the regular URL if not.
2958 if (!base_entry)
2959 return;
2960 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2961 base_entry->user_typed_url() : base_entry->url();
2962 if (!keyword_url.is_valid())
2963 return;
[email protected]2de7e002010-10-11 22:58:202964
[email protected]0b5b85c2010-10-11 23:00:122965 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2966 keyword_url,
2967 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532968
[email protected]0b5b85c2010-10-11 23:00:122969 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322970 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322971 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2972 keyword,
2973 url,
2974 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122975 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202976 provider_type);
[email protected]420ae012009-04-24 05:16:322977}
2978
[email protected]420ae012009-04-24 05:16:322979GURL TabContents::GetAlternateErrorPageURL() const {
2980 GURL url;
2981 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2982 if (profile()->IsOffTheRecord())
2983 return url;
2984
2985 PrefService* prefs = profile()->GetPrefs();
2986 DCHECK(prefs);
2987 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152988 url = google_util::AppendGoogleLocaleParam(
2989 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322990 url = google_util::AppendGoogleTLDParam(url);
2991 }
2992 return url;
2993}
2994
2995WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062996 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552997 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082998 WebPreferences web_prefs =
2999 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
3000
[email protected]9beff752010-09-22 19:35:433001 // Force accelerated compositing and 2d canvas off for chrome: and
3002 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:433003 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
3004 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:083005 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:433006 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:083007 }
3008
[email protected]39553442010-09-09 00:01:553009#if defined(OS_MACOSX)
3010 // Disable accelerated compositing if IOSurface's are not supported,
3011 // as is the case in 10.5.
3012 if (!IOSurfaceSupport::Initialize())
3013 web_prefs.accelerated_compositing_enabled = false;
3014#endif
3015
[email protected]447021c2010-09-08 21:29:083016 return web_prefs;
[email protected]420ae012009-04-24 05:16:323017}
3018
[email protected]fa1cf0b82010-01-15 21:49:443019void TabContents::OnIgnoredUIEvent() {
3020 if (constrained_window_count()) {
3021 ConstrainedWindow* window = *constrained_window_begin();
3022 window->FocusConstrainedWindow();
3023 }
3024}
3025
[email protected]420ae012009-04-24 05:16:323026void TabContents::OnJSOutOfMemory() {
3027 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:583028 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
3029 NULL, true));
[email protected]420ae012009-04-24 05:16:323030}
3031
[email protected]420ae012009-04-24 05:16:323032void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
3033 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:343034 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:323035 // delivered to a pending RenderViewHost. We must first run the onunload
3036 // handler of the old RenderViewHost before we can allow it to proceed.
3037 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
3038 new_request_id);
3039}
3040
[email protected]420ae012009-04-24 05:16:323041void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3042 bool is_during_unload) {
3043 if (is_during_unload) {
3044 // Hang occurred while firing the beforeunload/unload handler.
3045 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113046 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323047
3048 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3049 return;
3050
3051 // If the tab hangs in the beforeunload/unload handler there's really
3052 // nothing we can do to recover. Pretend the unload listeners have
3053 // all fired and close the tab. If the hang is in the beforeunload handler
3054 // then the user will not have the option of cancelling the close.
3055 Close(rvh);
3056 return;
3057 }
3058
3059 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003060 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323061}
3062
3063void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003064 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323065}
3066
3067void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563068 net::LoadState load_state,
3069 uint64 upload_position,
3070 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323071 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563072 upload_position_ = upload_position;
3073 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293074 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193075 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293076 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533077 load_state_host_ =
3078 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323079 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3080 SetNotWaitingForResponse();
3081 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503082 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323083}
3084
[email protected]1ee614862009-07-06 20:29:183085bool TabContents::IsExternalTabContainer() const {
3086 if (!delegate())
3087 return false;
3088
3089 return delegate()->IsExternalTabContainer();
3090}
3091
[email protected]1ee614862009-07-06 20:29:183092void TabContents::DidInsertCSS() {
3093 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323094}
3095
[email protected]546ae4e02010-12-08 14:57:193096void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353097 NotificationService::current()->Notify(
3098 NotificationType::FOCUS_CHANGED_IN_PAGE,
3099 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193100 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353101}
3102
[email protected]b75b8292010-10-01 07:28:253103void TabContents::UpdateZoomLimits(int minimum_percent,
3104 int maximum_percent,
3105 bool remember) {
3106 minimum_zoom_percent_ = minimum_percent;
3107 maximum_zoom_percent_ = maximum_percent;
3108 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383109}
3110
[email protected]9e823662010-10-13 23:36:003111void TabContents::UpdateContentRestrictions(int restrictions) {
3112 content_restrictions_ = restrictions;
3113 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323114}
3115
[email protected]420ae012009-04-24 05:16:323116void TabContents::BeforeUnloadFiredFromRenderManager(
3117 bool proceed,
3118 bool* proceed_to_fire_unload) {
3119 if (delegate())
3120 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3121}
3122
[email protected]3a3d47472010-07-15 21:03:543123void TabContents::DidStartLoadingFromRenderManager(
3124 RenderViewHost* render_view_host) {
3125 DidStartLoading();
3126}
3127
3128void TabContents::RenderViewGoneFromRenderManager(
3129 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233130 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3131 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543132}
3133
[email protected]420ae012009-04-24 05:16:323134void TabContents::UpdateRenderViewSizeForRenderManager() {
3135 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263136 gfx::Size size = view_->GetContainerSize();
3137 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3138 // here during container initialization and normal window size will be set
3139 // later. In case of tab duplication this resizing to 0x0 prevents setting
3140 // normal size later so just ignore it.
3141 if (!size.IsEmpty())
3142 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323143}
3144
[email protected]3a3d47472010-07-15 21:03:543145void TabContents::NotifySwappedFromRenderManager() {
3146 NotifySwapped();
3147}
3148
3149NavigationController& TabContents::GetControllerForRenderManager() {
3150 return controller();
3151}
3152
[email protected]420ae012009-04-24 05:16:323153DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223154 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323155}
3156
3157NavigationEntry*
3158TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3159 return controller_.GetLastCommittedEntry();
3160}
3161
3162bool TabContents::CreateRenderViewForRenderManager(
3163 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323164 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523165
[email protected]674b3822010-08-04 04:02:513166 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323167 return false;
3168
3169 // Now that the RenderView has been created, we need to tell it its size.
3170 rwh_view->SetSize(view_->GetContainerSize());
3171
3172 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3173 render_view_host);
3174 return true;
3175}
3176
3177void TabContents::Observe(NotificationType type,
3178 const NotificationSource& source,
3179 const NotificationDetails& details) {
3180 switch (type.value) {
3181 case NotificationType::BOOKMARK_MODEL_LOADED:
3182 // BookmarkModel finished loading, fall through to update starred state.
3183 case NotificationType::URLS_STARRED: {
3184 // Somewhere, a URL has been starred.
3185 // Ignore notifications for profiles other than our current one.
3186 Profile* source_profile = Source<Profile>(source).ptr();
3187 if (!source_profile || !source_profile->IsSameProfile(profile()))
3188 return;
3189
3190 UpdateStarredStateForCurrentURL();
3191 break;
3192 }
3193 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513194 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323195 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3196 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3197 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533198 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3199 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323200 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173201 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3202 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323203 } else {
3204 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3205 }
3206 break;
3207 }
3208 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3209 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3210 break;
3211
3212 case NotificationType::NAV_ENTRY_COMMITTED: {
3213 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3214
3215 NavigationController::LoadCommittedDetails& committed_details =
3216 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3217 ExpireInfoBars(committed_details);
3218 break;
3219 }
3220
[email protected]d3ba77272009-09-03 00:06:093221#if defined(OS_LINUX)
3222 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543223 renderer_preferences_util::UpdateFromSystemSettings(
3224 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093225 render_view_host()->SyncRendererPrefs();
3226 break;
3227 }
3228#endif
3229
[email protected]6c32ce72010-03-08 05:18:063230 case NotificationType::USER_STYLE_SHEET_UPDATED:
3231 UpdateWebPreferences();
3232 break;
3233
[email protected]79580c62010-02-02 02:36:253234 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453235 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253236 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493237 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293238 if (entry)
[email protected]da0c8e92010-02-09 23:25:493239 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293240 if (settings_details.ptr()->update_all() ||
3241 settings_details.ptr()->pattern().Matches(entry_url)) {
3242 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233243 profile()->GetHostContentSettingsMap()->
3244 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253245 }
3246 break;
3247 }
3248
[email protected]e5adff72010-06-14 18:13:063249 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573250 break;
[email protected]a888b29e62010-04-01 13:38:573251
3252 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063253 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573254 break;
[email protected]a888b29e62010-04-01 13:38:573255
[email protected]88152052010-10-01 04:05:183256 case NotificationType::GOOGLE_URL_UPDATED:
3257 UpdateAlternateErrorPageURL();
3258 break;
3259
[email protected]420ae012009-04-24 05:16:323260 default:
3261 NOTREACHED();
3262 }
3263}
[email protected]aacd7cc2009-09-02 14:51:103264
[email protected]9adb9692010-10-29 23:14:023265void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083266 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433267
[email protected]a888b29e62010-04-01 13:38:573268 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083269 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3270 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573271 extension,
[email protected]807871f2010-09-16 01:04:483272 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3273 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573274 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3275 Extension::EXTENSION_ICON_SMALLISH),
3276 ImageLoadingTracker::CACHE);
3277 } else {
[email protected]98aa0b52010-05-06 17:03:083278 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573279 }
3280}
3281
[email protected]9adb9692010-10-29 23:14:023282const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:003283 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:573284 if (!extensions_service)
3285 return NULL;
3286
[email protected]9adb9692010-10-29 23:14:023287 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573288 return extension ?
3289 extension : extensions_service->GetExtensionByWebExtent(url);
3290}
3291
[email protected]a888b29e62010-04-01 13:38:573292void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3293 int index) {
3294 if (image) {
[email protected]98aa0b52010-05-06 17:03:083295 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573296 NotifyNavigationStateChanged(INVALIDATE_TAB);
3297 }
3298}
3299
[email protected]beb440c2009-11-06 04:08:543300gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3301 return view_->GetTopLevelNativeWindow();
3302}
3303
3304void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3305 bool success,
3306 const std::wstring& prompt) {
3307 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3308 if (is_showing_before_unload_dialog_ && !success) {
3309 // If a beforeunload dialog is canceled, we need to stop the throbber from
3310 // spinning, since we forced it to start spinning in Navigate.
3311 DidStopLoading();
3312
3313 tab_close_start_time_ = base::TimeTicks();
3314 }
3315 is_showing_before_unload_dialog_ = false;
3316 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3317}
3318
3319void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3320 set_suppress_javascript_messages(suppress_message_boxes);
3321}
3322
[email protected]3a3d47472010-07-15 21:03:543323TabContents* TabContents::AsTabContents() {
3324 return this;
3325}
3326
3327ExtensionHost* TabContents::AsExtensionHost() {
3328 return NULL;
3329}
3330
[email protected]41fc0322009-09-04 22:23:403331void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103332 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3333}
[email protected]f45d2a72010-03-08 23:28:353334
3335void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3336 app_icon_ = app_icon;
3337 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3338}
[email protected]33f74972010-12-08 16:40:363339
3340void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3341 render_manager_.SwapInRenderViewHost(rvh);
3342}
3343
3344void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3345 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3346 rwh_view->SetSize(view()->GetContainerSize());
3347}