blob: 48e390856de933be56c16a39b835a805bfebe0d5 [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]06821f42d2010-05-03 22:34:357#if defined(OS_CHROMEOS)
8// For GdkScreen
9#include <gdk/gdk.h>
10#endif // defined(OS_CHROMEOS)
11
[email protected]a92b8642009-05-05 23:38:5612#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1113#include "app/resource_bundle.h"
[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]420ae012009-04-24 05:16:3218#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5419#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3720#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4021#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5422#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4523#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2124#include "chrome/browser/autofill/autofill_manager.h"
[email protected]aad51d1c2010-08-05 08:38:0925#include "chrome/browser/blocked_plugin_manager.h"
[email protected]66ba4932009-06-04 19:22:1326#include "chrome/browser/blocked_popup_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]0189bc722009-08-28 21:56:4844#include "chrome/browser/favicon_service.h"
[email protected]e5d2f7132010-04-09 18:13:5345#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4946#include "chrome/browser/google/google_util.h"
[email protected]79580c62010-02-02 02:36:2547#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2648#include "chrome/browser/hung_renderer_dialog.h"
[email protected]12f74a92010-02-05 22:32:1449#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3250#include "chrome/browser/load_from_memory_cache_details.h"
51#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4452#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0553#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1054#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5755#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2456#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5757#include "chrome/browser/plugin_installer.h"
[email protected]8e0bbf12010-07-20 00:03:4358#include "chrome/browser/popup_blocked_animation.h"
[email protected]37858e52010-08-26 00:22:0259#include "chrome/browser/prefs/pref_service.h"
[email protected]12802702010-07-09 19:43:0960#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4461#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0762#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1663#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5464#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3765#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0766#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5467#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3268#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1169#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1670#include "chrome/browser/search_engines/template_url_fetcher.h"
71#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1772#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1773#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5474#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]fd2b9ce2010-08-11 04:03:5775#include "chrome/browser/tab_contents/match_preview.h"
[email protected]f3ec7742009-01-15 00:59:1676#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4377#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1678#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]b5977a0c2010-08-24 19:46:2679#include "chrome/browser/tab_contents/tab_contents_file_select_helper.h"
[email protected]1f18184a2010-07-21 19:34:4980#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5781#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0282#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1683#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5884#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2785#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4986#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5787#include "chrome/common/extensions/extension_action.h"
[email protected]942690b132010-05-11 06:42:1488#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0989#include "chrome/common/extensions/url_pattern.h"
90#include "chrome/common/navigation_types.h"
91#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5692#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2993#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3294#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0295#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:1896#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:5497#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3798#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2699#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32100#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06101#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37102#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32103#include "net/base/mime_util.h"
104#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29105#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32106#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18107#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03108#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00109
[email protected]420ae012009-04-24 05:16:32110// Cross-Site Navigations
111//
112// If a TabContents is told to navigate to a different web site (as determined
113// by SiteInstance), it will replace its current RenderViewHost with a new
114// RenderViewHost dedicated to the new SiteInstance. This works as follows:
115//
116// - Navigate determines whether the destination is cross-site, and if so,
117// it creates a pending_render_view_host_ and moves into the PENDING
118// RendererState.
119// - The pending RVH is "suspended," so that no navigation messages are sent to
120// its renderer until the onbeforeunload JavaScript handler has a chance to
121// run in the current RVH.
122// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
123// that it has a pending cross-site request. ResourceDispatcherHost will
124// check for this when the response arrives.
125// - The current RVH runs its onbeforeunload handler. If it returns false, we
126// cancel all the pending logic and go back to NORMAL. Otherwise we allow
127// the pending RVH to send the navigation request to its renderer.
128// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
129// checks CrossSiteRequestManager to see that the RVH responsible has a
130// pending cross-site request, and then installs a CrossSiteEventHandler.
131// - When RDH receives a response, the BufferedEventHandler determines whether
132// it is a download. If so, it sends a message to the new renderer causing
133// it to cancel the request, and the download proceeds in the download
134// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34135// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32136// doesn't affect any functionality.
137// - After RDH receives a response and determines that it is safe and not a
138// download, it pauses the response to first run the old page's onunload
139// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34140// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32141// to the current RVH.
142// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
143// the ResourceDispatcherHost, who unpauses the response. Data is then sent
144// to the pending RVH.
145// - The pending renderer sends a FrameNavigate message that invokes the
146// DidNavigate method. This replaces the current RVH with the
147// pending RVH and goes back to the NORMAL RendererState.
148
149namespace {
150
151// Amount of time we wait between when a key event is received and the renderer
152// is queried for its state and pushed to the NavigationEntry.
153const int kQueryStateDelay = 5000;
154
155const int kSyncWaitDelay = 40;
156
[email protected]304f8792009-08-19 21:28:09157#if defined(OS_CHROMEOS)
158// If a popup window is bigger than this fraction of the screen on chrome os,
159// turn it into a tab
160const float kMaxWidthFactor = 0.5;
161const float kMaxHeightFactor = 0.6;
162#endif
163
[email protected]420ae012009-04-24 05:16:32164// If another javascript message box is displayed within
165// kJavascriptMessageExpectedDelay of a previous javascript message box being
166// dismissed, display an option to suppress future message boxes from this
167// contents.
168const int kJavascriptMessageExpectedDelay = 1000;
169
[email protected]420ae012009-04-24 05:16:32170// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51171const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32172 prefs::kAlternateErrorPagesEnabled,
173 prefs::kWebKitJavaEnabled,
174 prefs::kWebKitJavascriptEnabled,
175 prefs::kWebKitLoadsImagesAutomatically,
176 prefs::kWebKitPluginsEnabled,
177 prefs::kWebKitUsesUniversalDetector,
178 prefs::kWebKitSerifFontFamily,
179 prefs::kWebKitSansSerifFontFamily,
180 prefs::kWebKitFixedFontFamily,
181 prefs::kWebKitDefaultFontSize,
182 prefs::kWebKitDefaultFixedFontSize,
[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]1be69aa2010-09-02 01:02:46228void MakeNavigateParams(const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16229 NavigationController::ReloadType reload_type,
230 ViewMsg_Navigate_Params* params) {
[email protected]1be69aa2010-09-02 01:02:46231 const NavigationEntry& entry = *controller.pending_entry();
[email protected]056de2d2009-06-26 16:41:34232 params->page_id = entry.page_id();
[email protected]1be69aa2010-09-02 01:02:46233 params->pending_history_list_offset = controller.pending_entry_index();
[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(),
284 CURRENT_TAB, PageTransition::LINK);
285 return false;
286 }
287
288 virtual bool Cancel() {
289 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
290 CURRENT_TAB, PageTransition::LINK);
291 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]34ac70502009-09-25 17:07:23317 const TabContents* base_tab_contents)
[email protected]b680ad22009-04-15 23:19:42318 : delegate_(NULL),
[email protected]66ba4932009-06-04 19:22:13319 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(this, profile)),
320 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22321 TabContentsView::Create(this))),
322 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57323 property_bag_(),
324 registrar_(),
[email protected]12802702010-07-09 19:43:09325 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
326 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57327 save_package_(),
[email protected]6db0def92010-03-02 19:55:45328 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21329 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57330 password_manager_(),
331 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06332 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22333 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34334 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29335 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34336 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34337 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57338 current_load_start_(),
339 load_state_(net::LOAD_STATE_IDLE),
340 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56341 upload_size_(0),
342 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57343 received_page_title_(false),
344 is_starred_(false),
345 contents_mime_type_(),
346 encoding_(),
[email protected]332af7732009-03-11 13:21:35347 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49348 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47349 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57350 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57351 find_ui_active_(false),
352 find_op_aborted_(false),
353 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12354 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12355 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08356 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57357 capturing_contents_(false),
358 is_being_destroyed_(false),
359 notify_disconnection_(false),
360 history_requests_(),
361#if defined(OS_WIN)
362 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
363#endif
364 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44365 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01366 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54367 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54368 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16369 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38370 closed_by_user_gesture_(false),
371 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54372 renderer_preferences_util::UpdateFromSystemSettings(
373 &renderer_preferences_, profile);
374
[email protected]9fb83e82010-07-02 18:24:55375 content_settings_delegate_.reset(
376 new TabSpecificContentSettings(this, profile));
377
[email protected]16779842009-07-08 23:45:29378#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02379 // Make sure the thumbnailer is started before starting the render manager.
380 // The thumbnailer will want to listen for RVH creations, one of which will
381 // happen in RVHManager::Init.
382 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
383 if (generator)
384 generator->StartThumbnailing();
385#endif
386
[email protected]12636df2009-09-28 22:32:21387 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32388
[email protected]34ac70502009-09-25 17:07:23389 // We have the initial size of the view be based on the size of the passed in
390 // tab contents (normally a tab from the same window).
391 view_->CreateView(base_tab_contents ?
392 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32393
394 // Register for notifications about all interested prefs change.
395 PrefService* prefs = profile->GetPrefs();
396 if (prefs) {
397 for (int i = 0; i < kPrefsToObserveLength; ++i)
398 prefs->AddPrefObserver(kPrefsToObserve[i], this);
399 }
400
401 // Register for notifications about URL starredness changing on any profile.
402 registrar_.Add(this, NotificationType::URLS_STARRED,
403 NotificationService::AllSources());
404 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
405 NotificationService::AllSources());
406 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
407 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09408#if defined(OS_LINUX)
409 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
410 NotificationService::AllSources());
411#endif
[email protected]420ae012009-04-24 05:16:32412
[email protected]6c32ce72010-03-08 05:18:06413 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
414 NotificationService::AllSources());
415
[email protected]79580c62010-02-02 02:36:25416 // Register for notifications about content setting changes.
417 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
418 NotificationService::AllSources());
419
[email protected]a888b29e62010-04-01 13:38:57420 // Listen for extension changes so we can update extension_for_current_page_.
421 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
422 NotificationService::AllSources());
423 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
424 NotificationService::AllSources());
425 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
426 NotificationService::AllSources());
427
[email protected]c8865482009-07-23 20:40:10428 // Set-up the showing of the omnibox search infobar if applicable.
429 if (OmniboxSearchHint::IsEnabled(profile))
430 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]fd2b9ce2010-08-11 04:03:57431
432 if (MatchPreview::IsEnabled())
433 match_preview_.reset(new MatchPreview(this));
[email protected]332af7732009-03-11 13:21:35434}
initial.commit09911bf2008-07-26 23:55:29435
436TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32437 is_being_destroyed_ = true;
438
[email protected]bfe4c1582009-10-02 18:11:09439 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32440 registrar_.RemoveAll();
441
442 // Unregister the notifications of all observed prefs change.
443 PrefService* prefs = profile()->GetPrefs();
444 if (prefs) {
445 for (int i = 0; i < kPrefsToObserveLength; ++i)
446 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
447 }
448
[email protected]420ae012009-04-24 05:16:32449 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00450 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32451
[email protected]420ae012009-04-24 05:16:32452 // First cleanly close all child windows.
453 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
454 // some of these to close. CloseWindows is async, so it might get called
455 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49456 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32457
[email protected]8cc8d492010-02-02 10:40:49458 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13459 if (blocked_popups_)
460 blocked_popups_->Destroy();
461
[email protected]420ae012009-04-24 05:16:32462 // Notify any observer that have a reference on this tab contents.
463 NotificationService::current()->Notify(
464 NotificationType::TAB_CONTENTS_DESTROYED,
465 Source<TabContents>(this),
466 NotificationService::NoDetails());
467
[email protected]1e5e74f2009-05-27 20:55:12468 // Notify any lasting InfobarDelegates that have not yet been removed that
469 // whatever infobar they were handling in this TabContents has closed,
470 // because the TabContents is going away entirely.
471 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
472 // notification may trigger infobars calls that access their delegate. (and
473 // some implementations of InfoBarDelegate do delete themselves on
474 // InfoBarClosed()).
475 for (int i = 0; i < infobar_delegate_count(); ++i) {
476 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
477 delegate->InfoBarClosed();
478 }
479 infobar_delegates_.clear();
480
[email protected]420ae012009-04-24 05:16:32481 // TODO(brettw) this should be moved to the view.
482#if defined(OS_WIN)
483 // If we still have a window handle, destroy it. GetNativeView can return
484 // NULL if this contents was part of a window that closed.
485 if (GetNativeView())
486 ::DestroyWindow(GetNativeView());
487#endif
[email protected]7ab1e7d62009-10-14 23:32:01488
489 // OnCloseStarted isn't called in unit tests.
490 if (!tab_close_start_time_.is_null()) {
491 UMA_HISTOGRAM_TIMES("Tab.Close",
492 base::TimeTicks::Now() - tab_close_start_time_);
493 }
initial.commit09911bf2008-07-26 23:55:29494}
495
[email protected]d5f942ba2008-09-26 19:30:34496// static
497void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32498 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
499
500 WebPreferences pref_defaults;
501 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
502 pref_defaults.javascript_enabled);
503 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
504 pref_defaults.web_security_enabled);
505 prefs->RegisterBooleanPref(
506 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
507 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
508 pref_defaults.loads_images_automatically);
509 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
510 pref_defaults.plugins_enabled);
511 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
512 pref_defaults.dom_paste_enabled);
513 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
514 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14515 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32516 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
517 pref_defaults.text_areas_are_resizable);
518 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
519 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36520 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
521 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32522
523 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
524 IDS_ACCEPT_LANGUAGES);
525 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
526 IDS_DEFAULT_ENCODING);
527 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
528 IDS_STANDARD_FONT_IS_SERIF);
529 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
530 IDS_FIXED_FONT_FAMILY);
531 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
532 IDS_SERIF_FONT_FAMILY);
533 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
534 IDS_SANS_SERIF_FONT_FAMILY);
535 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
536 IDS_CURSIVE_FONT_FAMILY);
537 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
538 IDS_FANTASY_FONT_FAMILY);
539 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
540 IDS_DEFAULT_FONT_SIZE);
541 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
542 IDS_DEFAULT_FIXED_FONT_SIZE);
543 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
544 IDS_MINIMUM_FONT_SIZE);
545 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
546 IDS_MINIMUM_LOGICAL_FONT_SIZE);
547 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
548 IDS_USES_UNIVERSAL_DETECTOR);
549 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
550 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29551}
552
[email protected]13367f72009-07-08 16:39:02553// Returns true if contains content rendered by an extension.
554bool TabContents::HostsExtension() const {
555 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34556}
557
[email protected]cf28ec52010-04-09 22:56:34558AutoFillManager* TabContents::GetAutoFillManager() {
559 if (autofill_manager_.get() == NULL)
560 autofill_manager_.reset(new AutoFillManager(this));
561 return autofill_manager_.get();
562}
563
[email protected]6e95706d2009-04-23 22:55:01564PasswordManager* TabContents::GetPasswordManager() {
565 if (password_manager_.get() == NULL)
566 password_manager_.reset(new PasswordManager(this));
567 return password_manager_.get();
568}
569
570PluginInstaller* TabContents::GetPluginInstaller() {
571 if (plugin_installer_.get() == NULL)
572 plugin_installer_.reset(new PluginInstaller(this));
573 return plugin_installer_.get();
574}
575
[email protected]1f18184a2010-07-21 19:34:49576TabContentsSSLHelper* TabContents::GetSSLHelper() {
577 if (ssl_helper_.get() == NULL)
578 ssl_helper_.reset(new TabContentsSSLHelper(this));
579 return ssl_helper_.get();
580}
581
[email protected]8cb5d5b2010-02-09 11:36:16582RenderProcessHost* TabContents::GetRenderProcessHost() const {
583 return render_manager_.current_host()->process();
584}
585
[email protected]98aa0b52010-05-06 17:03:08586void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46587 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08588 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10589
[email protected]98aa0b52010-05-06 17:03:08590 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57591
[email protected]fca656c2010-02-10 20:30:10592 NotificationService::current()->Notify(
593 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
594 Source<TabContents>(this),
595 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49596}
597
[email protected]98aa0b52010-05-06 17:03:08598void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
599 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40600 return;
601
602 ExtensionsService* extension_service = profile()->GetExtensionsService();
603 if (extension_service && extension_service->is_ready()) {
604 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08605 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40606 if (extension)
[email protected]98aa0b52010-05-06 17:03:08607 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40608 }
609}
610
[email protected]98aa0b52010-05-06 17:03:08611SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08612 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51613 return NULL;
614
[email protected]98aa0b52010-05-06 17:03:08615 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51616}
617
[email protected]d5f942ba2008-09-26 19:30:34618const GURL& TabContents::GetURL() const {
619 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57620 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54621 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34622}
623
[email protected]96d185d2009-04-24 03:28:54624const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55625 // Transient entries take precedence. They are used for interstitial pages
626 // that are shown on top of existing pages.
627 NavigationEntry* entry = controller_.GetTransientEntry();
628 if (entry)
629 return entry->GetTitleForDisplay(&controller_);
630
[email protected]96d185d2009-04-24 03:28:54631 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
632 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
633 if (our_dom_ui) {
634 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55635 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54636 if (!(entry && entry->IsViewSourceMode())) {
637 // Give the DOM UI the chance to override our title.
638 const string16& title = our_dom_ui->overridden_title();
639 if (!title.empty())
640 return title;
641 }
642 }
643
644 // We use the title for the last committed entry rather than a pending
645 // navigation entry. For example, when the user types in a URL, we want to
646 // keep the old page's title until the new load has committed and we get a new
647 // title.
[email protected]96d185d2009-04-24 03:28:54648 entry = controller_.GetLastCommittedEntry();
649 if (entry)
650 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54651 return EmptyString16();
652}
653
[email protected]bbbc1ef2010-02-12 18:03:41654// static
655string16 TabContents::GetDefaultTitle() {
656 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
657}
658
[email protected]d5f942ba2008-09-26 19:30:34659int32 TabContents::GetMaxPageID() {
660 if (GetSiteInstance())
661 return GetSiteInstance()->max_page_id();
662 else
663 return max_page_id_;
664}
665
666void TabContents::UpdateMaxPageID(int32 page_id) {
667 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34668 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34669 // testing.
670 if (GetSiteInstance())
671 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16672 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34673}
674
[email protected]96d185d2009-04-24 03:28:54675SiteInstance* TabContents::GetSiteInstance() const {
676 return render_manager_.current_host()->site_instance();
677}
678
[email protected]96d185d2009-04-24 03:28:54679bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15680 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54681 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15682 if (entry && (entry->IsViewSourceMode() ||
683 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54684 return true;
[email protected]8ab24cc2009-11-13 20:56:15685 }
[email protected]83e3895b2009-06-11 00:07:16686
[email protected]96d185d2009-04-24 03:28:54687 DOMUI* dom_ui = GetDOMUIForCurrentState();
688 if (dom_ui)
689 return !dom_ui->should_hide_url();
690 return true;
691}
692
[email protected]d5f942ba2008-09-26 19:30:34693SkBitmap TabContents::GetFavIcon() const {
694 // Like GetTitle(), we also want to use the favicon for the last committed
695 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57696 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47697 if (entry)
698 return entry->favicon().bitmap();
699
[email protected]ce3fa3c2009-04-20 19:55:57700 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34701 if (entry)
702 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34703 return SkBitmap();
704}
705
[email protected]0b303cc2009-09-28 22:35:15706bool TabContents::FavIconIsValid() const {
707 NavigationEntry* entry = controller_.GetTransientEntry();
708 if (entry)
709 return entry->favicon().is_valid();
710
711 entry = controller_.GetLastCommittedEntry();
712 if (entry)
713 return entry->favicon().is_valid();
714
715 return false;
716}
717
[email protected]96d185d2009-04-24 03:28:54718bool TabContents::ShouldDisplayFavIcon() {
719 // Always display a throbber during pending loads.
720 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
721 return true;
722
723 DOMUI* dom_ui = GetDOMUIForCurrentState();
724 if (dom_ui)
725 return !dom_ui->hide_favicon();
726 return true;
727}
728
[email protected]96d185d2009-04-24 03:28:54729std::wstring TabContents::GetStatusText() const {
730 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
731 return std::wstring();
732
733 switch (load_state_) {
734 case net::LOAD_STATE_WAITING_FOR_CACHE:
735 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04736 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
737 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54738 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
739 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
740 case net::LOAD_STATE_RESOLVING_HOST:
741 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
742 case net::LOAD_STATE_CONNECTING:
743 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06744 case net::LOAD_STATE_SSL_HANDSHAKE:
745 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54746 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56747 if (upload_size_)
748 return l10n_util::GetStringF(
749 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
750 static_cast<int>((100 * upload_position_) / upload_size_));
751 else
752 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54753 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
754 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
755 load_state_host_);
756 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
757 case net::LOAD_STATE_IDLE:
758 case net::LOAD_STATE_READING_RESPONSE:
759 break;
760 }
761
762 return std::wstring();
763}
764
[email protected]d5f942ba2008-09-26 19:30:34765void TabContents::SetIsCrashed(bool state) {
766 if (state == is_crashed_)
767 return;
768
769 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50770 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34771}
772
[email protected]744ef172009-10-16 21:53:46773void TabContents::PageActionStateChanged() {
774 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00775}
[email protected]ce5c4502009-05-06 16:46:11776
[email protected]d5f942ba2008-09-26 19:30:34777void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
778 if (delegate_)
779 delegate_->NavigationStateChanged(this, changed_flags);
780}
781
[email protected]96d185d2009-04-24 03:28:54782void TabContents::DidBecomeSelected() {
783 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16784 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
785 if (rwhv) {
786 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43787#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16788 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43789#endif
790 }
[email protected]96d185d2009-04-24 03:28:54791
[email protected]8cb5d5b2010-02-09 11:36:16792 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54793}
794
795void TabContents::WasHidden() {
796 if (!capturing_contents()) {
797 // |render_view_host()| can be NULL if the user middle clicks a link to open
798 // a tab in then background, then closes the tab before selecting it. This
799 // is because closing the tab calls TabContents::Destroy(), which removes
800 // the |render_view_host()|; then when we actually destroy the window,
801 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16802 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
803 if (rwhv)
804 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54805 }
806
807 NotificationService::current()->Notify(
808 NotificationType::TAB_CONTENTS_HIDDEN,
809 Source<TabContents>(this),
810 NotificationService::NoDetails());
811}
812
[email protected]d5f942ba2008-09-26 19:30:34813void TabContents::Activate() {
814 if (delegate_)
815 delegate_->ActivateContents(this);
816}
817
[email protected]ea42e7782010-08-23 23:58:12818void TabContents::Deactivate() {
819 if (delegate_)
820 delegate_->DeactivateContents(this);
821}
822
[email protected]96d185d2009-04-24 03:28:54823void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16824 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
825 if (rwhv)
826 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54827}
828
829void TabContents::HideContents() {
830 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
831 // our superclass HideContents(), because some callers want to be very picky
832 // about the order in which these get called. In addition to making the code
833 // here practically impossible to understand, this also means we end up
834 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34835 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54836 WasHidden();
837}
838
[email protected]c0588052008-10-27 23:01:50839void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34840 WindowOpenDisposition disposition,
841 PageTransition::Type transition) {
842 if (delegate_)
[email protected]c0588052008-10-27 23:01:50843 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34844}
845
[email protected]1ccb3568d2010-02-19 10:51:16846bool TabContents::NavigateToPendingEntry(
847 NavigationController::ReloadType reload_type) {
[email protected]1be69aa2010-09-02 01:02:46848 const NavigationEntry& entry = *controller_.pending_entry();
[email protected]96d185d2009-04-24 03:28:54849
850 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
851 if (!dest_render_view_host)
852 return false; // Unable to create the desired render view host.
853
[email protected]770dd8b2010-05-24 18:11:39854 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
855 dest_render_view_host->EnablePreferredSizeChangedMode(
856 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
857 }
[email protected]9fb325e2010-05-06 18:23:24858
[email protected]0352e5472010-04-29 00:11:40859 // For security, we should never send non-DOM-UI URLs (other than about:blank)
860 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58861 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40862 bool is_allowed_in_dom_ui_renderer =
[email protected]583d45c12010-08-31 02:48:12863 DOMUIFactory::UseDOMUIForURL(profile(), entry.url()) ||
[email protected]0352e5472010-04-29 00:11:40864 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58865 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40866 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58867
[email protected]96d185d2009-04-24 03:28:54868 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12869 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32870 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00871 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
872 dest_render_view_host,
873 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32874 }
[email protected]96d185d2009-04-24 03:28:54875
876 // Used for page load time metrics.
877 current_load_start_ = base::TimeTicks::Now();
878
879 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34880 ViewMsg_Navigate_Params navigate_params;
[email protected]1be69aa2010-09-02 01:02:46881 MakeNavigateParams(controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34882 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54883
884 if (entry.page_id() == -1) {
885 // HACK!! This code suppresses javascript: URLs from being added to
886 // session history, which is what we want to do for javascript: URLs that
887 // do not generate content. What we really need is a message from the
888 // renderer telling us that a new page was not created. The same message
889 // could be used for mailto: URLs and the like.
890 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
891 return false;
892 }
893
894 // Clear any provisional password saves - this stops password infobars
895 // showing up on pages the user navigates to while the right page is
896 // loading.
897 GetPasswordManager()->ClearProvisionalSave();
898
[email protected]1ccb3568d2010-02-19 10:51:16899 if (reload_type != NavigationController::NO_RELOAD &&
900 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48901 FaviconService* favicon_service =
902 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
903 if (favicon_service)
904 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54905 }
906
[email protected]d5f942ba2008-09-26 19:30:34907 return true;
908}
909
[email protected]96d185d2009-04-24 03:28:54910void TabContents::Stop() {
911 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09912 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54913}
914
[email protected]96d185d2009-04-24 03:28:54915void TabContents::DisassociateFromPopupCount() {
916 render_view_host()->DisassociateFromPopupCount();
917}
918
919TabContents* TabContents::Clone() {
920 // We create a new SiteInstance so that the new tab won't share processes
921 // with the old one. This can be changed in the future if we need it to share
922 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32923 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54924 SiteInstance::CreateSiteInstance(profile()),
[email protected]12636df2009-09-28 22:32:21925 MSG_ROUTING_NONE, this);
[email protected]96d185d2009-04-24 03:28:54926 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08927 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08928 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54929 return tc;
930}
931
[email protected]4d677202009-07-19 07:37:12932void TabContents::ShowPageInfo(const GURL& url,
933 const NavigationEntry::SSLStatus& ssl,
934 bool show_history) {
935 if (!delegate_)
936 return;
937
[email protected]bb678332009-07-21 00:15:50938 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12939}
940
initial.commit09911bf2008-07-26 23:55:29941ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28942 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29943 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28944 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29945 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44946
947 if (child_windows_.size() == 1) {
948 window->ShowConstrainedWindow();
949 BlockTabContent(true);
950 }
951
initial.commit09911bf2008-07-26 23:55:29952 return window;
953}
954
[email protected]fa1cf0b82010-01-15 21:49:44955void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55956 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
957 if (rwhv)
958 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44959 render_view_host()->set_ignore_input_events(blocked);
960 if (delegate_)
961 delegate_->SetTabContentBlocked(this, blocked);
962}
963
initial.commit09911bf2008-07-26 23:55:29964void TabContents::AddNewContents(TabContents* new_contents,
965 WindowOpenDisposition disposition,
966 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29967 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29968 if (!delegate_)
969 return;
970
[email protected]35f7d212009-04-29 21:19:27971 if ((disposition == NEW_POPUP) && !user_gesture &&
972 !CommandLine::ForCurrentProcess()->HasSwitch(
973 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22974 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31975 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29976 delegate_->GetConstrainingContents(this)->AddPopup(
977 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31978 } else {
[email protected]304f8792009-08-19 21:28:09979#if defined(OS_CHROMEOS)
980 if (disposition == NEW_POPUP) {
981 // If the popup is bigger than a given factor of the screen, then
982 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11983 // Also check for width or height == 0, which would otherwise indicate
984 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09985 GdkScreen* screen = gdk_screen_get_default();
986 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
987 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11988 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
989 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09990 disposition = NEW_FOREGROUND_TAB;
991 }
992 }
993#endif
994
[email protected]0aa55312008-10-17 21:53:08995 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29996 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
997 user_gesture);
[email protected]7f37dd92009-09-15 16:35:49998 NotificationService::current()->Notify(
999 NotificationType::TAB_ADDED,
1000 Source<TabContentsDelegate>(delegate_),
1001 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291002 }
initial.commit09911bf2008-07-26 23:55:291003
[email protected]8cc8d492010-02-02 10:40:491004 // TODO(pkasting): Why is this necessary?
1005 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:291006}
1007
[email protected]bcd9dc42010-01-23 16:38:181008bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:201009 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:201010 bool is_js_code, const std::string& code_string,
1011 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511012 RenderViewHost* host = render_view_host();
1013 if (!host)
1014 return false;
1015
1016 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
1017 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
1018 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351019}
1020
[email protected]96d185d2009-04-24 03:28:541021void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491022 if (is_being_destroyed_)
1023 return;
[email protected]9fb83e82010-07-02 18:24:551024 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491025 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401026 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541027}
1028
[email protected]5c9e97a2009-09-09 23:48:301029gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541030 return view_->GetContentNativeView();
1031}
1032
1033gfx::NativeView TabContents::GetNativeView() const {
1034 return view_->GetNativeView();
1035}
1036
1037void TabContents::GetContainerBounds(gfx::Rect *out) const {
1038 view_->GetContainerBounds(out);
1039}
1040
1041void TabContents::Focus() {
1042 view_->Focus();
1043}
1044
[email protected]90daadb42009-06-08 21:27:281045void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541046 if (showing_interstitial_page()) {
1047 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1048 return;
1049 }
[email protected]96d185d2009-04-24 03:28:541050 render_view_host()->SetInitialFocus(reverse);
1051}
1052
1053bool TabContents::FocusLocationBarByDefault() {
1054 DOMUI* dom_ui = GetDOMUIForCurrentState();
1055 if (dom_ui)
1056 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431057 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251058 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431059 return true;
[email protected]96d185d2009-04-24 03:28:541060 return false;
1061}
1062
[email protected]a26dc362010-04-23 01:48:581063void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381064 if (delegate())
[email protected]a26dc362010-04-23 01:48:581065 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381066}
1067
[email protected]616ed5a2008-11-21 22:27:241068void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321069 if (delegate_ && !delegate_->infobars_enabled()) {
1070 delegate->InfoBarClosed();
1071 return;
1072 }
1073
[email protected]616ed5a2008-11-21 22:27:241074 // Look through the existing InfoBarDelegates we have for a match. If we've
1075 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051076 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451077 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1078 // Tell the new infobar to close so that it can clean itself up.
1079 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241080 return;
[email protected]6d27a7b2009-12-18 23:25:451081 }
[email protected]616ed5a2008-11-21 22:27:241082 }
1083
1084 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561085 NotificationService::current()->Notify(
1086 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1087 Source<TabContents>(this),
1088 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241089
1090 // Add ourselves as an observer for navigations the first time a delegate is
1091 // added. We use this notification to expire InfoBars that need to expire on
1092 // page transitions.
1093 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561094 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571095 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241096 }
1097}
1098
1099void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321100 if (delegate_ && !delegate_->infobars_enabled()) {
1101 return;
1102 }
1103
[email protected]616ed5a2008-11-21 22:27:241104 std::vector<InfoBarDelegate*>::iterator it =
1105 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1106 if (it != infobar_delegates_.end()) {
1107 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561108 NotificationService::current()->Notify(
1109 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1110 Source<TabContents>(this),
1111 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241112
[email protected]cdadf6f2010-08-20 16:36:081113 // Just to be safe, make sure the delegate was not removed by an observer.
1114 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1115 if (it != infobar_delegates_.end()) {
1116 infobar_delegates_.erase(it);
1117 // Remove ourselves as an observer if we are tracking no more InfoBars.
1118 if (infobar_delegates_.empty()) {
1119 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1120 Source<NavigationController>(&controller_));
1121 }
1122 } else {
1123 // If you hit this NOTREACHED, please comment in bug
1124 // http://crbug.com/50428 how you got there.
1125 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031126 }
[email protected]616ed5a2008-11-21 22:27:241127 }
1128}
[email protected]3edd9522009-03-04 22:19:411129
[email protected]f81821c2009-08-07 01:29:471130void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1131 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321132 if (delegate_ && !delegate_->infobars_enabled()) {
1133 new_delegate->InfoBarClosed();
1134 return;
1135 }
1136
[email protected]f81821c2009-08-07 01:29:471137 std::vector<InfoBarDelegate*>::iterator it =
1138 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1139 DCHECK(it != infobar_delegates_.end());
1140
1141 // Notify the container about the change of plans.
1142 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1143 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1144 old_delegate, new_delegate));
1145 NotificationService::current()->Notify(
1146 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1147 Source<TabContents>(this),
1148 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1149
[email protected]cdadf6f2010-08-20 16:36:081150 // Just to be safe, make sure the delegate was not removed by an observer.
1151 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1152 if (it != infobar_delegates_.end()) {
1153 // Remove the old one.
1154 infobar_delegates_.erase(it);
1155 } else {
1156 // If you hit this NOTREACHED, please comment in bug
1157 // http://crbug.com/50428 how you got there.
1158 NOTREACHED();
1159 }
[email protected]f81821c2009-08-07 01:29:471160
1161 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081162 DCHECK(find(infobar_delegates_.begin(),
1163 infobar_delegates_.end(), new_delegate) ==
1164 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471165 infobar_delegates_.push_back(new_delegate);
1166}
1167
[email protected]20ede072009-10-06 00:28:351168bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271169 if (showing_interstitial_page())
1170 return false;
1171
[email protected]c8f74942010-09-03 10:04:141172 // Do not show bookmarks bar if bookmarks aren't enabled.
1173 if (!browser_defaults::bookmarks_enabled)
1174 return false;
1175
[email protected]96d185d2009-04-24 03:28:541176 // See GetDOMUIForCurrentState() comment for more info. This case is very
1177 // similar, but for non-first loads, we want to use the committed entry. This
1178 // is so the bookmarks bar disappears at the same time the page does.
1179 if (controller_.GetLastCommittedEntry()) {
1180 // Not the first load, always use the committed DOM UI.
1181 if (render_manager_.dom_ui())
1182 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1183 return false; // Default.
1184 }
1185
1186 // When it's the first load, we know either the pending one or the committed
1187 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1188 // of them will be valid, so we can just check both.
1189 if (render_manager_.pending_dom_ui())
1190 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1191 if (render_manager_.dom_ui())
1192 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1193 return false; // Default.
1194}
1195
[email protected]3edd9522009-03-04 22:19:411196void TabContents::ToolbarSizeChanged(bool is_animating) {
1197 TabContentsDelegate* d = delegate();
1198 if (d)
1199 d->ToolbarSizeChanged(this, is_animating);
1200}
[email protected]616ed5a2008-11-21 22:27:241201
[email protected]fc6fb7fb2009-11-07 02:35:041202bool TabContents::CanDownload(int request_id) {
1203 TabContentsDelegate* d = delegate();
1204 if (d)
1205 return d->CanDownload(request_id);
1206 return true;
1207}
1208
[email protected]d5f942ba2008-09-26 19:30:341209void TabContents::OnStartDownload(DownloadItem* download) {
1210 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341211
1212 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311213 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341214
[email protected]5b928b62010-08-03 11:46:511215 if (tab_contents && tab_contents->delegate())
1216 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411217}
[email protected]3edd9522009-03-04 22:19:411218
[email protected]d5f942ba2008-09-26 19:30:341219void TabContents::WillClose(ConstrainedWindow* window) {
1220 ConstrainedWindowList::iterator it =
1221 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441222 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341223 if (it != child_windows_.end())
1224 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371225 if (child_windows_.size() > 0) {
1226 if (removed_topmost_window) {
1227 child_windows_[0]->ShowConstrainedWindow();
1228 }
[email protected]fa1cf0b82010-01-15 21:49:441229 BlockTabContent(true);
1230 } else {
1231 BlockTabContent(false);
1232 }
[email protected]66ba4932009-06-04 19:22:131233}
[email protected]d5f942ba2008-09-26 19:30:341234
[email protected]66ba4932009-06-04 19:22:131235void TabContents::WillCloseBlockedPopupContainer(
1236 BlockedPopupContainer* container) {
1237 DCHECK(blocked_popups_ == container);
1238 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491239 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341240}
1241
[email protected]d5f942ba2008-09-26 19:30:341242void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351243#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061244 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351245#endif
[email protected]d5f942ba2008-09-26 19:30:341246}
1247
[email protected]c1dc9f132009-11-20 23:13:211248void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121249 bool forward_direction,
1250 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211251 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011252 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211253 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531254 string16 last_search_prepopulate_text =
1255 FindBarState::GetLastPrepopulateText(profile());
1256
[email protected]87fae512009-12-11 02:20:211257 // Try the last thing we searched for on this tab, then the last thing
1258 // searched for on any tab.
1259 if (!previous_find_text_.empty())
1260 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531261 else if (!last_search_prepopulate_text.empty())
1262 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211263 else
[email protected]e491f1c2009-05-22 20:28:121264 return;
[email protected]e491f1c2009-05-22 20:28:121265 }
[email protected]6e95706d2009-04-23 22:55:011266
[email protected]101c90e2009-10-26 21:14:441267 // Keep track of the previous search.
1268 previous_find_text_ = find_text_;
1269
[email protected]6e95706d2009-04-23 22:55:011270 // This is a FindNext operation if we are searching for the same text again,
1271 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1272 // exception to this is if the Find was aborted (then we don't want FindNext
1273 // because the highlighting has been cleared and we need it to reappear). We
1274 // therefore treat FindNext after an aborted Find operation as a full fledged
1275 // Find.
[email protected]c1dc9f132009-11-20 23:13:211276 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121277 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011278 !find_op_aborted_;
1279 if (!find_next)
1280 current_find_request_id_ = find_request_id_counter_++;
1281
[email protected]c1dc9f132009-11-20 23:13:211282 if (!search_string.empty())
1283 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121284 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011285
1286 find_op_aborted_ = false;
1287
1288 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531289 FindBarState* find_bar_state = profile()->GetFindBarState();
1290 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011291 render_view_host()->StartFinding(current_find_request_id_,
1292 find_text_,
1293 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121294 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011295 find_next);
1296}
1297
[email protected]5bc8fe92010-03-11 18:19:001298void TabContents::StopFinding(
1299 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011300 if (selection_action == FindBarController::kClearSelection) {
1301 // kClearSelection means the find string has been cleared by the user, but
1302 // the UI has not been dismissed. In that case we want to clear the
1303 // previously remembered search (http://crbug.com/42639).
1304 previous_find_text_ = string16();
1305 } else {
[email protected]2d2dffc2009-06-09 21:41:001306 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011307 if (!find_text_.empty())
1308 previous_find_text_ = find_text_;
1309 }
[email protected]101c90e2009-10-26 21:14:441310 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011311 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121312 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001313 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011314}
1315
[email protected]420ae012009-04-24 05:16:321316void TabContents::OnSavePage() {
1317 // If we can not save the page, try to download it.
1318 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1319 DownloadManager* dlm = profile()->GetDownloadManager();
1320 const GURL& current_page_url = GetURL();
1321 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221322 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321323 return;
1324 }
1325
1326 Stop();
1327
1328 // Create the save package and possibly prompt the user for the name to save
1329 // the page as. The user prompt is an asynchronous operation that runs on
1330 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221331 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321332 save_package_->GetSaveInfo();
1333}
1334
1335// Used in automated testing to bypass prompting the user for file names.
1336// Instead, the names and paths are hard coded rather than running them through
1337// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111338bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321339 SavePackage::SavePackageType save_type) {
1340 // Stop the page from navigating.
1341 Stop();
1342
[email protected]828cabe2009-09-26 22:47:111343 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591344 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321345}
1346
[email protected]89d6e6e2009-12-03 23:06:511347void TabContents::EmailPageLocation() {
1348 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1349 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1350 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1351 title + "&body=%0A%0A" + page_url;
1352 platform_util::OpenExternal(GURL(mailto));
1353}
1354
[email protected]420ae012009-04-24 05:16:321355void TabContents::PrintPreview() {
1356 // We don't show the print preview yet, only the print dialog.
1357 PrintNow();
1358}
1359
1360bool TabContents::PrintNow() {
1361 // We can't print interstitial page for now.
1362 if (showing_interstitial_page())
1363 return false;
1364
1365 return render_view_host()->PrintPages();
1366}
1367
[email protected]82270452009-06-19 15:58:011368void TabContents::PrintingDone(int document_cookie, bool success) {
1369 render_view_host()->PrintingDone(document_cookie, success);
1370}
1371
[email protected]420ae012009-04-24 05:16:321372bool TabContents::IsActiveEntry(int32 page_id) {
1373 NavigationEntry* active_entry = controller_.GetActiveEntry();
1374 return (active_entry != NULL &&
1375 active_entry->site_instance() == GetSiteInstance() &&
1376 active_entry->page_id() == page_id);
1377}
1378
[email protected]b2fe07d12010-02-09 14:38:081379void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161380 set_encoding(encoding);
1381 render_view_host()->SetPageEncoding(encoding);
1382}
1383
[email protected]b2fe07d12010-02-09 14:38:081384void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161385 reset_encoding();
1386 render_view_host()->ResetPageEncodingToDefault();
1387}
1388
1389void TabContents::WindowMoveOrResizeStarted() {
1390 render_view_host()->WindowMoveOrResizeStarted();
1391}
1392
[email protected]3f8eb7f2009-10-02 23:58:051393void TabContents::LogNewTabTime(const std::string& event_name) {
1394 // Not all new tab pages get timed. In those cases, we don't have a
1395 // new_tab_start_time_.
1396 if (new_tab_start_time_.is_null())
1397 return;
1398
1399 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441400 MetricEventDurationDetails details(event_name,
1401 static_cast<int>(duration.InMilliseconds()));
1402
[email protected]7ab1e7d62009-10-14 23:32:011403 if (event_name == "Tab.NewTabScriptStart") {
1404 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1405 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1406 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1407 } else if (event_name == "Tab.NewTabOnload") {
1408 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051409 // The new tab page has finished loading; reset it.
1410 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441411 } else {
1412 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051413 }
[email protected]84abba62009-10-07 17:01:441414 NotificationService::current()->Notify(
1415 NotificationType::METRIC_EVENT_DURATION,
1416 Source<TabContents>(this),
1417 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051418}
1419
[email protected]7ab1e7d62009-10-14 23:32:011420void TabContents::OnCloseStarted() {
1421 if (tab_close_start_time_.is_null())
1422 tab_close_start_time_ = base::TimeTicks::Now();
1423}
1424
[email protected]46624bf2010-06-09 16:04:191425bool TabContents::ShouldAcceptDragAndDrop() const {
1426#if defined(OS_CHROMEOS)
1427 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1428 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561429 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191430#else
1431 return true;
1432#endif
1433}
1434
[email protected]c37e3b62010-01-22 00:15:171435TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171436 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161437
1438 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081439 if (extension_app_)
1440 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161441 else if (entry)
1442 tab_nav.SetFromNavigationEntry(*entry);
1443
[email protected]c37e3b62010-01-22 00:15:171444 std::vector<TabNavigation> navigations;
1445 navigations.push_back(tab_nav);
1446
1447 TabContents* new_contents =
1448 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL);
[email protected]98aa0b52010-05-06 17:03:081449 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171450 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171451
[email protected]98aa0b52010-05-06 17:03:081452 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161453 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1454
[email protected]c37e3b62010-01-22 00:15:171455 return new_contents;
1456}
1457
[email protected]ec0b6c42010-08-26 03:16:581458void TabContents::UpdateHistoryForNavigation(
1459 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1460 if (profile()->IsOffTheRecord())
1461 return;
1462
1463 // Add to history service.
1464 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1465 if (hs)
1466 hs->AddPage(*add_page_args);
1467}
1468
1469void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1470 if (profile()->IsOffTheRecord())
1471 return;
1472
1473 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1474 if (hs)
1475 hs->SetPageTitle(entry.virtual_url(), entry.title());
1476}
1477
[email protected]96d185d2009-04-24 03:28:541478// Notifies the RenderWidgetHost instance about the fact that the page is
1479// loading, or done loading and calls the base implementation.
1480void TabContents::SetIsLoading(bool is_loading,
1481 LoadNotificationDetails* details) {
1482 if (is_loading == is_loading_)
1483 return;
1484
1485 if (!is_loading) {
1486 load_state_ = net::LOAD_STATE_IDLE;
1487 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561488 upload_size_ = 0;
1489 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541490 }
1491
1492 render_manager_.SetIsLoading(is_loading);
1493
1494 is_loading_ = is_loading;
1495 waiting_for_response_ = is_loading;
1496
1497 if (delegate_)
1498 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351499 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541500
1501 NotificationType type = is_loading ? NotificationType::LOAD_START :
1502 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111503 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541504 if (details)
1505 det = Details<LoadNotificationDetails>(details);
1506 NotificationService::current()->Notify(type,
1507 Source<NavigationController>(&controller_),
1508 det);
1509}
1510
[email protected]b6c874582009-05-08 19:38:311511void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291512 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061513 // A page can't spawn popups (or do anything else, either) until its load
1514 // commits, so when we reach here, the popup was spawned by the
1515 // NavigationController's last committed entry, not the active entry. For
1516 // example, if a page opens a popup in an onunload() handler, then the active
1517 // entry is the page to be loaded as we navigate away from the unloading
1518 // page. For this reason, we can't use GetURL() to get the opener URL,
1519 // because it returns the active entry.
1520 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1521 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1522
1523 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491524 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091525 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491526 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1527 } else {
1528 if (!blocked_popups_)
1529 blocked_popups_ = new BlockedPopupContainer(this);
1530 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]55126132010-08-19 14:53:281531 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1532 std::string());
[email protected]be2ee282010-08-31 15:24:171533 if (!is_being_destroyed())
1534 PopupBlockedAnimation::Show(this);
[email protected]8cc8d492010-02-02 10:40:491535 }
[email protected]b9681312008-11-07 00:08:261536}
[email protected]616ed5a2008-11-21 22:27:241537
1538namespace {
1539bool TransitionIsReload(PageTransition::Type transition) {
1540 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1541}
1542}
1543
1544void TabContents::ExpireInfoBars(
1545 const NavigationController::LoadCommittedDetails& details) {
1546 // Only hide InfoBars when the user has done something that makes the main
1547 // frame load. We don't want various automatic or subframe navigations making
1548 // it disappear.
1549 if (!details.is_user_initiated_main_frame_load())
1550 return;
1551
[email protected]f86a07022008-11-25 01:06:051552 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241553 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081554 if (!delegate) {
1555 // If you hit this NOTREACHED, please comment in bug
1556 // http://crbug.com/50428 how you got there.
1557 NOTREACHED();
1558 continue;
1559 }
1560
[email protected]f86a07022008-11-25 01:06:051561 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241562 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241563 }
1564}
[email protected]fdd61c62009-04-22 19:22:571565
[email protected]96d185d2009-04-24 03:28:541566DOMUI* TabContents::GetDOMUIForCurrentState() {
1567 // When there is a pending navigation entry, we want to use the pending DOMUI
1568 // that goes along with it to control the basic flags. For example, we want to
1569 // show the pending URL in the URL bar, so we want the display_url flag to
1570 // be from the pending entry.
1571 //
1572 // The confusion comes because there are multiple possibilities for the
1573 // initial load in a tab as a side effect of the way the RenderViewHostManager
1574 // works.
1575 //
1576 // - For the very first tab the load looks "normal". The new tab DOM UI is
1577 // the pending one, and we want it to apply here.
1578 //
1579 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1580 // get switched to the one previously associated with the new tab pages.
1581 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1582 // have a committed DOM UI in this case.
1583 //
1584 // This condition handles all of these cases:
1585 //
1586 // - First load in first tab: no committed nav entry + pending nav entry +
1587 // pending dom ui:
1588 // -> Use pending DOM UI if any.
1589 //
1590 // - First load in second tab: no committed nav entry + pending nav entry +
1591 // no pending DOM UI:
1592 // -> Use the committed DOM UI if any.
1593 //
1594 // - Second navigation in any tab: committed nav entry + pending nav entry:
1595 // -> Use pending DOM UI if any.
1596 //
1597 // - Normal state with no load: committed nav entry + no pending nav entry:
1598 // -> Use committed DOM UI.
1599 if (controller_.pending_entry() &&
1600 (controller_.GetLastCommittedEntry() ||
1601 render_manager_.pending_dom_ui()))
1602 return render_manager_.pending_dom_ui();
1603 return render_manager_.dom_ui();
1604}
[email protected]420ae012009-04-24 05:16:321605
1606void TabContents::DidNavigateMainFramePostCommit(
1607 const NavigationController::LoadCommittedDetails& details,
1608 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441609 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1610 // If this is a window.open navigation, use the same DOMUI as the renderer
1611 // that opened the window, as long as both renderers have the same
1612 // privileges.
[email protected]583d45c12010-08-31 02:48:121613 if (opener_dom_ui_type_ ==
1614 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441615 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1616 // dom_ui might be NULL if the URL refers to a non-existent extension.
1617 if (dom_ui) {
1618 render_manager_.SetDOMUIPostCommit(dom_ui);
1619 dom_ui->RenderViewCreated(render_view_host());
1620 }
1621 }
1622 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1623 }
1624
[email protected]420ae012009-04-24 05:16:321625 if (details.is_user_initiated_main_frame_load()) {
1626 // Clear the status bubble. This is a workaround for a bug where WebKit
1627 // doesn't let us know that the cursor left an element during a
1628 // transition (this is also why the mouse cursor remains as a hand after
1629 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1630 // clear the bubble when a user navigates to a named anchor in the same
1631 // page.
1632 UpdateTargetURL(details.entry->page_id(), GURL());
1633
1634 // UpdateHelpersForDidNavigate will handle the case where the password_form
1635 // origin is valid.
1636 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1637 // cleaned up and covered by tests.
1638 if (!params.password_form.origin.is_valid())
1639 GetPasswordManager()->DidNavigate();
1640 }
1641
1642 // The keyword generator uses the navigation entries, so must be called after
1643 // the commit.
1644 GenerateKeywordIfNecessary(params);
1645
1646 // Allow the new page to set the title again.
1647 received_page_title_ = false;
1648
1649 // Get the favicon, either from history or request it from the net.
1650 fav_icon_helper_.FetchFavIcon(details.entry->url());
1651
[email protected]0de80162010-02-03 04:52:351652 // Clear all page actions, blocked content notifications and browser actions
1653 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141654 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081655 ExtensionsService* service = profile()->GetExtensionsService();
1656 if (service) {
1657 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571658 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081659 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521660 if (browser_action) {
1661 browser_action->ClearAllValuesForTab(controller().session_id().id());
1662 NotificationService::current()->Notify(
1663 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571664 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521665 NotificationService::NoDetails());
1666 }
[email protected]92c6f9b92009-10-24 04:35:081667
[email protected]5d246db22009-10-27 06:17:571668 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521669 service->extensions()->at(i)->page_action();
1670 if (page_action) {
1671 page_action->ClearAllValuesForTab(controller().session_id().id());
1672 PageActionStateChanged();
1673 }
[email protected]92c6f9b92009-10-24 04:35:081674 }
[email protected]aece2c7f2009-08-27 20:43:171675 }
[email protected]0de80162010-02-03 04:52:351676
1677 // Close blocked popups.
1678 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341679 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351680 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461681 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351682 }
1683
1684 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411685 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551686 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471687
1688 // Once the main frame is navigated, we're no longer considered to have
1689 // displayed insecure content.
1690 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171691 }
[email protected]ce5c4502009-05-06 16:46:111692
[email protected]8cc8d492010-02-02 10:40:491693 // Close constrained windows if necessary.
1694 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1695 details.previous_url, details.entry->url()))
1696 CloseConstrainedWindows();
1697
[email protected]420ae012009-04-24 05:16:321698 // Update the starred state.
1699 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531700
1701 // Clear the cache of forms in AutoFill.
1702 if (autofill_manager_.get())
1703 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321704}
1705
1706void TabContents::DidNavigateAnyFramePostCommit(
1707 RenderViewHost* render_view_host,
1708 const NavigationController::LoadCommittedDetails& details,
1709 const ViewHostMsg_FrameNavigate_Params& params) {
1710 // If we navigate, start showing messages again. This does nothing to prevent
1711 // a malicious script from spamming messages, since the script could just
1712 // reload the page to stop blocking.
1713 suppress_javascript_messages_ = false;
1714
[email protected]420ae012009-04-24 05:16:321715 // Notify the password manager of the navigation or form submit.
1716 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1717 // cleaned up and covered by tests.
1718 if (params.password_form.origin.is_valid())
1719 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551720
1721 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581722 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321723}
1724
[email protected]8cc8d492010-02-02 10:40:491725void TabContents::CloseConstrainedWindows() {
1726 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321727 // We use indices instead of iterators in case CloseWindow does something
1728 // that may invalidate an iterator.
1729 int size = static_cast<int>(child_windows_.size());
1730 for (int i = size - 1; i >= 0; --i) {
1731 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441732 if (window) {
[email protected]420ae012009-04-24 05:16:321733 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441734 BlockTabContent(false);
1735 }
[email protected]420ae012009-04-24 05:16:321736 }
1737}
1738
1739void TabContents::UpdateStarredStateForCurrentURL() {
1740 BookmarkModel* model = profile()->GetBookmarkModel();
1741 const bool old_state = is_starred_;
1742 is_starred_ = (model && model->IsBookmarked(GetURL()));
1743
1744 if (is_starred_ != old_state && delegate())
1745 delegate()->URLStarredChanged(this, is_starred_);
1746}
1747
1748void TabContents::UpdateAlternateErrorPageURL() {
1749 GURL url = GetAlternateErrorPageURL();
1750 render_view_host()->SetAlternateErrorPageURL(url);
1751}
1752
1753void TabContents::UpdateWebPreferences() {
1754 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1755}
1756
1757void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1758 RenderViewHost* rvh) {
1759 // If we are creating a RVH for a restored controller, then we might
1760 // have more page IDs than the SiteInstance's current max page ID. We must
1761 // make sure that the max page ID is larger than any restored page ID.
1762 // Note that it is ok for conflicting page IDs to exist in another tab
1763 // (i.e., NavigationController), but if any page ID is larger than the max,
1764 // the back/forward list will get confused.
1765 int max_restored_page_id = controller_.max_restored_page_id();
1766 if (max_restored_page_id > 0) {
1767 int curr_max_page_id = site_instance->max_page_id();
1768 if (max_restored_page_id > curr_max_page_id) {
1769 // Need to update the site instance immediately.
1770 site_instance->UpdateMaxPageID(max_restored_page_id);
1771
1772 // Also tell the renderer to update its internal representation. We
1773 // need to reserve enough IDs to make all restored page IDs less than
1774 // the max.
1775 if (curr_max_page_id < 0)
1776 curr_max_page_id = 0;
1777 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1778 }
1779 }
1780}
1781
[email protected]ec0b6c42010-08-26 03:16:581782scoped_refptr<history::HistoryAddPageArgs>
1783TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541784 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471785 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321786 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581787 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1788 new history::HistoryAddPageArgs(
1789 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1790 params.redirects, params.transition, history::SOURCE_BROWSED,
1791 details.did_replace_entry));
1792 if (PageTransition::IsMainFrame(params.transition) &&
1793 virtual_url != params.url) {
1794 // Hack on the "virtual" URL so that it will appear in history. For some
1795 // types of URLs, we will display a magic URL that is different from where
1796 // the page is actually navigated. We want the user to see in history what
1797 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1798 // only applies to the main frame, as the virtual URL doesn't apply to
1799 // sub-frames.
1800 add_page_args->url = virtual_url;
1801 if (!add_page_args->redirects.empty())
1802 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321803 }
[email protected]ec0b6c42010-08-26 03:16:581804 return add_page_args;
[email protected]420ae012009-04-24 05:16:321805}
1806
1807bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1808 const std::wstring& title) {
1809 // For file URLs without a title, use the pathname instead. In the case of a
1810 // synthesized title, we don't want the update to count toward the "one set
1811 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251812 string16 final_title;
[email protected]420ae012009-04-24 05:16:321813 bool explicit_set;
1814 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251815 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321816 explicit_set = false; // Don't count synthetic titles toward the set limit.
1817 } else {
[email protected]e53668962010-06-23 15:35:251818 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321819 explicit_set = true;
1820 }
1821
[email protected]e53668962010-06-23 15:35:251822 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321823 return false; // Nothing changed, don't bother.
1824
[email protected]e53668962010-06-23 15:35:251825 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321826
[email protected]ec0b6c42010-08-26 03:16:581827 if (!received_page_title_) {
1828 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321829 received_page_title_ = explicit_set;
1830 }
1831
1832 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251833 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321834
[email protected]cbc0e1b2010-04-12 18:33:041835 NotificationService::current()->Notify(
1836 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1837 Source<TabContents>(this),
1838 NotificationService::NoDetails());
1839
[email protected]420ae012009-04-24 05:16:321840 return true;
1841}
1842
1843void TabContents::NotifySwapped() {
1844 // After sending out a swap notification, we need to send a disconnect
1845 // notification so that clients that pick up a pointer to |this| can NULL the
1846 // pointer. See Bug 1230284.
1847 notify_disconnection_ = true;
1848 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341849 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221850 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321851 NotificationService::NoDetails());
1852}
1853
1854void TabContents::NotifyConnected() {
1855 notify_disconnection_ = true;
1856 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341857 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221858 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321859 NotificationService::NoDetails());
1860}
1861
1862void TabContents::NotifyDisconnected() {
1863 if (!notify_disconnection_)
1864 return;
1865
1866 notify_disconnection_ = false;
1867 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341868 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221869 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321870 NotificationService::NoDetails());
1871}
1872
1873void TabContents::GenerateKeywordIfNecessary(
1874 const ViewHostMsg_FrameNavigate_Params& params) {
1875 if (!params.searchable_form_url.is_valid())
1876 return;
1877
1878 if (profile()->IsOffTheRecord())
1879 return;
1880
1881 int last_index = controller_.last_committed_entry_index();
1882 // When there was no previous page, the last index will be 0. This is
1883 // normally due to a form submit that opened in a new tab.
1884 // TODO(brettw) bug 916126: we should support keywords when form submits
1885 // happen in new tabs.
1886 if (last_index <= 0)
1887 return;
1888 const NavigationEntry* previous_entry =
1889 controller_.GetEntryAtIndex(last_index - 1);
1890 if (IsFormSubmit(previous_entry)) {
1891 // Only generate a keyword if the previous page wasn't itself a form
1892 // submit.
1893 return;
1894 }
1895
1896 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1897 previous_entry->user_typed_url() : previous_entry->url();
1898 std::wstring keyword =
1899 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1900 if (keyword.empty())
1901 return;
1902
1903 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1904 if (!url_model)
1905 return;
1906
1907 if (!url_model->loaded()) {
1908 url_model->Load();
1909 return;
1910 }
1911
1912 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191913 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321914 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1915 return;
1916
1917 if (current_url) {
1918 if (current_url->originating_url().is_valid()) {
1919 // The existing keyword was generated from an OpenSearch description
1920 // document, don't regenerate.
1921 return;
1922 }
1923 url_model->Remove(current_url);
1924 }
1925 TemplateURL* new_url = new TemplateURL();
1926 new_url->set_keyword(keyword);
1927 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191928 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321929 new_url->add_input_encoding(params.searchable_form_encoding);
1930 DCHECK(controller_.GetLastCommittedEntry());
1931 const GURL& favicon_url =
1932 controller_.GetLastCommittedEntry()->favicon().url();
1933 if (favicon_url.is_valid()) {
1934 new_url->SetFavIconURL(favicon_url);
1935 } else {
1936 // The favicon url isn't valid. This means there really isn't a favicon,
1937 // or the favicon url wasn't obtained before the load started. This assumes
1938 // the later.
1939 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1940 // its url.
1941 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1942 }
1943 new_url->set_safe_for_autoreplace(true);
1944 url_model->Add(new_url);
1945}
1946
[email protected]bf5c2ff392009-07-08 16:24:331947void TabContents::OnUserGesture() {
1948 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011949 DownloadRequestLimiter* limiter =
1950 g_browser_process->download_request_limiter();
1951 if (limiter)
1952 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261953 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331954}
1955
1956void TabContents::OnFindReply(int request_id,
1957 int number_of_matches,
1958 const gfx::Rect& selection_rect,
1959 int active_match_ordinal,
1960 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421961 // Ignore responses for requests that have been aborted.
1962 if (find_op_aborted_)
1963 return;
1964
[email protected]bf5c2ff392009-07-08 16:24:331965 // Ignore responses for requests other than the one we have most recently
1966 // issued. That way we won't act on stale results when the user has
1967 // already typed in another query.
1968 if (request_id != current_find_request_id_)
1969 return;
1970
1971 if (number_of_matches == -1)
1972 number_of_matches = last_search_result_.number_of_matches();
1973 if (active_match_ordinal == -1)
1974 active_match_ordinal = last_search_result_.active_match_ordinal();
1975
1976 gfx::Rect selection = selection_rect;
1977 if (selection.IsEmpty())
1978 selection = last_search_result_.selection_rect();
1979
1980 // Notify the UI, automation and any other observers that a find result was
1981 // found.
1982 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1983 selection, active_match_ordinal,
1984 final_update);
1985 NotificationService::current()->Notify(
1986 NotificationType::FIND_RESULT_AVAILABLE,
1987 Source<TabContents>(this),
1988 Details<FindNotificationDetails>(&last_search_result_));
1989}
1990
1991void TabContents::GoToEntryAtOffset(int offset) {
[email protected]1be69aa2010-09-02 01:02:461992 if (!delegate_ || delegate_->OnGoToEntryOffset(offset))
1993 controller_.GoToOffset(offset);
[email protected]bf5c2ff392009-07-08 16:24:331994}
1995
[email protected]bf5c2ff392009-07-08 16:24:331996void TabContents::OnMissingPluginStatus(int status) {
1997#if defined(OS_WIN)
1998// TODO(PORT): pull in when plug-ins work
1999 GetPluginInstaller()->OnMissingPluginStatus(status);
2000#endif
2001}
2002
2003void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332004 DCHECK(!plugin_path.value().empty());
2005
2006 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:352007#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:332008 scoped_ptr<FileVersionInfo> version_info(
2009 FileVersionInfo::CreateFileVersionInfo(plugin_path));
2010 if (version_info.get()) {
2011 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:372012 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:332013 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:372014#if defined(OS_MACOSX)
2015 // Many plugins on the Mac have .plugin in the actual name, which looks
2016 // terrible, so look for that and strip it off if present.
2017 const std::wstring plugin_extension(L".plugin");
2018 if (EndsWith(plugin_name, plugin_extension, true))
2019 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2020#endif // OS_MACOSX
2021 }
[email protected]bf5c2ff392009-07-08 16:24:332022 }
[email protected]4a560ed2009-07-13 23:35:262023#else
2024 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2025#endif
[email protected]2ae8a922010-06-28 20:27:532026 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2027 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332028 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582029 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2030 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532031 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332032}
2033
2034void TabContents::OnCrashedWorker() {
2035 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582036 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422037 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332038}
2039
2040void TabContents::OnDidGetApplicationInfo(
2041 int32 page_id,
2042 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512043 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332044
[email protected]ed5431872009-11-17 08:39:512045 if (delegate())
2046 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332047}
2048
[email protected]851b1eb2010-08-09 13:32:292049void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2050 const GURL& update_url) {
2051 new DisabledPluginInfoBar(this, name, update_url);
2052}
2053
[email protected]a2cf65eb2010-01-18 08:20:382054void TabContents::OnPageContents(const GURL& url,
2055 int renderer_process_id,
2056 int32 page_id,
[email protected]e5106202010-06-11 21:12:362057 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102058 const std::string& language,
2059 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382060 // Don't index any https pages. People generally don't want their bank
2061 // accounts, etc. indexed on their computer, especially since some of these
2062 // things are not marked cachable.
2063 // TODO(brettw) we may want to consider more elaborate heuristics such as
2064 // the cachability of the page. We may also want to consider subframes (this
2065 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272066 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2067 // content indexing for chromeos in some future releases.
2068#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382069 if (!url.SchemeIsSecure()) {
2070 Profile* p = profile();
2071 if (p && !p->IsOffTheRecord()) {
2072 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2073 if (hs)
2074 hs->SetPageContents(url, contents);
2075 }
2076 }
[email protected]ccd40a52010-05-11 16:15:272077#endif
[email protected]a8a81292010-01-21 00:32:452078
[email protected]1c57b7b2010-07-12 17:38:102079 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452080
2081 std::string lang = language;
2082 NotificationService::current()->Notify(
2083 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152084 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452085 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382086}
2087
[email protected]7e0831b2010-02-01 08:45:152088void TabContents::OnPageTranslated(int32 page_id,
2089 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162090 const std::string& translated_lang,
2091 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552092 language_state_.set_current_language(translated_lang);
2093 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162094 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152095 NotificationService::current()->Notify(
2096 NotificationType::PAGE_TRANSLATED,
2097 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162098 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152099}
2100
[email protected]bf5c2ff392009-07-08 16:24:332101void TabContents::DidStartProvisionalLoadForFrame(
2102 RenderViewHost* render_view_host,
2103 bool is_main_frame,
2104 const GURL& url) {
2105 ProvisionalLoadDetails details(is_main_frame,
2106 controller_.IsURLInPageNavigation(url),
2107 url, std::string(), false);
2108 NotificationService::current()->Notify(
2109 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2110 Source<NavigationController>(&controller_),
2111 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142112 if (is_main_frame) {
[email protected]da4f8a12010-08-19 08:33:412113 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142114 content_settings_delegate_->ClearGeolocationContentSettings();
2115 }
[email protected]bf5c2ff392009-07-08 16:24:332116}
2117
2118void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202119 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332120 NotificationService::current()->Notify(
2121 NotificationType::RESOURCE_RESPONSE_STARTED,
2122 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202123 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332124}
2125
[email protected]3dbb80b2010-02-09 22:41:202126void TabContents::DidRedirectResource(
2127 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332128 NotificationService::current()->Notify(
2129 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2130 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202131 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332132}
2133
2134void TabContents::DidLoadResourceFromMemoryCache(
2135 const GURL& url,
2136 const std::string& frame_origin,
2137 const std::string& main_frame_origin,
2138 const std::string& security_info) {
2139 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442140 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332141 SSLManager::DeserializeSecurityInfo(security_info,
2142 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042143 &security_bits,
2144 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332145 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162146 GetRenderProcessHost()->id(), cert_id,
2147 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332148
2149 NotificationService::current()->Notify(
2150 NotificationType::LOAD_FROM_MEMORY_CACHE,
2151 Source<NavigationController>(&controller_),
2152 Details<LoadFromMemoryCacheDetails>(&details));
2153}
2154
[email protected]e3d60e5d2009-09-25 21:08:292155void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472156 displayed_insecure_content_ = true;
2157 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292158}
2159
2160void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592161 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292162}
2163
[email protected]bf5c2ff392009-07-08 16:24:332164void TabContents::DidFailProvisionalLoadWithError(
2165 RenderViewHost* render_view_host,
2166 bool is_main_frame,
2167 int error_code,
2168 const GURL& url,
2169 bool showing_repost_interstitial) {
2170 if (net::ERR_ABORTED == error_code) {
2171 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2172 // This means that the interstitial won't be torn down properly, which is
2173 // bad. But if we have an interstitial, go back to another tab type, and
2174 // then load the same interstitial again, we could end up getting the first
2175 // interstitial's "failed" message (as a result of the cancel) when we're on
2176 // the second one.
2177 //
2178 // We can't tell this apart, so we think we're tearing down the current page
2179 // which will cause a crash later one. There is also some code in
2180 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2181 // out because of this problem.
2182 //
2183 // http://code.google.com/p/chromium/issues/detail?id=2855
2184 // Because this will not tear down the interstitial properly, if "back" is
2185 // back to another tab type, the interstitial will still be somewhat alive
2186 // in the previous tab type. If you navigate somewhere that activates the
2187 // tab with the interstitial again, you'll see a flash before the new load
2188 // commits of the interstitial page.
2189 if (showing_interstitial_page()) {
2190 LOG(WARNING) << "Discarding message during interstitial.";
2191 return;
2192 }
2193
2194 // This will discard our pending entry if we cancelled the load (e.g., if we
2195 // decided to download the file instead of load it). Only discard the
2196 // pending entry if the URLs match, otherwise the user initiated a navigate
2197 // before the page loaded so that the discard would discard the wrong entry.
2198 NavigationEntry* pending_entry = controller_.pending_entry();
2199 if (pending_entry && pending_entry->url() == url) {
2200 controller_.DiscardNonCommittedEntries();
2201 // Update the URL display.
2202 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2203 }
2204
2205 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2206 }
2207
2208 // Send out a notification that we failed a provisional load with an error.
2209 ProvisionalLoadDetails details(is_main_frame,
2210 controller_.IsURLInPageNavigation(url),
2211 url, std::string(), false);
2212 details.set_error_code(error_code);
2213
2214 NotificationService::current()->Notify(
2215 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2216 Source<NavigationController>(&controller_),
2217 Details<ProvisionalLoadDetails>(&details));
2218}
2219
2220void TabContents::DocumentLoadedInFrame() {
2221 controller_.DocumentLoadedInFrame();
2222}
2223
[email protected]dcd5b332010-08-11 08:55:182224void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562225 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242226 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562227}
2228
[email protected]8d3347f2009-07-09 22:00:212229RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322230 return view_.get();
2231}
2232
[email protected]8d3347f2009-07-09 22:00:212233RenderViewHostDelegate::RendererManagement*
2234TabContents::GetRendererManagementDelegate() {
2235 return &render_manager_;
2236}
2237
[email protected]bf5c2ff392009-07-08 16:24:332238RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212239 TabContents::GetBrowserIntegrationDelegate() {
2240 return this;
[email protected]bf5c2ff392009-07-08 16:24:332241}
2242
[email protected]8d3347f2009-07-09 22:00:212243RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2244 return this;
[email protected]bf5c2ff392009-07-08 16:24:332245}
2246
[email protected]46ba9082010-06-22 10:00:582247RenderViewHostDelegate::ContentSettings*
2248TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552249 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582250}
2251
[email protected]8d3347f2009-07-09 22:00:212252RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322253 return save_package_.get(); // May be NULL, but we can return NULL.
2254}
2255
[email protected]8d3347f2009-07-09 22:00:212256RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092257 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212258}
2259
2260RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2261 return &fav_icon_helper_;
2262}
2263
[email protected]e8dbd674b2010-03-11 18:34:402264RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452265 if (autocomplete_history_manager_.get() == NULL)
2266 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2267 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332268}
2269
[email protected]21674df2009-10-28 19:51:212270RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342271 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212272}
2273
[email protected]aad51d1c2010-08-05 08:38:092274RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2275 if (blocked_plugin_manager_.get() == NULL)
2276 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2277 return blocked_plugin_manager_.get();
2278}
2279
[email protected]1f18184a2010-07-21 19:34:492280RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2281 return GetSSLHelper();
2282}
2283
[email protected]b5977a0c2010-08-24 19:46:262284RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2285 if (file_select_helper_.get() == NULL)
2286 file_select_helper_.reset(new TabContentsFileSelectHelper(this));
2287 return file_select_helper_.get();
2288}
2289
[email protected]fd571bb2010-03-19 01:23:542290AutomationResourceRoutingDelegate*
2291TabContents::GetAutomationResourceRoutingDelegate() {
2292 return delegate();
2293}
2294
[email protected]ced90ae12010-02-20 02:06:162295RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2296 return bookmark_drag_;
2297}
2298
2299void TabContents::SetBookmarkDragDelegate(
2300 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2301 bookmark_drag_ = bookmark_drag;
2302}
2303
[email protected]9fb83e82010-07-02 18:24:552304TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2305 return content_settings_delegate_.get();
2306}
2307
[email protected]93623c5d2009-12-10 21:40:322308RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462309 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512310}
2311
[email protected]57c6a652009-05-04 07:58:342312TabContents* TabContents::GetAsTabContents() {
2313 return this;
2314}
2315
[email protected]7b291f92009-08-14 05:43:532316ViewType::Type TabContents::GetRenderViewType() const {
2317 return ViewType::TAB_CONTENTS;
2318}
2319
2320int TabContents::GetBrowserWindowID() const {
2321 return controller().window_id().id();
2322}
2323
[email protected]420ae012009-04-24 05:16:322324void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062325 NotificationService::current()->Notify(
2326 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2327 Source<TabContents>(this),
2328 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322329 NavigationEntry* entry = controller_.GetActiveEntry();
2330 if (!entry)
2331 return;
2332
2333 // When we're creating views, we're still doing initial setup, so we always
2334 // use the pending DOM UI rather than any possibly existing committed one.
2335 if (render_manager_.pending_dom_ui()) {
2336 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2337 }
2338
2339 if (entry->IsViewSourceMode()) {
2340 // Put the renderer in view source mode.
2341 render_view_host->Send(
2342 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2343 }
[email protected]0666aef2009-05-13 19:48:082344
2345 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322346}
2347
2348void TabContents::RenderViewReady(RenderViewHost* rvh) {
2349 if (rvh != render_view_host()) {
2350 // Don't notify the world, since this came from a renderer in the
2351 // background.
2352 return;
2353 }
2354
2355 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302356 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322357 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302358
2359 // Restore the focus to the tab (otherwise the focus will be on the top
2360 // window).
2361 if (was_crashed && !FocusLocationBarByDefault())
2362 Focus();
[email protected]420ae012009-04-24 05:16:322363}
2364
2365void TabContents::RenderViewGone(RenderViewHost* rvh) {
2366 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092367 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322368 return;
2369 if (rvh != render_view_host()) {
2370 // The pending page's RenderViewHost is gone.
2371 return;
2372 }
2373
2374 SetIsLoading(false, NULL);
2375 NotifyDisconnected();
2376 SetIsCrashed(true);
2377
[email protected]ff9efc62010-02-18 22:10:542378 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212379 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542380 RemoveInfoBar(GetInfoBarDelegateAt(i));
2381
[email protected]8e537302009-06-10 21:19:582382 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552383 // Only do this if we're not in browser shutdown, so that TabContents
2384 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2385 // visible do not flash a sad tab page.
2386 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2387 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322388
2389 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002390 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322391}
2392
[email protected]2e4633c2009-07-09 16:58:062393void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2394 NotificationService::current()->Notify(
2395 NotificationType::RENDER_VIEW_HOST_DELETED,
2396 Source<TabContents>(this),
2397 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482398 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062399}
2400
[email protected]420ae012009-04-24 05:16:322401void TabContents::DidNavigate(RenderViewHost* rvh,
2402 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372403 int extra_invalidate_flags = 0;
2404
2405 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352406 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372407
[email protected]420ae012009-04-24 05:16:322408 render_manager_.DidNavigateMainFrame(rvh);
2409
[email protected]20ede072009-10-06 00:28:352410 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372411 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372412 }
2413
[email protected]420ae012009-04-24 05:16:322414 // Update the site of the SiteInstance if it doesn't have one yet.
2415 if (!GetSiteInstance()->has_site())
2416 GetSiteInstance()->SetSite(params.url);
2417
2418 // Need to update MIME type here because it's referred to in
2419 // UpdateNavigationCommands() called by RendererDidNavigate() to
2420 // determine whether or not to enable the encoding menu.
2421 // It's updated only for the main frame. For a subframe,
2422 // RenderView::UpdateURL does not set params.contents_mime_type.
2423 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2424 // TODO(jungshik): Add a test for the encoding menu to avoid
2425 // regressing it again.
2426 if (PageTransition::IsMainFrame(params.transition))
2427 contents_mime_type_ = params.contents_mime_type;
2428
2429 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372430 bool did_navigate = controller_.RendererDidNavigate(
2431 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392432
2433 // Update history. Note that this needs to happen after the entry is complete,
2434 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582435 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392436 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582437 // URLs, we use a data: URL as the real value. We actually want to save the
2438 // about: URL to the history db and keep the data: URL hidden. This is what
2439 // the TabContents' URL getter does.
2440 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2441 CreateHistoryAddPageArgs(GetURL(), details, params));
2442 if (!delegate() ||
2443 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2444 details.type)) {
2445 UpdateHistoryForNavigation(add_page_args);
2446 }
[email protected]3e90d4a2009-07-03 17:38:392447 }
2448
[email protected]76543b92009-08-31 17:27:452449 if (!did_navigate)
2450 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322451
2452 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2453 // for the appropriate notification (best) or you can add it to
2454 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2455 // necessary, please).
2456
2457 // Run post-commit tasks.
2458 if (details.is_main_frame)
2459 DidNavigateMainFramePostCommit(details, params);
2460 DidNavigateAnyFramePostCommit(rvh, details, params);
2461}
2462
2463void TabContents::UpdateState(RenderViewHost* rvh,
2464 int32 page_id,
2465 const std::string& state) {
2466 DCHECK(rvh == render_view_host());
2467
2468 // We must be prepared to handle state updates for any page, these occur
2469 // when the user is scrolling and entering form data, as well as when we're
2470 // leaving a page, in which case our state may have already been moved to
2471 // the next page. The navigation controller will look up the appropriate
2472 // NavigationEntry and update it when it is notified via the delegate.
2473
2474 int entry_index = controller_.GetEntryIndexWithPageID(
2475 GetSiteInstance(), page_id);
2476 if (entry_index < 0)
2477 return;
2478 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2479
2480 if (state == entry->content_state())
2481 return; // Nothing to update.
2482 entry->set_content_state(state);
2483 controller_.NotifyEntryChanged(entry, entry_index);
2484}
2485
2486void TabContents::UpdateTitle(RenderViewHost* rvh,
2487 int32 page_id, const std::wstring& title) {
2488 // If we have a title, that's a pretty good indication that we've started
2489 // getting useful data.
2490 SetNotWaitingForResponse();
2491
2492 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482493 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582494 page_id);
[email protected]420ae012009-04-24 05:16:322495 if (!entry || !UpdateTitleForEntry(entry, title))
2496 return;
2497
2498 // Broadcast notifications when the UI should be updated.
2499 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032500 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322501}
2502
[email protected]420ae012009-04-24 05:16:322503void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402504 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322505 set_encoding(encoding);
2506}
2507
2508void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2509 if (delegate())
2510 delegate()->UpdateTargetURL(this, url);
2511}
2512
2513void TabContents::UpdateThumbnail(const GURL& url,
2514 const SkBitmap& bitmap,
2515 const ThumbnailScore& score) {
2516 // Tell History about this thumbnail
[email protected]9ba208092010-08-10 20:02:082517 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492518 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422519 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282520 } else {
2521 HistoryService* hs;
2522 if (!profile()->IsOffTheRecord() &&
2523 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2524 hs->SetPageThumbnail(url, bitmap, score);
2525 }
[email protected]420ae012009-04-24 05:16:322526 }
2527}
2528
[email protected]c4e98902010-06-01 10:20:142529void TabContents::UpdateInspectorSetting(const std::string& key,
2530 const std::string& value) {
2531 DictionaryValue* inspector_settings =
2532 profile()->GetPrefs()->GetMutableDictionary(
2533 prefs::kWebKitInspectorSettings);
[email protected]8b6e84a2010-08-14 03:32:172534 inspector_settings->SetWithoutPathExpansion(key,
[email protected]628cf5a52010-06-07 14:25:332535 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082536}
2537
[email protected]45aafc92010-06-07 14:18:532538void TabContents::ClearInspectorSettings() {
2539 DictionaryValue* inspector_settings =
2540 profile()->GetPrefs()->GetMutableDictionary(
2541 prefs::kWebKitInspectorSettings);
2542 inspector_settings->Clear();
2543}
2544
[email protected]420ae012009-04-24 05:16:322545void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292546 // The UI may be in an event-tracking loop, such as between the
2547 // mouse-down and mouse-up in text selection or a button click.
2548 // Defer the close until after tracking is complete, so that we
2549 // don't free objects out from under the UI.
2550 // TODO(shess): This could probably be integrated with the
2551 // IsDoingDrag() test below. Punting for now because I need more
2552 // research to understand how this impacts platforms other than Mac.
2553 // TODO(shess): This could get more fine-grained. For instance,
2554 // closing a tab in another window while selecting text in the
2555 // current window's Omnibox should be just fine.
2556 if (view()->IsEventTracking()) {
2557 view()->CloseTabAfterEventTracking();
2558 return;
2559 }
2560
[email protected]24a4d1062009-07-10 23:10:422561 // If we close the tab while we're in the middle of a drag, we'll crash.
2562 // Instead, cancel the drag and close it as soon as the drag ends.
2563 if (view()->IsDoingDrag()) {
2564 view()->CancelDragAndCloseTab();
2565 return;
2566 }
2567
[email protected]420ae012009-04-24 05:16:322568 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2569 if (delegate() && rvh == render_view_host())
2570 delegate()->CloseContents(this);
2571}
2572
2573void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2574 if (delegate() && delegate()->IsPopup(this))
2575 delegate()->MoveContents(this, new_bounds);
2576}
2577
[email protected]7ab1e7d62009-10-14 23:32:012578void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382579 // By default, we assume that the content is not PDF. The renderer
2580 // will tell us if this is not the case.
2581 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322582 SetIsLoading(true, NULL);
2583}
2584
[email protected]7ab1e7d62009-10-14 23:32:012585void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322586 scoped_ptr<LoadNotificationDetails> details;
2587
2588 NavigationEntry* entry = controller_.GetActiveEntry();
2589 // An entry may not exist for a stop when loading an initial blank page or
2590 // if an iframe injected by script into a blank page finishes loading.
2591 if (entry) {
[email protected]420ae012009-04-24 05:16:322592 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2593
2594 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542595 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322596 entry->transition_type(),
2597 elapsed,
2598 &controller_,
2599 controller_.GetCurrentEntryIndex()));
2600 }
2601
2602 // Tell PasswordManager we've finished a page load, which serves as a
2603 // green light to save pending passwords and reset itself.
2604 GetPasswordManager()->DidStopLoading();
2605
2606 SetIsLoading(false, details.get());
2607}
2608
[email protected]420ae012009-04-24 05:16:322609void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2610 const GURL& source_url,
2611 const GURL& target_url) {
2612 NavigationEntry* entry;
2613 if (page_id == -1)
2614 entry = controller_.pending_entry();
2615 else
2616 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2617 if (!entry || entry->url() != source_url)
2618 return;
2619 entry->set_url(target_url);
2620}
2621
[email protected]420ae012009-04-24 05:16:322622void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2623 WindowOpenDisposition disposition) {
2624 if (render_manager_.dom_ui()) {
2625 // When we're a DOM UI, it will provide a page transition type for us (this
2626 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2627 // generated suggestions).
2628 //
2629 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162630 // want web sites to see a referrer of "chrome://blah" (and some
2631 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322632 // send to the site), so we send no referrer.
2633 OpenURL(url, GURL(), disposition,
2634 render_manager_.dom_ui()->link_transition_type());
2635 } else {
2636 OpenURL(url, referrer, disposition, PageTransition::LINK);
2637 }
2638}
2639
[email protected]1ee614862009-07-06 20:29:182640void TabContents::DomOperationResponse(const std::string& json_string,
2641 int automation_id) {
2642}
2643
[email protected]8b8e7c92010-08-19 18:05:562644void TabContents::ProcessDOMUIMessage(
2645 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322646 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442647 // This can happen if someone uses window.open() to open an extension URL
2648 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562649 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322650 return;
2651 }
[email protected]8b8e7c92010-08-19 18:05:562652 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322653}
2654
2655void TabContents::ProcessExternalHostMessage(const std::string& message,
2656 const std::string& origin,
2657 const std::string& target) {
2658 if (delegate())
2659 delegate()->ForwardMessageToExternalHost(message, origin, target);
2660}
2661
[email protected]420ae012009-04-24 05:16:322662void TabContents::RunJavaScriptMessage(
2663 const std::wstring& message,
2664 const std::wstring& default_prompt,
2665 const GURL& frame_url,
2666 const int flags,
2667 IPC::Message* reply_msg,
2668 bool* did_suppress_message) {
2669 // Suppress javascript messages when requested and when inside a constrained
2670 // popup window (because that activates them and breaks them out of the
2671 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552672 // Also suppress messages when showing an interstitial. The interstitial is
2673 // shown over the previous page, we don't want the hidden page dialogs to
2674 // interfere with the interstitial.
2675 bool suppress_this_message = suppress_javascript_messages_ ||
2676 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322677 if (delegate())
2678 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312679 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322680
2681 *did_suppress_message = suppress_this_message;
2682
2683 if (!suppress_this_message) {
2684 base::TimeDelta time_since_last_message(
2685 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2686 bool show_suppress_checkbox = false;
2687 // Show a checkbox offering to suppress further messages if this message is
2688 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2689 if (time_since_last_message <
2690 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2691 show_suppress_checkbox = true;
2692
[email protected]d6ad7442010-09-05 19:06:522693 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2694 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322695 } else {
2696 // If we are suppressing messages, just reply as is if the user immediately
2697 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542698 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322699 }
2700}
2701
2702void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2703 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012704 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222705 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322706}
2707
2708void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2709 const std::string& json_arguments,
2710 IPC::Message* reply_msg) {
2711 if (delegate()) {
2712 HtmlDialogUIDelegate* dialog_delegate =
2713 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222714 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322715 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2716 }
2717}
2718
[email protected]4d44a1c2010-04-28 19:20:412719void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562720 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412721 GetPasswordManager()->PasswordFormsFound(forms);
2722}
2723
2724void TabContents::PasswordFormsVisible(
2725 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2726 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322727}
2728
[email protected]420ae012009-04-24 05:16:322729// Checks to see if we should generate a keyword based on the OSDD, and if
2730// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2731void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2732 int32 page_id, const GURL& url,
2733 bool autodetected) {
2734 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2735 DCHECK(url.is_valid());
2736 if (!IsActiveEntry(page_id))
2737 return;
2738 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2739 if (!url_model)
2740 return;
2741 if (!url_model->loaded()) {
2742 url_model->Load();
2743 return;
2744 }
2745 if (!profile()->GetTemplateURLFetcher())
2746 return;
2747
2748 if (profile()->IsOffTheRecord())
2749 return;
2750
2751 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2752 DCHECK(entry);
2753
2754 const NavigationEntry* base_entry = entry;
2755 if (IsFormSubmit(base_entry)) {
2756 // If the current page is a form submit, find the last page that was not
2757 // a form submit and use its url to generate the keyword from.
2758 int index = controller_.last_committed_entry_index() - 1;
2759 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2760 index--;
2761 if (index >= 0)
2762 base_entry = controller_.GetEntryAtIndex(index);
2763 else
2764 base_entry = NULL;
2765 }
2766
2767 // We want to use the user typed URL if available since that represents what
2768 // the user typed to get here, and fall back on the regular URL if not.
2769 if (!base_entry)
2770 return;
2771 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2772 base_entry->user_typed_url() : base_entry->url();
2773 if (!keyword_url.is_valid())
2774 return;
2775 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2776 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532777
2778 // For JS added OSDD empty keyword is OK because we will generate keyword
2779 // later from OSDD content.
2780 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322781 return;
2782 const TemplateURL* template_url =
2783 url_model->GetTemplateURLForKeyword(keyword);
2784 if (template_url && (!template_url->safe_for_autoreplace() ||
2785 template_url->originating_url() == url)) {
2786 // Either there is a user created TemplateURL for this keyword, or the
2787 // keyword has the same OSDD url and we've parsed it.
2788 return;
2789 }
2790
2791 // Download the OpenSearch description document. If this is successful a
2792 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322793 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2794 keyword,
2795 url,
2796 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162797 this,
[email protected]420ae012009-04-24 05:16:322798 autodetected);
2799}
2800
[email protected]420ae012009-04-24 05:16:322801GURL TabContents::GetAlternateErrorPageURL() const {
2802 GURL url;
2803 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2804 if (profile()->IsOffTheRecord())
2805 return url;
2806
2807 PrefService* prefs = profile()->GetPrefs();
2808 DCHECK(prefs);
2809 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152810 url = google_util::AppendGoogleLocaleParam(
2811 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322812 url = google_util::AppendGoogleTLDParam(url);
2813 }
2814 return url;
2815}
2816
2817WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062818 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552819 bool is_dom_ui = false;
[email protected]6c32ce72010-03-08 05:18:062820 return RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
[email protected]420ae012009-04-24 05:16:322821}
2822
[email protected]fa1cf0b82010-01-15 21:49:442823void TabContents::OnIgnoredUIEvent() {
2824 if (constrained_window_count()) {
2825 ConstrainedWindow* window = *constrained_window_begin();
2826 window->FocusConstrainedWindow();
2827 }
2828}
2829
[email protected]420ae012009-04-24 05:16:322830void TabContents::OnJSOutOfMemory() {
2831 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582832 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2833 NULL, true));
[email protected]420ae012009-04-24 05:16:322834}
2835
[email protected]420ae012009-04-24 05:16:322836void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2837 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342838 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322839 // delivered to a pending RenderViewHost. We must first run the onunload
2840 // handler of the old RenderViewHost before we can allow it to proceed.
2841 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2842 new_request_id);
2843}
2844
[email protected]420ae012009-04-24 05:16:322845gfx::Rect TabContents::GetRootWindowResizerRect() const {
2846 if (delegate())
2847 return delegate()->GetRootWindowResizerRect();
2848 return gfx::Rect();
2849}
2850
2851void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2852 bool is_during_unload) {
2853 if (is_during_unload) {
2854 // Hang occurred while firing the beforeunload/unload handler.
2855 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112856 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322857
2858 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2859 return;
2860
2861 // If the tab hangs in the beforeunload/unload handler there's really
2862 // nothing we can do to recover. Pretend the unload listeners have
2863 // all fired and close the tab. If the hang is in the beforeunload handler
2864 // then the user will not have the option of cancelling the close.
2865 Close(rvh);
2866 return;
2867 }
2868
2869 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002870 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322871}
2872
2873void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002874 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322875}
2876
2877void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562878 net::LoadState load_state,
2879 uint64 upload_position,
2880 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322881 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562882 upload_position_ = upload_position;
2883 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292884 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192885 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292886 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532887 load_state_host_ =
2888 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322889 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2890 SetNotWaitingForResponse();
2891 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502892 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322893}
2894
[email protected]1ee614862009-07-06 20:29:182895bool TabContents::IsExternalTabContainer() const {
2896 if (!delegate())
2897 return false;
2898
2899 return delegate()->IsExternalTabContainer();
2900}
2901
[email protected]1ee614862009-07-06 20:29:182902void TabContents::DidInsertCSS() {
2903 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322904}
2905
[email protected]130efb02009-09-18 18:54:352906void TabContents::FocusedNodeChanged() {
2907 NotificationService::current()->Notify(
2908 NotificationType::FOCUS_CHANGED_IN_PAGE,
2909 Source<RenderViewHost>(render_view_host()),
2910 NotificationService::NoDetails());
2911}
2912
[email protected]ebf40a72010-07-22 01:46:382913void TabContents::SetDisplayingPDFContent() {
2914 displaying_pdf_content_ = true;
2915 if (delegate())
2916 delegate()->ContentTypeChanged(this);
2917}
2918
[email protected]420ae012009-04-24 05:16:322919void TabContents::BeforeUnloadFiredFromRenderManager(
2920 bool proceed,
2921 bool* proceed_to_fire_unload) {
2922 if (delegate())
2923 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2924}
2925
[email protected]3a3d47472010-07-15 21:03:542926void TabContents::DidStartLoadingFromRenderManager(
2927 RenderViewHost* render_view_host) {
2928 DidStartLoading();
2929}
2930
2931void TabContents::RenderViewGoneFromRenderManager(
2932 RenderViewHost* render_view_host) {
2933 RenderViewGone(render_view_host);
2934}
2935
[email protected]420ae012009-04-24 05:16:322936void TabContents::UpdateRenderViewSizeForRenderManager() {
2937 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262938 gfx::Size size = view_->GetContainerSize();
2939 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2940 // here during container initialization and normal window size will be set
2941 // later. In case of tab duplication this resizing to 0x0 prevents setting
2942 // normal size later so just ignore it.
2943 if (!size.IsEmpty())
2944 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322945}
2946
[email protected]3a3d47472010-07-15 21:03:542947void TabContents::NotifySwappedFromRenderManager() {
2948 NotifySwapped();
2949}
2950
2951NavigationController& TabContents::GetControllerForRenderManager() {
2952 return controller();
2953}
2954
[email protected]420ae012009-04-24 05:16:322955DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:222956 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322957}
2958
2959NavigationEntry*
2960TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2961 return controller_.GetLastCommittedEntry();
2962}
2963
2964bool TabContents::CreateRenderViewForRenderManager(
2965 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322966 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522967
[email protected]674b3822010-08-04 04:02:512968 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322969 return false;
2970
2971 // Now that the RenderView has been created, we need to tell it its size.
2972 rwh_view->SetSize(view_->GetContainerSize());
2973
2974 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2975 render_view_host);
2976 return true;
2977}
2978
2979void TabContents::Observe(NotificationType type,
2980 const NotificationSource& source,
2981 const NotificationDetails& details) {
2982 switch (type.value) {
2983 case NotificationType::BOOKMARK_MODEL_LOADED:
2984 // BookmarkModel finished loading, fall through to update starred state.
2985 case NotificationType::URLS_STARRED: {
2986 // Somewhere, a URL has been starred.
2987 // Ignore notifications for profiles other than our current one.
2988 Profile* source_profile = Source<Profile>(source).ptr();
2989 if (!source_profile || !source_profile->IsSameProfile(profile()))
2990 return;
2991
2992 UpdateStarredStateForCurrentURL();
2993 break;
2994 }
2995 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512996 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322997 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2998 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2999 UpdateAlternateErrorPageURL();
3000 } else if (*pref_name_in == prefs::kDefaultCharset ||
[email protected]57ecc4b2010-08-11 03:02:513001 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)
[email protected]420ae012009-04-24 05:16:323002 ) {
3003 UpdateWebPreferences();
3004 } else {
3005 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3006 }
3007 break;
3008 }
3009 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3010 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3011 break;
3012
3013 case NotificationType::NAV_ENTRY_COMMITTED: {
3014 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3015
3016 NavigationController::LoadCommittedDetails& committed_details =
3017 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3018 ExpireInfoBars(committed_details);
3019 break;
3020 }
3021
[email protected]d3ba77272009-09-03 00:06:093022#if defined(OS_LINUX)
3023 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543024 renderer_preferences_util::UpdateFromSystemSettings(
3025 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093026 render_view_host()->SyncRendererPrefs();
3027 break;
3028 }
3029#endif
3030
[email protected]6c32ce72010-03-08 05:18:063031 case NotificationType::USER_STYLE_SHEET_UPDATED:
3032 UpdateWebPreferences();
3033 break;
3034
[email protected]79580c62010-02-02 02:36:253035 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293036 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253037 settings_details(details);
[email protected]79580c62010-02-02 02:36:253038 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493039 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293040 if (entry)
[email protected]da0c8e92010-02-09 23:25:493041 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293042 if (settings_details.ptr()->update_all() ||
3043 settings_details.ptr()->pattern().Matches(entry_url)) {
3044 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233045 profile()->GetHostContentSettingsMap()->
3046 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253047 }
3048 break;
3049 }
3050
[email protected]e5adff72010-06-14 18:13:063051 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573052 break;
[email protected]a888b29e62010-04-01 13:38:573053
3054 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063055 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573056 break;
[email protected]a888b29e62010-04-01 13:38:573057
[email protected]420ae012009-04-24 05:16:323058 default:
3059 NOTREACHED();
3060 }
3061}
[email protected]aacd7cc2009-09-02 14:51:103062
[email protected]98aa0b52010-05-06 17:03:083063void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3064 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433065
[email protected]a888b29e62010-04-01 13:38:573066 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083067 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3068 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573069 extension,
[email protected]5351dbc2010-08-27 15:22:113070 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH),
[email protected]a888b29e62010-04-01 13:38:573071 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3072 Extension::EXTENSION_ICON_SMALLISH),
3073 ImageLoadingTracker::CACHE);
3074 } else {
[email protected]98aa0b52010-05-06 17:03:083075 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573076 }
3077}
3078
3079Extension* TabContents::GetExtensionContaining(const GURL& url) {
3080 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3081 if (!extensions_service)
3082 return NULL;
3083
3084 Extension* extension = extensions_service->GetExtensionByURL(url);
3085 return extension ?
3086 extension : extensions_service->GetExtensionByWebExtent(url);
3087}
3088
[email protected]a888b29e62010-04-01 13:38:573089void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3090 int index) {
3091 if (image) {
[email protected]98aa0b52010-05-06 17:03:083092 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573093 NotifyNavigationStateChanged(INVALIDATE_TAB);
3094 }
3095}
3096
[email protected]beb440c2009-11-06 04:08:543097gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3098 return view_->GetTopLevelNativeWindow();
3099}
3100
3101void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3102 bool success,
3103 const std::wstring& prompt) {
3104 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3105 if (is_showing_before_unload_dialog_ && !success) {
3106 // If a beforeunload dialog is canceled, we need to stop the throbber from
3107 // spinning, since we forced it to start spinning in Navigate.
3108 DidStopLoading();
3109
3110 tab_close_start_time_ = base::TimeTicks();
3111 }
3112 is_showing_before_unload_dialog_ = false;
3113 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3114}
3115
3116void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3117 set_suppress_javascript_messages(suppress_message_boxes);
3118}
3119
[email protected]3a3d47472010-07-15 21:03:543120TabContents* TabContents::AsTabContents() {
3121 return this;
3122}
3123
3124ExtensionHost* TabContents::AsExtensionHost() {
3125 return NULL;
3126}
3127
[email protected]41fc0322009-09-04 22:23:403128void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103129 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3130}
[email protected]f45d2a72010-03-08 23:28:353131
3132void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3133 app_icon_ = app_icon;
3134 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3135}
[email protected]ea68c06a2010-04-23 17:25:373136
3137// After a successful *new* login attempt, we take the PasswordFormManager in
3138// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3139// the user makes up their mind with the "save password" infobar. Note if the
3140// login is one we already know about, the end of the line is
3141// provisional_save_manager_ because we just update it on success and so such
3142// forms never end up in an infobar.
3143class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3144 public:
3145 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463146 PasswordFormManager* form_to_save)
3147 : ConfirmInfoBarDelegate(tab_contents),
3148 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583149 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373150
[email protected]d75aba1d2010-08-02 23:35:583151 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373152
[email protected]d75aba1d2010-08-02 23:35:583153 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373154 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463155 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583156 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373157 delete this;
3158 }
3159
[email protected]d75aba1d2010-08-02 23:35:583160 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3161
[email protected]e23d3a32010-08-13 19:39:583162 virtual string16 GetMessageText() const {
3163 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373164 }
3165
3166 virtual SkBitmap* GetIcon() const {
3167 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3168 IDR_INFOBAR_SAVE_PASSWORD);
3169 }
3170
3171 virtual int GetButtons() const {
3172 return BUTTON_OK | BUTTON_CANCEL;
3173 }
3174
[email protected]e23d3a32010-08-13 19:39:583175 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373176 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583177 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373178 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583179 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373180 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583181 return string16();
[email protected]ea68c06a2010-04-23 17:25:373182 }
3183
3184 virtual bool Accept() {
3185 DCHECK(form_to_save_.get());
3186 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583187 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373188 return true;
3189 }
3190
3191 virtual bool Cancel() {
3192 DCHECK(form_to_save_.get());
3193 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583194 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373195 return true;
3196 }
[email protected]d75aba1d2010-08-02 23:35:583197 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373198
3199 private:
3200 // The PasswordFormManager managing the form we're asking the user about,
3201 // and should update as per her decision.
3202 scoped_ptr<PasswordFormManager> form_to_save_;
3203
[email protected]12bb6822010-06-16 02:00:463204 // Used to track the results we get from the info bar.
3205 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583206 NO_RESPONSE = 0,
3207 REMEMBER_PASSWORD,
3208 DONT_REMEMBER_PASSWORD,
3209 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463210 };
3211 ResponseType infobar_response_;
3212
[email protected]ea68c06a2010-04-23 17:25:373213 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3214};
3215
3216void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163217 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373218 render_view_host()->FillPasswordForm(form_data);
3219}
3220
3221void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3222 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3223}
3224
3225Profile* TabContents::GetProfileForPasswordManager() {
3226 return profile();
3227}
3228
3229bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3230 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3231}