blob: 3aeb4e040079e2a1700354de8802d669ebc2f64d [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]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5529#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1030#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4531#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3332#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1434#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5436#include "chrome/browser/dom_ui/dom_ui.h"
37#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0238#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3239#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0140#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4941#include "chrome/browser/external_protocol_handler.h"
[email protected]eaa7dd182010-12-14 11:09:0042#include "chrome/browser/extensions/extension_service.h"
[email protected]ef0d04c2010-12-15 23:34:2143#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5844#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4245#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2546#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4847#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4948#include "chrome/browser/file_select_helper.h"
[email protected]f7578f52010-08-30 22:22:4949#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3252#include "chrome/browser/load_from_memory_cache_details.h"
53#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4454#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0555#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1056#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2457#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5758#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0259#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3660#include "chrome/browser/prerender/prerender_manager.h"
[email protected]dbeebd52010-11-16 20:34:1661#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0962#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3363#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1665#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5466#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3767#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0768#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5469#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3270#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1171#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1672#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1273#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1775#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1776#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5477#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1678#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4379#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1680#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4981#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5782#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4983#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1684#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3585#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1486#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5887#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2788#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2189#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4990#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5791#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4892#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1493#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0994#include "chrome/common/extensions/url_pattern.h"
95#include "chrome/common/navigation_types.h"
96#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5697#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2998#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3299#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:02100#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:18101#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54102#include "chrome/common/url_constants.h"
[email protected]ef0d04c2010-12-15 23:34:21103#include "gfx/codec/png_codec.h"
[email protected]ea68c06a2010-04-23 17:25:37104#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26105#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32106#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06107#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37108#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32109#include "net/base/mime_util.h"
110#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29111#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32112#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25113#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18114#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03115#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00116#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00117
[email protected]420ae012009-04-24 05:16:32118// Cross-Site Navigations
119//
120// If a TabContents is told to navigate to a different web site (as determined
121// by SiteInstance), it will replace its current RenderViewHost with a new
122// RenderViewHost dedicated to the new SiteInstance. This works as follows:
123//
124// - Navigate determines whether the destination is cross-site, and if so,
125// it creates a pending_render_view_host_ and moves into the PENDING
126// RendererState.
127// - The pending RVH is "suspended," so that no navigation messages are sent to
128// its renderer until the onbeforeunload JavaScript handler has a chance to
129// run in the current RVH.
130// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
131// that it has a pending cross-site request. ResourceDispatcherHost will
132// check for this when the response arrives.
133// - The current RVH runs its onbeforeunload handler. If it returns false, we
134// cancel all the pending logic and go back to NORMAL. Otherwise we allow
135// the pending RVH to send the navigation request to its renderer.
136// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
137// checks CrossSiteRequestManager to see that the RVH responsible has a
138// pending cross-site request, and then installs a CrossSiteEventHandler.
139// - When RDH receives a response, the BufferedEventHandler determines whether
140// it is a download. If so, it sends a message to the new renderer causing
141// it to cancel the request, and the download proceeds in the download
142// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34143// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32144// doesn't affect any functionality.
145// - After RDH receives a response and determines that it is safe and not a
146// download, it pauses the response to first run the old page's onunload
147// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34148// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32149// to the current RVH.
150// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
151// the ResourceDispatcherHost, who unpauses the response. Data is then sent
152// to the pending RVH.
153// - The pending renderer sends a FrameNavigate message that invokes the
154// DidNavigate method. This replaces the current RVH with the
155// pending RVH and goes back to the NORMAL RendererState.
156
157namespace {
158
159// Amount of time we wait between when a key event is received and the renderer
160// is queried for its state and pushed to the NavigationEntry.
161const int kQueryStateDelay = 5000;
162
[email protected]6ebdc9b2010-09-27 16:55:57163const int kSyncWaitDelay = 40;
164
[email protected]420ae012009-04-24 05:16:32165// If another javascript message box is displayed within
166// kJavascriptMessageExpectedDelay of a previous javascript message box being
167// dismissed, display an option to suppress future message boxes from this
168// contents.
169const int kJavascriptMessageExpectedDelay = 1000;
170
[email protected]420ae012009-04-24 05:16:32171// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51172const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32173 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17174 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32175 prefs::kWebKitJavaEnabled,
176 prefs::kWebKitJavascriptEnabled,
177 prefs::kWebKitLoadsImagesAutomatically,
178 prefs::kWebKitPluginsEnabled,
179 prefs::kWebKitUsesUniversalDetector,
180 prefs::kWebKitSerifFontFamily,
181 prefs::kWebKitSansSerifFontFamily,
182 prefs::kWebKitFixedFontFamily,
183 prefs::kWebKitDefaultFontSize,
184 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13185 prefs::kWebKitMinimumFontSize,
186 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36187 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32188 prefs::kDefaultCharset
189 // kWebKitStandardFontIsSerif needs to be added
190 // if we let users pick which font to use, serif or sans-serif when
191 // no font is specified or a CSS generic family (serif or sans-serif)
192 // is not specified.
193};
194
195const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
196
[email protected]420ae012009-04-24 05:16:32197// Returns true if the entry's transition type is FORM_SUBMIT.
198bool IsFormSubmit(const NavigationEntry* entry) {
199 return (PageTransition::StripQualifier(entry->transition_type()) ==
200 PageTransition::FORM_SUBMIT);
201}
202
203#if defined(OS_WIN)
204
205BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
206 // Note: erase is required to properly paint some widgets borders. This can
207 // be seen with textfields.
208 InvalidateRect(hwnd, NULL, TRUE);
209 return TRUE;
210}
211#endif
212
[email protected]5e369672009-11-03 23:48:30213ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16214 Profile* profile, const NavigationEntry& entry,
215 NavigationController::ReloadType reload_type) {
216 switch (reload_type) {
217 case NavigationController::RELOAD:
218 return ViewMsg_Navigate_Params::RELOAD;
219 case NavigationController::RELOAD_IGNORING_CACHE:
220 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
221 case NavigationController::NO_RELOAD:
222 break; // Fall through to rest of function.
223 }
[email protected]5e369672009-11-03 23:48:30224
225 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
226 profile->DidLastSessionExitCleanly())
227 return ViewMsg_Navigate_Params::RESTORE;
228
229 return ViewMsg_Navigate_Params::NORMAL;
230}
231
[email protected]876bc832010-09-07 16:29:54232void MakeNavigateParams(const NavigationEntry& entry,
233 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16234 NavigationController::ReloadType reload_type,
235 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34236 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54237 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00238 params->current_history_list_offset = controller.last_committed_entry_index();
239 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34240 params->url = entry.url();
241 params->referrer = entry.referrer();
242 params->transition = entry.transition_type();
243 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00244 params->navigation_type =
245 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34246 params->request_time = base::Time::Now();
247}
248
[email protected]851b1eb2010-08-09 13:32:29249class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
250 public:
251 DisabledPluginInfoBar(TabContents* tab_contents,
252 const string16& name,
253 const GURL& update_url)
254 : ConfirmInfoBarDelegate(tab_contents),
255 tab_contents_(tab_contents),
256 name_(name),
257 update_url_(update_url) {
258 tab_contents->AddInfoBar(this);
259 }
260
261 virtual int GetButtons() const {
262 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
263 }
264
[email protected]e23d3a32010-08-13 19:39:58265 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29266 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58267 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29268 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58269 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29270 return ConfirmInfoBarDelegate::GetButtonLabel(button);
271 }
272
[email protected]e23d3a32010-08-13 19:39:58273 virtual string16 GetMessageText() const {
274 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29275 }
276
[email protected]e23d3a32010-08-13 19:39:58277 virtual string16 GetLinkText() {
278 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29279 }
280
281 virtual SkBitmap* GetIcon() const {
282 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
283 IDR_INFOBAR_PLUGIN_INSTALL);
284 }
285
286 virtual bool Accept() {
287 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51288 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29289 return false;
290 }
291
292 virtual bool Cancel() {
293 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51294 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29295 return false;
296 }
297
298 virtual bool LinkClicked(WindowOpenDisposition disposition) {
299 // TODO(bauerb): Navigate to a help page explaining why we disabled
300 // the plugin, once we have one.
301 return false;
302 }
303
304 private:
305 TabContents* tab_contents_;
306 string16 name_;
307 GURL update_url_;
308};
309
[email protected]420ae012009-04-24 05:16:32310} // namespace
311
312// -----------------------------------------------------------------------------
313
[email protected]fdd61c62009-04-22 19:22:57314// static
315int TabContents::find_request_id_counter_ = -1;
316
[email protected]420ae012009-04-24 05:16:32317
[email protected]420ae012009-04-24 05:16:32318TabContents::TabContents(Profile* profile,
319 SiteInstance* site_instance,
320 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07321 const TabContents* base_tab_contents,
322 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42323 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07324 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
325 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13326 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22327 TabContentsView::Create(this))),
328 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57329 property_bag_(),
330 registrar_(),
[email protected]12802702010-07-09 19:43:09331 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
332 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57333 save_package_(),
[email protected]6db0def92010-03-02 19:55:45334 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21335 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57336 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06337 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22338 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34339 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23340 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
341 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34342 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34343 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57344 current_load_start_(),
345 load_state_(net::LOAD_STATE_IDLE),
346 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56347 upload_size_(0),
348 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57349 received_page_title_(false),
350 is_starred_(false),
351 contents_mime_type_(),
352 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40353 blocked_contents_(NULL),
354 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49355 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47356 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57357 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57358 find_ui_active_(false),
359 find_op_aborted_(false),
360 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12361 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12362 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08363 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57364 capturing_contents_(false),
365 is_being_destroyed_(false),
366 notify_disconnection_(false),
367 history_requests_(),
368#if defined(OS_WIN)
369 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
370#endif
371 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44372 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01373 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54374 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54375 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16376 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38377 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25378 minimum_zoom_percent_(
379 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
380 maximum_zoom_percent_(
381 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00382 temporary_zoom_settings_(false),
383 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54384 renderer_preferences_util::UpdateFromSystemSettings(
385 &renderer_preferences_, profile);
386
[email protected]9fb83e82010-07-02 18:24:55387 content_settings_delegate_.reset(
388 new TabSpecificContentSettings(this, profile));
389
[email protected]12636df2009-09-28 22:32:21390 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32391
[email protected]34ac70502009-09-25 17:07:23392 // We have the initial size of the view be based on the size of the passed in
393 // tab contents (normally a tab from the same window).
394 view_->CreateView(base_tab_contents ?
395 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32396
397 // Register for notifications about all interested prefs change.
398 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28399 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32400 if (prefs) {
401 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28402 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32403 }
404
405 // Register for notifications about URL starredness changing on any profile.
406 registrar_.Add(this, NotificationType::URLS_STARRED,
407 NotificationService::AllSources());
408 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
409 NotificationService::AllSources());
410 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
411 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09412#if defined(OS_LINUX)
413 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
414 NotificationService::AllSources());
415#endif
[email protected]420ae012009-04-24 05:16:32416
[email protected]6c32ce72010-03-08 05:18:06417 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
418 NotificationService::AllSources());
419
[email protected]79580c62010-02-02 02:36:25420 // Register for notifications about content setting changes.
421 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
422 NotificationService::AllSources());
423
[email protected]a888b29e62010-04-01 13:38:57424 // Listen for extension changes so we can update extension_for_current_page_.
425 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
426 NotificationService::AllSources());
427 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
428 NotificationService::AllSources());
429 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
430 NotificationService::AllSources());
431
[email protected]88152052010-10-01 04:05:18432 // Listen for Google URL changes
433 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
434 NotificationService::AllSources());
435
[email protected]c8865482009-07-23 20:40:10436 // Set-up the showing of the omnibox search infobar if applicable.
437 if (OmniboxSearchHint::IsEnabled(profile))
438 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35439}
initial.commit09911bf2008-07-26 23:55:29440
441TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32442 is_being_destroyed_ = true;
443
[email protected]bfe4c1582009-10-02 18:11:09444 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32445 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28446 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32447
[email protected]420ae012009-04-24 05:16:32448 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00449 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32450
[email protected]420ae012009-04-24 05:16:32451 // First cleanly close all child windows.
452 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
453 // some of these to close. CloseWindows is async, so it might get called
454 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49455 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32456
[email protected]c65e2f152010-10-14 15:30:40457 // Close all blocked contents.
458 if (blocked_contents_)
459 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13460
[email protected]420ae012009-04-24 05:16:32461 // Notify any observer that have a reference on this tab contents.
462 NotificationService::current()->Notify(
463 NotificationType::TAB_CONTENTS_DESTROYED,
464 Source<TabContents>(this),
465 NotificationService::NoDetails());
466
[email protected]1e5e74f2009-05-27 20:55:12467 // Notify any lasting InfobarDelegates that have not yet been removed that
468 // whatever infobar they were handling in this TabContents has closed,
469 // because the TabContents is going away entirely.
470 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
471 // notification may trigger infobars calls that access their delegate. (and
472 // some implementations of InfoBarDelegate do delete themselves on
473 // InfoBarClosed()).
474 for (int i = 0; i < infobar_delegate_count(); ++i) {
475 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
476 delegate->InfoBarClosed();
477 }
478 infobar_delegates_.clear();
479
[email protected]420ae012009-04-24 05:16:32480 // TODO(brettw) this should be moved to the view.
481#if defined(OS_WIN)
482 // If we still have a window handle, destroy it. GetNativeView can return
483 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42484 if (GetNativeView()) {
485 RenderViewHost* host = render_view_host();
486 if (host && host->view()) {
487 host->view()->WillWmDestroy();
488 }
[email protected]420ae012009-04-24 05:16:32489 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42490 }
[email protected]420ae012009-04-24 05:16:32491#endif
[email protected]7ab1e7d62009-10-14 23:32:01492
493 // OnCloseStarted isn't called in unit tests.
494 if (!tab_close_start_time_.is_null()) {
495 UMA_HISTOGRAM_TIMES("Tab.Close",
496 base::TimeTicks::Now() - tab_close_start_time_);
497 }
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]d5f942ba2008-09-26 19:30:34500// static
501void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32502 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
503
504 WebPreferences pref_defaults;
505 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
506 pref_defaults.javascript_enabled);
507 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
508 pref_defaults.web_security_enabled);
509 prefs->RegisterBooleanPref(
510 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
511 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
512 pref_defaults.loads_images_automatically);
513 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
514 pref_defaults.plugins_enabled);
515 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
516 pref_defaults.dom_paste_enabled);
517 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
518 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14519 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32520 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
521 pref_defaults.text_areas_are_resizable);
522 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
523 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36524 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
525 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32526
527 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
528 IDS_ACCEPT_LANGUAGES);
529 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
530 IDS_DEFAULT_ENCODING);
531 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
532 IDS_STANDARD_FONT_IS_SERIF);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
534 IDS_FIXED_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
536 IDS_SERIF_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
538 IDS_SANS_SERIF_FONT_FAMILY);
539 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
540 IDS_CURSIVE_FONT_FAMILY);
541 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
542 IDS_FANTASY_FONT_FAMILY);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
544 IDS_DEFAULT_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
546 IDS_DEFAULT_FIXED_FONT_SIZE);
547 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
548 IDS_MINIMUM_FONT_SIZE);
549 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
550 IDS_MINIMUM_LOGICAL_FONT_SIZE);
551 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
552 IDS_USES_UNIVERSAL_DETECTOR);
553 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
554 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29555}
556
[email protected]13367f72009-07-08 16:39:02557// Returns true if contains content rendered by an extension.
558bool TabContents::HostsExtension() const {
559 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34560}
561
[email protected]cf28ec52010-04-09 22:56:34562AutoFillManager* TabContents::GetAutoFillManager() {
563 if (autofill_manager_.get() == NULL)
564 autofill_manager_.reset(new AutoFillManager(this));
565 return autofill_manager_.get();
566}
567
[email protected]6e95706d2009-04-23 22:55:01568PluginInstaller* TabContents::GetPluginInstaller() {
569 if (plugin_installer_.get() == NULL)
570 plugin_installer_.reset(new PluginInstaller(this));
571 return plugin_installer_.get();
572}
573
[email protected]1f18184a2010-07-21 19:34:49574TabContentsSSLHelper* TabContents::GetSSLHelper() {
575 if (ssl_helper_.get() == NULL)
576 ssl_helper_.reset(new TabContentsSSLHelper(this));
577 return ssl_helper_.get();
578}
579
[email protected]8cb5d5b2010-02-09 11:36:16580RenderProcessHost* TabContents::GetRenderProcessHost() const {
581 return render_manager_.current_host()->process();
582}
583
[email protected]9adb9692010-10-29 23:14:02584void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46585 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08586 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10587
[email protected]98aa0b52010-05-06 17:03:08588 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57589
[email protected]fca656c2010-02-10 20:30:10590 NotificationService::current()->Notify(
591 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
592 Source<TabContents>(this),
593 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49594}
595
[email protected]98aa0b52010-05-06 17:03:08596void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
597 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40598 return;
599
[email protected]eaa7dd182010-12-14 11:09:00600 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50601 if (!extension_service || !extension_service->is_ready())
602 return;
603
604 const Extension* extension =
605 extension_service->GetExtensionById(extension_app_id, false);
606 if (extension)
607 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40608}
609
[email protected]98aa0b52010-05-06 17:03:08610SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08611 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51612 return NULL;
613
[email protected]98aa0b52010-05-06 17:03:08614 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51615}
616
[email protected]d5f942ba2008-09-26 19:30:34617const GURL& TabContents::GetURL() const {
618 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57619 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54620 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34621}
622
[email protected]96d185d2009-04-24 03:28:54623const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55624 // Transient entries take precedence. They are used for interstitial pages
625 // that are shown on top of existing pages.
626 NavigationEntry* entry = controller_.GetTransientEntry();
627 if (entry)
628 return entry->GetTitleForDisplay(&controller_);
629
[email protected]96d185d2009-04-24 03:28:54630 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
631 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
632 if (our_dom_ui) {
633 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55634 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54635 if (!(entry && entry->IsViewSourceMode())) {
636 // Give the DOM UI the chance to override our title.
637 const string16& title = our_dom_ui->overridden_title();
638 if (!title.empty())
639 return title;
640 }
641 }
642
643 // We use the title for the last committed entry rather than a pending
644 // navigation entry. For example, when the user types in a URL, we want to
645 // keep the old page's title until the new load has committed and we get a new
646 // title.
[email protected]96d185d2009-04-24 03:28:54647 entry = controller_.GetLastCommittedEntry();
648 if (entry)
649 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54650 return EmptyString16();
651}
652
[email protected]bbbc1ef2010-02-12 18:03:41653// static
654string16 TabContents::GetDefaultTitle() {
655 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
656}
657
[email protected]d5f942ba2008-09-26 19:30:34658int32 TabContents::GetMaxPageID() {
659 if (GetSiteInstance())
660 return GetSiteInstance()->max_page_id();
661 else
662 return max_page_id_;
663}
664
665void TabContents::UpdateMaxPageID(int32 page_id) {
666 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34667 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34668 // testing.
669 if (GetSiteInstance())
670 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16671 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34672}
673
[email protected]96d185d2009-04-24 03:28:54674SiteInstance* TabContents::GetSiteInstance() const {
675 return render_manager_.current_host()->site_instance();
676}
677
[email protected]96d185d2009-04-24 03:28:54678bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15679 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54680 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15681 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01682 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54683 return true;
[email protected]8ab24cc2009-11-13 20:56:15684 }
[email protected]83e3895b2009-06-11 00:07:16685
[email protected]96d185d2009-04-24 03:28:54686 DOMUI* dom_ui = GetDOMUIForCurrentState();
687 if (dom_ui)
688 return !dom_ui->should_hide_url();
689 return true;
690}
691
[email protected]d5f942ba2008-09-26 19:30:34692SkBitmap TabContents::GetFavIcon() const {
693 // Like GetTitle(), we also want to use the favicon for the last committed
694 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57695 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47696 if (entry)
697 return entry->favicon().bitmap();
698
[email protected]ce3fa3c2009-04-20 19:55:57699 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34700 if (entry)
701 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34702 return SkBitmap();
703}
704
[email protected]0b303cc2009-09-28 22:35:15705bool TabContents::FavIconIsValid() const {
706 NavigationEntry* entry = controller_.GetTransientEntry();
707 if (entry)
708 return entry->favicon().is_valid();
709
710 entry = controller_.GetLastCommittedEntry();
711 if (entry)
712 return entry->favicon().is_valid();
713
714 return false;
715}
716
[email protected]96d185d2009-04-24 03:28:54717bool TabContents::ShouldDisplayFavIcon() {
718 // Always display a throbber during pending loads.
719 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
720 return true;
721
722 DOMUI* dom_ui = GetDOMUIForCurrentState();
723 if (dom_ui)
724 return !dom_ui->hide_favicon();
725 return true;
726}
727
[email protected]96d185d2009-04-24 03:28:54728std::wstring TabContents::GetStatusText() const {
729 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
730 return std::wstring();
731
732 switch (load_state_) {
733 case net::LOAD_STATE_WAITING_FOR_CACHE:
734 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04735 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
736 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54737 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
738 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
739 case net::LOAD_STATE_RESOLVING_HOST:
740 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
741 case net::LOAD_STATE_CONNECTING:
742 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06743 case net::LOAD_STATE_SSL_HANDSHAKE:
744 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54745 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56746 if (upload_size_)
747 return l10n_util::GetStringF(
748 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
749 static_cast<int>((100 * upload_position_) / upload_size_));
750 else
751 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54752 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
753 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
754 load_state_host_);
755 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
756 case net::LOAD_STATE_IDLE:
757 case net::LOAD_STATE_READING_RESPONSE:
758 break;
759 }
760
761 return std::wstring();
762}
763
[email protected]3c9e1872010-11-18 16:17:49764void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
765 web_navigation_observers_.AddObserver(observer);
766}
767
768void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
769 web_navigation_observers_.RemoveObserver(observer);
770}
771
[email protected]443b80e2010-12-14 00:42:23772void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
773 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34774 return;
775
[email protected]443b80e2010-12-14 00:42:23776 crashed_status_ = status;
777 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50778 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34779}
780
[email protected]744ef172009-10-16 21:53:46781void TabContents::PageActionStateChanged() {
782 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00783}
[email protected]ce5c4502009-05-06 16:46:11784
[email protected]d5f942ba2008-09-26 19:30:34785void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
786 if (delegate_)
787 delegate_->NavigationStateChanged(this, changed_flags);
788}
789
[email protected]96d185d2009-04-24 03:28:54790void TabContents::DidBecomeSelected() {
791 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16792 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
793 if (rwhv) {
794 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43795#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16796 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43797#endif
798 }
[email protected]96d185d2009-04-24 03:28:54799
[email protected]8cb5d5b2010-02-09 11:36:16800 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11801 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54802}
803
[email protected]1b072562010-12-13 19:37:45804void TabContents::FadeForInstant() {
805 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
806 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
807 if (rwhv)
808 rwhv->SetVisuallyDeemphasized(&whitish, true);
809}
810
811void TabContents::CancelInstantFade() {
812 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
813 if (rwhv)
814 rwhv->SetVisuallyDeemphasized(NULL, false);
815}
816
[email protected]96d185d2009-04-24 03:28:54817void TabContents::WasHidden() {
818 if (!capturing_contents()) {
819 // |render_view_host()| can be NULL if the user middle clicks a link to open
820 // a tab in then background, then closes the tab before selecting it. This
821 // is because closing the tab calls TabContents::Destroy(), which removes
822 // the |render_view_host()|; then when we actually destroy the window,
823 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16824 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
825 if (rwhv)
826 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54827 }
828
829 NotificationService::current()->Notify(
830 NotificationType::TAB_CONTENTS_HIDDEN,
831 Source<TabContents>(this),
832 NotificationService::NoDetails());
833}
834
[email protected]d5f942ba2008-09-26 19:30:34835void TabContents::Activate() {
836 if (delegate_)
837 delegate_->ActivateContents(this);
838}
839
[email protected]ea42e7782010-08-23 23:58:12840void TabContents::Deactivate() {
841 if (delegate_)
842 delegate_->DeactivateContents(this);
843}
844
[email protected]96d185d2009-04-24 03:28:54845void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16846 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
847 if (rwhv)
848 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54849}
850
851void TabContents::HideContents() {
852 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
853 // our superclass HideContents(), because some callers want to be very picky
854 // about the order in which these get called. In addition to making the code
855 // here practically impossible to understand, this also means we end up
856 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34857 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54858 WasHidden();
859}
860
[email protected]5aab5e22010-12-08 22:13:29861bool TabContents::NeedToFireBeforeUnload() {
862 // TODO(creis): Should we fire even for interstitial pages?
863 return notify_disconnection() &&
864 !showing_interstitial_page() &&
865 !render_view_host()->SuddenTerminationAllowed();
866}
867
[email protected]c0588052008-10-27 23:01:50868void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34869 WindowOpenDisposition disposition,
870 PageTransition::Type transition) {
871 if (delegate_)
[email protected]c0588052008-10-27 23:01:50872 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34873}
874
[email protected]1ccb3568d2010-02-19 10:51:16875bool TabContents::NavigateToPendingEntry(
876 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54877 return NavigateToEntry(*controller_.pending_entry(), reload_type);
878}
[email protected]96d185d2009-04-24 03:28:54879
[email protected]876bc832010-09-07 16:29:54880bool TabContents::NavigateToEntry(
881 const NavigationEntry& entry,
882 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54883 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
884 if (!dest_render_view_host)
885 return false; // Unable to create the desired render view host.
886
[email protected]770dd8b2010-05-24 18:11:39887 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
888 dest_render_view_host->EnablePreferredSizeChangedMode(
889 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
890 }
[email protected]9fb325e2010-05-06 18:23:24891
[email protected]05fdd492010-11-15 17:52:07892 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
893 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58894 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40895 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07896 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58897 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40898 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58899
[email protected]96d185d2009-04-24 03:28:54900 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12901 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32902 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00903 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
904 dest_render_view_host,
905 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32906 }
[email protected]96d185d2009-04-24 03:28:54907
908 // Used for page load time metrics.
909 current_load_start_ = base::TimeTicks::Now();
910
911 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34912 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54913 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04914 if (delegate_) {
915 navigate_params.extra_headers =
916 delegate_->GetNavigationHeaders(navigate_params.url);
917 }
[email protected]056de2d2009-06-26 16:41:34918 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54919
920 if (entry.page_id() == -1) {
921 // HACK!! This code suppresses javascript: URLs from being added to
922 // session history, which is what we want to do for javascript: URLs that
923 // do not generate content. What we really need is a message from the
924 // renderer telling us that a new page was not created. The same message
925 // could be used for mailto: URLs and the like.
926 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
927 return false;
928 }
929
[email protected]3c9e1872010-11-18 16:17:49930 // Notify observers about navigation.
931 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
932 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54933
[email protected]1ccb3568d2010-02-19 10:51:16934 if (reload_type != NavigationController::NO_RELOAD &&
935 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48936 FaviconService* favicon_service =
937 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
938 if (favicon_service)
939 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54940 }
941
[email protected]d5f942ba2008-09-26 19:30:34942 return true;
943}
944
[email protected]96d185d2009-04-24 03:28:54945void TabContents::Stop() {
946 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09947 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54948}
949
[email protected]96d185d2009-04-24 03:28:54950void TabContents::DisassociateFromPopupCount() {
951 render_view_host()->DisassociateFromPopupCount();
952}
953
954TabContents* TabContents::Clone() {
955 // We create a new SiteInstance so that the new tab won't share processes
956 // with the old one. This can be changed in the future if we need it to share
957 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32958 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54959 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07960 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54961 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08962 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08963 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54964 return tc;
965}
966
[email protected]4d677202009-07-19 07:37:12967void TabContents::ShowPageInfo(const GURL& url,
968 const NavigationEntry::SSLStatus& ssl,
969 bool show_history) {
970 if (!delegate_)
971 return;
972
[email protected]bb678332009-07-21 00:15:50973 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12974}
975
[email protected]ef0d04c2010-12-15 23:34:21976void TabContents::SaveFavicon() {
977 NavigationEntry* entry = controller_.GetActiveEntry();
978 if (!entry || entry->url().is_empty())
979 return;
980
981 // Make sure the page is in history, otherwise adding the favicon does
982 // nothing.
983 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
984 Profile::IMPLICIT_ACCESS);
985 if (!history)
986 return;
987 history->AddPageNoVisitForBookmark(entry->url());
988
989 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
990 Profile::IMPLICIT_ACCESS);
991 if (!service)
992 return;
993 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
994 if (!favicon.is_valid() || favicon.url().is_empty() ||
995 favicon.bitmap().empty()) {
996 return;
997 }
998 std::vector<unsigned char> image_data;
999 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
1000 service->SetFavicon(entry->url(), favicon.url(), image_data);
1001}
1002
initial.commit09911bf2008-07-26 23:55:291003ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:281004 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:291005 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:281006 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:291007 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:441008
1009 if (child_windows_.size() == 1) {
1010 window->ShowConstrainedWindow();
1011 BlockTabContent(true);
1012 }
1013
initial.commit09911bf2008-07-26 23:55:291014 return window;
1015}
1016
[email protected]fa1cf0b82010-01-15 21:49:441017void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:551018 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:451019 // 70% opaque grey.
1020 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:551021 if (rwhv)
[email protected]1b072562010-12-13 19:37:451022 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:441023 render_view_host()->set_ignore_input_events(blocked);
1024 if (delegate_)
1025 delegate_->SetTabContentBlocked(this, blocked);
1026}
1027
initial.commit09911bf2008-07-26 23:55:291028void TabContents::AddNewContents(TabContents* new_contents,
1029 WindowOpenDisposition disposition,
1030 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291031 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401032 if (all_contents_blocked_) {
1033 if (!blocked_contents_)
1034 blocked_contents_ = new BlockedContentContainer(this);
1035 blocked_contents_->AddTabContents(
1036 new_contents, disposition, initial_pos, user_gesture);
1037 return;
1038 }
1039
initial.commit09911bf2008-07-26 23:55:291040 if (!delegate_)
1041 return;
1042
[email protected]35f7d212009-04-29 21:19:271043 if ((disposition == NEW_POPUP) && !user_gesture &&
1044 !CommandLine::ForCurrentProcess()->HasSwitch(
1045 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221046 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311047 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291048 delegate_->GetConstrainingContents(this)->AddPopup(
1049 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311050 } else {
[email protected]0aa55312008-10-17 21:53:081051 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291052 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1053 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491054 NotificationService::current()->Notify(
1055 NotificationType::TAB_ADDED,
1056 Source<TabContentsDelegate>(delegate_),
1057 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291058 }
initial.commit09911bf2008-07-26 23:55:291059
[email protected]8cc8d492010-02-02 10:40:491060 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401061 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291062}
1063
[email protected]bcd9dc42010-01-23 16:38:181064bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201065 bool is_js_code, const std::string& code_string,
1066 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511067 RenderViewHost* host = render_view_host();
1068 if (!host)
1069 return false;
1070
1071 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171072 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511073 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351074}
1075
[email protected]96d185d2009-04-24 03:28:541076void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491077 if (is_being_destroyed_)
1078 return;
[email protected]9fb83e82010-07-02 18:24:551079 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491080 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401081 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541082}
1083
[email protected]5c9e97a2009-09-09 23:48:301084gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541085 return view_->GetContentNativeView();
1086}
1087
1088gfx::NativeView TabContents::GetNativeView() const {
1089 return view_->GetNativeView();
1090}
1091
1092void TabContents::GetContainerBounds(gfx::Rect *out) const {
1093 view_->GetContainerBounds(out);
1094}
1095
1096void TabContents::Focus() {
1097 view_->Focus();
1098}
1099
[email protected]90daadb42009-06-08 21:27:281100void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541101 if (showing_interstitial_page()) {
1102 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1103 return;
1104 }
[email protected]96d185d2009-04-24 03:28:541105 render_view_host()->SetInitialFocus(reverse);
1106}
1107
1108bool TabContents::FocusLocationBarByDefault() {
1109 DOMUI* dom_ui = GetDOMUIForCurrentState();
1110 if (dom_ui)
1111 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431112 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251113 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431114 return true;
[email protected]96d185d2009-04-24 03:28:541115 return false;
1116}
1117
[email protected]a26dc362010-04-23 01:48:581118void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381119 if (delegate())
[email protected]a26dc362010-04-23 01:48:581120 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381121}
1122
[email protected]616ed5a2008-11-21 22:27:241123void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321124 if (delegate_ && !delegate_->infobars_enabled()) {
1125 delegate->InfoBarClosed();
1126 return;
1127 }
1128
[email protected]616ed5a2008-11-21 22:27:241129 // Look through the existing InfoBarDelegates we have for a match. If we've
1130 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051131 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451132 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1133 // Tell the new infobar to close so that it can clean itself up.
1134 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241135 return;
[email protected]6d27a7b2009-12-18 23:25:451136 }
[email protected]616ed5a2008-11-21 22:27:241137 }
1138
1139 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561140 NotificationService::current()->Notify(
1141 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1142 Source<TabContents>(this),
1143 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241144
1145 // Add ourselves as an observer for navigations the first time a delegate is
1146 // added. We use this notification to expire InfoBars that need to expire on
1147 // page transitions.
1148 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561149 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571150 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241151 }
1152}
1153
1154void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321155 if (delegate_ && !delegate_->infobars_enabled()) {
1156 return;
1157 }
1158
[email protected]616ed5a2008-11-21 22:27:241159 std::vector<InfoBarDelegate*>::iterator it =
1160 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1161 if (it != infobar_delegates_.end()) {
1162 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561163 NotificationService::current()->Notify(
1164 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1165 Source<TabContents>(this),
1166 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241167
[email protected]cdadf6f2010-08-20 16:36:081168 // Just to be safe, make sure the delegate was not removed by an observer.
1169 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1170 if (it != infobar_delegates_.end()) {
1171 infobar_delegates_.erase(it);
1172 // Remove ourselves as an observer if we are tracking no more InfoBars.
1173 if (infobar_delegates_.empty()) {
1174 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1175 Source<NavigationController>(&controller_));
1176 }
1177 } else {
1178 // If you hit this NOTREACHED, please comment in bug
1179 // http://crbug.com/50428 how you got there.
1180 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031181 }
[email protected]616ed5a2008-11-21 22:27:241182 }
1183}
[email protected]3edd9522009-03-04 22:19:411184
[email protected]f81821c2009-08-07 01:29:471185void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1186 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321187 if (delegate_ && !delegate_->infobars_enabled()) {
1188 new_delegate->InfoBarClosed();
1189 return;
1190 }
1191
[email protected]f81821c2009-08-07 01:29:471192 std::vector<InfoBarDelegate*>::iterator it =
1193 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1194 DCHECK(it != infobar_delegates_.end());
1195
1196 // Notify the container about the change of plans.
1197 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1198 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1199 old_delegate, new_delegate));
1200 NotificationService::current()->Notify(
1201 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1202 Source<TabContents>(this),
1203 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1204
[email protected]cdadf6f2010-08-20 16:36:081205 // Just to be safe, make sure the delegate was not removed by an observer.
1206 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1207 if (it != infobar_delegates_.end()) {
1208 // Remove the old one.
1209 infobar_delegates_.erase(it);
1210 } else {
1211 // If you hit this NOTREACHED, please comment in bug
1212 // http://crbug.com/50428 how you got there.
1213 NOTREACHED();
1214 }
[email protected]f81821c2009-08-07 01:29:471215
1216 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081217 DCHECK(find(infobar_delegates_.begin(),
1218 infobar_delegates_.end(), new_delegate) ==
1219 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471220 infobar_delegates_.push_back(new_delegate);
1221}
1222
[email protected]20ede072009-10-06 00:28:351223bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271224 if (showing_interstitial_page())
1225 return false;
1226
[email protected]c8f74942010-09-03 10:04:141227 // Do not show bookmarks bar if bookmarks aren't enabled.
1228 if (!browser_defaults::bookmarks_enabled)
1229 return false;
1230
[email protected]96d185d2009-04-24 03:28:541231 // See GetDOMUIForCurrentState() comment for more info. This case is very
1232 // similar, but for non-first loads, we want to use the committed entry. This
1233 // is so the bookmarks bar disappears at the same time the page does.
1234 if (controller_.GetLastCommittedEntry()) {
1235 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371236 return (render_manager_.dom_ui() == NULL) ?
1237 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541238 }
1239
1240 // When it's the first load, we know either the pending one or the committed
1241 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1242 // of them will be valid, so we can just check both.
1243 if (render_manager_.pending_dom_ui())
1244 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371245 return (render_manager_.dom_ui() == NULL) ?
1246 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541247}
1248
[email protected]3edd9522009-03-04 22:19:411249void TabContents::ToolbarSizeChanged(bool is_animating) {
1250 TabContentsDelegate* d = delegate();
1251 if (d)
1252 d->ToolbarSizeChanged(this, is_animating);
1253}
[email protected]616ed5a2008-11-21 22:27:241254
[email protected]fc6fb7fb2009-11-07 02:35:041255bool TabContents::CanDownload(int request_id) {
1256 TabContentsDelegate* d = delegate();
1257 if (d)
1258 return d->CanDownload(request_id);
1259 return true;
1260}
1261
[email protected]d5f942ba2008-09-26 19:30:341262void TabContents::OnStartDownload(DownloadItem* download) {
1263 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341264
1265 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311266 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341267
[email protected]5b928b62010-08-03 11:46:511268 if (tab_contents && tab_contents->delegate())
1269 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411270}
[email protected]3edd9522009-03-04 22:19:411271
[email protected]d5f942ba2008-09-26 19:30:341272void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371273 ConstrainedWindowList::iterator i(
1274 std::find(child_windows_.begin(), child_windows_.end(), window));
1275 bool removed_topmost_window = i == child_windows_.begin();
1276 if (i != child_windows_.end())
1277 child_windows_.erase(i);
1278 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441279 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371280 } else {
1281 if (removed_topmost_window)
1282 child_windows_[0]->ShowConstrainedWindow();
1283 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441284 }
[email protected]66ba4932009-06-04 19:22:131285}
[email protected]d5f942ba2008-09-26 19:30:341286
[email protected]c65e2f152010-10-14 15:30:401287void TabContents::WillCloseBlockedContentContainer(
1288 BlockedContentContainer* container) {
1289 DCHECK(blocked_contents_ == container);
1290 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491291 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341292}
1293
[email protected]d5f942ba2008-09-26 19:30:341294void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351295#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061296 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351297#endif
[email protected]d5f942ba2008-09-26 19:30:341298}
1299
[email protected]c1dc9f132009-11-20 23:13:211300void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121301 bool forward_direction,
1302 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211303 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011304 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211305 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531306 string16 last_search_prepopulate_text =
1307 FindBarState::GetLastPrepopulateText(profile());
1308
[email protected]87fae512009-12-11 02:20:211309 // Try the last thing we searched for on this tab, then the last thing
1310 // searched for on any tab.
1311 if (!previous_find_text_.empty())
1312 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531313 else if (!last_search_prepopulate_text.empty())
1314 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211315 else
[email protected]e491f1c2009-05-22 20:28:121316 return;
[email protected]e491f1c2009-05-22 20:28:121317 }
[email protected]6e95706d2009-04-23 22:55:011318
[email protected]101c90e2009-10-26 21:14:441319 // Keep track of the previous search.
1320 previous_find_text_ = find_text_;
1321
[email protected]6e95706d2009-04-23 22:55:011322 // This is a FindNext operation if we are searching for the same text again,
1323 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1324 // exception to this is if the Find was aborted (then we don't want FindNext
1325 // because the highlighting has been cleared and we need it to reappear). We
1326 // therefore treat FindNext after an aborted Find operation as a full fledged
1327 // Find.
[email protected]c1dc9f132009-11-20 23:13:211328 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121329 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011330 !find_op_aborted_;
1331 if (!find_next)
1332 current_find_request_id_ = find_request_id_counter_++;
1333
[email protected]c1dc9f132009-11-20 23:13:211334 if (!search_string.empty())
1335 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121336 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011337
1338 find_op_aborted_ = false;
1339
1340 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531341 FindBarState* find_bar_state = profile()->GetFindBarState();
1342 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011343 render_view_host()->StartFinding(current_find_request_id_,
1344 find_text_,
1345 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121346 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011347 find_next);
1348}
1349
[email protected]5bc8fe92010-03-11 18:19:001350void TabContents::StopFinding(
1351 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011352 if (selection_action == FindBarController::kClearSelection) {
1353 // kClearSelection means the find string has been cleared by the user, but
1354 // the UI has not been dismissed. In that case we want to clear the
1355 // previously remembered search (http://crbug.com/42639).
1356 previous_find_text_ = string16();
1357 } else {
[email protected]2d2dffc2009-06-09 21:41:001358 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011359 if (!find_text_.empty())
1360 previous_find_text_ = find_text_;
1361 }
[email protected]101c90e2009-10-26 21:14:441362 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011363 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121364 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001365 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011366}
1367
[email protected]420ae012009-04-24 05:16:321368void TabContents::OnSavePage() {
1369 // If we can not save the page, try to download it.
1370 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1371 DownloadManager* dlm = profile()->GetDownloadManager();
1372 const GURL& current_page_url = GetURL();
1373 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221374 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321375 return;
1376 }
1377
1378 Stop();
1379
1380 // Create the save package and possibly prompt the user for the name to save
1381 // the page as. The user prompt is an asynchronous operation that runs on
1382 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221383 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321384 save_package_->GetSaveInfo();
1385}
1386
1387// Used in automated testing to bypass prompting the user for file names.
1388// Instead, the names and paths are hard coded rather than running them through
1389// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111390bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321391 SavePackage::SavePackageType save_type) {
1392 // Stop the page from navigating.
1393 Stop();
1394
[email protected]828cabe2009-09-26 22:47:111395 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591396 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321397}
1398
[email protected]89d6e6e2009-12-03 23:06:511399void TabContents::EmailPageLocation() {
1400 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1401 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1402 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1403 title + "&body=%0A%0A" + page_url;
1404 platform_util::OpenExternal(GURL(mailto));
1405}
1406
[email protected]420ae012009-04-24 05:16:321407void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161408 if (CommandLine::ForCurrentProcess()->HasSwitch(
1409 switches::kEnablePrintPreview)) {
1410 if (showing_interstitial_page())
1411 return;
1412 render_view_host()->PrintPreview();
1413 } else {
1414 PrintNow();
1415 }
[email protected]420ae012009-04-24 05:16:321416}
1417
1418bool TabContents::PrintNow() {
1419 // We can't print interstitial page for now.
1420 if (showing_interstitial_page())
1421 return false;
1422
1423 return render_view_host()->PrintPages();
1424}
1425
[email protected]82270452009-06-19 15:58:011426void TabContents::PrintingDone(int document_cookie, bool success) {
1427 render_view_host()->PrintingDone(document_cookie, success);
1428}
1429
[email protected]420ae012009-04-24 05:16:321430bool TabContents::IsActiveEntry(int32 page_id) {
1431 NavigationEntry* active_entry = controller_.GetActiveEntry();
1432 return (active_entry != NULL &&
1433 active_entry->site_instance() == GetSiteInstance() &&
1434 active_entry->page_id() == page_id);
1435}
1436
[email protected]b2fe07d12010-02-09 14:38:081437void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161438 set_encoding(encoding);
1439 render_view_host()->SetPageEncoding(encoding);
1440}
1441
[email protected]b2fe07d12010-02-09 14:38:081442void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161443 reset_encoding();
1444 render_view_host()->ResetPageEncodingToDefault();
1445}
1446
1447void TabContents::WindowMoveOrResizeStarted() {
1448 render_view_host()->WindowMoveOrResizeStarted();
1449}
1450
[email protected]c65e2f152010-10-14 15:30:401451void TabContents::SetAllContentsBlocked(bool value) {
1452 if (all_contents_blocked_ == value)
1453 return;
1454
1455 all_contents_blocked_ = value;
1456 if (!all_contents_blocked_ && blocked_contents_) {
1457 std::vector<TabContents*> blocked;
1458 blocked_contents_->GetBlockedContents(&blocked);
1459 for (size_t i = 0; i < blocked.size(); ++i)
1460 blocked_contents_->LaunchForContents(blocked[i]);
1461 }
1462}
1463
[email protected]3f8eb7f2009-10-02 23:58:051464void TabContents::LogNewTabTime(const std::string& event_name) {
1465 // Not all new tab pages get timed. In those cases, we don't have a
1466 // new_tab_start_time_.
1467 if (new_tab_start_time_.is_null())
1468 return;
1469
1470 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441471 MetricEventDurationDetails details(event_name,
1472 static_cast<int>(duration.InMilliseconds()));
1473
[email protected]7ab1e7d62009-10-14 23:32:011474 if (event_name == "Tab.NewTabScriptStart") {
1475 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1476 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1477 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1478 } else if (event_name == "Tab.NewTabOnload") {
1479 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051480 // The new tab page has finished loading; reset it.
1481 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441482 } else {
1483 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051484 }
[email protected]84abba62009-10-07 17:01:441485 NotificationService::current()->Notify(
1486 NotificationType::METRIC_EVENT_DURATION,
1487 Source<TabContents>(this),
1488 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051489}
1490
[email protected]7ab1e7d62009-10-14 23:32:011491void TabContents::OnCloseStarted() {
1492 if (tab_close_start_time_.is_null())
1493 tab_close_start_time_ = base::TimeTicks::Now();
1494}
1495
[email protected]46624bf2010-06-09 16:04:191496bool TabContents::ShouldAcceptDragAndDrop() const {
1497#if defined(OS_CHROMEOS)
1498 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1499 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201500 if (delegate() && delegate()->IsPopup(this))
1501 return false;
1502 return true;
[email protected]46624bf2010-06-09 16:04:191503#else
1504 return true;
1505#endif
1506}
1507
[email protected]ec0b6c42010-08-26 03:16:581508void TabContents::UpdateHistoryForNavigation(
1509 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1510 if (profile()->IsOffTheRecord())
1511 return;
1512
1513 // Add to history service.
1514 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1515 if (hs)
1516 hs->AddPage(*add_page_args);
1517}
1518
1519void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1520 if (profile()->IsOffTheRecord())
1521 return;
1522
1523 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1524 if (hs)
1525 hs->SetPageTitle(entry.virtual_url(), entry.title());
1526}
1527
[email protected]d0b8d092010-10-25 04:05:171528double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251529 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1530 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171531 return 0;
[email protected]b75b8292010-10-01 07:28:251532
1533 double zoom_level;
1534 if (temporary_zoom_settings_) {
1535 zoom_level = zoom_map->GetTemporaryZoomLevel(
1536 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1537 } else {
1538 zoom_level = zoom_map->GetZoomLevel(GetURL());
1539 }
[email protected]d0b8d092010-10-25 04:05:171540 return zoom_level;
1541}
[email protected]b75b8292010-10-01 07:28:251542
[email protected]d0b8d092010-10-25 04:05:171543int TabContents::GetZoomPercent(bool* enable_increment,
1544 bool* enable_decrement) {
1545 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251546 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171547 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251548 *enable_decrement = percent > minimum_zoom_percent_;
1549 *enable_increment = percent < maximum_zoom_percent_;
1550 return percent;
1551}
1552
[email protected]77d8d622010-12-15 10:30:121553void TabContents::ViewSource()
1554{
[email protected]1788e772010-12-15 16:40:501555 if (!delegate_)
1556 return;
1557
1558 NavigationEntry* active_entry = controller().GetActiveEntry();
1559 if (!active_entry)
1560 return;
1561
1562 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121563}
1564
[email protected]96d185d2009-04-24 03:28:541565// Notifies the RenderWidgetHost instance about the fact that the page is
1566// loading, or done loading and calls the base implementation.
1567void TabContents::SetIsLoading(bool is_loading,
1568 LoadNotificationDetails* details) {
1569 if (is_loading == is_loading_)
1570 return;
1571
1572 if (!is_loading) {
1573 load_state_ = net::LOAD_STATE_IDLE;
1574 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561575 upload_size_ = 0;
1576 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541577 }
1578
1579 render_manager_.SetIsLoading(is_loading);
1580
1581 is_loading_ = is_loading;
1582 waiting_for_response_ = is_loading;
1583
[email protected]6ebdc9b2010-09-27 16:55:571584 if (delegate_)
1585 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351586 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541587
1588 NotificationType type = is_loading ? NotificationType::LOAD_START :
1589 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111590 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541591 if (details)
1592 det = Details<LoadNotificationDetails>(details);
1593 NotificationService::current()->Notify(type,
1594 Source<NavigationController>(&controller_),
1595 det);
1596}
1597
[email protected]b6c874582009-05-08 19:38:311598void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291599 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061600 // A page can't spawn popups (or do anything else, either) until its load
1601 // commits, so when we reach here, the popup was spawned by the
1602 // NavigationController's last committed entry, not the active entry. For
1603 // example, if a page opens a popup in an onunload() handler, then the active
1604 // entry is the page to be loaded as we navigate away from the unloading
1605 // page. For this reason, we can't use GetURL() to get the opener URL,
1606 // because it returns the active entry.
1607 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1608 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1609
1610 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491611 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091612 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491613 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1614 } else {
[email protected]c65e2f152010-10-14 15:30:401615 if (!blocked_contents_)
1616 blocked_contents_ = new BlockedContentContainer(this);
1617 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1618 true);
[email protected]55126132010-08-19 14:53:281619 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1620 std::string());
[email protected]8cc8d492010-02-02 10:40:491621 }
[email protected]b9681312008-11-07 00:08:261622}
[email protected]616ed5a2008-11-21 22:27:241623
[email protected]616ed5a2008-11-21 22:27:241624void TabContents::ExpireInfoBars(
1625 const NavigationController::LoadCommittedDetails& details) {
1626 // Only hide InfoBars when the user has done something that makes the main
1627 // frame load. We don't want various automatic or subframe navigations making
1628 // it disappear.
1629 if (!details.is_user_initiated_main_frame_load())
1630 return;
1631
[email protected]f86a07022008-11-25 01:06:051632 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241633 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081634 if (!delegate) {
1635 // If you hit this NOTREACHED, please comment in bug
1636 // http://crbug.com/50428 how you got there.
1637 NOTREACHED();
1638 continue;
1639 }
1640
[email protected]f86a07022008-11-25 01:06:051641 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241642 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241643 }
1644}
[email protected]fdd61c62009-04-22 19:22:571645
[email protected]96d185d2009-04-24 03:28:541646DOMUI* TabContents::GetDOMUIForCurrentState() {
1647 // When there is a pending navigation entry, we want to use the pending DOMUI
1648 // that goes along with it to control the basic flags. For example, we want to
1649 // show the pending URL in the URL bar, so we want the display_url flag to
1650 // be from the pending entry.
1651 //
1652 // The confusion comes because there are multiple possibilities for the
1653 // initial load in a tab as a side effect of the way the RenderViewHostManager
1654 // works.
1655 //
1656 // - For the very first tab the load looks "normal". The new tab DOM UI is
1657 // the pending one, and we want it to apply here.
1658 //
1659 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1660 // get switched to the one previously associated with the new tab pages.
1661 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1662 // have a committed DOM UI in this case.
1663 //
1664 // This condition handles all of these cases:
1665 //
1666 // - First load in first tab: no committed nav entry + pending nav entry +
1667 // pending dom ui:
1668 // -> Use pending DOM UI if any.
1669 //
1670 // - First load in second tab: no committed nav entry + pending nav entry +
1671 // no pending DOM UI:
1672 // -> Use the committed DOM UI if any.
1673 //
1674 // - Second navigation in any tab: committed nav entry + pending nav entry:
1675 // -> Use pending DOM UI if any.
1676 //
1677 // - Normal state with no load: committed nav entry + no pending nav entry:
1678 // -> Use committed DOM UI.
1679 if (controller_.pending_entry() &&
1680 (controller_.GetLastCommittedEntry() ||
1681 render_manager_.pending_dom_ui()))
1682 return render_manager_.pending_dom_ui();
1683 return render_manager_.dom_ui();
1684}
[email protected]420ae012009-04-24 05:16:321685
1686void TabContents::DidNavigateMainFramePostCommit(
1687 const NavigationController::LoadCommittedDetails& details,
1688 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441689 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1690 // If this is a window.open navigation, use the same DOMUI as the renderer
1691 // that opened the window, as long as both renderers have the same
1692 // privileges.
[email protected]583d45c12010-08-31 02:48:121693 if (opener_dom_ui_type_ ==
1694 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441695 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1696 // dom_ui might be NULL if the URL refers to a non-existent extension.
1697 if (dom_ui) {
1698 render_manager_.SetDOMUIPostCommit(dom_ui);
1699 dom_ui->RenderViewCreated(render_view_host());
1700 }
1701 }
1702 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1703 }
1704
[email protected]420ae012009-04-24 05:16:321705 if (details.is_user_initiated_main_frame_load()) {
1706 // Clear the status bubble. This is a workaround for a bug where WebKit
1707 // doesn't let us know that the cursor left an element during a
1708 // transition (this is also why the mouse cursor remains as a hand after
1709 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1710 // clear the bubble when a user navigates to a named anchor in the same
1711 // page.
1712 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321713 }
1714
1715 // The keyword generator uses the navigation entries, so must be called after
1716 // the commit.
1717 GenerateKeywordIfNecessary(params);
1718
1719 // Allow the new page to set the title again.
1720 received_page_title_ = false;
1721
1722 // Get the favicon, either from history or request it from the net.
1723 fav_icon_helper_.FetchFavIcon(details.entry->url());
1724
[email protected]0de80162010-02-03 04:52:351725 // Clear all page actions, blocked content notifications and browser actions
1726 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141727 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001728 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081729 if (service) {
1730 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571731 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081732 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521733 if (browser_action) {
1734 browser_action->ClearAllValuesForTab(controller().session_id().id());
1735 NotificationService::current()->Notify(
1736 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571737 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521738 NotificationService::NoDetails());
1739 }
[email protected]92c6f9b92009-10-24 04:35:081740
[email protected]5d246db22009-10-27 06:17:571741 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521742 service->extensions()->at(i)->page_action();
1743 if (page_action) {
1744 page_action->ClearAllValuesForTab(controller().session_id().id());
1745 PageActionStateChanged();
1746 }
[email protected]92c6f9b92009-10-24 04:35:081747 }
[email protected]aece2c7f2009-08-27 20:43:171748 }
[email protected]0de80162010-02-03 04:52:351749
1750 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401751 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341752 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401753 blocked_contents_->Destroy();
1754 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351755 }
1756
1757 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411758 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551759 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471760
1761 // Once the main frame is navigated, we're no longer considered to have
1762 // displayed insecure content.
1763 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171764 }
[email protected]ce5c4502009-05-06 16:46:111765
[email protected]8cc8d492010-02-02 10:40:491766 // Close constrained windows if necessary.
1767 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1768 details.previous_url, details.entry->url()))
1769 CloseConstrainedWindows();
1770
[email protected]420ae012009-04-24 05:16:321771 // Update the starred state.
1772 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531773
[email protected]3c9e1872010-11-18 16:17:491774 // Notify observers about navigation.
1775 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1776 DidNavigateMainFramePostCommit(details, params));
1777
[email protected]c07c9752010-03-12 05:57:531778 // Clear the cache of forms in AutoFill.
1779 if (autofill_manager_.get())
1780 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321781}
1782
1783void TabContents::DidNavigateAnyFramePostCommit(
1784 RenderViewHost* render_view_host,
1785 const NavigationController::LoadCommittedDetails& details,
1786 const ViewHostMsg_FrameNavigate_Params& params) {
1787 // If we navigate, start showing messages again. This does nothing to prevent
1788 // a malicious script from spamming messages, since the script could just
1789 // reload the page to stop blocking.
1790 suppress_javascript_messages_ = false;
1791
[email protected]3c9e1872010-11-18 16:17:491792 // Notify observers about navigation.
1793 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1794 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551795
1796 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581797 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321798}
1799
[email protected]8cc8d492010-02-02 10:40:491800void TabContents::CloseConstrainedWindows() {
1801 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321802 // We use indices instead of iterators in case CloseWindow does something
1803 // that may invalidate an iterator.
1804 int size = static_cast<int>(child_windows_.size());
1805 for (int i = size - 1; i >= 0; --i) {
1806 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441807 if (window) {
[email protected]420ae012009-04-24 05:16:321808 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441809 BlockTabContent(false);
1810 }
[email protected]420ae012009-04-24 05:16:321811 }
1812}
1813
1814void TabContents::UpdateStarredStateForCurrentURL() {
1815 BookmarkModel* model = profile()->GetBookmarkModel();
1816 const bool old_state = is_starred_;
1817 is_starred_ = (model && model->IsBookmarked(GetURL()));
1818
1819 if (is_starred_ != old_state && delegate())
1820 delegate()->URLStarredChanged(this, is_starred_);
1821}
1822
1823void TabContents::UpdateAlternateErrorPageURL() {
1824 GURL url = GetAlternateErrorPageURL();
1825 render_view_host()->SetAlternateErrorPageURL(url);
1826}
1827
1828void TabContents::UpdateWebPreferences() {
1829 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1830}
1831
[email protected]d0b8d092010-10-25 04:05:171832void TabContents::UpdateZoomLevel() {
1833 render_view_host()->SetZoomLevel(GetZoomLevel());
1834}
1835
[email protected]420ae012009-04-24 05:16:321836void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1837 RenderViewHost* rvh) {
1838 // If we are creating a RVH for a restored controller, then we might
1839 // have more page IDs than the SiteInstance's current max page ID. We must
1840 // make sure that the max page ID is larger than any restored page ID.
1841 // Note that it is ok for conflicting page IDs to exist in another tab
1842 // (i.e., NavigationController), but if any page ID is larger than the max,
1843 // the back/forward list will get confused.
1844 int max_restored_page_id = controller_.max_restored_page_id();
1845 if (max_restored_page_id > 0) {
1846 int curr_max_page_id = site_instance->max_page_id();
1847 if (max_restored_page_id > curr_max_page_id) {
1848 // Need to update the site instance immediately.
1849 site_instance->UpdateMaxPageID(max_restored_page_id);
1850
1851 // Also tell the renderer to update its internal representation. We
1852 // need to reserve enough IDs to make all restored page IDs less than
1853 // the max.
1854 if (curr_max_page_id < 0)
1855 curr_max_page_id = 0;
1856 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1857 }
1858 }
1859}
1860
[email protected]ec0b6c42010-08-26 03:16:581861scoped_refptr<history::HistoryAddPageArgs>
1862TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541863 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471864 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321865 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581866 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1867 new history::HistoryAddPageArgs(
1868 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1869 params.redirects, params.transition, history::SOURCE_BROWSED,
1870 details.did_replace_entry));
1871 if (PageTransition::IsMainFrame(params.transition) &&
1872 virtual_url != params.url) {
1873 // Hack on the "virtual" URL so that it will appear in history. For some
1874 // types of URLs, we will display a magic URL that is different from where
1875 // the page is actually navigated. We want the user to see in history what
1876 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1877 // only applies to the main frame, as the virtual URL doesn't apply to
1878 // sub-frames.
1879 add_page_args->url = virtual_url;
1880 if (!add_page_args->redirects.empty())
1881 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321882 }
[email protected]ec0b6c42010-08-26 03:16:581883 return add_page_args;
[email protected]420ae012009-04-24 05:16:321884}
1885
1886bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1887 const std::wstring& title) {
1888 // For file URLs without a title, use the pathname instead. In the case of a
1889 // synthesized title, we don't want the update to count toward the "one set
1890 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251891 string16 final_title;
[email protected]420ae012009-04-24 05:16:321892 bool explicit_set;
1893 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251894 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321895 explicit_set = false; // Don't count synthetic titles toward the set limit.
1896 } else {
[email protected]e53668962010-06-23 15:35:251897 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321898 explicit_set = true;
1899 }
1900
[email protected]e53668962010-06-23 15:35:251901 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321902 return false; // Nothing changed, don't bother.
1903
[email protected]e53668962010-06-23 15:35:251904 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321905
[email protected]ec0b6c42010-08-26 03:16:581906 if (!received_page_title_) {
1907 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321908 received_page_title_ = explicit_set;
1909 }
1910
1911 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251912 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321913
[email protected]cbc0e1b2010-04-12 18:33:041914 NotificationService::current()->Notify(
1915 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1916 Source<TabContents>(this),
1917 NotificationService::NoDetails());
1918
[email protected]420ae012009-04-24 05:16:321919 return true;
1920}
1921
1922void TabContents::NotifySwapped() {
1923 // After sending out a swap notification, we need to send a disconnect
1924 // notification so that clients that pick up a pointer to |this| can NULL the
1925 // pointer. See Bug 1230284.
1926 notify_disconnection_ = true;
1927 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341928 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221929 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321930 NotificationService::NoDetails());
1931}
1932
1933void TabContents::NotifyConnected() {
1934 notify_disconnection_ = true;
1935 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341936 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221937 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321938 NotificationService::NoDetails());
1939}
1940
1941void TabContents::NotifyDisconnected() {
1942 if (!notify_disconnection_)
1943 return;
1944
1945 notify_disconnection_ = false;
1946 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341947 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221948 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321949 NotificationService::NoDetails());
1950}
1951
1952void TabContents::GenerateKeywordIfNecessary(
1953 const ViewHostMsg_FrameNavigate_Params& params) {
1954 if (!params.searchable_form_url.is_valid())
1955 return;
1956
1957 if (profile()->IsOffTheRecord())
1958 return;
1959
1960 int last_index = controller_.last_committed_entry_index();
1961 // When there was no previous page, the last index will be 0. This is
1962 // normally due to a form submit that opened in a new tab.
1963 // TODO(brettw) bug 916126: we should support keywords when form submits
1964 // happen in new tabs.
1965 if (last_index <= 0)
1966 return;
1967 const NavigationEntry* previous_entry =
1968 controller_.GetEntryAtIndex(last_index - 1);
1969 if (IsFormSubmit(previous_entry)) {
1970 // Only generate a keyword if the previous page wasn't itself a form
1971 // submit.
1972 return;
1973 }
1974
1975 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1976 previous_entry->user_typed_url() : previous_entry->url();
1977 std::wstring keyword =
1978 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1979 if (keyword.empty())
1980 return;
1981
1982 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1983 if (!url_model)
1984 return;
1985
1986 if (!url_model->loaded()) {
1987 url_model->Load();
1988 return;
1989 }
1990
1991 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191992 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321993 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1994 return;
1995
1996 if (current_url) {
1997 if (current_url->originating_url().is_valid()) {
1998 // The existing keyword was generated from an OpenSearch description
1999 // document, don't regenerate.
2000 return;
2001 }
2002 url_model->Remove(current_url);
2003 }
2004 TemplateURL* new_url = new TemplateURL();
2005 new_url->set_keyword(keyword);
2006 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:192007 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:322008 new_url->add_input_encoding(params.searchable_form_encoding);
2009 DCHECK(controller_.GetLastCommittedEntry());
2010 const GURL& favicon_url =
2011 controller_.GetLastCommittedEntry()->favicon().url();
2012 if (favicon_url.is_valid()) {
2013 new_url->SetFavIconURL(favicon_url);
2014 } else {
2015 // The favicon url isn't valid. This means there really isn't a favicon,
2016 // or the favicon url wasn't obtained before the load started. This assumes
2017 // the later.
2018 // TODO(sky): Need a way to set the favicon that doesn't involve generating
2019 // its url.
2020 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
2021 }
2022 new_url->set_safe_for_autoreplace(true);
2023 url_model->Add(new_url);
2024}
2025
[email protected]bf5c2ff392009-07-08 16:24:332026void TabContents::OnUserGesture() {
2027 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:012028 DownloadRequestLimiter* limiter =
2029 g_browser_process->download_request_limiter();
2030 if (limiter)
2031 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:262032 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:332033}
2034
2035void TabContents::OnFindReply(int request_id,
2036 int number_of_matches,
2037 const gfx::Rect& selection_rect,
2038 int active_match_ordinal,
2039 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:422040 // Ignore responses for requests that have been aborted.
2041 if (find_op_aborted_)
2042 return;
2043
[email protected]bf5c2ff392009-07-08 16:24:332044 // Ignore responses for requests other than the one we have most recently
2045 // issued. That way we won't act on stale results when the user has
2046 // already typed in another query.
2047 if (request_id != current_find_request_id_)
2048 return;
2049
2050 if (number_of_matches == -1)
2051 number_of_matches = last_search_result_.number_of_matches();
2052 if (active_match_ordinal == -1)
2053 active_match_ordinal = last_search_result_.active_match_ordinal();
2054
2055 gfx::Rect selection = selection_rect;
2056 if (selection.IsEmpty())
2057 selection = last_search_result_.selection_rect();
2058
2059 // Notify the UI, automation and any other observers that a find result was
2060 // found.
2061 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
2062 selection, active_match_ordinal,
2063 final_update);
2064 NotificationService::current()->Notify(
2065 NotificationType::FIND_RESULT_AVAILABLE,
2066 Source<TabContents>(this),
2067 Details<FindNotificationDetails>(&last_search_result_));
2068}
2069
2070void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542071 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2072 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2073 if (!entry)
2074 return;
2075 // Note that we don't call NavigationController::GotToOffset() as we don't
2076 // want to create a pending navigation entry (it might end up lingering
2077 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522078 entry->set_transition_type(entry->transition_type() |
2079 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542080 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2081 }
[email protected]bf5c2ff392009-07-08 16:24:332082}
2083
[email protected]bf5c2ff392009-07-08 16:24:332084void TabContents::OnMissingPluginStatus(int status) {
2085#if defined(OS_WIN)
2086// TODO(PORT): pull in when plug-ins work
2087 GetPluginInstaller()->OnMissingPluginStatus(status);
2088#endif
2089}
2090
2091void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332092 DCHECK(!plugin_path.value().empty());
2093
2094 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002095 WebPluginInfo plugin_info;
2096 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2097 plugin_path, &plugin_info) &&
2098 !plugin_info.name.empty()) {
2099 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372100#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002101 // Many plugins on the Mac have .plugin in the actual name, which looks
2102 // terrible, so look for that and strip it off if present.
2103 const std::wstring plugin_extension(L".plugin");
2104 if (EndsWith(plugin_name, plugin_extension, true))
2105 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372106#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332107 }
[email protected]2ae8a922010-06-28 20:27:532108 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2109 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332110 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582111 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2112 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532113 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332114}
2115
2116void TabContents::OnCrashedWorker() {
2117 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582118 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422119 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332120}
2121
[email protected]38789d82010-11-17 06:03:442122void TabContents::OnDidGetApplicationInfo(int32 page_id,
2123 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512124 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332125
[email protected]ed5431872009-11-17 08:39:512126 if (delegate())
2127 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332128}
2129
[email protected]bb461532010-11-26 21:50:232130void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2131 if (delegate())
2132 delegate()->OnInstallApplication(this, info);
2133}
2134
[email protected]851b1eb2010-08-09 13:32:292135void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2136 const GURL& update_url) {
2137 new DisabledPluginInfoBar(this, name, update_url);
2138}
2139
[email protected]a2cf65eb2010-01-18 08:20:382140void TabContents::OnPageContents(const GURL& url,
2141 int renderer_process_id,
2142 int32 page_id,
[email protected]e5106202010-06-11 21:12:362143 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102144 const std::string& language,
2145 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382146 // Don't index any https pages. People generally don't want their bank
2147 // accounts, etc. indexed on their computer, especially since some of these
2148 // things are not marked cachable.
2149 // TODO(brettw) we may want to consider more elaborate heuristics such as
2150 // the cachability of the page. We may also want to consider subframes (this
2151 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272152 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2153 // content indexing for chromeos in some future releases.
2154#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382155 if (!url.SchemeIsSecure()) {
2156 Profile* p = profile();
2157 if (p && !p->IsOffTheRecord()) {
2158 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2159 if (hs)
2160 hs->SetPageContents(url, contents);
2161 }
2162 }
[email protected]ccd40a52010-05-11 16:15:272163#endif
[email protected]a8a81292010-01-21 00:32:452164
[email protected]1c57b7b2010-07-12 17:38:102165 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452166
2167 std::string lang = language;
2168 NotificationService::current()->Notify(
2169 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152170 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452171 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382172}
2173
[email protected]7e0831b2010-02-01 08:45:152174void TabContents::OnPageTranslated(int32 page_id,
2175 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162176 const std::string& translated_lang,
2177 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552178 language_state_.set_current_language(translated_lang);
2179 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162180 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152181 NotificationService::current()->Notify(
2182 NotificationType::PAGE_TRANSLATED,
2183 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162184 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152185}
2186
[email protected]ce833282010-11-04 15:48:392187void TabContents::OnSetSuggestions(
2188 int32 page_id,
2189 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262190 if (delegate())
[email protected]ce833282010-11-04 15:48:392191 delegate()->OnSetSuggestions(page_id, suggestions);
2192}
2193
2194void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2195 if (delegate())
2196 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262197}
2198
[email protected]bf5c2ff392009-07-08 16:24:332199void TabContents::DidStartProvisionalLoadForFrame(
2200 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182201 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332202 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272203 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332204 const GURL& url) {
2205 ProvisionalLoadDetails details(is_main_frame,
2206 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412207 url, std::string(), false,
2208 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332209 NotificationService::current()->Notify(
2210 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2211 Source<NavigationController>(&controller_),
2212 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142213 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272214 // If we're displaying a network error page do not reset the content
2215 // settings delegate's cookies so the user has a chance to modify cookie
2216 // settings.
2217 if (!is_error_page)
2218 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142219 content_settings_delegate_->ClearGeolocationContentSettings();
2220 }
[email protected]bf5c2ff392009-07-08 16:24:332221}
2222
2223void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202224 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332225 NotificationService::current()->Notify(
2226 NotificationType::RESOURCE_RESPONSE_STARTED,
2227 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202228 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332229}
2230
[email protected]3dbb80b2010-02-09 22:41:202231void TabContents::DidRedirectResource(
2232 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332233 NotificationService::current()->Notify(
2234 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2235 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202236 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332237}
2238
2239void TabContents::DidLoadResourceFromMemoryCache(
2240 const GURL& url,
2241 const std::string& frame_origin,
2242 const std::string& main_frame_origin,
2243 const std::string& security_info) {
2244 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442245 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332246 SSLManager::DeserializeSecurityInfo(security_info,
2247 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042248 &security_bits,
2249 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332250 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162251 GetRenderProcessHost()->id(), cert_id,
2252 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332253
2254 NotificationService::current()->Notify(
2255 NotificationType::LOAD_FROM_MEMORY_CACHE,
2256 Source<NavigationController>(&controller_),
2257 Details<LoadFromMemoryCacheDetails>(&details));
2258}
2259
[email protected]e3d60e5d2009-09-25 21:08:292260void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472261 displayed_insecure_content_ = true;
2262 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292263}
2264
2265void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592266 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292267}
2268
[email protected]bf5c2ff392009-07-08 16:24:332269void TabContents::DidFailProvisionalLoadWithError(
2270 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182271 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332272 bool is_main_frame,
2273 int error_code,
2274 const GURL& url,
2275 bool showing_repost_interstitial) {
2276 if (net::ERR_ABORTED == error_code) {
2277 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2278 // This means that the interstitial won't be torn down properly, which is
2279 // bad. But if we have an interstitial, go back to another tab type, and
2280 // then load the same interstitial again, we could end up getting the first
2281 // interstitial's "failed" message (as a result of the cancel) when we're on
2282 // the second one.
2283 //
2284 // We can't tell this apart, so we think we're tearing down the current page
2285 // which will cause a crash later one. There is also some code in
2286 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2287 // out because of this problem.
2288 //
2289 // http://code.google.com/p/chromium/issues/detail?id=2855
2290 // Because this will not tear down the interstitial properly, if "back" is
2291 // back to another tab type, the interstitial will still be somewhat alive
2292 // in the previous tab type. If you navigate somewhere that activates the
2293 // tab with the interstitial again, you'll see a flash before the new load
2294 // commits of the interstitial page.
2295 if (showing_interstitial_page()) {
2296 LOG(WARNING) << "Discarding message during interstitial.";
2297 return;
2298 }
2299
2300 // This will discard our pending entry if we cancelled the load (e.g., if we
2301 // decided to download the file instead of load it). Only discard the
2302 // pending entry if the URLs match, otherwise the user initiated a navigate
2303 // before the page loaded so that the discard would discard the wrong entry.
2304 NavigationEntry* pending_entry = controller_.pending_entry();
2305 if (pending_entry && pending_entry->url() == url) {
2306 controller_.DiscardNonCommittedEntries();
2307 // Update the URL display.
2308 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2309 }
2310
2311 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2312 }
2313
2314 // Send out a notification that we failed a provisional load with an error.
2315 ProvisionalLoadDetails details(is_main_frame,
2316 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412317 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332318 details.set_error_code(error_code);
2319
2320 NotificationService::current()->Notify(
2321 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2322 Source<NavigationController>(&controller_),
2323 Details<ProvisionalLoadDetails>(&details));
2324}
2325
[email protected]4b8e2b02010-11-30 09:15:182326void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332327 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082328 NotificationService::current()->Notify(
2329 NotificationType::FRAME_DOM_CONTENT_LOADED,
2330 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182331 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332332}
2333
[email protected]4b8e2b02010-11-30 09:15:182334void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172335 NotificationService::current()->Notify(
2336 NotificationType::FRAME_DID_FINISH_LOAD,
2337 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182338 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172339}
2340
[email protected]dcd5b332010-08-11 08:55:182341void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562342 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242343 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562344}
2345
[email protected]8d3347f2009-07-09 22:00:212346RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322347 return view_.get();
2348}
2349
[email protected]8d3347f2009-07-09 22:00:212350RenderViewHostDelegate::RendererManagement*
2351TabContents::GetRendererManagementDelegate() {
2352 return &render_manager_;
2353}
2354
[email protected]bf5c2ff392009-07-08 16:24:332355RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212356 TabContents::GetBrowserIntegrationDelegate() {
2357 return this;
[email protected]bf5c2ff392009-07-08 16:24:332358}
2359
[email protected]8d3347f2009-07-09 22:00:212360RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2361 return this;
[email protected]bf5c2ff392009-07-08 16:24:332362}
2363
[email protected]46ba9082010-06-22 10:00:582364RenderViewHostDelegate::ContentSettings*
2365TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552366 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582367}
2368
[email protected]8d3347f2009-07-09 22:00:212369RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322370 return save_package_.get(); // May be NULL, but we can return NULL.
2371}
2372
[email protected]8d3347f2009-07-09 22:00:212373RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092374 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212375}
2376
2377RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2378 return &fav_icon_helper_;
2379}
2380
[email protected]e8dbd674b2010-03-11 18:34:402381RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452382 if (autocomplete_history_manager_.get() == NULL)
2383 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2384 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332385}
2386
[email protected]21674df2009-10-28 19:51:212387RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342388 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212389}
2390
[email protected]1f18184a2010-07-21 19:34:492391RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2392 return GetSSLHelper();
2393}
2394
[email protected]b5977a0c2010-08-24 19:46:262395RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2396 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492397 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262398 return file_select_helper_.get();
2399}
2400
[email protected]fd571bb2010-03-19 01:23:542401AutomationResourceRoutingDelegate*
2402TabContents::GetAutomationResourceRoutingDelegate() {
2403 return delegate();
2404}
2405
[email protected]ced90ae12010-02-20 02:06:162406RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2407 return bookmark_drag_;
2408}
2409
2410void TabContents::SetBookmarkDragDelegate(
2411 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2412 bookmark_drag_ = bookmark_drag;
2413}
2414
[email protected]9fb83e82010-07-02 18:24:552415TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2416 return content_settings_delegate_.get();
2417}
2418
[email protected]93623c5d2009-12-10 21:40:322419RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462420 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512421}
2422
[email protected]57c6a652009-05-04 07:58:342423TabContents* TabContents::GetAsTabContents() {
2424 return this;
2425}
2426
[email protected]7b291f92009-08-14 05:43:532427ViewType::Type TabContents::GetRenderViewType() const {
2428 return ViewType::TAB_CONTENTS;
2429}
2430
2431int TabContents::GetBrowserWindowID() const {
2432 return controller().window_id().id();
2433}
2434
[email protected]420ae012009-04-24 05:16:322435void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062436 NotificationService::current()->Notify(
2437 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2438 Source<TabContents>(this),
2439 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322440 NavigationEntry* entry = controller_.GetActiveEntry();
2441 if (!entry)
2442 return;
2443
2444 // When we're creating views, we're still doing initial setup, so we always
2445 // use the pending DOM UI rather than any possibly existing committed one.
2446 if (render_manager_.pending_dom_ui()) {
2447 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2448 }
2449
2450 if (entry->IsViewSourceMode()) {
2451 // Put the renderer in view source mode.
2452 render_view_host->Send(
2453 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2454 }
[email protected]0666aef2009-05-13 19:48:082455
2456 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322457}
2458
2459void TabContents::RenderViewReady(RenderViewHost* rvh) {
2460 if (rvh != render_view_host()) {
2461 // Don't notify the world, since this came from a renderer in the
2462 // background.
2463 return;
2464 }
2465
2466 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302467 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232468 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302469
2470 // Restore the focus to the tab (otherwise the focus will be on the top
2471 // window).
[email protected]484ae5912010-09-29 19:16:142472 if (was_crashed && !FocusLocationBarByDefault() &&
2473 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302474 Focus();
[email protected]484ae5912010-09-29 19:16:142475 }
[email protected]420ae012009-04-24 05:16:322476}
2477
[email protected]443b80e2010-12-14 00:42:232478void TabContents::RenderViewGone(RenderViewHost* rvh,
2479 base::TerminationStatus status,
2480 int error_code) {
[email protected]420ae012009-04-24 05:16:322481 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092482 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322483 return;
2484 if (rvh != render_view_host()) {
2485 // The pending page's RenderViewHost is gone.
2486 return;
2487 }
2488
2489 SetIsLoading(false, NULL);
2490 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232491 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322492
[email protected]ff9efc62010-02-18 22:10:542493 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212494 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542495 RemoveInfoBar(GetInfoBarDelegateAt(i));
2496
[email protected]8e537302009-06-10 21:19:582497 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552498 // Only do this if we're not in browser shutdown, so that TabContents
2499 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2500 // visible do not flash a sad tab page.
2501 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2502 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322503
2504 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002505 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322506}
2507
[email protected]2e4633c2009-07-09 16:58:062508void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2509 NotificationService::current()->Notify(
2510 NotificationType::RENDER_VIEW_HOST_DELETED,
2511 Source<TabContents>(this),
2512 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482513 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062514}
2515
[email protected]420ae012009-04-24 05:16:322516void TabContents::DidNavigate(RenderViewHost* rvh,
2517 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372518 int extra_invalidate_flags = 0;
2519
2520 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]33f74972010-12-08 16:40:362521 PrerenderManager* pm = profile()->GetPrerenderManager();
2522 if (pm != NULL) {
2523 if (pm->MaybeUsePreloadedPage(this, params.url)) {
2524 // TODO(tburkard): If the preloaded page has not finished preloading
2525 // yet, we should not do this.
2526 DidStopLoading();
2527 return;
2528 }
2529 }
2530
[email protected]20ede072009-10-06 00:28:352531 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372532
[email protected]420ae012009-04-24 05:16:322533 render_manager_.DidNavigateMainFrame(rvh);
2534
[email protected]20ede072009-10-06 00:28:352535 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372536 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372537 }
2538
[email protected]420ae012009-04-24 05:16:322539 // Update the site of the SiteInstance if it doesn't have one yet.
2540 if (!GetSiteInstance()->has_site())
2541 GetSiteInstance()->SetSite(params.url);
2542
2543 // Need to update MIME type here because it's referred to in
2544 // UpdateNavigationCommands() called by RendererDidNavigate() to
2545 // determine whether or not to enable the encoding menu.
2546 // It's updated only for the main frame. For a subframe,
2547 // RenderView::UpdateURL does not set params.contents_mime_type.
2548 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2549 // TODO(jungshik): Add a test for the encoding menu to avoid
2550 // regressing it again.
2551 if (PageTransition::IsMainFrame(params.transition))
2552 contents_mime_type_ = params.contents_mime_type;
2553
2554 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372555 bool did_navigate = controller_.RendererDidNavigate(
2556 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392557
[email protected]a9c0bfe2010-09-17 08:35:222558 // Send notification about committed provisional loads. This notification is
2559 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2560 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2561 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072562 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2563 // that is not recorded in the navigation history. For the purpose of
2564 // tracking navigation events, we treat this event as a sub frame navigation
2565 // event.
2566 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2567 ProvisionalLoadDetails load_details(
2568 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412569 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222570 load_details.set_transition_type(params.transition);
2571 // Whether or not a page transition was triggered by going backward or
2572 // forward in the history is only stored in the navigation controller's
2573 // entry list.
2574 if (did_navigate &&
2575 (controller_.GetActiveEntry()->transition_type() &
2576 PageTransition::FORWARD_BACK)) {
2577 load_details.set_transition_type(
2578 params.transition | PageTransition::FORWARD_BACK);
2579 }
2580 NotificationService::current()->Notify(
2581 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2582 Source<NavigationController>(&controller_),
2583 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222584 }
2585
[email protected]3e90d4a2009-07-03 17:38:392586 // Update history. Note that this needs to happen after the entry is complete,
2587 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582588 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392589 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582590 // URLs, we use a data: URL as the real value. We actually want to save the
2591 // about: URL to the history db and keep the data: URL hidden. This is what
2592 // the TabContents' URL getter does.
2593 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2594 CreateHistoryAddPageArgs(GetURL(), details, params));
2595 if (!delegate() ||
2596 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2597 details.type)) {
2598 UpdateHistoryForNavigation(add_page_args);
2599 }
[email protected]3e90d4a2009-07-03 17:38:392600 }
2601
[email protected]76543b92009-08-31 17:27:452602 if (!did_navigate)
2603 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322604
2605 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2606 // for the appropriate notification (best) or you can add it to
2607 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2608 // necessary, please).
2609
2610 // Run post-commit tasks.
2611 if (details.is_main_frame)
2612 DidNavigateMainFramePostCommit(details, params);
2613 DidNavigateAnyFramePostCommit(rvh, details, params);
2614}
2615
2616void TabContents::UpdateState(RenderViewHost* rvh,
2617 int32 page_id,
2618 const std::string& state) {
2619 DCHECK(rvh == render_view_host());
2620
2621 // We must be prepared to handle state updates for any page, these occur
2622 // when the user is scrolling and entering form data, as well as when we're
2623 // leaving a page, in which case our state may have already been moved to
2624 // the next page. The navigation controller will look up the appropriate
2625 // NavigationEntry and update it when it is notified via the delegate.
2626
2627 int entry_index = controller_.GetEntryIndexWithPageID(
2628 GetSiteInstance(), page_id);
2629 if (entry_index < 0)
2630 return;
2631 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2632
2633 if (state == entry->content_state())
2634 return; // Nothing to update.
2635 entry->set_content_state(state);
2636 controller_.NotifyEntryChanged(entry, entry_index);
2637}
2638
2639void TabContents::UpdateTitle(RenderViewHost* rvh,
2640 int32 page_id, const std::wstring& title) {
2641 // If we have a title, that's a pretty good indication that we've started
2642 // getting useful data.
2643 SetNotWaitingForResponse();
2644
2645 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482646 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582647 page_id);
[email protected]420ae012009-04-24 05:16:322648 if (!entry || !UpdateTitleForEntry(entry, title))
2649 return;
2650
2651 // Broadcast notifications when the UI should be updated.
2652 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032653 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322654}
2655
[email protected]420ae012009-04-24 05:16:322656void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402657 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322658 set_encoding(encoding);
2659}
2660
2661void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2662 if (delegate())
2663 delegate()->UpdateTargetURL(this, url);
2664}
2665
2666void TabContents::UpdateThumbnail(const GURL& url,
2667 const SkBitmap& bitmap,
2668 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442669 if (profile()->IsOffTheRecord())
2670 return;
2671
[email protected]420ae012009-04-24 05:16:322672 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492673 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442674 history::TopSites* ts = profile()->GetTopSites();
2675 if (ts)
2676 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282677 } else {
[email protected]e6baed562010-11-02 22:33:442678 HistoryService* hs =
2679 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2680 if (hs)
[email protected]449478302009-06-09 20:04:282681 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322682 }
2683}
2684
[email protected]c4e98902010-06-01 10:20:142685void TabContents::UpdateInspectorSetting(const std::string& key,
2686 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052687 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082688}
2689
[email protected]45aafc92010-06-07 14:18:532690void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052691 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532692}
2693
[email protected]420ae012009-04-24 05:16:322694void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292695 // The UI may be in an event-tracking loop, such as between the
2696 // mouse-down and mouse-up in text selection or a button click.
2697 // Defer the close until after tracking is complete, so that we
2698 // don't free objects out from under the UI.
2699 // TODO(shess): This could probably be integrated with the
2700 // IsDoingDrag() test below. Punting for now because I need more
2701 // research to understand how this impacts platforms other than Mac.
2702 // TODO(shess): This could get more fine-grained. For instance,
2703 // closing a tab in another window while selecting text in the
2704 // current window's Omnibox should be just fine.
2705 if (view()->IsEventTracking()) {
2706 view()->CloseTabAfterEventTracking();
2707 return;
2708 }
2709
[email protected]24a4d1062009-07-10 23:10:422710 // If we close the tab while we're in the middle of a drag, we'll crash.
2711 // Instead, cancel the drag and close it as soon as the drag ends.
2712 if (view()->IsDoingDrag()) {
2713 view()->CancelDragAndCloseTab();
2714 return;
2715 }
2716
[email protected]420ae012009-04-24 05:16:322717 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2718 if (delegate() && rvh == render_view_host())
2719 delegate()->CloseContents(this);
2720}
2721
2722void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2723 if (delegate() && delegate()->IsPopup(this))
2724 delegate()->MoveContents(this, new_bounds);
2725}
2726
[email protected]7ab1e7d62009-10-14 23:32:012727void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322728 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492729
[email protected]de4761b2010-12-07 21:05:212730 if (delegate()) {
2731 bool is_print_preview_tab =
2732 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2733 if (content_restrictions_ || is_print_preview_tab) {
2734 content_restrictions_= is_print_preview_tab ?
2735 CONTENT_RESTRICTION_PRINT : 0;
2736 delegate()->ContentRestrictionsChanged(this);
2737 }
[email protected]9e823662010-10-13 23:36:002738 }
[email protected]3c9e1872010-11-18 16:17:492739
2740 // Notify observers about navigation.
2741 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2742 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322743}
2744
[email protected]7ab1e7d62009-10-14 23:32:012745void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322746 scoped_ptr<LoadNotificationDetails> details;
2747
2748 NavigationEntry* entry = controller_.GetActiveEntry();
2749 // An entry may not exist for a stop when loading an initial blank page or
2750 // if an iframe injected by script into a blank page finishes loading.
2751 if (entry) {
[email protected]420ae012009-04-24 05:16:322752 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2753
2754 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542755 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322756 entry->transition_type(),
2757 elapsed,
2758 &controller_,
2759 controller_.GetCurrentEntryIndex()));
2760 }
2761
[email protected]420ae012009-04-24 05:16:322762 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492763
2764 // Notify observers about navigation.
2765 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2766 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322767}
2768
[email protected]25497492010-09-11 15:15:082769void TabContents::DocumentOnLoadCompletedInMainFrame(
2770 RenderViewHost* render_view_host,
2771 int32 page_id) {
2772 NotificationService::current()->Notify(
2773 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2774 Source<TabContents>(this),
2775 Details<int>(&page_id));
2776}
2777
[email protected]420ae012009-04-24 05:16:322778void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2779 const GURL& source_url,
2780 const GURL& target_url) {
2781 NavigationEntry* entry;
2782 if (page_id == -1)
2783 entry = controller_.pending_entry();
2784 else
2785 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2786 if (!entry || entry->url() != source_url)
2787 return;
2788 entry->set_url(target_url);
2789}
2790
[email protected]420ae012009-04-24 05:16:322791void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2792 WindowOpenDisposition disposition) {
2793 if (render_manager_.dom_ui()) {
2794 // When we're a DOM UI, it will provide a page transition type for us (this
2795 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2796 // generated suggestions).
2797 //
2798 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162799 // want web sites to see a referrer of "chrome://blah" (and some
2800 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322801 // send to the site), so we send no referrer.
2802 OpenURL(url, GURL(), disposition,
2803 render_manager_.dom_ui()->link_transition_type());
2804 } else {
2805 OpenURL(url, referrer, disposition, PageTransition::LINK);
2806 }
2807}
2808
[email protected]1ee614862009-07-06 20:29:182809void TabContents::DomOperationResponse(const std::string& json_string,
2810 int automation_id) {
2811}
2812
[email protected]8b8e7c92010-08-19 18:05:562813void TabContents::ProcessDOMUIMessage(
2814 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322815 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442816 // This can happen if someone uses window.open() to open an extension URL
2817 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562818 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322819 return;
2820 }
[email protected]8b8e7c92010-08-19 18:05:562821 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322822}
2823
2824void TabContents::ProcessExternalHostMessage(const std::string& message,
2825 const std::string& origin,
2826 const std::string& target) {
2827 if (delegate())
2828 delegate()->ForwardMessageToExternalHost(message, origin, target);
2829}
2830
[email protected]420ae012009-04-24 05:16:322831void TabContents::RunJavaScriptMessage(
2832 const std::wstring& message,
2833 const std::wstring& default_prompt,
2834 const GURL& frame_url,
2835 const int flags,
2836 IPC::Message* reply_msg,
2837 bool* did_suppress_message) {
2838 // Suppress javascript messages when requested and when inside a constrained
2839 // popup window (because that activates them and breaks them out of the
2840 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552841 // Also suppress messages when showing an interstitial. The interstitial is
2842 // shown over the previous page, we don't want the hidden page dialogs to
2843 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502844 bool suppress_this_message =
2845 suppress_javascript_messages_ ||
2846 showing_interstitial_page() ||
2847 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322848 if (delegate())
2849 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312850 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322851
2852 *did_suppress_message = suppress_this_message;
2853
2854 if (!suppress_this_message) {
2855 base::TimeDelta time_since_last_message(
2856 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2857 bool show_suppress_checkbox = false;
2858 // Show a checkbox offering to suppress further messages if this message is
2859 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2860 if (time_since_last_message <
2861 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2862 show_suppress_checkbox = true;
2863
[email protected]d6ad7442010-09-05 19:06:522864 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2865 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322866 } else {
2867 // If we are suppressing messages, just reply as is if the user immediately
2868 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542869 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322870 }
2871}
2872
2873void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2874 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292875 if (delegate())
2876 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502877 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2878 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2879 std::wstring());
2880 return;
2881 }
[email protected]7ab1e7d62009-10-14 23:32:012882 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222883 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322884}
2885
2886void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2887 const std::string& json_arguments,
2888 IPC::Message* reply_msg) {
2889 if (delegate()) {
2890 HtmlDialogUIDelegate* dialog_delegate =
2891 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222892 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322893 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2894 }
2895}
2896
[email protected]c4aa86962010-11-24 23:08:042897void TabContents::PasswordFormsFound(
2898 const std::vector<webkit_glue::PasswordForm>& forms) {
2899 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2900 PasswordFormsFound(forms));
2901}
2902
2903void TabContents::PasswordFormsVisible(
2904 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2905 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2906 PasswordFormsVisible(visible_forms));
2907}
2908
[email protected]420ae012009-04-24 05:16:322909// Checks to see if we should generate a keyword based on the OSDD, and if
2910// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202911void TabContents::PageHasOSDD(
2912 RenderViewHost* render_view_host,
2913 int32 page_id,
2914 const GURL& url,
2915 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122916 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322917 DCHECK(url.is_valid());
2918 if (!IsActiveEntry(page_id))
2919 return;
[email protected]420ae012009-04-24 05:16:322920 if (!profile()->GetTemplateURLFetcher())
2921 return;
[email protected]420ae012009-04-24 05:16:322922 if (profile()->IsOffTheRecord())
2923 return;
2924
[email protected]2de7e002010-10-11 22:58:202925 TemplateURLFetcher::ProviderType provider_type;
2926 switch (msg_provider_type.type) {
2927 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2928 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2929 break;
2930
2931 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2932 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2933 break;
2934
2935 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2936 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2937 break;
2938
2939 default:
2940 NOTREACHED();
2941 return;
2942 }
2943
[email protected]420ae012009-04-24 05:16:322944 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2945 DCHECK(entry);
2946
2947 const NavigationEntry* base_entry = entry;
2948 if (IsFormSubmit(base_entry)) {
2949 // If the current page is a form submit, find the last page that was not
2950 // a form submit and use its url to generate the keyword from.
2951 int index = controller_.last_committed_entry_index() - 1;
2952 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2953 index--;
2954 if (index >= 0)
2955 base_entry = controller_.GetEntryAtIndex(index);
2956 else
2957 base_entry = NULL;
2958 }
2959
2960 // We want to use the user typed URL if available since that represents what
2961 // the user typed to get here, and fall back on the regular URL if not.
2962 if (!base_entry)
2963 return;
2964 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2965 base_entry->user_typed_url() : base_entry->url();
2966 if (!keyword_url.is_valid())
2967 return;
[email protected]2de7e002010-10-11 22:58:202968
[email protected]0b5b85c2010-10-11 23:00:122969 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2970 keyword_url,
2971 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532972
[email protected]0b5b85c2010-10-11 23:00:122973 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322974 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322975 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2976 keyword,
2977 url,
2978 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122979 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202980 provider_type);
[email protected]420ae012009-04-24 05:16:322981}
2982
[email protected]420ae012009-04-24 05:16:322983GURL TabContents::GetAlternateErrorPageURL() const {
2984 GURL url;
2985 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2986 if (profile()->IsOffTheRecord())
2987 return url;
2988
2989 PrefService* prefs = profile()->GetPrefs();
2990 DCHECK(prefs);
2991 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152992 url = google_util::AppendGoogleLocaleParam(
2993 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322994 url = google_util::AppendGoogleTLDParam(url);
2995 }
2996 return url;
2997}
2998
2999WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:063000 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:553001 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:083002 WebPreferences web_prefs =
3003 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
3004
[email protected]9beff752010-09-22 19:35:433005 // Force accelerated compositing and 2d canvas off for chrome: and
3006 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:433007 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
3008 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:083009 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:433010 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:083011 }
3012
[email protected]39553442010-09-09 00:01:553013#if defined(OS_MACOSX)
3014 // Disable accelerated compositing if IOSurface's are not supported,
3015 // as is the case in 10.5.
3016 if (!IOSurfaceSupport::Initialize())
3017 web_prefs.accelerated_compositing_enabled = false;
3018#endif
3019
[email protected]447021c2010-09-08 21:29:083020 return web_prefs;
[email protected]420ae012009-04-24 05:16:323021}
3022
[email protected]fa1cf0b82010-01-15 21:49:443023void TabContents::OnIgnoredUIEvent() {
3024 if (constrained_window_count()) {
3025 ConstrainedWindow* window = *constrained_window_begin();
3026 window->FocusConstrainedWindow();
3027 }
3028}
3029
[email protected]420ae012009-04-24 05:16:323030void TabContents::OnJSOutOfMemory() {
3031 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:583032 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
3033 NULL, true));
[email protected]420ae012009-04-24 05:16:323034}
3035
[email protected]420ae012009-04-24 05:16:323036void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
3037 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:343038 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:323039 // delivered to a pending RenderViewHost. We must first run the onunload
3040 // handler of the old RenderViewHost before we can allow it to proceed.
3041 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
3042 new_request_id);
3043}
3044
[email protected]420ae012009-04-24 05:16:323045void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3046 bool is_during_unload) {
3047 if (is_during_unload) {
3048 // Hang occurred while firing the beforeunload/unload handler.
3049 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113050 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323051
3052 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3053 return;
3054
3055 // If the tab hangs in the beforeunload/unload handler there's really
3056 // nothing we can do to recover. Pretend the unload listeners have
3057 // all fired and close the tab. If the hang is in the beforeunload handler
3058 // then the user will not have the option of cancelling the close.
3059 Close(rvh);
3060 return;
3061 }
3062
3063 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003064 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323065}
3066
3067void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003068 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323069}
3070
3071void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563072 net::LoadState load_state,
3073 uint64 upload_position,
3074 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323075 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563076 upload_position_ = upload_position;
3077 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293078 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193079 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293080 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533081 load_state_host_ =
3082 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323083 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3084 SetNotWaitingForResponse();
3085 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503086 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323087}
3088
[email protected]1ee614862009-07-06 20:29:183089bool TabContents::IsExternalTabContainer() const {
3090 if (!delegate())
3091 return false;
3092
3093 return delegate()->IsExternalTabContainer();
3094}
3095
[email protected]1ee614862009-07-06 20:29:183096void TabContents::DidInsertCSS() {
3097 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323098}
3099
[email protected]546ae4e02010-12-08 14:57:193100void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353101 NotificationService::current()->Notify(
3102 NotificationType::FOCUS_CHANGED_IN_PAGE,
3103 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193104 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353105}
3106
[email protected]b75b8292010-10-01 07:28:253107void TabContents::UpdateZoomLimits(int minimum_percent,
3108 int maximum_percent,
3109 bool remember) {
3110 minimum_zoom_percent_ = minimum_percent;
3111 maximum_zoom_percent_ = maximum_percent;
3112 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383113}
3114
[email protected]9e823662010-10-13 23:36:003115void TabContents::UpdateContentRestrictions(int restrictions) {
3116 content_restrictions_ = restrictions;
3117 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323118}
3119
[email protected]420ae012009-04-24 05:16:323120void TabContents::BeforeUnloadFiredFromRenderManager(
3121 bool proceed,
3122 bool* proceed_to_fire_unload) {
3123 if (delegate())
3124 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3125}
3126
[email protected]3a3d47472010-07-15 21:03:543127void TabContents::DidStartLoadingFromRenderManager(
3128 RenderViewHost* render_view_host) {
3129 DidStartLoading();
3130}
3131
3132void TabContents::RenderViewGoneFromRenderManager(
3133 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233134 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3135 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543136}
3137
[email protected]420ae012009-04-24 05:16:323138void TabContents::UpdateRenderViewSizeForRenderManager() {
3139 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263140 gfx::Size size = view_->GetContainerSize();
3141 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3142 // here during container initialization and normal window size will be set
3143 // later. In case of tab duplication this resizing to 0x0 prevents setting
3144 // normal size later so just ignore it.
3145 if (!size.IsEmpty())
3146 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323147}
3148
[email protected]3a3d47472010-07-15 21:03:543149void TabContents::NotifySwappedFromRenderManager() {
3150 NotifySwapped();
3151}
3152
3153NavigationController& TabContents::GetControllerForRenderManager() {
3154 return controller();
3155}
3156
[email protected]420ae012009-04-24 05:16:323157DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223158 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323159}
3160
3161NavigationEntry*
3162TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3163 return controller_.GetLastCommittedEntry();
3164}
3165
3166bool TabContents::CreateRenderViewForRenderManager(
3167 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323168 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523169
[email protected]674b3822010-08-04 04:02:513170 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323171 return false;
3172
3173 // Now that the RenderView has been created, we need to tell it its size.
3174 rwh_view->SetSize(view_->GetContainerSize());
3175
3176 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3177 render_view_host);
3178 return true;
3179}
3180
3181void TabContents::Observe(NotificationType type,
3182 const NotificationSource& source,
3183 const NotificationDetails& details) {
3184 switch (type.value) {
3185 case NotificationType::BOOKMARK_MODEL_LOADED:
3186 // BookmarkModel finished loading, fall through to update starred state.
3187 case NotificationType::URLS_STARRED: {
3188 // Somewhere, a URL has been starred.
3189 // Ignore notifications for profiles other than our current one.
3190 Profile* source_profile = Source<Profile>(source).ptr();
3191 if (!source_profile || !source_profile->IsSameProfile(profile()))
3192 return;
3193
3194 UpdateStarredStateForCurrentURL();
3195 break;
3196 }
3197 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513198 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323199 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3200 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3201 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533202 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3203 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323204 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173205 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3206 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323207 } else {
3208 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3209 }
3210 break;
3211 }
3212 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3213 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3214 break;
3215
3216 case NotificationType::NAV_ENTRY_COMMITTED: {
3217 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3218
3219 NavigationController::LoadCommittedDetails& committed_details =
3220 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3221 ExpireInfoBars(committed_details);
3222 break;
3223 }
3224
[email protected]d3ba77272009-09-03 00:06:093225#if defined(OS_LINUX)
3226 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543227 renderer_preferences_util::UpdateFromSystemSettings(
3228 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093229 render_view_host()->SyncRendererPrefs();
3230 break;
3231 }
3232#endif
3233
[email protected]6c32ce72010-03-08 05:18:063234 case NotificationType::USER_STYLE_SHEET_UPDATED:
3235 UpdateWebPreferences();
3236 break;
3237
[email protected]79580c62010-02-02 02:36:253238 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453239 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253240 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493241 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293242 if (entry)
[email protected]da0c8e92010-02-09 23:25:493243 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293244 if (settings_details.ptr()->update_all() ||
3245 settings_details.ptr()->pattern().Matches(entry_url)) {
3246 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233247 profile()->GetHostContentSettingsMap()->
3248 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253249 }
3250 break;
3251 }
3252
[email protected]e5adff72010-06-14 18:13:063253 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573254 break;
[email protected]a888b29e62010-04-01 13:38:573255
3256 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063257 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573258 break;
[email protected]a888b29e62010-04-01 13:38:573259
[email protected]88152052010-10-01 04:05:183260 case NotificationType::GOOGLE_URL_UPDATED:
3261 UpdateAlternateErrorPageURL();
3262 break;
3263
[email protected]420ae012009-04-24 05:16:323264 default:
3265 NOTREACHED();
3266 }
3267}
[email protected]aacd7cc2009-09-02 14:51:103268
[email protected]9adb9692010-10-29 23:14:023269void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083270 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433271
[email protected]a888b29e62010-04-01 13:38:573272 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083273 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3274 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573275 extension,
[email protected]807871f2010-09-16 01:04:483276 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3277 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573278 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3279 Extension::EXTENSION_ICON_SMALLISH),
3280 ImageLoadingTracker::CACHE);
3281 } else {
[email protected]98aa0b52010-05-06 17:03:083282 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573283 }
3284}
3285
[email protected]9adb9692010-10-29 23:14:023286const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:003287 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:573288 if (!extensions_service)
3289 return NULL;
3290
[email protected]9adb9692010-10-29 23:14:023291 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573292 return extension ?
3293 extension : extensions_service->GetExtensionByWebExtent(url);
3294}
3295
[email protected]a888b29e62010-04-01 13:38:573296void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3297 int index) {
3298 if (image) {
[email protected]98aa0b52010-05-06 17:03:083299 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573300 NotifyNavigationStateChanged(INVALIDATE_TAB);
3301 }
3302}
3303
[email protected]beb440c2009-11-06 04:08:543304gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3305 return view_->GetTopLevelNativeWindow();
3306}
3307
3308void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3309 bool success,
3310 const std::wstring& prompt) {
3311 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3312 if (is_showing_before_unload_dialog_ && !success) {
3313 // If a beforeunload dialog is canceled, we need to stop the throbber from
3314 // spinning, since we forced it to start spinning in Navigate.
3315 DidStopLoading();
3316
3317 tab_close_start_time_ = base::TimeTicks();
3318 }
3319 is_showing_before_unload_dialog_ = false;
3320 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3321}
3322
3323void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3324 set_suppress_javascript_messages(suppress_message_boxes);
3325}
3326
[email protected]3a3d47472010-07-15 21:03:543327TabContents* TabContents::AsTabContents() {
3328 return this;
3329}
3330
3331ExtensionHost* TabContents::AsExtensionHost() {
3332 return NULL;
3333}
3334
[email protected]41fc0322009-09-04 22:23:403335void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103336 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3337}
[email protected]f45d2a72010-03-08 23:28:353338
3339void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3340 app_icon_ = app_icon;
3341 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3342}
[email protected]33f74972010-12-08 16:40:363343
3344void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3345 render_manager_.SwapInRenderViewHost(rvh);
3346}
3347
3348void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3349 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3350 rwh_view->SetSize(view()->GetContainerSize());
3351}