blob: 67428cef80370f154a8dc03f6a316acfd2dfdaed [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]39553442010-09-09 00:01:5514#if defined(OS_MACOSX)
15#include "app/surface/io_surface_support_mac.h"
16#endif
[email protected]614519812010-03-19 08:20:5617#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4918#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0120#include "base/i18n/rtl.h"
[email protected]420ae012009-04-24 05:16:3221#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5422#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3723#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4024#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5425#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4526#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2127#include "chrome/browser/autofill/autofill_manager.h"
[email protected]aad51d1c2010-08-05 08:38:0928#include "chrome/browser/blocked_plugin_manager.h"
[email protected]66ba4932009-06-04 19:22:1329#include "chrome/browser/blocked_popup_container.h"
[email protected]420ae012009-04-24 05:16:3230#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5431#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5532#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2933#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1034#include "chrome/browser/character_encoding.h"
[email protected]96d185d2009-04-24 03:28:5435#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1436#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3237#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5438#include "chrome/browser/dom_ui/dom_ui.h"
39#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0240#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3241#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0142#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4943#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0844#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5845#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4246#include "chrome/browser/history/top_sites.h"
[email protected]0189bc722009-08-28 21:56:4847#include "chrome/browser/favicon_service.h"
[email protected]ba70d082010-09-10 16:54:4948#include "chrome/browser/file_select_helper.h"
[email protected]e5d2f7132010-04-09 18:13:5349#include "chrome/browser/find_bar_state.h"
[email protected]f7578f52010-08-30 22:22:4950#include "chrome/browser/google/google_util.h"
[email protected]79580c62010-02-02 02:36:2551#include "chrome/browser/host_content_settings_map.h"
[email protected]8897c382009-05-06 17:53:2652#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0753#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]12f74a92010-02-05 22:32:1454#include "chrome/browser/message_box_handler.h"
[email protected]420ae012009-04-24 05:16:3255#include "chrome/browser/load_from_memory_cache_details.h"
56#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4457#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0558#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1059#include "chrome/browser/omnibox_search_hint.h"
[email protected]fdd61c62009-04-22 19:22:5760#include "chrome/browser/password_manager/password_manager.h"
[email protected]14a000d2010-04-29 21:44:2461#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5762#include "chrome/browser/plugin_installer.h"
[email protected]8e0bbf12010-07-20 00:03:4363#include "chrome/browser/popup_blocked_animation.h"
[email protected]37858e52010-08-26 00:22:0264#include "chrome/browser/prefs/pref_service.h"
[email protected]12802702010-07-09 19:43:0965#include "chrome/browser/printing/print_view_manager.h"
[email protected]ce560f82009-06-03 09:39:4466#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0767#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1668#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5469#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3770#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0771#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5472#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3273#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1174#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1675#include "chrome/browser/search_engines/template_url_fetcher.h"
76#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1777#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1778#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5479#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1680#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4381#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1682#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4983#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5784#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]58dca552009-06-17 00:35:0285#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1686#include "chrome/browser/translate/page_translated_details.h"
[email protected]54ec6472010-04-09 19:39:5887#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2788#include "chrome/common/chrome_switches.h"
[email protected]3b355642010-02-05 16:01:4989#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5790#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4891#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1492#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0993#include "chrome/common/extensions/url_pattern.h"
94#include "chrome/common/navigation_types.h"
95#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5696#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2997#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3298#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0299#include "chrome/common/render_messages_params.h"
[email protected]1ee614862009-07-06 20:29:18100#include "chrome/common/renderer_preferences.h"
[email protected]96d185d2009-04-24 03:28:54101#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:37102#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:26103#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:32104#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:06105#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:37106#include "grit/theme_resources.h"
[email protected]420ae012009-04-24 05:16:32107#include "net/base/mime_util.h"
108#include "net/base/net_errors.h"
[email protected]d686e812009-06-03 19:10:29109#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32110#include "net/base/registry_controlled_domain.h"
[email protected]1ee614862009-07-06 20:29:18111#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03112#include "webkit/glue/password_form.h"
[email protected]3e45ba92009-02-20 21:09:00113
[email protected]420ae012009-04-24 05:16:32114// Cross-Site Navigations
115//
116// If a TabContents is told to navigate to a different web site (as determined
117// by SiteInstance), it will replace its current RenderViewHost with a new
118// RenderViewHost dedicated to the new SiteInstance. This works as follows:
119//
120// - Navigate determines whether the destination is cross-site, and if so,
121// it creates a pending_render_view_host_ and moves into the PENDING
122// RendererState.
123// - The pending RVH is "suspended," so that no navigation messages are sent to
124// its renderer until the onbeforeunload JavaScript handler has a chance to
125// run in the current RVH.
126// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
127// that it has a pending cross-site request. ResourceDispatcherHost will
128// check for this when the response arrives.
129// - The current RVH runs its onbeforeunload handler. If it returns false, we
130// cancel all the pending logic and go back to NORMAL. Otherwise we allow
131// the pending RVH to send the navigation request to its renderer.
132// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
133// checks CrossSiteRequestManager to see that the RVH responsible has a
134// pending cross-site request, and then installs a CrossSiteEventHandler.
135// - When RDH receives a response, the BufferedEventHandler determines whether
136// it is a download. If so, it sends a message to the new renderer causing
137// it to cancel the request, and the download proceeds in the download
138// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34139// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32140// doesn't affect any functionality.
141// - After RDH receives a response and determines that it is safe and not a
142// download, it pauses the response to first run the old page's onunload
143// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34144// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32145// to the current RVH.
146// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
147// the ResourceDispatcherHost, who unpauses the response. Data is then sent
148// to the pending RVH.
149// - The pending renderer sends a FrameNavigate message that invokes the
150// DidNavigate method. This replaces the current RVH with the
151// pending RVH and goes back to the NORMAL RendererState.
152
153namespace {
154
155// Amount of time we wait between when a key event is received and the renderer
156// is queried for its state and pushed to the NavigationEntry.
157const int kQueryStateDelay = 5000;
158
159const int kSyncWaitDelay = 40;
160
[email protected]304f8792009-08-19 21:28:09161#if defined(OS_CHROMEOS)
162// If a popup window is bigger than this fraction of the screen on chrome os,
163// turn it into a tab
164const float kMaxWidthFactor = 0.5;
165const float kMaxHeightFactor = 0.6;
166#endif
167
[email protected]420ae012009-04-24 05:16:32168// If another javascript message box is displayed within
169// kJavascriptMessageExpectedDelay of a previous javascript message box being
170// dismissed, display an option to suppress future message boxes from this
171// contents.
172const int kJavascriptMessageExpectedDelay = 1000;
173
[email protected]420ae012009-04-24 05:16:32174// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51175const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32176 prefs::kAlternateErrorPagesEnabled,
177 prefs::kWebKitJavaEnabled,
178 prefs::kWebKitJavascriptEnabled,
179 prefs::kWebKitLoadsImagesAutomatically,
180 prefs::kWebKitPluginsEnabled,
181 prefs::kWebKitUsesUniversalDetector,
182 prefs::kWebKitSerifFontFamily,
183 prefs::kWebKitSansSerifFontFamily,
184 prefs::kWebKitFixedFontFamily,
185 prefs::kWebKitDefaultFontSize,
186 prefs::kWebKitDefaultFixedFontSize,
[email protected]1661a3c02010-05-20 16:32:36187 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32188 prefs::kDefaultCharset
189 // kWebKitStandardFontIsSerif needs to be added
190 // if we let users pick which font to use, serif or sans-serif when
191 // no font is specified or a CSS generic family (serif or sans-serif)
192 // is not specified.
193};
194
195const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
196
[email protected]420ae012009-04-24 05:16:32197// Returns true if the entry's transition type is FORM_SUBMIT.
198bool IsFormSubmit(const NavigationEntry* entry) {
199 return (PageTransition::StripQualifier(entry->transition_type()) ==
200 PageTransition::FORM_SUBMIT);
201}
202
203#if defined(OS_WIN)
204
205BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
206 // Note: erase is required to properly paint some widgets borders. This can
207 // be seen with textfields.
208 InvalidateRect(hwnd, NULL, TRUE);
209 return TRUE;
210}
211#endif
212
[email protected]5e369672009-11-03 23:48:30213ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16214 Profile* profile, const NavigationEntry& entry,
215 NavigationController::ReloadType reload_type) {
216 switch (reload_type) {
217 case NavigationController::RELOAD:
218 return ViewMsg_Navigate_Params::RELOAD;
219 case NavigationController::RELOAD_IGNORING_CACHE:
220 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
221 case NavigationController::NO_RELOAD:
222 break; // Fall through to rest of function.
223 }
[email protected]5e369672009-11-03 23:48:30224
225 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
226 profile->DidLastSessionExitCleanly())
227 return ViewMsg_Navigate_Params::RESTORE;
228
229 return ViewMsg_Navigate_Params::NORMAL;
230}
231
[email protected]876bc832010-09-07 16:29:54232void MakeNavigateParams(const NavigationEntry& entry,
233 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16234 NavigationController::ReloadType reload_type,
235 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34236 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54237 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00238 params->current_history_list_offset = controller.last_committed_entry_index();
239 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34240 params->url = entry.url();
241 params->referrer = entry.referrer();
242 params->transition = entry.transition_type();
243 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00244 params->navigation_type =
245 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34246 params->request_time = base::Time::Now();
247}
248
[email protected]851b1eb2010-08-09 13:32:29249class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
250 public:
251 DisabledPluginInfoBar(TabContents* tab_contents,
252 const string16& name,
253 const GURL& update_url)
254 : ConfirmInfoBarDelegate(tab_contents),
255 tab_contents_(tab_contents),
256 name_(name),
257 update_url_(update_url) {
258 tab_contents->AddInfoBar(this);
259 }
260
261 virtual int GetButtons() const {
262 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
263 }
264
[email protected]e23d3a32010-08-13 19:39:58265 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29266 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58267 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29268 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58269 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29270 return ConfirmInfoBarDelegate::GetButtonLabel(button);
271 }
272
[email protected]e23d3a32010-08-13 19:39:58273 virtual string16 GetMessageText() const {
274 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29275 }
276
[email protected]e23d3a32010-08-13 19:39:58277 virtual string16 GetLinkText() {
278 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29279 }
280
281 virtual SkBitmap* GetIcon() const {
282 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
283 IDR_INFOBAR_PLUGIN_INSTALL);
284 }
285
286 virtual bool Accept() {
287 tab_contents_->OpenURL(update_url_, GURL(),
288 CURRENT_TAB, PageTransition::LINK);
289 return false;
290 }
291
292 virtual bool Cancel() {
293 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
294 CURRENT_TAB, PageTransition::LINK);
295 return false;
296 }
297
298 virtual bool LinkClicked(WindowOpenDisposition disposition) {
299 // TODO(bauerb): Navigate to a help page explaining why we disabled
300 // the plugin, once we have one.
301 return false;
302 }
303
304 private:
305 TabContents* tab_contents_;
306 string16 name_;
307 GURL update_url_;
308};
309
[email protected]420ae012009-04-24 05:16:32310} // namespace
311
312// -----------------------------------------------------------------------------
313
[email protected]fdd61c62009-04-22 19:22:57314// static
315int TabContents::find_request_id_counter_ = -1;
316
[email protected]420ae012009-04-24 05:16:32317
[email protected]420ae012009-04-24 05:16:32318TabContents::TabContents(Profile* profile,
319 SiteInstance* site_instance,
320 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07321 const TabContents* base_tab_contents,
322 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42323 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07324 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
325 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13326 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22327 TabContentsView::Create(this))),
328 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57329 property_bag_(),
330 registrar_(),
[email protected]12802702010-07-09 19:43:09331 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
332 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57333 save_package_(),
[email protected]6db0def92010-03-02 19:55:45334 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21335 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57336 password_manager_(),
337 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06338 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22339 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34340 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29341 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34342 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34343 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57344 current_load_start_(),
345 load_state_(net::LOAD_STATE_IDLE),
346 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56347 upload_size_(0),
348 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57349 received_page_title_(false),
350 is_starred_(false),
351 contents_mime_type_(),
352 encoding_(),
[email protected]332af7732009-03-11 13:21:35353 blocked_popups_(NULL),
[email protected]8cc8d492010-02-02 10:40:49354 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47355 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57356 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57357 find_ui_active_(false),
358 find_op_aborted_(false),
359 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12360 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12361 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08362 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57363 capturing_contents_(false),
364 is_being_destroyed_(false),
365 notify_disconnection_(false),
366 history_requests_(),
367#if defined(OS_WIN)
368 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
369#endif
370 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44371 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01372 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54373 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54374 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16375 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38376 closed_by_user_gesture_(false),
377 displaying_pdf_content_(false) {
[email protected]7ff431e2010-01-07 18:18:54378 renderer_preferences_util::UpdateFromSystemSettings(
379 &renderer_preferences_, profile);
380
[email protected]9fb83e82010-07-02 18:24:55381 content_settings_delegate_.reset(
382 new TabSpecificContentSettings(this, profile));
383
[email protected]16779842009-07-08 23:45:29384#if defined(OS_CHROMEOS)
[email protected]58dca552009-06-17 00:35:02385 // Make sure the thumbnailer is started before starting the render manager.
386 // The thumbnailer will want to listen for RVH creations, one of which will
387 // happen in RVHManager::Init.
388 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
389 if (generator)
390 generator->StartThumbnailing();
391#endif
392
[email protected]12636df2009-09-28 22:32:21393 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32394
[email protected]34ac70502009-09-25 17:07:23395 // We have the initial size of the view be based on the size of the passed in
396 // tab contents (normally a tab from the same window).
397 view_->CreateView(base_tab_contents ?
398 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32399
400 // Register for notifications about all interested prefs change.
401 PrefService* prefs = profile->GetPrefs();
402 if (prefs) {
403 for (int i = 0; i < kPrefsToObserveLength; ++i)
404 prefs->AddPrefObserver(kPrefsToObserve[i], this);
405 }
406
407 // Register for notifications about URL starredness changing on any profile.
408 registrar_.Add(this, NotificationType::URLS_STARRED,
409 NotificationService::AllSources());
410 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
411 NotificationService::AllSources());
412 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
413 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09414#if defined(OS_LINUX)
415 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
416 NotificationService::AllSources());
417#endif
[email protected]420ae012009-04-24 05:16:32418
[email protected]6c32ce72010-03-08 05:18:06419 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
420 NotificationService::AllSources());
421
[email protected]79580c62010-02-02 02:36:25422 // Register for notifications about content setting changes.
423 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
424 NotificationService::AllSources());
425
[email protected]a888b29e62010-04-01 13:38:57426 // Listen for extension changes so we can update extension_for_current_page_.
427 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
428 NotificationService::AllSources());
429 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
430 NotificationService::AllSources());
431 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
432 NotificationService::AllSources());
433
[email protected]c8865482009-07-23 20:40:10434 // Set-up the showing of the omnibox search infobar if applicable.
435 if (OmniboxSearchHint::IsEnabled(profile))
436 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35437}
initial.commit09911bf2008-07-26 23:55:29438
439TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32440 is_being_destroyed_ = true;
441
[email protected]bfe4c1582009-10-02 18:11:09442 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32443 registrar_.RemoveAll();
444
445 // Unregister the notifications of all observed prefs change.
446 PrefService* prefs = profile()->GetPrefs();
447 if (prefs) {
448 for (int i = 0; i < kPrefsToObserveLength; ++i)
449 prefs->RemovePrefObserver(kPrefsToObserve[i], this);
450 }
451
[email protected]420ae012009-04-24 05:16:32452 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00453 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32454
[email protected]420ae012009-04-24 05:16:32455 // First cleanly close all child windows.
456 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
457 // some of these to close. CloseWindows is async, so it might get called
458 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49459 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32460
[email protected]8cc8d492010-02-02 10:40:49461 // Close all blocked popups.
[email protected]66ba4932009-06-04 19:22:13462 if (blocked_popups_)
463 blocked_popups_->Destroy();
464
[email protected]420ae012009-04-24 05:16:32465 // Notify any observer that have a reference on this tab contents.
466 NotificationService::current()->Notify(
467 NotificationType::TAB_CONTENTS_DESTROYED,
468 Source<TabContents>(this),
469 NotificationService::NoDetails());
470
[email protected]1e5e74f2009-05-27 20:55:12471 // Notify any lasting InfobarDelegates that have not yet been removed that
472 // whatever infobar they were handling in this TabContents has closed,
473 // because the TabContents is going away entirely.
474 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
475 // notification may trigger infobars calls that access their delegate. (and
476 // some implementations of InfoBarDelegate do delete themselves on
477 // InfoBarClosed()).
478 for (int i = 0; i < infobar_delegate_count(); ++i) {
479 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
480 delegate->InfoBarClosed();
481 }
482 infobar_delegates_.clear();
483
[email protected]420ae012009-04-24 05:16:32484 // TODO(brettw) this should be moved to the view.
485#if defined(OS_WIN)
486 // If we still have a window handle, destroy it. GetNativeView can return
487 // NULL if this contents was part of a window that closed.
488 if (GetNativeView())
489 ::DestroyWindow(GetNativeView());
490#endif
[email protected]7ab1e7d62009-10-14 23:32:01491
492 // OnCloseStarted isn't called in unit tests.
493 if (!tab_close_start_time_.is_null()) {
494 UMA_HISTOGRAM_TIMES("Tab.Close",
495 base::TimeTicks::Now() - tab_close_start_time_);
496 }
initial.commit09911bf2008-07-26 23:55:29497}
498
[email protected]d5f942ba2008-09-26 19:30:34499// static
500void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32501 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
502
503 WebPreferences pref_defaults;
504 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
505 pref_defaults.javascript_enabled);
506 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
507 pref_defaults.web_security_enabled);
508 prefs->RegisterBooleanPref(
509 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
510 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
511 pref_defaults.loads_images_automatically);
512 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
513 pref_defaults.plugins_enabled);
514 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
515 pref_defaults.dom_paste_enabled);
516 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
517 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14518 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32519 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
520 pref_defaults.text_areas_are_resizable);
521 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
522 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36523 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
524 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32525
526 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
527 IDS_ACCEPT_LANGUAGES);
528 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
529 IDS_DEFAULT_ENCODING);
530 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
531 IDS_STANDARD_FONT_IS_SERIF);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
533 IDS_FIXED_FONT_FAMILY);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
535 IDS_SERIF_FONT_FAMILY);
536 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
537 IDS_SANS_SERIF_FONT_FAMILY);
538 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
539 IDS_CURSIVE_FONT_FAMILY);
540 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
541 IDS_FANTASY_FONT_FAMILY);
542 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
543 IDS_DEFAULT_FONT_SIZE);
544 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
545 IDS_DEFAULT_FIXED_FONT_SIZE);
546 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
547 IDS_MINIMUM_FONT_SIZE);
548 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
549 IDS_MINIMUM_LOGICAL_FONT_SIZE);
550 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
551 IDS_USES_UNIVERSAL_DETECTOR);
552 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
553 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29554}
555
[email protected]13367f72009-07-08 16:39:02556// Returns true if contains content rendered by an extension.
557bool TabContents::HostsExtension() const {
558 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34559}
560
[email protected]cf28ec52010-04-09 22:56:34561AutoFillManager* TabContents::GetAutoFillManager() {
562 if (autofill_manager_.get() == NULL)
563 autofill_manager_.reset(new AutoFillManager(this));
564 return autofill_manager_.get();
565}
566
[email protected]6e95706d2009-04-23 22:55:01567PasswordManager* TabContents::GetPasswordManager() {
568 if (password_manager_.get() == NULL)
569 password_manager_.reset(new PasswordManager(this));
570 return password_manager_.get();
571}
572
573PluginInstaller* TabContents::GetPluginInstaller() {
574 if (plugin_installer_.get() == NULL)
575 plugin_installer_.reset(new PluginInstaller(this));
576 return plugin_installer_.get();
577}
578
[email protected]1f18184a2010-07-21 19:34:49579TabContentsSSLHelper* TabContents::GetSSLHelper() {
580 if (ssl_helper_.get() == NULL)
581 ssl_helper_.reset(new TabContentsSSLHelper(this));
582 return ssl_helper_.get();
583}
584
[email protected]8cb5d5b2010-02-09 11:36:16585RenderProcessHost* TabContents::GetRenderProcessHost() const {
586 return render_manager_.current_host()->process();
587}
588
[email protected]98aa0b52010-05-06 17:03:08589void TabContents::SetExtensionApp(Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46590 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08591 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10592
[email protected]98aa0b52010-05-06 17:03:08593 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57594
[email protected]fca656c2010-02-10 20:30:10595 NotificationService::current()->Notify(
596 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
597 Source<TabContents>(this),
598 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49599}
600
[email protected]98aa0b52010-05-06 17:03:08601void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
602 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40603 return;
604
605 ExtensionsService* extension_service = profile()->GetExtensionsService();
606 if (extension_service && extension_service->is_ready()) {
607 Extension* extension =
[email protected]98aa0b52010-05-06 17:03:08608 extension_service->GetExtensionById(extension_app_id, false);
[email protected]911f8152010-03-18 16:46:40609 if (extension)
[email protected]98aa0b52010-05-06 17:03:08610 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40611 }
612}
613
[email protected]98aa0b52010-05-06 17:03:08614SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08615 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51616 return NULL;
617
[email protected]98aa0b52010-05-06 17:03:08618 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51619}
620
[email protected]d5f942ba2008-09-26 19:30:34621const GURL& TabContents::GetURL() const {
622 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57623 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54624 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34625}
626
[email protected]96d185d2009-04-24 03:28:54627const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55628 // Transient entries take precedence. They are used for interstitial pages
629 // that are shown on top of existing pages.
630 NavigationEntry* entry = controller_.GetTransientEntry();
631 if (entry)
632 return entry->GetTitleForDisplay(&controller_);
633
[email protected]96d185d2009-04-24 03:28:54634 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
635 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
636 if (our_dom_ui) {
637 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55638 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54639 if (!(entry && entry->IsViewSourceMode())) {
640 // Give the DOM UI the chance to override our title.
641 const string16& title = our_dom_ui->overridden_title();
642 if (!title.empty())
643 return title;
644 }
645 }
646
647 // We use the title for the last committed entry rather than a pending
648 // navigation entry. For example, when the user types in a URL, we want to
649 // keep the old page's title until the new load has committed and we get a new
650 // title.
[email protected]96d185d2009-04-24 03:28:54651 entry = controller_.GetLastCommittedEntry();
652 if (entry)
653 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54654 return EmptyString16();
655}
656
[email protected]bbbc1ef2010-02-12 18:03:41657// static
658string16 TabContents::GetDefaultTitle() {
659 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
660}
661
[email protected]d5f942ba2008-09-26 19:30:34662int32 TabContents::GetMaxPageID() {
663 if (GetSiteInstance())
664 return GetSiteInstance()->max_page_id();
665 else
666 return max_page_id_;
667}
668
669void TabContents::UpdateMaxPageID(int32 page_id) {
670 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34671 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34672 // testing.
673 if (GetSiteInstance())
674 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16675 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34676}
677
[email protected]96d185d2009-04-24 03:28:54678SiteInstance* TabContents::GetSiteInstance() const {
679 return render_manager_.current_host()->site_instance();
680}
681
[email protected]96d185d2009-04-24 03:28:54682bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15683 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54684 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15685 if (entry && (entry->IsViewSourceMode() ||
686 entry->page_type() == NavigationEntry::INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54687 return true;
[email protected]8ab24cc2009-11-13 20:56:15688 }
[email protected]83e3895b2009-06-11 00:07:16689
[email protected]96d185d2009-04-24 03:28:54690 DOMUI* dom_ui = GetDOMUIForCurrentState();
691 if (dom_ui)
692 return !dom_ui->should_hide_url();
693 return true;
694}
695
[email protected]d5f942ba2008-09-26 19:30:34696SkBitmap TabContents::GetFavIcon() const {
697 // Like GetTitle(), we also want to use the favicon for the last committed
698 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57699 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47700 if (entry)
701 return entry->favicon().bitmap();
702
[email protected]ce3fa3c2009-04-20 19:55:57703 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34704 if (entry)
705 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34706 return SkBitmap();
707}
708
[email protected]0b303cc2009-09-28 22:35:15709bool TabContents::FavIconIsValid() const {
710 NavigationEntry* entry = controller_.GetTransientEntry();
711 if (entry)
712 return entry->favicon().is_valid();
713
714 entry = controller_.GetLastCommittedEntry();
715 if (entry)
716 return entry->favicon().is_valid();
717
718 return false;
719}
720
[email protected]96d185d2009-04-24 03:28:54721bool TabContents::ShouldDisplayFavIcon() {
722 // Always display a throbber during pending loads.
723 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
724 return true;
725
726 DOMUI* dom_ui = GetDOMUIForCurrentState();
727 if (dom_ui)
728 return !dom_ui->hide_favicon();
729 return true;
730}
731
[email protected]96d185d2009-04-24 03:28:54732std::wstring TabContents::GetStatusText() const {
733 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
734 return std::wstring();
735
736 switch (load_state_) {
737 case net::LOAD_STATE_WAITING_FOR_CACHE:
738 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04739 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
740 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54741 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
742 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
743 case net::LOAD_STATE_RESOLVING_HOST:
744 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
745 case net::LOAD_STATE_CONNECTING:
746 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06747 case net::LOAD_STATE_SSL_HANDSHAKE:
748 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54749 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56750 if (upload_size_)
751 return l10n_util::GetStringF(
752 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
753 static_cast<int>((100 * upload_position_) / upload_size_));
754 else
755 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54756 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
757 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
758 load_state_host_);
759 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
760 case net::LOAD_STATE_IDLE:
761 case net::LOAD_STATE_READING_RESPONSE:
762 break;
763 }
764
765 return std::wstring();
766}
767
[email protected]d5f942ba2008-09-26 19:30:34768void TabContents::SetIsCrashed(bool state) {
769 if (state == is_crashed_)
770 return;
771
772 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50773 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34774}
775
[email protected]744ef172009-10-16 21:53:46776void TabContents::PageActionStateChanged() {
777 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00778}
[email protected]ce5c4502009-05-06 16:46:11779
[email protected]d5f942ba2008-09-26 19:30:34780void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
781 if (delegate_)
782 delegate_->NavigationStateChanged(this, changed_flags);
783}
784
[email protected]96d185d2009-04-24 03:28:54785void TabContents::DidBecomeSelected() {
786 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16787 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
788 if (rwhv) {
789 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43790#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16791 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43792#endif
793 }
[email protected]96d185d2009-04-24 03:28:54794
[email protected]8cb5d5b2010-02-09 11:36:16795 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]96d185d2009-04-24 03:28:54796}
797
798void TabContents::WasHidden() {
799 if (!capturing_contents()) {
800 // |render_view_host()| can be NULL if the user middle clicks a link to open
801 // a tab in then background, then closes the tab before selecting it. This
802 // is because closing the tab calls TabContents::Destroy(), which removes
803 // the |render_view_host()|; then when we actually destroy the window,
804 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16805 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
806 if (rwhv)
807 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54808 }
809
810 NotificationService::current()->Notify(
811 NotificationType::TAB_CONTENTS_HIDDEN,
812 Source<TabContents>(this),
813 NotificationService::NoDetails());
814}
815
[email protected]d5f942ba2008-09-26 19:30:34816void TabContents::Activate() {
817 if (delegate_)
818 delegate_->ActivateContents(this);
819}
820
[email protected]ea42e7782010-08-23 23:58:12821void TabContents::Deactivate() {
822 if (delegate_)
823 delegate_->DeactivateContents(this);
824}
825
[email protected]96d185d2009-04-24 03:28:54826void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16827 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
828 if (rwhv)
829 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54830}
831
832void TabContents::HideContents() {
833 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
834 // our superclass HideContents(), because some callers want to be very picky
835 // about the order in which these get called. In addition to making the code
836 // here practically impossible to understand, this also means we end up
837 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34838 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54839 WasHidden();
840}
841
[email protected]c0588052008-10-27 23:01:50842void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34843 WindowOpenDisposition disposition,
844 PageTransition::Type transition) {
845 if (delegate_)
[email protected]c0588052008-10-27 23:01:50846 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34847}
848
[email protected]1ccb3568d2010-02-19 10:51:16849bool TabContents::NavigateToPendingEntry(
850 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54851 return NavigateToEntry(*controller_.pending_entry(), reload_type);
852}
[email protected]96d185d2009-04-24 03:28:54853
[email protected]876bc832010-09-07 16:29:54854bool TabContents::NavigateToEntry(
855 const NavigationEntry& entry,
856 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54857 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
858 if (!dest_render_view_host)
859 return false; // Unable to create the desired render view host.
860
[email protected]770dd8b2010-05-24 18:11:39861 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
862 dest_render_view_host->EnablePreferredSizeChangedMode(
863 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
864 }
[email protected]9fb325e2010-05-06 18:23:24865
[email protected]0352e5472010-04-29 00:11:40866 // For security, we should never send non-DOM-UI URLs (other than about:blank)
867 // to a DOM UI renderer. Double check that here.
[email protected]54ec6472010-04-09 19:39:58868 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40869 bool is_allowed_in_dom_ui_renderer =
[email protected]583d45c12010-08-31 02:48:12870 DOMUIFactory::UseDOMUIForURL(profile(), entry.url()) ||
[email protected]0352e5472010-04-29 00:11:40871 entry.url() == GURL(chrome::kAboutBlankURL);
[email protected]54ec6472010-04-09 19:39:58872 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40873 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58874
[email protected]96d185d2009-04-24 03:28:54875 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12876 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32877 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00878 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
879 dest_render_view_host,
880 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32881 }
[email protected]96d185d2009-04-24 03:28:54882
883 // Used for page load time metrics.
884 current_load_start_ = base::TimeTicks::Now();
885
886 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34887 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54888 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]056de2d2009-06-26 16:41:34889 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54890
891 if (entry.page_id() == -1) {
892 // HACK!! This code suppresses javascript: URLs from being added to
893 // session history, which is what we want to do for javascript: URLs that
894 // do not generate content. What we really need is a message from the
895 // renderer telling us that a new page was not created. The same message
896 // could be used for mailto: URLs and the like.
897 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
898 return false;
899 }
900
901 // Clear any provisional password saves - this stops password infobars
902 // showing up on pages the user navigates to while the right page is
903 // loading.
904 GetPasswordManager()->ClearProvisionalSave();
905
[email protected]1ccb3568d2010-02-19 10:51:16906 if (reload_type != NavigationController::NO_RELOAD &&
907 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48908 FaviconService* favicon_service =
909 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
910 if (favicon_service)
911 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54912 }
913
[email protected]d5f942ba2008-09-26 19:30:34914 return true;
915}
916
[email protected]96d185d2009-04-24 03:28:54917void TabContents::Stop() {
918 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09919 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54920}
921
[email protected]96d185d2009-04-24 03:28:54922void TabContents::DisassociateFromPopupCount() {
923 render_view_host()->DisassociateFromPopupCount();
924}
925
926TabContents* TabContents::Clone() {
927 // We create a new SiteInstance so that the new tab won't share processes
928 // with the old one. This can be changed in the future if we need it to share
929 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32930 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54931 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07932 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54933 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08934 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08935 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54936 return tc;
937}
938
[email protected]4d677202009-07-19 07:37:12939void TabContents::ShowPageInfo(const GURL& url,
940 const NavigationEntry::SSLStatus& ssl,
941 bool show_history) {
942 if (!delegate_)
943 return;
944
[email protected]bb678332009-07-21 00:15:50945 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12946}
947
initial.commit09911bf2008-07-26 23:55:29948ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28949 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29950 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28951 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29952 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44953
954 if (child_windows_.size() == 1) {
955 window->ShowConstrainedWindow();
956 BlockTabContent(true);
957 }
958
initial.commit09911bf2008-07-26 23:55:29959 return window;
960}
961
[email protected]fa1cf0b82010-01-15 21:49:44962void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55963 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
964 if (rwhv)
965 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44966 render_view_host()->set_ignore_input_events(blocked);
967 if (delegate_)
968 delegate_->SetTabContentBlocked(this, blocked);
969}
970
initial.commit09911bf2008-07-26 23:55:29971void TabContents::AddNewContents(TabContents* new_contents,
972 WindowOpenDisposition disposition,
973 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29974 bool user_gesture) {
initial.commit09911bf2008-07-26 23:55:29975 if (!delegate_)
976 return;
977
[email protected]35f7d212009-04-29 21:19:27978 if ((disposition == NEW_POPUP) && !user_gesture &&
979 !CommandLine::ForCurrentProcess()->HasSwitch(
980 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22981 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31982 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29983 delegate_->GetConstrainingContents(this)->AddPopup(
984 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31985 } else {
[email protected]304f8792009-08-19 21:28:09986#if defined(OS_CHROMEOS)
987 if (disposition == NEW_POPUP) {
988 // If the popup is bigger than a given factor of the screen, then
989 // turn it into a foreground tab (on chrome os only)
[email protected]8323b082010-07-16 16:56:11990 // Also check for width or height == 0, which would otherwise indicate
991 // a tab sized popup window.
[email protected]304f8792009-08-19 21:28:09992 GdkScreen* screen = gdk_screen_get_default();
993 int max_width = gdk_screen_get_width(screen) * kMaxWidthFactor;
994 int max_height = gdk_screen_get_height(screen) * kMaxHeightFactor;
[email protected]8323b082010-07-16 16:56:11995 if (initial_pos.width() > max_width || initial_pos.width() == 0 ||
996 initial_pos.height() > max_height || initial_pos.height() == 0) {
[email protected]304f8792009-08-19 21:28:09997 disposition = NEW_FOREGROUND_TAB;
998 }
999 }
1000#endif
1001
[email protected]0aa55312008-10-17 21:53:081002 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291003 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1004 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491005 NotificationService::current()->Notify(
1006 NotificationType::TAB_ADDED,
1007 Source<TabContentsDelegate>(delegate_),
1008 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291009 }
initial.commit09911bf2008-07-26 23:55:291010
[email protected]8cc8d492010-02-02 10:40:491011 // TODO(pkasting): Why is this necessary?
1012 PopupNotificationVisibilityChanged(blocked_popups_ != NULL);
initial.commit09911bf2008-07-26 23:55:291013}
1014
[email protected]bcd9dc42010-01-23 16:38:181015bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]61f5a7b2009-12-22 22:21:201016 const std::vector<URLPattern>& host_permissions,
[email protected]20ad2692009-11-20 18:27:201017 bool is_js_code, const std::string& code_string,
1018 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511019 RenderViewHost* host = render_view_host();
1020 if (!host)
1021 return false;
1022
1023 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
1024 ViewMsg_ExecuteCode_Params(request_id, extension_id, host_permissions,
1025 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351026}
1027
[email protected]96d185d2009-04-24 03:28:541028void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491029 if (is_being_destroyed_)
1030 return;
[email protected]9fb83e82010-07-02 18:24:551031 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491032 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401033 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541034}
1035
[email protected]5c9e97a2009-09-09 23:48:301036gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541037 return view_->GetContentNativeView();
1038}
1039
1040gfx::NativeView TabContents::GetNativeView() const {
1041 return view_->GetNativeView();
1042}
1043
1044void TabContents::GetContainerBounds(gfx::Rect *out) const {
1045 view_->GetContainerBounds(out);
1046}
1047
1048void TabContents::Focus() {
1049 view_->Focus();
1050}
1051
[email protected]90daadb42009-06-08 21:27:281052void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541053 if (showing_interstitial_page()) {
1054 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1055 return;
1056 }
[email protected]96d185d2009-04-24 03:28:541057 render_view_host()->SetInitialFocus(reverse);
1058}
1059
1060bool TabContents::FocusLocationBarByDefault() {
1061 DOMUI* dom_ui = GetDOMUIForCurrentState();
1062 if (dom_ui)
1063 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431064 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251065 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431066 return true;
[email protected]96d185d2009-04-24 03:28:541067 return false;
1068}
1069
[email protected]a26dc362010-04-23 01:48:581070void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381071 if (delegate())
[email protected]a26dc362010-04-23 01:48:581072 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381073}
1074
[email protected]616ed5a2008-11-21 22:27:241075void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321076 if (delegate_ && !delegate_->infobars_enabled()) {
1077 delegate->InfoBarClosed();
1078 return;
1079 }
1080
[email protected]616ed5a2008-11-21 22:27:241081 // Look through the existing InfoBarDelegates we have for a match. If we've
1082 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051083 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451084 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1085 // Tell the new infobar to close so that it can clean itself up.
1086 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241087 return;
[email protected]6d27a7b2009-12-18 23:25:451088 }
[email protected]616ed5a2008-11-21 22:27:241089 }
1090
1091 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561092 NotificationService::current()->Notify(
1093 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1094 Source<TabContents>(this),
1095 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241096
1097 // Add ourselves as an observer for navigations the first time a delegate is
1098 // added. We use this notification to expire InfoBars that need to expire on
1099 // page transitions.
1100 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561101 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571102 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241103 }
1104}
1105
1106void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321107 if (delegate_ && !delegate_->infobars_enabled()) {
1108 return;
1109 }
1110
[email protected]616ed5a2008-11-21 22:27:241111 std::vector<InfoBarDelegate*>::iterator it =
1112 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1113 if (it != infobar_delegates_.end()) {
1114 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561115 NotificationService::current()->Notify(
1116 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1117 Source<TabContents>(this),
1118 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241119
[email protected]cdadf6f2010-08-20 16:36:081120 // Just to be safe, make sure the delegate was not removed by an observer.
1121 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1122 if (it != infobar_delegates_.end()) {
1123 infobar_delegates_.erase(it);
1124 // Remove ourselves as an observer if we are tracking no more InfoBars.
1125 if (infobar_delegates_.empty()) {
1126 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1127 Source<NavigationController>(&controller_));
1128 }
1129 } else {
1130 // If you hit this NOTREACHED, please comment in bug
1131 // http://crbug.com/50428 how you got there.
1132 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031133 }
[email protected]616ed5a2008-11-21 22:27:241134 }
1135}
[email protected]3edd9522009-03-04 22:19:411136
[email protected]f81821c2009-08-07 01:29:471137void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1138 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321139 if (delegate_ && !delegate_->infobars_enabled()) {
1140 new_delegate->InfoBarClosed();
1141 return;
1142 }
1143
[email protected]f81821c2009-08-07 01:29:471144 std::vector<InfoBarDelegate*>::iterator it =
1145 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1146 DCHECK(it != infobar_delegates_.end());
1147
1148 // Notify the container about the change of plans.
1149 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1150 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1151 old_delegate, new_delegate));
1152 NotificationService::current()->Notify(
1153 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1154 Source<TabContents>(this),
1155 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1156
[email protected]cdadf6f2010-08-20 16:36:081157 // Just to be safe, make sure the delegate was not removed by an observer.
1158 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1159 if (it != infobar_delegates_.end()) {
1160 // Remove the old one.
1161 infobar_delegates_.erase(it);
1162 } else {
1163 // If you hit this NOTREACHED, please comment in bug
1164 // http://crbug.com/50428 how you got there.
1165 NOTREACHED();
1166 }
[email protected]f81821c2009-08-07 01:29:471167
1168 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081169 DCHECK(find(infobar_delegates_.begin(),
1170 infobar_delegates_.end(), new_delegate) ==
1171 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471172 infobar_delegates_.push_back(new_delegate);
1173}
1174
[email protected]20ede072009-10-06 00:28:351175bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271176 if (showing_interstitial_page())
1177 return false;
1178
[email protected]c8f74942010-09-03 10:04:141179 // Do not show bookmarks bar if bookmarks aren't enabled.
1180 if (!browser_defaults::bookmarks_enabled)
1181 return false;
1182
[email protected]96d185d2009-04-24 03:28:541183 // See GetDOMUIForCurrentState() comment for more info. This case is very
1184 // similar, but for non-first loads, we want to use the committed entry. This
1185 // is so the bookmarks bar disappears at the same time the page does.
1186 if (controller_.GetLastCommittedEntry()) {
1187 // Not the first load, always use the committed DOM UI.
1188 if (render_manager_.dom_ui())
1189 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1190 return false; // Default.
1191 }
1192
1193 // When it's the first load, we know either the pending one or the committed
1194 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1195 // of them will be valid, so we can just check both.
1196 if (render_manager_.pending_dom_ui())
1197 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
1198 if (render_manager_.dom_ui())
1199 return render_manager_.dom_ui()->force_bookmark_bar_visible();
1200 return false; // Default.
1201}
1202
[email protected]3edd9522009-03-04 22:19:411203void TabContents::ToolbarSizeChanged(bool is_animating) {
1204 TabContentsDelegate* d = delegate();
1205 if (d)
1206 d->ToolbarSizeChanged(this, is_animating);
1207}
[email protected]616ed5a2008-11-21 22:27:241208
[email protected]fc6fb7fb2009-11-07 02:35:041209bool TabContents::CanDownload(int request_id) {
1210 TabContentsDelegate* d = delegate();
1211 if (d)
1212 return d->CanDownload(request_id);
1213 return true;
1214}
1215
[email protected]d5f942ba2008-09-26 19:30:341216void TabContents::OnStartDownload(DownloadItem* download) {
1217 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341218
1219 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311220 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341221
[email protected]5b928b62010-08-03 11:46:511222 if (tab_contents && tab_contents->delegate())
1223 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411224}
[email protected]3edd9522009-03-04 22:19:411225
[email protected]d5f942ba2008-09-26 19:30:341226void TabContents::WillClose(ConstrainedWindow* window) {
1227 ConstrainedWindowList::iterator it =
1228 find(child_windows_.begin(), child_windows_.end(), window);
[email protected]fa1cf0b82010-01-15 21:49:441229 bool removed_topmost_window = it == child_windows_.begin();
[email protected]d5f942ba2008-09-26 19:30:341230 if (it != child_windows_.end())
1231 child_windows_.erase(it);
[email protected]55098792010-03-24 18:20:371232 if (child_windows_.size() > 0) {
1233 if (removed_topmost_window) {
1234 child_windows_[0]->ShowConstrainedWindow();
1235 }
[email protected]fa1cf0b82010-01-15 21:49:441236 BlockTabContent(true);
1237 } else {
1238 BlockTabContent(false);
1239 }
[email protected]66ba4932009-06-04 19:22:131240}
[email protected]d5f942ba2008-09-26 19:30:341241
[email protected]66ba4932009-06-04 19:22:131242void TabContents::WillCloseBlockedPopupContainer(
1243 BlockedPopupContainer* container) {
1244 DCHECK(blocked_popups_ == container);
1245 blocked_popups_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491246 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341247}
1248
[email protected]d5f942ba2008-09-26 19:30:341249void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351250#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061251 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351252#endif
[email protected]d5f942ba2008-09-26 19:30:341253}
1254
[email protected]c1dc9f132009-11-20 23:13:211255void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121256 bool forward_direction,
1257 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211258 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011259 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211260 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531261 string16 last_search_prepopulate_text =
1262 FindBarState::GetLastPrepopulateText(profile());
1263
[email protected]87fae512009-12-11 02:20:211264 // Try the last thing we searched for on this tab, then the last thing
1265 // searched for on any tab.
1266 if (!previous_find_text_.empty())
1267 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531268 else if (!last_search_prepopulate_text.empty())
1269 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211270 else
[email protected]e491f1c2009-05-22 20:28:121271 return;
[email protected]e491f1c2009-05-22 20:28:121272 }
[email protected]6e95706d2009-04-23 22:55:011273
[email protected]101c90e2009-10-26 21:14:441274 // Keep track of the previous search.
1275 previous_find_text_ = find_text_;
1276
[email protected]6e95706d2009-04-23 22:55:011277 // This is a FindNext operation if we are searching for the same text again,
1278 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1279 // exception to this is if the Find was aborted (then we don't want FindNext
1280 // because the highlighting has been cleared and we need it to reappear). We
1281 // therefore treat FindNext after an aborted Find operation as a full fledged
1282 // Find.
[email protected]c1dc9f132009-11-20 23:13:211283 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121284 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011285 !find_op_aborted_;
1286 if (!find_next)
1287 current_find_request_id_ = find_request_id_counter_++;
1288
[email protected]c1dc9f132009-11-20 23:13:211289 if (!search_string.empty())
1290 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121291 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011292
1293 find_op_aborted_ = false;
1294
1295 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531296 FindBarState* find_bar_state = profile()->GetFindBarState();
1297 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011298 render_view_host()->StartFinding(current_find_request_id_,
1299 find_text_,
1300 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121301 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011302 find_next);
1303}
1304
[email protected]5bc8fe92010-03-11 18:19:001305void TabContents::StopFinding(
1306 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011307 if (selection_action == FindBarController::kClearSelection) {
1308 // kClearSelection means the find string has been cleared by the user, but
1309 // the UI has not been dismissed. In that case we want to clear the
1310 // previously remembered search (http://crbug.com/42639).
1311 previous_find_text_ = string16();
1312 } else {
[email protected]2d2dffc2009-06-09 21:41:001313 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011314 if (!find_text_.empty())
1315 previous_find_text_ = find_text_;
1316 }
[email protected]101c90e2009-10-26 21:14:441317 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011318 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121319 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001320 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011321}
1322
[email protected]420ae012009-04-24 05:16:321323void TabContents::OnSavePage() {
1324 // If we can not save the page, try to download it.
1325 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1326 DownloadManager* dlm = profile()->GetDownloadManager();
1327 const GURL& current_page_url = GetURL();
1328 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221329 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321330 return;
1331 }
1332
1333 Stop();
1334
1335 // Create the save package and possibly prompt the user for the name to save
1336 // the page as. The user prompt is an asynchronous operation that runs on
1337 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221338 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321339 save_package_->GetSaveInfo();
1340}
1341
1342// Used in automated testing to bypass prompting the user for file names.
1343// Instead, the names and paths are hard coded rather than running them through
1344// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111345bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321346 SavePackage::SavePackageType save_type) {
1347 // Stop the page from navigating.
1348 Stop();
1349
[email protected]828cabe2009-09-26 22:47:111350 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591351 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321352}
1353
[email protected]89d6e6e2009-12-03 23:06:511354void TabContents::EmailPageLocation() {
1355 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1356 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1357 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1358 title + "&body=%0A%0A" + page_url;
1359 platform_util::OpenExternal(GURL(mailto));
1360}
1361
[email protected]420ae012009-04-24 05:16:321362void TabContents::PrintPreview() {
1363 // We don't show the print preview yet, only the print dialog.
1364 PrintNow();
1365}
1366
1367bool TabContents::PrintNow() {
1368 // We can't print interstitial page for now.
1369 if (showing_interstitial_page())
1370 return false;
1371
1372 return render_view_host()->PrintPages();
1373}
1374
[email protected]82270452009-06-19 15:58:011375void TabContents::PrintingDone(int document_cookie, bool success) {
1376 render_view_host()->PrintingDone(document_cookie, success);
1377}
1378
[email protected]420ae012009-04-24 05:16:321379bool TabContents::IsActiveEntry(int32 page_id) {
1380 NavigationEntry* active_entry = controller_.GetActiveEntry();
1381 return (active_entry != NULL &&
1382 active_entry->site_instance() == GetSiteInstance() &&
1383 active_entry->page_id() == page_id);
1384}
1385
[email protected]b2fe07d12010-02-09 14:38:081386void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161387 set_encoding(encoding);
1388 render_view_host()->SetPageEncoding(encoding);
1389}
1390
[email protected]b2fe07d12010-02-09 14:38:081391void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161392 reset_encoding();
1393 render_view_host()->ResetPageEncodingToDefault();
1394}
1395
1396void TabContents::WindowMoveOrResizeStarted() {
1397 render_view_host()->WindowMoveOrResizeStarted();
1398}
1399
[email protected]3f8eb7f2009-10-02 23:58:051400void TabContents::LogNewTabTime(const std::string& event_name) {
1401 // Not all new tab pages get timed. In those cases, we don't have a
1402 // new_tab_start_time_.
1403 if (new_tab_start_time_.is_null())
1404 return;
1405
1406 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441407 MetricEventDurationDetails details(event_name,
1408 static_cast<int>(duration.InMilliseconds()));
1409
[email protected]7ab1e7d62009-10-14 23:32:011410 if (event_name == "Tab.NewTabScriptStart") {
1411 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1412 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1413 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1414 } else if (event_name == "Tab.NewTabOnload") {
1415 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051416 // The new tab page has finished loading; reset it.
1417 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441418 } else {
1419 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051420 }
[email protected]84abba62009-10-07 17:01:441421 NotificationService::current()->Notify(
1422 NotificationType::METRIC_EVENT_DURATION,
1423 Source<TabContents>(this),
1424 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051425}
1426
[email protected]7ab1e7d62009-10-14 23:32:011427void TabContents::OnCloseStarted() {
1428 if (tab_close_start_time_.is_null())
1429 tab_close_start_time_ = base::TimeTicks::Now();
1430}
1431
[email protected]46624bf2010-06-09 16:04:191432bool TabContents::ShouldAcceptDragAndDrop() const {
1433#if defined(OS_CHROMEOS)
1434 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1435 // See http://crosbug.com/2413
[email protected]be04582b2010-07-26 21:56:561436 return delegate() && !delegate()->IsPopup(this);
[email protected]46624bf2010-06-09 16:04:191437#else
1438 return true;
1439#endif
1440}
1441
[email protected]c37e3b62010-01-22 00:15:171442TabContents* TabContents::CloneAndMakePhantom() {
[email protected]c37e3b62010-01-22 00:15:171443 TabNavigation tab_nav;
[email protected]df72ac72010-02-06 00:43:161444
1445 NavigationEntry* entry = controller().GetActiveEntry();
[email protected]98aa0b52010-05-06 17:03:081446 if (extension_app_)
1447 tab_nav.set_virtual_url(extension_app_->GetFullLaunchURL());
[email protected]df72ac72010-02-06 00:43:161448 else if (entry)
1449 tab_nav.SetFromNavigationEntry(*entry);
1450
[email protected]c37e3b62010-01-22 00:15:171451 std::vector<TabNavigation> navigations;
1452 navigations.push_back(tab_nav);
1453
1454 TabContents* new_contents =
[email protected]6ee12c42010-09-14 09:36:071455 new TabContents(profile(), NULL, MSG_ROUTING_NONE, NULL,
1456 controller_.session_storage_namespace()->Clone());
[email protected]98aa0b52010-05-06 17:03:081457 new_contents->SetExtensionApp(extension_app_);
[email protected]c37e3b62010-01-22 00:15:171458 new_contents->controller().RestoreFromState(navigations, 0, false);
[email protected]c37e3b62010-01-22 00:15:171459
[email protected]98aa0b52010-05-06 17:03:081460 if (!extension_app_ && entry)
[email protected]df72ac72010-02-06 00:43:161461 new_contents->controller().GetActiveEntry()->favicon() = entry->favicon();
1462
[email protected]c37e3b62010-01-22 00:15:171463 return new_contents;
1464}
1465
[email protected]ec0b6c42010-08-26 03:16:581466void TabContents::UpdateHistoryForNavigation(
1467 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1468 if (profile()->IsOffTheRecord())
1469 return;
1470
1471 // Add to history service.
1472 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1473 if (hs)
1474 hs->AddPage(*add_page_args);
1475}
1476
1477void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1478 if (profile()->IsOffTheRecord())
1479 return;
1480
1481 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1482 if (hs)
1483 hs->SetPageTitle(entry.virtual_url(), entry.title());
1484}
1485
[email protected]96d185d2009-04-24 03:28:541486// Notifies the RenderWidgetHost instance about the fact that the page is
1487// loading, or done loading and calls the base implementation.
1488void TabContents::SetIsLoading(bool is_loading,
1489 LoadNotificationDetails* details) {
1490 if (is_loading == is_loading_)
1491 return;
1492
1493 if (!is_loading) {
1494 load_state_ = net::LOAD_STATE_IDLE;
1495 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561496 upload_size_ = 0;
1497 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541498 }
1499
1500 render_manager_.SetIsLoading(is_loading);
1501
1502 is_loading_ = is_loading;
1503 waiting_for_response_ = is_loading;
1504
1505 if (delegate_)
1506 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351507 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541508
1509 NotificationType type = is_loading ? NotificationType::LOAD_START :
1510 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111511 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541512 if (details)
1513 det = Details<LoadNotificationDetails>(details);
1514 NotificationService::current()->Notify(type,
1515 Source<NavigationController>(&controller_),
1516 det);
1517}
1518
[email protected]b6c874582009-05-08 19:38:311519void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291520 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061521 // A page can't spawn popups (or do anything else, either) until its load
1522 // commits, so when we reach here, the popup was spawned by the
1523 // NavigationController's last committed entry, not the active entry. For
1524 // example, if a page opens a popup in an onunload() handler, then the active
1525 // entry is the page to be loaded as we navigate away from the unloading
1526 // page. For this reason, we can't use GetURL() to get the opener URL,
1527 // because it returns the active entry.
1528 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1529 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1530
1531 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491532 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091533 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491534 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1535 } else {
1536 if (!blocked_popups_)
1537 blocked_popups_ = new BlockedPopupContainer(this);
1538 blocked_popups_->AddTabContents(new_contents, initial_pos);
[email protected]55126132010-08-19 14:53:281539 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1540 std::string());
[email protected]be2ee282010-08-31 15:24:171541 if (!is_being_destroyed())
1542 PopupBlockedAnimation::Show(this);
[email protected]8cc8d492010-02-02 10:40:491543 }
[email protected]b9681312008-11-07 00:08:261544}
[email protected]616ed5a2008-11-21 22:27:241545
1546namespace {
1547bool TransitionIsReload(PageTransition::Type transition) {
1548 return PageTransition::StripQualifier(transition) == PageTransition::RELOAD;
1549}
1550}
1551
1552void TabContents::ExpireInfoBars(
1553 const NavigationController::LoadCommittedDetails& details) {
1554 // Only hide InfoBars when the user has done something that makes the main
1555 // frame load. We don't want various automatic or subframe navigations making
1556 // it disappear.
1557 if (!details.is_user_initiated_main_frame_load())
1558 return;
1559
[email protected]f86a07022008-11-25 01:06:051560 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241561 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081562 if (!delegate) {
1563 // If you hit this NOTREACHED, please comment in bug
1564 // http://crbug.com/50428 how you got there.
1565 NOTREACHED();
1566 continue;
1567 }
1568
[email protected]f86a07022008-11-25 01:06:051569 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241570 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241571 }
1572}
[email protected]fdd61c62009-04-22 19:22:571573
[email protected]96d185d2009-04-24 03:28:541574DOMUI* TabContents::GetDOMUIForCurrentState() {
1575 // When there is a pending navigation entry, we want to use the pending DOMUI
1576 // that goes along with it to control the basic flags. For example, we want to
1577 // show the pending URL in the URL bar, so we want the display_url flag to
1578 // be from the pending entry.
1579 //
1580 // The confusion comes because there are multiple possibilities for the
1581 // initial load in a tab as a side effect of the way the RenderViewHostManager
1582 // works.
1583 //
1584 // - For the very first tab the load looks "normal". The new tab DOM UI is
1585 // the pending one, and we want it to apply here.
1586 //
1587 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1588 // get switched to the one previously associated with the new tab pages.
1589 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1590 // have a committed DOM UI in this case.
1591 //
1592 // This condition handles all of these cases:
1593 //
1594 // - First load in first tab: no committed nav entry + pending nav entry +
1595 // pending dom ui:
1596 // -> Use pending DOM UI if any.
1597 //
1598 // - First load in second tab: no committed nav entry + pending nav entry +
1599 // no pending DOM UI:
1600 // -> Use the committed DOM UI if any.
1601 //
1602 // - Second navigation in any tab: committed nav entry + pending nav entry:
1603 // -> Use pending DOM UI if any.
1604 //
1605 // - Normal state with no load: committed nav entry + no pending nav entry:
1606 // -> Use committed DOM UI.
1607 if (controller_.pending_entry() &&
1608 (controller_.GetLastCommittedEntry() ||
1609 render_manager_.pending_dom_ui()))
1610 return render_manager_.pending_dom_ui();
1611 return render_manager_.dom_ui();
1612}
[email protected]420ae012009-04-24 05:16:321613
1614void TabContents::DidNavigateMainFramePostCommit(
1615 const NavigationController::LoadCommittedDetails& details,
1616 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441617 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1618 // If this is a window.open navigation, use the same DOMUI as the renderer
1619 // that opened the window, as long as both renderers have the same
1620 // privileges.
[email protected]583d45c12010-08-31 02:48:121621 if (opener_dom_ui_type_ ==
1622 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441623 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1624 // dom_ui might be NULL if the URL refers to a non-existent extension.
1625 if (dom_ui) {
1626 render_manager_.SetDOMUIPostCommit(dom_ui);
1627 dom_ui->RenderViewCreated(render_view_host());
1628 }
1629 }
1630 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1631 }
1632
[email protected]420ae012009-04-24 05:16:321633 if (details.is_user_initiated_main_frame_load()) {
1634 // Clear the status bubble. This is a workaround for a bug where WebKit
1635 // doesn't let us know that the cursor left an element during a
1636 // transition (this is also why the mouse cursor remains as a hand after
1637 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1638 // clear the bubble when a user navigates to a named anchor in the same
1639 // page.
1640 UpdateTargetURL(details.entry->page_id(), GURL());
1641
1642 // UpdateHelpersForDidNavigate will handle the case where the password_form
1643 // origin is valid.
1644 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1645 // cleaned up and covered by tests.
1646 if (!params.password_form.origin.is_valid())
1647 GetPasswordManager()->DidNavigate();
1648 }
1649
1650 // The keyword generator uses the navigation entries, so must be called after
1651 // the commit.
1652 GenerateKeywordIfNecessary(params);
1653
1654 // Allow the new page to set the title again.
1655 received_page_title_ = false;
1656
1657 // Get the favicon, either from history or request it from the net.
1658 fav_icon_helper_.FetchFavIcon(details.entry->url());
1659
[email protected]0de80162010-02-03 04:52:351660 // Clear all page actions, blocked content notifications and browser actions
1661 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141662 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081663 ExtensionsService* service = profile()->GetExtensionsService();
1664 if (service) {
1665 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571666 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081667 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521668 if (browser_action) {
1669 browser_action->ClearAllValuesForTab(controller().session_id().id());
1670 NotificationService::current()->Notify(
1671 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571672 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521673 NotificationService::NoDetails());
1674 }
[email protected]92c6f9b92009-10-24 04:35:081675
[email protected]5d246db22009-10-27 06:17:571676 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521677 service->extensions()->at(i)->page_action();
1678 if (page_action) {
1679 page_action->ClearAllValuesForTab(controller().session_id().id());
1680 PageActionStateChanged();
1681 }
[email protected]92c6f9b92009-10-24 04:35:081682 }
[email protected]aece2c7f2009-08-27 20:43:171683 }
[email protected]0de80162010-02-03 04:52:351684
1685 // Close blocked popups.
1686 if (blocked_popups_) {
[email protected]0fbd70332010-06-01 19:28:341687 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]0de80162010-02-03 04:52:351688 blocked_popups_->Destroy();
[email protected]da7b5262010-02-25 21:12:461689 blocked_popups_ = NULL;
[email protected]0de80162010-02-03 04:52:351690 }
1691
1692 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411693 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551694 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471695
1696 // Once the main frame is navigated, we're no longer considered to have
1697 // displayed insecure content.
1698 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171699 }
[email protected]ce5c4502009-05-06 16:46:111700
[email protected]8cc8d492010-02-02 10:40:491701 // Close constrained windows if necessary.
1702 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1703 details.previous_url, details.entry->url()))
1704 CloseConstrainedWindows();
1705
[email protected]420ae012009-04-24 05:16:321706 // Update the starred state.
1707 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531708
1709 // Clear the cache of forms in AutoFill.
1710 if (autofill_manager_.get())
1711 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321712}
1713
1714void TabContents::DidNavigateAnyFramePostCommit(
1715 RenderViewHost* render_view_host,
1716 const NavigationController::LoadCommittedDetails& details,
1717 const ViewHostMsg_FrameNavigate_Params& params) {
1718 // If we navigate, start showing messages again. This does nothing to prevent
1719 // a malicious script from spamming messages, since the script could just
1720 // reload the page to stop blocking.
1721 suppress_javascript_messages_ = false;
1722
[email protected]420ae012009-04-24 05:16:321723 // Notify the password manager of the navigation or form submit.
1724 // TODO(brettw) bug 1343111: Password manager stuff in here needs to be
1725 // cleaned up and covered by tests.
1726 if (params.password_form.origin.is_valid())
1727 GetPasswordManager()->ProvisionallySavePassword(params.password_form);
[email protected]3b1c1812010-02-12 21:53:551728
1729 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581730 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321731}
1732
[email protected]8cc8d492010-02-02 10:40:491733void TabContents::CloseConstrainedWindows() {
1734 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321735 // We use indices instead of iterators in case CloseWindow does something
1736 // that may invalidate an iterator.
1737 int size = static_cast<int>(child_windows_.size());
1738 for (int i = size - 1; i >= 0; --i) {
1739 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441740 if (window) {
[email protected]420ae012009-04-24 05:16:321741 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441742 BlockTabContent(false);
1743 }
[email protected]420ae012009-04-24 05:16:321744 }
1745}
1746
1747void TabContents::UpdateStarredStateForCurrentURL() {
1748 BookmarkModel* model = profile()->GetBookmarkModel();
1749 const bool old_state = is_starred_;
1750 is_starred_ = (model && model->IsBookmarked(GetURL()));
1751
1752 if (is_starred_ != old_state && delegate())
1753 delegate()->URLStarredChanged(this, is_starred_);
1754}
1755
1756void TabContents::UpdateAlternateErrorPageURL() {
1757 GURL url = GetAlternateErrorPageURL();
1758 render_view_host()->SetAlternateErrorPageURL(url);
1759}
1760
1761void TabContents::UpdateWebPreferences() {
1762 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1763}
1764
1765void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1766 RenderViewHost* rvh) {
1767 // If we are creating a RVH for a restored controller, then we might
1768 // have more page IDs than the SiteInstance's current max page ID. We must
1769 // make sure that the max page ID is larger than any restored page ID.
1770 // Note that it is ok for conflicting page IDs to exist in another tab
1771 // (i.e., NavigationController), but if any page ID is larger than the max,
1772 // the back/forward list will get confused.
1773 int max_restored_page_id = controller_.max_restored_page_id();
1774 if (max_restored_page_id > 0) {
1775 int curr_max_page_id = site_instance->max_page_id();
1776 if (max_restored_page_id > curr_max_page_id) {
1777 // Need to update the site instance immediately.
1778 site_instance->UpdateMaxPageID(max_restored_page_id);
1779
1780 // Also tell the renderer to update its internal representation. We
1781 // need to reserve enough IDs to make all restored page IDs less than
1782 // the max.
1783 if (curr_max_page_id < 0)
1784 curr_max_page_id = 0;
1785 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1786 }
1787 }
1788}
1789
[email protected]ec0b6c42010-08-26 03:16:581790scoped_refptr<history::HistoryAddPageArgs>
1791TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541792 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471793 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321794 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581795 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1796 new history::HistoryAddPageArgs(
1797 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1798 params.redirects, params.transition, history::SOURCE_BROWSED,
1799 details.did_replace_entry));
1800 if (PageTransition::IsMainFrame(params.transition) &&
1801 virtual_url != params.url) {
1802 // Hack on the "virtual" URL so that it will appear in history. For some
1803 // types of URLs, we will display a magic URL that is different from where
1804 // the page is actually navigated. We want the user to see in history what
1805 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1806 // only applies to the main frame, as the virtual URL doesn't apply to
1807 // sub-frames.
1808 add_page_args->url = virtual_url;
1809 if (!add_page_args->redirects.empty())
1810 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321811 }
[email protected]ec0b6c42010-08-26 03:16:581812 return add_page_args;
[email protected]420ae012009-04-24 05:16:321813}
1814
1815bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1816 const std::wstring& title) {
1817 // For file URLs without a title, use the pathname instead. In the case of a
1818 // synthesized title, we don't want the update to count toward the "one set
1819 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251820 string16 final_title;
[email protected]420ae012009-04-24 05:16:321821 bool explicit_set;
1822 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251823 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321824 explicit_set = false; // Don't count synthetic titles toward the set limit.
1825 } else {
[email protected]e53668962010-06-23 15:35:251826 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321827 explicit_set = true;
1828 }
1829
[email protected]e53668962010-06-23 15:35:251830 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321831 return false; // Nothing changed, don't bother.
1832
[email protected]e53668962010-06-23 15:35:251833 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321834
[email protected]ec0b6c42010-08-26 03:16:581835 if (!received_page_title_) {
1836 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321837 received_page_title_ = explicit_set;
1838 }
1839
1840 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251841 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321842
[email protected]cbc0e1b2010-04-12 18:33:041843 NotificationService::current()->Notify(
1844 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1845 Source<TabContents>(this),
1846 NotificationService::NoDetails());
1847
[email protected]420ae012009-04-24 05:16:321848 return true;
1849}
1850
1851void TabContents::NotifySwapped() {
1852 // After sending out a swap notification, we need to send a disconnect
1853 // notification so that clients that pick up a pointer to |this| can NULL the
1854 // pointer. See Bug 1230284.
1855 notify_disconnection_ = true;
1856 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341857 NotificationType::TAB_CONTENTS_SWAPPED,
[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::NotifyConnected() {
1863 notify_disconnection_ = true;
1864 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341865 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221866 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321867 NotificationService::NoDetails());
1868}
1869
1870void TabContents::NotifyDisconnected() {
1871 if (!notify_disconnection_)
1872 return;
1873
1874 notify_disconnection_ = false;
1875 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341876 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221877 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321878 NotificationService::NoDetails());
1879}
1880
1881void TabContents::GenerateKeywordIfNecessary(
1882 const ViewHostMsg_FrameNavigate_Params& params) {
1883 if (!params.searchable_form_url.is_valid())
1884 return;
1885
1886 if (profile()->IsOffTheRecord())
1887 return;
1888
1889 int last_index = controller_.last_committed_entry_index();
1890 // When there was no previous page, the last index will be 0. This is
1891 // normally due to a form submit that opened in a new tab.
1892 // TODO(brettw) bug 916126: we should support keywords when form submits
1893 // happen in new tabs.
1894 if (last_index <= 0)
1895 return;
1896 const NavigationEntry* previous_entry =
1897 controller_.GetEntryAtIndex(last_index - 1);
1898 if (IsFormSubmit(previous_entry)) {
1899 // Only generate a keyword if the previous page wasn't itself a form
1900 // submit.
1901 return;
1902 }
1903
1904 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1905 previous_entry->user_typed_url() : previous_entry->url();
1906 std::wstring keyword =
1907 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1908 if (keyword.empty())
1909 return;
1910
1911 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1912 if (!url_model)
1913 return;
1914
1915 if (!url_model->loaded()) {
1916 url_model->Load();
1917 return;
1918 }
1919
1920 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191921 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321922 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1923 return;
1924
1925 if (current_url) {
1926 if (current_url->originating_url().is_valid()) {
1927 // The existing keyword was generated from an OpenSearch description
1928 // document, don't regenerate.
1929 return;
1930 }
1931 url_model->Remove(current_url);
1932 }
1933 TemplateURL* new_url = new TemplateURL();
1934 new_url->set_keyword(keyword);
1935 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191936 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321937 new_url->add_input_encoding(params.searchable_form_encoding);
1938 DCHECK(controller_.GetLastCommittedEntry());
1939 const GURL& favicon_url =
1940 controller_.GetLastCommittedEntry()->favicon().url();
1941 if (favicon_url.is_valid()) {
1942 new_url->SetFavIconURL(favicon_url);
1943 } else {
1944 // The favicon url isn't valid. This means there really isn't a favicon,
1945 // or the favicon url wasn't obtained before the load started. This assumes
1946 // the later.
1947 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1948 // its url.
1949 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1950 }
1951 new_url->set_safe_for_autoreplace(true);
1952 url_model->Add(new_url);
1953}
1954
[email protected]bf5c2ff392009-07-08 16:24:331955void TabContents::OnUserGesture() {
1956 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011957 DownloadRequestLimiter* limiter =
1958 g_browser_process->download_request_limiter();
1959 if (limiter)
1960 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261961 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331962}
1963
1964void TabContents::OnFindReply(int request_id,
1965 int number_of_matches,
1966 const gfx::Rect& selection_rect,
1967 int active_match_ordinal,
1968 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421969 // Ignore responses for requests that have been aborted.
1970 if (find_op_aborted_)
1971 return;
1972
[email protected]bf5c2ff392009-07-08 16:24:331973 // Ignore responses for requests other than the one we have most recently
1974 // issued. That way we won't act on stale results when the user has
1975 // already typed in another query.
1976 if (request_id != current_find_request_id_)
1977 return;
1978
1979 if (number_of_matches == -1)
1980 number_of_matches = last_search_result_.number_of_matches();
1981 if (active_match_ordinal == -1)
1982 active_match_ordinal = last_search_result_.active_match_ordinal();
1983
1984 gfx::Rect selection = selection_rect;
1985 if (selection.IsEmpty())
1986 selection = last_search_result_.selection_rect();
1987
1988 // Notify the UI, automation and any other observers that a find result was
1989 // found.
1990 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1991 selection, active_match_ordinal,
1992 final_update);
1993 NotificationService::current()->Notify(
1994 NotificationType::FIND_RESULT_AVAILABLE,
1995 Source<TabContents>(this),
1996 Details<FindNotificationDetails>(&last_search_result_));
1997}
1998
1999void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542000 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2001 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2002 if (!entry)
2003 return;
2004 // Note that we don't call NavigationController::GotToOffset() as we don't
2005 // want to create a pending navigation entry (it might end up lingering
2006 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522007 entry->set_transition_type(entry->transition_type() |
2008 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542009 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2010 }
[email protected]bf5c2ff392009-07-08 16:24:332011}
2012
[email protected]bf5c2ff392009-07-08 16:24:332013void TabContents::OnMissingPluginStatus(int status) {
2014#if defined(OS_WIN)
2015// TODO(PORT): pull in when plug-ins work
2016 GetPluginInstaller()->OnMissingPluginStatus(status);
2017#endif
2018}
2019
2020void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332021 DCHECK(!plugin_path.value().empty());
2022
2023 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]d32d46182009-07-23 00:09:352024#if defined(OS_WIN) || defined(OS_MACOSX)
[email protected]bf5c2ff392009-07-08 16:24:332025 scoped_ptr<FileVersionInfo> version_info(
2026 FileVersionInfo::CreateFileVersionInfo(plugin_path));
2027 if (version_info.get()) {
2028 const std::wstring& product_name = version_info->product_name();
[email protected]996fd702009-09-04 19:12:372029 if (!product_name.empty()) {
[email protected]bf5c2ff392009-07-08 16:24:332030 plugin_name = product_name;
[email protected]996fd702009-09-04 19:12:372031#if defined(OS_MACOSX)
2032 // Many plugins on the Mac have .plugin in the actual name, which looks
2033 // terrible, so look for that and strip it off if present.
2034 const std::wstring plugin_extension(L".plugin");
2035 if (EndsWith(plugin_name, plugin_extension, true))
2036 plugin_name.erase(plugin_name.length() - plugin_extension.length());
2037#endif // OS_MACOSX
2038 }
[email protected]bf5c2ff392009-07-08 16:24:332039 }
[email protected]4a560ed2009-07-13 23:35:262040#else
2041 NOTIMPLEMENTED() << " convert plugin path to plugin name";
2042#endif
[email protected]2ae8a922010-06-28 20:27:532043 SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed(
2044 IDR_INFOBAR_PLUGIN_CRASHED);
[email protected]bf5c2ff392009-07-08 16:24:332045 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582046 this, l10n_util::GetStringFUTF16(IDS_PLUGIN_CRASHED_PROMPT,
2047 WideToUTF16Hack(plugin_name)),
[email protected]2ae8a922010-06-28 20:27:532048 crash_icon, true));
[email protected]bf5c2ff392009-07-08 16:24:332049}
2050
2051void TabContents::OnCrashedWorker() {
2052 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582053 this, l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT),
[email protected]938e1f92010-04-01 18:09:422054 NULL, true));
[email protected]bf5c2ff392009-07-08 16:24:332055}
2056
2057void TabContents::OnDidGetApplicationInfo(
2058 int32 page_id,
2059 const webkit_glue::WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512060 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332061
[email protected]ed5431872009-11-17 08:39:512062 if (delegate())
2063 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332064}
2065
[email protected]851b1eb2010-08-09 13:32:292066void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2067 const GURL& update_url) {
2068 new DisabledPluginInfoBar(this, name, update_url);
2069}
2070
[email protected]a2cf65eb2010-01-18 08:20:382071void TabContents::OnPageContents(const GURL& url,
2072 int renderer_process_id,
2073 int32 page_id,
[email protected]e5106202010-06-11 21:12:362074 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102075 const std::string& language,
2076 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382077 // Don't index any https pages. People generally don't want their bank
2078 // accounts, etc. indexed on their computer, especially since some of these
2079 // things are not marked cachable.
2080 // TODO(brettw) we may want to consider more elaborate heuristics such as
2081 // the cachability of the page. We may also want to consider subframes (this
2082 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272083 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2084 // content indexing for chromeos in some future releases.
2085#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382086 if (!url.SchemeIsSecure()) {
2087 Profile* p = profile();
2088 if (p && !p->IsOffTheRecord()) {
2089 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2090 if (hs)
2091 hs->SetPageContents(url, contents);
2092 }
2093 }
[email protected]ccd40a52010-05-11 16:15:272094#endif
[email protected]a8a81292010-01-21 00:32:452095
[email protected]1c57b7b2010-07-12 17:38:102096 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452097
2098 std::string lang = language;
2099 NotificationService::current()->Notify(
2100 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152101 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452102 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382103}
2104
[email protected]7e0831b2010-02-01 08:45:152105void TabContents::OnPageTranslated(int32 page_id,
2106 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162107 const std::string& translated_lang,
2108 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552109 language_state_.set_current_language(translated_lang);
2110 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162111 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152112 NotificationService::current()->Notify(
2113 NotificationType::PAGE_TRANSLATED,
2114 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162115 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152116}
2117
[email protected]15d9c0c2010-09-10 22:36:262118void TabContents::OnSetSuggestResult(int32 page_id, const std::string& result) {
2119 if (delegate())
2120 delegate()->OnSetSuggestResult(page_id, result);
2121}
2122
[email protected]bf5c2ff392009-07-08 16:24:332123void TabContents::DidStartProvisionalLoadForFrame(
2124 RenderViewHost* render_view_host,
2125 bool is_main_frame,
2126 const GURL& url) {
2127 ProvisionalLoadDetails details(is_main_frame,
2128 controller_.IsURLInPageNavigation(url),
2129 url, std::string(), false);
2130 NotificationService::current()->Notify(
2131 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2132 Source<NavigationController>(&controller_),
2133 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142134 if (is_main_frame) {
[email protected]da4f8a12010-08-19 08:33:412135 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142136 content_settings_delegate_->ClearGeolocationContentSettings();
2137 }
[email protected]bf5c2ff392009-07-08 16:24:332138}
2139
2140void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202141 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332142 NotificationService::current()->Notify(
2143 NotificationType::RESOURCE_RESPONSE_STARTED,
2144 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202145 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332146}
2147
[email protected]3dbb80b2010-02-09 22:41:202148void TabContents::DidRedirectResource(
2149 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332150 NotificationService::current()->Notify(
2151 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2152 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202153 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332154}
2155
2156void TabContents::DidLoadResourceFromMemoryCache(
2157 const GURL& url,
2158 const std::string& frame_origin,
2159 const std::string& main_frame_origin,
2160 const std::string& security_info) {
2161 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442162 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332163 SSLManager::DeserializeSecurityInfo(security_info,
2164 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042165 &security_bits,
2166 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332167 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162168 GetRenderProcessHost()->id(), cert_id,
2169 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332170
2171 NotificationService::current()->Notify(
2172 NotificationType::LOAD_FROM_MEMORY_CACHE,
2173 Source<NavigationController>(&controller_),
2174 Details<LoadFromMemoryCacheDetails>(&details));
2175}
2176
[email protected]e3d60e5d2009-09-25 21:08:292177void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472178 displayed_insecure_content_ = true;
2179 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292180}
2181
2182void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592183 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292184}
2185
[email protected]bf5c2ff392009-07-08 16:24:332186void TabContents::DidFailProvisionalLoadWithError(
2187 RenderViewHost* render_view_host,
2188 bool is_main_frame,
2189 int error_code,
2190 const GURL& url,
2191 bool showing_repost_interstitial) {
2192 if (net::ERR_ABORTED == error_code) {
2193 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2194 // This means that the interstitial won't be torn down properly, which is
2195 // bad. But if we have an interstitial, go back to another tab type, and
2196 // then load the same interstitial again, we could end up getting the first
2197 // interstitial's "failed" message (as a result of the cancel) when we're on
2198 // the second one.
2199 //
2200 // We can't tell this apart, so we think we're tearing down the current page
2201 // which will cause a crash later one. There is also some code in
2202 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2203 // out because of this problem.
2204 //
2205 // http://code.google.com/p/chromium/issues/detail?id=2855
2206 // Because this will not tear down the interstitial properly, if "back" is
2207 // back to another tab type, the interstitial will still be somewhat alive
2208 // in the previous tab type. If you navigate somewhere that activates the
2209 // tab with the interstitial again, you'll see a flash before the new load
2210 // commits of the interstitial page.
2211 if (showing_interstitial_page()) {
2212 LOG(WARNING) << "Discarding message during interstitial.";
2213 return;
2214 }
2215
2216 // This will discard our pending entry if we cancelled the load (e.g., if we
2217 // decided to download the file instead of load it). Only discard the
2218 // pending entry if the URLs match, otherwise the user initiated a navigate
2219 // before the page loaded so that the discard would discard the wrong entry.
2220 NavigationEntry* pending_entry = controller_.pending_entry();
2221 if (pending_entry && pending_entry->url() == url) {
2222 controller_.DiscardNonCommittedEntries();
2223 // Update the URL display.
2224 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2225 }
2226
2227 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2228 }
2229
2230 // Send out a notification that we failed a provisional load with an error.
2231 ProvisionalLoadDetails details(is_main_frame,
2232 controller_.IsURLInPageNavigation(url),
2233 url, std::string(), false);
2234 details.set_error_code(error_code);
2235
2236 NotificationService::current()->Notify(
2237 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2238 Source<NavigationController>(&controller_),
2239 Details<ProvisionalLoadDetails>(&details));
2240}
2241
2242void TabContents::DocumentLoadedInFrame() {
2243 controller_.DocumentLoadedInFrame();
2244}
2245
[email protected]dcd5b332010-08-11 08:55:182246void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562247 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242248 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562249}
2250
[email protected]8d3347f2009-07-09 22:00:212251RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322252 return view_.get();
2253}
2254
[email protected]8d3347f2009-07-09 22:00:212255RenderViewHostDelegate::RendererManagement*
2256TabContents::GetRendererManagementDelegate() {
2257 return &render_manager_;
2258}
2259
[email protected]bf5c2ff392009-07-08 16:24:332260RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212261 TabContents::GetBrowserIntegrationDelegate() {
2262 return this;
[email protected]bf5c2ff392009-07-08 16:24:332263}
2264
[email protected]8d3347f2009-07-09 22:00:212265RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2266 return this;
[email protected]bf5c2ff392009-07-08 16:24:332267}
2268
[email protected]46ba9082010-06-22 10:00:582269RenderViewHostDelegate::ContentSettings*
2270TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552271 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582272}
2273
[email protected]8d3347f2009-07-09 22:00:212274RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322275 return save_package_.get(); // May be NULL, but we can return NULL.
2276}
2277
[email protected]8d3347f2009-07-09 22:00:212278RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092279 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212280}
2281
2282RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2283 return &fav_icon_helper_;
2284}
2285
[email protected]e8dbd674b2010-03-11 18:34:402286RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452287 if (autocomplete_history_manager_.get() == NULL)
2288 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2289 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332290}
2291
[email protected]21674df2009-10-28 19:51:212292RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342293 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212294}
2295
[email protected]aad51d1c2010-08-05 08:38:092296RenderViewHostDelegate::BlockedPlugin* TabContents::GetBlockedPluginDelegate() {
2297 if (blocked_plugin_manager_.get() == NULL)
2298 blocked_plugin_manager_.reset(new BlockedPluginManager(this));
2299 return blocked_plugin_manager_.get();
2300}
2301
[email protected]1f18184a2010-07-21 19:34:492302RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2303 return GetSSLHelper();
2304}
2305
[email protected]b5977a0c2010-08-24 19:46:262306RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2307 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492308 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262309 return file_select_helper_.get();
2310}
2311
[email protected]fd571bb2010-03-19 01:23:542312AutomationResourceRoutingDelegate*
2313TabContents::GetAutomationResourceRoutingDelegate() {
2314 return delegate();
2315}
2316
[email protected]ced90ae12010-02-20 02:06:162317RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2318 return bookmark_drag_;
2319}
2320
2321void TabContents::SetBookmarkDragDelegate(
2322 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2323 bookmark_drag_ = bookmark_drag;
2324}
2325
[email protected]9fb83e82010-07-02 18:24:552326TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2327 return content_settings_delegate_.get();
2328}
2329
[email protected]93623c5d2009-12-10 21:40:322330RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462331 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512332}
2333
[email protected]57c6a652009-05-04 07:58:342334TabContents* TabContents::GetAsTabContents() {
2335 return this;
2336}
2337
[email protected]7b291f92009-08-14 05:43:532338ViewType::Type TabContents::GetRenderViewType() const {
2339 return ViewType::TAB_CONTENTS;
2340}
2341
2342int TabContents::GetBrowserWindowID() const {
2343 return controller().window_id().id();
2344}
2345
[email protected]420ae012009-04-24 05:16:322346void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062347 NotificationService::current()->Notify(
2348 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2349 Source<TabContents>(this),
2350 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322351 NavigationEntry* entry = controller_.GetActiveEntry();
2352 if (!entry)
2353 return;
2354
2355 // When we're creating views, we're still doing initial setup, so we always
2356 // use the pending DOM UI rather than any possibly existing committed one.
2357 if (render_manager_.pending_dom_ui()) {
2358 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2359 }
2360
2361 if (entry->IsViewSourceMode()) {
2362 // Put the renderer in view source mode.
2363 render_view_host->Send(
2364 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2365 }
[email protected]0666aef2009-05-13 19:48:082366
2367 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322368}
2369
2370void TabContents::RenderViewReady(RenderViewHost* rvh) {
2371 if (rvh != render_view_host()) {
2372 // Don't notify the world, since this came from a renderer in the
2373 // background.
2374 return;
2375 }
2376
2377 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302378 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322379 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302380
2381 // Restore the focus to the tab (otherwise the focus will be on the top
2382 // window).
2383 if (was_crashed && !FocusLocationBarByDefault())
2384 Focus();
[email protected]420ae012009-04-24 05:16:322385}
2386
2387void TabContents::RenderViewGone(RenderViewHost* rvh) {
2388 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092389 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322390 return;
2391 if (rvh != render_view_host()) {
2392 // The pending page's RenderViewHost is gone.
2393 return;
2394 }
2395
2396 SetIsLoading(false, NULL);
2397 NotifyDisconnected();
2398 SetIsCrashed(true);
2399
[email protected]ff9efc62010-02-18 22:10:542400 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212401 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542402 RemoveInfoBar(GetInfoBarDelegateAt(i));
2403
[email protected]8e537302009-06-10 21:19:582404 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552405 // Only do this if we're not in browser shutdown, so that TabContents
2406 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2407 // visible do not flash a sad tab page.
2408 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2409 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322410
2411 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002412 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322413}
2414
[email protected]2e4633c2009-07-09 16:58:062415void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2416 NotificationService::current()->Notify(
2417 NotificationType::RENDER_VIEW_HOST_DELETED,
2418 Source<TabContents>(this),
2419 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482420 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062421}
2422
[email protected]420ae012009-04-24 05:16:322423void TabContents::DidNavigate(RenderViewHost* rvh,
2424 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372425 int extra_invalidate_flags = 0;
2426
2427 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352428 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372429
[email protected]420ae012009-04-24 05:16:322430 render_manager_.DidNavigateMainFrame(rvh);
2431
[email protected]20ede072009-10-06 00:28:352432 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372433 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372434 }
2435
[email protected]420ae012009-04-24 05:16:322436 // Update the site of the SiteInstance if it doesn't have one yet.
2437 if (!GetSiteInstance()->has_site())
2438 GetSiteInstance()->SetSite(params.url);
2439
2440 // Need to update MIME type here because it's referred to in
2441 // UpdateNavigationCommands() called by RendererDidNavigate() to
2442 // determine whether or not to enable the encoding menu.
2443 // It's updated only for the main frame. For a subframe,
2444 // RenderView::UpdateURL does not set params.contents_mime_type.
2445 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2446 // TODO(jungshik): Add a test for the encoding menu to avoid
2447 // regressing it again.
2448 if (PageTransition::IsMainFrame(params.transition))
2449 contents_mime_type_ = params.contents_mime_type;
2450
2451 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372452 bool did_navigate = controller_.RendererDidNavigate(
2453 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392454
2455 // Update history. Note that this needs to happen after the entry is complete,
2456 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582457 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392458 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582459 // URLs, we use a data: URL as the real value. We actually want to save the
2460 // about: URL to the history db and keep the data: URL hidden. This is what
2461 // the TabContents' URL getter does.
2462 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2463 CreateHistoryAddPageArgs(GetURL(), details, params));
2464 if (!delegate() ||
2465 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2466 details.type)) {
2467 UpdateHistoryForNavigation(add_page_args);
2468 }
[email protected]3e90d4a2009-07-03 17:38:392469 }
2470
[email protected]76543b92009-08-31 17:27:452471 if (!did_navigate)
2472 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322473
2474 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2475 // for the appropriate notification (best) or you can add it to
2476 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2477 // necessary, please).
2478
2479 // Run post-commit tasks.
2480 if (details.is_main_frame)
2481 DidNavigateMainFramePostCommit(details, params);
2482 DidNavigateAnyFramePostCommit(rvh, details, params);
2483}
2484
2485void TabContents::UpdateState(RenderViewHost* rvh,
2486 int32 page_id,
2487 const std::string& state) {
2488 DCHECK(rvh == render_view_host());
2489
2490 // We must be prepared to handle state updates for any page, these occur
2491 // when the user is scrolling and entering form data, as well as when we're
2492 // leaving a page, in which case our state may have already been moved to
2493 // the next page. The navigation controller will look up the appropriate
2494 // NavigationEntry and update it when it is notified via the delegate.
2495
2496 int entry_index = controller_.GetEntryIndexWithPageID(
2497 GetSiteInstance(), page_id);
2498 if (entry_index < 0)
2499 return;
2500 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2501
2502 if (state == entry->content_state())
2503 return; // Nothing to update.
2504 entry->set_content_state(state);
2505 controller_.NotifyEntryChanged(entry, entry_index);
2506}
2507
2508void TabContents::UpdateTitle(RenderViewHost* rvh,
2509 int32 page_id, const std::wstring& title) {
2510 // If we have a title, that's a pretty good indication that we've started
2511 // getting useful data.
2512 SetNotWaitingForResponse();
2513
2514 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482515 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582516 page_id);
[email protected]420ae012009-04-24 05:16:322517 if (!entry || !UpdateTitleForEntry(entry, title))
2518 return;
2519
2520 // Broadcast notifications when the UI should be updated.
2521 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032522 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322523}
2524
[email protected]420ae012009-04-24 05:16:322525void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402526 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322527 set_encoding(encoding);
2528}
2529
2530void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2531 if (delegate())
2532 delegate()->UpdateTargetURL(this, url);
2533}
2534
2535void TabContents::UpdateThumbnail(const GURL& url,
2536 const SkBitmap& bitmap,
2537 const ThumbnailScore& score) {
2538 // Tell History about this thumbnail
[email protected]9ba208092010-08-10 20:02:082539 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kNoTopSites)) {
[email protected]72d0fc72009-07-09 17:30:492540 if (!profile()->IsOffTheRecord())
[email protected]523623c2010-05-19 16:03:422541 profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282542 } else {
2543 HistoryService* hs;
2544 if (!profile()->IsOffTheRecord() &&
2545 (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) {
2546 hs->SetPageThumbnail(url, bitmap, score);
2547 }
[email protected]420ae012009-04-24 05:16:322548 }
2549}
2550
[email protected]c4e98902010-06-01 10:20:142551void TabContents::UpdateInspectorSetting(const std::string& key,
2552 const std::string& value) {
2553 DictionaryValue* inspector_settings =
2554 profile()->GetPrefs()->GetMutableDictionary(
2555 prefs::kWebKitInspectorSettings);
[email protected]8b6e84a2010-08-14 03:32:172556 inspector_settings->SetWithoutPathExpansion(key,
[email protected]628cf5a52010-06-07 14:25:332557 Value::CreateStringValue(value));
[email protected]0df30122009-06-03 12:13:082558}
2559
[email protected]45aafc92010-06-07 14:18:532560void TabContents::ClearInspectorSettings() {
2561 DictionaryValue* inspector_settings =
2562 profile()->GetPrefs()->GetMutableDictionary(
2563 prefs::kWebKitInspectorSettings);
2564 inspector_settings->Clear();
2565}
2566
[email protected]420ae012009-04-24 05:16:322567void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292568 // The UI may be in an event-tracking loop, such as between the
2569 // mouse-down and mouse-up in text selection or a button click.
2570 // Defer the close until after tracking is complete, so that we
2571 // don't free objects out from under the UI.
2572 // TODO(shess): This could probably be integrated with the
2573 // IsDoingDrag() test below. Punting for now because I need more
2574 // research to understand how this impacts platforms other than Mac.
2575 // TODO(shess): This could get more fine-grained. For instance,
2576 // closing a tab in another window while selecting text in the
2577 // current window's Omnibox should be just fine.
2578 if (view()->IsEventTracking()) {
2579 view()->CloseTabAfterEventTracking();
2580 return;
2581 }
2582
[email protected]24a4d1062009-07-10 23:10:422583 // If we close the tab while we're in the middle of a drag, we'll crash.
2584 // Instead, cancel the drag and close it as soon as the drag ends.
2585 if (view()->IsDoingDrag()) {
2586 view()->CancelDragAndCloseTab();
2587 return;
2588 }
2589
[email protected]420ae012009-04-24 05:16:322590 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2591 if (delegate() && rvh == render_view_host())
2592 delegate()->CloseContents(this);
2593}
2594
2595void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2596 if (delegate() && delegate()->IsPopup(this))
2597 delegate()->MoveContents(this, new_bounds);
2598}
2599
[email protected]7ab1e7d62009-10-14 23:32:012600void TabContents::DidStartLoading() {
[email protected]ebf40a72010-07-22 01:46:382601 // By default, we assume that the content is not PDF. The renderer
2602 // will tell us if this is not the case.
2603 displaying_pdf_content_ = false;
[email protected]420ae012009-04-24 05:16:322604 SetIsLoading(true, NULL);
2605}
2606
[email protected]7ab1e7d62009-10-14 23:32:012607void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322608 scoped_ptr<LoadNotificationDetails> details;
2609
2610 NavigationEntry* entry = controller_.GetActiveEntry();
2611 // An entry may not exist for a stop when loading an initial blank page or
2612 // if an iframe injected by script into a blank page finishes loading.
2613 if (entry) {
[email protected]420ae012009-04-24 05:16:322614 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2615
2616 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542617 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322618 entry->transition_type(),
2619 elapsed,
2620 &controller_,
2621 controller_.GetCurrentEntryIndex()));
2622 }
2623
2624 // Tell PasswordManager we've finished a page load, which serves as a
2625 // green light to save pending passwords and reset itself.
2626 GetPasswordManager()->DidStopLoading();
2627
2628 SetIsLoading(false, details.get());
2629}
2630
[email protected]25497492010-09-11 15:15:082631void TabContents::DocumentOnLoadCompletedInMainFrame(
2632 RenderViewHost* render_view_host,
2633 int32 page_id) {
2634 NotificationService::current()->Notify(
2635 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2636 Source<TabContents>(this),
2637 Details<int>(&page_id));
2638}
2639
[email protected]420ae012009-04-24 05:16:322640void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2641 const GURL& source_url,
2642 const GURL& target_url) {
2643 NavigationEntry* entry;
2644 if (page_id == -1)
2645 entry = controller_.pending_entry();
2646 else
2647 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2648 if (!entry || entry->url() != source_url)
2649 return;
2650 entry->set_url(target_url);
2651}
2652
[email protected]420ae012009-04-24 05:16:322653void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2654 WindowOpenDisposition disposition) {
2655 if (render_manager_.dom_ui()) {
2656 // When we're a DOM UI, it will provide a page transition type for us (this
2657 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2658 // generated suggestions).
2659 //
2660 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162661 // want web sites to see a referrer of "chrome://blah" (and some
2662 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322663 // send to the site), so we send no referrer.
2664 OpenURL(url, GURL(), disposition,
2665 render_manager_.dom_ui()->link_transition_type());
2666 } else {
2667 OpenURL(url, referrer, disposition, PageTransition::LINK);
2668 }
2669}
2670
[email protected]1ee614862009-07-06 20:29:182671void TabContents::DomOperationResponse(const std::string& json_string,
2672 int automation_id) {
2673}
2674
[email protected]8b8e7c92010-08-19 18:05:562675void TabContents::ProcessDOMUIMessage(
2676 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322677 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442678 // This can happen if someone uses window.open() to open an extension URL
2679 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562680 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322681 return;
2682 }
[email protected]8b8e7c92010-08-19 18:05:562683 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322684}
2685
2686void TabContents::ProcessExternalHostMessage(const std::string& message,
2687 const std::string& origin,
2688 const std::string& target) {
2689 if (delegate())
2690 delegate()->ForwardMessageToExternalHost(message, origin, target);
2691}
2692
[email protected]420ae012009-04-24 05:16:322693void TabContents::RunJavaScriptMessage(
2694 const std::wstring& message,
2695 const std::wstring& default_prompt,
2696 const GURL& frame_url,
2697 const int flags,
2698 IPC::Message* reply_msg,
2699 bool* did_suppress_message) {
2700 // Suppress javascript messages when requested and when inside a constrained
2701 // popup window (because that activates them and breaks them out of the
2702 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552703 // Also suppress messages when showing an interstitial. The interstitial is
2704 // shown over the previous page, we don't want the hidden page dialogs to
2705 // interfere with the interstitial.
2706 bool suppress_this_message = suppress_javascript_messages_ ||
2707 showing_interstitial_page();
[email protected]420ae012009-04-24 05:16:322708 if (delegate())
2709 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312710 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322711
2712 *did_suppress_message = suppress_this_message;
2713
2714 if (!suppress_this_message) {
2715 base::TimeDelta time_since_last_message(
2716 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2717 bool show_suppress_checkbox = false;
2718 // Show a checkbox offering to suppress further messages if this message is
2719 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2720 if (time_since_last_message <
2721 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2722 show_suppress_checkbox = true;
2723
[email protected]d6ad7442010-09-05 19:06:522724 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2725 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322726 } else {
2727 // If we are suppressing messages, just reply as is if the user immediately
2728 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542729 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322730 }
2731}
2732
2733void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2734 IPC::Message* reply_msg) {
[email protected]7ab1e7d62009-10-14 23:32:012735 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222736 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322737}
2738
2739void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2740 const std::string& json_arguments,
2741 IPC::Message* reply_msg) {
2742 if (delegate()) {
2743 HtmlDialogUIDelegate* dialog_delegate =
2744 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222745 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322746 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2747 }
2748}
2749
[email protected]4d44a1c2010-04-28 19:20:412750void TabContents::PasswordFormsFound(
[email protected]ed3fb032009-06-16 19:50:562751 const std::vector<webkit_glue::PasswordForm>& forms) {
[email protected]4d44a1c2010-04-28 19:20:412752 GetPasswordManager()->PasswordFormsFound(forms);
2753}
2754
2755void TabContents::PasswordFormsVisible(
2756 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2757 GetPasswordManager()->PasswordFormsVisible(visible_forms);
[email protected]420ae012009-04-24 05:16:322758}
2759
[email protected]420ae012009-04-24 05:16:322760// Checks to see if we should generate a keyword based on the OSDD, and if
2761// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
2762void TabContents::PageHasOSDD(RenderViewHost* render_view_host,
2763 int32 page_id, const GURL& url,
2764 bool autodetected) {
2765 // Make sure page_id is the current page, and the TemplateURLModel is loaded.
2766 DCHECK(url.is_valid());
2767 if (!IsActiveEntry(page_id))
2768 return;
2769 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
2770 if (!url_model)
2771 return;
2772 if (!url_model->loaded()) {
2773 url_model->Load();
2774 return;
2775 }
2776 if (!profile()->GetTemplateURLFetcher())
2777 return;
2778
2779 if (profile()->IsOffTheRecord())
2780 return;
2781
2782 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2783 DCHECK(entry);
2784
2785 const NavigationEntry* base_entry = entry;
2786 if (IsFormSubmit(base_entry)) {
2787 // If the current page is a form submit, find the last page that was not
2788 // a form submit and use its url to generate the keyword from.
2789 int index = controller_.last_committed_entry_index() - 1;
2790 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2791 index--;
2792 if (index >= 0)
2793 base_entry = controller_.GetEntryAtIndex(index);
2794 else
2795 base_entry = NULL;
2796 }
2797
2798 // We want to use the user typed URL if available since that represents what
2799 // the user typed to get here, and fall back on the regular URL if not.
2800 if (!base_entry)
2801 return;
2802 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2803 base_entry->user_typed_url() : base_entry->url();
2804 if (!keyword_url.is_valid())
2805 return;
2806 std::wstring keyword = TemplateURLModel::GenerateKeyword(keyword_url,
2807 autodetected);
[email protected]a88dbdd52010-01-15 19:25:532808
2809 // For JS added OSDD empty keyword is OK because we will generate keyword
2810 // later from OSDD content.
2811 if (autodetected && keyword.empty())
[email protected]420ae012009-04-24 05:16:322812 return;
2813 const TemplateURL* template_url =
2814 url_model->GetTemplateURLForKeyword(keyword);
2815 if (template_url && (!template_url->safe_for_autoreplace() ||
2816 template_url->originating_url() == url)) {
2817 // Either there is a user created TemplateURL for this keyword, or the
2818 // keyword has the same OSDD url and we've parsed it.
2819 return;
2820 }
2821
2822 // Download the OpenSearch description document. If this is successful a
2823 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322824 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2825 keyword,
2826 url,
2827 base_entry->favicon().url(),
[email protected]d0cc9fb52009-06-23 02:26:162828 this,
[email protected]420ae012009-04-24 05:16:322829 autodetected);
2830}
2831
[email protected]420ae012009-04-24 05:16:322832GURL TabContents::GetAlternateErrorPageURL() const {
2833 GURL url;
2834 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2835 if (profile()->IsOffTheRecord())
2836 return url;
2837
2838 PrefService* prefs = profile()->GetPrefs();
2839 DCHECK(prefs);
2840 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152841 url = google_util::AppendGoogleLocaleParam(
2842 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322843 url = google_util::AppendGoogleTLDParam(url);
2844 }
2845 return url;
2846}
2847
2848WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062849 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552850 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082851 WebPreferences web_prefs =
2852 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2853
2854 // Force accelerated compositing off for chrome: and chrome-extension:
2855 // pages.
2856 if (GetURL().SchemeIs(chrome::kChromeUIScheme) ||
2857 GetURL().SchemeIs(chrome::kExtensionScheme)) {
2858 web_prefs.accelerated_compositing_enabled = false;
2859 }
2860
[email protected]39553442010-09-09 00:01:552861#if defined(OS_MACOSX)
2862 // Disable accelerated compositing if IOSurface's are not supported,
2863 // as is the case in 10.5.
2864 if (!IOSurfaceSupport::Initialize())
2865 web_prefs.accelerated_compositing_enabled = false;
2866#endif
2867
[email protected]447021c2010-09-08 21:29:082868 return web_prefs;
[email protected]420ae012009-04-24 05:16:322869}
2870
[email protected]fa1cf0b82010-01-15 21:49:442871void TabContents::OnIgnoredUIEvent() {
2872 if (constrained_window_count()) {
2873 ConstrainedWindow* window = *constrained_window_begin();
2874 window->FocusConstrainedWindow();
2875 }
2876}
2877
[email protected]420ae012009-04-24 05:16:322878void TabContents::OnJSOutOfMemory() {
2879 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582880 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2881 NULL, true));
[email protected]420ae012009-04-24 05:16:322882}
2883
[email protected]420ae012009-04-24 05:16:322884void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2885 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342886 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322887 // delivered to a pending RenderViewHost. We must first run the onunload
2888 // handler of the old RenderViewHost before we can allow it to proceed.
2889 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2890 new_request_id);
2891}
2892
[email protected]420ae012009-04-24 05:16:322893gfx::Rect TabContents::GetRootWindowResizerRect() const {
2894 if (delegate())
2895 return delegate()->GetRootWindowResizerRect();
2896 return gfx::Rect();
2897}
2898
2899void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2900 bool is_during_unload) {
2901 if (is_during_unload) {
2902 // Hang occurred while firing the beforeunload/unload handler.
2903 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112904 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322905
2906 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2907 return;
2908
2909 // If the tab hangs in the beforeunload/unload handler there's really
2910 // nothing we can do to recover. Pretend the unload listeners have
2911 // all fired and close the tab. If the hang is in the beforeunload handler
2912 // then the user will not have the option of cancelling the close.
2913 Close(rvh);
2914 return;
2915 }
2916
2917 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002918 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322919}
2920
2921void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002922 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322923}
2924
2925void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562926 net::LoadState load_state,
2927 uint64 upload_position,
2928 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322929 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562930 upload_position_ = upload_position;
2931 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292932 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192933 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292934 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:532935 load_state_host_ =
2936 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:322937 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2938 SetNotWaitingForResponse();
2939 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502940 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322941}
2942
[email protected]1ee614862009-07-06 20:29:182943bool TabContents::IsExternalTabContainer() const {
2944 if (!delegate())
2945 return false;
2946
2947 return delegate()->IsExternalTabContainer();
2948}
2949
[email protected]1ee614862009-07-06 20:29:182950void TabContents::DidInsertCSS() {
2951 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322952}
2953
[email protected]130efb02009-09-18 18:54:352954void TabContents::FocusedNodeChanged() {
2955 NotificationService::current()->Notify(
2956 NotificationType::FOCUS_CHANGED_IN_PAGE,
2957 Source<RenderViewHost>(render_view_host()),
2958 NotificationService::NoDetails());
2959}
2960
[email protected]ebf40a72010-07-22 01:46:382961void TabContents::SetDisplayingPDFContent() {
2962 displaying_pdf_content_ = true;
2963 if (delegate())
2964 delegate()->ContentTypeChanged(this);
2965}
2966
[email protected]420ae012009-04-24 05:16:322967void TabContents::BeforeUnloadFiredFromRenderManager(
2968 bool proceed,
2969 bool* proceed_to_fire_unload) {
2970 if (delegate())
2971 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2972}
2973
[email protected]3a3d47472010-07-15 21:03:542974void TabContents::DidStartLoadingFromRenderManager(
2975 RenderViewHost* render_view_host) {
2976 DidStartLoading();
2977}
2978
2979void TabContents::RenderViewGoneFromRenderManager(
2980 RenderViewHost* render_view_host) {
2981 RenderViewGone(render_view_host);
2982}
2983
[email protected]420ae012009-04-24 05:16:322984void TabContents::UpdateRenderViewSizeForRenderManager() {
2985 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262986 gfx::Size size = view_->GetContainerSize();
2987 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2988 // here during container initialization and normal window size will be set
2989 // later. In case of tab duplication this resizing to 0x0 prevents setting
2990 // normal size later so just ignore it.
2991 if (!size.IsEmpty())
2992 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322993}
2994
[email protected]3a3d47472010-07-15 21:03:542995void TabContents::NotifySwappedFromRenderManager() {
2996 NotifySwapped();
2997}
2998
2999NavigationController& TabContents::GetControllerForRenderManager() {
3000 return controller();
3001}
3002
[email protected]420ae012009-04-24 05:16:323003DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223004 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323005}
3006
3007NavigationEntry*
3008TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3009 return controller_.GetLastCommittedEntry();
3010}
3011
3012bool TabContents::CreateRenderViewForRenderManager(
3013 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323014 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523015
[email protected]674b3822010-08-04 04:02:513016 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323017 return false;
3018
3019 // Now that the RenderView has been created, we need to tell it its size.
3020 rwh_view->SetSize(view_->GetContainerSize());
3021
3022 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3023 render_view_host);
3024 return true;
3025}
3026
3027void TabContents::Observe(NotificationType type,
3028 const NotificationSource& source,
3029 const NotificationDetails& details) {
3030 switch (type.value) {
3031 case NotificationType::BOOKMARK_MODEL_LOADED:
3032 // BookmarkModel finished loading, fall through to update starred state.
3033 case NotificationType::URLS_STARRED: {
3034 // Somewhere, a URL has been starred.
3035 // Ignore notifications for profiles other than our current one.
3036 Profile* source_profile = Source<Profile>(source).ptr();
3037 if (!source_profile || !source_profile->IsSameProfile(profile()))
3038 return;
3039
3040 UpdateStarredStateForCurrentURL();
3041 break;
3042 }
3043 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513044 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323045 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3046 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3047 UpdateAlternateErrorPageURL();
3048 } else if (*pref_name_in == prefs::kDefaultCharset ||
[email protected]57ecc4b2010-08-11 03:02:513049 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)
[email protected]420ae012009-04-24 05:16:323050 ) {
3051 UpdateWebPreferences();
3052 } else {
3053 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3054 }
3055 break;
3056 }
3057 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3058 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3059 break;
3060
3061 case NotificationType::NAV_ENTRY_COMMITTED: {
3062 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3063
3064 NavigationController::LoadCommittedDetails& committed_details =
3065 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3066 ExpireInfoBars(committed_details);
3067 break;
3068 }
3069
[email protected]d3ba77272009-09-03 00:06:093070#if defined(OS_LINUX)
3071 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543072 renderer_preferences_util::UpdateFromSystemSettings(
3073 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093074 render_view_host()->SyncRendererPrefs();
3075 break;
3076 }
3077#endif
3078
[email protected]6c32ce72010-03-08 05:18:063079 case NotificationType::USER_STYLE_SHEET_UPDATED:
3080 UpdateWebPreferences();
3081 break;
3082
[email protected]79580c62010-02-02 02:36:253083 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]0314ae02010-04-08 09:18:293084 Details<const HostContentSettingsMap::ContentSettingsDetails>
[email protected]79580c62010-02-02 02:36:253085 settings_details(details);
[email protected]79580c62010-02-02 02:36:253086 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493087 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293088 if (entry)
[email protected]da0c8e92010-02-09 23:25:493089 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293090 if (settings_details.ptr()->update_all() ||
3091 settings_details.ptr()->pattern().Matches(entry_url)) {
3092 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233093 profile()->GetHostContentSettingsMap()->
3094 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253095 }
3096 break;
3097 }
3098
[email protected]e5adff72010-06-14 18:13:063099 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573100 break;
[email protected]a888b29e62010-04-01 13:38:573101
3102 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063103 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573104 break;
[email protected]a888b29e62010-04-01 13:38:573105
[email protected]420ae012009-04-24 05:16:323106 default:
3107 NOTREACHED();
3108 }
3109}
[email protected]aacd7cc2009-09-02 14:51:103110
[email protected]98aa0b52010-05-06 17:03:083111void TabContents::UpdateExtensionAppIcon(Extension* extension) {
3112 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433113
[email protected]a888b29e62010-04-01 13:38:573114 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083115 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3116 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573117 extension,
[email protected]807871f2010-09-16 01:04:483118 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3119 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573120 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3121 Extension::EXTENSION_ICON_SMALLISH),
3122 ImageLoadingTracker::CACHE);
3123 } else {
[email protected]98aa0b52010-05-06 17:03:083124 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573125 }
3126}
3127
3128Extension* TabContents::GetExtensionContaining(const GURL& url) {
3129 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3130 if (!extensions_service)
3131 return NULL;
3132
3133 Extension* extension = extensions_service->GetExtensionByURL(url);
3134 return extension ?
3135 extension : extensions_service->GetExtensionByWebExtent(url);
3136}
3137
[email protected]a888b29e62010-04-01 13:38:573138void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3139 int index) {
3140 if (image) {
[email protected]98aa0b52010-05-06 17:03:083141 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573142 NotifyNavigationStateChanged(INVALIDATE_TAB);
3143 }
3144}
3145
[email protected]beb440c2009-11-06 04:08:543146gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3147 return view_->GetTopLevelNativeWindow();
3148}
3149
3150void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3151 bool success,
3152 const std::wstring& prompt) {
3153 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3154 if (is_showing_before_unload_dialog_ && !success) {
3155 // If a beforeunload dialog is canceled, we need to stop the throbber from
3156 // spinning, since we forced it to start spinning in Navigate.
3157 DidStopLoading();
3158
3159 tab_close_start_time_ = base::TimeTicks();
3160 }
3161 is_showing_before_unload_dialog_ = false;
3162 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3163}
3164
3165void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3166 set_suppress_javascript_messages(suppress_message_boxes);
3167}
3168
[email protected]3a3d47472010-07-15 21:03:543169TabContents* TabContents::AsTabContents() {
3170 return this;
3171}
3172
3173ExtensionHost* TabContents::AsExtensionHost() {
3174 return NULL;
3175}
3176
[email protected]41fc0322009-09-04 22:23:403177void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103178 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3179}
[email protected]f45d2a72010-03-08 23:28:353180
3181void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3182 app_icon_ = app_icon;
3183 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3184}
[email protected]ea68c06a2010-04-23 17:25:373185
3186// After a successful *new* login attempt, we take the PasswordFormManager in
3187// provisional_save_manager_ and move it to a SavePasswordInfoBarDelegate while
3188// the user makes up their mind with the "save password" infobar. Note if the
3189// login is one we already know about, the end of the line is
3190// provisional_save_manager_ because we just update it on success and so such
3191// forms never end up in an infobar.
3192class SavePasswordInfoBarDelegate : public ConfirmInfoBarDelegate {
3193 public:
3194 SavePasswordInfoBarDelegate(TabContents* tab_contents,
[email protected]12bb6822010-06-16 02:00:463195 PasswordFormManager* form_to_save)
3196 : ConfirmInfoBarDelegate(tab_contents),
3197 form_to_save_(form_to_save),
[email protected]d75aba1d2010-08-02 23:35:583198 infobar_response_(NO_RESPONSE) {}
[email protected]ea68c06a2010-04-23 17:25:373199
[email protected]d75aba1d2010-08-02 23:35:583200 virtual ~SavePasswordInfoBarDelegate() {}
[email protected]ea68c06a2010-04-23 17:25:373201
[email protected]d75aba1d2010-08-02 23:35:583202 // Begin ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373203 virtual void InfoBarClosed() {
[email protected]12bb6822010-06-16 02:00:463204 UMA_HISTOGRAM_ENUMERATION("PasswordManager.InfoBarResponse",
[email protected]d75aba1d2010-08-02 23:35:583205 infobar_response_, NUM_RESPONSE_TYPES);
[email protected]ea68c06a2010-04-23 17:25:373206 delete this;
3207 }
3208
[email protected]d75aba1d2010-08-02 23:35:583209 virtual Type GetInfoBarType() { return PAGE_ACTION_TYPE; }
3210
[email protected]e23d3a32010-08-13 19:39:583211 virtual string16 GetMessageText() const {
3212 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_PASSWORD_PROMPT);
[email protected]ea68c06a2010-04-23 17:25:373213 }
3214
3215 virtual SkBitmap* GetIcon() const {
3216 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
3217 IDR_INFOBAR_SAVE_PASSWORD);
3218 }
3219
3220 virtual int GetButtons() const {
3221 return BUTTON_OK | BUTTON_CANCEL;
3222 }
3223
[email protected]e23d3a32010-08-13 19:39:583224 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]ea68c06a2010-04-23 17:25:373225 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:583226 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_SAVE_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373227 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:583228 return l10n_util::GetStringUTF16(IDS_PASSWORD_MANAGER_BLACKLIST_BUTTON);
[email protected]ea68c06a2010-04-23 17:25:373229 NOTREACHED();
[email protected]e23d3a32010-08-13 19:39:583230 return string16();
[email protected]ea68c06a2010-04-23 17:25:373231 }
3232
3233 virtual bool Accept() {
3234 DCHECK(form_to_save_.get());
3235 form_to_save_->Save();
[email protected]d75aba1d2010-08-02 23:35:583236 infobar_response_ = REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373237 return true;
3238 }
3239
3240 virtual bool Cancel() {
3241 DCHECK(form_to_save_.get());
3242 form_to_save_->PermanentlyBlacklist();
[email protected]d75aba1d2010-08-02 23:35:583243 infobar_response_ = DONT_REMEMBER_PASSWORD;
[email protected]ea68c06a2010-04-23 17:25:373244 return true;
3245 }
[email protected]d75aba1d2010-08-02 23:35:583246 // End ConfirmInfoBarDelegate implementation.
[email protected]ea68c06a2010-04-23 17:25:373247
3248 private:
3249 // The PasswordFormManager managing the form we're asking the user about,
3250 // and should update as per her decision.
3251 scoped_ptr<PasswordFormManager> form_to_save_;
3252
[email protected]12bb6822010-06-16 02:00:463253 // Used to track the results we get from the info bar.
3254 enum ResponseType {
[email protected]d75aba1d2010-08-02 23:35:583255 NO_RESPONSE = 0,
3256 REMEMBER_PASSWORD,
3257 DONT_REMEMBER_PASSWORD,
3258 NUM_RESPONSE_TYPES,
[email protected]12bb6822010-06-16 02:00:463259 };
3260 ResponseType infobar_response_;
3261
[email protected]ea68c06a2010-04-23 17:25:373262 DISALLOW_COPY_AND_ASSIGN(SavePasswordInfoBarDelegate);
3263};
3264
3265void TabContents::FillPasswordForm(
[email protected]e768baf2010-07-16 19:36:163266 const webkit_glue::PasswordFormFillData& form_data) {
[email protected]ea68c06a2010-04-23 17:25:373267 render_view_host()->FillPasswordForm(form_data);
3268}
3269
3270void TabContents::AddSavePasswordInfoBar(PasswordFormManager* form_to_save) {
3271 AddInfoBar(new SavePasswordInfoBarDelegate(this, form_to_save));
3272}
3273
3274Profile* TabContents::GetProfileForPasswordManager() {
3275 return profile();
3276}
3277
3278bool TabContents::DidLastPageLoadEncounterSSLErrors() {
3279 return controller().ssl_manager()->ProcessedSSLErrorFromRequest();
3280}