blob: 536948a64da6428058909e1e934f759fd07f8a65 [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 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]8cc8d492010-02-02 10:40:499#include "base/auto_reset.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]6db0def92010-03-02 19:55:4516#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2117#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4018#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3219#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5420#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5521#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1022#include "chrome/browser/character_encoding.h"
[email protected]724159a2010-12-30 01:11:1823#include "chrome/browser/child_process_security_policy.h"
[email protected]5f24f212010-12-02 14:47:4524#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3325#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5426#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1427#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2728#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3229#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5430#include "chrome/browser/dom_ui/dom_ui.h"
[email protected]bcef0dc02009-02-28 00:35:0231#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3232#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0133#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0034#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3135#include "chrome/browser/external_protocol_handler.h"
36#include "chrome/browser/favicon_service.h"
37#include "chrome/browser/file_select_helper.h"
38#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2139#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5840#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4241#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2542#include "chrome/browser/host_zoom_map.h"
[email protected]8897c382009-05-06 17:53:2643#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0744#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3245#include "chrome/browser/load_from_memory_cache_details.h"
46#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4447#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1848#include "chrome/browser/metrics/user_metrics.h"
[email protected]ea0e80892009-08-22 00:36:0549#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1050#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1751#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2452#include "chrome/browser/platform_util.h"
[email protected]f4f50ef2011-01-21 19:01:1953#include "chrome/browser/plugin_installer_infobar_delegate.h"
[email protected]37858e52010-08-26 00:22:0254#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3655#include "chrome/browser/prerender/prerender_manager.h"
[email protected]973407b2011-01-26 23:18:2356#include "chrome/browser/prerender/prerender_plt_recorder.h"
[email protected]dbeebd52010-11-16 20:34:1657#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0958#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3359#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1661#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5462#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3763#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5465#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3266#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1167#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1668#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1269#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1670#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1771#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1772#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5473#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1674#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4375#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1676#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]585b30362011-01-28 02:30:1777#include "chrome/browser/tab_contents/tab_contents_observer.h"
[email protected]1f18184a2010-07-21 19:34:4978#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5779#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]d54169e92011-01-21 09:19:5280#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1681#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3582#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1483#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5884#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2785#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2186#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4987#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5788#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4889#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1490#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0991#include "chrome/common/extensions/url_pattern.h"
92#include "chrome/common/navigation_types.h"
93#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5694#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2995#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3296#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0297#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5498#include "chrome/common/url_constants.h"
[email protected]ef0d04c2010-12-15 23:34:2199#include "gfx/codec/png_codec.h"
[email protected]ea68c06a2010-04-23 17:25:37100#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26101#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32102#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06103#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37104#include "grit/theme_resources.h"
[email protected]d686e812009-06-03 19:10:29105#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32106#include "net/base/registry_controlled_domain.h"
[email protected]8bd0fe62011-01-17 06:44:37107#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c051a1b2011-01-21 23:30:17108#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46109#include "ui/base/resource/resource_bundle.h"
[email protected]d5e311b2010-07-20 17:15:03110#include "webkit/glue/password_form.h"
[email protected]191eb3f72010-12-21 06:27:50111#include "webkit/plugins/npapi/plugin_list.h"
[email protected]3c733bde2010-12-21 19:56:31112#include "webkit/glue/webpreferences.h"
113
114#if defined(OS_MACOSX)
115#include "app/surface/io_surface_support_mac.h"
116#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00117
[email protected]61d68ef12011-01-13 14:02:56118#if defined(OS_CHROMEOS)
119#include "chrome/browser/chromeos/locale_change_guard.h"
120#endif // defined(OS_CHROMEOS)
121
[email protected]420ae012009-04-24 05:16:32122// Cross-Site Navigations
123//
124// If a TabContents is told to navigate to a different web site (as determined
125// by SiteInstance), it will replace its current RenderViewHost with a new
126// RenderViewHost dedicated to the new SiteInstance. This works as follows:
127//
128// - Navigate determines whether the destination is cross-site, and if so,
129// it creates a pending_render_view_host_ and moves into the PENDING
130// RendererState.
131// - The pending RVH is "suspended," so that no navigation messages are sent to
132// its renderer until the onbeforeunload JavaScript handler has a chance to
133// run in the current RVH.
134// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
135// that it has a pending cross-site request. ResourceDispatcherHost will
136// check for this when the response arrives.
137// - The current RVH runs its onbeforeunload handler. If it returns false, we
138// cancel all the pending logic and go back to NORMAL. Otherwise we allow
139// the pending RVH to send the navigation request to its renderer.
140// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
141// checks CrossSiteRequestManager to see that the RVH responsible has a
142// pending cross-site request, and then installs a CrossSiteEventHandler.
143// - When RDH receives a response, the BufferedEventHandler determines whether
144// it is a download. If so, it sends a message to the new renderer causing
145// it to cancel the request, and the download proceeds in the download
146// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34147// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32148// doesn't affect any functionality.
149// - After RDH receives a response and determines that it is safe and not a
150// download, it pauses the response to first run the old page's onunload
151// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34152// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32153// to the current RVH.
154// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
155// the ResourceDispatcherHost, who unpauses the response. Data is then sent
156// to the pending RVH.
157// - The pending renderer sends a FrameNavigate message that invokes the
158// DidNavigate method. This replaces the current RVH with the
159// pending RVH and goes back to the NORMAL RendererState.
160
161namespace {
162
163// Amount of time we wait between when a key event is received and the renderer
164// is queried for its state and pushed to the NavigationEntry.
165const int kQueryStateDelay = 5000;
166
[email protected]6ebdc9b2010-09-27 16:55:57167const int kSyncWaitDelay = 40;
168
[email protected]420ae012009-04-24 05:16:32169// If another javascript message box is displayed within
170// kJavascriptMessageExpectedDelay of a previous javascript message box being
171// dismissed, display an option to suppress future message boxes from this
172// contents.
173const int kJavascriptMessageExpectedDelay = 1000;
174
[email protected]420ae012009-04-24 05:16:32175// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51176const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32177 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17178 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32179 prefs::kWebKitJavaEnabled,
180 prefs::kWebKitJavascriptEnabled,
181 prefs::kWebKitLoadsImagesAutomatically,
182 prefs::kWebKitPluginsEnabled,
183 prefs::kWebKitUsesUniversalDetector,
184 prefs::kWebKitSerifFontFamily,
185 prefs::kWebKitSansSerifFontFamily,
186 prefs::kWebKitFixedFontFamily,
187 prefs::kWebKitDefaultFontSize,
188 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13189 prefs::kWebKitMinimumFontSize,
190 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36191 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32192 prefs::kDefaultCharset
193 // kWebKitStandardFontIsSerif needs to be added
194 // if we let users pick which font to use, serif or sans-serif when
195 // no font is specified or a CSS generic family (serif or sans-serif)
196 // is not specified.
197};
198
199const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
200
[email protected]420ae012009-04-24 05:16:32201// Returns true if the entry's transition type is FORM_SUBMIT.
202bool IsFormSubmit(const NavigationEntry* entry) {
203 return (PageTransition::StripQualifier(entry->transition_type()) ==
204 PageTransition::FORM_SUBMIT);
205}
206
207#if defined(OS_WIN)
208
209BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
210 // Note: erase is required to properly paint some widgets borders. This can
211 // be seen with textfields.
212 InvalidateRect(hwnd, NULL, TRUE);
213 return TRUE;
214}
215#endif
216
[email protected]5e369672009-11-03 23:48:30217ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16218 Profile* profile, const NavigationEntry& entry,
219 NavigationController::ReloadType reload_type) {
220 switch (reload_type) {
221 case NavigationController::RELOAD:
222 return ViewMsg_Navigate_Params::RELOAD;
223 case NavigationController::RELOAD_IGNORING_CACHE:
224 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
225 case NavigationController::NO_RELOAD:
226 break; // Fall through to rest of function.
227 }
[email protected]5e369672009-11-03 23:48:30228
229 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
230 profile->DidLastSessionExitCleanly())
231 return ViewMsg_Navigate_Params::RESTORE;
232
233 return ViewMsg_Navigate_Params::NORMAL;
234}
235
[email protected]876bc832010-09-07 16:29:54236void MakeNavigateParams(const NavigationEntry& entry,
237 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16238 NavigationController::ReloadType reload_type,
239 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34240 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54241 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00242 params->current_history_list_offset = controller.last_committed_entry_index();
243 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34244 params->url = entry.url();
245 params->referrer = entry.referrer();
246 params->transition = entry.transition_type();
247 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00248 params->navigation_type =
249 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34250 params->request_time = base::Time::Now();
251}
252
[email protected]d12dcdd62011-01-27 06:53:25253// PluginInfoBar --------------------------------------------------------------
254
255class PluginInfoBar : public ConfirmInfoBarDelegate {
256 public:
257 PluginInfoBar(TabContents* tab_contents, const string16& name);
258
259 // ConfirmInfoBarDelegate:
260 virtual void InfoBarClosed() = 0;
261 virtual SkBitmap* GetIcon() const;
262 virtual string16 GetMessageText() const = 0;
263 virtual int GetButtons() const;
264 virtual string16 GetButtonLabel(InfoBarButton button) const = 0;
265 virtual bool Accept() = 0;
266 virtual bool Cancel() = 0;
267 virtual string16 GetLinkText();
268 virtual bool LinkClicked(WindowOpenDisposition disposition) = 0;
269
270 protected:
271 virtual ~PluginInfoBar();
272
273 void CommonCancel();
274 void CommonClose();
275 void CommonLearnMore(WindowOpenDisposition disposition);
276
277 string16 name_;
278 TabContents* tab_contents_;
279
280 private:
281 DISALLOW_COPY_AND_ASSIGN(PluginInfoBar);
282};
283
284PluginInfoBar::PluginInfoBar(TabContents* tab_contents, const string16& name)
285 : ConfirmInfoBarDelegate(tab_contents),
286 name_(name),
287 tab_contents_(tab_contents) {
288}
289
290PluginInfoBar::~PluginInfoBar() {
291}
292
293void PluginInfoBar::CommonClose() {
294 delete this;
295}
296
297SkBitmap* PluginInfoBar::GetIcon() const {
298 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
299 IDR_INFOBAR_PLUGIN_INSTALL);
300}
301
302int PluginInfoBar::GetButtons() const {
303 return BUTTON_OK | BUTTON_CANCEL;
304}
305
306void PluginInfoBar::CommonCancel() {
307 tab_contents_->render_view_host()->LoadBlockedPlugins();
308}
309
310string16 PluginInfoBar::GetLinkText() {
311 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
312}
313
314void PluginInfoBar::CommonLearnMore(WindowOpenDisposition disposition) {
315 // TODO(bauerb): Navigate to a help page explaining why we disabled
316 // or blocked the plugin, once we have one.
317}
318
319
320// BlockedPluginInfoBar -------------------------------------------------------
321
322class BlockedPluginInfoBar : public PluginInfoBar {
323 public:
324 BlockedPluginInfoBar(TabContents* tab_contents,
325 const string16& name);
326
327 // ConfirmInfoBarDelegate:
328 virtual string16 GetMessageText() const;
329 virtual string16 GetButtonLabel(InfoBarButton button) const;
330 virtual bool Accept();
331 virtual bool Cancel();
332 virtual void InfoBarClosed();
333 virtual bool LinkClicked(WindowOpenDisposition disposition);
334
335 protected:
336 virtual ~BlockedPluginInfoBar();
337
338 private:
339 DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar);
340};
341
342BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents,
343 const string16& name)
344 : PluginInfoBar(tab_contents, name) {
345 tab_contents->AddInfoBar(this);
346 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Shown"));
347}
348
349BlockedPluginInfoBar::~BlockedPluginInfoBar() {
350}
351
352string16 BlockedPluginInfoBar::GetMessageText() const {
353 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_);
354}
355
356string16 BlockedPluginInfoBar::GetButtonLabel(InfoBarButton button) const {
357 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
358 IDS_PLUGIN_ENABLE_ALWAYS : IDS_PLUGIN_ENABLE_TEMPORARILY);
359}
360
361bool BlockedPluginInfoBar::Accept() {
362 UserMetrics::RecordAction(
363 UserMetricsAction("BlockedPluginInfobar.AlwaysAllow"));
364 tab_contents_->profile()->GetHostContentSettingsMap()->AddExceptionForURL(
365 tab_contents_->GetURL(), CONTENT_SETTINGS_TYPE_PLUGINS, std::string(),
366 CONTENT_SETTING_ALLOW);
367 tab_contents_->render_view_host()->LoadBlockedPlugins();
368 return false;
369}
370
371bool BlockedPluginInfoBar::Cancel() {
372 UserMetrics::RecordAction(
373 UserMetricsAction("BlockedPluginInfobar.AllowThisTime"));
374 CommonCancel();
375 return false;
376}
377
378void BlockedPluginInfoBar::InfoBarClosed() {
379 UserMetrics::RecordAction(UserMetricsAction("BlockedPluginInfobar.Closed"));
380 CommonClose();
381}
382
383bool BlockedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) {
384 UserMetrics::RecordAction(
385 UserMetricsAction("BlockedPluginInfobar.LearnMore"));
386 CommonLearnMore(disposition);
387 return false;
388}
[email protected]f4f50ef2011-01-21 19:01:19389
390// OutdatedPluginInfoBar ------------------------------------------------------
391
[email protected]d12dcdd62011-01-27 06:53:25392class OutdatedPluginInfoBar : public PluginInfoBar {
[email protected]851b1eb2010-08-09 13:32:29393 public:
[email protected]3c2826852010-12-16 19:09:14394 OutdatedPluginInfoBar(TabContents* tab_contents,
[email protected]851b1eb2010-08-09 13:32:29395 const string16& name,
[email protected]f4f50ef2011-01-21 19:01:19396 const GURL& update_url);
[email protected]f5ec1ba2010-12-22 17:47:40397
[email protected]f4f50ef2011-01-21 19:01:19398 // ConfirmInfoBarDelegate:
[email protected]f4f50ef2011-01-21 19:01:19399 virtual string16 GetMessageText() const;
[email protected]f4f50ef2011-01-21 19:01:19400 virtual string16 GetButtonLabel(InfoBarButton button) const;
401 virtual bool Accept();
402 virtual bool Cancel();
[email protected]d12dcdd62011-01-27 06:53:25403 virtual void InfoBarClosed();
[email protected]f4f50ef2011-01-21 19:01:19404 virtual bool LinkClicked(WindowOpenDisposition disposition);
405
[email protected]d12dcdd62011-01-27 06:53:25406 protected:
407 virtual ~OutdatedPluginInfoBar();
408
409 private:
[email protected]851b1eb2010-08-09 13:32:29410 GURL update_url_;
[email protected]d12dcdd62011-01-27 06:53:25411
412 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar);
[email protected]851b1eb2010-08-09 13:32:29413};
414
[email protected]f4f50ef2011-01-21 19:01:19415OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents,
416 const string16& name,
417 const GURL& update_url)
[email protected]d12dcdd62011-01-27 06:53:25418 : PluginInfoBar(tab_contents, name), update_url_(update_url) {
[email protected]f4f50ef2011-01-21 19:01:19419 tab_contents->AddInfoBar(this);
[email protected]d12dcdd62011-01-27 06:53:25420 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown"));
[email protected]f4f50ef2011-01-21 19:01:19421}
422
423OutdatedPluginInfoBar::~OutdatedPluginInfoBar() {
424}
425
[email protected]f4f50ef2011-01-21 19:01:19426string16 OutdatedPluginInfoBar::GetMessageText() const {
427 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
428}
429
[email protected]f4f50ef2011-01-21 19:01:19430string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const {
431 return l10n_util::GetStringUTF16((button == BUTTON_OK) ?
432 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY);
433}
434
435bool OutdatedPluginInfoBar::Accept() {
436 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update"));
437 tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB,
438 PageTransition::LINK);
439 return false;
440}
441
442bool OutdatedPluginInfoBar::Cancel() {
443 UserMetrics::RecordAction(
444 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime"));
[email protected]d12dcdd62011-01-27 06:53:25445 CommonCancel();
[email protected]f4f50ef2011-01-21 19:01:19446 return false;
447}
448
[email protected]d12dcdd62011-01-27 06:53:25449void OutdatedPluginInfoBar::InfoBarClosed() {
450 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed"));
451 CommonClose();
[email protected]f4f50ef2011-01-21 19:01:19452}
453
454bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) {
455 UserMetrics::RecordAction(
456 UserMetricsAction("OutdatedPluginInfobar.LearnMore"));
[email protected]d12dcdd62011-01-27 06:53:25457 CommonLearnMore(disposition);
[email protected]f4f50ef2011-01-21 19:01:19458 return false;
459}
460
[email protected]420ae012009-04-24 05:16:32461} // namespace
462
[email protected]f4f50ef2011-01-21 19:01:19463
464// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32465
[email protected]fdd61c62009-04-22 19:22:57466// static
467int TabContents::find_request_id_counter_ = -1;
468
[email protected]420ae012009-04-24 05:16:32469
[email protected]420ae012009-04-24 05:16:32470TabContents::TabContents(Profile* profile,
471 SiteInstance* site_instance,
472 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07473 const TabContents* base_tab_contents,
474 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42475 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07476 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
477 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13478 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22479 TabContentsView::Create(this))),
480 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57481 property_bag_(),
482 registrar_(),
[email protected]12802702010-07-09 19:43:09483 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
484 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57485 save_package_(),
[email protected]6db0def92010-03-02 19:55:45486 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21487 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57488 plugin_installer_(),
[email protected]973407b2011-01-26 23:18:23489 prerender_plt_recorder_(),
[email protected]6f821dd2010-02-23 00:54:06490 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22491 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34492 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23493 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
494 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34495 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34496 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57497 current_load_start_(),
498 load_state_(net::LOAD_STATE_IDLE),
499 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56500 upload_size_(0),
501 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57502 received_page_title_(false),
503 is_starred_(false),
504 contents_mime_type_(),
505 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40506 blocked_contents_(NULL),
507 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49508 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47509 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57510 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57511 find_ui_active_(false),
512 find_op_aborted_(false),
513 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12514 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12515 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08516 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57517 capturing_contents_(false),
518 is_being_destroyed_(false),
519 notify_disconnection_(false),
520 history_requests_(),
521#if defined(OS_WIN)
522 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
523#endif
524 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44525 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01526 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54527 renderer_preferences_(),
[email protected]80a8fad2011-01-29 04:02:38528 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16529 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38530 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25531 minimum_zoom_percent_(
532 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
533 maximum_zoom_percent_(
534 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00535 temporary_zoom_settings_(false),
536 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54537 renderer_preferences_util::UpdateFromSystemSettings(
538 &renderer_preferences_, profile);
539
[email protected]9fb83e82010-07-02 18:24:55540 content_settings_delegate_.reset(
541 new TabSpecificContentSettings(this, profile));
542
[email protected]12636df2009-09-28 22:32:21543 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32544
[email protected]34ac70502009-09-25 17:07:23545 // We have the initial size of the view be based on the size of the passed in
546 // tab contents (normally a tab from the same window).
547 view_->CreateView(base_tab_contents ?
548 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32549
550 // Register for notifications about all interested prefs change.
551 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28552 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32553 if (prefs) {
554 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28555 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32556 }
557
558 // Register for notifications about URL starredness changing on any profile.
559 registrar_.Add(this, NotificationType::URLS_STARRED,
560 NotificationService::AllSources());
561 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
562 NotificationService::AllSources());
563 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
564 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09565#if defined(OS_LINUX)
566 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
567 NotificationService::AllSources());
568#endif
[email protected]420ae012009-04-24 05:16:32569
[email protected]6c32ce72010-03-08 05:18:06570 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
571 NotificationService::AllSources());
572
[email protected]79580c62010-02-02 02:36:25573 // Register for notifications about content setting changes.
574 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
575 NotificationService::AllSources());
576
[email protected]a888b29e62010-04-01 13:38:57577 // Listen for extension changes so we can update extension_for_current_page_.
578 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
579 NotificationService::AllSources());
580 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
581 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57582
[email protected]88152052010-10-01 04:05:18583 // Listen for Google URL changes
584 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
585 NotificationService::AllSources());
586
[email protected]c8865482009-07-23 20:40:10587 // Set-up the showing of the omnibox search infobar if applicable.
588 if (OmniboxSearchHint::IsEnabled(profile))
589 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53590
591 autofill_manager_.reset(new AutoFillManager(this));
[email protected]585b30362011-01-28 02:30:17592 AddObserver(autofill_manager_.get());
[email protected]403415a2011-01-10 18:57:53593 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
[email protected]585b30362011-01-28 02:30:17594 AddObserver(autocomplete_history_manager_.get());
[email protected]973407b2011-01-26 23:18:23595 prerender_plt_recorder_.reset(new PrerenderPLTRecorder(this));
[email protected]585b30362011-01-28 02:30:17596 AddObserver(prerender_plt_recorder_.get());
597 AddObserver(&fav_icon_helper_);
598 AddObserver(printing_.get());
[email protected]74da5bd2011-01-27 22:03:27599 desktop_notification_handler_.reset(
600 new DesktopNotificationHandler(this, GetRenderProcessHost()));
[email protected]585b30362011-01-28 02:30:17601 AddObserver(desktop_notification_handler_.get());
[email protected]332af7732009-03-11 13:21:35602}
initial.commit09911bf2008-07-26 23:55:29603
604TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32605 is_being_destroyed_ = true;
606
[email protected]bfe4c1582009-10-02 18:11:09607 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32608 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28609 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32610
[email protected]420ae012009-04-24 05:16:32611 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00612 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32613
[email protected]420ae012009-04-24 05:16:32614 // First cleanly close all child windows.
615 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
616 // some of these to close. CloseWindows is async, so it might get called
617 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49618 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32619
[email protected]c65e2f152010-10-14 15:30:40620 // Close all blocked contents.
621 if (blocked_contents_)
622 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13623
[email protected]420ae012009-04-24 05:16:32624 // Notify any observer that have a reference on this tab contents.
625 NotificationService::current()->Notify(
626 NotificationType::TAB_CONTENTS_DESTROYED,
627 Source<TabContents>(this),
628 NotificationService::NoDetails());
629
[email protected]1e5e74f2009-05-27 20:55:12630 // Notify any lasting InfobarDelegates that have not yet been removed that
631 // whatever infobar they were handling in this TabContents has closed,
632 // because the TabContents is going away entirely.
633 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
634 // notification may trigger infobars calls that access their delegate. (and
635 // some implementations of InfoBarDelegate do delete themselves on
636 // InfoBarClosed()).
637 for (int i = 0; i < infobar_delegate_count(); ++i) {
638 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
639 delegate->InfoBarClosed();
640 }
641 infobar_delegates_.clear();
642
[email protected]420ae012009-04-24 05:16:32643 // TODO(brettw) this should be moved to the view.
644#if defined(OS_WIN)
645 // If we still have a window handle, destroy it. GetNativeView can return
646 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42647 if (GetNativeView()) {
648 RenderViewHost* host = render_view_host();
649 if (host && host->view()) {
650 host->view()->WillWmDestroy();
651 }
[email protected]420ae012009-04-24 05:16:32652 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42653 }
[email protected]420ae012009-04-24 05:16:32654#endif
[email protected]7ab1e7d62009-10-14 23:32:01655
656 // OnCloseStarted isn't called in unit tests.
657 if (!tab_close_start_time_.is_null()) {
658 UMA_HISTOGRAM_TIMES("Tab.Close",
659 base::TimeTicks::Now() - tab_close_start_time_);
660 }
initial.commit09911bf2008-07-26 23:55:29661}
662
[email protected]d5f942ba2008-09-26 19:30:34663// static
664void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32665 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
666
667 WebPreferences pref_defaults;
668 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
669 pref_defaults.javascript_enabled);
670 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
671 pref_defaults.web_security_enabled);
672 prefs->RegisterBooleanPref(
673 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
674 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
675 pref_defaults.loads_images_automatically);
676 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
677 pref_defaults.plugins_enabled);
678 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
679 pref_defaults.dom_paste_enabled);
680 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
681 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14682 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32683 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
684 pref_defaults.text_areas_are_resizable);
685 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
686 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36687 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
688 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32689
690 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
691 IDS_ACCEPT_LANGUAGES);
692 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
693 IDS_DEFAULT_ENCODING);
694 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
695 IDS_STANDARD_FONT_IS_SERIF);
696 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
697 IDS_FIXED_FONT_FAMILY);
698 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
699 IDS_SERIF_FONT_FAMILY);
700 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
701 IDS_SANS_SERIF_FONT_FAMILY);
702 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
703 IDS_CURSIVE_FONT_FAMILY);
704 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
705 IDS_FANTASY_FONT_FAMILY);
706 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
707 IDS_DEFAULT_FONT_SIZE);
708 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
709 IDS_DEFAULT_FIXED_FONT_SIZE);
710 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
711 IDS_MINIMUM_FONT_SIZE);
712 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
713 IDS_MINIMUM_LOGICAL_FONT_SIZE);
714 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
715 IDS_USES_UNIVERSAL_DETECTOR);
716 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
717 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29718}
719
[email protected]724159a2010-12-30 01:11:18720bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17721 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
722 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10723 while ((observer = it.GetNext()) != NULL)
724 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53725 return true;
[email protected]403415a2011-01-10 18:57:53726
[email protected]724159a2010-12-30 01:11:18727 bool handled = true;
728 bool message_is_ok = true;
729 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
730 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
731 OnDidStartProvisionalLoadForFrame)
732 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
733 OnDidRedirectProvisionalLoad)
734 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
735 OnDidFailProvisionalLoadWithError)
736 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
737 OnDidLoadResourceFromMemoryCache)
738 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
739 OnDidDisplayInsecureContent)
740 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
741 OnDidRunInsecureContent)
742 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
743 OnDocumentLoadedInFrame)
744 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17745 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
746 OnUpdateContentRestrictions)
747 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
748 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25749 IPC_MESSAGE_HANDLER(ViewHostMsg_Find_Reply, OnFindReply)
750 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
751 IPC_MESSAGE_HANDLER(ViewHostMsg_MissingPluginStatus, OnMissingPluginStatus)
752 IPC_MESSAGE_HANDLER(ViewHostMsg_CrashedPlugin, OnCrashedPlugin)
753 IPC_MESSAGE_HANDLER(ViewHostMsg_BlockedOutdatedPlugin,
754 OnBlockedOutdatedPlugin)
755 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
756 OnDidGetApplicationInfo)
757 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
758 OnInstallApplication)
759 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
760 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
761 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
762 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
763 OnInstantSupportDetermined)
[email protected]34f128d2011-01-25 19:07:44764 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
[email protected]724159a2010-12-30 01:11:18765 IPC_MESSAGE_UNHANDLED(handled = false)
766 IPC_END_MESSAGE_MAP_EX()
767
768 if (!message_is_ok) {
769 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
770 GetRenderProcessHost()->ReceivedBadMessage();
771 }
772
773 return handled;
774}
775
[email protected]13367f72009-07-08 16:39:02776// Returns true if contains content rendered by an extension.
777bool TabContents::HostsExtension() const {
778 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34779}
780
[email protected]f4f50ef2011-01-21 19:01:19781PluginInstallerInfoBarDelegate* TabContents::GetPluginInstaller() {
[email protected]6e95706d2009-04-23 22:55:01782 if (plugin_installer_.get() == NULL)
[email protected]f4f50ef2011-01-21 19:01:19783 plugin_installer_.reset(new PluginInstallerInfoBarDelegate(this));
[email protected]6e95706d2009-04-23 22:55:01784 return plugin_installer_.get();
785}
786
[email protected]1f18184a2010-07-21 19:34:49787TabContentsSSLHelper* TabContents::GetSSLHelper() {
788 if (ssl_helper_.get() == NULL)
789 ssl_helper_.reset(new TabContentsSSLHelper(this));
790 return ssl_helper_.get();
791}
792
[email protected]8cb5d5b2010-02-09 11:36:16793RenderProcessHost* TabContents::GetRenderProcessHost() const {
794 return render_manager_.current_host()->process();
795}
796
[email protected]9adb9692010-10-29 23:14:02797void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46798 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08799 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10800
[email protected]98aa0b52010-05-06 17:03:08801 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57802
[email protected]fca656c2010-02-10 20:30:10803 NotificationService::current()->Notify(
804 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
805 Source<TabContents>(this),
806 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49807}
808
[email protected]98aa0b52010-05-06 17:03:08809void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
810 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40811 return;
812
[email protected]eaa7dd182010-12-14 11:09:00813 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50814 if (!extension_service || !extension_service->is_ready())
815 return;
816
817 const Extension* extension =
818 extension_service->GetExtensionById(extension_app_id, false);
819 if (extension)
820 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40821}
822
[email protected]98aa0b52010-05-06 17:03:08823SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08824 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51825 return NULL;
826
[email protected]98aa0b52010-05-06 17:03:08827 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51828}
829
[email protected]d5f942ba2008-09-26 19:30:34830const GURL& TabContents::GetURL() const {
831 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57832 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54833 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34834}
835
[email protected]96d185d2009-04-24 03:28:54836const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55837 // Transient entries take precedence. They are used for interstitial pages
838 // that are shown on top of existing pages.
839 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23840 if (entry) {
841 return entry->GetTitleForDisplay(profile()->GetPrefs()->
842 GetString(prefs::kAcceptLanguages));
843 }
[email protected]96d185d2009-04-24 03:28:54844 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
845 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
846 if (our_dom_ui) {
847 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55848 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54849 if (!(entry && entry->IsViewSourceMode())) {
850 // Give the DOM UI the chance to override our title.
851 const string16& title = our_dom_ui->overridden_title();
852 if (!title.empty())
853 return title;
854 }
855 }
856
857 // We use the title for the last committed entry rather than a pending
858 // navigation entry. For example, when the user types in a URL, we want to
859 // keep the old page's title until the new load has committed and we get a new
860 // title.
[email protected]96d185d2009-04-24 03:28:54861 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23862 if (entry) {
863 return entry->GetTitleForDisplay(profile()->GetPrefs()->
864 GetString(prefs::kAcceptLanguages));
865 }
[email protected]96d185d2009-04-24 03:28:54866 return EmptyString16();
867}
868
[email protected]bbbc1ef2010-02-12 18:03:41869// static
870string16 TabContents::GetDefaultTitle() {
871 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
872}
873
[email protected]d5f942ba2008-09-26 19:30:34874int32 TabContents::GetMaxPageID() {
875 if (GetSiteInstance())
876 return GetSiteInstance()->max_page_id();
877 else
878 return max_page_id_;
879}
880
881void TabContents::UpdateMaxPageID(int32 page_id) {
882 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34883 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34884 // testing.
885 if (GetSiteInstance())
886 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16887 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34888}
889
[email protected]96d185d2009-04-24 03:28:54890SiteInstance* TabContents::GetSiteInstance() const {
891 return render_manager_.current_host()->site_instance();
892}
893
[email protected]96d185d2009-04-24 03:28:54894bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15895 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54896 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15897 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01898 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54899 return true;
[email protected]8ab24cc2009-11-13 20:56:15900 }
[email protected]83e3895b2009-06-11 00:07:16901
[email protected]96d185d2009-04-24 03:28:54902 DOMUI* dom_ui = GetDOMUIForCurrentState();
903 if (dom_ui)
904 return !dom_ui->should_hide_url();
905 return true;
906}
907
[email protected]d5f942ba2008-09-26 19:30:34908SkBitmap TabContents::GetFavIcon() const {
909 // Like GetTitle(), we also want to use the favicon for the last committed
910 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57911 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47912 if (entry)
913 return entry->favicon().bitmap();
914
[email protected]ce3fa3c2009-04-20 19:55:57915 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34916 if (entry)
917 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34918 return SkBitmap();
919}
920
[email protected]0b303cc2009-09-28 22:35:15921bool TabContents::FavIconIsValid() const {
922 NavigationEntry* entry = controller_.GetTransientEntry();
923 if (entry)
924 return entry->favicon().is_valid();
925
926 entry = controller_.GetLastCommittedEntry();
927 if (entry)
928 return entry->favicon().is_valid();
929
930 return false;
931}
932
[email protected]96d185d2009-04-24 03:28:54933bool TabContents::ShouldDisplayFavIcon() {
934 // Always display a throbber during pending loads.
935 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
936 return true;
937
938 DOMUI* dom_ui = GetDOMUIForCurrentState();
939 if (dom_ui)
940 return !dom_ui->hide_favicon();
941 return true;
942}
943
[email protected]42197a22010-12-28 23:29:42944string16 TabContents::GetStatusText() const {
[email protected]96d185d2009-04-24 03:28:54945 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
[email protected]42197a22010-12-28 23:29:42946 return string16();
[email protected]96d185d2009-04-24 03:28:54947
948 switch (load_state_) {
949 case net::LOAD_STATE_WAITING_FOR_CACHE:
[email protected]42197a22010-12-28 23:29:42950 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04951 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
[email protected]42197a22010-12-28 23:29:42952 return
953 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54954 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
[email protected]42197a22010-12-28 23:29:42955 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
[email protected]96d185d2009-04-24 03:28:54956 case net::LOAD_STATE_RESOLVING_HOST:
[email protected]42197a22010-12-28 23:29:42957 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
[email protected]96d185d2009-04-24 03:28:54958 case net::LOAD_STATE_CONNECTING:
[email protected]42197a22010-12-28 23:29:42959 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06960 case net::LOAD_STATE_SSL_HANDSHAKE:
[email protected]42197a22010-12-28 23:29:42961 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54962 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56963 if (upload_size_)
[email protected]42197a22010-12-28 23:29:42964 return l10n_util::GetStringFUTF16Int(
[email protected]094e5b22009-09-25 04:23:56965 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
966 static_cast<int>((100 * upload_position_) / upload_size_));
967 else
[email protected]42197a22010-12-28 23:29:42968 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54969 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
[email protected]42197a22010-12-28 23:29:42970 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
971 load_state_host_);
[email protected]96d185d2009-04-24 03:28:54972 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
973 case net::LOAD_STATE_IDLE:
974 case net::LOAD_STATE_READING_RESPONSE:
975 break;
976 }
977
[email protected]42197a22010-12-28 23:29:42978 return string16();
[email protected]96d185d2009-04-24 03:28:54979}
980
[email protected]585b30362011-01-28 02:30:17981void TabContents::AddObserver(TabContentsObserver* observer) {
982 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49983}
984
[email protected]585b30362011-01-28 02:30:17985void TabContents::RemoveObserver(TabContentsObserver* observer) {
986 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49987}
988
[email protected]443b80e2010-12-14 00:42:23989void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
990 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34991 return;
992
[email protected]443b80e2010-12-14 00:42:23993 crashed_status_ = status;
994 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50995 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34996}
997
[email protected]744ef172009-10-16 21:53:46998void TabContents::PageActionStateChanged() {
999 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:001000}
[email protected]ce5c4502009-05-06 16:46:111001
[email protected]d5f942ba2008-09-26 19:30:341002void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
1003 if (delegate_)
1004 delegate_->NavigationStateChanged(this, changed_flags);
1005}
1006
[email protected]96d185d2009-04-24 03:28:541007void TabContents::DidBecomeSelected() {
1008 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:161009 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
1010 if (rwhv) {
1011 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:431012#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:161013 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:431014#endif
1015 }
[email protected]96d185d2009-04-24 03:28:541016
[email protected]8cb5d5b2010-02-09 11:36:161017 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:111018 last_selected_time_ = base::TimeTicks::Now();
[email protected]61d68ef12011-01-13 14:02:561019#if defined(OS_CHROMEOS)
1020 chromeos::LocaleChangeGuard::Check(this);
1021#endif
[email protected]96d185d2009-04-24 03:28:541022}
1023
[email protected]a94454b2010-12-16 04:16:031024void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:451025 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
1026 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
1027 if (rwhv)
[email protected]a94454b2010-12-16 04:16:031028 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:451029}
1030
1031void TabContents::CancelInstantFade() {
1032 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
1033 if (rwhv)
1034 rwhv->SetVisuallyDeemphasized(NULL, false);
1035}
1036
[email protected]96d185d2009-04-24 03:28:541037void TabContents::WasHidden() {
1038 if (!capturing_contents()) {
1039 // |render_view_host()| can be NULL if the user middle clicks a link to open
1040 // a tab in then background, then closes the tab before selecting it. This
1041 // is because closing the tab calls TabContents::Destroy(), which removes
1042 // the |render_view_host()|; then when we actually destroy the window,
1043 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:161044 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
1045 if (rwhv)
1046 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:541047 }
1048
1049 NotificationService::current()->Notify(
1050 NotificationType::TAB_CONTENTS_HIDDEN,
1051 Source<TabContents>(this),
1052 NotificationService::NoDetails());
1053}
1054
[email protected]d5f942ba2008-09-26 19:30:341055void TabContents::Activate() {
1056 if (delegate_)
1057 delegate_->ActivateContents(this);
1058}
1059
[email protected]ea42e7782010-08-23 23:58:121060void TabContents::Deactivate() {
1061 if (delegate_)
1062 delegate_->DeactivateContents(this);
1063}
1064
[email protected]96d185d2009-04-24 03:28:541065void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:161066 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
1067 if (rwhv)
1068 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:541069}
1070
1071void TabContents::HideContents() {
1072 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
1073 // our superclass HideContents(), because some callers want to be very picky
1074 // about the order in which these get called. In addition to making the code
1075 // here practically impossible to understand, this also means we end up
1076 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:341077 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:541078 WasHidden();
1079}
1080
[email protected]5aab5e22010-12-08 22:13:291081bool TabContents::NeedToFireBeforeUnload() {
1082 // TODO(creis): Should we fire even for interstitial pages?
1083 return notify_disconnection() &&
1084 !showing_interstitial_page() &&
1085 !render_view_host()->SuddenTerminationAllowed();
1086}
1087
[email protected]c0588052008-10-27 23:01:501088void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:341089 WindowOpenDisposition disposition,
1090 PageTransition::Type transition) {
1091 if (delegate_)
[email protected]c0588052008-10-27 23:01:501092 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:341093}
1094
[email protected]1ccb3568d2010-02-19 10:51:161095bool TabContents::NavigateToPendingEntry(
1096 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:541097 return NavigateToEntry(*controller_.pending_entry(), reload_type);
1098}
[email protected]96d185d2009-04-24 03:28:541099
[email protected]876bc832010-09-07 16:29:541100bool TabContents::NavigateToEntry(
1101 const NavigationEntry& entry,
1102 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:541103 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
1104 if (!dest_render_view_host)
1105 return false; // Unable to create the desired render view host.
1106
[email protected]770dd8b2010-05-24 18:11:391107 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
1108 dest_render_view_host->EnablePreferredSizeChangedMode(
1109 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
1110 }
[email protected]9fb325e2010-05-06 18:23:241111
[email protected]80a8fad2011-01-29 04:02:381112 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:071113 // Double check that here.
[email protected]54ec6472010-04-09 19:39:581114 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:401115 bool is_allowed_in_dom_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:381116 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:581117 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:401118 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:581119
[email protected]96d185d2009-04-24 03:28:541120 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:121121 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:321122 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:001123 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
1124 dest_render_view_host,
1125 entry.url());
[email protected]7e8e6b62009-05-08 11:28:321126 }
[email protected]96d185d2009-04-24 03:28:541127
1128 // Used for page load time metrics.
1129 current_load_start_ = base::TimeTicks::Now();
1130
1131 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:341132 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:541133 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:041134 if (delegate_) {
1135 navigate_params.extra_headers =
1136 delegate_->GetNavigationHeaders(navigate_params.url);
1137 }
[email protected]056de2d2009-06-26 16:41:341138 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:541139
1140 if (entry.page_id() == -1) {
1141 // HACK!! This code suppresses javascript: URLs from being added to
1142 // session history, which is what we want to do for javascript: URLs that
1143 // do not generate content. What we really need is a message from the
1144 // renderer telling us that a new page was not created. The same message
1145 // could be used for mailto: URLs and the like.
1146 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
1147 return false;
1148 }
1149
[email protected]3c9e1872010-11-18 16:17:491150 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171151 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:541152
[email protected]1ccb3568d2010-02-19 10:51:161153 if (reload_type != NavigationController::NO_RELOAD &&
1154 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:481155 FaviconService* favicon_service =
1156 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
1157 if (favicon_service)
1158 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:541159 }
1160
[email protected]d5f942ba2008-09-26 19:30:341161 return true;
1162}
1163
[email protected]96d185d2009-04-24 03:28:541164void TabContents::Stop() {
1165 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:091166 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:541167}
1168
[email protected]96d185d2009-04-24 03:28:541169void TabContents::DisassociateFromPopupCount() {
1170 render_view_host()->DisassociateFromPopupCount();
1171}
1172
1173TabContents* TabContents::Clone() {
1174 // We create a new SiteInstance so that the new tab won't share processes
1175 // with the old one. This can be changed in the future if we need it to share
1176 // processes for some reason.
[email protected]420ae012009-04-24 05:16:321177 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:541178 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:071179 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:541180 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:081181 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:081182 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:541183 return tc;
1184}
1185
[email protected]4d677202009-07-19 07:37:121186void TabContents::ShowPageInfo(const GURL& url,
1187 const NavigationEntry::SSLStatus& ssl,
1188 bool show_history) {
1189 if (!delegate_)
1190 return;
1191
[email protected]bb678332009-07-21 00:15:501192 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:121193}
1194
[email protected]ef0d04c2010-12-15 23:34:211195void TabContents::SaveFavicon() {
1196 NavigationEntry* entry = controller_.GetActiveEntry();
1197 if (!entry || entry->url().is_empty())
1198 return;
1199
1200 // Make sure the page is in history, otherwise adding the favicon does
1201 // nothing.
1202 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
1203 Profile::IMPLICIT_ACCESS);
1204 if (!history)
1205 return;
1206 history->AddPageNoVisitForBookmark(entry->url());
1207
1208 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
1209 Profile::IMPLICIT_ACCESS);
1210 if (!service)
1211 return;
1212 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
1213 if (!favicon.is_valid() || favicon.url().is_empty() ||
1214 favicon.bitmap().empty()) {
1215 return;
1216 }
1217 std::vector<unsigned char> image_data;
1218 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
1219 service->SetFavicon(entry->url(), favicon.url(), image_data);
1220}
1221
initial.commit09911bf2008-07-26 23:55:291222ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:281223 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:291224 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:281225 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:291226 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:441227
1228 if (child_windows_.size() == 1) {
1229 window->ShowConstrainedWindow();
1230 BlockTabContent(true);
1231 }
1232
initial.commit09911bf2008-07-26 23:55:291233 return window;
1234}
1235
[email protected]fa1cf0b82010-01-15 21:49:441236void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:551237 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:451238 // 70% opaque grey.
1239 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:551240 if (rwhv)
[email protected]1b072562010-12-13 19:37:451241 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:441242 render_view_host()->set_ignore_input_events(blocked);
1243 if (delegate_)
1244 delegate_->SetTabContentBlocked(this, blocked);
1245}
1246
initial.commit09911bf2008-07-26 23:55:291247void TabContents::AddNewContents(TabContents* new_contents,
1248 WindowOpenDisposition disposition,
1249 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:291250 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:401251 if (all_contents_blocked_) {
1252 if (!blocked_contents_)
1253 blocked_contents_ = new BlockedContentContainer(this);
1254 blocked_contents_->AddTabContents(
1255 new_contents, disposition, initial_pos, user_gesture);
1256 return;
1257 }
1258
initial.commit09911bf2008-07-26 23:55:291259 if (!delegate_)
1260 return;
1261
[email protected]35f7d212009-04-29 21:19:271262 if ((disposition == NEW_POPUP) && !user_gesture &&
1263 !CommandLine::ForCurrentProcess()->HasSwitch(
1264 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221265 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311266 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291267 delegate_->GetConstrainingContents(this)->AddPopup(
1268 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311269 } else {
[email protected]0aa55312008-10-17 21:53:081270 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291271 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1272 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491273 NotificationService::current()->Notify(
1274 NotificationType::TAB_ADDED,
1275 Source<TabContentsDelegate>(delegate_),
1276 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291277 }
initial.commit09911bf2008-07-26 23:55:291278
[email protected]8cc8d492010-02-02 10:40:491279 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401280 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291281}
1282
[email protected]bcd9dc42010-01-23 16:38:181283bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201284 bool is_js_code, const std::string& code_string,
1285 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511286 RenderViewHost* host = render_view_host();
1287 if (!host)
1288 return false;
1289
1290 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171291 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511292 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351293}
1294
[email protected]96d185d2009-04-24 03:28:541295void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491296 if (is_being_destroyed_)
1297 return;
[email protected]9fb83e82010-07-02 18:24:551298 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491299 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401300 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541301}
1302
[email protected]5c9e97a2009-09-09 23:48:301303gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541304 return view_->GetContentNativeView();
1305}
1306
1307gfx::NativeView TabContents::GetNativeView() const {
1308 return view_->GetNativeView();
1309}
1310
1311void TabContents::GetContainerBounds(gfx::Rect *out) const {
1312 view_->GetContainerBounds(out);
1313}
1314
1315void TabContents::Focus() {
1316 view_->Focus();
1317}
1318
[email protected]90daadb42009-06-08 21:27:281319void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541320 if (showing_interstitial_page()) {
1321 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1322 return;
1323 }
[email protected]96d185d2009-04-24 03:28:541324 render_view_host()->SetInitialFocus(reverse);
1325}
1326
1327bool TabContents::FocusLocationBarByDefault() {
1328 DOMUI* dom_ui = GetDOMUIForCurrentState();
1329 if (dom_ui)
1330 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431331 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251332 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431333 return true;
[email protected]96d185d2009-04-24 03:28:541334 return false;
1335}
1336
[email protected]a26dc362010-04-23 01:48:581337void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381338 if (delegate())
[email protected]a26dc362010-04-23 01:48:581339 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381340}
1341
[email protected]616ed5a2008-11-21 22:27:241342void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321343 if (delegate_ && !delegate_->infobars_enabled()) {
1344 delegate->InfoBarClosed();
1345 return;
1346 }
1347
[email protected]616ed5a2008-11-21 22:27:241348 // Look through the existing InfoBarDelegates we have for a match. If we've
1349 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051350 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451351 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1352 // Tell the new infobar to close so that it can clean itself up.
1353 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241354 return;
[email protected]6d27a7b2009-12-18 23:25:451355 }
[email protected]616ed5a2008-11-21 22:27:241356 }
1357
1358 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561359 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:191360 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:561361 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241362
1363 // Add ourselves as an observer for navigations the first time a delegate is
1364 // added. We use this notification to expire InfoBars that need to expire on
1365 // page transitions.
1366 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561367 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571368 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241369 }
1370}
1371
1372void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321373 if (delegate_ && !delegate_->infobars_enabled()) {
1374 return;
1375 }
1376
[email protected]616ed5a2008-11-21 22:27:241377 std::vector<InfoBarDelegate*>::iterator it =
1378 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1379 if (it != infobar_delegates_.end()) {
1380 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561381 NotificationService::current()->Notify(
1382 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1383 Source<TabContents>(this),
1384 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241385
[email protected]f4f50ef2011-01-21 19:01:191386 infobar_delegates_.erase(it);
1387 // Remove ourselves as an observer if we are tracking no more InfoBars.
1388 if (infobar_delegates_.empty()) {
1389 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1390 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031391 }
[email protected]616ed5a2008-11-21 22:27:241392 }
1393}
[email protected]3edd9522009-03-04 22:19:411394
[email protected]f81821c2009-08-07 01:29:471395void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1396 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321397 if (delegate_ && !delegate_->infobars_enabled()) {
1398 new_delegate->InfoBarClosed();
1399 return;
1400 }
1401
[email protected]f81821c2009-08-07 01:29:471402 std::vector<InfoBarDelegate*>::iterator it =
1403 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1404 DCHECK(it != infobar_delegates_.end());
1405
1406 // Notify the container about the change of plans.
1407 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1408 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1409 old_delegate, new_delegate));
1410 NotificationService::current()->Notify(
1411 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1412 Source<TabContents>(this),
1413 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1414
[email protected]f4f50ef2011-01-21 19:01:191415 // Remove the old one.
1416 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471417
1418 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081419 DCHECK(find(infobar_delegates_.begin(),
1420 infobar_delegates_.end(), new_delegate) ==
1421 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471422 infobar_delegates_.push_back(new_delegate);
1423}
1424
[email protected]20ede072009-10-06 00:28:351425bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271426 if (showing_interstitial_page())
1427 return false;
1428
[email protected]c8f74942010-09-03 10:04:141429 // Do not show bookmarks bar if bookmarks aren't enabled.
1430 if (!browser_defaults::bookmarks_enabled)
1431 return false;
1432
[email protected]96d185d2009-04-24 03:28:541433 // See GetDOMUIForCurrentState() comment for more info. This case is very
1434 // similar, but for non-first loads, we want to use the committed entry. This
1435 // is so the bookmarks bar disappears at the same time the page does.
1436 if (controller_.GetLastCommittedEntry()) {
1437 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371438 return (render_manager_.dom_ui() == NULL) ?
1439 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541440 }
1441
1442 // When it's the first load, we know either the pending one or the committed
1443 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1444 // of them will be valid, so we can just check both.
1445 if (render_manager_.pending_dom_ui())
1446 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371447 return (render_manager_.dom_ui() == NULL) ?
1448 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541449}
1450
[email protected]3edd9522009-03-04 22:19:411451void TabContents::ToolbarSizeChanged(bool is_animating) {
1452 TabContentsDelegate* d = delegate();
1453 if (d)
1454 d->ToolbarSizeChanged(this, is_animating);
1455}
[email protected]616ed5a2008-11-21 22:27:241456
[email protected]fc6fb7fb2009-11-07 02:35:041457bool TabContents::CanDownload(int request_id) {
1458 TabContentsDelegate* d = delegate();
1459 if (d)
1460 return d->CanDownload(request_id);
1461 return true;
1462}
1463
[email protected]d5f942ba2008-09-26 19:30:341464void TabContents::OnStartDownload(DownloadItem* download) {
1465 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341466
1467 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311468 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341469
[email protected]5b928b62010-08-03 11:46:511470 if (tab_contents && tab_contents->delegate())
1471 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411472}
[email protected]3edd9522009-03-04 22:19:411473
[email protected]d5f942ba2008-09-26 19:30:341474void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371475 ConstrainedWindowList::iterator i(
1476 std::find(child_windows_.begin(), child_windows_.end(), window));
1477 bool removed_topmost_window = i == child_windows_.begin();
1478 if (i != child_windows_.end())
1479 child_windows_.erase(i);
1480 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441481 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371482 } else {
1483 if (removed_topmost_window)
1484 child_windows_[0]->ShowConstrainedWindow();
1485 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441486 }
[email protected]66ba4932009-06-04 19:22:131487}
[email protected]d5f942ba2008-09-26 19:30:341488
[email protected]c65e2f152010-10-14 15:30:401489void TabContents::WillCloseBlockedContentContainer(
1490 BlockedContentContainer* container) {
1491 DCHECK(blocked_contents_ == container);
1492 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491493 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341494}
1495
[email protected]d5f942ba2008-09-26 19:30:341496void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351497#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061498 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351499#endif
[email protected]d5f942ba2008-09-26 19:30:341500}
1501
[email protected]c1dc9f132009-11-20 23:13:211502void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121503 bool forward_direction,
1504 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211505 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011506 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211507 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531508 string16 last_search_prepopulate_text =
1509 FindBarState::GetLastPrepopulateText(profile());
1510
[email protected]87fae512009-12-11 02:20:211511 // Try the last thing we searched for on this tab, then the last thing
1512 // searched for on any tab.
1513 if (!previous_find_text_.empty())
1514 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531515 else if (!last_search_prepopulate_text.empty())
1516 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211517 else
[email protected]e491f1c2009-05-22 20:28:121518 return;
[email protected]e491f1c2009-05-22 20:28:121519 }
[email protected]6e95706d2009-04-23 22:55:011520
[email protected]101c90e2009-10-26 21:14:441521 // Keep track of the previous search.
1522 previous_find_text_ = find_text_;
1523
[email protected]6e95706d2009-04-23 22:55:011524 // This is a FindNext operation if we are searching for the same text again,
1525 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1526 // exception to this is if the Find was aborted (then we don't want FindNext
1527 // because the highlighting has been cleared and we need it to reappear). We
1528 // therefore treat FindNext after an aborted Find operation as a full fledged
1529 // Find.
[email protected]c1dc9f132009-11-20 23:13:211530 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121531 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011532 !find_op_aborted_;
1533 if (!find_next)
1534 current_find_request_id_ = find_request_id_counter_++;
1535
[email protected]c1dc9f132009-11-20 23:13:211536 if (!search_string.empty())
1537 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121538 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011539
1540 find_op_aborted_ = false;
1541
1542 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531543 FindBarState* find_bar_state = profile()->GetFindBarState();
1544 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011545 render_view_host()->StartFinding(current_find_request_id_,
1546 find_text_,
1547 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121548 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011549 find_next);
1550}
1551
[email protected]5bc8fe92010-03-11 18:19:001552void TabContents::StopFinding(
1553 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011554 if (selection_action == FindBarController::kClearSelection) {
1555 // kClearSelection means the find string has been cleared by the user, but
1556 // the UI has not been dismissed. In that case we want to clear the
1557 // previously remembered search (http://crbug.com/42639).
1558 previous_find_text_ = string16();
1559 } else {
[email protected]2d2dffc2009-06-09 21:41:001560 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011561 if (!find_text_.empty())
1562 previous_find_text_ = find_text_;
1563 }
[email protected]101c90e2009-10-26 21:14:441564 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011565 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121566 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001567 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011568}
1569
[email protected]420ae012009-04-24 05:16:321570void TabContents::OnSavePage() {
1571 // If we can not save the page, try to download it.
1572 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1573 DownloadManager* dlm = profile()->GetDownloadManager();
1574 const GURL& current_page_url = GetURL();
1575 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221576 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321577 return;
1578 }
1579
1580 Stop();
1581
1582 // Create the save package and possibly prompt the user for the name to save
1583 // the page as. The user prompt is an asynchronous operation that runs on
1584 // another thread.
[email protected]34f128d2011-01-25 19:07:441585 SetSavePackage(new SavePackage(this));
[email protected]420ae012009-04-24 05:16:321586 save_package_->GetSaveInfo();
1587}
1588
1589// Used in automated testing to bypass prompting the user for file names.
1590// Instead, the names and paths are hard coded rather than running them through
1591// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111592bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321593 SavePackage::SavePackageType save_type) {
1594 // Stop the page from navigating.
1595 Stop();
1596
[email protected]34f128d2011-01-25 19:07:441597 SetSavePackage(new SavePackage(this, save_type, main_file, dir_path));
[email protected]cdf6cc82009-08-04 21:48:591598 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321599}
1600
[email protected]34f128d2011-01-25 19:07:441601void TabContents::SetSavePackage(SavePackage* save_package) {
1602 if (save_package_.get())
[email protected]585b30362011-01-28 02:30:171603 RemoveObserver(save_package_.get());
[email protected]34f128d2011-01-25 19:07:441604 save_package_ = save_package;
[email protected]585b30362011-01-28 02:30:171605 AddObserver(save_package);
[email protected]34f128d2011-01-25 19:07:441606}
1607
[email protected]89d6e6e2009-12-03 23:06:511608void TabContents::EmailPageLocation() {
1609 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1610 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1611 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1612 title + "&body=%0A%0A" + page_url;
1613 platform_util::OpenExternal(GURL(mailto));
1614}
1615
[email protected]420ae012009-04-24 05:16:321616void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161617 if (CommandLine::ForCurrentProcess()->HasSwitch(
1618 switches::kEnablePrintPreview)) {
1619 if (showing_interstitial_page())
1620 return;
1621 render_view_host()->PrintPreview();
1622 } else {
1623 PrintNow();
1624 }
[email protected]420ae012009-04-24 05:16:321625}
1626
1627bool TabContents::PrintNow() {
1628 // We can't print interstitial page for now.
1629 if (showing_interstitial_page())
1630 return false;
1631
1632 return render_view_host()->PrintPages();
1633}
1634
[email protected]82270452009-06-19 15:58:011635void TabContents::PrintingDone(int document_cookie, bool success) {
1636 render_view_host()->PrintingDone(document_cookie, success);
1637}
1638
[email protected]420ae012009-04-24 05:16:321639bool TabContents::IsActiveEntry(int32 page_id) {
1640 NavigationEntry* active_entry = controller_.GetActiveEntry();
1641 return (active_entry != NULL &&
1642 active_entry->site_instance() == GetSiteInstance() &&
1643 active_entry->page_id() == page_id);
1644}
1645
[email protected]b2fe07d12010-02-09 14:38:081646void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161647 set_encoding(encoding);
1648 render_view_host()->SetPageEncoding(encoding);
1649}
1650
[email protected]b2fe07d12010-02-09 14:38:081651void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161652 reset_encoding();
1653 render_view_host()->ResetPageEncodingToDefault();
1654}
1655
1656void TabContents::WindowMoveOrResizeStarted() {
1657 render_view_host()->WindowMoveOrResizeStarted();
1658}
1659
[email protected]c65e2f152010-10-14 15:30:401660void TabContents::SetAllContentsBlocked(bool value) {
1661 if (all_contents_blocked_ == value)
1662 return;
1663
1664 all_contents_blocked_ = value;
1665 if (!all_contents_blocked_ && blocked_contents_) {
1666 std::vector<TabContents*> blocked;
1667 blocked_contents_->GetBlockedContents(&blocked);
1668 for (size_t i = 0; i < blocked.size(); ++i)
1669 blocked_contents_->LaunchForContents(blocked[i]);
1670 }
1671}
1672
[email protected]3f8eb7f2009-10-02 23:58:051673void TabContents::LogNewTabTime(const std::string& event_name) {
1674 // Not all new tab pages get timed. In those cases, we don't have a
1675 // new_tab_start_time_.
1676 if (new_tab_start_time_.is_null())
1677 return;
1678
1679 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441680 MetricEventDurationDetails details(event_name,
1681 static_cast<int>(duration.InMilliseconds()));
1682
[email protected]7ab1e7d62009-10-14 23:32:011683 if (event_name == "Tab.NewTabScriptStart") {
1684 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1685 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1686 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1687 } else if (event_name == "Tab.NewTabOnload") {
1688 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051689 // The new tab page has finished loading; reset it.
1690 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441691 } else {
1692 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051693 }
[email protected]84abba62009-10-07 17:01:441694 NotificationService::current()->Notify(
1695 NotificationType::METRIC_EVENT_DURATION,
1696 Source<TabContents>(this),
1697 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051698}
1699
[email protected]7ab1e7d62009-10-14 23:32:011700void TabContents::OnCloseStarted() {
1701 if (tab_close_start_time_.is_null())
1702 tab_close_start_time_ = base::TimeTicks::Now();
1703}
1704
[email protected]46624bf2010-06-09 16:04:191705bool TabContents::ShouldAcceptDragAndDrop() const {
1706#if defined(OS_CHROMEOS)
1707 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1708 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201709 if (delegate() && delegate()->IsPopup(this))
1710 return false;
1711 return true;
[email protected]46624bf2010-06-09 16:04:191712#else
1713 return true;
1714#endif
1715}
1716
[email protected]ec0b6c42010-08-26 03:16:581717void TabContents::UpdateHistoryForNavigation(
1718 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1719 if (profile()->IsOffTheRecord())
1720 return;
1721
1722 // Add to history service.
1723 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1724 if (hs)
1725 hs->AddPage(*add_page_args);
1726}
1727
1728void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1729 if (profile()->IsOffTheRecord())
1730 return;
1731
1732 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1733 if (hs)
1734 hs->SetPageTitle(entry.virtual_url(), entry.title());
1735}
1736
[email protected]d0b8d092010-10-25 04:05:171737double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251738 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1739 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171740 return 0;
[email protected]b75b8292010-10-01 07:28:251741
1742 double zoom_level;
1743 if (temporary_zoom_settings_) {
1744 zoom_level = zoom_map->GetTemporaryZoomLevel(
1745 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1746 } else {
1747 zoom_level = zoom_map->GetZoomLevel(GetURL());
1748 }
[email protected]d0b8d092010-10-25 04:05:171749 return zoom_level;
1750}
[email protected]b75b8292010-10-01 07:28:251751
[email protected]d0b8d092010-10-25 04:05:171752int TabContents::GetZoomPercent(bool* enable_increment,
1753 bool* enable_decrement) {
1754 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251755 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171756 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251757 *enable_decrement = percent > minimum_zoom_percent_;
1758 *enable_increment = percent < maximum_zoom_percent_;
1759 return percent;
1760}
1761
[email protected]3c733bde2010-12-21 19:56:311762void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501763 if (!delegate_)
1764 return;
1765
1766 NavigationEntry* active_entry = controller().GetActiveEntry();
1767 if (!active_entry)
1768 return;
1769
1770 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121771}
1772
[email protected]724159a2010-12-30 01:11:181773void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1774 bool is_main_frame,
1775 const GURL& url) {
1776 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1777 GURL validated_url(url);
1778 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1779 GetRenderProcessHost()->id(), &validated_url);
1780
1781 ProvisionalLoadDetails details(
1782 is_main_frame,
1783 controller_.IsURLInPageNavigation(validated_url),
1784 validated_url, std::string(), false, is_error_page, frame_id);
1785 NotificationService::current()->Notify(
1786 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1787 Source<NavigationController>(&controller_),
1788 Details<ProvisionalLoadDetails>(&details));
1789 if (is_main_frame) {
1790 // If we're displaying a network error page do not reset the content
1791 // settings delegate's cookies so the user has a chance to modify cookie
1792 // settings.
1793 if (!is_error_page)
1794 content_settings_delegate_->ClearCookieSpecificContentSettings();
1795 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381796
1797 // Check if the URL we are about to load has been prerendered by any chance,
1798 // and use it if possible.
1799 MaybeUsePreloadedPage(url);
[email protected]724159a2010-12-30 01:11:181800 }
1801}
1802
1803void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1804 const GURL& source_url,
1805 const GURL& target_url) {
1806 NavigationEntry* entry;
1807 if (page_id == -1)
1808 entry = controller_.pending_entry();
1809 else
1810 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1811 if (!entry || entry->url() != source_url)
1812 return;
1813 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381814
1815 // Check if the URL we are about to load has been prerendered by any chance,
1816 // and use it if possible.
1817 MaybeUsePreloadedPage(target_url);
[email protected]724159a2010-12-30 01:11:181818}
1819
1820void TabContents::OnDidFailProvisionalLoadWithError(
1821 int64 frame_id,
1822 bool is_main_frame,
1823 int error_code,
1824 const GURL& url,
1825 bool showing_repost_interstitial) {
1826 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1827 << ", error_code: " << error_code
1828 << " is_main_frame: " << is_main_frame
1829 << " showing_repost_interstitial: " << showing_repost_interstitial
1830 << " frame_id: " << frame_id;
1831 GURL validated_url(url);
1832 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1833 GetRenderProcessHost()->id(), &validated_url);
1834
1835 if (net::ERR_ABORTED == error_code) {
1836 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1837 // This means that the interstitial won't be torn down properly, which is
1838 // bad. But if we have an interstitial, go back to another tab type, and
1839 // then load the same interstitial again, we could end up getting the first
1840 // interstitial's "failed" message (as a result of the cancel) when we're on
1841 // the second one.
1842 //
1843 // We can't tell this apart, so we think we're tearing down the current page
1844 // which will cause a crash later one. There is also some code in
1845 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1846 // out because of this problem.
1847 //
1848 // http://code.google.com/p/chromium/issues/detail?id=2855
1849 // Because this will not tear down the interstitial properly, if "back" is
1850 // back to another tab type, the interstitial will still be somewhat alive
1851 // in the previous tab type. If you navigate somewhere that activates the
1852 // tab with the interstitial again, you'll see a flash before the new load
1853 // commits of the interstitial page.
1854 if (showing_interstitial_page()) {
1855 LOG(WARNING) << "Discarding message during interstitial.";
1856 return;
1857 }
1858
1859 // This will discard our pending entry if we cancelled the load (e.g., if we
1860 // decided to download the file instead of load it). Only discard the
1861 // pending entry if the URLs match, otherwise the user initiated a navigate
1862 // before the page loaded so that the discard would discard the wrong entry.
1863 NavigationEntry* pending_entry = controller_.pending_entry();
1864 if (pending_entry && pending_entry->url() == validated_url) {
1865 controller_.DiscardNonCommittedEntries();
1866 // Update the URL display.
1867 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1868 }
1869
1870 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1871 }
1872
1873 // Send out a notification that we failed a provisional load with an error.
1874 ProvisionalLoadDetails details(
1875 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
1876 validated_url, std::string(), false, false, frame_id);
1877 details.set_error_code(error_code);
1878
1879 NotificationService::current()->Notify(
1880 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1881 Source<NavigationController>(&controller_),
1882 Details<ProvisionalLoadDetails>(&details));
1883}
1884
1885void TabContents::OnDidLoadResourceFromMemoryCache(
1886 const GURL& url,
1887 const std::string& frame_origin,
1888 const std::string& main_frame_origin,
1889 const std::string& security_info) {
1890 static base::StatsCounter cache("WebKit.CacheHit");
1891 cache.Increment();
1892
1893 // Send out a notification that we loaded a resource from our memory cache.
1894 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1895 SSLManager::DeserializeSecurityInfo(security_info,
1896 &cert_id, &cert_status,
1897 &security_bits,
1898 &connection_status);
1899 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
1900 GetRenderProcessHost()->id(), cert_id,
1901 cert_status);
1902
1903 NotificationService::current()->Notify(
1904 NotificationType::LOAD_FROM_MEMORY_CACHE,
1905 Source<NavigationController>(&controller_),
1906 Details<LoadFromMemoryCacheDetails>(&details));
1907}
1908
1909void TabContents::OnDidDisplayInsecureContent() {
1910 displayed_insecure_content_ = true;
1911 SSLManager::NotifySSLInternalStateChanged();
1912}
1913
1914void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021915 const std::string& security_origin, const GURL& target_url) {
[email protected]724159a2010-12-30 01:11:181916 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1917}
1918
1919void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1920 controller_.DocumentLoadedInFrame();
1921 NotificationService::current()->Notify(
1922 NotificationType::FRAME_DOM_CONTENT_LOADED,
1923 Source<NavigationController>(&controller_),
1924 Details<int64>(&frame_id));
1925}
1926
1927void TabContents::OnDidFinishLoad(int64 frame_id) {
1928 NotificationService::current()->Notify(
1929 NotificationType::FRAME_DID_FINISH_LOAD,
1930 Source<NavigationController>(&controller_),
1931 Details<int64>(&frame_id));
1932}
1933
[email protected]c8f73ab2011-01-22 00:05:171934void TabContents::OnUpdateContentRestrictions(int restrictions) {
1935 content_restrictions_ = restrictions;
1936 delegate()->ContentRestrictionsChanged(this);
1937}
1938
1939void TabContents::OnPDFHasUnsupportedFeature() {
1940 PDFHasUnsupportedFeature(this);
1941}
1942
[email protected]96d185d2009-04-24 03:28:541943// Notifies the RenderWidgetHost instance about the fact that the page is
1944// loading, or done loading and calls the base implementation.
1945void TabContents::SetIsLoading(bool is_loading,
1946 LoadNotificationDetails* details) {
1947 if (is_loading == is_loading_)
1948 return;
1949
1950 if (!is_loading) {
1951 load_state_ = net::LOAD_STATE_IDLE;
1952 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561953 upload_size_ = 0;
1954 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541955 }
1956
1957 render_manager_.SetIsLoading(is_loading);
1958
1959 is_loading_ = is_loading;
1960 waiting_for_response_ = is_loading;
1961
[email protected]6ebdc9b2010-09-27 16:55:571962 if (delegate_)
1963 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351964 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541965
1966 NotificationType type = is_loading ? NotificationType::LOAD_START :
1967 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111968 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541969 if (details)
1970 det = Details<LoadNotificationDetails>(details);
1971 NotificationService::current()->Notify(type,
1972 Source<NavigationController>(&controller_),
1973 det);
1974}
1975
[email protected]b6c874582009-05-08 19:38:311976void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291977 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061978 // A page can't spawn popups (or do anything else, either) until its load
1979 // commits, so when we reach here, the popup was spawned by the
1980 // NavigationController's last committed entry, not the active entry. For
1981 // example, if a page opens a popup in an onunload() handler, then the active
1982 // entry is the page to be loaded as we navigate away from the unloading
1983 // page. For this reason, we can't use GetURL() to get the opener URL,
1984 // because it returns the active entry.
1985 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1986 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1987
1988 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491989 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091990 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491991 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1992 } else {
[email protected]c65e2f152010-10-14 15:30:401993 if (!blocked_contents_)
1994 blocked_contents_ = new BlockedContentContainer(this);
1995 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1996 true);
[email protected]55126132010-08-19 14:53:281997 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1998 std::string());
[email protected]8cc8d492010-02-02 10:40:491999 }
[email protected]b9681312008-11-07 00:08:262000}
[email protected]616ed5a2008-11-21 22:27:242001
[email protected]616ed5a2008-11-21 22:27:242002void TabContents::ExpireInfoBars(
2003 const NavigationController::LoadCommittedDetails& details) {
2004 // Only hide InfoBars when the user has done something that makes the main
2005 // frame load. We don't want various automatic or subframe navigations making
2006 // it disappear.
2007 if (!details.is_user_initiated_main_frame_load())
2008 return;
2009
[email protected]f86a07022008-11-25 01:06:052010 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:242011 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]f86a07022008-11-25 01:06:052012 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:242013 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:242014 }
2015}
[email protected]fdd61c62009-04-22 19:22:572016
[email protected]96d185d2009-04-24 03:28:542017DOMUI* TabContents::GetDOMUIForCurrentState() {
2018 // When there is a pending navigation entry, we want to use the pending DOMUI
2019 // that goes along with it to control the basic flags. For example, we want to
2020 // show the pending URL in the URL bar, so we want the display_url flag to
2021 // be from the pending entry.
2022 //
2023 // The confusion comes because there are multiple possibilities for the
2024 // initial load in a tab as a side effect of the way the RenderViewHostManager
2025 // works.
2026 //
2027 // - For the very first tab the load looks "normal". The new tab DOM UI is
2028 // the pending one, and we want it to apply here.
2029 //
2030 // - For subsequent new tabs, they'll get a new SiteInstance which will then
2031 // get switched to the one previously associated with the new tab pages.
2032 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
2033 // have a committed DOM UI in this case.
2034 //
2035 // This condition handles all of these cases:
2036 //
2037 // - First load in first tab: no committed nav entry + pending nav entry +
2038 // pending dom ui:
2039 // -> Use pending DOM UI if any.
2040 //
2041 // - First load in second tab: no committed nav entry + pending nav entry +
2042 // no pending DOM UI:
2043 // -> Use the committed DOM UI if any.
2044 //
2045 // - Second navigation in any tab: committed nav entry + pending nav entry:
2046 // -> Use pending DOM UI if any.
2047 //
2048 // - Normal state with no load: committed nav entry + no pending nav entry:
2049 // -> Use committed DOM UI.
2050 if (controller_.pending_entry() &&
2051 (controller_.GetLastCommittedEntry() ||
2052 render_manager_.pending_dom_ui()))
2053 return render_manager_.pending_dom_ui();
2054 return render_manager_.dom_ui();
2055}
[email protected]420ae012009-04-24 05:16:322056
2057void TabContents::DidNavigateMainFramePostCommit(
2058 const NavigationController::LoadCommittedDetails& details,
2059 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:382060 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
2061 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:442062 // that opened the window, as long as both renderers have the same
2063 // privileges.
[email protected]80a8fad2011-01-29 04:02:382064 if (opener_web_ui_type_ ==
2065 WebUIFactory::GetWebUIType(profile(), GetURL())) {
2066 DOMUI* dom_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
[email protected]c2e74fe82009-09-03 17:57:442067 // dom_ui might be NULL if the URL refers to a non-existent extension.
2068 if (dom_ui) {
2069 render_manager_.SetDOMUIPostCommit(dom_ui);
2070 dom_ui->RenderViewCreated(render_view_host());
2071 }
2072 }
[email protected]80a8fad2011-01-29 04:02:382073 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:442074 }
2075
[email protected]420ae012009-04-24 05:16:322076 if (details.is_user_initiated_main_frame_load()) {
2077 // Clear the status bubble. This is a workaround for a bug where WebKit
2078 // doesn't let us know that the cursor left an element during a
2079 // transition (this is also why the mouse cursor remains as a hand after
2080 // clicking on a link); see bugs 1184641 and 980803. We don't want to
2081 // clear the bubble when a user navigates to a named anchor in the same
2082 // page.
2083 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:322084 }
2085
2086 // The keyword generator uses the navigation entries, so must be called after
2087 // the commit.
2088 GenerateKeywordIfNecessary(params);
2089
2090 // Allow the new page to set the title again.
2091 received_page_title_ = false;
2092
2093 // Get the favicon, either from history or request it from the net.
2094 fav_icon_helper_.FetchFavIcon(details.entry->url());
2095
[email protected]0de80162010-02-03 04:52:352096 // Clear all page actions, blocked content notifications and browser actions
2097 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:142098 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:002099 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:082100 if (service) {
2101 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:572102 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:082103 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:522104 if (browser_action) {
2105 browser_action->ClearAllValuesForTab(controller().session_id().id());
2106 NotificationService::current()->Notify(
2107 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:572108 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:522109 NotificationService::NoDetails());
2110 }
[email protected]92c6f9b92009-10-24 04:35:082111
[email protected]5d246db22009-10-27 06:17:572112 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:522113 service->extensions()->at(i)->page_action();
2114 if (page_action) {
2115 page_action->ClearAllValuesForTab(controller().session_id().id());
2116 PageActionStateChanged();
2117 }
[email protected]92c6f9b92009-10-24 04:35:082118 }
[email protected]aece2c7f2009-08-27 20:43:172119 }
[email protected]0de80162010-02-03 04:52:352120
2121 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:402122 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:342123 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:402124 blocked_contents_->Destroy();
2125 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:352126 }
2127
2128 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:412129 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:552130 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:472131
2132 // Once the main frame is navigated, we're no longer considered to have
2133 // displayed insecure content.
2134 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:172135 }
[email protected]ce5c4502009-05-06 16:46:112136
[email protected]8cc8d492010-02-02 10:40:492137 // Close constrained windows if necessary.
2138 if (!net::RegistryControlledDomainService::SameDomainOrHost(
2139 details.previous_url, details.entry->url()))
2140 CloseConstrainedWindows();
2141
[email protected]420ae012009-04-24 05:16:322142 // Update the starred state.
2143 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:532144
[email protected]3c9e1872010-11-18 16:17:492145 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172146 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:492147 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:322148}
2149
2150void TabContents::DidNavigateAnyFramePostCommit(
2151 RenderViewHost* render_view_host,
2152 const NavigationController::LoadCommittedDetails& details,
2153 const ViewHostMsg_FrameNavigate_Params& params) {
2154 // If we navigate, start showing messages again. This does nothing to prevent
2155 // a malicious script from spamming messages, since the script could just
2156 // reload the page to stop blocking.
2157 suppress_javascript_messages_ = false;
2158
[email protected]3c9e1872010-11-18 16:17:492159 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172160 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:492161 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:552162
2163 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:582164 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:322165}
2166
[email protected]8cc8d492010-02-02 10:40:492167void TabContents::CloseConstrainedWindows() {
2168 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:322169 // We use indices instead of iterators in case CloseWindow does something
2170 // that may invalidate an iterator.
[email protected]61d68ef12011-01-13 14:02:562171 for (size_t i = 0; i < child_windows_.size(); ++i) {
2172 ConstrainedWindow* window = child_windows_[child_windows_.size() - 1 - i];
[email protected]fa1cf0b82010-01-15 21:49:442173 if (window) {
[email protected]420ae012009-04-24 05:16:322174 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:442175 BlockTabContent(false);
2176 }
[email protected]420ae012009-04-24 05:16:322177 }
2178}
2179
2180void TabContents::UpdateStarredStateForCurrentURL() {
2181 BookmarkModel* model = profile()->GetBookmarkModel();
2182 const bool old_state = is_starred_;
2183 is_starred_ = (model && model->IsBookmarked(GetURL()));
2184
2185 if (is_starred_ != old_state && delegate())
2186 delegate()->URLStarredChanged(this, is_starred_);
2187}
2188
2189void TabContents::UpdateAlternateErrorPageURL() {
2190 GURL url = GetAlternateErrorPageURL();
2191 render_view_host()->SetAlternateErrorPageURL(url);
2192}
2193
2194void TabContents::UpdateWebPreferences() {
2195 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
2196}
2197
[email protected]d0b8d092010-10-25 04:05:172198void TabContents::UpdateZoomLevel() {
2199 render_view_host()->SetZoomLevel(GetZoomLevel());
2200}
2201
[email protected]420ae012009-04-24 05:16:322202void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
2203 RenderViewHost* rvh) {
2204 // If we are creating a RVH for a restored controller, then we might
2205 // have more page IDs than the SiteInstance's current max page ID. We must
2206 // make sure that the max page ID is larger than any restored page ID.
2207 // Note that it is ok for conflicting page IDs to exist in another tab
2208 // (i.e., NavigationController), but if any page ID is larger than the max,
2209 // the back/forward list will get confused.
2210 int max_restored_page_id = controller_.max_restored_page_id();
2211 if (max_restored_page_id > 0) {
2212 int curr_max_page_id = site_instance->max_page_id();
2213 if (max_restored_page_id > curr_max_page_id) {
2214 // Need to update the site instance immediately.
2215 site_instance->UpdateMaxPageID(max_restored_page_id);
2216
2217 // Also tell the renderer to update its internal representation. We
2218 // need to reserve enough IDs to make all restored page IDs less than
2219 // the max.
2220 if (curr_max_page_id < 0)
2221 curr_max_page_id = 0;
2222 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
2223 }
2224 }
2225}
2226
[email protected]ec0b6c42010-08-26 03:16:582227scoped_refptr<history::HistoryAddPageArgs>
2228TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:542229 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:472230 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:322231 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:582232 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2233 new history::HistoryAddPageArgs(
2234 params.url, base::Time::Now(), this, params.page_id, params.referrer,
2235 params.redirects, params.transition, history::SOURCE_BROWSED,
2236 details.did_replace_entry));
2237 if (PageTransition::IsMainFrame(params.transition) &&
2238 virtual_url != params.url) {
2239 // Hack on the "virtual" URL so that it will appear in history. For some
2240 // types of URLs, we will display a magic URL that is different from where
2241 // the page is actually navigated. We want the user to see in history what
2242 // they saw in the URL bar, so we add the virtual URL as a redirect. This
2243 // only applies to the main frame, as the virtual URL doesn't apply to
2244 // sub-frames.
2245 add_page_args->url = virtual_url;
2246 if (!add_page_args->redirects.empty())
2247 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:322248 }
[email protected]ec0b6c42010-08-26 03:16:582249 return add_page_args;
[email protected]420ae012009-04-24 05:16:322250}
2251
2252bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
2253 const std::wstring& title) {
2254 // For file URLs without a title, use the pathname instead. In the case of a
2255 // synthesized title, we don't want the update to count toward the "one set
2256 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:252257 string16 final_title;
[email protected]420ae012009-04-24 05:16:322258 bool explicit_set;
2259 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:252260 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:322261 explicit_set = false; // Don't count synthetic titles toward the set limit.
2262 } else {
[email protected]e53668962010-06-23 15:35:252263 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:322264 explicit_set = true;
2265 }
2266
[email protected]e53668962010-06-23 15:35:252267 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:322268 return false; // Nothing changed, don't bother.
2269
[email protected]e53668962010-06-23 15:35:252270 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:322271
[email protected]ec0b6c42010-08-26 03:16:582272 if (!received_page_title_) {
2273 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:322274 received_page_title_ = explicit_set;
2275 }
2276
2277 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:252278 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:322279
[email protected]cbc0e1b2010-04-12 18:33:042280 NotificationService::current()->Notify(
2281 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
2282 Source<TabContents>(this),
2283 NotificationService::NoDetails());
2284
[email protected]420ae012009-04-24 05:16:322285 return true;
2286}
2287
2288void TabContents::NotifySwapped() {
2289 // After sending out a swap notification, we need to send a disconnect
2290 // notification so that clients that pick up a pointer to |this| can NULL the
2291 // pointer. See Bug 1230284.
2292 notify_disconnection_ = true;
2293 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:342294 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:222295 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:322296 NotificationService::NoDetails());
2297}
2298
2299void TabContents::NotifyConnected() {
2300 notify_disconnection_ = true;
2301 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:342302 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:222303 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:322304 NotificationService::NoDetails());
2305}
2306
2307void TabContents::NotifyDisconnected() {
2308 if (!notify_disconnection_)
2309 return;
2310
2311 notify_disconnection_ = false;
2312 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:342313 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:222314 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:322315 NotificationService::NoDetails());
2316}
2317
2318void TabContents::GenerateKeywordIfNecessary(
2319 const ViewHostMsg_FrameNavigate_Params& params) {
2320 if (!params.searchable_form_url.is_valid())
2321 return;
2322
2323 if (profile()->IsOffTheRecord())
2324 return;
2325
2326 int last_index = controller_.last_committed_entry_index();
2327 // When there was no previous page, the last index will be 0. This is
2328 // normally due to a form submit that opened in a new tab.
2329 // TODO(brettw) bug 916126: we should support keywords when form submits
2330 // happen in new tabs.
2331 if (last_index <= 0)
2332 return;
2333 const NavigationEntry* previous_entry =
2334 controller_.GetEntryAtIndex(last_index - 1);
2335 if (IsFormSubmit(previous_entry)) {
2336 // Only generate a keyword if the previous page wasn't itself a form
2337 // submit.
2338 return;
2339 }
2340
2341 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
2342 previous_entry->user_typed_url() : previous_entry->url();
[email protected]400b133f2011-01-19 18:32:302343 string16 keyword =
[email protected]420ae012009-04-24 05:16:322344 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
2345 if (keyword.empty())
2346 return;
2347
2348 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2349 if (!url_model)
2350 return;
2351
2352 if (!url_model->loaded()) {
2353 url_model->Load();
2354 return;
2355 }
2356
2357 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:192358 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:322359 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
2360 return;
2361
2362 if (current_url) {
2363 if (current_url->originating_url().is_valid()) {
2364 // The existing keyword was generated from an OpenSearch description
2365 // document, don't regenerate.
2366 return;
2367 }
2368 url_model->Remove(current_url);
2369 }
2370 TemplateURL* new_url = new TemplateURL();
2371 new_url->set_keyword(keyword);
2372 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:192373 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:322374 new_url->add_input_encoding(params.searchable_form_encoding);
2375 DCHECK(controller_.GetLastCommittedEntry());
2376 const GURL& favicon_url =
2377 controller_.GetLastCommittedEntry()->favicon().url();
2378 if (favicon_url.is_valid()) {
2379 new_url->SetFavIconURL(favicon_url);
2380 } else {
2381 // The favicon url isn't valid. This means there really isn't a favicon,
2382 // or the favicon url wasn't obtained before the load started. This assumes
2383 // the later.
2384 // TODO(sky): Need a way to set the favicon that doesn't involve generating
2385 // its url.
2386 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
2387 }
2388 new_url->set_safe_for_autoreplace(true);
2389 url_model->Add(new_url);
2390}
2391
[email protected]bf5c2ff392009-07-08 16:24:332392void TabContents::OnFindReply(int request_id,
2393 int number_of_matches,
2394 const gfx::Rect& selection_rect,
2395 int active_match_ordinal,
2396 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:422397 // Ignore responses for requests that have been aborted.
[email protected]bf5c2ff392009-07-08 16:24:332398 // Ignore responses for requests other than the one we have most recently
2399 // issued. That way we won't act on stale results when the user has
2400 // already typed in another query.
[email protected]7d472472011-01-22 01:30:252401 if (!find_op_aborted_ && request_id == current_find_request_id_) {
2402 if (number_of_matches == -1)
2403 number_of_matches = last_search_result_.number_of_matches();
2404 if (active_match_ordinal == -1)
2405 active_match_ordinal = last_search_result_.active_match_ordinal();
[email protected]bf5c2ff392009-07-08 16:24:332406
[email protected]7d472472011-01-22 01:30:252407 gfx::Rect selection = selection_rect;
2408 if (selection.IsEmpty())
2409 selection = last_search_result_.selection_rect();
[email protected]bf5c2ff392009-07-08 16:24:332410
[email protected]7d472472011-01-22 01:30:252411 // Notify the UI, automation and any other observers that a find result was
2412 // found.
2413 last_search_result_ = FindNotificationDetails(
2414 request_id, number_of_matches, selection, active_match_ordinal,
2415 final_update);
2416 NotificationService::current()->Notify(
2417 NotificationType::FIND_RESULT_AVAILABLE,
2418 Source<TabContents>(this),
2419 Details<FindNotificationDetails>(&last_search_result_));
2420 }
[email protected]bf5c2ff392009-07-08 16:24:332421
[email protected]7d472472011-01-22 01:30:252422 // Send a notification to the renderer that we are ready to receive more
2423 // results from the scoping effort of the Find operation. The FindInPage
2424 // scoping is asynchronous and periodically sends results back up to the
2425 // browser using IPC. In an effort to not spam the browser we have the
2426 // browser send an ACK for each FindReply message and have the renderer
2427 // queue up the latest status message while waiting for this ACK.
2428 render_view_host()->Send(new ViewMsg_FindReplyACK(
2429 render_view_host()->routing_id()));
[email protected]bf5c2ff392009-07-08 16:24:332430}
2431
[email protected]7d472472011-01-22 01:30:252432void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542433 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2434 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2435 if (!entry)
2436 return;
2437 // Note that we don't call NavigationController::GotToOffset() as we don't
2438 // want to create a pending navigation entry (it might end up lingering
2439 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522440 entry->set_transition_type(entry->transition_type() |
2441 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542442 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2443 }
[email protected]bf5c2ff392009-07-08 16:24:332444}
2445
[email protected]bf5c2ff392009-07-08 16:24:332446void TabContents::OnMissingPluginStatus(int status) {
2447#if defined(OS_WIN)
2448// TODO(PORT): pull in when plug-ins work
2449 GetPluginInstaller()->OnMissingPluginStatus(status);
2450#endif
2451}
2452
2453void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332454 DCHECK(!plugin_path.value().empty());
2455
2456 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]191eb3f72010-12-21 06:27:502457 webkit::npapi::WebPluginInfo plugin_info;
2458 if (webkit::npapi::PluginList::Singleton()->GetPluginInfoByPath(
[email protected]45446a52010-11-04 17:41:002459 plugin_path, &plugin_info) &&
2460 !plugin_info.name.empty()) {
2461 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372462#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002463 // Many plugins on the Mac have .plugin in the actual name, which looks
2464 // terrible, so look for that and strip it off if present.
2465 const std::wstring plugin_extension(L".plugin");
2466 if (EndsWith(plugin_name, plugin_extension, true))
2467 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372468#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332469 }
[email protected]2ae8a922010-06-28 20:27:532470 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2471 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]f4f50ef2011-01-21 19:01:192472 AddInfoBar(new SimpleAlertInfoBarDelegate(this, crash_icon,
2473 l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2474 WideToUTF16Hack(plugin_name)), true));
[email protected]bf5c2ff392009-07-08 16:24:332475}
2476
[email protected]38789d82010-11-17 06:03:442477void TabContents::OnDidGetApplicationInfo(int32 page_id,
2478 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512479 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332480
[email protected]ed5431872009-11-17 08:39:512481 if (delegate())
2482 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332483}
2484
[email protected]bb461532010-11-26 21:50:232485void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2486 if (delegate())
2487 delegate()->OnInstallApplication(this, info);
2488}
2489
[email protected]3c2826852010-12-16 19:09:142490void TabContents::OnBlockedOutdatedPlugin(const string16& name,
2491 const GURL& update_url) {
[email protected]d12dcdd62011-01-27 06:53:252492 if (!update_url.is_empty())
2493 new OutdatedPluginInfoBar(this, name, update_url);
2494 else
2495 new BlockedPluginInfoBar(this, name);
[email protected]851b1eb2010-08-09 13:32:292496}
2497
[email protected]a2cf65eb2010-01-18 08:20:382498void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:382499 int32 page_id,
[email protected]e5106202010-06-11 21:12:362500 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102501 const std::string& language,
2502 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382503 // Don't index any https pages. People generally don't want their bank
2504 // accounts, etc. indexed on their computer, especially since some of these
2505 // things are not marked cachable.
2506 // TODO(brettw) we may want to consider more elaborate heuristics such as
2507 // the cachability of the page. We may also want to consider subframes (this
2508 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272509 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2510 // content indexing for chromeos in some future releases.
2511#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382512 if (!url.SchemeIsSecure()) {
2513 Profile* p = profile();
2514 if (p && !p->IsOffTheRecord()) {
2515 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2516 if (hs)
2517 hs->SetPageContents(url, contents);
2518 }
2519 }
[email protected]ccd40a52010-05-11 16:15:272520#endif
[email protected]a8a81292010-01-21 00:32:452521
[email protected]1c57b7b2010-07-12 17:38:102522 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452523
2524 std::string lang = language;
2525 NotificationService::current()->Notify(
2526 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152527 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452528 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:522529
2530 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
2531 if (CommandLine::ForCurrentProcess()->HasSwitch(
2532 switches::kEnableInBrowserThumbnailing)) {
2533 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
2534 }
[email protected]a2cf65eb2010-01-18 08:20:382535}
2536
[email protected]7e0831b2010-02-01 08:45:152537void TabContents::OnPageTranslated(int32 page_id,
2538 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162539 const std::string& translated_lang,
2540 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552541 language_state_.set_current_language(translated_lang);
2542 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162543 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152544 NotificationService::current()->Notify(
2545 NotificationType::PAGE_TRANSLATED,
2546 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162547 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152548}
2549
[email protected]ce833282010-11-04 15:48:392550void TabContents::OnSetSuggestions(
2551 int32 page_id,
2552 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262553 if (delegate())
[email protected]ce833282010-11-04 15:48:392554 delegate()->OnSetSuggestions(page_id, suggestions);
2555}
2556
2557void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2558 if (delegate())
2559 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262560}
2561
[email protected]34f128d2011-01-25 19:07:442562void TabContents::OnRunFileChooser(
2563 const ViewHostMsg_RunFileChooser_Params& params) {
2564 if (file_select_helper_.get() == NULL)
2565 file_select_helper_.reset(new FileSelectHelper(profile()));
2566 file_select_helper_->RunFileChooser(render_view_host(), params);
2567}
2568
2569
[email protected]dcd5b332010-08-11 08:55:182570void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562571 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242572 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562573}
2574
[email protected]8d3347f2009-07-09 22:00:212575RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322576 return view_.get();
2577}
2578
[email protected]8d3347f2009-07-09 22:00:212579RenderViewHostDelegate::RendererManagement*
2580TabContents::GetRendererManagementDelegate() {
2581 return &render_manager_;
2582}
2583
[email protected]46ba9082010-06-22 10:00:582584RenderViewHostDelegate::ContentSettings*
2585TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552586 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582587}
2588
[email protected]1f18184a2010-07-21 19:34:492589RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2590 return GetSSLHelper();
2591}
2592
[email protected]fd571bb2010-03-19 01:23:542593AutomationResourceRoutingDelegate*
2594TabContents::GetAutomationResourceRoutingDelegate() {
2595 return delegate();
2596}
2597
[email protected]ced90ae12010-02-20 02:06:162598RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2599 return bookmark_drag_;
2600}
2601
2602void TabContents::SetBookmarkDragDelegate(
2603 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2604 bookmark_drag_ = bookmark_drag;
2605}
2606
[email protected]9fb83e82010-07-02 18:24:552607TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2608 return content_settings_delegate_.get();
2609}
2610
[email protected]93623c5d2009-12-10 21:40:322611RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462612 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512613}
2614
[email protected]57c6a652009-05-04 07:58:342615TabContents* TabContents::GetAsTabContents() {
2616 return this;
2617}
2618
[email protected]7b291f92009-08-14 05:43:532619ViewType::Type TabContents::GetRenderViewType() const {
2620 return ViewType::TAB_CONTENTS;
2621}
2622
2623int TabContents::GetBrowserWindowID() const {
2624 return controller().window_id().id();
2625}
2626
[email protected]420ae012009-04-24 05:16:322627void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062628 NotificationService::current()->Notify(
2629 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2630 Source<TabContents>(this),
2631 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322632 NavigationEntry* entry = controller_.GetActiveEntry();
2633 if (!entry)
2634 return;
2635
2636 // When we're creating views, we're still doing initial setup, so we always
2637 // use the pending DOM UI rather than any possibly existing committed one.
2638 if (render_manager_.pending_dom_ui()) {
2639 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2640 }
2641
2642 if (entry->IsViewSourceMode()) {
2643 // Put the renderer in view source mode.
2644 render_view_host->Send(
2645 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2646 }
[email protected]0666aef2009-05-13 19:48:082647
2648 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322649}
2650
2651void TabContents::RenderViewReady(RenderViewHost* rvh) {
2652 if (rvh != render_view_host()) {
2653 // Don't notify the world, since this came from a renderer in the
2654 // background.
2655 return;
2656 }
2657
2658 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302659 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232660 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302661
2662 // Restore the focus to the tab (otherwise the focus will be on the top
2663 // window).
[email protected]484ae5912010-09-29 19:16:142664 if (was_crashed && !FocusLocationBarByDefault() &&
2665 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302666 Focus();
[email protected]484ae5912010-09-29 19:16:142667 }
[email protected]420ae012009-04-24 05:16:322668}
2669
[email protected]443b80e2010-12-14 00:42:232670void TabContents::RenderViewGone(RenderViewHost* rvh,
2671 base::TerminationStatus status,
2672 int error_code) {
[email protected]420ae012009-04-24 05:16:322673 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092674 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322675 return;
2676 if (rvh != render_view_host()) {
2677 // The pending page's RenderViewHost is gone.
2678 return;
2679 }
2680
2681 SetIsLoading(false, NULL);
2682 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232683 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322684
[email protected]ff9efc62010-02-18 22:10:542685 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212686 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542687 RemoveInfoBar(GetInfoBarDelegateAt(i));
2688
[email protected]8e537302009-06-10 21:19:582689 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552690 // Only do this if we're not in browser shutdown, so that TabContents
2691 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2692 // visible do not flash a sad tab page.
2693 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162694 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322695
2696 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002697 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322698}
2699
[email protected]2e4633c2009-07-09 16:58:062700void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2701 NotificationService::current()->Notify(
2702 NotificationType::RENDER_VIEW_HOST_DELETED,
2703 Source<TabContents>(this),
2704 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482705 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062706}
2707
[email protected]420ae012009-04-24 05:16:322708void TabContents::DidNavigate(RenderViewHost* rvh,
2709 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372710 int extra_invalidate_flags = 0;
2711
2712 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]e7d50892011-01-19 21:47:382713 if (MaybeUsePreloadedPage(params.url)) {
2714 return;
[email protected]33f74972010-12-08 16:40:362715 }
2716
[email protected]20ede072009-10-06 00:28:352717 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372718
[email protected]420ae012009-04-24 05:16:322719 render_manager_.DidNavigateMainFrame(rvh);
2720
[email protected]20ede072009-10-06 00:28:352721 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372722 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372723 }
2724
[email protected]420ae012009-04-24 05:16:322725 // Update the site of the SiteInstance if it doesn't have one yet.
2726 if (!GetSiteInstance()->has_site())
2727 GetSiteInstance()->SetSite(params.url);
2728
2729 // Need to update MIME type here because it's referred to in
2730 // UpdateNavigationCommands() called by RendererDidNavigate() to
2731 // determine whether or not to enable the encoding menu.
2732 // It's updated only for the main frame. For a subframe,
2733 // RenderView::UpdateURL does not set params.contents_mime_type.
2734 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2735 // TODO(jungshik): Add a test for the encoding menu to avoid
2736 // regressing it again.
2737 if (PageTransition::IsMainFrame(params.transition))
2738 contents_mime_type_ = params.contents_mime_type;
2739
2740 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372741 bool did_navigate = controller_.RendererDidNavigate(
2742 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392743
[email protected]a9c0bfe2010-09-17 08:35:222744 // Send notification about committed provisional loads. This notification is
2745 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2746 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2747 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072748 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2749 // that is not recorded in the navigation history. For the purpose of
2750 // tracking navigation events, we treat this event as a sub frame navigation
2751 // event.
2752 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2753 ProvisionalLoadDetails load_details(
2754 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412755 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222756 load_details.set_transition_type(params.transition);
2757 // Whether or not a page transition was triggered by going backward or
2758 // forward in the history is only stored in the navigation controller's
2759 // entry list.
2760 if (did_navigate &&
2761 (controller_.GetActiveEntry()->transition_type() &
2762 PageTransition::FORWARD_BACK)) {
2763 load_details.set_transition_type(
2764 params.transition | PageTransition::FORWARD_BACK);
2765 }
2766 NotificationService::current()->Notify(
2767 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2768 Source<NavigationController>(&controller_),
2769 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222770 }
2771
[email protected]3e90d4a2009-07-03 17:38:392772 // Update history. Note that this needs to happen after the entry is complete,
2773 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582774 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392775 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582776 // URLs, we use a data: URL as the real value. We actually want to save the
2777 // about: URL to the history db and keep the data: URL hidden. This is what
2778 // the TabContents' URL getter does.
2779 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2780 CreateHistoryAddPageArgs(GetURL(), details, params));
2781 if (!delegate() ||
2782 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2783 details.type)) {
2784 UpdateHistoryForNavigation(add_page_args);
2785 }
[email protected]3e90d4a2009-07-03 17:38:392786 }
2787
[email protected]76543b92009-08-31 17:27:452788 if (!did_navigate)
2789 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322790
2791 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2792 // for the appropriate notification (best) or you can add it to
2793 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2794 // necessary, please).
2795
2796 // Run post-commit tasks.
2797 if (details.is_main_frame)
2798 DidNavigateMainFramePostCommit(details, params);
2799 DidNavigateAnyFramePostCommit(rvh, details, params);
2800}
2801
2802void TabContents::UpdateState(RenderViewHost* rvh,
2803 int32 page_id,
2804 const std::string& state) {
2805 DCHECK(rvh == render_view_host());
2806
2807 // We must be prepared to handle state updates for any page, these occur
2808 // when the user is scrolling and entering form data, as well as when we're
2809 // leaving a page, in which case our state may have already been moved to
2810 // the next page. The navigation controller will look up the appropriate
2811 // NavigationEntry and update it when it is notified via the delegate.
2812
2813 int entry_index = controller_.GetEntryIndexWithPageID(
2814 GetSiteInstance(), page_id);
2815 if (entry_index < 0)
2816 return;
2817 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2818
2819 if (state == entry->content_state())
2820 return; // Nothing to update.
2821 entry->set_content_state(state);
2822 controller_.NotifyEntryChanged(entry, entry_index);
2823}
2824
2825void TabContents::UpdateTitle(RenderViewHost* rvh,
2826 int32 page_id, const std::wstring& title) {
2827 // If we have a title, that's a pretty good indication that we've started
2828 // getting useful data.
2829 SetNotWaitingForResponse();
2830
2831 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482832 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582833 page_id);
[email protected]420ae012009-04-24 05:16:322834 if (!entry || !UpdateTitleForEntry(entry, title))
2835 return;
2836
2837 // Broadcast notifications when the UI should be updated.
2838 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032839 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322840}
2841
[email protected]420ae012009-04-24 05:16:322842void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402843 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322844 set_encoding(encoding);
2845}
2846
2847void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2848 if (delegate())
2849 delegate()->UpdateTargetURL(this, url);
2850}
2851
2852void TabContents::UpdateThumbnail(const GURL& url,
2853 const SkBitmap& bitmap,
2854 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442855 if (profile()->IsOffTheRecord())
2856 return;
2857
[email protected]420ae012009-04-24 05:16:322858 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072859 history::TopSites* ts = profile()->GetTopSites();
2860 if (ts)
2861 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322862}
2863
[email protected]c4e98902010-06-01 10:20:142864void TabContents::UpdateInspectorSetting(const std::string& key,
2865 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052866 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082867}
2868
[email protected]45aafc92010-06-07 14:18:532869void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052870 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532871}
2872
[email protected]420ae012009-04-24 05:16:322873void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292874 // The UI may be in an event-tracking loop, such as between the
2875 // mouse-down and mouse-up in text selection or a button click.
2876 // Defer the close until after tracking is complete, so that we
2877 // don't free objects out from under the UI.
2878 // TODO(shess): This could probably be integrated with the
2879 // IsDoingDrag() test below. Punting for now because I need more
2880 // research to understand how this impacts platforms other than Mac.
2881 // TODO(shess): This could get more fine-grained. For instance,
2882 // closing a tab in another window while selecting text in the
2883 // current window's Omnibox should be just fine.
2884 if (view()->IsEventTracking()) {
2885 view()->CloseTabAfterEventTracking();
2886 return;
2887 }
2888
[email protected]24a4d1062009-07-10 23:10:422889 // If we close the tab while we're in the middle of a drag, we'll crash.
2890 // Instead, cancel the drag and close it as soon as the drag ends.
2891 if (view()->IsDoingDrag()) {
2892 view()->CancelDragAndCloseTab();
2893 return;
2894 }
2895
[email protected]420ae012009-04-24 05:16:322896 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2897 if (delegate() && rvh == render_view_host())
2898 delegate()->CloseContents(this);
2899}
2900
2901void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2902 if (delegate() && delegate()->IsPopup(this))
2903 delegate()->MoveContents(this, new_bounds);
2904}
2905
[email protected]7ab1e7d62009-10-14 23:32:012906void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322907 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492908
[email protected]de4761b2010-12-07 21:05:212909 if (delegate()) {
2910 bool is_print_preview_tab =
2911 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2912 if (content_restrictions_ || is_print_preview_tab) {
2913 content_restrictions_= is_print_preview_tab ?
2914 CONTENT_RESTRICTION_PRINT : 0;
2915 delegate()->ContentRestrictionsChanged(this);
2916 }
[email protected]9e823662010-10-13 23:36:002917 }
[email protected]3c9e1872010-11-18 16:17:492918
2919 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172920 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322921}
2922
[email protected]7ab1e7d62009-10-14 23:32:012923void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322924 scoped_ptr<LoadNotificationDetails> details;
2925
2926 NavigationEntry* entry = controller_.GetActiveEntry();
2927 // An entry may not exist for a stop when loading an initial blank page or
2928 // if an iframe injected by script into a blank page finishes loading.
2929 if (entry) {
[email protected]420ae012009-04-24 05:16:322930 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2931
2932 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542933 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322934 entry->transition_type(),
2935 elapsed,
2936 &controller_,
2937 controller_.GetCurrentEntryIndex()));
2938 }
2939
[email protected]420ae012009-04-24 05:16:322940 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492941
2942 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172943 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322944}
2945
[email protected]1a3c3cb2010-12-16 21:03:402946void TabContents::DidChangeLoadProgress(double progress) {
2947 if (delegate())
2948 delegate()->LoadProgressChanged(progress);
2949}
2950
[email protected]25497492010-09-11 15:15:082951void TabContents::DocumentOnLoadCompletedInMainFrame(
2952 RenderViewHost* render_view_host,
2953 int32 page_id) {
2954 NotificationService::current()->Notify(
2955 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2956 Source<TabContents>(this),
2957 Details<int>(&page_id));
2958}
2959
[email protected]420ae012009-04-24 05:16:322960void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2961 WindowOpenDisposition disposition) {
2962 if (render_manager_.dom_ui()) {
2963 // When we're a DOM UI, it will provide a page transition type for us (this
2964 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2965 // generated suggestions).
2966 //
2967 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162968 // want web sites to see a referrer of "chrome://blah" (and some
2969 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322970 // send to the site), so we send no referrer.
2971 OpenURL(url, GURL(), disposition,
2972 render_manager_.dom_ui()->link_transition_type());
2973 } else {
2974 OpenURL(url, referrer, disposition, PageTransition::LINK);
2975 }
2976}
2977
[email protected]1ee614862009-07-06 20:29:182978void TabContents::DomOperationResponse(const std::string& json_string,
2979 int automation_id) {
2980}
2981
[email protected]8b8e7c92010-08-19 18:05:562982void TabContents::ProcessDOMUIMessage(
2983 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322984 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442985 // This can happen if someone uses window.open() to open an extension URL
2986 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562987 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322988 return;
2989 }
[email protected]8b8e7c92010-08-19 18:05:562990 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322991}
2992
2993void TabContents::ProcessExternalHostMessage(const std::string& message,
2994 const std::string& origin,
2995 const std::string& target) {
2996 if (delegate())
2997 delegate()->ForwardMessageToExternalHost(message, origin, target);
2998}
2999
[email protected]420ae012009-04-24 05:16:323000void TabContents::RunJavaScriptMessage(
3001 const std::wstring& message,
3002 const std::wstring& default_prompt,
3003 const GURL& frame_url,
3004 const int flags,
3005 IPC::Message* reply_msg,
3006 bool* did_suppress_message) {
3007 // Suppress javascript messages when requested and when inside a constrained
3008 // popup window (because that activates them and breaks them out of the
3009 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:553010 // Also suppress messages when showing an interstitial. The interstitial is
3011 // shown over the previous page, we don't want the hidden page dialogs to
3012 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:503013 bool suppress_this_message =
3014 suppress_javascript_messages_ ||
3015 showing_interstitial_page() ||
3016 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:323017 if (delegate())
3018 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:313019 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:323020
3021 *did_suppress_message = suppress_this_message;
3022
3023 if (!suppress_this_message) {
3024 base::TimeDelta time_since_last_message(
3025 base::TimeTicks::Now() - last_javascript_message_dismissal_);
3026 bool show_suppress_checkbox = false;
3027 // Show a checkbox offering to suppress further messages if this message is
3028 // being displayed within kJavascriptMessageExpectedDelay of the last one.
3029 if (time_since_last_message <
3030 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
3031 show_suppress_checkbox = true;
3032
[email protected]d6ad7442010-09-05 19:06:523033 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
3034 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:323035 } else {
3036 // If we are suppressing messages, just reply as is if the user immediately
3037 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:543038 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:323039 }
3040}
3041
3042void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
3043 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:293044 if (delegate())
3045 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:503046 if (delegate() && delegate()->ShouldSuppressDialogs()) {
3047 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
3048 std::wstring());
3049 return;
3050 }
[email protected]7ab1e7d62009-10-14 23:32:013051 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:223052 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:323053}
3054
3055void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
3056 const std::string& json_arguments,
3057 IPC::Message* reply_msg) {
3058 if (delegate()) {
3059 HtmlDialogUIDelegate* dialog_delegate =
3060 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:223061 reply_msg, this);
[email protected]420ae012009-04-24 05:16:323062 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
3063 }
3064}
3065
[email protected]420ae012009-04-24 05:16:323066// Checks to see if we should generate a keyword based on the OSDD, and if
3067// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:203068void TabContents::PageHasOSDD(
3069 RenderViewHost* render_view_host,
3070 int32 page_id,
3071 const GURL& url,
3072 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:123073 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:323074 DCHECK(url.is_valid());
3075 if (!IsActiveEntry(page_id))
3076 return;
[email protected]420ae012009-04-24 05:16:323077 if (!profile()->GetTemplateURLFetcher())
3078 return;
[email protected]420ae012009-04-24 05:16:323079 if (profile()->IsOffTheRecord())
3080 return;
3081
[email protected]2de7e002010-10-11 22:58:203082 TemplateURLFetcher::ProviderType provider_type;
3083 switch (msg_provider_type.type) {
3084 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
3085 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
3086 break;
3087
3088 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
3089 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
3090 break;
3091
3092 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
3093 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
3094 break;
3095
3096 default:
3097 NOTREACHED();
3098 return;
3099 }
3100
[email protected]420ae012009-04-24 05:16:323101 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
3102 DCHECK(entry);
3103
3104 const NavigationEntry* base_entry = entry;
3105 if (IsFormSubmit(base_entry)) {
3106 // If the current page is a form submit, find the last page that was not
3107 // a form submit and use its url to generate the keyword from.
3108 int index = controller_.last_committed_entry_index() - 1;
3109 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
3110 index--;
3111 if (index >= 0)
3112 base_entry = controller_.GetEntryAtIndex(index);
3113 else
3114 base_entry = NULL;
3115 }
3116
3117 // We want to use the user typed URL if available since that represents what
3118 // the user typed to get here, and fall back on the regular URL if not.
3119 if (!base_entry)
3120 return;
3121 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
3122 base_entry->user_typed_url() : base_entry->url();
3123 if (!keyword_url.is_valid())
3124 return;
[email protected]2de7e002010-10-11 22:58:203125
[email protected]400b133f2011-01-19 18:32:303126 string16 keyword = TemplateURLModel::GenerateKeyword(
[email protected]0b5b85c2010-10-11 23:00:123127 keyword_url,
3128 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:533129
[email protected]0b5b85c2010-10-11 23:00:123130 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:323131 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:323132 profile()->GetTemplateURLFetcher()->ScheduleDownload(
3133 keyword,
3134 url,
3135 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:123136 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:203137 provider_type);
[email protected]420ae012009-04-24 05:16:323138}
3139
[email protected]420ae012009-04-24 05:16:323140GURL TabContents::GetAlternateErrorPageURL() const {
3141 GURL url;
3142 // Disable alternate error pages when in OffTheRecord/Incognito mode.
3143 if (profile()->IsOffTheRecord())
3144 return url;
3145
3146 PrefService* prefs = profile()->GetPrefs();
3147 DCHECK(prefs);
3148 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:153149 url = google_util::AppendGoogleLocaleParam(
3150 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:323151 url = google_util::AppendGoogleTLDParam(url);
3152 }
3153 return url;
3154}
3155
3156WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:063157 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:553158 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:083159 WebPreferences web_prefs =
3160 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
3161
[email protected]9beff752010-09-22 19:35:433162 // Force accelerated compositing and 2d canvas off for chrome: and
3163 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:433164 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
3165 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:083166 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:433167 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:083168 }
3169
[email protected]39553442010-09-09 00:01:553170#if defined(OS_MACOSX)
3171 // Disable accelerated compositing if IOSurface's are not supported,
3172 // as is the case in 10.5.
3173 if (!IOSurfaceSupport::Initialize())
3174 web_prefs.accelerated_compositing_enabled = false;
3175#endif
3176
[email protected]447021c2010-09-08 21:29:083177 return web_prefs;
[email protected]420ae012009-04-24 05:16:323178}
3179
[email protected]7d472472011-01-22 01:30:253180void TabContents::OnUserGesture() {
3181 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
3182 DownloadRequestLimiter* limiter =
3183 g_browser_process->download_request_limiter();
3184 if (limiter)
3185 limiter->OnUserGesture(this);
3186 ExternalProtocolHandler::PermitLaunchUrl();
3187}
3188
[email protected]fa1cf0b82010-01-15 21:49:443189void TabContents::OnIgnoredUIEvent() {
3190 if (constrained_window_count()) {
3191 ConstrainedWindow* window = *constrained_window_begin();
3192 window->FocusConstrainedWindow();
3193 }
3194}
3195
[email protected]420ae012009-04-24 05:16:323196void TabContents::OnJSOutOfMemory() {
[email protected]f4f50ef2011-01-21 19:01:193197 AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL,
3198 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true));
[email protected]420ae012009-04-24 05:16:323199}
3200
[email protected]420ae012009-04-24 05:16:323201void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
3202 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:343203 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:323204 // delivered to a pending RenderViewHost. We must first run the onunload
3205 // handler of the old RenderViewHost before we can allow it to proceed.
3206 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
3207 new_request_id);
3208}
3209
[email protected]420ae012009-04-24 05:16:323210void TabContents::RendererUnresponsive(RenderViewHost* rvh,
3211 bool is_during_unload) {
3212 if (is_during_unload) {
3213 // Hang occurred while firing the beforeunload/unload handler.
3214 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:113215 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:323216
3217 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
3218 return;
3219
3220 // If the tab hangs in the beforeunload/unload handler there's really
3221 // nothing we can do to recover. Pretend the unload listeners have
3222 // all fired and close the tab. If the hang is in the beforeunload handler
3223 // then the user will not have the option of cancelling the close.
3224 Close(rvh);
3225 return;
3226 }
3227
3228 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:003229 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:323230}
3231
3232void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:003233 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:323234}
3235
3236void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:563237 net::LoadState load_state,
3238 uint64 upload_position,
3239 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:323240 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:563241 upload_position_ = upload_position;
3242 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:293243 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193244 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293245 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:423246 load_state_host_ = WideToUTF16Hack(
3247 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:323248 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3249 SetNotWaitingForResponse();
3250 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503251 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323252}
3253
[email protected]1ee614862009-07-06 20:29:183254bool TabContents::IsExternalTabContainer() const {
3255 if (!delegate())
3256 return false;
3257
3258 return delegate()->IsExternalTabContainer();
3259}
3260
[email protected]1ee614862009-07-06 20:29:183261void TabContents::DidInsertCSS() {
3262 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323263}
3264
[email protected]546ae4e02010-12-08 14:57:193265void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353266 NotificationService::current()->Notify(
3267 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:213268 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:193269 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353270}
3271
[email protected]b75b8292010-10-01 07:28:253272void TabContents::UpdateZoomLimits(int minimum_percent,
3273 int maximum_percent,
3274 bool remember) {
3275 minimum_zoom_percent_ = minimum_percent;
3276 maximum_zoom_percent_ = maximum_percent;
3277 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383278}
3279
[email protected]7d472472011-01-22 01:30:253280void TabContents::WorkerCrashed() {
3281 AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL,
3282 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true));
3283}
3284
[email protected]420ae012009-04-24 05:16:323285void TabContents::BeforeUnloadFiredFromRenderManager(
3286 bool proceed,
3287 bool* proceed_to_fire_unload) {
3288 if (delegate())
3289 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3290}
3291
[email protected]3a3d47472010-07-15 21:03:543292void TabContents::DidStartLoadingFromRenderManager(
3293 RenderViewHost* render_view_host) {
3294 DidStartLoading();
3295}
3296
3297void TabContents::RenderViewGoneFromRenderManager(
3298 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:233299 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
3300 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:543301}
3302
[email protected]420ae012009-04-24 05:16:323303void TabContents::UpdateRenderViewSizeForRenderManager() {
3304 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263305 gfx::Size size = view_->GetContainerSize();
3306 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3307 // here during container initialization and normal window size will be set
3308 // later. In case of tab duplication this resizing to 0x0 prevents setting
3309 // normal size later so just ignore it.
3310 if (!size.IsEmpty())
3311 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323312}
3313
[email protected]3a3d47472010-07-15 21:03:543314void TabContents::NotifySwappedFromRenderManager() {
3315 NotifySwapped();
3316}
3317
3318NavigationController& TabContents::GetControllerForRenderManager() {
3319 return controller();
3320}
3321
[email protected]420ae012009-04-24 05:16:323322DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:383323 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323324}
3325
3326NavigationEntry*
3327TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3328 return controller_.GetLastCommittedEntry();
3329}
3330
3331bool TabContents::CreateRenderViewForRenderManager(
3332 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323333 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523334
[email protected]674b3822010-08-04 04:02:513335 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323336 return false;
3337
3338 // Now that the RenderView has been created, we need to tell it its size.
3339 rwh_view->SetSize(view_->GetContainerSize());
3340
3341 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3342 render_view_host);
3343 return true;
3344}
3345
3346void TabContents::Observe(NotificationType type,
3347 const NotificationSource& source,
3348 const NotificationDetails& details) {
3349 switch (type.value) {
3350 case NotificationType::BOOKMARK_MODEL_LOADED:
3351 // BookmarkModel finished loading, fall through to update starred state.
3352 case NotificationType::URLS_STARRED: {
3353 // Somewhere, a URL has been starred.
3354 // Ignore notifications for profiles other than our current one.
3355 Profile* source_profile = Source<Profile>(source).ptr();
3356 if (!source_profile || !source_profile->IsSameProfile(profile()))
3357 return;
3358
3359 UpdateStarredStateForCurrentURL();
3360 break;
3361 }
3362 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513363 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323364 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3365 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3366 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533367 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3368 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323369 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173370 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3371 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323372 } else {
3373 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3374 }
3375 break;
3376 }
3377 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3378 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3379 break;
3380
3381 case NotificationType::NAV_ENTRY_COMMITTED: {
3382 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3383
3384 NavigationController::LoadCommittedDetails& committed_details =
3385 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3386 ExpireInfoBars(committed_details);
3387 break;
3388 }
3389
[email protected]d3ba77272009-09-03 00:06:093390#if defined(OS_LINUX)
3391 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543392 renderer_preferences_util::UpdateFromSystemSettings(
3393 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093394 render_view_host()->SyncRendererPrefs();
3395 break;
3396 }
3397#endif
3398
[email protected]6c32ce72010-03-08 05:18:063399 case NotificationType::USER_STYLE_SHEET_UPDATED:
3400 UpdateWebPreferences();
3401 break;
3402
[email protected]79580c62010-02-02 02:36:253403 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453404 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253405 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493406 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293407 if (entry)
[email protected]da0c8e92010-02-09 23:25:493408 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293409 if (settings_details.ptr()->update_all() ||
3410 settings_details.ptr()->pattern().Matches(entry_url)) {
3411 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233412 profile()->GetHostContentSettingsMap()->
3413 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253414 }
3415 break;
3416 }
3417
[email protected]e5adff72010-06-14 18:13:063418 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573419 break;
[email protected]a888b29e62010-04-01 13:38:573420
3421 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:573422 break;
[email protected]a888b29e62010-04-01 13:38:573423
[email protected]88152052010-10-01 04:05:183424 case NotificationType::GOOGLE_URL_UPDATED:
3425 UpdateAlternateErrorPageURL();
3426 break;
3427
[email protected]420ae012009-04-24 05:16:323428 default:
3429 NOTREACHED();
3430 }
3431}
[email protected]aacd7cc2009-09-02 14:51:103432
[email protected]9adb9692010-10-29 23:14:023433void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083434 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433435
[email protected]a888b29e62010-04-01 13:38:573436 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083437 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3438 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573439 extension,
[email protected]807871f2010-09-16 01:04:483440 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3441 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573442 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3443 Extension::EXTENSION_ICON_SMALLISH),
3444 ImageLoadingTracker::CACHE);
3445 } else {
[email protected]98aa0b52010-05-06 17:03:083446 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573447 }
3448}
3449
[email protected]9adb9692010-10-29 23:14:023450const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:003451 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:573452 if (!extensions_service)
3453 return NULL;
3454
[email protected]9adb9692010-10-29 23:14:023455 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573456 return extension ?
3457 extension : extensions_service->GetExtensionByWebExtent(url);
3458}
3459
[email protected]a888b29e62010-04-01 13:38:573460void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3461 int index) {
3462 if (image) {
[email protected]98aa0b52010-05-06 17:03:083463 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573464 NotifyNavigationStateChanged(INVALIDATE_TAB);
3465 }
3466}
3467
[email protected]beb440c2009-11-06 04:08:543468gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3469 return view_->GetTopLevelNativeWindow();
3470}
3471
3472void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3473 bool success,
3474 const std::wstring& prompt) {
3475 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3476 if (is_showing_before_unload_dialog_ && !success) {
3477 // If a beforeunload dialog is canceled, we need to stop the throbber from
3478 // spinning, since we forced it to start spinning in Navigate.
3479 DidStopLoading();
3480
3481 tab_close_start_time_ = base::TimeTicks();
3482 }
3483 is_showing_before_unload_dialog_ = false;
3484 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3485}
3486
3487void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3488 set_suppress_javascript_messages(suppress_message_boxes);
3489}
3490
[email protected]3a3d47472010-07-15 21:03:543491TabContents* TabContents::AsTabContents() {
3492 return this;
3493}
3494
3495ExtensionHost* TabContents::AsExtensionHost() {
3496 return NULL;
3497}
3498
[email protected]41fc0322009-09-04 22:23:403499void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103500 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3501}
[email protected]f45d2a72010-03-08 23:28:353502
3503void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3504 app_icon_ = app_icon;
3505 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3506}
[email protected]33f74972010-12-08 16:40:363507
3508void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
3509 render_manager_.SwapInRenderViewHost(rvh);
3510}
3511
3512void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
3513 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
3514 rwh_view->SetSize(view()->GetContainerSize());
3515}
[email protected]e7d50892011-01-19 21:47:383516
3517bool TabContents::MaybeUsePreloadedPage(const GURL& url) {
3518 PrerenderManager* pm = profile()->GetPrerenderManager();
3519 if (pm != NULL) {
[email protected]973407b2011-01-26 23:18:233520 if (pm->MaybeUsePreloadedPage(this, url))
[email protected]e7d50892011-01-19 21:47:383521 return true;
[email protected]e7d50892011-01-19 21:47:383522 }
3523 return false;
3524}