blob: 77a334757aa9af9a2848c0fe875c0f9736d694ee [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]aad51d1c2010-08-05 08:38:0927#include "chrome/browser/blocked_plugin_manager.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5429#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5530#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2931#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1032#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5433#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1434#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3235#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5436#include "chrome/browser/dom_ui/dom_ui.h"
37#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0238#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3239#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0140#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4941#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0842#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5843#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4244#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2545#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4846#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4947#include "chrome/browser/file_select_helper.h"
[email protected]e5d2f7132010-04-09 18:13:5348#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4949#include "chrome/browser/google/google_util.h"
[email protected]79580c62010-02-02 02:36:2550#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2651#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0752#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]12f74a92010-02-05 22:32:1453#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3254#include "chrome/browser/load_from_memory_cache_details.h"
55#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4456#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0557#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1058#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5759#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2460#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5761#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0262#include "chrome/browser/prefs/pref_service.h"
[email protected]12802702010-07-09 19:43:0963#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4464#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0765#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1666#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5467#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3768#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0769#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5470#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3271#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1172#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1673#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1274#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1675#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1776#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1777#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5478#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1679#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4380#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1681#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4982#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5783#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0284#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1685#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5886#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2787#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4988#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5789#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4890#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1491#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0992#include "chrome/common/extensions/url_pattern.h"
93#include "chrome/common/navigation_types.h"
94#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5695#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2996#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3297#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0298#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1899#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54100#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37101#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26102#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32103#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06104#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37105#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32106#include "net/base/mime_util.h"
107#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29108#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32109#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25110#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18111#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03112#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00113
[email protected]420ae012009-04-24 05:16:32114// Cross-Site Navigations
115//
116// If a TabContents is told to navigate to a different web site (as determined
117// by SiteInstance), it will replace its current RenderViewHost with a new
118// RenderViewHost dedicated to the new SiteInstance. This works as follows:
119//
120// - Navigate determines whether the destination is cross-site, and if so,
121// it creates a pending_render_view_host_ and moves into the PENDING
122// RendererState.
123// - The pending RVH is "suspended," so that no navigation messages are sent to
124// its renderer until the onbeforeunload JavaScript handler has a chance to
125// run in the current RVH.
126// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
127// that it has a pending cross-site request. ResourceDispatcherHost will
128// check for this when the response arrives.
129// - The current RVH runs its onbeforeunload handler. If it returns false, we
130// cancel all the pending logic and go back to NORMAL. Otherwise we allow
131// the pending RVH to send the navigation request to its renderer.
132// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
133// checks CrossSiteRequestManager to see that the RVH responsible has a
134// pending cross-site request, and then installs a CrossSiteEventHandler.
135// - When RDH receives a response, the BufferedEventHandler determines whether
136// it is a download. If so, it sends a message to the new renderer causing
137// it to cancel the request, and the download proceeds in the download
138// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34139// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32140// doesn't affect any functionality.
141// - After RDH receives a response and determines that it is safe and not a
142// download, it pauses the response to first run the old page's onunload
143// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34144// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32145// to the current RVH.
146// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
147// the ResourceDispatcherHost, who unpauses the response. Data is then sent
148// to the pending RVH.
149// - The pending renderer sends a FrameNavigate message that invokes the
150// DidNavigate method. This replaces the current RVH with the
151// pending RVH and goes back to the NORMAL RendererState.
152
153namespace {
154
155// Amount of time we wait between when a key event is received and the renderer
156// is queried for its state and pushed to the NavigationEntry.
157const int kQueryStateDelay = 5000;
158
[email protected]6ebdc9b2010-09-27 16:55:57159const int kSyncWaitDelay = 40;
160
[email protected]420ae012009-04-24 05:16:32161// If another javascript message box is displayed within
162// kJavascriptMessageExpectedDelay of a previous javascript message box being
163// dismissed, display an option to suppress future message boxes from this
164// contents.
165const int kJavascriptMessageExpectedDelay = 1000;
166
[email protected]420ae012009-04-24 05:16:32167// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51168const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32169 prefs::kAlternateErrorPagesEnabled,
170 prefs::kWebKitJavaEnabled,
171 prefs::kWebKitJavascriptEnabled,
172 prefs::kWebKitLoadsImagesAutomatically,
173 prefs::kWebKitPluginsEnabled,
174 prefs::kWebKitUsesUniversalDetector,
175 prefs::kWebKitSerifFontFamily,
176 prefs::kWebKitSansSerifFontFamily,
177 prefs::kWebKitFixedFontFamily,
178 prefs::kWebKitDefaultFontSize,
179 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13180 prefs::kWebKitMinimumFontSize,
181 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36182 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32183 prefs::kDefaultCharset
184 // kWebKitStandardFontIsSerif needs to be added
185 // if we let users pick which font to use, serif or sans-serif when
186 // no font is specified or a CSS generic family (serif or sans-serif)
187 // is not specified.
188};
189
190const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
191
[email protected]420ae012009-04-24 05:16:32192// Returns true if the entry's transition type is FORM_SUBMIT.
193bool IsFormSubmit(const NavigationEntry* entry) {
194 return (PageTransition::StripQualifier(entry->transition_type()) ==
195 PageTransition::FORM_SUBMIT);
196}
197
198#if defined(OS_WIN)
199
200BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
201 // Note: erase is required to properly paint some widgets borders. This can
202 // be seen with textfields.
203 InvalidateRect(hwnd, NULL, TRUE);
204 return TRUE;
205}
206#endif
207
[email protected]5e369672009-11-03 23:48:30208ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16209 Profile* profile, const NavigationEntry& entry,
210 NavigationController::ReloadType reload_type) {
211 switch (reload_type) {
212 case NavigationController::RELOAD:
213 return ViewMsg_Navigate_Params::RELOAD;
214 case NavigationController::RELOAD_IGNORING_CACHE:
215 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
216 case NavigationController::NO_RELOAD:
217 break; // Fall through to rest of function.
218 }
[email protected]5e369672009-11-03 23:48:30219
220 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
221 profile->DidLastSessionExitCleanly())
222 return ViewMsg_Navigate_Params::RESTORE;
223
224 return ViewMsg_Navigate_Params::NORMAL;
225}
226
[email protected]876bc832010-09-07 16:29:54227void MakeNavigateParams(const NavigationEntry& entry,
228 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16229 NavigationController::ReloadType reload_type,
230 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34231 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54232 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00233 params->current_history_list_offset = controller.last_committed_entry_index();
234 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34235 params->url = entry.url();
236 params->referrer = entry.referrer();
237 params->transition = entry.transition_type();
238 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00239 params->navigation_type =
240 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34241 params->request_time = base::Time::Now();
242}
243
[email protected]851b1eb2010-08-09 13:32:29244class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
245 public:
246 DisabledPluginInfoBar(TabContents* tab_contents,
247 const string16& name,
248 const GURL& update_url)
249 : ConfirmInfoBarDelegate(tab_contents),
250 tab_contents_(tab_contents),
251 name_(name),
252 update_url_(update_url) {
253 tab_contents->AddInfoBar(this);
254 }
255
256 virtual int GetButtons() const {
257 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
258 }
259
[email protected]e23d3a32010-08-13 19:39:58260 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29261 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58262 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29263 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58264 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29265 return ConfirmInfoBarDelegate::GetButtonLabel(button);
266 }
267
[email protected]e23d3a32010-08-13 19:39:58268 virtual string16 GetMessageText() const {
269 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29270 }
271
[email protected]e23d3a32010-08-13 19:39:58272 virtual string16 GetLinkText() {
273 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29274 }
275
276 virtual SkBitmap* GetIcon() const {
277 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
278 IDR_INFOBAR_PLUGIN_INSTALL);
279 }
280
281 virtual bool Accept() {
282 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51283 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29284 return false;
285 }
286
287 virtual bool Cancel() {
288 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51289 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29290 return false;
291 }
292
293 virtual bool LinkClicked(WindowOpenDisposition disposition) {
294 // TODO(bauerb): Navigate to a help page explaining why we disabled
295 // the plugin, once we have one.
296 return false;
297 }
298
299 private:
300 TabContents* tab_contents_;
301 string16 name_;
302 GURL update_url_;
303};
304
[email protected]420ae012009-04-24 05:16:32305} // namespace
306
307// -----------------------------------------------------------------------------
308
[email protected]fdd61c62009-04-22 19:22:57309// static
310int TabContents::find_request_id_counter_ = -1;
311
[email protected]420ae012009-04-24 05:16:32312
[email protected]420ae012009-04-24 05:16:32313TabContents::TabContents(Profile* profile,
314 SiteInstance* site_instance,
315 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07316 const TabContents* base_tab_contents,
317 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42318 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07319 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
320 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13321 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22322 TabContentsView::Create(this))),
323 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57324 property_bag_(),
325 registrar_(),
[email protected]12802702010-07-09 19:43:09326 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
327 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57328 save_package_(),
[email protected]6db0def92010-03-02 19:55:45329 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21330 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57331 password_manager_(),
332 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06333 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22334 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34335 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29336 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34337 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34338 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57339 current_load_start_(),
340 load_state_(net::LOAD_STATE_IDLE),
341 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56342 upload_size_(0),
343 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57344 received_page_title_(false),
345 is_starred_(false),
346 contents_mime_type_(),
347 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40348 blocked_contents_(NULL),
349 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49350 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47351 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57352 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57353 find_ui_active_(false),
354 find_op_aborted_(false),
355 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12356 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12357 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08358 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57359 capturing_contents_(false),
360 is_being_destroyed_(false),
361 notify_disconnection_(false),
362 history_requests_(),
363#if defined(OS_WIN)
364 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
365#endif
366 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44367 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01368 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54369 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54370 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16371 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38372 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25373 minimum_zoom_percent_(
374 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
375 maximum_zoom_percent_(
376 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00377 temporary_zoom_settings_(false),
378 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54379 renderer_preferences_util::UpdateFromSystemSettings(
380 &renderer_preferences_, profile);
381
[email protected]9fb83e82010-07-02 18:24:55382 content_settings_delegate_.reset(
383 new TabSpecificContentSettings(this, profile));
384
[email protected]16779842009-07-08 23:45:29385#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02386 // Make sure the thumbnailer is started before starting the render manager.
387 // The thumbnailer will want to listen for RVH creations, one of which will
388 // happen in RVHManager::Init.
389 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
390 if (generator)
391 generator->StartThumbnailing();
392#endif
393
[email protected]12636df2009-09-28 22:32:21394 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32395
[email protected]34ac70502009-09-25 17:07:23396 // We have the initial size of the view be based on the size of the passed in
397 // tab contents (normally a tab from the same window).
398 view_->CreateView(base_tab_contents ?
399 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32400
401 // Register for notifications about all interested prefs change.
402 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28403 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32404 if (prefs) {
405 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28406 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32407 }
408
409 // Register for notifications about URL starredness changing on any profile.
410 registrar_.Add(this, NotificationType::URLS_STARRED,
411 NotificationService::AllSources());
412 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
413 NotificationService::AllSources());
414 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
415 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09416#if defined(OS_LINUX)
417 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
418 NotificationService::AllSources());
419#endif
[email protected]420ae012009-04-24 05:16:32420
[email protected]6c32ce72010-03-08 05:18:06421 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
422 NotificationService::AllSources());
423
[email protected]79580c62010-02-02 02:36:25424 // Register for notifications about content setting changes.
425 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
426 NotificationService::AllSources());
427
[email protected]a888b29e62010-04-01 13:38:57428 // Listen for extension changes so we can update extension_for_current_page_.
429 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
430 NotificationService::AllSources());
431 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
432 NotificationService::AllSources());
433 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
434 NotificationService::AllSources());
435
[email protected]88152052010-10-01 04:05:18436 // Listen for Google URL changes
437 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
438 NotificationService::AllSources());
439
[email protected]c8865482009-07-23 20:40:10440 // Set-up the showing of the omnibox search infobar if applicable.
441 if (OmniboxSearchHint::IsEnabled(profile))
442 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35443}
initial.commit09911bf2008-07-26 23:55:29444
445TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32446 is_being_destroyed_ = true;
447
[email protected]bfe4c1582009-10-02 18:11:09448 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32449 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28450 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32451
[email protected]420ae012009-04-24 05:16:32452 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00453 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32454
[email protected]420ae012009-04-24 05:16:32455 // First cleanly close all child windows.
456 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
457 // some of these to close. CloseWindows is async, so it might get called
458 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49459 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32460
[email protected]c65e2f152010-10-14 15:30:40461 // Close all blocked contents.
462 if (blocked_contents_)
463 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13464
[email protected]420ae012009-04-24 05:16:32465 // Notify any observer that have a reference on this tab contents.
466 NotificationService::current()->Notify(
467 NotificationType::TAB_CONTENTS_DESTROYED,
468 Source<TabContents>(this),
469 NotificationService::NoDetails());
470
[email protected]1e5e74f2009-05-27 20:55:12471 // Notify any lasting InfobarDelegates that have not yet been removed that
472 // whatever infobar they were handling in this TabContents has closed,
473 // because the TabContents is going away entirely.
474 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
475 // notification may trigger infobars calls that access their delegate. (and
476 // some implementations of InfoBarDelegate do delete themselves on
477 // InfoBarClosed()).
478 for (int i = 0; i < infobar_delegate_count(); ++i) {
479 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
480 delegate->InfoBarClosed();
481 }
482 infobar_delegates_.clear();
483
[email protected]420ae012009-04-24 05:16:32484 // TODO(brettw) this should be moved to the view.
485#if defined(OS_WIN)
486 // If we still have a window handle, destroy it. GetNativeView can return
487 // NULL if this contents was part of a window that closed.
488 if (GetNativeView())
489 ::DestroyWindow(GetNativeView());
490#endif
[email protected]7ab1e7d62009-10-14 23:32:01491
492 // OnCloseStarted isn't called in unit tests.
493 if (!tab_close_start_time_.is_null()) {
494 UMA_HISTOGRAM_TIMES("Tab.Close",
495 base::TimeTicks::Now() - tab_close_start_time_);
496 }
initial.commit09911bf2008-07-26 23:55:29497}
498
[email protected]d5f942ba2008-09-26 19:30:34499// static
500void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32501 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
502
503 WebPreferences pref_defaults;
504 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
505 pref_defaults.javascript_enabled);
506 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
507 pref_defaults.web_security_enabled);
508 prefs->RegisterBooleanPref(
509 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
510 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
511 pref_defaults.loads_images_automatically);
512 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
513 pref_defaults.plugins_enabled);
514 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
515 pref_defaults.dom_paste_enabled);
516 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
517 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14518 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32519 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
520 pref_defaults.text_areas_are_resizable);
521 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
522 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36523 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
524 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32525
526 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
527 IDS_ACCEPT_LANGUAGES);
528 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
529 IDS_DEFAULT_ENCODING);
530 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
531 IDS_STANDARD_FONT_IS_SERIF);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
533 IDS_FIXED_FONT_FAMILY);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
535 IDS_SERIF_FONT_FAMILY);
536 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
537 IDS_SANS_SERIF_FONT_FAMILY);
538 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
539 IDS_CURSIVE_FONT_FAMILY);
540 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
541 IDS_FANTASY_FONT_FAMILY);
542 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
543 IDS_DEFAULT_FONT_SIZE);
544 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
545 IDS_DEFAULT_FIXED_FONT_SIZE);
546 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
547 IDS_MINIMUM_FONT_SIZE);
548 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
549 IDS_MINIMUM_LOGICAL_FONT_SIZE);
550 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
551 IDS_USES_UNIVERSAL_DETECTOR);
552 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
553 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]13367f72009-07-08 16:39:02556// Returns true if contains content rendered by an extension.
557bool TabContents::HostsExtension() const {
558 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34559}
560
[email protected]cf28ec52010-04-09 22:56:34561AutoFillManager* TabContents::GetAutoFillManager() {
562 if (autofill_manager_.get() == NULL)
563 autofill_manager_.reset(new AutoFillManager(this));
564 return autofill_manager_.get();
565}
566
[email protected]6e95706d2009-04-23 22:55:01567PasswordManager* TabContents::GetPasswordManager() {
568 if (password_manager_.get() == NULL)
569 password_manager_.reset(new PasswordManager(this));
570 return password_manager_.get();
571}
572
573PluginInstaller* TabContents::GetPluginInstaller() {
574 if (plugin_installer_.get() == NULL)
575 plugin_installer_.reset(new PluginInstaller(this));
576 return plugin_installer_.get();
577}
578
[email protected]1f18184a2010-07-21 19:34:49579TabContentsSSLHelper* TabContents::GetSSLHelper() {
580 if (ssl_helper_.get() == NULL)
581 ssl_helper_.reset(new TabContentsSSLHelper(this));
582 return ssl_helper_.get();
583}
584
[email protected]8cb5d5b2010-02-09 11:36:16585RenderProcessHost* TabContents::GetRenderProcessHost() const {
586 return render_manager_.current_host()->process();
587}
588
[email protected]98aa0b52010-05-06 17:03:08589void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46590 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08591 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10592
[email protected]98aa0b52010-05-06 17:03:08593 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57594
[email protected]fca656c2010-02-10 20:30:10595 NotificationService::current()->Notify(
596 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
597 Source<TabContents>(this),
598 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49599}
600
[email protected]98aa0b52010-05-06 17:03:08601void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
602 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40603 return;
604
605 ExtensionsService* extension_service = profile()->GetExtensionsService();
606 if (extension_service && extension_service->is_ready()) {
607 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08608 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40609 if (extension)
[email protected]98aa0b52010-05-06 17:03:08610 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40611 }
612}
613
[email protected]98aa0b52010-05-06 17:03:08614SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08615 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51616 return NULL;
617
[email protected]98aa0b52010-05-06 17:03:08618 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51619}
620
[email protected]d5f942ba2008-09-26 19:30:34621const GURL& TabContents::GetURL() const {
622 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57623 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54624 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34625}
626
[email protected]96d185d2009-04-24 03:28:54627const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55628 // Transient entries take precedence. They are used for interstitial pages
629 // that are shown on top of existing pages.
630 NavigationEntry* entry = controller_.GetTransientEntry();
631 if (entry)
632 return entry->GetTitleForDisplay(&controller_);
633
[email protected]96d185d2009-04-24 03:28:54634 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
635 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
636 if (our_dom_ui) {
637 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55638 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54639 if (!(entry && entry->IsViewSourceMode())) {
640 // Give the DOM UI the chance to override our title.
641 const string16& title = our_dom_ui->overridden_title();
642 if (!title.empty())
643 return title;
644 }
645 }
646
647 // We use the title for the last committed entry rather than a pending
648 // navigation entry. For example, when the user types in a URL, we want to
649 // keep the old page's title until the new load has committed and we get a new
650 // title.
[email protected]96d185d2009-04-24 03:28:54651 entry = controller_.GetLastCommittedEntry();
652 if (entry)
653 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54654 return EmptyString16();
655}
656
[email protected]bbbc1ef2010-02-12 18:03:41657// static
658string16 TabContents::GetDefaultTitle() {
659 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
660}
661
[email protected]d5f942ba2008-09-26 19:30:34662int32 TabContents::GetMaxPageID() {
663 if (GetSiteInstance())
664 return GetSiteInstance()->max_page_id();
665 else
666 return max_page_id_;
667}
668
669void TabContents::UpdateMaxPageID(int32 page_id) {
670 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34671 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34672 // testing.
673 if (GetSiteInstance())
674 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16675 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34676}
677
[email protected]96d185d2009-04-24 03:28:54678SiteInstance* TabContents::GetSiteInstance() const {
679 return render_manager_.current_host()->site_instance();
680}
681
[email protected]96d185d2009-04-24 03:28:54682bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15683 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54684 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15685 if (entry && (entry->IsViewSourceMode() ||
686 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54687 return true;
[email protected]8ab24cc2009-11-13 20:56:15688 }
[email protected]83e3895b2009-06-11 00:07:16689
[email protected]96d185d2009-04-24 03:28:54690 DOMUI* dom_ui = GetDOMUIForCurrentState();
691 if (dom_ui)
692 return !dom_ui->should_hide_url();
693 return true;
694}
695
[email protected]d5f942ba2008-09-26 19:30:34696SkBitmap TabContents::GetFavIcon() const {
697 // Like GetTitle(), we also want to use the favicon for the last committed
698 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57699 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47700 if (entry)
701 return entry->favicon().bitmap();
702
[email protected]ce3fa3c2009-04-20 19:55:57703 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34704 if (entry)
705 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34706 return SkBitmap();
707}
708
[email protected]0b303cc2009-09-28 22:35:15709bool TabContents::FavIconIsValid() const {
710 NavigationEntry* entry = controller_.GetTransientEntry();
711 if (entry)
712 return entry->favicon().is_valid();
713
714 entry = controller_.GetLastCommittedEntry();
715 if (entry)
716 return entry->favicon().is_valid();
717
718 return false;
719}
720
[email protected]96d185d2009-04-24 03:28:54721bool TabContents::ShouldDisplayFavIcon() {
722 // Always display a throbber during pending loads.
723 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
724 return true;
725
726 DOMUI* dom_ui = GetDOMUIForCurrentState();
727 if (dom_ui)
728 return !dom_ui->hide_favicon();
729 return true;
730}
731
[email protected]96d185d2009-04-24 03:28:54732std::wstring TabContents::GetStatusText() const {
733 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
734 return std::wstring();
735
736 switch (load_state_) {
737 case net::LOAD_STATE_WAITING_FOR_CACHE:
738 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04739 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
740 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54741 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
742 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
743 case net::LOAD_STATE_RESOLVING_HOST:
744 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
745 case net::LOAD_STATE_CONNECTING:
746 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06747 case net::LOAD_STATE_SSL_HANDSHAKE:
748 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54749 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56750 if (upload_size_)
751 return l10n_util::GetStringF(
752 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
753 static_cast<int>((100 * upload_position_) / upload_size_));
754 else
755 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54756 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
757 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
758 load_state_host_);
759 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
760 case net::LOAD_STATE_IDLE:
761 case net::LOAD_STATE_READING_RESPONSE:
762 break;
763 }
764
765 return std::wstring();
766}
767
[email protected]d5f942ba2008-09-26 19:30:34768void TabContents::SetIsCrashed(bool state) {
769 if (state == is_crashed_)
770 return;
771
772 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50773 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34774}
775
[email protected]744ef172009-10-16 21:53:46776void TabContents::PageActionStateChanged() {
777 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00778}
[email protected]ce5c4502009-05-06 16:46:11779
[email protected]d5f942ba2008-09-26 19:30:34780void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
781 if (delegate_)
782 delegate_->NavigationStateChanged(this, changed_flags);
783}
784
[email protected]96d185d2009-04-24 03:28:54785void TabContents::DidBecomeSelected() {
786 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16787 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
788 if (rwhv) {
789 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43790#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16791 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43792#endif
793 }
[email protected]96d185d2009-04-24 03:28:54794
[email protected]8cb5d5b2010-02-09 11:36:16795 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54796}
797
798void TabContents::WasHidden() {
799 if (!capturing_contents()) {
800 // |render_view_host()| can be NULL if the user middle clicks a link to open
801 // a tab in then background, then closes the tab before selecting it. This
802 // is because closing the tab calls TabContents::Destroy(), which removes
803 // the |render_view_host()|; then when we actually destroy the window,
804 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16805 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
806 if (rwhv)
807 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54808 }
809
810 NotificationService::current()->Notify(
811 NotificationType::TAB_CONTENTS_HIDDEN,
812 Source<TabContents>(this),
813 NotificationService::NoDetails());
814}
815
[email protected]d5f942ba2008-09-26 19:30:34816void TabContents::Activate() {
817 if (delegate_)
818 delegate_->ActivateContents(this);
819}
820
[email protected]ea42e7782010-08-23 23:58:12821void TabContents::Deactivate() {
822 if (delegate_)
823 delegate_->DeactivateContents(this);
824}
825
[email protected]96d185d2009-04-24 03:28:54826void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16827 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
828 if (rwhv)
829 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54830}
831
832void TabContents::HideContents() {
833 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
834 // our superclass HideContents(), because some callers want to be very picky
835 // about the order in which these get called. In addition to making the code
836 // here practically impossible to understand, this also means we end up
837 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34838 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54839 WasHidden();
840}
841
[email protected]c0588052008-10-27 23:01:50842void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34843 WindowOpenDisposition disposition,
844 PageTransition::Type transition) {
845 if (delegate_)
[email protected]c0588052008-10-27 23:01:50846 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34847}
848
[email protected]1ccb3568d2010-02-19 10:51:16849bool TabContents::NavigateToPendingEntry(
850 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54851 return NavigateToEntry(*controller_.pending_entry(), reload_type);
852}
[email protected]96d185d2009-04-24 03:28:54853
[email protected]876bc832010-09-07 16:29:54854bool TabContents::NavigateToEntry(
855 const NavigationEntry& entry,
856 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54857 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
858 if (!dest_render_view_host)
859 return false; // Unable to create the desired render view host.
860
[email protected]770dd8b2010-05-24 18:11:39861 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
862 dest_render_view_host->EnablePreferredSizeChangedMode(
863 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
864 }
[email protected]9fb325e2010-05-06 18:23:24865
[email protected]0352e5472010-04-29 00:11:40866 // For security, we should never send non-DOM-UI URLs (other than about:blank)
867 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58868 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40869 bool is_allowed_in_dom_ui_renderer =
[email protected]583d45c12010-08-31 02:48:12870 DOMUIFactory::UseDOMUIForURL(profile(), entry.url()) ||
[email protected]0352e5472010-04-29 00:11:40871 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58872 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40873 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58874
[email protected]96d185d2009-04-24 03:28:54875 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12876 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32877 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00878 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
879 dest_render_view_host,
880 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32881 }
[email protected]96d185d2009-04-24 03:28:54882
883 // Used for page load time metrics.
884 current_load_start_ = base::TimeTicks::Now();
885
886 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34887 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54888 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34889 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54890
891 if (entry.page_id() == -1) {
892 // HACK!! This code suppresses javascript: URLs from being added to
893 // session history, which is what we want to do for javascript: URLs that
894 // do not generate content. What we really need is a message from the
895 // renderer telling us that a new page was not created. The same message
896 // could be used for mailto: URLs and the like.
897 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
898 return false;
899 }
900
901 // Clear any provisional password saves - this stops password infobars
902 // showing up on pages the user navigates to while the right page is
903 // loading.
904 GetPasswordManager()->ClearProvisionalSave();
905
[email protected]1ccb3568d2010-02-19 10:51:16906 if (reload_type != NavigationController::NO_RELOAD &&
907 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48908 FaviconService* favicon_service =
909 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
910 if (favicon_service)
911 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54912 }
913
[email protected]d5f942ba2008-09-26 19:30:34914 return true;
915}
916
[email protected]96d185d2009-04-24 03:28:54917void TabContents::Stop() {
918 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09919 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54920}
921
[email protected]96d185d2009-04-24 03:28:54922void TabContents::DisassociateFromPopupCount() {
923 render_view_host()->DisassociateFromPopupCount();
924}
925
926TabContents* TabContents::Clone() {
927 // We create a new SiteInstance so that the new tab won't share processes
928 // with the old one. This can be changed in the future if we need it to share
929 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32930 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54931 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07932 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54933 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08934 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08935 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54936 return tc;
937}
938
[email protected]4d677202009-07-19 07:37:12939void TabContents::ShowPageInfo(const GURL& url,
940 const NavigationEntry::SSLStatus& ssl,
941 bool show_history) {
942 if (!delegate_)
943 return;
944
[email protected]bb678332009-07-21 00:15:50945 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12946}
947
initial.commit09911bf2008-07-26 23:55:29948ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28949 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29950 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28951 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29952 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44953
954 if (child_windows_.size() == 1) {
955 window->ShowConstrainedWindow();
956 BlockTabContent(true);
957 }
958
initial.commit09911bf2008-07-26 23:55:29959 return window;
960}
961
[email protected]fa1cf0b82010-01-15 21:49:44962void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55963 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
964 if (rwhv)
965 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44966 render_view_host()->set_ignore_input_events(blocked);
967 if (delegate_)
968 delegate_->SetTabContentBlocked(this, blocked);
969}
970
initial.commit09911bf2008-07-26 23:55:29971void TabContents::AddNewContents(TabContents* new_contents,
972 WindowOpenDisposition disposition,
973 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29974 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40975 if (all_contents_blocked_) {
976 if (!blocked_contents_)
977 blocked_contents_ = new BlockedContentContainer(this);
978 blocked_contents_->AddTabContents(
979 new_contents, disposition, initial_pos, user_gesture);
980 return;
981 }
982
initial.commit09911bf2008-07-26 23:55:29983 if (!delegate_)
984 return;
985
[email protected]35f7d212009-04-29 21:19:27986 if ((disposition == NEW_POPUP) && !user_gesture &&
987 !CommandLine::ForCurrentProcess()->HasSwitch(
988 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22989 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31990 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29991 delegate_->GetConstrainingContents(this)->AddPopup(
992 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31993 } else {
[email protected]0aa55312008-10-17 21:53:08994 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29995 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
996 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49997 NotificationService::current()->Notify(
998 NotificationType::TAB_ADDED,
999 Source<TabContentsDelegate>(delegate_),
1000 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291001 }
initial.commit09911bf2008-07-26 23:55:291002
[email protected]8cc8d492010-02-02 10:40:491003 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401004 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291005}
1006
[email protected]bcd9dc42010-01-23 16:38:181007bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201008 bool is_js_code, const std::string& code_string,
1009 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511010 RenderViewHost* host = render_view_host();
1011 if (!host)
1012 return false;
1013
1014 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171015 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511016 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351017}
1018
[email protected]96d185d2009-04-24 03:28:541019void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491020 if (is_being_destroyed_)
1021 return;
[email protected]9fb83e82010-07-02 18:24:551022 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491023 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401024 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541025}
1026
[email protected]5c9e97a2009-09-09 23:48:301027gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541028 return view_->GetContentNativeView();
1029}
1030
1031gfx::NativeView TabContents::GetNativeView() const {
1032 return view_->GetNativeView();
1033}
1034
1035void TabContents::GetContainerBounds(gfx::Rect *out) const {
1036 view_->GetContainerBounds(out);
1037}
1038
1039void TabContents::Focus() {
1040 view_->Focus();
1041}
1042
[email protected]90daadb42009-06-08 21:27:281043void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541044 if (showing_interstitial_page()) {
1045 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1046 return;
1047 }
[email protected]96d185d2009-04-24 03:28:541048 render_view_host()->SetInitialFocus(reverse);
1049}
1050
1051bool TabContents::FocusLocationBarByDefault() {
1052 DOMUI* dom_ui = GetDOMUIForCurrentState();
1053 if (dom_ui)
1054 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431055 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251056 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431057 return true;
[email protected]96d185d2009-04-24 03:28:541058 return false;
1059}
1060
[email protected]a26dc362010-04-23 01:48:581061void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381062 if (delegate())
[email protected]a26dc362010-04-23 01:48:581063 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381064}
1065
[email protected]616ed5a2008-11-21 22:27:241066void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321067 if (delegate_ && !delegate_->infobars_enabled()) {
1068 delegate->InfoBarClosed();
1069 return;
1070 }
1071
[email protected]616ed5a2008-11-21 22:27:241072 // Look through the existing InfoBarDelegates we have for a match. If we've
1073 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051074 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451075 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1076 // Tell the new infobar to close so that it can clean itself up.
1077 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241078 return;
[email protected]6d27a7b2009-12-18 23:25:451079 }
[email protected]616ed5a2008-11-21 22:27:241080 }
1081
1082 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561083 NotificationService::current()->Notify(
1084 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1085 Source<TabContents>(this),
1086 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241087
1088 // Add ourselves as an observer for navigations the first time a delegate is
1089 // added. We use this notification to expire InfoBars that need to expire on
1090 // page transitions.
1091 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561092 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571093 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241094 }
1095}
1096
1097void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321098 if (delegate_ && !delegate_->infobars_enabled()) {
1099 return;
1100 }
1101
[email protected]616ed5a2008-11-21 22:27:241102 std::vector<InfoBarDelegate*>::iterator it =
1103 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1104 if (it != infobar_delegates_.end()) {
1105 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561106 NotificationService::current()->Notify(
1107 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1108 Source<TabContents>(this),
1109 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241110
[email protected]cdadf6f2010-08-20 16:36:081111 // Just to be safe, make sure the delegate was not removed by an observer.
1112 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1113 if (it != infobar_delegates_.end()) {
1114 infobar_delegates_.erase(it);
1115 // Remove ourselves as an observer if we are tracking no more InfoBars.
1116 if (infobar_delegates_.empty()) {
1117 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1118 Source<NavigationController>(&controller_));
1119 }
1120 } else {
1121 // If you hit this NOTREACHED, please comment in bug
1122 // http://crbug.com/50428 how you got there.
1123 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031124 }
[email protected]616ed5a2008-11-21 22:27:241125 }
1126}
[email protected]3edd9522009-03-04 22:19:411127
[email protected]f81821c2009-08-07 01:29:471128void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1129 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321130 if (delegate_ && !delegate_->infobars_enabled()) {
1131 new_delegate->InfoBarClosed();
1132 return;
1133 }
1134
[email protected]f81821c2009-08-07 01:29:471135 std::vector<InfoBarDelegate*>::iterator it =
1136 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1137 DCHECK(it != infobar_delegates_.end());
1138
1139 // Notify the container about the change of plans.
1140 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1141 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1142 old_delegate, new_delegate));
1143 NotificationService::current()->Notify(
1144 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1145 Source<TabContents>(this),
1146 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1147
[email protected]cdadf6f2010-08-20 16:36:081148 // Just to be safe, make sure the delegate was not removed by an observer.
1149 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1150 if (it != infobar_delegates_.end()) {
1151 // Remove the old one.
1152 infobar_delegates_.erase(it);
1153 } else {
1154 // If you hit this NOTREACHED, please comment in bug
1155 // http://crbug.com/50428 how you got there.
1156 NOTREACHED();
1157 }
[email protected]f81821c2009-08-07 01:29:471158
1159 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081160 DCHECK(find(infobar_delegates_.begin(),
1161 infobar_delegates_.end(), new_delegate) ==
1162 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471163 infobar_delegates_.push_back(new_delegate);
1164}
1165
[email protected]20ede072009-10-06 00:28:351166bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271167 if (showing_interstitial_page())
1168 return false;
1169
[email protected]c8f74942010-09-03 10:04:141170 // Do not show bookmarks bar if bookmarks aren't enabled.
1171 if (!browser_defaults::bookmarks_enabled)
1172 return false;
1173
[email protected]96d185d2009-04-24 03:28:541174 // See GetDOMUIForCurrentState() comment for more info. This case is very
1175 // similar, but for non-first loads, we want to use the committed entry. This
1176 // is so the bookmarks bar disappears at the same time the page does.
1177 if (controller_.GetLastCommittedEntry()) {
1178 // Not the first load, always use the committed DOM UI.
1179 if (render_manager_.dom_ui())
1180 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1181 return false; // Default.
1182 }
1183
1184 // When it's the first load, we know either the pending one or the committed
1185 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1186 // of them will be valid, so we can just check both.
1187 if (render_manager_.pending_dom_ui())
1188 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1189 if (render_manager_.dom_ui())
1190 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1191 return false; // Default.
1192}
1193
[email protected]3edd9522009-03-04 22:19:411194void TabContents::ToolbarSizeChanged(bool is_animating) {
1195 TabContentsDelegate* d = delegate();
1196 if (d)
1197 d->ToolbarSizeChanged(this, is_animating);
1198}
[email protected]616ed5a2008-11-21 22:27:241199
[email protected]fc6fb7fb2009-11-07 02:35:041200bool TabContents::CanDownload(int request_id) {
1201 TabContentsDelegate* d = delegate();
1202 if (d)
1203 return d->CanDownload(request_id);
1204 return true;
1205}
1206
[email protected]d5f942ba2008-09-26 19:30:341207void TabContents::OnStartDownload(DownloadItem* download) {
1208 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341209
1210 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311211 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341212
[email protected]5b928b62010-08-03 11:46:511213 if (tab_contents && tab_contents->delegate())
1214 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411215}
[email protected]3edd9522009-03-04 22:19:411216
[email protected]d5f942ba2008-09-26 19:30:341217void TabContents::WillClose(ConstrainedWindow* window) {
1218 ConstrainedWindowList::iterator it =
1219 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441220 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341221 if (it != child_windows_.end())
1222 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371223 if (child_windows_.size() > 0) {
1224 if (removed_topmost_window) {
1225 child_windows_[0]->ShowConstrainedWindow();
1226 }
[email protected]fa1cf0b82010-01-15 21:49:441227 BlockTabContent(true);
1228 } else {
1229 BlockTabContent(false);
1230 }
[email protected]66ba4932009-06-04 19:22:131231}
[email protected]d5f942ba2008-09-26 19:30:341232
[email protected]c65e2f152010-10-14 15:30:401233void TabContents::WillCloseBlockedContentContainer(
1234 BlockedContentContainer* container) {
1235 DCHECK(blocked_contents_ == container);
1236 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491237 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341238}
1239
[email protected]d5f942ba2008-09-26 19:30:341240void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351241#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061242 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351243#endif
[email protected]d5f942ba2008-09-26 19:30:341244}
1245
[email protected]c1dc9f132009-11-20 23:13:211246void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121247 bool forward_direction,
1248 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211249 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011250 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211251 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531252 string16 last_search_prepopulate_text =
1253 FindBarState::GetLastPrepopulateText(profile());
1254
[email protected]87fae512009-12-11 02:20:211255 // Try the last thing we searched for on this tab, then the last thing
1256 // searched for on any tab.
1257 if (!previous_find_text_.empty())
1258 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531259 else if (!last_search_prepopulate_text.empty())
1260 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211261 else
[email protected]e491f1c2009-05-22 20:28:121262 return;
[email protected]e491f1c2009-05-22 20:28:121263 }
[email protected]6e95706d2009-04-23 22:55:011264
[email protected]101c90e2009-10-26 21:14:441265 // Keep track of the previous search.
1266 previous_find_text_ = find_text_;
1267
[email protected]6e95706d2009-04-23 22:55:011268 // This is a FindNext operation if we are searching for the same text again,
1269 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1270 // exception to this is if the Find was aborted (then we don't want FindNext
1271 // because the highlighting has been cleared and we need it to reappear). We
1272 // therefore treat FindNext after an aborted Find operation as a full fledged
1273 // Find.
[email protected]c1dc9f132009-11-20 23:13:211274 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121275 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011276 !find_op_aborted_;
1277 if (!find_next)
1278 current_find_request_id_ = find_request_id_counter_++;
1279
[email protected]c1dc9f132009-11-20 23:13:211280 if (!search_string.empty())
1281 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121282 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011283
1284 find_op_aborted_ = false;
1285
1286 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531287 FindBarState* find_bar_state = profile()->GetFindBarState();
1288 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011289 render_view_host()->StartFinding(current_find_request_id_,
1290 find_text_,
1291 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121292 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011293 find_next);
1294}
1295
[email protected]5bc8fe92010-03-11 18:19:001296void TabContents::StopFinding(
1297 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011298 if (selection_action == FindBarController::kClearSelection) {
1299 // kClearSelection means the find string has been cleared by the user, but
1300 // the UI has not been dismissed. In that case we want to clear the
1301 // previously remembered search (http://crbug.com/42639).
1302 previous_find_text_ = string16();
1303 } else {
[email protected]2d2dffc2009-06-09 21:41:001304 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011305 if (!find_text_.empty())
1306 previous_find_text_ = find_text_;
1307 }
[email protected]101c90e2009-10-26 21:14:441308 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011309 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121310 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001311 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011312}
1313
[email protected]420ae012009-04-24 05:16:321314void TabContents::OnSavePage() {
1315 // If we can not save the page, try to download it.
1316 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1317 DownloadManager* dlm = profile()->GetDownloadManager();
1318 const GURL& current_page_url = GetURL();
1319 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221320 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321321 return;
1322 }
1323
1324 Stop();
1325
1326 // Create the save package and possibly prompt the user for the name to save
1327 // the page as. The user prompt is an asynchronous operation that runs on
1328 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221329 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321330 save_package_->GetSaveInfo();
1331}
1332
1333// Used in automated testing to bypass prompting the user for file names.
1334// Instead, the names and paths are hard coded rather than running them through
1335// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111336bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321337 SavePackage::SavePackageType save_type) {
1338 // Stop the page from navigating.
1339 Stop();
1340
[email protected]828cabe2009-09-26 22:47:111341 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591342 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321343}
1344
[email protected]89d6e6e2009-12-03 23:06:511345void TabContents::EmailPageLocation() {
1346 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1347 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1348 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1349 title + "&body=%0A%0A" + page_url;
1350 platform_util::OpenExternal(GURL(mailto));
1351}
1352
[email protected]420ae012009-04-24 05:16:321353void TabContents::PrintPreview() {
1354 // We don't show the print preview yet, only the print dialog.
1355 PrintNow();
1356}
1357
1358bool TabContents::PrintNow() {
1359 // We can't print interstitial page for now.
1360 if (showing_interstitial_page())
1361 return false;
1362
1363 return render_view_host()->PrintPages();
1364}
1365
[email protected]82270452009-06-19 15:58:011366void TabContents::PrintingDone(int document_cookie, bool success) {
1367 render_view_host()->PrintingDone(document_cookie, success);
1368}
1369
[email protected]420ae012009-04-24 05:16:321370bool TabContents::IsActiveEntry(int32 page_id) {
1371 NavigationEntry* active_entry = controller_.GetActiveEntry();
1372 return (active_entry != NULL &&
1373 active_entry->site_instance() == GetSiteInstance() &&
1374 active_entry->page_id() == page_id);
1375}
1376
[email protected]b2fe07d12010-02-09 14:38:081377void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161378 set_encoding(encoding);
1379 render_view_host()->SetPageEncoding(encoding);
1380}
1381
[email protected]b2fe07d12010-02-09 14:38:081382void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161383 reset_encoding();
1384 render_view_host()->ResetPageEncodingToDefault();
1385}
1386
1387void TabContents::WindowMoveOrResizeStarted() {
1388 render_view_host()->WindowMoveOrResizeStarted();
1389}
1390
[email protected]c65e2f152010-10-14 15:30:401391void TabContents::SetAllContentsBlocked(bool value) {
1392 if (all_contents_blocked_ == value)
1393 return;
1394
1395 all_contents_blocked_ = value;
1396 if (!all_contents_blocked_ && blocked_contents_) {
1397 std::vector<TabContents*> blocked;
1398 blocked_contents_->GetBlockedContents(&blocked);
1399 for (size_t i = 0; i < blocked.size(); ++i)
1400 blocked_contents_->LaunchForContents(blocked[i]);
1401 }
1402}
1403
[email protected]3f8eb7f2009-10-02 23:58:051404void TabContents::LogNewTabTime(const std::string& event_name) {
1405 // Not all new tab pages get timed. In those cases, we don't have a
1406 // new_tab_start_time_.
1407 if (new_tab_start_time_.is_null())
1408 return;
1409
1410 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441411 MetricEventDurationDetails details(event_name,
1412 static_cast<int>(duration.InMilliseconds()));
1413
[email protected]7ab1e7d62009-10-14 23:32:011414 if (event_name == "Tab.NewTabScriptStart") {
1415 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1416 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1417 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1418 } else if (event_name == "Tab.NewTabOnload") {
1419 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051420 // The new tab page has finished loading; reset it.
1421 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441422 } else {
1423 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051424 }
[email protected]84abba62009-10-07 17:01:441425 NotificationService::current()->Notify(
1426 NotificationType::METRIC_EVENT_DURATION,
1427 Source<TabContents>(this),
1428 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051429}
1430
[email protected]7ab1e7d62009-10-14 23:32:011431void TabContents::OnCloseStarted() {
1432 if (tab_close_start_time_.is_null())
1433 tab_close_start_time_ = base::TimeTicks::Now();
1434}
1435
[email protected]46624bf2010-06-09 16:04:191436bool TabContents::ShouldAcceptDragAndDrop() const {
1437#if defined(OS_CHROMEOS)
1438 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1439 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201440 if (delegate() && delegate()->IsPopup(this))
1441 return false;
1442 return true;
[email protected]46624bf2010-06-09 16:04:191443#else
1444 return true;
1445#endif
1446}
1447
[email protected]ec0b6c42010-08-26 03:16:581448void TabContents::UpdateHistoryForNavigation(
1449 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1450 if (profile()->IsOffTheRecord())
1451 return;
1452
1453 // Add to history service.
1454 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1455 if (hs)
1456 hs->AddPage(*add_page_args);
1457}
1458
1459void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1460 if (profile()->IsOffTheRecord())
1461 return;
1462
1463 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1464 if (hs)
1465 hs->SetPageTitle(entry.virtual_url(), entry.title());
1466}
1467
[email protected]b75b8292010-10-01 07:28:251468int TabContents::GetZoomPercent(bool* enable_increment,
1469 bool* enable_decrement) {
1470 *enable_decrement = *enable_increment = false;
1471 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1472 if (!zoom_map)
1473 return 100;
1474
1475 double zoom_level;
1476 if (temporary_zoom_settings_) {
1477 zoom_level = zoom_map->GetTemporaryZoomLevel(
1478 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1479 } else {
1480 zoom_level = zoom_map->GetZoomLevel(GetURL());
1481 }
1482
[email protected]b75b8292010-10-01 07:28:251483 int percent = static_cast<int>(
1484 WebKit::WebView::zoomLevelToZoomFactor(zoom_level) * 100);
[email protected]b75b8292010-10-01 07:28:251485 *enable_decrement = percent > minimum_zoom_percent_;
1486 *enable_increment = percent < maximum_zoom_percent_;
1487 return percent;
1488}
1489
[email protected]96d185d2009-04-24 03:28:541490// Notifies the RenderWidgetHost instance about the fact that the page is
1491// loading, or done loading and calls the base implementation.
1492void TabContents::SetIsLoading(bool is_loading,
1493 LoadNotificationDetails* details) {
1494 if (is_loading == is_loading_)
1495 return;
1496
1497 if (!is_loading) {
1498 load_state_ = net::LOAD_STATE_IDLE;
1499 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561500 upload_size_ = 0;
1501 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541502 }
1503
1504 render_manager_.SetIsLoading(is_loading);
1505
1506 is_loading_ = is_loading;
1507 waiting_for_response_ = is_loading;
1508
[email protected]6ebdc9b2010-09-27 16:55:571509 if (delegate_)
1510 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351511 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541512
1513 NotificationType type = is_loading ? NotificationType::LOAD_START :
1514 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111515 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541516 if (details)
1517 det = Details<LoadNotificationDetails>(details);
1518 NotificationService::current()->Notify(type,
1519 Source<NavigationController>(&controller_),
1520 det);
1521}
1522
[email protected]b6c874582009-05-08 19:38:311523void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291524 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061525 // A page can't spawn popups (or do anything else, either) until its load
1526 // commits, so when we reach here, the popup was spawned by the
1527 // NavigationController's last committed entry, not the active entry. For
1528 // example, if a page opens a popup in an onunload() handler, then the active
1529 // entry is the page to be loaded as we navigate away from the unloading
1530 // page. For this reason, we can't use GetURL() to get the opener URL,
1531 // because it returns the active entry.
1532 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1533 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1534
1535 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491536 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091537 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491538 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1539 } else {
[email protected]c65e2f152010-10-14 15:30:401540 if (!blocked_contents_)
1541 blocked_contents_ = new BlockedContentContainer(this);
1542 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1543 true);
[email protected]55126132010-08-19 14:53:281544 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1545 std::string());
[email protected]8cc8d492010-02-02 10:40:491546 }
[email protected]b9681312008-11-07 00:08:261547}
[email protected]616ed5a2008-11-21 22:27:241548
[email protected]616ed5a2008-11-21 22:27:241549void TabContents::ExpireInfoBars(
1550 const NavigationController::LoadCommittedDetails& details) {
1551 // Only hide InfoBars when the user has done something that makes the main
1552 // frame load. We don't want various automatic or subframe navigations making
1553 // it disappear.
1554 if (!details.is_user_initiated_main_frame_load())
1555 return;
1556
[email protected]f86a07022008-11-25 01:06:051557 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241558 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081559 if (!delegate) {
1560 // If you hit this NOTREACHED, please comment in bug
1561 // http://crbug.com/50428 how you got there.
1562 NOTREACHED();
1563 continue;
1564 }
1565
[email protected]f86a07022008-11-25 01:06:051566 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241567 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241568 }
1569}
[email protected]fdd61c62009-04-22 19:22:571570
[email protected]96d185d2009-04-24 03:28:541571DOMUI* TabContents::GetDOMUIForCurrentState() {
1572 // When there is a pending navigation entry, we want to use the pending DOMUI
1573 // that goes along with it to control the basic flags. For example, we want to
1574 // show the pending URL in the URL bar, so we want the display_url flag to
1575 // be from the pending entry.
1576 //
1577 // The confusion comes because there are multiple possibilities for the
1578 // initial load in a tab as a side effect of the way the RenderViewHostManager
1579 // works.
1580 //
1581 // - For the very first tab the load looks "normal". The new tab DOM UI is
1582 // the pending one, and we want it to apply here.
1583 //
1584 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1585 // get switched to the one previously associated with the new tab pages.
1586 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1587 // have a committed DOM UI in this case.
1588 //
1589 // This condition handles all of these cases:
1590 //
1591 // - First load in first tab: no committed nav entry + pending nav entry +
1592 // pending dom ui:
1593 // -> Use pending DOM UI if any.
1594 //
1595 // - First load in second tab: no committed nav entry + pending nav entry +
1596 // no pending DOM UI:
1597 // -> Use the committed DOM UI if any.
1598 //
1599 // - Second navigation in any tab: committed nav entry + pending nav entry:
1600 // -> Use pending DOM UI if any.
1601 //
1602 // - Normal state with no load: committed nav entry + no pending nav entry:
1603 // -> Use committed DOM UI.
1604 if (controller_.pending_entry() &&
1605 (controller_.GetLastCommittedEntry() ||
1606 render_manager_.pending_dom_ui()))
1607 return render_manager_.pending_dom_ui();
1608 return render_manager_.dom_ui();
1609}
[email protected]420ae012009-04-24 05:16:321610
1611void TabContents::DidNavigateMainFramePostCommit(
1612 const NavigationController::LoadCommittedDetails& details,
1613 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441614 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1615 // If this is a window.open navigation, use the same DOMUI as the renderer
1616 // that opened the window, as long as both renderers have the same
1617 // privileges.
[email protected]583d45c12010-08-31 02:48:121618 if (opener_dom_ui_type_ ==
1619 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441620 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1621 // dom_ui might be NULL if the URL refers to a non-existent extension.
1622 if (dom_ui) {
1623 render_manager_.SetDOMUIPostCommit(dom_ui);
1624 dom_ui->RenderViewCreated(render_view_host());
1625 }
1626 }
1627 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1628 }
1629
[email protected]420ae012009-04-24 05:16:321630 if (details.is_user_initiated_main_frame_load()) {
1631 // Clear the status bubble. This is a workaround for a bug where WebKit
1632 // doesn't let us know that the cursor left an element during a
1633 // transition (this is also why the mouse cursor remains as a hand after
1634 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1635 // clear the bubble when a user navigates to a named anchor in the same
1636 // page.
1637 UpdateTargetURL(details.entry->page_id(), GURL());
1638
1639 // UpdateHelpersForDidNavigate will handle the case where the password_form
1640 // origin is valid.
1641 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1642 // cleaned up and covered by tests.
1643 if (!params.password_form.origin.is_valid())
1644 GetPasswordManager()->DidNavigate();
1645 }
1646
1647 // The keyword generator uses the navigation entries, so must be called after
1648 // the commit.
1649 GenerateKeywordIfNecessary(params);
1650
1651 // Allow the new page to set the title again.
1652 received_page_title_ = false;
1653
1654 // Get the favicon, either from history or request it from the net.
1655 fav_icon_helper_.FetchFavIcon(details.entry->url());
1656
[email protected]0de80162010-02-03 04:52:351657 // Clear all page actions, blocked content notifications and browser actions
1658 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141659 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081660 ExtensionsService* service = profile()->GetExtensionsService();
1661 if (service) {
1662 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571663 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081664 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521665 if (browser_action) {
1666 browser_action->ClearAllValuesForTab(controller().session_id().id());
1667 NotificationService::current()->Notify(
1668 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571669 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521670 NotificationService::NoDetails());
1671 }
[email protected]92c6f9b92009-10-24 04:35:081672
[email protected]5d246db22009-10-27 06:17:571673 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521674 service->extensions()->at(i)->page_action();
1675 if (page_action) {
1676 page_action->ClearAllValuesForTab(controller().session_id().id());
1677 PageActionStateChanged();
1678 }
[email protected]92c6f9b92009-10-24 04:35:081679 }
[email protected]aece2c7f2009-08-27 20:43:171680 }
[email protected]0de80162010-02-03 04:52:351681
1682 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401683 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341684 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401685 blocked_contents_->Destroy();
1686 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351687 }
1688
1689 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411690 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551691 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471692
1693 // Once the main frame is navigated, we're no longer considered to have
1694 // displayed insecure content.
1695 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171696 }
[email protected]ce5c4502009-05-06 16:46:111697
[email protected]8cc8d492010-02-02 10:40:491698 // Close constrained windows if necessary.
1699 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1700 details.previous_url, details.entry->url()))
1701 CloseConstrainedWindows();
1702
[email protected]420ae012009-04-24 05:16:321703 // Update the starred state.
1704 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531705
1706 // Clear the cache of forms in AutoFill.
1707 if (autofill_manager_.get())
1708 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321709}
1710
1711void TabContents::DidNavigateAnyFramePostCommit(
1712 RenderViewHost* render_view_host,
1713 const NavigationController::LoadCommittedDetails& details,
1714 const ViewHostMsg_FrameNavigate_Params& params) {
1715 // If we navigate, start showing messages again. This does nothing to prevent
1716 // a malicious script from spamming messages, since the script could just
1717 // reload the page to stop blocking.
1718 suppress_javascript_messages_ = false;
1719
[email protected]420ae012009-04-24 05:16:321720 // Notify the password manager of the navigation or form submit.
1721 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1722 // cleaned up and covered by tests.
1723 if (params.password_form.origin.is_valid())
1724 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551725
1726 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581727 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321728}
1729
[email protected]8cc8d492010-02-02 10:40:491730void TabContents::CloseConstrainedWindows() {
1731 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321732 // We use indices instead of iterators in case CloseWindow does something
1733 // that may invalidate an iterator.
1734 int size = static_cast<int>(child_windows_.size());
1735 for (int i = size - 1; i >= 0; --i) {
1736 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441737 if (window) {
[email protected]420ae012009-04-24 05:16:321738 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441739 BlockTabContent(false);
1740 }
[email protected]420ae012009-04-24 05:16:321741 }
1742}
1743
1744void TabContents::UpdateStarredStateForCurrentURL() {
1745 BookmarkModel* model = profile()->GetBookmarkModel();
1746 const bool old_state = is_starred_;
1747 is_starred_ = (model && model->IsBookmarked(GetURL()));
1748
1749 if (is_starred_ != old_state && delegate())
1750 delegate()->URLStarredChanged(this, is_starred_);
1751}
1752
1753void TabContents::UpdateAlternateErrorPageURL() {
1754 GURL url = GetAlternateErrorPageURL();
1755 render_view_host()->SetAlternateErrorPageURL(url);
1756}
1757
1758void TabContents::UpdateWebPreferences() {
1759 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1760}
1761
1762void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1763 RenderViewHost* rvh) {
1764 // If we are creating a RVH for a restored controller, then we might
1765 // have more page IDs than the SiteInstance's current max page ID. We must
1766 // make sure that the max page ID is larger than any restored page ID.
1767 // Note that it is ok for conflicting page IDs to exist in another tab
1768 // (i.e., NavigationController), but if any page ID is larger than the max,
1769 // the back/forward list will get confused.
1770 int max_restored_page_id = controller_.max_restored_page_id();
1771 if (max_restored_page_id > 0) {
1772 int curr_max_page_id = site_instance->max_page_id();
1773 if (max_restored_page_id > curr_max_page_id) {
1774 // Need to update the site instance immediately.
1775 site_instance->UpdateMaxPageID(max_restored_page_id);
1776
1777 // Also tell the renderer to update its internal representation. We
1778 // need to reserve enough IDs to make all restored page IDs less than
1779 // the max.
1780 if (curr_max_page_id < 0)
1781 curr_max_page_id = 0;
1782 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1783 }
1784 }
1785}
1786
[email protected]ec0b6c42010-08-26 03:16:581787scoped_refptr<history::HistoryAddPageArgs>
1788TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541789 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471790 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321791 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581792 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1793 new history::HistoryAddPageArgs(
1794 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1795 params.redirects, params.transition, history::SOURCE_BROWSED,
1796 details.did_replace_entry));
1797 if (PageTransition::IsMainFrame(params.transition) &&
1798 virtual_url != params.url) {
1799 // Hack on the "virtual" URL so that it will appear in history. For some
1800 // types of URLs, we will display a magic URL that is different from where
1801 // the page is actually navigated. We want the user to see in history what
1802 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1803 // only applies to the main frame, as the virtual URL doesn't apply to
1804 // sub-frames.
1805 add_page_args->url = virtual_url;
1806 if (!add_page_args->redirects.empty())
1807 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321808 }
[email protected]ec0b6c42010-08-26 03:16:581809 return add_page_args;
[email protected]420ae012009-04-24 05:16:321810}
1811
1812bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1813 const std::wstring& title) {
1814 // For file URLs without a title, use the pathname instead. In the case of a
1815 // synthesized title, we don't want the update to count toward the "one set
1816 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251817 string16 final_title;
[email protected]420ae012009-04-24 05:16:321818 bool explicit_set;
1819 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251820 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321821 explicit_set = false; // Don't count synthetic titles toward the set limit.
1822 } else {
[email protected]e53668962010-06-23 15:35:251823 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321824 explicit_set = true;
1825 }
1826
[email protected]e53668962010-06-23 15:35:251827 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321828 return false; // Nothing changed, don't bother.
1829
[email protected]e53668962010-06-23 15:35:251830 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321831
[email protected]ec0b6c42010-08-26 03:16:581832 if (!received_page_title_) {
1833 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321834 received_page_title_ = explicit_set;
1835 }
1836
1837 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251838 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321839
[email protected]cbc0e1b2010-04-12 18:33:041840 NotificationService::current()->Notify(
1841 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1842 Source<TabContents>(this),
1843 NotificationService::NoDetails());
1844
[email protected]420ae012009-04-24 05:16:321845 return true;
1846}
1847
1848void TabContents::NotifySwapped() {
1849 // After sending out a swap notification, we need to send a disconnect
1850 // notification so that clients that pick up a pointer to |this| can NULL the
1851 // pointer. See Bug 1230284.
1852 notify_disconnection_ = true;
1853 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341854 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221855 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321856 NotificationService::NoDetails());
1857}
1858
1859void TabContents::NotifyConnected() {
1860 notify_disconnection_ = true;
1861 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341862 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221863 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321864 NotificationService::NoDetails());
1865}
1866
1867void TabContents::NotifyDisconnected() {
1868 if (!notify_disconnection_)
1869 return;
1870
1871 notify_disconnection_ = false;
1872 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341873 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221874 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321875 NotificationService::NoDetails());
1876}
1877
1878void TabContents::GenerateKeywordIfNecessary(
1879 const ViewHostMsg_FrameNavigate_Params& params) {
1880 if (!params.searchable_form_url.is_valid())
1881 return;
1882
1883 if (profile()->IsOffTheRecord())
1884 return;
1885
1886 int last_index = controller_.last_committed_entry_index();
1887 // When there was no previous page, the last index will be 0. This is
1888 // normally due to a form submit that opened in a new tab.
1889 // TODO(brettw) bug 916126: we should support keywords when form submits
1890 // happen in new tabs.
1891 if (last_index <= 0)
1892 return;
1893 const NavigationEntry* previous_entry =
1894 controller_.GetEntryAtIndex(last_index - 1);
1895 if (IsFormSubmit(previous_entry)) {
1896 // Only generate a keyword if the previous page wasn't itself a form
1897 // submit.
1898 return;
1899 }
1900
1901 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1902 previous_entry->user_typed_url() : previous_entry->url();
1903 std::wstring keyword =
1904 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1905 if (keyword.empty())
1906 return;
1907
1908 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1909 if (!url_model)
1910 return;
1911
1912 if (!url_model->loaded()) {
1913 url_model->Load();
1914 return;
1915 }
1916
1917 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191918 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321919 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1920 return;
1921
1922 if (current_url) {
1923 if (current_url->originating_url().is_valid()) {
1924 // The existing keyword was generated from an OpenSearch description
1925 // document, don't regenerate.
1926 return;
1927 }
1928 url_model->Remove(current_url);
1929 }
1930 TemplateURL* new_url = new TemplateURL();
1931 new_url->set_keyword(keyword);
1932 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191933 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321934 new_url->add_input_encoding(params.searchable_form_encoding);
1935 DCHECK(controller_.GetLastCommittedEntry());
1936 const GURL& favicon_url =
1937 controller_.GetLastCommittedEntry()->favicon().url();
1938 if (favicon_url.is_valid()) {
1939 new_url->SetFavIconURL(favicon_url);
1940 } else {
1941 // The favicon url isn't valid. This means there really isn't a favicon,
1942 // or the favicon url wasn't obtained before the load started. This assumes
1943 // the later.
1944 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1945 // its url.
1946 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1947 }
1948 new_url->set_safe_for_autoreplace(true);
1949 url_model->Add(new_url);
1950}
1951
[email protected]bf5c2ff392009-07-08 16:24:331952void TabContents::OnUserGesture() {
1953 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011954 DownloadRequestLimiter* limiter =
1955 g_browser_process->download_request_limiter();
1956 if (limiter)
1957 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261958 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331959}
1960
1961void TabContents::OnFindReply(int request_id,
1962 int number_of_matches,
1963 const gfx::Rect& selection_rect,
1964 int active_match_ordinal,
1965 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421966 // Ignore responses for requests that have been aborted.
1967 if (find_op_aborted_)
1968 return;
1969
[email protected]bf5c2ff392009-07-08 16:24:331970 // Ignore responses for requests other than the one we have most recently
1971 // issued. That way we won't act on stale results when the user has
1972 // already typed in another query.
1973 if (request_id != current_find_request_id_)
1974 return;
1975
1976 if (number_of_matches == -1)
1977 number_of_matches = last_search_result_.number_of_matches();
1978 if (active_match_ordinal == -1)
1979 active_match_ordinal = last_search_result_.active_match_ordinal();
1980
1981 gfx::Rect selection = selection_rect;
1982 if (selection.IsEmpty())
1983 selection = last_search_result_.selection_rect();
1984
1985 // Notify the UI, automation and any other observers that a find result was
1986 // found.
1987 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1988 selection, active_match_ordinal,
1989 final_update);
1990 NotificationService::current()->Notify(
1991 NotificationType::FIND_RESULT_AVAILABLE,
1992 Source<TabContents>(this),
1993 Details<FindNotificationDetails>(&last_search_result_));
1994}
1995
1996void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541997 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1998 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1999 if (!entry)
2000 return;
2001 // Note that we don't call NavigationController::GotToOffset() as we don't
2002 // want to create a pending navigation entry (it might end up lingering
2003 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522004 entry->set_transition_type(entry->transition_type() |
2005 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542006 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2007 }
[email protected]bf5c2ff392009-07-08 16:24:332008}
2009
[email protected]bf5c2ff392009-07-08 16:24:332010void TabContents::OnMissingPluginStatus(int status) {
2011#if defined(OS_WIN)
2012// TODO(PORT): pull in when plug-ins work
2013 GetPluginInstaller()->OnMissingPluginStatus(status);
2014#endif
2015}
2016
2017void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332018 DCHECK(!plugin_path.value().empty());
2019
2020 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:352021#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:332022 scoped_ptr<FileVersionInfo> version_info(
2023 FileVersionInfo::CreateFileVersionInfo(plugin_path));
2024 if (version_info.get()) {
2025 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:372026 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:332027 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:372028#if defined(OS_MACOSX)
2029 // Many plugins on the Mac have .plugin in the actual name, which looks
2030 // terrible, so look for that and strip it off if present.
2031 const std::wstring plugin_extension(L".plugin");
2032 if (EndsWith(plugin_name, plugin_extension, true))
2033 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2034#endif // OS_MACOSX
2035 }
[email protected]bf5c2ff392009-07-08 16:24:332036 }
[email protected]4a560ed2009-07-13 23:35:262037#else
2038 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2039#endif
[email protected]2ae8a922010-06-28 20:27:532040 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2041 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332042 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582043 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2044 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532045 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332046}
2047
2048void TabContents::OnCrashedWorker() {
2049 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582050 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422051 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332052}
2053
2054void TabContents::OnDidGetApplicationInfo(
2055 int32 page_id,
2056 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512057 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332058
[email protected]ed5431872009-11-17 08:39:512059 if (delegate())
2060 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332061}
2062
[email protected]851b1eb2010-08-09 13:32:292063void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2064 const GURL& update_url) {
2065 new DisabledPluginInfoBar(this, name, update_url);
2066}
2067
[email protected]a2cf65eb2010-01-18 08:20:382068void TabContents::OnPageContents(const GURL& url,
2069 int renderer_process_id,
2070 int32 page_id,
[email protected]e5106202010-06-11 21:12:362071 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102072 const std::string& language,
2073 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382074 // Don't index any https pages. People generally don't want their bank
2075 // accounts, etc. indexed on their computer, especially since some of these
2076 // things are not marked cachable.
2077 // TODO(brettw) we may want to consider more elaborate heuristics such as
2078 // the cachability of the page. We may also want to consider subframes (this
2079 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272080 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2081 // content indexing for chromeos in some future releases.
2082#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382083 if (!url.SchemeIsSecure()) {
2084 Profile* p = profile();
2085 if (p && !p->IsOffTheRecord()) {
2086 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2087 if (hs)
2088 hs->SetPageContents(url, contents);
2089 }
2090 }
[email protected]ccd40a52010-05-11 16:15:272091#endif
[email protected]a8a81292010-01-21 00:32:452092
[email protected]1c57b7b2010-07-12 17:38:102093 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452094
2095 std::string lang = language;
2096 NotificationService::current()->Notify(
2097 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152098 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452099 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382100}
2101
[email protected]7e0831b2010-02-01 08:45:152102void TabContents::OnPageTranslated(int32 page_id,
2103 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162104 const std::string& translated_lang,
2105 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552106 language_state_.set_current_language(translated_lang);
2107 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162108 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152109 NotificationService::current()->Notify(
2110 NotificationType::PAGE_TRANSLATED,
2111 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162112 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152113}
2114
[email protected]15d9c0c2010-09-10 22:36:262115void TabContents::OnSetSuggestResult(int32 page_id, const std::string& result) {
2116 if (delegate())
2117 delegate()->OnSetSuggestResult(page_id, result);
2118}
2119
[email protected]bf5c2ff392009-07-08 16:24:332120void TabContents::DidStartProvisionalLoadForFrame(
2121 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072122 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332123 bool is_main_frame,
2124 const GURL& url) {
2125 ProvisionalLoadDetails details(is_main_frame,
2126 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072127 url, std::string(), false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332128 NotificationService::current()->Notify(
2129 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2130 Source<NavigationController>(&controller_),
2131 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142132 if (is_main_frame) {
[email protected]da4f8a12010-08-19 08:33:412133 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142134 content_settings_delegate_->ClearGeolocationContentSettings();
2135 }
[email protected]bf5c2ff392009-07-08 16:24:332136}
2137
2138void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202139 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332140 NotificationService::current()->Notify(
2141 NotificationType::RESOURCE_RESPONSE_STARTED,
2142 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202143 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332144}
2145
[email protected]3dbb80b2010-02-09 22:41:202146void TabContents::DidRedirectResource(
2147 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332148 NotificationService::current()->Notify(
2149 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2150 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202151 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332152}
2153
2154void TabContents::DidLoadResourceFromMemoryCache(
2155 const GURL& url,
2156 const std::string& frame_origin,
2157 const std::string& main_frame_origin,
2158 const std::string& security_info) {
2159 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442160 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332161 SSLManager::DeserializeSecurityInfo(security_info,
2162 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042163 &security_bits,
2164 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332165 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162166 GetRenderProcessHost()->id(), cert_id,
2167 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332168
2169 NotificationService::current()->Notify(
2170 NotificationType::LOAD_FROM_MEMORY_CACHE,
2171 Source<NavigationController>(&controller_),
2172 Details<LoadFromMemoryCacheDetails>(&details));
2173}
2174
[email protected]e3d60e5d2009-09-25 21:08:292175void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472176 displayed_insecure_content_ = true;
2177 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292178}
2179
2180void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592181 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292182}
2183
[email protected]bf5c2ff392009-07-08 16:24:332184void TabContents::DidFailProvisionalLoadWithError(
2185 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072186 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332187 bool is_main_frame,
2188 int error_code,
2189 const GURL& url,
2190 bool showing_repost_interstitial) {
2191 if (net::ERR_ABORTED == error_code) {
2192 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2193 // This means that the interstitial won't be torn down properly, which is
2194 // bad. But if we have an interstitial, go back to another tab type, and
2195 // then load the same interstitial again, we could end up getting the first
2196 // interstitial's "failed" message (as a result of the cancel) when we're on
2197 // the second one.
2198 //
2199 // We can't tell this apart, so we think we're tearing down the current page
2200 // which will cause a crash later one. There is also some code in
2201 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2202 // out because of this problem.
2203 //
2204 // http://code.google.com/p/chromium/issues/detail?id=2855
2205 // Because this will not tear down the interstitial properly, if "back" is
2206 // back to another tab type, the interstitial will still be somewhat alive
2207 // in the previous tab type. If you navigate somewhere that activates the
2208 // tab with the interstitial again, you'll see a flash before the new load
2209 // commits of the interstitial page.
2210 if (showing_interstitial_page()) {
2211 LOG(WARNING) << "Discarding message during interstitial.";
2212 return;
2213 }
2214
2215 // This will discard our pending entry if we cancelled the load (e.g., if we
2216 // decided to download the file instead of load it). Only discard the
2217 // pending entry if the URLs match, otherwise the user initiated a navigate
2218 // before the page loaded so that the discard would discard the wrong entry.
2219 NavigationEntry* pending_entry = controller_.pending_entry();
2220 if (pending_entry && pending_entry->url() == url) {
2221 controller_.DiscardNonCommittedEntries();
2222 // Update the URL display.
2223 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2224 }
2225
2226 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2227 }
2228
2229 // Send out a notification that we failed a provisional load with an error.
2230 ProvisionalLoadDetails details(is_main_frame,
2231 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072232 url, std::string(), false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332233 details.set_error_code(error_code);
2234
2235 NotificationService::current()->Notify(
2236 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2237 Source<NavigationController>(&controller_),
2238 Details<ProvisionalLoadDetails>(&details));
2239}
2240
2241void TabContents::DocumentLoadedInFrame() {
2242 controller_.DocumentLoadedInFrame();
2243}
2244
[email protected]dcd5b332010-08-11 08:55:182245void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562246 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242247 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562248}
2249
[email protected]8d3347f2009-07-09 22:00:212250RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322251 return view_.get();
2252}
2253
[email protected]8d3347f2009-07-09 22:00:212254RenderViewHostDelegate::RendererManagement*
2255TabContents::GetRendererManagementDelegate() {
2256 return &render_manager_;
2257}
2258
[email protected]bf5c2ff392009-07-08 16:24:332259RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212260 TabContents::GetBrowserIntegrationDelegate() {
2261 return this;
[email protected]bf5c2ff392009-07-08 16:24:332262}
2263
[email protected]8d3347f2009-07-09 22:00:212264RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2265 return this;
[email protected]bf5c2ff392009-07-08 16:24:332266}
2267
[email protected]46ba9082010-06-22 10:00:582268RenderViewHostDelegate::ContentSettings*
2269TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552270 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582271}
2272
[email protected]8d3347f2009-07-09 22:00:212273RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322274 return save_package_.get(); // May be NULL, but we can return NULL.
2275}
2276
[email protected]8d3347f2009-07-09 22:00:212277RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092278 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212279}
2280
2281RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2282 return &fav_icon_helper_;
2283}
2284
[email protected]e8dbd674b2010-03-11 18:34:402285RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452286 if (autocomplete_history_manager_.get() == NULL)
2287 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2288 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332289}
2290
[email protected]21674df2009-10-28 19:51:212291RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342292 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212293}
2294
[email protected]aad51d1c2010-08-05 08:38:092295RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2296 if (blocked_plugin_manager_.get() == NULL)
2297 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2298 return blocked_plugin_manager_.get();
2299}
2300
[email protected]1f18184a2010-07-21 19:34:492301RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2302 return GetSSLHelper();
2303}
2304
[email protected]b5977a0c2010-08-24 19:46:262305RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2306 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492307 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262308 return file_select_helper_.get();
2309}
2310
[email protected]fd571bb2010-03-19 01:23:542311AutomationResourceRoutingDelegate*
2312TabContents::GetAutomationResourceRoutingDelegate() {
2313 return delegate();
2314}
2315
[email protected]ced90ae12010-02-20 02:06:162316RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2317 return bookmark_drag_;
2318}
2319
2320void TabContents::SetBookmarkDragDelegate(
2321 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2322 bookmark_drag_ = bookmark_drag;
2323}
2324
[email protected]9fb83e82010-07-02 18:24:552325TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2326 return content_settings_delegate_.get();
2327}
2328
[email protected]93623c5d2009-12-10 21:40:322329RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462330 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512331}
2332
[email protected]57c6a652009-05-04 07:58:342333TabContents* TabContents::GetAsTabContents() {
2334 return this;
2335}
2336
[email protected]7b291f92009-08-14 05:43:532337ViewType::Type TabContents::GetRenderViewType() const {
2338 return ViewType::TAB_CONTENTS;
2339}
2340
2341int TabContents::GetBrowserWindowID() const {
2342 return controller().window_id().id();
2343}
2344
[email protected]420ae012009-04-24 05:16:322345void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062346 NotificationService::current()->Notify(
2347 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2348 Source<TabContents>(this),
2349 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322350 NavigationEntry* entry = controller_.GetActiveEntry();
2351 if (!entry)
2352 return;
2353
2354 // When we're creating views, we're still doing initial setup, so we always
2355 // use the pending DOM UI rather than any possibly existing committed one.
2356 if (render_manager_.pending_dom_ui()) {
2357 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2358 }
2359
2360 if (entry->IsViewSourceMode()) {
2361 // Put the renderer in view source mode.
2362 render_view_host->Send(
2363 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2364 }
[email protected]0666aef2009-05-13 19:48:082365
2366 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322367}
2368
2369void TabContents::RenderViewReady(RenderViewHost* rvh) {
2370 if (rvh != render_view_host()) {
2371 // Don't notify the world, since this came from a renderer in the
2372 // background.
2373 return;
2374 }
2375
2376 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302377 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322378 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302379
2380 // Restore the focus to the tab (otherwise the focus will be on the top
2381 // window).
[email protected]484ae5912010-09-29 19:16:142382 if (was_crashed && !FocusLocationBarByDefault() &&
2383 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302384 Focus();
[email protected]484ae5912010-09-29 19:16:142385 }
[email protected]420ae012009-04-24 05:16:322386}
2387
2388void TabContents::RenderViewGone(RenderViewHost* rvh) {
2389 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092390 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322391 return;
2392 if (rvh != render_view_host()) {
2393 // The pending page's RenderViewHost is gone.
2394 return;
2395 }
2396
2397 SetIsLoading(false, NULL);
2398 NotifyDisconnected();
2399 SetIsCrashed(true);
2400
[email protected]ff9efc62010-02-18 22:10:542401 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212402 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542403 RemoveInfoBar(GetInfoBarDelegateAt(i));
2404
[email protected]8e537302009-06-10 21:19:582405 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552406 // Only do this if we're not in browser shutdown, so that TabContents
2407 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2408 // visible do not flash a sad tab page.
2409 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2410 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322411
2412 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002413 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322414}
2415
[email protected]2e4633c2009-07-09 16:58:062416void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2417 NotificationService::current()->Notify(
2418 NotificationType::RENDER_VIEW_HOST_DELETED,
2419 Source<TabContents>(this),
2420 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482421 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062422}
2423
[email protected]420ae012009-04-24 05:16:322424void TabContents::DidNavigate(RenderViewHost* rvh,
2425 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372426 int extra_invalidate_flags = 0;
2427
2428 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352429 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372430
[email protected]420ae012009-04-24 05:16:322431 render_manager_.DidNavigateMainFrame(rvh);
2432
[email protected]20ede072009-10-06 00:28:352433 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372434 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372435 }
2436
[email protected]420ae012009-04-24 05:16:322437 // Update the site of the SiteInstance if it doesn't have one yet.
2438 if (!GetSiteInstance()->has_site())
2439 GetSiteInstance()->SetSite(params.url);
2440
2441 // Need to update MIME type here because it's referred to in
2442 // UpdateNavigationCommands() called by RendererDidNavigate() to
2443 // determine whether or not to enable the encoding menu.
2444 // It's updated only for the main frame. For a subframe,
2445 // RenderView::UpdateURL does not set params.contents_mime_type.
2446 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2447 // TODO(jungshik): Add a test for the encoding menu to avoid
2448 // regressing it again.
2449 if (PageTransition::IsMainFrame(params.transition))
2450 contents_mime_type_ = params.contents_mime_type;
2451
2452 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372453 bool did_navigate = controller_.RendererDidNavigate(
2454 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392455
[email protected]a9c0bfe2010-09-17 08:35:222456 // Send notification about committed provisional loads. This notification is
2457 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2458 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2459 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072460 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2461 // that is not recorded in the navigation history. For the purpose of
2462 // tracking navigation events, we treat this event as a sub frame navigation
2463 // event.
2464 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2465 ProvisionalLoadDetails load_details(
2466 is_main_frame, details.is_in_page, params.url, std::string(), false,
2467 params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222468 load_details.set_transition_type(params.transition);
2469 // Whether or not a page transition was triggered by going backward or
2470 // forward in the history is only stored in the navigation controller's
2471 // entry list.
2472 if (did_navigate &&
2473 (controller_.GetActiveEntry()->transition_type() &
2474 PageTransition::FORWARD_BACK)) {
2475 load_details.set_transition_type(
2476 params.transition | PageTransition::FORWARD_BACK);
2477 }
2478 NotificationService::current()->Notify(
2479 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2480 Source<NavigationController>(&controller_),
2481 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222482 }
2483
[email protected]3e90d4a2009-07-03 17:38:392484 // Update history. Note that this needs to happen after the entry is complete,
2485 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582486 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392487 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582488 // URLs, we use a data: URL as the real value. We actually want to save the
2489 // about: URL to the history db and keep the data: URL hidden. This is what
2490 // the TabContents' URL getter does.
2491 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2492 CreateHistoryAddPageArgs(GetURL(), details, params));
2493 if (!delegate() ||
2494 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2495 details.type)) {
2496 UpdateHistoryForNavigation(add_page_args);
2497 }
[email protected]3e90d4a2009-07-03 17:38:392498 }
2499
[email protected]76543b92009-08-31 17:27:452500 if (!did_navigate)
2501 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322502
2503 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2504 // for the appropriate notification (best) or you can add it to
2505 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2506 // necessary, please).
2507
2508 // Run post-commit tasks.
2509 if (details.is_main_frame)
2510 DidNavigateMainFramePostCommit(details, params);
2511 DidNavigateAnyFramePostCommit(rvh, details, params);
2512}
2513
2514void TabContents::UpdateState(RenderViewHost* rvh,
2515 int32 page_id,
2516 const std::string& state) {
2517 DCHECK(rvh == render_view_host());
2518
2519 // We must be prepared to handle state updates for any page, these occur
2520 // when the user is scrolling and entering form data, as well as when we're
2521 // leaving a page, in which case our state may have already been moved to
2522 // the next page. The navigation controller will look up the appropriate
2523 // NavigationEntry and update it when it is notified via the delegate.
2524
2525 int entry_index = controller_.GetEntryIndexWithPageID(
2526 GetSiteInstance(), page_id);
2527 if (entry_index < 0)
2528 return;
2529 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2530
2531 if (state == entry->content_state())
2532 return; // Nothing to update.
2533 entry->set_content_state(state);
2534 controller_.NotifyEntryChanged(entry, entry_index);
2535}
2536
2537void TabContents::UpdateTitle(RenderViewHost* rvh,
2538 int32 page_id, const std::wstring& title) {
2539 // If we have a title, that's a pretty good indication that we've started
2540 // getting useful data.
2541 SetNotWaitingForResponse();
2542
2543 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482544 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582545 page_id);
[email protected]420ae012009-04-24 05:16:322546 if (!entry || !UpdateTitleForEntry(entry, title))
2547 return;
2548
2549 // Broadcast notifications when the UI should be updated.
2550 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032551 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322552}
2553
[email protected]420ae012009-04-24 05:16:322554void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402555 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322556 set_encoding(encoding);
2557}
2558
2559void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2560 if (delegate())
2561 delegate()->UpdateTargetURL(this, url);
2562}
2563
2564void TabContents::UpdateThumbnail(const GURL& url,
2565 const SkBitmap& bitmap,
2566 const ThumbnailScore& score) {
2567 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492568 if (history::TopSites::IsEnabled()) {
[email protected]72d0fc72009-07-09 17:30:492569 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422570 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282571 } else {
2572 HistoryService* hs;
2573 if (!profile()->IsOffTheRecord() &&
2574 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2575 hs->SetPageThumbnail(url, bitmap, score);
2576 }
[email protected]420ae012009-04-24 05:16:322577 }
2578}
2579
[email protected]c4e98902010-06-01 10:20:142580void TabContents::UpdateInspectorSetting(const std::string& key,
2581 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052582 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082583}
2584
[email protected]45aafc92010-06-07 14:18:532585void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052586 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532587}
2588
[email protected]420ae012009-04-24 05:16:322589void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292590 // The UI may be in an event-tracking loop, such as between the
2591 // mouse-down and mouse-up in text selection or a button click.
2592 // Defer the close until after tracking is complete, so that we
2593 // don't free objects out from under the UI.
2594 // TODO(shess): This could probably be integrated with the
2595 // IsDoingDrag() test below. Punting for now because I need more
2596 // research to understand how this impacts platforms other than Mac.
2597 // TODO(shess): This could get more fine-grained. For instance,
2598 // closing a tab in another window while selecting text in the
2599 // current window's Omnibox should be just fine.
2600 if (view()->IsEventTracking()) {
2601 view()->CloseTabAfterEventTracking();
2602 return;
2603 }
2604
[email protected]24a4d1062009-07-10 23:10:422605 // If we close the tab while we're in the middle of a drag, we'll crash.
2606 // Instead, cancel the drag and close it as soon as the drag ends.
2607 if (view()->IsDoingDrag()) {
2608 view()->CancelDragAndCloseTab();
2609 return;
2610 }
2611
[email protected]420ae012009-04-24 05:16:322612 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2613 if (delegate() && rvh == render_view_host())
2614 delegate()->CloseContents(this);
2615}
2616
2617void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2618 if (delegate() && delegate()->IsPopup(this))
2619 delegate()->MoveContents(this, new_bounds);
2620}
2621
[email protected]7ab1e7d62009-10-14 23:32:012622void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322623 SetIsLoading(true, NULL);
[email protected]9e823662010-10-13 23:36:002624 if (content_restrictions_) {
2625 content_restrictions_= 0;
2626 delegate()->ContentRestrictionsChanged(this);
2627 }
[email protected]420ae012009-04-24 05:16:322628}
2629
[email protected]7ab1e7d62009-10-14 23:32:012630void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322631 scoped_ptr<LoadNotificationDetails> details;
2632
2633 NavigationEntry* entry = controller_.GetActiveEntry();
2634 // An entry may not exist for a stop when loading an initial blank page or
2635 // if an iframe injected by script into a blank page finishes loading.
2636 if (entry) {
[email protected]420ae012009-04-24 05:16:322637 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2638
2639 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542640 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322641 entry->transition_type(),
2642 elapsed,
2643 &controller_,
2644 controller_.GetCurrentEntryIndex()));
2645 }
2646
2647 // Tell PasswordManager we've finished a page load, which serves as a
2648 // green light to save pending passwords and reset itself.
2649 GetPasswordManager()->DidStopLoading();
2650
2651 SetIsLoading(false, details.get());
2652}
2653
[email protected]25497492010-09-11 15:15:082654void TabContents::DocumentOnLoadCompletedInMainFrame(
2655 RenderViewHost* render_view_host,
2656 int32 page_id) {
2657 NotificationService::current()->Notify(
2658 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2659 Source<TabContents>(this),
2660 Details<int>(&page_id));
2661}
2662
[email protected]420ae012009-04-24 05:16:322663void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2664 const GURL& source_url,
2665 const GURL& target_url) {
2666 NavigationEntry* entry;
2667 if (page_id == -1)
2668 entry = controller_.pending_entry();
2669 else
2670 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2671 if (!entry || entry->url() != source_url)
2672 return;
2673 entry->set_url(target_url);
2674}
2675
[email protected]420ae012009-04-24 05:16:322676void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2677 WindowOpenDisposition disposition) {
2678 if (render_manager_.dom_ui()) {
2679 // When we're a DOM UI, it will provide a page transition type for us (this
2680 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2681 // generated suggestions).
2682 //
2683 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162684 // want web sites to see a referrer of "chrome://blah" (and some
2685 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322686 // send to the site), so we send no referrer.
2687 OpenURL(url, GURL(), disposition,
2688 render_manager_.dom_ui()->link_transition_type());
2689 } else {
2690 OpenURL(url, referrer, disposition, PageTransition::LINK);
2691 }
2692}
2693
[email protected]1ee614862009-07-06 20:29:182694void TabContents::DomOperationResponse(const std::string& json_string,
2695 int automation_id) {
2696}
2697
[email protected]8b8e7c92010-08-19 18:05:562698void TabContents::ProcessDOMUIMessage(
2699 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322700 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442701 // This can happen if someone uses window.open() to open an extension URL
2702 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562703 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322704 return;
2705 }
[email protected]8b8e7c92010-08-19 18:05:562706 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322707}
2708
2709void TabContents::ProcessExternalHostMessage(const std::string& message,
2710 const std::string& origin,
2711 const std::string& target) {
2712 if (delegate())
2713 delegate()->ForwardMessageToExternalHost(message, origin, target);
2714}
2715
[email protected]420ae012009-04-24 05:16:322716void TabContents::RunJavaScriptMessage(
2717 const std::wstring& message,
2718 const std::wstring& default_prompt,
2719 const GURL& frame_url,
2720 const int flags,
2721 IPC::Message* reply_msg,
2722 bool* did_suppress_message) {
2723 // Suppress javascript messages when requested and when inside a constrained
2724 // popup window (because that activates them and breaks them out of the
2725 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552726 // Also suppress messages when showing an interstitial. The interstitial is
2727 // shown over the previous page, we don't want the hidden page dialogs to
2728 // interfere with the interstitial.
2729 bool suppress_this_message = suppress_javascript_messages_ ||
2730 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322731 if (delegate())
2732 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312733 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322734
2735 *did_suppress_message = suppress_this_message;
2736
2737 if (!suppress_this_message) {
2738 base::TimeDelta time_since_last_message(
2739 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2740 bool show_suppress_checkbox = false;
2741 // Show a checkbox offering to suppress further messages if this message is
2742 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2743 if (time_since_last_message <
2744 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2745 show_suppress_checkbox = true;
2746
[email protected]d6ad7442010-09-05 19:06:522747 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2748 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322749 } else {
2750 // If we are suppressing messages, just reply as is if the user immediately
2751 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542752 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322753 }
2754}
2755
2756void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2757 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012758 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222759 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322760}
2761
2762void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2763 const std::string& json_arguments,
2764 IPC::Message* reply_msg) {
2765 if (delegate()) {
2766 HtmlDialogUIDelegate* dialog_delegate =
2767 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222768 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322769 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2770 }
2771}
2772
[email protected]4d44a1c2010-04-28 19:20:412773void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562774 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412775 GetPasswordManager()->PasswordFormsFound(forms);
2776}
2777
2778void TabContents::PasswordFormsVisible(
2779 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2780 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322781}
2782
[email protected]420ae012009-04-24 05:16:322783// Checks to see if we should generate a keyword based on the OSDD, and if
2784// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202785void TabContents::PageHasOSDD(
2786 RenderViewHost* render_view_host,
2787 int32 page_id,
2788 const GURL& url,
2789 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122790 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322791 DCHECK(url.is_valid());
2792 if (!IsActiveEntry(page_id))
2793 return;
[email protected]420ae012009-04-24 05:16:322794 if (!profile()->GetTemplateURLFetcher())
2795 return;
[email protected]420ae012009-04-24 05:16:322796 if (profile()->IsOffTheRecord())
2797 return;
2798
[email protected]2de7e002010-10-11 22:58:202799 TemplateURLFetcher::ProviderType provider_type;
2800 switch (msg_provider_type.type) {
2801 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2802 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2803 break;
2804
2805 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2806 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2807 break;
2808
2809 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2810 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2811 break;
2812
2813 default:
2814 NOTREACHED();
2815 return;
2816 }
2817
[email protected]420ae012009-04-24 05:16:322818 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2819 DCHECK(entry);
2820
2821 const NavigationEntry* base_entry = entry;
2822 if (IsFormSubmit(base_entry)) {
2823 // If the current page is a form submit, find the last page that was not
2824 // a form submit and use its url to generate the keyword from.
2825 int index = controller_.last_committed_entry_index() - 1;
2826 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2827 index--;
2828 if (index >= 0)
2829 base_entry = controller_.GetEntryAtIndex(index);
2830 else
2831 base_entry = NULL;
2832 }
2833
2834 // We want to use the user typed URL if available since that represents what
2835 // the user typed to get here, and fall back on the regular URL if not.
2836 if (!base_entry)
2837 return;
2838 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2839 base_entry->user_typed_url() : base_entry->url();
2840 if (!keyword_url.is_valid())
2841 return;
[email protected]2de7e002010-10-11 22:58:202842
[email protected]0b5b85c2010-10-11 23:00:122843 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2844 keyword_url,
2845 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532846
[email protected]0b5b85c2010-10-11 23:00:122847 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322848 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322849 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2850 keyword,
2851 url,
2852 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122853 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202854 provider_type);
[email protected]420ae012009-04-24 05:16:322855}
2856
[email protected]420ae012009-04-24 05:16:322857GURL TabContents::GetAlternateErrorPageURL() const {
2858 GURL url;
2859 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2860 if (profile()->IsOffTheRecord())
2861 return url;
2862
2863 PrefService* prefs = profile()->GetPrefs();
2864 DCHECK(prefs);
2865 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152866 url = google_util::AppendGoogleLocaleParam(
2867 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322868 url = google_util::AppendGoogleTLDParam(url);
2869 }
2870 return url;
2871}
2872
2873WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062874 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552875 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082876 WebPreferences web_prefs =
2877 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2878
[email protected]9beff752010-09-22 19:35:432879 // Force accelerated compositing and 2d canvas off for chrome: and
2880 // chrome-extension: pages.
[email protected]447021c2010-09-08 21:29:082881 if (GetURL().SchemeIs(chrome::kChromeUIScheme) ||
2882 GetURL().SchemeIs(chrome::kExtensionScheme)) {
2883 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432884 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082885 }
2886
[email protected]39553442010-09-09 00:01:552887#if defined(OS_MACOSX)
2888 // Disable accelerated compositing if IOSurface's are not supported,
2889 // as is the case in 10.5.
2890 if (!IOSurfaceSupport::Initialize())
2891 web_prefs.accelerated_compositing_enabled = false;
2892#endif
2893
[email protected]447021c2010-09-08 21:29:082894 return web_prefs;
[email protected]420ae012009-04-24 05:16:322895}
2896
[email protected]fa1cf0b82010-01-15 21:49:442897void TabContents::OnIgnoredUIEvent() {
2898 if (constrained_window_count()) {
2899 ConstrainedWindow* window = *constrained_window_begin();
2900 window->FocusConstrainedWindow();
2901 }
2902}
2903
[email protected]420ae012009-04-24 05:16:322904void TabContents::OnJSOutOfMemory() {
2905 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582906 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2907 NULL, true));
[email protected]420ae012009-04-24 05:16:322908}
2909
[email protected]420ae012009-04-24 05:16:322910void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2911 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342912 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322913 // delivered to a pending RenderViewHost. We must first run the onunload
2914 // handler of the old RenderViewHost before we can allow it to proceed.
2915 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2916 new_request_id);
2917}
2918
[email protected]420ae012009-04-24 05:16:322919gfx::Rect TabContents::GetRootWindowResizerRect() const {
2920 if (delegate())
2921 return delegate()->GetRootWindowResizerRect();
2922 return gfx::Rect();
2923}
2924
2925void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2926 bool is_during_unload) {
2927 if (is_during_unload) {
2928 // Hang occurred while firing the beforeunload/unload handler.
2929 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112930 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322931
2932 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2933 return;
2934
2935 // If the tab hangs in the beforeunload/unload handler there's really
2936 // nothing we can do to recover. Pretend the unload listeners have
2937 // all fired and close the tab. If the hang is in the beforeunload handler
2938 // then the user will not have the option of cancelling the close.
2939 Close(rvh);
2940 return;
2941 }
2942
2943 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002944 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322945}
2946
2947void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002948 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322949}
2950
2951void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562952 net::LoadState load_state,
2953 uint64 upload_position,
2954 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322955 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562956 upload_position_ = upload_position;
2957 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292958 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192959 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292960 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532961 load_state_host_ =
2962 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322963 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2964 SetNotWaitingForResponse();
2965 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502966 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322967}
2968
[email protected]1ee614862009-07-06 20:29:182969bool TabContents::IsExternalTabContainer() const {
2970 if (!delegate())
2971 return false;
2972
2973 return delegate()->IsExternalTabContainer();
2974}
2975
[email protected]1ee614862009-07-06 20:29:182976void TabContents::DidInsertCSS() {
2977 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322978}
2979
[email protected]130efb02009-09-18 18:54:352980void TabContents::FocusedNodeChanged() {
2981 NotificationService::current()->Notify(
2982 NotificationType::FOCUS_CHANGED_IN_PAGE,
2983 Source<RenderViewHost>(render_view_host()),
2984 NotificationService::NoDetails());
2985}
2986
[email protected]b75b8292010-10-01 07:28:252987void TabContents::UpdateZoomLimits(int minimum_percent,
2988 int maximum_percent,
2989 bool remember) {
2990 minimum_zoom_percent_ = minimum_percent;
2991 maximum_zoom_percent_ = maximum_percent;
2992 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382993}
2994
[email protected]9e823662010-10-13 23:36:002995void TabContents::UpdateContentRestrictions(int restrictions) {
2996 content_restrictions_ = restrictions;
2997 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:322998}
2999
[email protected]420ae012009-04-24 05:16:323000void TabContents::BeforeUnloadFiredFromRenderManager(
3001 bool proceed,
3002 bool* proceed_to_fire_unload) {
3003 if (delegate())
3004 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3005}
3006
[email protected]3a3d47472010-07-15 21:03:543007void TabContents::DidStartLoadingFromRenderManager(
3008 RenderViewHost* render_view_host) {
3009 DidStartLoading();
3010}
3011
3012void TabContents::RenderViewGoneFromRenderManager(
3013 RenderViewHost* render_view_host) {
3014 RenderViewGone(render_view_host);
3015}
3016
[email protected]420ae012009-04-24 05:16:323017void TabContents::UpdateRenderViewSizeForRenderManager() {
3018 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263019 gfx::Size size = view_->GetContainerSize();
3020 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3021 // here during container initialization and normal window size will be set
3022 // later. In case of tab duplication this resizing to 0x0 prevents setting
3023 // normal size later so just ignore it.
3024 if (!size.IsEmpty())
3025 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323026}
3027
[email protected]3a3d47472010-07-15 21:03:543028void TabContents::NotifySwappedFromRenderManager() {
3029 NotifySwapped();
3030}
3031
3032NavigationController& TabContents::GetControllerForRenderManager() {
3033 return controller();
3034}
3035
[email protected]420ae012009-04-24 05:16:323036DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223037 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323038}
3039
3040NavigationEntry*
3041TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3042 return controller_.GetLastCommittedEntry();
3043}
3044
3045bool TabContents::CreateRenderViewForRenderManager(
3046 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323047 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523048
[email protected]674b3822010-08-04 04:02:513049 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323050 return false;
3051
3052 // Now that the RenderView has been created, we need to tell it its size.
3053 rwh_view->SetSize(view_->GetContainerSize());
3054
3055 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3056 render_view_host);
3057 return true;
3058}
3059
3060void TabContents::Observe(NotificationType type,
3061 const NotificationSource& source,
3062 const NotificationDetails& details) {
3063 switch (type.value) {
3064 case NotificationType::BOOKMARK_MODEL_LOADED:
3065 // BookmarkModel finished loading, fall through to update starred state.
3066 case NotificationType::URLS_STARRED: {
3067 // Somewhere, a URL has been starred.
3068 // Ignore notifications for profiles other than our current one.
3069 Profile* source_profile = Source<Profile>(source).ptr();
3070 if (!source_profile || !source_profile->IsSameProfile(profile()))
3071 return;
3072
3073 UpdateStarredStateForCurrentURL();
3074 break;
3075 }
3076 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513077 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323078 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3079 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3080 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533081 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3082 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323083 UpdateWebPreferences();
3084 } else {
3085 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3086 }
3087 break;
3088 }
3089 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3090 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3091 break;
3092
3093 case NotificationType::NAV_ENTRY_COMMITTED: {
3094 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3095
3096 NavigationController::LoadCommittedDetails& committed_details =
3097 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3098 ExpireInfoBars(committed_details);
3099 break;
3100 }
3101
[email protected]d3ba77272009-09-03 00:06:093102#if defined(OS_LINUX)
3103 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543104 renderer_preferences_util::UpdateFromSystemSettings(
3105 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093106 render_view_host()->SyncRendererPrefs();
3107 break;
3108 }
3109#endif
3110
[email protected]6c32ce72010-03-08 05:18:063111 case NotificationType::USER_STYLE_SHEET_UPDATED:
3112 UpdateWebPreferences();
3113 break;
3114
[email protected]79580c62010-02-02 02:36:253115 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293116 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253117 settings_details(details);
[email protected]79580c62010-02-02 02:36:253118 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493119 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293120 if (entry)
[email protected]da0c8e92010-02-09 23:25:493121 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293122 if (settings_details.ptr()->update_all() ||
3123 settings_details.ptr()->pattern().Matches(entry_url)) {
3124 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233125 profile()->GetHostContentSettingsMap()->
3126 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253127 }
3128 break;
3129 }
3130
[email protected]e5adff72010-06-14 18:13:063131 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573132 break;
[email protected]a888b29e62010-04-01 13:38:573133
3134 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063135 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573136 break;
[email protected]a888b29e62010-04-01 13:38:573137
[email protected]88152052010-10-01 04:05:183138 case NotificationType::GOOGLE_URL_UPDATED:
3139 UpdateAlternateErrorPageURL();
3140 break;
3141
[email protected]420ae012009-04-24 05:16:323142 default:
3143 NOTREACHED();
3144 }
3145}
[email protected]aacd7cc2009-09-02 14:51:103146
[email protected]98aa0b52010-05-06 17:03:083147void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3148 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433149
[email protected]a888b29e62010-04-01 13:38:573150 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083151 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3152 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573153 extension,
[email protected]807871f2010-09-16 01:04:483154 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3155 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573156 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3157 Extension::EXTENSION_ICON_SMALLISH),
3158 ImageLoadingTracker::CACHE);
3159 } else {
[email protected]98aa0b52010-05-06 17:03:083160 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573161 }
3162}
3163
3164Extension* TabContents::GetExtensionContaining(const GURL& url) {
3165 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3166 if (!extensions_service)
3167 return NULL;
3168
3169 Extension* extension = extensions_service->GetExtensionByURL(url);
3170 return extension ?
3171 extension : extensions_service->GetExtensionByWebExtent(url);
3172}
3173
[email protected]a888b29e62010-04-01 13:38:573174void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3175 int index) {
3176 if (image) {
[email protected]98aa0b52010-05-06 17:03:083177 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573178 NotifyNavigationStateChanged(INVALIDATE_TAB);
3179 }
3180}
3181
[email protected]beb440c2009-11-06 04:08:543182gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3183 return view_->GetTopLevelNativeWindow();
3184}
3185
3186void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3187 bool success,
3188 const std::wstring& prompt) {
3189 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3190 if (is_showing_before_unload_dialog_ && !success) {
3191 // If a beforeunload dialog is canceled, we need to stop the throbber from
3192 // spinning, since we forced it to start spinning in Navigate.
3193 DidStopLoading();
3194
3195 tab_close_start_time_ = base::TimeTicks();
3196 }
3197 is_showing_before_unload_dialog_ = false;
3198 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3199}
3200
3201void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3202 set_suppress_javascript_messages(suppress_message_boxes);
3203}
3204
[email protected]3a3d47472010-07-15 21:03:543205TabContents* TabContents::AsTabContents() {
3206 return this;
3207}
3208
3209ExtensionHost* TabContents::AsExtensionHost() {
3210 return NULL;
3211}
3212
[email protected]41fc0322009-09-04 22:23:403213void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103214 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3215}
[email protected]f45d2a72010-03-08 23:28:353216
3217void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3218 app_icon_ = app_icon;
3219 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3220}
[email protected]ea68c06a2010-04-23 17:25:373221
3222// After a successful *new* login attempt, we take the PasswordFormManager in
3223// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3224// the user makes up their mind with the "save password" infobar. Note if the
3225// login is one we already know about, the end of the line is
3226// provisional_save_manager_ because we just update it on success and so such
3227// forms never end up in an infobar.
3228class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3229 public:
3230 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463231 PasswordFormManager* form_to_save)
3232 : ConfirmInfoBarDelegate(tab_contents),
3233 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583234 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373235
[email protected]d75aba1d2010-08-02 23:35:583236 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373237
[email protected]d75aba1d2010-08-02 23:35:583238 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373239 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463240 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583241 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373242 delete this;
3243 }
3244
[email protected]d75aba1d2010-08-02 23:35:583245 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3246
[email protected]e23d3a32010-08-13 19:39:583247 virtual string16 GetMessageText() const {
3248 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373249 }
3250
3251 virtual SkBitmap* GetIcon() const {
3252 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3253 IDR_INFOBAR_SAVE_PASSWORD);
3254 }
3255
3256 virtual int GetButtons() const {
3257 return BUTTON_OK | BUTTON_CANCEL;
3258 }
3259
[email protected]e23d3a32010-08-13 19:39:583260 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373261 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583262 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373263 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583264 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373265 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583266 return string16();
[email protected]ea68c06a2010-04-23 17:25:373267 }
3268
3269 virtual bool Accept() {
3270 DCHECK(form_to_save_.get());
3271 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583272 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373273 return true;
3274 }
3275
3276 virtual bool Cancel() {
3277 DCHECK(form_to_save_.get());
3278 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583279 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373280 return true;
3281 }
[email protected]d75aba1d2010-08-02 23:35:583282 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373283
3284 private:
3285 // The PasswordFormManager managing the form we're asking the user about,
3286 // and should update as per her decision.
3287 scoped_ptr<PasswordFormManager> form_to_save_;
3288
[email protected]12bb6822010-06-16 02:00:463289 // Used to track the results we get from the info bar.
3290 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583291 NO_RESPONSE = 0,
3292 REMEMBER_PASSWORD,
3293 DONT_REMEMBER_PASSWORD,
3294 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463295 };
3296 ResponseType infobar_response_;
3297
[email protected]ea68c06a2010-04-23 17:25:373298 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3299};
3300
3301void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163302 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373303 render_view_host()->FillPasswordForm(form_data);
3304}
3305
3306void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3307 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3308}
3309
3310Profile* TabContents::GetProfileForPasswordManager() {
3311 return profile();
3312}
3313
3314bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3315 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3316}