blob: b6bc9aed107ae87f601a55bc76df495d911bc83c [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5529#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1031#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5432#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1433#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3234#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5435#include "chrome/browser/dom_ui/dom_ui.h"
36#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0237#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3238#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0139#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4940#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0841#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5842#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4243#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2544#include "chrome/browser/host_zoom_map.h"
[email protected]0189bc722009-08-28 21:56:4845#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4946#include "chrome/browser/file_select_helper.h"
[email protected]e5d2f7132010-04-09 18:13:5347#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4948#include "chrome/browser/google/google_util.h"
[email protected]79580c62010-02-02 02:36:2549#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]12f74a92010-02-05 22:32:1452#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3253#include "chrome/browser/load_from_memory_cache_details.h"
54#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4455#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0556#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1057#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5758#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2459#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5760#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0261#include "chrome/browser/prefs/pref_service.h"
[email protected]12802702010-07-09 19:43:0962#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4463#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1665#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5466#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3767#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0768#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5469#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3270#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1171#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1672#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1273#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1674#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1775#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1776#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5477#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1678#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4379#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1680#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4981#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5782#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0283#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1684#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5885#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2786#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4987#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5788#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4889#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1490#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0991#include "chrome/common/extensions/url_pattern.h"
92#include "chrome/common/navigation_types.h"
93#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5694#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2995#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3296#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0297#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1898#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5499#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37100#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26101#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32102#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06103#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37104#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32105#include "net/base/mime_util.h"
106#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29107#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32108#include "net/base/registry_controlled_domain.h"
[email protected]b75b8292010-10-01 07:28:25109#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18110#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03111#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00112#include "webkit/glue/plugins/plugin_list.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,
[email protected]d0b8d092010-10-25 04:05:17170 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32171 prefs::kWebKitJavaEnabled,
172 prefs::kWebKitJavascriptEnabled,
173 prefs::kWebKitLoadsImagesAutomatically,
174 prefs::kWebKitPluginsEnabled,
175 prefs::kWebKitUsesUniversalDetector,
176 prefs::kWebKitSerifFontFamily,
177 prefs::kWebKitSansSerifFontFamily,
178 prefs::kWebKitFixedFontFamily,
179 prefs::kWebKitDefaultFontSize,
180 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13181 prefs::kWebKitMinimumFontSize,
182 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36183 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32184 prefs::kDefaultCharset
185 // kWebKitStandardFontIsSerif needs to be added
186 // if we let users pick which font to use, serif or sans-serif when
187 // no font is specified or a CSS generic family (serif or sans-serif)
188 // is not specified.
189};
190
191const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
192
[email protected]420ae012009-04-24 05:16:32193// Returns true if the entry's transition type is FORM_SUBMIT.
194bool IsFormSubmit(const NavigationEntry* entry) {
195 return (PageTransition::StripQualifier(entry->transition_type()) ==
196 PageTransition::FORM_SUBMIT);
197}
198
199#if defined(OS_WIN)
200
201BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
202 // Note: erase is required to properly paint some widgets borders. This can
203 // be seen with textfields.
204 InvalidateRect(hwnd, NULL, TRUE);
205 return TRUE;
206}
207#endif
208
[email protected]5e369672009-11-03 23:48:30209ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16210 Profile* profile, const NavigationEntry& entry,
211 NavigationController::ReloadType reload_type) {
212 switch (reload_type) {
213 case NavigationController::RELOAD:
214 return ViewMsg_Navigate_Params::RELOAD;
215 case NavigationController::RELOAD_IGNORING_CACHE:
216 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
217 case NavigationController::NO_RELOAD:
218 break; // Fall through to rest of function.
219 }
[email protected]5e369672009-11-03 23:48:30220
221 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
222 profile->DidLastSessionExitCleanly())
223 return ViewMsg_Navigate_Params::RESTORE;
224
225 return ViewMsg_Navigate_Params::NORMAL;
226}
227
[email protected]876bc832010-09-07 16:29:54228void MakeNavigateParams(const NavigationEntry& entry,
229 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16230 NavigationController::ReloadType reload_type,
231 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34232 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54233 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00234 params->current_history_list_offset = controller.last_committed_entry_index();
235 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34236 params->url = entry.url();
237 params->referrer = entry.referrer();
238 params->transition = entry.transition_type();
239 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00240 params->navigation_type =
241 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34242 params->request_time = base::Time::Now();
243}
244
[email protected]851b1eb2010-08-09 13:32:29245class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
246 public:
247 DisabledPluginInfoBar(TabContents* tab_contents,
248 const string16& name,
249 const GURL& update_url)
250 : ConfirmInfoBarDelegate(tab_contents),
251 tab_contents_(tab_contents),
252 name_(name),
253 update_url_(update_url) {
254 tab_contents->AddInfoBar(this);
255 }
256
257 virtual int GetButtons() const {
258 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
259 }
260
[email protected]e23d3a32010-08-13 19:39:58261 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29262 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58263 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29264 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58265 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29266 return ConfirmInfoBarDelegate::GetButtonLabel(button);
267 }
268
[email protected]e23d3a32010-08-13 19:39:58269 virtual string16 GetMessageText() const {
270 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29271 }
272
[email protected]e23d3a32010-08-13 19:39:58273 virtual string16 GetLinkText() {
274 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29275 }
276
277 virtual SkBitmap* GetIcon() const {
278 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
279 IDR_INFOBAR_PLUGIN_INSTALL);
280 }
281
282 virtual bool Accept() {
283 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51284 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29285 return false;
286 }
287
288 virtual bool Cancel() {
289 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51290 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29291 return false;
292 }
293
294 virtual bool LinkClicked(WindowOpenDisposition disposition) {
295 // TODO(bauerb): Navigate to a help page explaining why we disabled
296 // the plugin, once we have one.
297 return false;
298 }
299
300 private:
301 TabContents* tab_contents_;
302 string16 name_;
303 GURL update_url_;
304};
305
[email protected]420ae012009-04-24 05:16:32306} // namespace
307
308// -----------------------------------------------------------------------------
309
[email protected]fdd61c62009-04-22 19:22:57310// static
311int TabContents::find_request_id_counter_ = -1;
312
[email protected]420ae012009-04-24 05:16:32313
[email protected]420ae012009-04-24 05:16:32314TabContents::TabContents(Profile* profile,
315 SiteInstance* site_instance,
316 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07317 const TabContents* base_tab_contents,
318 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42319 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07320 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
321 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13322 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22323 TabContentsView::Create(this))),
324 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57325 property_bag_(),
326 registrar_(),
[email protected]12802702010-07-09 19:43:09327 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
328 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57329 save_package_(),
[email protected]6db0def92010-03-02 19:55:45330 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21331 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57332 password_manager_(),
333 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06334 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22335 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34336 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29337 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34338 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34339 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57340 current_load_start_(),
341 load_state_(net::LOAD_STATE_IDLE),
342 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56343 upload_size_(0),
344 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57345 received_page_title_(false),
346 is_starred_(false),
347 contents_mime_type_(),
348 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40349 blocked_contents_(NULL),
350 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49351 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47352 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57353 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57354 find_ui_active_(false),
355 find_op_aborted_(false),
356 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12357 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12358 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08359 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57360 capturing_contents_(false),
361 is_being_destroyed_(false),
362 notify_disconnection_(false),
363 history_requests_(),
364#if defined(OS_WIN)
365 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
366#endif
367 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44368 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01369 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54370 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54371 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16372 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38373 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25374 minimum_zoom_percent_(
375 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
376 maximum_zoom_percent_(
377 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00378 temporary_zoom_settings_(false),
379 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54380 renderer_preferences_util::UpdateFromSystemSettings(
381 &renderer_preferences_, profile);
382
[email protected]9fb83e82010-07-02 18:24:55383 content_settings_delegate_.reset(
384 new TabSpecificContentSettings(this, profile));
385
[email protected]16779842009-07-08 23:45:29386#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02387 // Make sure the thumbnailer is started before starting the render manager.
388 // The thumbnailer will want to listen for RVH creations, one of which will
389 // happen in RVHManager::Init.
390 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
391 if (generator)
392 generator->StartThumbnailing();
393#endif
394
[email protected]12636df2009-09-28 22:32:21395 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32396
[email protected]34ac70502009-09-25 17:07:23397 // We have the initial size of the view be based on the size of the passed in
398 // tab contents (normally a tab from the same window).
399 view_->CreateView(base_tab_contents ?
400 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32401
402 // Register for notifications about all interested prefs change.
403 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28404 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32405 if (prefs) {
406 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28407 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32408 }
409
410 // Register for notifications about URL starredness changing on any profile.
411 registrar_.Add(this, NotificationType::URLS_STARRED,
412 NotificationService::AllSources());
413 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
414 NotificationService::AllSources());
415 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
416 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09417#if defined(OS_LINUX)
418 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
419 NotificationService::AllSources());
420#endif
[email protected]420ae012009-04-24 05:16:32421
[email protected]6c32ce72010-03-08 05:18:06422 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
423 NotificationService::AllSources());
424
[email protected]79580c62010-02-02 02:36:25425 // Register for notifications about content setting changes.
426 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
427 NotificationService::AllSources());
428
[email protected]a888b29e62010-04-01 13:38:57429 // Listen for extension changes so we can update extension_for_current_page_.
430 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
431 NotificationService::AllSources());
432 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
433 NotificationService::AllSources());
434 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
435 NotificationService::AllSources());
436
[email protected]88152052010-10-01 04:05:18437 // Listen for Google URL changes
438 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
439 NotificationService::AllSources());
440
[email protected]c8865482009-07-23 20:40:10441 // Set-up the showing of the omnibox search infobar if applicable.
442 if (OmniboxSearchHint::IsEnabled(profile))
443 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35444}
initial.commit09911bf2008-07-26 23:55:29445
446TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32447 is_being_destroyed_ = true;
448
[email protected]bfe4c1582009-10-02 18:11:09449 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32450 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28451 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32452
[email protected]420ae012009-04-24 05:16:32453 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00454 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32455
[email protected]420ae012009-04-24 05:16:32456 // First cleanly close all child windows.
457 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
458 // some of these to close. CloseWindows is async, so it might get called
459 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49460 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32461
[email protected]c65e2f152010-10-14 15:30:40462 // Close all blocked contents.
463 if (blocked_contents_)
464 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13465
[email protected]420ae012009-04-24 05:16:32466 // Notify any observer that have a reference on this tab contents.
467 NotificationService::current()->Notify(
468 NotificationType::TAB_CONTENTS_DESTROYED,
469 Source<TabContents>(this),
470 NotificationService::NoDetails());
471
[email protected]1e5e74f2009-05-27 20:55:12472 // Notify any lasting InfobarDelegates that have not yet been removed that
473 // whatever infobar they were handling in this TabContents has closed,
474 // because the TabContents is going away entirely.
475 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
476 // notification may trigger infobars calls that access their delegate. (and
477 // some implementations of InfoBarDelegate do delete themselves on
478 // InfoBarClosed()).
479 for (int i = 0; i < infobar_delegate_count(); ++i) {
480 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
481 delegate->InfoBarClosed();
482 }
483 infobar_delegates_.clear();
484
[email protected]420ae012009-04-24 05:16:32485 // TODO(brettw) this should be moved to the view.
486#if defined(OS_WIN)
487 // If we still have a window handle, destroy it. GetNativeView can return
488 // NULL if this contents was part of a window that closed.
489 if (GetNativeView())
490 ::DestroyWindow(GetNativeView());
491#endif
[email protected]7ab1e7d62009-10-14 23:32:01492
493 // OnCloseStarted isn't called in unit tests.
494 if (!tab_close_start_time_.is_null()) {
495 UMA_HISTOGRAM_TIMES("Tab.Close",
496 base::TimeTicks::Now() - tab_close_start_time_);
497 }
initial.commit09911bf2008-07-26 23:55:29498}
499
[email protected]d5f942ba2008-09-26 19:30:34500// static
501void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32502 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
503
504 WebPreferences pref_defaults;
505 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
506 pref_defaults.javascript_enabled);
507 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
508 pref_defaults.web_security_enabled);
509 prefs->RegisterBooleanPref(
510 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
511 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
512 pref_defaults.loads_images_automatically);
513 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
514 pref_defaults.plugins_enabled);
515 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
516 pref_defaults.dom_paste_enabled);
517 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
518 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14519 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32520 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
521 pref_defaults.text_areas_are_resizable);
522 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
523 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36524 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
525 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32526
527 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
528 IDS_ACCEPT_LANGUAGES);
529 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
530 IDS_DEFAULT_ENCODING);
531 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
532 IDS_STANDARD_FONT_IS_SERIF);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
534 IDS_FIXED_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
536 IDS_SERIF_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
538 IDS_SANS_SERIF_FONT_FAMILY);
539 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
540 IDS_CURSIVE_FONT_FAMILY);
541 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
542 IDS_FANTASY_FONT_FAMILY);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
544 IDS_DEFAULT_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
546 IDS_DEFAULT_FIXED_FONT_SIZE);
547 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
548 IDS_MINIMUM_FONT_SIZE);
549 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
550 IDS_MINIMUM_LOGICAL_FONT_SIZE);
551 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
552 IDS_USES_UNIVERSAL_DETECTOR);
553 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
554 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29555}
556
[email protected]13367f72009-07-08 16:39:02557// Returns true if contains content rendered by an extension.
558bool TabContents::HostsExtension() const {
559 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34560}
561
[email protected]cf28ec52010-04-09 22:56:34562AutoFillManager* TabContents::GetAutoFillManager() {
563 if (autofill_manager_.get() == NULL)
564 autofill_manager_.reset(new AutoFillManager(this));
565 return autofill_manager_.get();
566}
567
[email protected]6e95706d2009-04-23 22:55:01568PasswordManager* TabContents::GetPasswordManager() {
569 if (password_manager_.get() == NULL)
570 password_manager_.reset(new PasswordManager(this));
571 return password_manager_.get();
572}
573
574PluginInstaller* TabContents::GetPluginInstaller() {
575 if (plugin_installer_.get() == NULL)
576 plugin_installer_.reset(new PluginInstaller(this));
577 return plugin_installer_.get();
578}
579
[email protected]1f18184a2010-07-21 19:34:49580TabContentsSSLHelper* TabContents::GetSSLHelper() {
581 if (ssl_helper_.get() == NULL)
582 ssl_helper_.reset(new TabContentsSSLHelper(this));
583 return ssl_helper_.get();
584}
585
[email protected]8cb5d5b2010-02-09 11:36:16586RenderProcessHost* TabContents::GetRenderProcessHost() const {
587 return render_manager_.current_host()->process();
588}
589
[email protected]9adb9692010-10-29 23:14:02590void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46591 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08592 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10593
[email protected]98aa0b52010-05-06 17:03:08594 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57595
[email protected]fca656c2010-02-10 20:30:10596 NotificationService::current()->Notify(
597 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
598 Source<TabContents>(this),
599 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49600}
601
[email protected]98aa0b52010-05-06 17:03:08602void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
603 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40604 return;
605
606 ExtensionsService* extension_service = profile()->GetExtensionsService();
607 if (extension_service && extension_service->is_ready()) {
[email protected]9adb9692010-10-29 23:14:02608 const Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08609 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40610 if (extension)
[email protected]98aa0b52010-05-06 17:03:08611 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40612 }
613}
614
[email protected]98aa0b52010-05-06 17:03:08615SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08616 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51617 return NULL;
618
[email protected]98aa0b52010-05-06 17:03:08619 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51620}
621
[email protected]d5f942ba2008-09-26 19:30:34622const GURL& TabContents::GetURL() const {
623 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57624 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54625 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34626}
627
[email protected]96d185d2009-04-24 03:28:54628const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55629 // Transient entries take precedence. They are used for interstitial pages
630 // that are shown on top of existing pages.
631 NavigationEntry* entry = controller_.GetTransientEntry();
632 if (entry)
633 return entry->GetTitleForDisplay(&controller_);
634
[email protected]96d185d2009-04-24 03:28:54635 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
636 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
637 if (our_dom_ui) {
638 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55639 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54640 if (!(entry && entry->IsViewSourceMode())) {
641 // Give the DOM UI the chance to override our title.
642 const string16& title = our_dom_ui->overridden_title();
643 if (!title.empty())
644 return title;
645 }
646 }
647
648 // We use the title for the last committed entry rather than a pending
649 // navigation entry. For example, when the user types in a URL, we want to
650 // keep the old page's title until the new load has committed and we get a new
651 // title.
[email protected]96d185d2009-04-24 03:28:54652 entry = controller_.GetLastCommittedEntry();
653 if (entry)
654 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54655 return EmptyString16();
656}
657
[email protected]bbbc1ef2010-02-12 18:03:41658// static
659string16 TabContents::GetDefaultTitle() {
660 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
661}
662
[email protected]d5f942ba2008-09-26 19:30:34663int32 TabContents::GetMaxPageID() {
664 if (GetSiteInstance())
665 return GetSiteInstance()->max_page_id();
666 else
667 return max_page_id_;
668}
669
670void TabContents::UpdateMaxPageID(int32 page_id) {
671 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34672 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34673 // testing.
674 if (GetSiteInstance())
675 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16676 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34677}
678
[email protected]96d185d2009-04-24 03:28:54679SiteInstance* TabContents::GetSiteInstance() const {
680 return render_manager_.current_host()->site_instance();
681}
682
[email protected]96d185d2009-04-24 03:28:54683bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15684 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54685 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15686 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01687 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54688 return true;
[email protected]8ab24cc2009-11-13 20:56:15689 }
[email protected]83e3895b2009-06-11 00:07:16690
[email protected]96d185d2009-04-24 03:28:54691 DOMUI* dom_ui = GetDOMUIForCurrentState();
692 if (dom_ui)
693 return !dom_ui->should_hide_url();
694 return true;
695}
696
[email protected]d5f942ba2008-09-26 19:30:34697SkBitmap TabContents::GetFavIcon() const {
698 // Like GetTitle(), we also want to use the favicon for the last committed
699 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57700 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47701 if (entry)
702 return entry->favicon().bitmap();
703
[email protected]ce3fa3c2009-04-20 19:55:57704 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34705 if (entry)
706 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34707 return SkBitmap();
708}
709
[email protected]0b303cc2009-09-28 22:35:15710bool TabContents::FavIconIsValid() const {
711 NavigationEntry* entry = controller_.GetTransientEntry();
712 if (entry)
713 return entry->favicon().is_valid();
714
715 entry = controller_.GetLastCommittedEntry();
716 if (entry)
717 return entry->favicon().is_valid();
718
719 return false;
720}
721
[email protected]96d185d2009-04-24 03:28:54722bool TabContents::ShouldDisplayFavIcon() {
723 // Always display a throbber during pending loads.
724 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
725 return true;
726
727 DOMUI* dom_ui = GetDOMUIForCurrentState();
728 if (dom_ui)
729 return !dom_ui->hide_favicon();
730 return true;
731}
732
[email protected]96d185d2009-04-24 03:28:54733std::wstring TabContents::GetStatusText() const {
734 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
735 return std::wstring();
736
737 switch (load_state_) {
738 case net::LOAD_STATE_WAITING_FOR_CACHE:
739 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04740 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
741 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54742 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
743 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
744 case net::LOAD_STATE_RESOLVING_HOST:
745 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
746 case net::LOAD_STATE_CONNECTING:
747 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06748 case net::LOAD_STATE_SSL_HANDSHAKE:
749 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54750 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56751 if (upload_size_)
752 return l10n_util::GetStringF(
753 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
754 static_cast<int>((100 * upload_position_) / upload_size_));
755 else
756 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54757 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
758 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
759 load_state_host_);
760 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
761 case net::LOAD_STATE_IDLE:
762 case net::LOAD_STATE_READING_RESPONSE:
763 break;
764 }
765
766 return std::wstring();
767}
768
[email protected]d5f942ba2008-09-26 19:30:34769void TabContents::SetIsCrashed(bool state) {
770 if (state == is_crashed_)
771 return;
772
773 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50774 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34775}
776
[email protected]744ef172009-10-16 21:53:46777void TabContents::PageActionStateChanged() {
778 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00779}
[email protected]ce5c4502009-05-06 16:46:11780
[email protected]d5f942ba2008-09-26 19:30:34781void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
782 if (delegate_)
783 delegate_->NavigationStateChanged(this, changed_flags);
784}
785
[email protected]96d185d2009-04-24 03:28:54786void TabContents::DidBecomeSelected() {
787 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16788 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
789 if (rwhv) {
790 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43791#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16792 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43793#endif
794 }
[email protected]96d185d2009-04-24 03:28:54795
[email protected]8cb5d5b2010-02-09 11:36:16796 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54797}
798
799void TabContents::WasHidden() {
800 if (!capturing_contents()) {
801 // |render_view_host()| can be NULL if the user middle clicks a link to open
802 // a tab in then background, then closes the tab before selecting it. This
803 // is because closing the tab calls TabContents::Destroy(), which removes
804 // the |render_view_host()|; then when we actually destroy the window,
805 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16806 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
807 if (rwhv)
808 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54809 }
810
811 NotificationService::current()->Notify(
812 NotificationType::TAB_CONTENTS_HIDDEN,
813 Source<TabContents>(this),
814 NotificationService::NoDetails());
815}
816
[email protected]d5f942ba2008-09-26 19:30:34817void TabContents::Activate() {
818 if (delegate_)
819 delegate_->ActivateContents(this);
820}
821
[email protected]ea42e7782010-08-23 23:58:12822void TabContents::Deactivate() {
823 if (delegate_)
824 delegate_->DeactivateContents(this);
825}
826
[email protected]96d185d2009-04-24 03:28:54827void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16828 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
829 if (rwhv)
830 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54831}
832
833void TabContents::HideContents() {
834 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
835 // our superclass HideContents(), because some callers want to be very picky
836 // about the order in which these get called. In addition to making the code
837 // here practically impossible to understand, this also means we end up
838 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34839 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54840 WasHidden();
841}
842
[email protected]c0588052008-10-27 23:01:50843void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34844 WindowOpenDisposition disposition,
845 PageTransition::Type transition) {
846 if (delegate_)
[email protected]c0588052008-10-27 23:01:50847 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34848}
849
[email protected]1ccb3568d2010-02-19 10:51:16850bool TabContents::NavigateToPendingEntry(
851 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54852 return NavigateToEntry(*controller_.pending_entry(), reload_type);
853}
[email protected]96d185d2009-04-24 03:28:54854
[email protected]876bc832010-09-07 16:29:54855bool TabContents::NavigateToEntry(
856 const NavigationEntry& entry,
857 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54858 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
859 if (!dest_render_view_host)
860 return false; // Unable to create the desired render view host.
861
[email protected]770dd8b2010-05-24 18:11:39862 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
863 dest_render_view_host->EnablePreferredSizeChangedMode(
864 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
865 }
[email protected]9fb325e2010-05-06 18:23:24866
[email protected]05fdd492010-11-15 17:52:07867 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
868 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58869 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40870 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07871 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[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]d0b8d092010-10-25 04:05:171468double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251469 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1470 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171471 return 0;
[email protected]b75b8292010-10-01 07:28:251472
1473 double zoom_level;
1474 if (temporary_zoom_settings_) {
1475 zoom_level = zoom_map->GetTemporaryZoomLevel(
1476 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1477 } else {
1478 zoom_level = zoom_map->GetZoomLevel(GetURL());
1479 }
[email protected]d0b8d092010-10-25 04:05:171480 return zoom_level;
1481}
[email protected]b75b8292010-10-01 07:28:251482
[email protected]d0b8d092010-10-25 04:05:171483int TabContents::GetZoomPercent(bool* enable_increment,
1484 bool* enable_decrement) {
1485 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251486 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171487 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251488 *enable_decrement = percent > minimum_zoom_percent_;
1489 *enable_increment = percent < maximum_zoom_percent_;
1490 return percent;
1491}
1492
[email protected]96d185d2009-04-24 03:28:541493// Notifies the RenderWidgetHost instance about the fact that the page is
1494// loading, or done loading and calls the base implementation.
1495void TabContents::SetIsLoading(bool is_loading,
1496 LoadNotificationDetails* details) {
1497 if (is_loading == is_loading_)
1498 return;
1499
1500 if (!is_loading) {
1501 load_state_ = net::LOAD_STATE_IDLE;
1502 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561503 upload_size_ = 0;
1504 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541505 }
1506
1507 render_manager_.SetIsLoading(is_loading);
1508
1509 is_loading_ = is_loading;
1510 waiting_for_response_ = is_loading;
1511
[email protected]6ebdc9b2010-09-27 16:55:571512 if (delegate_)
1513 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351514 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541515
1516 NotificationType type = is_loading ? NotificationType::LOAD_START :
1517 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111518 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541519 if (details)
1520 det = Details<LoadNotificationDetails>(details);
1521 NotificationService::current()->Notify(type,
1522 Source<NavigationController>(&controller_),
1523 det);
1524}
1525
[email protected]b6c874582009-05-08 19:38:311526void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291527 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061528 // A page can't spawn popups (or do anything else, either) until its load
1529 // commits, so when we reach here, the popup was spawned by the
1530 // NavigationController's last committed entry, not the active entry. For
1531 // example, if a page opens a popup in an onunload() handler, then the active
1532 // entry is the page to be loaded as we navigate away from the unloading
1533 // page. For this reason, we can't use GetURL() to get the opener URL,
1534 // because it returns the active entry.
1535 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1536 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1537
1538 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491539 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091540 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491541 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1542 } else {
[email protected]c65e2f152010-10-14 15:30:401543 if (!blocked_contents_)
1544 blocked_contents_ = new BlockedContentContainer(this);
1545 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1546 true);
[email protected]55126132010-08-19 14:53:281547 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1548 std::string());
[email protected]8cc8d492010-02-02 10:40:491549 }
[email protected]b9681312008-11-07 00:08:261550}
[email protected]616ed5a2008-11-21 22:27:241551
[email protected]616ed5a2008-11-21 22:27:241552void TabContents::ExpireInfoBars(
1553 const NavigationController::LoadCommittedDetails& details) {
1554 // Only hide InfoBars when the user has done something that makes the main
1555 // frame load. We don't want various automatic or subframe navigations making
1556 // it disappear.
1557 if (!details.is_user_initiated_main_frame_load())
1558 return;
1559
[email protected]f86a07022008-11-25 01:06:051560 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241561 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081562 if (!delegate) {
1563 // If you hit this NOTREACHED, please comment in bug
1564 // http://crbug.com/50428 how you got there.
1565 NOTREACHED();
1566 continue;
1567 }
1568
[email protected]f86a07022008-11-25 01:06:051569 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241570 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241571 }
1572}
[email protected]fdd61c62009-04-22 19:22:571573
[email protected]96d185d2009-04-24 03:28:541574DOMUI* TabContents::GetDOMUIForCurrentState() {
1575 // When there is a pending navigation entry, we want to use the pending DOMUI
1576 // that goes along with it to control the basic flags. For example, we want to
1577 // show the pending URL in the URL bar, so we want the display_url flag to
1578 // be from the pending entry.
1579 //
1580 // The confusion comes because there are multiple possibilities for the
1581 // initial load in a tab as a side effect of the way the RenderViewHostManager
1582 // works.
1583 //
1584 // - For the very first tab the load looks "normal". The new tab DOM UI is
1585 // the pending one, and we want it to apply here.
1586 //
1587 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1588 // get switched to the one previously associated with the new tab pages.
1589 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1590 // have a committed DOM UI in this case.
1591 //
1592 // This condition handles all of these cases:
1593 //
1594 // - First load in first tab: no committed nav entry + pending nav entry +
1595 // pending dom ui:
1596 // -> Use pending DOM UI if any.
1597 //
1598 // - First load in second tab: no committed nav entry + pending nav entry +
1599 // no pending DOM UI:
1600 // -> Use the committed DOM UI if any.
1601 //
1602 // - Second navigation in any tab: committed nav entry + pending nav entry:
1603 // -> Use pending DOM UI if any.
1604 //
1605 // - Normal state with no load: committed nav entry + no pending nav entry:
1606 // -> Use committed DOM UI.
1607 if (controller_.pending_entry() &&
1608 (controller_.GetLastCommittedEntry() ||
1609 render_manager_.pending_dom_ui()))
1610 return render_manager_.pending_dom_ui();
1611 return render_manager_.dom_ui();
1612}
[email protected]420ae012009-04-24 05:16:321613
1614void TabContents::DidNavigateMainFramePostCommit(
1615 const NavigationController::LoadCommittedDetails& details,
1616 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441617 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1618 // If this is a window.open navigation, use the same DOMUI as the renderer
1619 // that opened the window, as long as both renderers have the same
1620 // privileges.
[email protected]583d45c12010-08-31 02:48:121621 if (opener_dom_ui_type_ ==
1622 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441623 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1624 // dom_ui might be NULL if the URL refers to a non-existent extension.
1625 if (dom_ui) {
1626 render_manager_.SetDOMUIPostCommit(dom_ui);
1627 dom_ui->RenderViewCreated(render_view_host());
1628 }
1629 }
1630 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1631 }
1632
[email protected]420ae012009-04-24 05:16:321633 if (details.is_user_initiated_main_frame_load()) {
1634 // Clear the status bubble. This is a workaround for a bug where WebKit
1635 // doesn't let us know that the cursor left an element during a
1636 // transition (this is also why the mouse cursor remains as a hand after
1637 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1638 // clear the bubble when a user navigates to a named anchor in the same
1639 // page.
1640 UpdateTargetURL(details.entry->page_id(), GURL());
1641
1642 // UpdateHelpersForDidNavigate will handle the case where the password_form
1643 // origin is valid.
1644 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1645 // cleaned up and covered by tests.
1646 if (!params.password_form.origin.is_valid())
1647 GetPasswordManager()->DidNavigate();
1648 }
1649
1650 // The keyword generator uses the navigation entries, so must be called after
1651 // the commit.
1652 GenerateKeywordIfNecessary(params);
1653
1654 // Allow the new page to set the title again.
1655 received_page_title_ = false;
1656
1657 // Get the favicon, either from history or request it from the net.
1658 fav_icon_helper_.FetchFavIcon(details.entry->url());
1659
[email protected]0de80162010-02-03 04:52:351660 // Clear all page actions, blocked content notifications and browser actions
1661 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141662 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081663 ExtensionsService* service = profile()->GetExtensionsService();
1664 if (service) {
1665 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571666 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081667 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521668 if (browser_action) {
1669 browser_action->ClearAllValuesForTab(controller().session_id().id());
1670 NotificationService::current()->Notify(
1671 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571672 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521673 NotificationService::NoDetails());
1674 }
[email protected]92c6f9b92009-10-24 04:35:081675
[email protected]5d246db22009-10-27 06:17:571676 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521677 service->extensions()->at(i)->page_action();
1678 if (page_action) {
1679 page_action->ClearAllValuesForTab(controller().session_id().id());
1680 PageActionStateChanged();
1681 }
[email protected]92c6f9b92009-10-24 04:35:081682 }
[email protected]aece2c7f2009-08-27 20:43:171683 }
[email protected]0de80162010-02-03 04:52:351684
1685 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401686 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341687 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401688 blocked_contents_->Destroy();
1689 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351690 }
1691
1692 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411693 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551694 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471695
1696 // Once the main frame is navigated, we're no longer considered to have
1697 // displayed insecure content.
1698 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171699 }
[email protected]ce5c4502009-05-06 16:46:111700
[email protected]8cc8d492010-02-02 10:40:491701 // Close constrained windows if necessary.
1702 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1703 details.previous_url, details.entry->url()))
1704 CloseConstrainedWindows();
1705
[email protected]420ae012009-04-24 05:16:321706 // Update the starred state.
1707 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531708
1709 // Clear the cache of forms in AutoFill.
1710 if (autofill_manager_.get())
1711 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321712}
1713
1714void TabContents::DidNavigateAnyFramePostCommit(
1715 RenderViewHost* render_view_host,
1716 const NavigationController::LoadCommittedDetails& details,
1717 const ViewHostMsg_FrameNavigate_Params& params) {
1718 // If we navigate, start showing messages again. This does nothing to prevent
1719 // a malicious script from spamming messages, since the script could just
1720 // reload the page to stop blocking.
1721 suppress_javascript_messages_ = false;
1722
[email protected]420ae012009-04-24 05:16:321723 // Notify the password manager of the navigation or form submit.
1724 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1725 // cleaned up and covered by tests.
1726 if (params.password_form.origin.is_valid())
1727 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551728
1729 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581730 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]8cc8d492010-02-02 10:40:491733void TabContents::CloseConstrainedWindows() {
1734 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321735 // We use indices instead of iterators in case CloseWindow does something
1736 // that may invalidate an iterator.
1737 int size = static_cast<int>(child_windows_.size());
1738 for (int i = size - 1; i >= 0; --i) {
1739 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441740 if (window) {
[email protected]420ae012009-04-24 05:16:321741 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441742 BlockTabContent(false);
1743 }
[email protected]420ae012009-04-24 05:16:321744 }
1745}
1746
1747void TabContents::UpdateStarredStateForCurrentURL() {
1748 BookmarkModel* model = profile()->GetBookmarkModel();
1749 const bool old_state = is_starred_;
1750 is_starred_ = (model && model->IsBookmarked(GetURL()));
1751
1752 if (is_starred_ != old_state && delegate())
1753 delegate()->URLStarredChanged(this, is_starred_);
1754}
1755
1756void TabContents::UpdateAlternateErrorPageURL() {
1757 GURL url = GetAlternateErrorPageURL();
1758 render_view_host()->SetAlternateErrorPageURL(url);
1759}
1760
1761void TabContents::UpdateWebPreferences() {
1762 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1763}
1764
[email protected]d0b8d092010-10-25 04:05:171765void TabContents::UpdateZoomLevel() {
1766 render_view_host()->SetZoomLevel(GetZoomLevel());
1767}
1768
[email protected]420ae012009-04-24 05:16:321769void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1770 RenderViewHost* rvh) {
1771 // If we are creating a RVH for a restored controller, then we might
1772 // have more page IDs than the SiteInstance's current max page ID. We must
1773 // make sure that the max page ID is larger than any restored page ID.
1774 // Note that it is ok for conflicting page IDs to exist in another tab
1775 // (i.e., NavigationController), but if any page ID is larger than the max,
1776 // the back/forward list will get confused.
1777 int max_restored_page_id = controller_.max_restored_page_id();
1778 if (max_restored_page_id > 0) {
1779 int curr_max_page_id = site_instance->max_page_id();
1780 if (max_restored_page_id > curr_max_page_id) {
1781 // Need to update the site instance immediately.
1782 site_instance->UpdateMaxPageID(max_restored_page_id);
1783
1784 // Also tell the renderer to update its internal representation. We
1785 // need to reserve enough IDs to make all restored page IDs less than
1786 // the max.
1787 if (curr_max_page_id < 0)
1788 curr_max_page_id = 0;
1789 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1790 }
1791 }
1792}
1793
[email protected]ec0b6c42010-08-26 03:16:581794scoped_refptr<history::HistoryAddPageArgs>
1795TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541796 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471797 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321798 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581799 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1800 new history::HistoryAddPageArgs(
1801 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1802 params.redirects, params.transition, history::SOURCE_BROWSED,
1803 details.did_replace_entry));
1804 if (PageTransition::IsMainFrame(params.transition) &&
1805 virtual_url != params.url) {
1806 // Hack on the "virtual" URL so that it will appear in history. For some
1807 // types of URLs, we will display a magic URL that is different from where
1808 // the page is actually navigated. We want the user to see in history what
1809 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1810 // only applies to the main frame, as the virtual URL doesn't apply to
1811 // sub-frames.
1812 add_page_args->url = virtual_url;
1813 if (!add_page_args->redirects.empty())
1814 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321815 }
[email protected]ec0b6c42010-08-26 03:16:581816 return add_page_args;
[email protected]420ae012009-04-24 05:16:321817}
1818
1819bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1820 const std::wstring& title) {
1821 // For file URLs without a title, use the pathname instead. In the case of a
1822 // synthesized title, we don't want the update to count toward the "one set
1823 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251824 string16 final_title;
[email protected]420ae012009-04-24 05:16:321825 bool explicit_set;
1826 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251827 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321828 explicit_set = false; // Don't count synthetic titles toward the set limit.
1829 } else {
[email protected]e53668962010-06-23 15:35:251830 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321831 explicit_set = true;
1832 }
1833
[email protected]e53668962010-06-23 15:35:251834 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321835 return false; // Nothing changed, don't bother.
1836
[email protected]e53668962010-06-23 15:35:251837 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321838
[email protected]ec0b6c42010-08-26 03:16:581839 if (!received_page_title_) {
1840 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321841 received_page_title_ = explicit_set;
1842 }
1843
1844 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251845 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321846
[email protected]cbc0e1b2010-04-12 18:33:041847 NotificationService::current()->Notify(
1848 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1849 Source<TabContents>(this),
1850 NotificationService::NoDetails());
1851
[email protected]420ae012009-04-24 05:16:321852 return true;
1853}
1854
1855void TabContents::NotifySwapped() {
1856 // After sending out a swap notification, we need to send a disconnect
1857 // notification so that clients that pick up a pointer to |this| can NULL the
1858 // pointer. See Bug 1230284.
1859 notify_disconnection_ = true;
1860 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341861 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221862 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321863 NotificationService::NoDetails());
1864}
1865
1866void TabContents::NotifyConnected() {
1867 notify_disconnection_ = true;
1868 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341869 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221870 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321871 NotificationService::NoDetails());
1872}
1873
1874void TabContents::NotifyDisconnected() {
1875 if (!notify_disconnection_)
1876 return;
1877
1878 notify_disconnection_ = false;
1879 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341880 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221881 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321882 NotificationService::NoDetails());
1883}
1884
1885void TabContents::GenerateKeywordIfNecessary(
1886 const ViewHostMsg_FrameNavigate_Params& params) {
1887 if (!params.searchable_form_url.is_valid())
1888 return;
1889
1890 if (profile()->IsOffTheRecord())
1891 return;
1892
1893 int last_index = controller_.last_committed_entry_index();
1894 // When there was no previous page, the last index will be 0. This is
1895 // normally due to a form submit that opened in a new tab.
1896 // TODO(brettw) bug 916126: we should support keywords when form submits
1897 // happen in new tabs.
1898 if (last_index <= 0)
1899 return;
1900 const NavigationEntry* previous_entry =
1901 controller_.GetEntryAtIndex(last_index - 1);
1902 if (IsFormSubmit(previous_entry)) {
1903 // Only generate a keyword if the previous page wasn't itself a form
1904 // submit.
1905 return;
1906 }
1907
1908 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1909 previous_entry->user_typed_url() : previous_entry->url();
1910 std::wstring keyword =
1911 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1912 if (keyword.empty())
1913 return;
1914
1915 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1916 if (!url_model)
1917 return;
1918
1919 if (!url_model->loaded()) {
1920 url_model->Load();
1921 return;
1922 }
1923
1924 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191925 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321926 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1927 return;
1928
1929 if (current_url) {
1930 if (current_url->originating_url().is_valid()) {
1931 // The existing keyword was generated from an OpenSearch description
1932 // document, don't regenerate.
1933 return;
1934 }
1935 url_model->Remove(current_url);
1936 }
1937 TemplateURL* new_url = new TemplateURL();
1938 new_url->set_keyword(keyword);
1939 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191940 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321941 new_url->add_input_encoding(params.searchable_form_encoding);
1942 DCHECK(controller_.GetLastCommittedEntry());
1943 const GURL& favicon_url =
1944 controller_.GetLastCommittedEntry()->favicon().url();
1945 if (favicon_url.is_valid()) {
1946 new_url->SetFavIconURL(favicon_url);
1947 } else {
1948 // The favicon url isn't valid. This means there really isn't a favicon,
1949 // or the favicon url wasn't obtained before the load started. This assumes
1950 // the later.
1951 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1952 // its url.
1953 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1954 }
1955 new_url->set_safe_for_autoreplace(true);
1956 url_model->Add(new_url);
1957}
1958
[email protected]bf5c2ff392009-07-08 16:24:331959void TabContents::OnUserGesture() {
1960 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011961 DownloadRequestLimiter* limiter =
1962 g_browser_process->download_request_limiter();
1963 if (limiter)
1964 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261965 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331966}
1967
1968void TabContents::OnFindReply(int request_id,
1969 int number_of_matches,
1970 const gfx::Rect& selection_rect,
1971 int active_match_ordinal,
1972 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421973 // Ignore responses for requests that have been aborted.
1974 if (find_op_aborted_)
1975 return;
1976
[email protected]bf5c2ff392009-07-08 16:24:331977 // Ignore responses for requests other than the one we have most recently
1978 // issued. That way we won't act on stale results when the user has
1979 // already typed in another query.
1980 if (request_id != current_find_request_id_)
1981 return;
1982
1983 if (number_of_matches == -1)
1984 number_of_matches = last_search_result_.number_of_matches();
1985 if (active_match_ordinal == -1)
1986 active_match_ordinal = last_search_result_.active_match_ordinal();
1987
1988 gfx::Rect selection = selection_rect;
1989 if (selection.IsEmpty())
1990 selection = last_search_result_.selection_rect();
1991
1992 // Notify the UI, automation and any other observers that a find result was
1993 // found.
1994 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1995 selection, active_match_ordinal,
1996 final_update);
1997 NotificationService::current()->Notify(
1998 NotificationType::FIND_RESULT_AVAILABLE,
1999 Source<TabContents>(this),
2000 Details<FindNotificationDetails>(&last_search_result_));
2001}
2002
2003void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542004 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2005 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2006 if (!entry)
2007 return;
2008 // Note that we don't call NavigationController::GotToOffset() as we don't
2009 // want to create a pending navigation entry (it might end up lingering
2010 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522011 entry->set_transition_type(entry->transition_type() |
2012 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542013 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2014 }
[email protected]bf5c2ff392009-07-08 16:24:332015}
2016
[email protected]bf5c2ff392009-07-08 16:24:332017void TabContents::OnMissingPluginStatus(int status) {
2018#if defined(OS_WIN)
2019// TODO(PORT): pull in when plug-ins work
2020 GetPluginInstaller()->OnMissingPluginStatus(status);
2021#endif
2022}
2023
2024void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332025 DCHECK(!plugin_path.value().empty());
2026
2027 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002028 WebPluginInfo plugin_info;
2029 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2030 plugin_path, &plugin_info) &&
2031 !plugin_info.name.empty()) {
2032 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372033#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002034 // Many plugins on the Mac have .plugin in the actual name, which looks
2035 // terrible, so look for that and strip it off if present.
2036 const std::wstring plugin_extension(L".plugin");
2037 if (EndsWith(plugin_name, plugin_extension, true))
2038 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372039#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332040 }
[email protected]2ae8a922010-06-28 20:27:532041 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2042 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332043 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582044 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2045 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532046 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332047}
2048
2049void TabContents::OnCrashedWorker() {
2050 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582051 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422052 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332053}
2054
2055void TabContents::OnDidGetApplicationInfo(
2056 int32 page_id,
2057 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512058 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332059
[email protected]ed5431872009-11-17 08:39:512060 if (delegate())
2061 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332062}
2063
[email protected]851b1eb2010-08-09 13:32:292064void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2065 const GURL& update_url) {
2066 new DisabledPluginInfoBar(this, name, update_url);
2067}
2068
[email protected]a2cf65eb2010-01-18 08:20:382069void TabContents::OnPageContents(const GURL& url,
2070 int renderer_process_id,
2071 int32 page_id,
[email protected]e5106202010-06-11 21:12:362072 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102073 const std::string& language,
2074 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382075 // Don't index any https pages. People generally don't want their bank
2076 // accounts, etc. indexed on their computer, especially since some of these
2077 // things are not marked cachable.
2078 // TODO(brettw) we may want to consider more elaborate heuristics such as
2079 // the cachability of the page. We may also want to consider subframes (this
2080 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272081 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2082 // content indexing for chromeos in some future releases.
2083#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382084 if (!url.SchemeIsSecure()) {
2085 Profile* p = profile();
2086 if (p && !p->IsOffTheRecord()) {
2087 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2088 if (hs)
2089 hs->SetPageContents(url, contents);
2090 }
2091 }
[email protected]ccd40a52010-05-11 16:15:272092#endif
[email protected]a8a81292010-01-21 00:32:452093
[email protected]1c57b7b2010-07-12 17:38:102094 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452095
2096 std::string lang = language;
2097 NotificationService::current()->Notify(
2098 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152099 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452100 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382101}
2102
[email protected]7e0831b2010-02-01 08:45:152103void TabContents::OnPageTranslated(int32 page_id,
2104 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162105 const std::string& translated_lang,
2106 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552107 language_state_.set_current_language(translated_lang);
2108 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162109 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152110 NotificationService::current()->Notify(
2111 NotificationType::PAGE_TRANSLATED,
2112 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162113 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152114}
2115
[email protected]ce833282010-11-04 15:48:392116void TabContents::OnSetSuggestions(
2117 int32 page_id,
2118 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262119 if (delegate())
[email protected]ce833282010-11-04 15:48:392120 delegate()->OnSetSuggestions(page_id, suggestions);
2121}
2122
2123void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2124 if (delegate())
2125 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262126}
2127
[email protected]bf5c2ff392009-07-08 16:24:332128void TabContents::DidStartProvisionalLoadForFrame(
2129 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072130 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332131 bool is_main_frame,
2132 const GURL& url) {
2133 ProvisionalLoadDetails details(is_main_frame,
2134 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072135 url, std::string(), false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332136 NotificationService::current()->Notify(
2137 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2138 Source<NavigationController>(&controller_),
2139 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142140 if (is_main_frame) {
[email protected]da4f8a12010-08-19 08:33:412141 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142142 content_settings_delegate_->ClearGeolocationContentSettings();
2143 }
[email protected]bf5c2ff392009-07-08 16:24:332144}
2145
2146void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202147 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332148 NotificationService::current()->Notify(
2149 NotificationType::RESOURCE_RESPONSE_STARTED,
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
[email protected]3dbb80b2010-02-09 22:41:202154void TabContents::DidRedirectResource(
2155 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332156 NotificationService::current()->Notify(
2157 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2158 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202159 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332160}
2161
2162void TabContents::DidLoadResourceFromMemoryCache(
2163 const GURL& url,
2164 const std::string& frame_origin,
2165 const std::string& main_frame_origin,
2166 const std::string& security_info) {
2167 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442168 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332169 SSLManager::DeserializeSecurityInfo(security_info,
2170 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042171 &security_bits,
2172 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332173 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162174 GetRenderProcessHost()->id(), cert_id,
2175 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332176
2177 NotificationService::current()->Notify(
2178 NotificationType::LOAD_FROM_MEMORY_CACHE,
2179 Source<NavigationController>(&controller_),
2180 Details<LoadFromMemoryCacheDetails>(&details));
2181}
2182
[email protected]e3d60e5d2009-09-25 21:08:292183void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472184 displayed_insecure_content_ = true;
2185 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292186}
2187
2188void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592189 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292190}
2191
[email protected]bf5c2ff392009-07-08 16:24:332192void TabContents::DidFailProvisionalLoadWithError(
2193 RenderViewHost* render_view_host,
[email protected]dabb0d12010-10-05 12:50:072194 long long frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332195 bool is_main_frame,
2196 int error_code,
2197 const GURL& url,
2198 bool showing_repost_interstitial) {
2199 if (net::ERR_ABORTED == error_code) {
2200 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2201 // This means that the interstitial won't be torn down properly, which is
2202 // bad. But if we have an interstitial, go back to another tab type, and
2203 // then load the same interstitial again, we could end up getting the first
2204 // interstitial's "failed" message (as a result of the cancel) when we're on
2205 // the second one.
2206 //
2207 // We can't tell this apart, so we think we're tearing down the current page
2208 // which will cause a crash later one. There is also some code in
2209 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2210 // out because of this problem.
2211 //
2212 // http://code.google.com/p/chromium/issues/detail?id=2855
2213 // Because this will not tear down the interstitial properly, if "back" is
2214 // back to another tab type, the interstitial will still be somewhat alive
2215 // in the previous tab type. If you navigate somewhere that activates the
2216 // tab with the interstitial again, you'll see a flash before the new load
2217 // commits of the interstitial page.
2218 if (showing_interstitial_page()) {
2219 LOG(WARNING) << "Discarding message during interstitial.";
2220 return;
2221 }
2222
2223 // This will discard our pending entry if we cancelled the load (e.g., if we
2224 // decided to download the file instead of load it). Only discard the
2225 // pending entry if the URLs match, otherwise the user initiated a navigate
2226 // before the page loaded so that the discard would discard the wrong entry.
2227 NavigationEntry* pending_entry = controller_.pending_entry();
2228 if (pending_entry && pending_entry->url() == url) {
2229 controller_.DiscardNonCommittedEntries();
2230 // Update the URL display.
2231 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2232 }
2233
2234 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2235 }
2236
2237 // Send out a notification that we failed a provisional load with an error.
2238 ProvisionalLoadDetails details(is_main_frame,
2239 controller_.IsURLInPageNavigation(url),
[email protected]dabb0d12010-10-05 12:50:072240 url, std::string(), false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332241 details.set_error_code(error_code);
2242
2243 NotificationService::current()->Notify(
2244 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2245 Source<NavigationController>(&controller_),
2246 Details<ProvisionalLoadDetails>(&details));
2247}
2248
[email protected]622474d2010-11-04 09:21:082249void TabContents::DocumentLoadedInFrame(long long frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332250 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082251 NotificationService::current()->Notify(
2252 NotificationType::FRAME_DOM_CONTENT_LOADED,
2253 Source<NavigationController>(&controller_),
2254 Details<long long>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332255}
2256
[email protected]fdd94a02010-11-05 08:07:172257void TabContents::DidFinishLoad(long long frame_id) {
2258 NotificationService::current()->Notify(
2259 NotificationType::FRAME_DID_FINISH_LOAD,
2260 Source<NavigationController>(&controller_),
2261 Details<long long>(&frame_id));
2262}
2263
[email protected]dcd5b332010-08-11 08:55:182264void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562265 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242266 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562267}
2268
[email protected]8d3347f2009-07-09 22:00:212269RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322270 return view_.get();
2271}
2272
[email protected]8d3347f2009-07-09 22:00:212273RenderViewHostDelegate::RendererManagement*
2274TabContents::GetRendererManagementDelegate() {
2275 return &render_manager_;
2276}
2277
[email protected]bf5c2ff392009-07-08 16:24:332278RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212279 TabContents::GetBrowserIntegrationDelegate() {
2280 return this;
[email protected]bf5c2ff392009-07-08 16:24:332281}
2282
[email protected]8d3347f2009-07-09 22:00:212283RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2284 return this;
[email protected]bf5c2ff392009-07-08 16:24:332285}
2286
[email protected]46ba9082010-06-22 10:00:582287RenderViewHostDelegate::ContentSettings*
2288TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552289 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582290}
2291
[email protected]8d3347f2009-07-09 22:00:212292RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322293 return save_package_.get(); // May be NULL, but we can return NULL.
2294}
2295
[email protected]8d3347f2009-07-09 22:00:212296RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092297 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212298}
2299
2300RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2301 return &fav_icon_helper_;
2302}
2303
[email protected]e8dbd674b2010-03-11 18:34:402304RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452305 if (autocomplete_history_manager_.get() == NULL)
2306 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2307 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332308}
2309
[email protected]21674df2009-10-28 19:51:212310RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342311 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212312}
2313
[email protected]1f18184a2010-07-21 19:34:492314RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2315 return GetSSLHelper();
2316}
2317
[email protected]b5977a0c2010-08-24 19:46:262318RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2319 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492320 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262321 return file_select_helper_.get();
2322}
2323
[email protected]fd571bb2010-03-19 01:23:542324AutomationResourceRoutingDelegate*
2325TabContents::GetAutomationResourceRoutingDelegate() {
2326 return delegate();
2327}
2328
[email protected]ced90ae12010-02-20 02:06:162329RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2330 return bookmark_drag_;
2331}
2332
2333void TabContents::SetBookmarkDragDelegate(
2334 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2335 bookmark_drag_ = bookmark_drag;
2336}
2337
[email protected]9fb83e82010-07-02 18:24:552338TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2339 return content_settings_delegate_.get();
2340}
2341
[email protected]93623c5d2009-12-10 21:40:322342RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462343 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512344}
2345
[email protected]57c6a652009-05-04 07:58:342346TabContents* TabContents::GetAsTabContents() {
2347 return this;
2348}
2349
[email protected]7b291f92009-08-14 05:43:532350ViewType::Type TabContents::GetRenderViewType() const {
2351 return ViewType::TAB_CONTENTS;
2352}
2353
2354int TabContents::GetBrowserWindowID() const {
2355 return controller().window_id().id();
2356}
2357
[email protected]420ae012009-04-24 05:16:322358void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062359 NotificationService::current()->Notify(
2360 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2361 Source<TabContents>(this),
2362 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322363 NavigationEntry* entry = controller_.GetActiveEntry();
2364 if (!entry)
2365 return;
2366
2367 // When we're creating views, we're still doing initial setup, so we always
2368 // use the pending DOM UI rather than any possibly existing committed one.
2369 if (render_manager_.pending_dom_ui()) {
2370 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2371 }
2372
2373 if (entry->IsViewSourceMode()) {
2374 // Put the renderer in view source mode.
2375 render_view_host->Send(
2376 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2377 }
[email protected]0666aef2009-05-13 19:48:082378
2379 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322380}
2381
2382void TabContents::RenderViewReady(RenderViewHost* rvh) {
2383 if (rvh != render_view_host()) {
2384 // Don't notify the world, since this came from a renderer in the
2385 // background.
2386 return;
2387 }
2388
2389 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302390 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322391 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302392
2393 // Restore the focus to the tab (otherwise the focus will be on the top
2394 // window).
[email protected]484ae5912010-09-29 19:16:142395 if (was_crashed && !FocusLocationBarByDefault() &&
2396 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302397 Focus();
[email protected]484ae5912010-09-29 19:16:142398 }
[email protected]420ae012009-04-24 05:16:322399}
2400
2401void TabContents::RenderViewGone(RenderViewHost* rvh) {
2402 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092403 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322404 return;
2405 if (rvh != render_view_host()) {
2406 // The pending page's RenderViewHost is gone.
2407 return;
2408 }
2409
2410 SetIsLoading(false, NULL);
2411 NotifyDisconnected();
2412 SetIsCrashed(true);
2413
[email protected]ff9efc62010-02-18 22:10:542414 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212415 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542416 RemoveInfoBar(GetInfoBarDelegateAt(i));
2417
[email protected]8e537302009-06-10 21:19:582418 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552419 // Only do this if we're not in browser shutdown, so that TabContents
2420 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2421 // visible do not flash a sad tab page.
2422 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2423 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322424
2425 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002426 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322427}
2428
[email protected]2e4633c2009-07-09 16:58:062429void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2430 NotificationService::current()->Notify(
2431 NotificationType::RENDER_VIEW_HOST_DELETED,
2432 Source<TabContents>(this),
2433 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482434 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062435}
2436
[email protected]420ae012009-04-24 05:16:322437void TabContents::DidNavigate(RenderViewHost* rvh,
2438 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372439 int extra_invalidate_flags = 0;
2440
2441 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352442 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372443
[email protected]420ae012009-04-24 05:16:322444 render_manager_.DidNavigateMainFrame(rvh);
2445
[email protected]20ede072009-10-06 00:28:352446 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372447 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372448 }
2449
[email protected]420ae012009-04-24 05:16:322450 // Update the site of the SiteInstance if it doesn't have one yet.
2451 if (!GetSiteInstance()->has_site())
2452 GetSiteInstance()->SetSite(params.url);
2453
2454 // Need to update MIME type here because it's referred to in
2455 // UpdateNavigationCommands() called by RendererDidNavigate() to
2456 // determine whether or not to enable the encoding menu.
2457 // It's updated only for the main frame. For a subframe,
2458 // RenderView::UpdateURL does not set params.contents_mime_type.
2459 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2460 // TODO(jungshik): Add a test for the encoding menu to avoid
2461 // regressing it again.
2462 if (PageTransition::IsMainFrame(params.transition))
2463 contents_mime_type_ = params.contents_mime_type;
2464
2465 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372466 bool did_navigate = controller_.RendererDidNavigate(
2467 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392468
[email protected]a9c0bfe2010-09-17 08:35:222469 // Send notification about committed provisional loads. This notification is
2470 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2471 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2472 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072473 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2474 // that is not recorded in the navigation history. For the purpose of
2475 // tracking navigation events, we treat this event as a sub frame navigation
2476 // event.
2477 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2478 ProvisionalLoadDetails load_details(
2479 is_main_frame, details.is_in_page, params.url, std::string(), false,
2480 params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222481 load_details.set_transition_type(params.transition);
2482 // Whether or not a page transition was triggered by going backward or
2483 // forward in the history is only stored in the navigation controller's
2484 // entry list.
2485 if (did_navigate &&
2486 (controller_.GetActiveEntry()->transition_type() &
2487 PageTransition::FORWARD_BACK)) {
2488 load_details.set_transition_type(
2489 params.transition | PageTransition::FORWARD_BACK);
2490 }
2491 NotificationService::current()->Notify(
2492 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2493 Source<NavigationController>(&controller_),
2494 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222495 }
2496
[email protected]3e90d4a2009-07-03 17:38:392497 // Update history. Note that this needs to happen after the entry is complete,
2498 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582499 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392500 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582501 // URLs, we use a data: URL as the real value. We actually want to save the
2502 // about: URL to the history db and keep the data: URL hidden. This is what
2503 // the TabContents' URL getter does.
2504 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2505 CreateHistoryAddPageArgs(GetURL(), details, params));
2506 if (!delegate() ||
2507 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2508 details.type)) {
2509 UpdateHistoryForNavigation(add_page_args);
2510 }
[email protected]3e90d4a2009-07-03 17:38:392511 }
2512
[email protected]76543b92009-08-31 17:27:452513 if (!did_navigate)
2514 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322515
2516 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2517 // for the appropriate notification (best) or you can add it to
2518 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2519 // necessary, please).
2520
2521 // Run post-commit tasks.
2522 if (details.is_main_frame)
2523 DidNavigateMainFramePostCommit(details, params);
2524 DidNavigateAnyFramePostCommit(rvh, details, params);
2525}
2526
2527void TabContents::UpdateState(RenderViewHost* rvh,
2528 int32 page_id,
2529 const std::string& state) {
2530 DCHECK(rvh == render_view_host());
2531
2532 // We must be prepared to handle state updates for any page, these occur
2533 // when the user is scrolling and entering form data, as well as when we're
2534 // leaving a page, in which case our state may have already been moved to
2535 // the next page. The navigation controller will look up the appropriate
2536 // NavigationEntry and update it when it is notified via the delegate.
2537
2538 int entry_index = controller_.GetEntryIndexWithPageID(
2539 GetSiteInstance(), page_id);
2540 if (entry_index < 0)
2541 return;
2542 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2543
2544 if (state == entry->content_state())
2545 return; // Nothing to update.
2546 entry->set_content_state(state);
2547 controller_.NotifyEntryChanged(entry, entry_index);
2548}
2549
2550void TabContents::UpdateTitle(RenderViewHost* rvh,
2551 int32 page_id, const std::wstring& title) {
2552 // If we have a title, that's a pretty good indication that we've started
2553 // getting useful data.
2554 SetNotWaitingForResponse();
2555
2556 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482557 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582558 page_id);
[email protected]420ae012009-04-24 05:16:322559 if (!entry || !UpdateTitleForEntry(entry, title))
2560 return;
2561
2562 // Broadcast notifications when the UI should be updated.
2563 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032564 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322565}
2566
[email protected]420ae012009-04-24 05:16:322567void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402568 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322569 set_encoding(encoding);
2570}
2571
2572void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2573 if (delegate())
2574 delegate()->UpdateTargetURL(this, url);
2575}
2576
2577void TabContents::UpdateThumbnail(const GURL& url,
2578 const SkBitmap& bitmap,
2579 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442580 if (profile()->IsOffTheRecord())
2581 return;
2582
[email protected]420ae012009-04-24 05:16:322583 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492584 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442585 history::TopSites* ts = profile()->GetTopSites();
2586 if (ts)
2587 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282588 } else {
[email protected]e6baed562010-11-02 22:33:442589 HistoryService* hs =
2590 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2591 if (hs)
[email protected]449478302009-06-09 20:04:282592 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322593 }
2594}
2595
[email protected]c4e98902010-06-01 10:20:142596void TabContents::UpdateInspectorSetting(const std::string& key,
2597 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052598 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082599}
2600
[email protected]45aafc92010-06-07 14:18:532601void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052602 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532603}
2604
[email protected]420ae012009-04-24 05:16:322605void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292606 // The UI may be in an event-tracking loop, such as between the
2607 // mouse-down and mouse-up in text selection or a button click.
2608 // Defer the close until after tracking is complete, so that we
2609 // don't free objects out from under the UI.
2610 // TODO(shess): This could probably be integrated with the
2611 // IsDoingDrag() test below. Punting for now because I need more
2612 // research to understand how this impacts platforms other than Mac.
2613 // TODO(shess): This could get more fine-grained. For instance,
2614 // closing a tab in another window while selecting text in the
2615 // current window's Omnibox should be just fine.
2616 if (view()->IsEventTracking()) {
2617 view()->CloseTabAfterEventTracking();
2618 return;
2619 }
2620
[email protected]24a4d1062009-07-10 23:10:422621 // If we close the tab while we're in the middle of a drag, we'll crash.
2622 // Instead, cancel the drag and close it as soon as the drag ends.
2623 if (view()->IsDoingDrag()) {
2624 view()->CancelDragAndCloseTab();
2625 return;
2626 }
2627
[email protected]420ae012009-04-24 05:16:322628 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2629 if (delegate() && rvh == render_view_host())
2630 delegate()->CloseContents(this);
2631}
2632
2633void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2634 if (delegate() && delegate()->IsPopup(this))
2635 delegate()->MoveContents(this, new_bounds);
2636}
2637
[email protected]7ab1e7d62009-10-14 23:32:012638void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322639 SetIsLoading(true, NULL);
[email protected]9e823662010-10-13 23:36:002640 if (content_restrictions_) {
2641 content_restrictions_= 0;
2642 delegate()->ContentRestrictionsChanged(this);
2643 }
[email protected]420ae012009-04-24 05:16:322644}
2645
[email protected]7ab1e7d62009-10-14 23:32:012646void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322647 scoped_ptr<LoadNotificationDetails> details;
2648
2649 NavigationEntry* entry = controller_.GetActiveEntry();
2650 // An entry may not exist for a stop when loading an initial blank page or
2651 // if an iframe injected by script into a blank page finishes loading.
2652 if (entry) {
[email protected]420ae012009-04-24 05:16:322653 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2654
2655 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542656 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322657 entry->transition_type(),
2658 elapsed,
2659 &controller_,
2660 controller_.GetCurrentEntryIndex()));
2661 }
2662
2663 // Tell PasswordManager we've finished a page load, which serves as a
2664 // green light to save pending passwords and reset itself.
2665 GetPasswordManager()->DidStopLoading();
2666
2667 SetIsLoading(false, details.get());
2668}
2669
[email protected]25497492010-09-11 15:15:082670void TabContents::DocumentOnLoadCompletedInMainFrame(
2671 RenderViewHost* render_view_host,
2672 int32 page_id) {
2673 NotificationService::current()->Notify(
2674 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2675 Source<TabContents>(this),
2676 Details<int>(&page_id));
2677}
2678
[email protected]420ae012009-04-24 05:16:322679void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2680 const GURL& source_url,
2681 const GURL& target_url) {
2682 NavigationEntry* entry;
2683 if (page_id == -1)
2684 entry = controller_.pending_entry();
2685 else
2686 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2687 if (!entry || entry->url() != source_url)
2688 return;
2689 entry->set_url(target_url);
2690}
2691
[email protected]420ae012009-04-24 05:16:322692void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2693 WindowOpenDisposition disposition) {
2694 if (render_manager_.dom_ui()) {
2695 // When we're a DOM UI, it will provide a page transition type for us (this
2696 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2697 // generated suggestions).
2698 //
2699 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162700 // want web sites to see a referrer of "chrome://blah" (and some
2701 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322702 // send to the site), so we send no referrer.
2703 OpenURL(url, GURL(), disposition,
2704 render_manager_.dom_ui()->link_transition_type());
2705 } else {
2706 OpenURL(url, referrer, disposition, PageTransition::LINK);
2707 }
2708}
2709
[email protected]1ee614862009-07-06 20:29:182710void TabContents::DomOperationResponse(const std::string& json_string,
2711 int automation_id) {
2712}
2713
[email protected]8b8e7c92010-08-19 18:05:562714void TabContents::ProcessDOMUIMessage(
2715 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322716 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442717 // This can happen if someone uses window.open() to open an extension URL
2718 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562719 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322720 return;
2721 }
[email protected]8b8e7c92010-08-19 18:05:562722 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322723}
2724
2725void TabContents::ProcessExternalHostMessage(const std::string& message,
2726 const std::string& origin,
2727 const std::string& target) {
2728 if (delegate())
2729 delegate()->ForwardMessageToExternalHost(message, origin, target);
2730}
2731
[email protected]420ae012009-04-24 05:16:322732void TabContents::RunJavaScriptMessage(
2733 const std::wstring& message,
2734 const std::wstring& default_prompt,
2735 const GURL& frame_url,
2736 const int flags,
2737 IPC::Message* reply_msg,
2738 bool* did_suppress_message) {
2739 // Suppress javascript messages when requested and when inside a constrained
2740 // popup window (because that activates them and breaks them out of the
2741 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552742 // Also suppress messages when showing an interstitial. The interstitial is
2743 // shown over the previous page, we don't want the hidden page dialogs to
2744 // interfere with the interstitial.
2745 bool suppress_this_message = suppress_javascript_messages_ ||
2746 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322747 if (delegate())
2748 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312749 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322750
2751 *did_suppress_message = suppress_this_message;
2752
2753 if (!suppress_this_message) {
2754 base::TimeDelta time_since_last_message(
2755 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2756 bool show_suppress_checkbox = false;
2757 // Show a checkbox offering to suppress further messages if this message is
2758 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2759 if (time_since_last_message <
2760 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2761 show_suppress_checkbox = true;
2762
[email protected]d6ad7442010-09-05 19:06:522763 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2764 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322765 } else {
2766 // If we are suppressing messages, just reply as is if the user immediately
2767 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542768 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322769 }
2770}
2771
2772void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2773 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012774 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222775 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322776}
2777
2778void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2779 const std::string& json_arguments,
2780 IPC::Message* reply_msg) {
2781 if (delegate()) {
2782 HtmlDialogUIDelegate* dialog_delegate =
2783 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222784 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322785 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2786 }
2787}
2788
[email protected]4d44a1c2010-04-28 19:20:412789void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562790 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412791 GetPasswordManager()->PasswordFormsFound(forms);
2792}
2793
2794void TabContents::PasswordFormsVisible(
2795 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2796 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322797}
2798
[email protected]420ae012009-04-24 05:16:322799// Checks to see if we should generate a keyword based on the OSDD, and if
2800// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202801void TabContents::PageHasOSDD(
2802 RenderViewHost* render_view_host,
2803 int32 page_id,
2804 const GURL& url,
2805 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122806 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322807 DCHECK(url.is_valid());
2808 if (!IsActiveEntry(page_id))
2809 return;
[email protected]420ae012009-04-24 05:16:322810 if (!profile()->GetTemplateURLFetcher())
2811 return;
[email protected]420ae012009-04-24 05:16:322812 if (profile()->IsOffTheRecord())
2813 return;
2814
[email protected]2de7e002010-10-11 22:58:202815 TemplateURLFetcher::ProviderType provider_type;
2816 switch (msg_provider_type.type) {
2817 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2818 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2819 break;
2820
2821 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2822 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2823 break;
2824
2825 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2826 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2827 break;
2828
2829 default:
2830 NOTREACHED();
2831 return;
2832 }
2833
[email protected]420ae012009-04-24 05:16:322834 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2835 DCHECK(entry);
2836
2837 const NavigationEntry* base_entry = entry;
2838 if (IsFormSubmit(base_entry)) {
2839 // If the current page is a form submit, find the last page that was not
2840 // a form submit and use its url to generate the keyword from.
2841 int index = controller_.last_committed_entry_index() - 1;
2842 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2843 index--;
2844 if (index >= 0)
2845 base_entry = controller_.GetEntryAtIndex(index);
2846 else
2847 base_entry = NULL;
2848 }
2849
2850 // We want to use the user typed URL if available since that represents what
2851 // the user typed to get here, and fall back on the regular URL if not.
2852 if (!base_entry)
2853 return;
2854 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2855 base_entry->user_typed_url() : base_entry->url();
2856 if (!keyword_url.is_valid())
2857 return;
[email protected]2de7e002010-10-11 22:58:202858
[email protected]0b5b85c2010-10-11 23:00:122859 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2860 keyword_url,
2861 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532862
[email protected]0b5b85c2010-10-11 23:00:122863 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322864 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322865 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2866 keyword,
2867 url,
2868 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122869 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202870 provider_type);
[email protected]420ae012009-04-24 05:16:322871}
2872
[email protected]420ae012009-04-24 05:16:322873GURL TabContents::GetAlternateErrorPageURL() const {
2874 GURL url;
2875 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2876 if (profile()->IsOffTheRecord())
2877 return url;
2878
2879 PrefService* prefs = profile()->GetPrefs();
2880 DCHECK(prefs);
2881 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152882 url = google_util::AppendGoogleLocaleParam(
2883 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322884 url = google_util::AppendGoogleTLDParam(url);
2885 }
2886 return url;
2887}
2888
2889WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062890 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552891 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082892 WebPreferences web_prefs =
2893 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2894
[email protected]9beff752010-09-22 19:35:432895 // Force accelerated compositing and 2d canvas off for chrome: and
2896 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432897 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2898 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082899 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432900 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082901 }
2902
[email protected]39553442010-09-09 00:01:552903#if defined(OS_MACOSX)
2904 // Disable accelerated compositing if IOSurface's are not supported,
2905 // as is the case in 10.5.
2906 if (!IOSurfaceSupport::Initialize())
2907 web_prefs.accelerated_compositing_enabled = false;
2908#endif
2909
[email protected]447021c2010-09-08 21:29:082910 return web_prefs;
[email protected]420ae012009-04-24 05:16:322911}
2912
[email protected]fa1cf0b82010-01-15 21:49:442913void TabContents::OnIgnoredUIEvent() {
2914 if (constrained_window_count()) {
2915 ConstrainedWindow* window = *constrained_window_begin();
2916 window->FocusConstrainedWindow();
2917 }
2918}
2919
[email protected]420ae012009-04-24 05:16:322920void TabContents::OnJSOutOfMemory() {
2921 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582922 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2923 NULL, true));
[email protected]420ae012009-04-24 05:16:322924}
2925
[email protected]420ae012009-04-24 05:16:322926void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2927 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342928 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322929 // delivered to a pending RenderViewHost. We must first run the onunload
2930 // handler of the old RenderViewHost before we can allow it to proceed.
2931 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2932 new_request_id);
2933}
2934
[email protected]420ae012009-04-24 05:16:322935gfx::Rect TabContents::GetRootWindowResizerRect() const {
2936 if (delegate())
2937 return delegate()->GetRootWindowResizerRect();
2938 return gfx::Rect();
2939}
2940
2941void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2942 bool is_during_unload) {
2943 if (is_during_unload) {
2944 // Hang occurred while firing the beforeunload/unload handler.
2945 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112946 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322947
2948 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2949 return;
2950
2951 // If the tab hangs in the beforeunload/unload handler there's really
2952 // nothing we can do to recover. Pretend the unload listeners have
2953 // all fired and close the tab. If the hang is in the beforeunload handler
2954 // then the user will not have the option of cancelling the close.
2955 Close(rvh);
2956 return;
2957 }
2958
2959 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002960 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322961}
2962
2963void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002964 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322965}
2966
2967void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562968 net::LoadState load_state,
2969 uint64 upload_position,
2970 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322971 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562972 upload_position_ = upload_position;
2973 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292974 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192975 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292976 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532977 load_state_host_ =
2978 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322979 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2980 SetNotWaitingForResponse();
2981 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502982 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322983}
2984
[email protected]1ee614862009-07-06 20:29:182985bool TabContents::IsExternalTabContainer() const {
2986 if (!delegate())
2987 return false;
2988
2989 return delegate()->IsExternalTabContainer();
2990}
2991
[email protected]1ee614862009-07-06 20:29:182992void TabContents::DidInsertCSS() {
2993 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322994}
2995
[email protected]130efb02009-09-18 18:54:352996void TabContents::FocusedNodeChanged() {
2997 NotificationService::current()->Notify(
2998 NotificationType::FOCUS_CHANGED_IN_PAGE,
2999 Source<RenderViewHost>(render_view_host()),
3000 NotificationService::NoDetails());
3001}
3002
[email protected]b75b8292010-10-01 07:28:253003void TabContents::UpdateZoomLimits(int minimum_percent,
3004 int maximum_percent,
3005 bool remember) {
3006 minimum_zoom_percent_ = minimum_percent;
3007 maximum_zoom_percent_ = maximum_percent;
3008 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383009}
3010
[email protected]9e823662010-10-13 23:36:003011void TabContents::UpdateContentRestrictions(int restrictions) {
3012 content_restrictions_ = restrictions;
3013 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323014}
3015
[email protected]420ae012009-04-24 05:16:323016void TabContents::BeforeUnloadFiredFromRenderManager(
3017 bool proceed,
3018 bool* proceed_to_fire_unload) {
3019 if (delegate())
3020 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3021}
3022
[email protected]3a3d47472010-07-15 21:03:543023void TabContents::DidStartLoadingFromRenderManager(
3024 RenderViewHost* render_view_host) {
3025 DidStartLoading();
3026}
3027
3028void TabContents::RenderViewGoneFromRenderManager(
3029 RenderViewHost* render_view_host) {
3030 RenderViewGone(render_view_host);
3031}
3032
[email protected]420ae012009-04-24 05:16:323033void TabContents::UpdateRenderViewSizeForRenderManager() {
3034 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263035 gfx::Size size = view_->GetContainerSize();
3036 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3037 // here during container initialization and normal window size will be set
3038 // later. In case of tab duplication this resizing to 0x0 prevents setting
3039 // normal size later so just ignore it.
3040 if (!size.IsEmpty())
3041 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323042}
3043
[email protected]3a3d47472010-07-15 21:03:543044void TabContents::NotifySwappedFromRenderManager() {
3045 NotifySwapped();
3046}
3047
3048NavigationController& TabContents::GetControllerForRenderManager() {
3049 return controller();
3050}
3051
[email protected]420ae012009-04-24 05:16:323052DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223053 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323054}
3055
3056NavigationEntry*
3057TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3058 return controller_.GetLastCommittedEntry();
3059}
3060
3061bool TabContents::CreateRenderViewForRenderManager(
3062 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323063 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523064
[email protected]674b3822010-08-04 04:02:513065 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323066 return false;
3067
3068 // Now that the RenderView has been created, we need to tell it its size.
3069 rwh_view->SetSize(view_->GetContainerSize());
3070
3071 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3072 render_view_host);
3073 return true;
3074}
3075
3076void TabContents::Observe(NotificationType type,
3077 const NotificationSource& source,
3078 const NotificationDetails& details) {
3079 switch (type.value) {
3080 case NotificationType::BOOKMARK_MODEL_LOADED:
3081 // BookmarkModel finished loading, fall through to update starred state.
3082 case NotificationType::URLS_STARRED: {
3083 // Somewhere, a URL has been starred.
3084 // Ignore notifications for profiles other than our current one.
3085 Profile* source_profile = Source<Profile>(source).ptr();
3086 if (!source_profile || !source_profile->IsSameProfile(profile()))
3087 return;
3088
3089 UpdateStarredStateForCurrentURL();
3090 break;
3091 }
3092 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513093 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323094 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3095 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3096 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533097 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3098 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323099 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173100 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3101 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323102 } else {
3103 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3104 }
3105 break;
3106 }
3107 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3108 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3109 break;
3110
3111 case NotificationType::NAV_ENTRY_COMMITTED: {
3112 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3113
3114 NavigationController::LoadCommittedDetails& committed_details =
3115 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3116 ExpireInfoBars(committed_details);
3117 break;
3118 }
3119
[email protected]d3ba77272009-09-03 00:06:093120#if defined(OS_LINUX)
3121 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543122 renderer_preferences_util::UpdateFromSystemSettings(
3123 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093124 render_view_host()->SyncRendererPrefs();
3125 break;
3126 }
3127#endif
3128
[email protected]6c32ce72010-03-08 05:18:063129 case NotificationType::USER_STYLE_SHEET_UPDATED:
3130 UpdateWebPreferences();
3131 break;
3132
[email protected]79580c62010-02-02 02:36:253133 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293134 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253135 settings_details(details);
[email protected]79580c62010-02-02 02:36:253136 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493137 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293138 if (entry)
[email protected]da0c8e92010-02-09 23:25:493139 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293140 if (settings_details.ptr()->update_all() ||
3141 settings_details.ptr()->pattern().Matches(entry_url)) {
3142 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233143 profile()->GetHostContentSettingsMap()->
3144 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253145 }
3146 break;
3147 }
3148
[email protected]e5adff72010-06-14 18:13:063149 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573150 break;
[email protected]a888b29e62010-04-01 13:38:573151
3152 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063153 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573154 break;
[email protected]a888b29e62010-04-01 13:38:573155
[email protected]88152052010-10-01 04:05:183156 case NotificationType::GOOGLE_URL_UPDATED:
3157 UpdateAlternateErrorPageURL();
3158 break;
3159
[email protected]420ae012009-04-24 05:16:323160 default:
3161 NOTREACHED();
3162 }
3163}
[email protected]aacd7cc2009-09-02 14:51:103164
[email protected]9adb9692010-10-29 23:14:023165void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083166 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433167
[email protected]a888b29e62010-04-01 13:38:573168 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083169 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3170 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573171 extension,
[email protected]807871f2010-09-16 01:04:483172 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3173 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573174 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3175 Extension::EXTENSION_ICON_SMALLISH),
3176 ImageLoadingTracker::CACHE);
3177 } else {
[email protected]98aa0b52010-05-06 17:03:083178 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573179 }
3180}
3181
[email protected]9adb9692010-10-29 23:14:023182const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573183 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3184 if (!extensions_service)
3185 return NULL;
3186
[email protected]9adb9692010-10-29 23:14:023187 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573188 return extension ?
3189 extension : extensions_service->GetExtensionByWebExtent(url);
3190}
3191
[email protected]a888b29e62010-04-01 13:38:573192void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3193 int index) {
3194 if (image) {
[email protected]98aa0b52010-05-06 17:03:083195 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573196 NotifyNavigationStateChanged(INVALIDATE_TAB);
3197 }
3198}
3199
[email protected]beb440c2009-11-06 04:08:543200gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3201 return view_->GetTopLevelNativeWindow();
3202}
3203
3204void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3205 bool success,
3206 const std::wstring& prompt) {
3207 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3208 if (is_showing_before_unload_dialog_ && !success) {
3209 // If a beforeunload dialog is canceled, we need to stop the throbber from
3210 // spinning, since we forced it to start spinning in Navigate.
3211 DidStopLoading();
3212
3213 tab_close_start_time_ = base::TimeTicks();
3214 }
3215 is_showing_before_unload_dialog_ = false;
3216 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3217}
3218
3219void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3220 set_suppress_javascript_messages(suppress_message_boxes);
3221}
3222
[email protected]3a3d47472010-07-15 21:03:543223TabContents* TabContents::AsTabContents() {
3224 return this;
3225}
3226
3227ExtensionHost* TabContents::AsExtensionHost() {
3228 return NULL;
3229}
3230
[email protected]41fc0322009-09-04 22:23:403231void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103232 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3233}
[email protected]f45d2a72010-03-08 23:28:353234
3235void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3236 app_icon_ = app_icon;
3237 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3238}
[email protected]ea68c06a2010-04-23 17:25:373239
3240// After a successful *new* login attempt, we take the PasswordFormManager in
3241// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3242// the user makes up their mind with the "save password" infobar. Note if the
3243// login is one we already know about, the end of the line is
3244// provisional_save_manager_ because we just update it on success and so such
3245// forms never end up in an infobar.
3246class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3247 public:
3248 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463249 PasswordFormManager* form_to_save)
3250 : ConfirmInfoBarDelegate(tab_contents),
3251 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583252 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373253
[email protected]d75aba1d2010-08-02 23:35:583254 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373255
[email protected]d75aba1d2010-08-02 23:35:583256 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373257 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463258 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583259 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373260 delete this;
3261 }
3262
[email protected]d75aba1d2010-08-02 23:35:583263 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3264
[email protected]e23d3a32010-08-13 19:39:583265 virtual string16 GetMessageText() const {
3266 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373267 }
3268
3269 virtual SkBitmap* GetIcon() const {
3270 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3271 IDR_INFOBAR_SAVE_PASSWORD);
3272 }
3273
3274 virtual int GetButtons() const {
3275 return BUTTON_OK | BUTTON_CANCEL;
3276 }
3277
[email protected]e23d3a32010-08-13 19:39:583278 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373279 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583280 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373281 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583282 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373283 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583284 return string16();
[email protected]ea68c06a2010-04-23 17:25:373285 }
3286
3287 virtual bool Accept() {
3288 DCHECK(form_to_save_.get());
3289 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583290 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373291 return true;
3292 }
3293
3294 virtual bool Cancel() {
3295 DCHECK(form_to_save_.get());
3296 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583297 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373298 return true;
3299 }
[email protected]d75aba1d2010-08-02 23:35:583300 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373301
3302 private:
3303 // The PasswordFormManager managing the form we're asking the user about,
3304 // and should update as per her decision.
3305 scoped_ptr<PasswordFormManager> form_to_save_;
3306
[email protected]12bb6822010-06-16 02:00:463307 // Used to track the results we get from the info bar.
3308 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583309 NO_RESPONSE = 0,
3310 REMEMBER_PASSWORD,
3311 DONT_REMEMBER_PASSWORD,
3312 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463313 };
3314 ResponseType infobar_response_;
3315
[email protected]ea68c06a2010-04-23 17:25:373316 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3317};
3318
3319void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163320 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373321 render_view_host()->FillPasswordForm(form_data);
3322}
3323
3324void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3325 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3326}
3327
3328Profile* TabContents::GetProfileForPasswordManager() {
3329 return profile();
3330}
3331
3332bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3333 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3334}