blob: 3b4a48b9c5093da89a749307637249f365050236 [file] [log] [blame]
[email protected]7e7414ae2010-01-26 20:19:291// Copyright (c) 2010 The Chromium Authors. All rights reserved.
license.botbf09a502008-08-24 00:55:552// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
initial.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/tab_contents.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]a92b8642009-05-05 23:38:569#include "app/l10n_util.h"
[email protected]9929da92009-05-05 02:05:1110#include "app/resource_bundle.h"
[email protected]39553442010-09-09 00:01:5511#if defined(OS_MACOSX)
12#include "app/surface/io_surface_support_mac.h"
13#endif
[email protected]614519812010-03-19 08:20:5614#include "app/text_elider.h"
[email protected]8cc8d492010-02-02 10:40:4915#include "base/auto_reset.h"
[email protected]420ae012009-04-24 05:16:3216#include "base/file_version_info.h"
[email protected]7cf1b6ce2010-03-20 06:37:0117#include "base/i18n/rtl.h"
[email protected]835d7c82010-10-14 04:38:3818#include "base/metrics/histogram.h"
[email protected]420ae012009-04-24 05:16:3219#include "base/process_util.h"
[email protected]96d185d2009-04-24 03:28:5420#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3721#include "base/string_util.h"
[email protected]440b37b22010-08-30 05:31:4022#include "base/utf_string_conversions.h"
[email protected]96d185d2009-04-24 03:28:5423#include "base/time.h"
[email protected]6db0def92010-03-02 19:55:4524#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2125#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4026#include "chrome/browser/blocked_content_container.h"
[email protected]420ae012009-04-24 05:16:3227#include "chrome/browser/bookmarks/bookmark_model.h"
[email protected]96d185d2009-04-24 03:28:5428#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5529#include "chrome/browser/browser_shutdown.h"
initial.commit09911bf2008-07-26 23:55:2930#include "chrome/browser/cert_store.h"
[email protected]aacd7cc2009-09-02 14:51:1031#include "chrome/browser/character_encoding.h"
[email protected]5f24f212010-12-02 14:47:4532#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3333#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5434#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1435#include "chrome/browser/defaults.h"
[email protected]420ae012009-04-24 05:16:3236#include "chrome/browser/dom_operation_notification_details.h"
[email protected]96d185d2009-04-24 03:28:5437#include "chrome/browser/dom_ui/dom_ui.h"
38#include "chrome/browser/dom_ui/dom_ui_factory.h"
[email protected]bcef0dc02009-02-28 00:35:0239#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3240#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0141#include "chrome/browser/download/download_request_limiter.h"
[email protected]e7eaedde2009-09-25 20:09:4942#include "chrome/browser/external_protocol_handler.h"
[email protected]92c6f9b92009-10-24 04:35:0843#include "chrome/browser/extensions/extensions_service.h"
[email protected]ec0b6c42010-08-26 03:16:5844#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4245#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2546#include "chrome/browser/host_zoom_map.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]f7578f52010-08-30 22:22:4949#include "chrome/browser/google/google_util.h"
[email protected]8897c382009-05-06 17:53:2650#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0751#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3252#include "chrome/browser/load_from_memory_cache_details.h"
53#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4454#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]ea0e80892009-08-22 00:36:0555#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1056#include "chrome/browser/omnibox_search_hint.h"
[email protected]14a000d2010-04-29 21:44:2457#include "chrome/browser/platform_util.h"
[email protected]fdd61c62009-04-22 19:22:5758#include "chrome/browser/plugin_installer.h"
[email protected]37858e52010-08-26 00:22:0259#include "chrome/browser/prefs/pref_service.h"
[email protected]dbeebd52010-11-16 20:34:1660#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0961#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3362#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0763#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1664#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5465#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3766#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0767#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5468#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3269#include "chrome/browser/renderer_preferences_util.h"
[email protected]8b62334b2010-08-31 22:37:1170#include "chrome/browser/search_engines/template_url.h"
[email protected]152b8ba32010-03-29 19:40:1671#include "chrome/browser/search_engines/template_url_fetcher.h"
[email protected]0b5b85c2010-10-11 23:00:1272#include "chrome/browser/search_engines/template_url_fetcher_ui_callbacks.h"
[email protected]152b8ba32010-03-29 19:40:1673#include "chrome/browser/search_engines/template_url_model.h"
[email protected]c37e3b62010-01-22 00:15:1774#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1775#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5476#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1677#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4378#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1679#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]1f18184a2010-07-21 19:34:4980#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5781#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]3c9e1872010-11-18 16:17:4982#include "chrome/browser/tab_contents/web_navigation_observer.h"
[email protected]152b8ba32010-03-29 19:40:1683#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3584#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]45300ad42010-12-02 15:51:1485#include "chrome/browser/ui/find_bar/find_bar_state.h"
[email protected]54ec6472010-04-09 19:39:5886#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2787#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2188#include "chrome/common/content_restriction.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]b75b8292010-10-01 07:28:25111#include "third_party/WebKit/WebKit/chromium/public/WebView.h"
[email protected]1ee614862009-07-06 20:29:18112#include "webkit/glue/webpreferences.h"
[email protected]d5e311b2010-07-20 17:15:03113#include "webkit/glue/password_form.h"
[email protected]45446a52010-11-04 17:41:00114#include "webkit/glue/plugins/plugin_list.h"
[email protected]3e45ba92009-02-20 21:09:00115
[email protected]420ae012009-04-24 05:16:32116// Cross-Site Navigations
117//
118// If a TabContents is told to navigate to a different web site (as determined
119// by SiteInstance), it will replace its current RenderViewHost with a new
120// RenderViewHost dedicated to the new SiteInstance. This works as follows:
121//
122// - Navigate determines whether the destination is cross-site, and if so,
123// it creates a pending_render_view_host_ and moves into the PENDING
124// RendererState.
125// - The pending RVH is "suspended," so that no navigation messages are sent to
126// its renderer until the onbeforeunload JavaScript handler has a chance to
127// run in the current RVH.
128// - The pending RVH tells CrossSiteRequestManager (a thread-safe singleton)
129// that it has a pending cross-site request. ResourceDispatcherHost will
130// check for this when the response arrives.
131// - The current RVH runs its onbeforeunload handler. If it returns false, we
132// cancel all the pending logic and go back to NORMAL. Otherwise we allow
133// the pending RVH to send the navigation request to its renderer.
134// - ResourceDispatcherHost receives a ResourceRequest on the IO thread. It
135// checks CrossSiteRequestManager to see that the RVH responsible has a
136// pending cross-site request, and then installs a CrossSiteEventHandler.
137// - When RDH receives a response, the BufferedEventHandler determines whether
138// it is a download. If so, it sends a message to the new renderer causing
139// it to cancel the request, and the download proceeds in the download
140// thread. For now, we stay in a PENDING state (with a pending RVH) until
[email protected]57c6a652009-05-04 07:58:34141// the next DidNavigate event for this TabContents. This isn't ideal, but it
[email protected]420ae012009-04-24 05:16:32142// doesn't affect any functionality.
143// - After RDH receives a response and determines that it is safe and not a
144// download, it pauses the response to first run the old page's onunload
145// handler. It does this by asynchronously calling the OnCrossSiteResponse
[email protected]57c6a652009-05-04 07:58:34146// method of TabContents on the UI thread, which sends a ClosePage message
[email protected]420ae012009-04-24 05:16:32147// to the current RVH.
148// - Once the onunload handler is finished, a ClosePage_ACK message is sent to
149// the ResourceDispatcherHost, who unpauses the response. Data is then sent
150// to the pending RVH.
151// - The pending renderer sends a FrameNavigate message that invokes the
152// DidNavigate method. This replaces the current RVH with the
153// pending RVH and goes back to the NORMAL RendererState.
154
155namespace {
156
157// Amount of time we wait between when a key event is received and the renderer
158// is queried for its state and pushed to the NavigationEntry.
159const int kQueryStateDelay = 5000;
160
[email protected]6ebdc9b2010-09-27 16:55:57161const int kSyncWaitDelay = 40;
162
[email protected]420ae012009-04-24 05:16:32163// If another javascript message box is displayed within
164// kJavascriptMessageExpectedDelay of a previous javascript message box being
165// dismissed, display an option to suppress future message boxes from this
166// contents.
167const int kJavascriptMessageExpectedDelay = 1000;
168
[email protected]420ae012009-04-24 05:16:32169// The list of prefs we want to observe.
[email protected]57ecc4b2010-08-11 03:02:51170const char* kPrefsToObserve[] = {
[email protected]420ae012009-04-24 05:16:32171 prefs::kAlternateErrorPagesEnabled,
[email protected]d0b8d092010-10-25 04:05:17172 prefs::kDefaultZoomLevel,
[email protected]420ae012009-04-24 05:16:32173 prefs::kWebKitJavaEnabled,
174 prefs::kWebKitJavascriptEnabled,
175 prefs::kWebKitLoadsImagesAutomatically,
176 prefs::kWebKitPluginsEnabled,
177 prefs::kWebKitUsesUniversalDetector,
178 prefs::kWebKitSerifFontFamily,
179 prefs::kWebKitSansSerifFontFamily,
180 prefs::kWebKitFixedFontFamily,
181 prefs::kWebKitDefaultFontSize,
182 prefs::kWebKitDefaultFixedFontSize,
[email protected]6bdf05b2010-10-13 20:34:13183 prefs::kWebKitMinimumFontSize,
184 prefs::kWebKitMinimumLogicalFontSize,
[email protected]1661a3c02010-05-20 16:32:36185 prefs::kWebkitTabsToLinks,
[email protected]420ae012009-04-24 05:16:32186 prefs::kDefaultCharset
187 // kWebKitStandardFontIsSerif needs to be added
188 // if we let users pick which font to use, serif or sans-serif when
189 // no font is specified or a CSS generic family (serif or sans-serif)
190 // is not specified.
191};
192
193const int kPrefsToObserveLength = arraysize(kPrefsToObserve);
194
[email protected]420ae012009-04-24 05:16:32195// Returns true if the entry's transition type is FORM_SUBMIT.
196bool IsFormSubmit(const NavigationEntry* entry) {
197 return (PageTransition::StripQualifier(entry->transition_type()) ==
198 PageTransition::FORM_SUBMIT);
199}
200
201#if defined(OS_WIN)
202
203BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
204 // Note: erase is required to properly paint some widgets borders. This can
205 // be seen with textfields.
206 InvalidateRect(hwnd, NULL, TRUE);
207 return TRUE;
208}
209#endif
210
[email protected]5e369672009-11-03 23:48:30211ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16212 Profile* profile, const NavigationEntry& entry,
213 NavigationController::ReloadType reload_type) {
214 switch (reload_type) {
215 case NavigationController::RELOAD:
216 return ViewMsg_Navigate_Params::RELOAD;
217 case NavigationController::RELOAD_IGNORING_CACHE:
218 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
219 case NavigationController::NO_RELOAD:
220 break; // Fall through to rest of function.
221 }
[email protected]5e369672009-11-03 23:48:30222
223 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
224 profile->DidLastSessionExitCleanly())
225 return ViewMsg_Navigate_Params::RESTORE;
226
227 return ViewMsg_Navigate_Params::NORMAL;
228}
229
[email protected]876bc832010-09-07 16:29:54230void MakeNavigateParams(const NavigationEntry& entry,
231 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16232 NavigationController::ReloadType reload_type,
233 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34234 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54235 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00236 params->current_history_list_offset = controller.last_committed_entry_index();
237 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34238 params->url = entry.url();
239 params->referrer = entry.referrer();
240 params->transition = entry.transition_type();
241 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00242 params->navigation_type =
243 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34244 params->request_time = base::Time::Now();
245}
246
[email protected]851b1eb2010-08-09 13:32:29247class DisabledPluginInfoBar : public ConfirmInfoBarDelegate {
248 public:
249 DisabledPluginInfoBar(TabContents* tab_contents,
250 const string16& name,
251 const GURL& update_url)
252 : ConfirmInfoBarDelegate(tab_contents),
253 tab_contents_(tab_contents),
254 name_(name),
255 update_url_(update_url) {
256 tab_contents->AddInfoBar(this);
257 }
258
259 virtual int GetButtons() const {
260 return BUTTON_OK | BUTTON_CANCEL | BUTTON_OK_DEFAULT;
261 }
262
[email protected]e23d3a32010-08-13 19:39:58263 virtual string16 GetButtonLabel(InfoBarButton button) const {
[email protected]851b1eb2010-08-09 13:32:29264 if (button == BUTTON_CANCEL)
[email protected]e23d3a32010-08-13 19:39:58265 return l10n_util::GetStringUTF16(IDS_PLUGIN_ENABLE_TEMPORARILY);
[email protected]851b1eb2010-08-09 13:32:29266 if (button == BUTTON_OK)
[email protected]e23d3a32010-08-13 19:39:58267 return l10n_util::GetStringUTF16(IDS_PLUGIN_UPDATE);
[email protected]851b1eb2010-08-09 13:32:29268 return ConfirmInfoBarDelegate::GetButtonLabel(button);
269 }
270
[email protected]e23d3a32010-08-13 19:39:58271 virtual string16 GetMessageText() const {
272 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_);
[email protected]851b1eb2010-08-09 13:32:29273 }
274
[email protected]e23d3a32010-08-13 19:39:58275 virtual string16 GetLinkText() {
276 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
[email protected]851b1eb2010-08-09 13:32:29277 }
278
279 virtual SkBitmap* GetIcon() const {
280 return ResourceBundle::GetSharedInstance().GetBitmapNamed(
281 IDR_INFOBAR_PLUGIN_INSTALL);
282 }
283
284 virtual bool Accept() {
285 tab_contents_->OpenURL(update_url_, GURL(),
[email protected]57b66d02010-09-30 11:24:51286 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29287 return false;
288 }
289
290 virtual bool Cancel() {
291 tab_contents_->OpenURL(GURL(chrome::kChromeUIPluginsURL), GURL(),
[email protected]57b66d02010-09-30 11:24:51292 NEW_FOREGROUND_TAB, PageTransition::LINK);
[email protected]851b1eb2010-08-09 13:32:29293 return false;
294 }
295
296 virtual bool LinkClicked(WindowOpenDisposition disposition) {
297 // TODO(bauerb): Navigate to a help page explaining why we disabled
298 // the plugin, once we have one.
299 return false;
300 }
301
302 private:
303 TabContents* tab_contents_;
304 string16 name_;
305 GURL update_url_;
306};
307
[email protected]420ae012009-04-24 05:16:32308} // namespace
309
310// -----------------------------------------------------------------------------
311
[email protected]fdd61c62009-04-22 19:22:57312// static
313int TabContents::find_request_id_counter_ = -1;
314
[email protected]420ae012009-04-24 05:16:32315
[email protected]420ae012009-04-24 05:16:32316TabContents::TabContents(Profile* profile,
317 SiteInstance* site_instance,
318 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07319 const TabContents* base_tab_contents,
320 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42321 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07322 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
323 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13324 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22325 TabContentsView::Create(this))),
326 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]fdd61c62009-04-22 19:22:57327 property_bag_(),
328 registrar_(),
[email protected]12802702010-07-09 19:43:09329 ALLOW_THIS_IN_INITIALIZER_LIST(printing_(
330 new printing::PrintViewManager(*this))),
[email protected]fdd61c62009-04-22 19:22:57331 save_package_(),
[email protected]6db0def92010-03-02 19:55:45332 autocomplete_history_manager_(),
[email protected]21674df2009-10-28 19:51:21333 autofill_manager_(),
[email protected]fdd61c62009-04-22 19:22:57334 plugin_installer_(),
[email protected]6f821dd2010-02-23 00:54:06335 bookmark_drag_(NULL),
[email protected]d82ed61e2009-06-16 02:46:22336 ALLOW_THIS_IN_INITIALIZER_LIST(fav_icon_helper_(this)),
[email protected]d5f942ba2008-09-26 19:30:34337 is_loading_(false),
initial.commit09911bf2008-07-26 23:55:29338 is_crashed_(false),
[email protected]d5f942ba2008-09-26 19:30:34339 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34340 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57341 current_load_start_(),
342 load_state_(net::LOAD_STATE_IDLE),
343 load_state_host_(),
[email protected]094e5b22009-09-25 04:23:56344 upload_size_(0),
345 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57346 received_page_title_(false),
347 is_starred_(false),
348 contents_mime_type_(),
349 encoding_(),
[email protected]c65e2f152010-10-14 15:30:40350 blocked_contents_(NULL),
351 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49352 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47353 displayed_insecure_content_(false),
[email protected]fdd61c62009-04-22 19:22:57354 infobar_delegates_(),
[email protected]fdd61c62009-04-22 19:22:57355 find_ui_active_(false),
356 find_op_aborted_(false),
357 current_find_request_id_(find_request_id_counter_++),
[email protected]e491f1c2009-05-22 20:28:12358 last_search_case_sensitive_(false),
[email protected]e491f1c2009-05-22 20:28:12359 last_search_result_(),
[email protected]98aa0b52010-05-06 17:03:08360 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57361 capturing_contents_(false),
362 is_being_destroyed_(false),
363 notify_disconnection_(false),
364 history_requests_(),
365#if defined(OS_WIN)
366 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
367#endif
368 last_javascript_message_dismissal_(),
[email protected]c2e74fe82009-09-03 17:57:44369 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01370 is_showing_before_unload_dialog_(false),
[email protected]7ff431e2010-01-07 18:18:54371 renderer_preferences_(),
[email protected]1a242c32010-02-02 21:20:54372 opener_dom_ui_type_(DOMUIFactory::kNoDOMUI),
[email protected]777a7b62010-05-11 13:28:16373 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38374 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25375 minimum_zoom_percent_(
376 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
377 maximum_zoom_percent_(
378 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00379 temporary_zoom_settings_(false),
380 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54381 renderer_preferences_util::UpdateFromSystemSettings(
382 &renderer_preferences_, profile);
383
[email protected]9fb83e82010-07-02 18:24:55384 content_settings_delegate_.reset(
385 new TabSpecificContentSettings(this, profile));
386
[email protected]12636df2009-09-28 22:32:21387 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32388
[email protected]34ac70502009-09-25 17:07:23389 // We have the initial size of the view be based on the size of the passed in
390 // tab contents (normally a tab from the same window).
391 view_->CreateView(base_tab_contents ?
392 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32393
394 // Register for notifications about all interested prefs change.
395 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28396 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32397 if (prefs) {
398 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28399 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32400 }
401
402 // Register for notifications about URL starredness changing on any profile.
403 registrar_.Add(this, NotificationType::URLS_STARRED,
404 NotificationService::AllSources());
405 registrar_.Add(this, NotificationType::BOOKMARK_MODEL_LOADED,
406 NotificationService::AllSources());
407 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
408 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09409#if defined(OS_LINUX)
410 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
411 NotificationService::AllSources());
412#endif
[email protected]420ae012009-04-24 05:16:32413
[email protected]6c32ce72010-03-08 05:18:06414 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
415 NotificationService::AllSources());
416
[email protected]79580c62010-02-02 02:36:25417 // Register for notifications about content setting changes.
418 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
419 NotificationService::AllSources());
420
[email protected]a888b29e62010-04-01 13:38:57421 // Listen for extension changes so we can update extension_for_current_page_.
422 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
423 NotificationService::AllSources());
424 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
425 NotificationService::AllSources());
426 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED_DISABLED,
427 NotificationService::AllSources());
428
[email protected]88152052010-10-01 04:05:18429 // Listen for Google URL changes
430 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
431 NotificationService::AllSources());
432
[email protected]c8865482009-07-23 20:40:10433 // Set-up the showing of the omnibox search infobar if applicable.
434 if (OmniboxSearchHint::IsEnabled(profile))
435 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]332af7732009-03-11 13:21:35436}
initial.commit09911bf2008-07-26 23:55:29437
438TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32439 is_being_destroyed_ = true;
440
[email protected]bfe4c1582009-10-02 18:11:09441 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32442 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28443 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32444
[email protected]420ae012009-04-24 05:16:32445 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00446 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32447
[email protected]420ae012009-04-24 05:16:32448 // First cleanly close all child windows.
449 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
450 // some of these to close. CloseWindows is async, so it might get called
451 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49452 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32453
[email protected]c65e2f152010-10-14 15:30:40454 // Close all blocked contents.
455 if (blocked_contents_)
456 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13457
[email protected]420ae012009-04-24 05:16:32458 // Notify any observer that have a reference on this tab contents.
459 NotificationService::current()->Notify(
460 NotificationType::TAB_CONTENTS_DESTROYED,
461 Source<TabContents>(this),
462 NotificationService::NoDetails());
463
[email protected]1e5e74f2009-05-27 20:55:12464 // Notify any lasting InfobarDelegates that have not yet been removed that
465 // whatever infobar they were handling in this TabContents has closed,
466 // because the TabContents is going away entirely.
467 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
468 // notification may trigger infobars calls that access their delegate. (and
469 // some implementations of InfoBarDelegate do delete themselves on
470 // InfoBarClosed()).
471 for (int i = 0; i < infobar_delegate_count(); ++i) {
472 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
473 delegate->InfoBarClosed();
474 }
475 infobar_delegates_.clear();
476
[email protected]420ae012009-04-24 05:16:32477 // TODO(brettw) this should be moved to the view.
478#if defined(OS_WIN)
479 // If we still have a window handle, destroy it. GetNativeView can return
480 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42481 if (GetNativeView()) {
482 RenderViewHost* host = render_view_host();
483 if (host && host->view()) {
484 host->view()->WillWmDestroy();
485 }
[email protected]420ae012009-04-24 05:16:32486 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42487 }
[email protected]420ae012009-04-24 05:16:32488#endif
[email protected]7ab1e7d62009-10-14 23:32:01489
490 // OnCloseStarted isn't called in unit tests.
491 if (!tab_close_start_time_.is_null()) {
492 UMA_HISTOGRAM_TIMES("Tab.Close",
493 base::TimeTicks::Now() - tab_close_start_time_);
494 }
initial.commit09911bf2008-07-26 23:55:29495}
496
[email protected]d5f942ba2008-09-26 19:30:34497// static
498void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32499 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
500
501 WebPreferences pref_defaults;
502 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
503 pref_defaults.javascript_enabled);
504 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
505 pref_defaults.web_security_enabled);
506 prefs->RegisterBooleanPref(
507 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
508 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
509 pref_defaults.loads_images_automatically);
510 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
511 pref_defaults.plugins_enabled);
512 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
513 pref_defaults.dom_paste_enabled);
514 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
515 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14516 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32517 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
518 pref_defaults.text_areas_are_resizable);
519 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
520 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36521 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
522 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32523
524 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
525 IDS_ACCEPT_LANGUAGES);
526 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
527 IDS_DEFAULT_ENCODING);
528 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
529 IDS_STANDARD_FONT_IS_SERIF);
530 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
531 IDS_FIXED_FONT_FAMILY);
532 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
533 IDS_SERIF_FONT_FAMILY);
534 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
535 IDS_SANS_SERIF_FONT_FAMILY);
536 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
537 IDS_CURSIVE_FONT_FAMILY);
538 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
539 IDS_FANTASY_FONT_FAMILY);
540 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
541 IDS_DEFAULT_FONT_SIZE);
542 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
543 IDS_DEFAULT_FIXED_FONT_SIZE);
544 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
545 IDS_MINIMUM_FONT_SIZE);
546 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
547 IDS_MINIMUM_LOGICAL_FONT_SIZE);
548 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
549 IDS_USES_UNIVERSAL_DETECTOR);
550 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
551 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29552}
553
[email protected]13367f72009-07-08 16:39:02554// Returns true if contains content rendered by an extension.
555bool TabContents::HostsExtension() const {
556 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34557}
558
[email protected]cf28ec52010-04-09 22:56:34559AutoFillManager* TabContents::GetAutoFillManager() {
560 if (autofill_manager_.get() == NULL)
561 autofill_manager_.reset(new AutoFillManager(this));
562 return autofill_manager_.get();
563}
564
[email protected]6e95706d2009-04-23 22:55:01565PluginInstaller* TabContents::GetPluginInstaller() {
566 if (plugin_installer_.get() == NULL)
567 plugin_installer_.reset(new PluginInstaller(this));
568 return plugin_installer_.get();
569}
570
[email protected]1f18184a2010-07-21 19:34:49571TabContentsSSLHelper* TabContents::GetSSLHelper() {
572 if (ssl_helper_.get() == NULL)
573 ssl_helper_.reset(new TabContentsSSLHelper(this));
574 return ssl_helper_.get();
575}
576
[email protected]8cb5d5b2010-02-09 11:36:16577RenderProcessHost* TabContents::GetRenderProcessHost() const {
578 return render_manager_.current_host()->process();
579}
580
[email protected]9adb9692010-10-29 23:14:02581void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46582 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08583 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10584
[email protected]98aa0b52010-05-06 17:03:08585 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57586
[email protected]fca656c2010-02-10 20:30:10587 NotificationService::current()->Notify(
588 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
589 Source<TabContents>(this),
590 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49591}
592
[email protected]98aa0b52010-05-06 17:03:08593void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
594 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40595 return;
596
597 ExtensionsService* extension_service = profile()->GetExtensionsService();
[email protected]fa6a9102010-11-22 15:38:50598 if (!extension_service || !extension_service->is_ready())
599 return;
600
601 const Extension* extension =
602 extension_service->GetExtensionById(extension_app_id, false);
603 if (extension)
604 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40605}
606
[email protected]98aa0b52010-05-06 17:03:08607SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08608 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51609 return NULL;
610
[email protected]98aa0b52010-05-06 17:03:08611 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51612}
613
[email protected]d5f942ba2008-09-26 19:30:34614const GURL& TabContents::GetURL() const {
615 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57616 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54617 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34618}
619
[email protected]96d185d2009-04-24 03:28:54620const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55621 // Transient entries take precedence. They are used for interstitial pages
622 // that are shown on top of existing pages.
623 NavigationEntry* entry = controller_.GetTransientEntry();
624 if (entry)
625 return entry->GetTitleForDisplay(&controller_);
626
[email protected]96d185d2009-04-24 03:28:54627 DOMUI* our_dom_ui = render_manager_.pending_dom_ui() ?
628 render_manager_.pending_dom_ui() : render_manager_.dom_ui();
629 if (our_dom_ui) {
630 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55631 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54632 if (!(entry && entry->IsViewSourceMode())) {
633 // Give the DOM UI the chance to override our title.
634 const string16& title = our_dom_ui->overridden_title();
635 if (!title.empty())
636 return title;
637 }
638 }
639
640 // We use the title for the last committed entry rather than a pending
641 // navigation entry. For example, when the user types in a URL, we want to
642 // keep the old page's title until the new load has committed and we get a new
643 // title.
[email protected]96d185d2009-04-24 03:28:54644 entry = controller_.GetLastCommittedEntry();
645 if (entry)
646 return entry->GetTitleForDisplay(&controller_);
[email protected]96d185d2009-04-24 03:28:54647 return EmptyString16();
648}
649
[email protected]bbbc1ef2010-02-12 18:03:41650// static
651string16 TabContents::GetDefaultTitle() {
652 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
653}
654
[email protected]d5f942ba2008-09-26 19:30:34655int32 TabContents::GetMaxPageID() {
656 if (GetSiteInstance())
657 return GetSiteInstance()->max_page_id();
658 else
659 return max_page_id_;
660}
661
662void TabContents::UpdateMaxPageID(int32 page_id) {
663 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34664 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34665 // testing.
666 if (GetSiteInstance())
667 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16668 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34669}
670
[email protected]96d185d2009-04-24 03:28:54671SiteInstance* TabContents::GetSiteInstance() const {
672 return render_manager_.current_host()->site_instance();
673}
674
[email protected]96d185d2009-04-24 03:28:54675bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15676 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54677 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15678 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01679 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54680 return true;
[email protected]8ab24cc2009-11-13 20:56:15681 }
[email protected]83e3895b2009-06-11 00:07:16682
[email protected]96d185d2009-04-24 03:28:54683 DOMUI* dom_ui = GetDOMUIForCurrentState();
684 if (dom_ui)
685 return !dom_ui->should_hide_url();
686 return true;
687}
688
[email protected]d5f942ba2008-09-26 19:30:34689SkBitmap TabContents::GetFavIcon() const {
690 // Like GetTitle(), we also want to use the favicon for the last committed
691 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57692 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47693 if (entry)
694 return entry->favicon().bitmap();
695
[email protected]ce3fa3c2009-04-20 19:55:57696 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34697 if (entry)
698 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34699 return SkBitmap();
700}
701
[email protected]0b303cc2009-09-28 22:35:15702bool TabContents::FavIconIsValid() const {
703 NavigationEntry* entry = controller_.GetTransientEntry();
704 if (entry)
705 return entry->favicon().is_valid();
706
707 entry = controller_.GetLastCommittedEntry();
708 if (entry)
709 return entry->favicon().is_valid();
710
711 return false;
712}
713
[email protected]96d185d2009-04-24 03:28:54714bool TabContents::ShouldDisplayFavIcon() {
715 // Always display a throbber during pending loads.
716 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
717 return true;
718
719 DOMUI* dom_ui = GetDOMUIForCurrentState();
720 if (dom_ui)
721 return !dom_ui->hide_favicon();
722 return true;
723}
724
[email protected]96d185d2009-04-24 03:28:54725std::wstring TabContents::GetStatusText() const {
726 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
727 return std::wstring();
728
729 switch (load_state_) {
730 case net::LOAD_STATE_WAITING_FOR_CACHE:
731 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04732 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
733 return l10n_util::GetString(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54734 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
735 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
736 case net::LOAD_STATE_RESOLVING_HOST:
737 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_HOST);
738 case net::LOAD_STATE_CONNECTING:
739 return l10n_util::GetString(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06740 case net::LOAD_STATE_SSL_HANDSHAKE:
741 return l10n_util::GetString(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54742 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56743 if (upload_size_)
744 return l10n_util::GetStringF(
745 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
746 static_cast<int>((100 * upload_position_) / upload_size_));
747 else
748 return l10n_util::GetString(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54749 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
750 return l10n_util::GetStringF(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
751 load_state_host_);
752 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
753 case net::LOAD_STATE_IDLE:
754 case net::LOAD_STATE_READING_RESPONSE:
755 break;
756 }
757
758 return std::wstring();
759}
760
[email protected]3c9e1872010-11-18 16:17:49761void TabContents::AddNavigationObserver(WebNavigationObserver* observer) {
762 web_navigation_observers_.AddObserver(observer);
763}
764
765void TabContents::RemoveNavigationObserver(WebNavigationObserver* observer) {
766 web_navigation_observers_.RemoveObserver(observer);
767}
768
[email protected]d5f942ba2008-09-26 19:30:34769void TabContents::SetIsCrashed(bool state) {
770 if (state == is_crashed_)
771 return;
772
773 is_crashed_ = state;
[email protected]c9cd2222009-05-06 05:16:50774 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34775}
776
[email protected]744ef172009-10-16 21:53:46777void TabContents::PageActionStateChanged() {
778 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00779}
[email protected]ce5c4502009-05-06 16:46:11780
[email protected]d5f942ba2008-09-26 19:30:34781void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
782 if (delegate_)
783 delegate_->NavigationStateChanged(this, changed_flags);
784}
785
[email protected]96d185d2009-04-24 03:28:54786void TabContents::DidBecomeSelected() {
787 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16788 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
789 if (rwhv) {
790 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43791#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16792 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43793#endif
794 }
[email protected]96d185d2009-04-24 03:28:54795
[email protected]8cb5d5b2010-02-09 11:36:16796 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11797 last_selected_time_ = base::TimeTicks::Now();
[email protected]96d185d2009-04-24 03:28:54798}
799
800void TabContents::WasHidden() {
801 if (!capturing_contents()) {
802 // |render_view_host()| can be NULL if the user middle clicks a link to open
803 // a tab in then background, then closes the tab before selecting it. This
804 // is because closing the tab calls TabContents::Destroy(), which removes
805 // the |render_view_host()|; then when we actually destroy the window,
806 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16807 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
808 if (rwhv)
809 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54810 }
811
812 NotificationService::current()->Notify(
813 NotificationType::TAB_CONTENTS_HIDDEN,
814 Source<TabContents>(this),
815 NotificationService::NoDetails());
816}
817
[email protected]d5f942ba2008-09-26 19:30:34818void TabContents::Activate() {
819 if (delegate_)
820 delegate_->ActivateContents(this);
821}
822
[email protected]ea42e7782010-08-23 23:58:12823void TabContents::Deactivate() {
824 if (delegate_)
825 delegate_->DeactivateContents(this);
826}
827
[email protected]96d185d2009-04-24 03:28:54828void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16829 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
830 if (rwhv)
831 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54832}
833
834void TabContents::HideContents() {
835 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
836 // our superclass HideContents(), because some callers want to be very picky
837 // about the order in which these get called. In addition to making the code
838 // here practically impossible to understand, this also means we end up
839 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34840 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54841 WasHidden();
842}
843
[email protected]c0588052008-10-27 23:01:50844void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34845 WindowOpenDisposition disposition,
846 PageTransition::Type transition) {
847 if (delegate_)
[email protected]c0588052008-10-27 23:01:50848 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34849}
850
[email protected]1ccb3568d2010-02-19 10:51:16851bool TabContents::NavigateToPendingEntry(
852 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54853 return NavigateToEntry(*controller_.pending_entry(), reload_type);
854}
[email protected]96d185d2009-04-24 03:28:54855
[email protected]876bc832010-09-07 16:29:54856bool TabContents::NavigateToEntry(
857 const NavigationEntry& entry,
858 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54859 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
860 if (!dest_render_view_host)
861 return false; // Unable to create the desired render view host.
862
[email protected]770dd8b2010-05-24 18:11:39863 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
864 dest_render_view_host->EnablePreferredSizeChangedMode(
865 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
866 }
[email protected]9fb325e2010-05-06 18:23:24867
[email protected]05fdd492010-11-15 17:52:07868 // For security, we should never send non-DOM-UI URLs to a DOM UI renderer.
869 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58870 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]0352e5472010-04-29 00:11:40871 bool is_allowed_in_dom_ui_renderer =
[email protected]05fdd492010-11-15 17:52:07872 DOMUIFactory::IsURLAcceptableForDOMUI(profile(), entry.url());
[email protected]54ec6472010-04-09 19:39:58873 CHECK(!BindingsPolicy::is_dom_ui_enabled(enabled_bindings) ||
[email protected]0352e5472010-04-29 00:11:40874 is_allowed_in_dom_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58875
[email protected]96d185d2009-04-24 03:28:54876 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12877 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32878 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00879 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
880 dest_render_view_host,
881 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32882 }
[email protected]96d185d2009-04-24 03:28:54883
884 // Used for page load time metrics.
885 current_load_start_ = base::TimeTicks::Now();
886
887 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34888 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54889 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04890 if (delegate_) {
891 navigate_params.extra_headers =
892 delegate_->GetNavigationHeaders(navigate_params.url);
893 }
[email protected]056de2d2009-06-26 16:41:34894 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54895
896 if (entry.page_id() == -1) {
897 // HACK!! This code suppresses javascript: URLs from being added to
898 // session history, which is what we want to do for javascript: URLs that
899 // do not generate content. What we really need is a message from the
900 // renderer telling us that a new page was not created. The same message
901 // could be used for mailto: URLs and the like.
902 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
903 return false;
904 }
905
[email protected]3c9e1872010-11-18 16:17:49906 // Notify observers about navigation.
907 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
908 NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54909
[email protected]1ccb3568d2010-02-19 10:51:16910 if (reload_type != NavigationController::NO_RELOAD &&
911 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48912 FaviconService* favicon_service =
913 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
914 if (favicon_service)
915 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54916 }
917
[email protected]d5f942ba2008-09-26 19:30:34918 return true;
919}
920
[email protected]96d185d2009-04-24 03:28:54921void TabContents::Stop() {
922 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09923 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54924}
925
[email protected]96d185d2009-04-24 03:28:54926void TabContents::DisassociateFromPopupCount() {
927 render_view_host()->DisassociateFromPopupCount();
928}
929
930TabContents* TabContents::Clone() {
931 // We create a new SiteInstance so that the new tab won't share processes
932 // with the old one. This can be changed in the future if we need it to share
933 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32934 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54935 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07936 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54937 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08938 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08939 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54940 return tc;
941}
942
[email protected]4d677202009-07-19 07:37:12943void TabContents::ShowPageInfo(const GURL& url,
944 const NavigationEntry::SSLStatus& ssl,
945 bool show_history) {
946 if (!delegate_)
947 return;
948
[email protected]bb678332009-07-21 00:15:50949 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12950}
951
initial.commit09911bf2008-07-26 23:55:29952ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28953 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29954 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28955 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29956 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44957
958 if (child_windows_.size() == 1) {
959 window->ShowConstrainedWindow();
960 BlockTabContent(true);
961 }
962
initial.commit09911bf2008-07-26 23:55:29963 return window;
964}
965
[email protected]fa1cf0b82010-01-15 21:49:44966void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55967 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
968 if (rwhv)
969 rwhv->SetVisuallyDeemphasized(blocked);
[email protected]fa1cf0b82010-01-15 21:49:44970 render_view_host()->set_ignore_input_events(blocked);
971 if (delegate_)
972 delegate_->SetTabContentBlocked(this, blocked);
973}
974
initial.commit09911bf2008-07-26 23:55:29975void TabContents::AddNewContents(TabContents* new_contents,
976 WindowOpenDisposition disposition,
977 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29978 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40979 if (all_contents_blocked_) {
980 if (!blocked_contents_)
981 blocked_contents_ = new BlockedContentContainer(this);
982 blocked_contents_->AddTabContents(
983 new_contents, disposition, initial_pos, user_gesture);
984 return;
985 }
986
initial.commit09911bf2008-07-26 23:55:29987 if (!delegate_)
988 return;
989
[email protected]35f7d212009-04-29 21:19:27990 if ((disposition == NEW_POPUP) && !user_gesture &&
991 !CommandLine::ForCurrentProcess()->HasSwitch(
992 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:22993 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:31994 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:29995 delegate_->GetConstrainingContents(this)->AddPopup(
996 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:31997 } else {
[email protected]0aa55312008-10-17 21:53:08998 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:29999 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1000 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491001 NotificationService::current()->Notify(
1002 NotificationType::TAB_ADDED,
1003 Source<TabContentsDelegate>(delegate_),
1004 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291005 }
initial.commit09911bf2008-07-26 23:55:291006
[email protected]8cc8d492010-02-02 10:40:491007 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401008 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291009}
1010
[email protected]bcd9dc42010-01-23 16:38:181011bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201012 bool is_js_code, const std::string& code_string,
1013 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511014 RenderViewHost* host = render_view_host();
1015 if (!host)
1016 return false;
1017
1018 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171019 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511020 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351021}
1022
[email protected]96d185d2009-04-24 03:28:541023void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491024 if (is_being_destroyed_)
1025 return;
[email protected]9fb83e82010-07-02 18:24:551026 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491027 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401028 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541029}
1030
[email protected]5c9e97a2009-09-09 23:48:301031gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541032 return view_->GetContentNativeView();
1033}
1034
1035gfx::NativeView TabContents::GetNativeView() const {
1036 return view_->GetNativeView();
1037}
1038
1039void TabContents::GetContainerBounds(gfx::Rect *out) const {
1040 view_->GetContainerBounds(out);
1041}
1042
1043void TabContents::Focus() {
1044 view_->Focus();
1045}
1046
[email protected]90daadb42009-06-08 21:27:281047void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541048 if (showing_interstitial_page()) {
1049 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1050 return;
1051 }
[email protected]96d185d2009-04-24 03:28:541052 render_view_host()->SetInitialFocus(reverse);
1053}
1054
1055bool TabContents::FocusLocationBarByDefault() {
1056 DOMUI* dom_ui = GetDOMUIForCurrentState();
1057 if (dom_ui)
1058 return dom_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431059 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251060 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431061 return true;
[email protected]96d185d2009-04-24 03:28:541062 return false;
1063}
1064
[email protected]a26dc362010-04-23 01:48:581065void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381066 if (delegate())
[email protected]a26dc362010-04-23 01:48:581067 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381068}
1069
[email protected]616ed5a2008-11-21 22:27:241070void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321071 if (delegate_ && !delegate_->infobars_enabled()) {
1072 delegate->InfoBarClosed();
1073 return;
1074 }
1075
[email protected]616ed5a2008-11-21 22:27:241076 // Look through the existing InfoBarDelegates we have for a match. If we've
1077 // already got one that matches, then we don't add the new one.
[email protected]f86a07022008-11-25 01:06:051078 for (int i = 0; i < infobar_delegate_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451079 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1080 // Tell the new infobar to close so that it can clean itself up.
1081 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241082 return;
[email protected]6d27a7b2009-12-18 23:25:451083 }
[email protected]616ed5a2008-11-21 22:27:241084 }
1085
1086 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561087 NotificationService::current()->Notify(
1088 NotificationType::TAB_CONTENTS_INFOBAR_ADDED,
1089 Source<TabContents>(this),
1090 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241091
1092 // Add ourselves as an observer for navigations the first time a delegate is
1093 // added. We use this notification to expire InfoBars that need to expire on
1094 // page transitions.
1095 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561096 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571097 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241098 }
1099}
1100
1101void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321102 if (delegate_ && !delegate_->infobars_enabled()) {
1103 return;
1104 }
1105
[email protected]616ed5a2008-11-21 22:27:241106 std::vector<InfoBarDelegate*>::iterator it =
1107 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1108 if (it != infobar_delegates_.end()) {
1109 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561110 NotificationService::current()->Notify(
1111 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1112 Source<TabContents>(this),
1113 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241114
[email protected]cdadf6f2010-08-20 16:36:081115 // Just to be safe, make sure the delegate was not removed by an observer.
1116 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1117 if (it != infobar_delegates_.end()) {
1118 infobar_delegates_.erase(it);
1119 // Remove ourselves as an observer if we are tracking no more InfoBars.
1120 if (infobar_delegates_.empty()) {
1121 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1122 Source<NavigationController>(&controller_));
1123 }
1124 } else {
1125 // If you hit this NOTREACHED, please comment in bug
1126 // http://crbug.com/50428 how you got there.
1127 NOTREACHED();
[email protected]6a02963e2009-01-06 16:58:031128 }
[email protected]616ed5a2008-11-21 22:27:241129 }
1130}
[email protected]3edd9522009-03-04 22:19:411131
[email protected]f81821c2009-08-07 01:29:471132void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1133 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321134 if (delegate_ && !delegate_->infobars_enabled()) {
1135 new_delegate->InfoBarClosed();
1136 return;
1137 }
1138
[email protected]f81821c2009-08-07 01:29:471139 std::vector<InfoBarDelegate*>::iterator it =
1140 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1141 DCHECK(it != infobar_delegates_.end());
1142
1143 // Notify the container about the change of plans.
1144 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1145 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1146 old_delegate, new_delegate));
1147 NotificationService::current()->Notify(
1148 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1149 Source<TabContents>(this),
1150 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1151
[email protected]cdadf6f2010-08-20 16:36:081152 // Just to be safe, make sure the delegate was not removed by an observer.
1153 it = find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1154 if (it != infobar_delegates_.end()) {
1155 // Remove the old one.
1156 infobar_delegates_.erase(it);
1157 } else {
1158 // If you hit this NOTREACHED, please comment in bug
1159 // http://crbug.com/50428 how you got there.
1160 NOTREACHED();
1161 }
[email protected]f81821c2009-08-07 01:29:471162
1163 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081164 DCHECK(find(infobar_delegates_.begin(),
1165 infobar_delegates_.end(), new_delegate) ==
1166 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471167 infobar_delegates_.push_back(new_delegate);
1168}
1169
[email protected]20ede072009-10-06 00:28:351170bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271171 if (showing_interstitial_page())
1172 return false;
1173
[email protected]c8f74942010-09-03 10:04:141174 // Do not show bookmarks bar if bookmarks aren't enabled.
1175 if (!browser_defaults::bookmarks_enabled)
1176 return false;
1177
[email protected]96d185d2009-04-24 03:28:541178 // See GetDOMUIForCurrentState() comment for more info. This case is very
1179 // similar, but for non-first loads, we want to use the committed entry. This
1180 // is so the bookmarks bar disappears at the same time the page does.
1181 if (controller_.GetLastCommittedEntry()) {
1182 // Not the first load, always use the committed DOM UI.
[email protected]d6219912010-11-17 19:47:371183 return (render_manager_.dom_ui() == NULL) ?
1184 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541185 }
1186
1187 // When it's the first load, we know either the pending one or the committed
1188 // one will have the DOM UI in it (see GetDOMUIForCurrentState), and only one
1189 // of them will be valid, so we can just check both.
1190 if (render_manager_.pending_dom_ui())
1191 return render_manager_.pending_dom_ui()->force_bookmark_bar_visible();
[email protected]d6219912010-11-17 19:47:371192 return (render_manager_.dom_ui() == NULL) ?
1193 false : render_manager_.dom_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541194}
1195
[email protected]3edd9522009-03-04 22:19:411196void TabContents::ToolbarSizeChanged(bool is_animating) {
1197 TabContentsDelegate* d = delegate();
1198 if (d)
1199 d->ToolbarSizeChanged(this, is_animating);
1200}
[email protected]616ed5a2008-11-21 22:27:241201
[email protected]fc6fb7fb2009-11-07 02:35:041202bool TabContents::CanDownload(int request_id) {
1203 TabContentsDelegate* d = delegate();
1204 if (d)
1205 return d->CanDownload(request_id);
1206 return true;
1207}
1208
[email protected]d5f942ba2008-09-26 19:30:341209void TabContents::OnStartDownload(DownloadItem* download) {
1210 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341211
1212 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311213 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341214
[email protected]5b928b62010-08-03 11:46:511215 if (tab_contents && tab_contents->delegate())
1216 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411217}
[email protected]3edd9522009-03-04 22:19:411218
[email protected]d5f942ba2008-09-26 19:30:341219void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371220 ConstrainedWindowList::iterator i(
1221 std::find(child_windows_.begin(), child_windows_.end(), window));
1222 bool removed_topmost_window = i == child_windows_.begin();
1223 if (i != child_windows_.end())
1224 child_windows_.erase(i);
1225 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441226 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371227 } else {
1228 if (removed_topmost_window)
1229 child_windows_[0]->ShowConstrainedWindow();
1230 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441231 }
[email protected]66ba4932009-06-04 19:22:131232}
[email protected]d5f942ba2008-09-26 19:30:341233
[email protected]c65e2f152010-10-14 15:30:401234void TabContents::WillCloseBlockedContentContainer(
1235 BlockedContentContainer* container) {
1236 DCHECK(blocked_contents_ == container);
1237 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491238 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341239}
1240
[email protected]d5f942ba2008-09-26 19:30:341241void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351242#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061243 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351244#endif
[email protected]d5f942ba2008-09-26 19:30:341245}
1246
[email protected]c1dc9f132009-11-20 23:13:211247void TabContents::StartFinding(string16 search_string,
[email protected]e491f1c2009-05-22 20:28:121248 bool forward_direction,
1249 bool case_sensitive) {
[email protected]c1dc9f132009-11-20 23:13:211250 // If search_string is empty, it means FindNext was pressed with a keyboard
[email protected]6e95706d2009-04-23 22:55:011251 // shortcut so unless we have something to search for we return early.
[email protected]c1dc9f132009-11-20 23:13:211252 if (search_string.empty() && find_text_.empty()) {
[email protected]e5d2f7132010-04-09 18:13:531253 string16 last_search_prepopulate_text =
1254 FindBarState::GetLastPrepopulateText(profile());
1255
[email protected]87fae512009-12-11 02:20:211256 // Try the last thing we searched for on this tab, then the last thing
1257 // searched for on any tab.
1258 if (!previous_find_text_.empty())
1259 search_string = previous_find_text_;
[email protected]e5d2f7132010-04-09 18:13:531260 else if (!last_search_prepopulate_text.empty())
1261 search_string = last_search_prepopulate_text;
[email protected]87fae512009-12-11 02:20:211262 else
[email protected]e491f1c2009-05-22 20:28:121263 return;
[email protected]e491f1c2009-05-22 20:28:121264 }
[email protected]6e95706d2009-04-23 22:55:011265
[email protected]101c90e2009-10-26 21:14:441266 // Keep track of the previous search.
1267 previous_find_text_ = find_text_;
1268
[email protected]6e95706d2009-04-23 22:55:011269 // This is a FindNext operation if we are searching for the same text again,
1270 // or if the passed in search text is empty (FindNext keyboard shortcut). The
1271 // exception to this is if the Find was aborted (then we don't want FindNext
1272 // because the highlighting has been cleared and we need it to reappear). We
1273 // therefore treat FindNext after an aborted Find operation as a full fledged
1274 // Find.
[email protected]c1dc9f132009-11-20 23:13:211275 bool find_next = (find_text_ == search_string || search_string.empty()) &&
[email protected]e491f1c2009-05-22 20:28:121276 (last_search_case_sensitive_ == case_sensitive) &&
[email protected]6e95706d2009-04-23 22:55:011277 !find_op_aborted_;
1278 if (!find_next)
1279 current_find_request_id_ = find_request_id_counter_++;
1280
[email protected]c1dc9f132009-11-20 23:13:211281 if (!search_string.empty())
1282 find_text_ = search_string;
[email protected]e491f1c2009-05-22 20:28:121283 last_search_case_sensitive_ = case_sensitive;
[email protected]6e95706d2009-04-23 22:55:011284
1285 find_op_aborted_ = false;
1286
1287 // Keep track of what the last search was across the tabs.
[email protected]e5d2f7132010-04-09 18:13:531288 FindBarState* find_bar_state = profile()->GetFindBarState();
1289 find_bar_state->set_last_prepopulate_text(find_text_);
[email protected]6e95706d2009-04-23 22:55:011290 render_view_host()->StartFinding(current_find_request_id_,
1291 find_text_,
1292 forward_direction,
[email protected]e491f1c2009-05-22 20:28:121293 case_sensitive,
[email protected]6e95706d2009-04-23 22:55:011294 find_next);
1295}
1296
[email protected]5bc8fe92010-03-11 18:19:001297void TabContents::StopFinding(
1298 FindBarController::SelectionAction selection_action) {
[email protected]d6e8d332010-06-04 22:26:011299 if (selection_action == FindBarController::kClearSelection) {
1300 // kClearSelection means the find string has been cleared by the user, but
1301 // the UI has not been dismissed. In that case we want to clear the
1302 // previously remembered search (http://crbug.com/42639).
1303 previous_find_text_ = string16();
1304 } else {
[email protected]2d2dffc2009-06-09 21:41:001305 find_ui_active_ = false;
[email protected]d6e8d332010-06-04 22:26:011306 if (!find_text_.empty())
1307 previous_find_text_ = find_text_;
1308 }
[email protected]101c90e2009-10-26 21:14:441309 find_text_.clear();
[email protected]6e95706d2009-04-23 22:55:011310 find_op_aborted_ = true;
[email protected]e491f1c2009-05-22 20:28:121311 last_search_result_ = FindNotificationDetails();
[email protected]5bc8fe92010-03-11 18:19:001312 render_view_host()->StopFinding(selection_action);
[email protected]6e95706d2009-04-23 22:55:011313}
1314
[email protected]420ae012009-04-24 05:16:321315void TabContents::OnSavePage() {
1316 // If we can not save the page, try to download it.
1317 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1318 DownloadManager* dlm = profile()->GetDownloadManager();
1319 const GURL& current_page_url = GetURL();
1320 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221321 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321322 return;
1323 }
1324
1325 Stop();
1326
1327 // Create the save package and possibly prompt the user for the name to save
1328 // the page as. The user prompt is an asynchronous operation that runs on
1329 // another thread.
[email protected]d82ed61e2009-06-16 02:46:221330 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321331 save_package_->GetSaveInfo();
1332}
1333
1334// Used in automated testing to bypass prompting the user for file names.
1335// Instead, the names and paths are hard coded rather than running them through
1336// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111337bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321338 SavePackage::SavePackageType save_type) {
1339 // Stop the page from navigating.
1340 Stop();
1341
[email protected]828cabe2009-09-26 22:47:111342 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591343 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321344}
1345
[email protected]89d6e6e2009-12-03 23:06:511346void TabContents::EmailPageLocation() {
1347 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1348 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1349 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1350 title + "&body=%0A%0A" + page_url;
1351 platform_util::OpenExternal(GURL(mailto));
1352}
1353
[email protected]420ae012009-04-24 05:16:321354void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161355 if (CommandLine::ForCurrentProcess()->HasSwitch(
1356 switches::kEnablePrintPreview)) {
1357 if (showing_interstitial_page())
1358 return;
1359 render_view_host()->PrintPreview();
1360 } else {
1361 PrintNow();
1362 }
[email protected]420ae012009-04-24 05:16:321363}
1364
1365bool TabContents::PrintNow() {
1366 // We can't print interstitial page for now.
1367 if (showing_interstitial_page())
1368 return false;
1369
1370 return render_view_host()->PrintPages();
1371}
1372
[email protected]82270452009-06-19 15:58:011373void TabContents::PrintingDone(int document_cookie, bool success) {
1374 render_view_host()->PrintingDone(document_cookie, success);
1375}
1376
[email protected]420ae012009-04-24 05:16:321377bool TabContents::IsActiveEntry(int32 page_id) {
1378 NavigationEntry* active_entry = controller_.GetActiveEntry();
1379 return (active_entry != NULL &&
1380 active_entry->site_instance() == GetSiteInstance() &&
1381 active_entry->page_id() == page_id);
1382}
1383
[email protected]b2fe07d12010-02-09 14:38:081384void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161385 set_encoding(encoding);
1386 render_view_host()->SetPageEncoding(encoding);
1387}
1388
[email protected]b2fe07d12010-02-09 14:38:081389void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161390 reset_encoding();
1391 render_view_host()->ResetPageEncodingToDefault();
1392}
1393
1394void TabContents::WindowMoveOrResizeStarted() {
1395 render_view_host()->WindowMoveOrResizeStarted();
1396}
1397
[email protected]c65e2f152010-10-14 15:30:401398void TabContents::SetAllContentsBlocked(bool value) {
1399 if (all_contents_blocked_ == value)
1400 return;
1401
1402 all_contents_blocked_ = value;
1403 if (!all_contents_blocked_ && blocked_contents_) {
1404 std::vector<TabContents*> blocked;
1405 blocked_contents_->GetBlockedContents(&blocked);
1406 for (size_t i = 0; i < blocked.size(); ++i)
1407 blocked_contents_->LaunchForContents(blocked[i]);
1408 }
1409}
1410
[email protected]3f8eb7f2009-10-02 23:58:051411void TabContents::LogNewTabTime(const std::string& event_name) {
1412 // Not all new tab pages get timed. In those cases, we don't have a
1413 // new_tab_start_time_.
1414 if (new_tab_start_time_.is_null())
1415 return;
1416
1417 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441418 MetricEventDurationDetails details(event_name,
1419 static_cast<int>(duration.InMilliseconds()));
1420
[email protected]7ab1e7d62009-10-14 23:32:011421 if (event_name == "Tab.NewTabScriptStart") {
1422 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1423 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1424 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1425 } else if (event_name == "Tab.NewTabOnload") {
1426 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051427 // The new tab page has finished loading; reset it.
1428 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441429 } else {
1430 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051431 }
[email protected]84abba62009-10-07 17:01:441432 NotificationService::current()->Notify(
1433 NotificationType::METRIC_EVENT_DURATION,
1434 Source<TabContents>(this),
1435 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051436}
1437
[email protected]7ab1e7d62009-10-14 23:32:011438void TabContents::OnCloseStarted() {
1439 if (tab_close_start_time_.is_null())
1440 tab_close_start_time_ = base::TimeTicks::Now();
1441}
1442
[email protected]46624bf2010-06-09 16:04:191443bool TabContents::ShouldAcceptDragAndDrop() const {
1444#if defined(OS_CHROMEOS)
1445 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1446 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201447 if (delegate() && delegate()->IsPopup(this))
1448 return false;
1449 return true;
[email protected]46624bf2010-06-09 16:04:191450#else
1451 return true;
1452#endif
1453}
1454
[email protected]ec0b6c42010-08-26 03:16:581455void TabContents::UpdateHistoryForNavigation(
1456 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1457 if (profile()->IsOffTheRecord())
1458 return;
1459
1460 // Add to history service.
1461 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1462 if (hs)
1463 hs->AddPage(*add_page_args);
1464}
1465
1466void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1467 if (profile()->IsOffTheRecord())
1468 return;
1469
1470 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1471 if (hs)
1472 hs->SetPageTitle(entry.virtual_url(), entry.title());
1473}
1474
[email protected]d0b8d092010-10-25 04:05:171475double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251476 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1477 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171478 return 0;
[email protected]b75b8292010-10-01 07:28:251479
1480 double zoom_level;
1481 if (temporary_zoom_settings_) {
1482 zoom_level = zoom_map->GetTemporaryZoomLevel(
1483 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1484 } else {
1485 zoom_level = zoom_map->GetZoomLevel(GetURL());
1486 }
[email protected]d0b8d092010-10-25 04:05:171487 return zoom_level;
1488}
[email protected]b75b8292010-10-01 07:28:251489
[email protected]d0b8d092010-10-25 04:05:171490int TabContents::GetZoomPercent(bool* enable_increment,
1491 bool* enable_decrement) {
1492 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251493 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171494 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251495 *enable_decrement = percent > minimum_zoom_percent_;
1496 *enable_increment = percent < maximum_zoom_percent_;
1497 return percent;
1498}
1499
[email protected]96d185d2009-04-24 03:28:541500// Notifies the RenderWidgetHost instance about the fact that the page is
1501// loading, or done loading and calls the base implementation.
1502void TabContents::SetIsLoading(bool is_loading,
1503 LoadNotificationDetails* details) {
1504 if (is_loading == is_loading_)
1505 return;
1506
1507 if (!is_loading) {
1508 load_state_ = net::LOAD_STATE_IDLE;
1509 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561510 upload_size_ = 0;
1511 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541512 }
1513
1514 render_manager_.SetIsLoading(is_loading);
1515
1516 is_loading_ = is_loading;
1517 waiting_for_response_ = is_loading;
1518
[email protected]6ebdc9b2010-09-27 16:55:571519 if (delegate_)
1520 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351521 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541522
1523 NotificationType type = is_loading ? NotificationType::LOAD_START :
1524 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111525 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541526 if (details)
1527 det = Details<LoadNotificationDetails>(details);
1528 NotificationService::current()->Notify(type,
1529 Source<NavigationController>(&controller_),
1530 det);
1531}
1532
[email protected]b6c874582009-05-08 19:38:311533void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291534 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061535 // A page can't spawn popups (or do anything else, either) until its load
1536 // commits, so when we reach here, the popup was spawned by the
1537 // NavigationController's last committed entry, not the active entry. For
1538 // example, if a page opens a popup in an onunload() handler, then the active
1539 // entry is the page to be loaded as we navigate away from the unloading
1540 // page. For this reason, we can't use GetURL() to get the opener URL,
1541 // because it returns the active entry.
1542 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1543 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1544
1545 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491546 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091547 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491548 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1549 } else {
[email protected]c65e2f152010-10-14 15:30:401550 if (!blocked_contents_)
1551 blocked_contents_ = new BlockedContentContainer(this);
1552 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1553 true);
[email protected]55126132010-08-19 14:53:281554 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1555 std::string());
[email protected]8cc8d492010-02-02 10:40:491556 }
[email protected]b9681312008-11-07 00:08:261557}
[email protected]616ed5a2008-11-21 22:27:241558
[email protected]616ed5a2008-11-21 22:27:241559void TabContents::ExpireInfoBars(
1560 const NavigationController::LoadCommittedDetails& details) {
1561 // Only hide InfoBars when the user has done something that makes the main
1562 // frame load. We don't want various automatic or subframe navigations making
1563 // it disappear.
1564 if (!details.is_user_initiated_main_frame_load())
1565 return;
1566
[email protected]f86a07022008-11-25 01:06:051567 for (int i = infobar_delegate_count() - 1; i >= 0; --i) {
[email protected]616ed5a2008-11-21 22:27:241568 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
[email protected]cdadf6f2010-08-20 16:36:081569 if (!delegate) {
1570 // If you hit this NOTREACHED, please comment in bug
1571 // http://crbug.com/50428 how you got there.
1572 NOTREACHED();
1573 continue;
1574 }
1575
[email protected]f86a07022008-11-25 01:06:051576 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241577 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241578 }
1579}
[email protected]fdd61c62009-04-22 19:22:571580
[email protected]96d185d2009-04-24 03:28:541581DOMUI* TabContents::GetDOMUIForCurrentState() {
1582 // When there is a pending navigation entry, we want to use the pending DOMUI
1583 // that goes along with it to control the basic flags. For example, we want to
1584 // show the pending URL in the URL bar, so we want the display_url flag to
1585 // be from the pending entry.
1586 //
1587 // The confusion comes because there are multiple possibilities for the
1588 // initial load in a tab as a side effect of the way the RenderViewHostManager
1589 // works.
1590 //
1591 // - For the very first tab the load looks "normal". The new tab DOM UI is
1592 // the pending one, and we want it to apply here.
1593 //
1594 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1595 // get switched to the one previously associated with the new tab pages.
1596 // This switching will cause the manager to commit the RVH/DOMUI. So we'll
1597 // have a committed DOM UI in this case.
1598 //
1599 // This condition handles all of these cases:
1600 //
1601 // - First load in first tab: no committed nav entry + pending nav entry +
1602 // pending dom ui:
1603 // -> Use pending DOM UI if any.
1604 //
1605 // - First load in second tab: no committed nav entry + pending nav entry +
1606 // no pending DOM UI:
1607 // -> Use the committed DOM UI if any.
1608 //
1609 // - Second navigation in any tab: committed nav entry + pending nav entry:
1610 // -> Use pending DOM UI if any.
1611 //
1612 // - Normal state with no load: committed nav entry + no pending nav entry:
1613 // -> Use committed DOM UI.
1614 if (controller_.pending_entry() &&
1615 (controller_.GetLastCommittedEntry() ||
1616 render_manager_.pending_dom_ui()))
1617 return render_manager_.pending_dom_ui();
1618 return render_manager_.dom_ui();
1619}
[email protected]420ae012009-04-24 05:16:321620
1621void TabContents::DidNavigateMainFramePostCommit(
1622 const NavigationController::LoadCommittedDetails& details,
1623 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]c2e74fe82009-09-03 17:57:441624 if (opener_dom_ui_type_ != DOMUIFactory::kNoDOMUI) {
1625 // If this is a window.open navigation, use the same DOMUI as the renderer
1626 // that opened the window, as long as both renderers have the same
1627 // privileges.
[email protected]583d45c12010-08-31 02:48:121628 if (opener_dom_ui_type_ ==
1629 DOMUIFactory::GetDOMUIType(profile(), GetURL())) {
[email protected]c2e74fe82009-09-03 17:57:441630 DOMUI* dom_ui = DOMUIFactory::CreateDOMUIForURL(this, GetURL());
1631 // dom_ui might be NULL if the URL refers to a non-existent extension.
1632 if (dom_ui) {
1633 render_manager_.SetDOMUIPostCommit(dom_ui);
1634 dom_ui->RenderViewCreated(render_view_host());
1635 }
1636 }
1637 opener_dom_ui_type_ = DOMUIFactory::kNoDOMUI;
1638 }
1639
[email protected]420ae012009-04-24 05:16:321640 if (details.is_user_initiated_main_frame_load()) {
1641 // Clear the status bubble. This is a workaround for a bug where WebKit
1642 // doesn't let us know that the cursor left an element during a
1643 // transition (this is also why the mouse cursor remains as a hand after
1644 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1645 // clear the bubble when a user navigates to a named anchor in the same
1646 // page.
1647 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321648 }
1649
1650 // The keyword generator uses the navigation entries, so must be called after
1651 // the commit.
1652 GenerateKeywordIfNecessary(params);
1653
1654 // Allow the new page to set the title again.
1655 received_page_title_ = false;
1656
1657 // Get the favicon, either from history or request it from the net.
1658 fav_icon_helper_.FetchFavIcon(details.entry->url());
1659
[email protected]0de80162010-02-03 04:52:351660 // Clear all page actions, blocked content notifications and browser actions
1661 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141662 if (!details.is_in_page) {
[email protected]92c6f9b92009-10-24 04:35:081663 ExtensionsService* service = profile()->GetExtensionsService();
1664 if (service) {
1665 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571666 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081667 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521668 if (browser_action) {
1669 browser_action->ClearAllValuesForTab(controller().session_id().id());
1670 NotificationService::current()->Notify(
1671 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571672 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521673 NotificationService::NoDetails());
1674 }
[email protected]92c6f9b92009-10-24 04:35:081675
[email protected]5d246db22009-10-27 06:17:571676 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521677 service->extensions()->at(i)->page_action();
1678 if (page_action) {
1679 page_action->ClearAllValuesForTab(controller().session_id().id());
1680 PageActionStateChanged();
1681 }
[email protected]92c6f9b92009-10-24 04:35:081682 }
[email protected]aece2c7f2009-08-27 20:43:171683 }
[email protected]0de80162010-02-03 04:52:351684
1685 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401686 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341687 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401688 blocked_contents_->Destroy();
1689 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351690 }
1691
1692 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411693 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551694 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471695
1696 // Once the main frame is navigated, we're no longer considered to have
1697 // displayed insecure content.
1698 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171699 }
[email protected]ce5c4502009-05-06 16:46:111700
[email protected]8cc8d492010-02-02 10:40:491701 // Close constrained windows if necessary.
1702 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1703 details.previous_url, details.entry->url()))
1704 CloseConstrainedWindows();
1705
[email protected]420ae012009-04-24 05:16:321706 // Update the starred state.
1707 UpdateStarredStateForCurrentURL();
[email protected]c07c9752010-03-12 05:57:531708
[email protected]3c9e1872010-11-18 16:17:491709 // Notify observers about navigation.
1710 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1711 DidNavigateMainFramePostCommit(details, params));
1712
[email protected]c07c9752010-03-12 05:57:531713 // Clear the cache of forms in AutoFill.
1714 if (autofill_manager_.get())
1715 autofill_manager_->Reset();
[email protected]420ae012009-04-24 05:16:321716}
1717
1718void TabContents::DidNavigateAnyFramePostCommit(
1719 RenderViewHost* render_view_host,
1720 const NavigationController::LoadCommittedDetails& details,
1721 const ViewHostMsg_FrameNavigate_Params& params) {
1722 // If we navigate, start showing messages again. This does nothing to prevent
1723 // a malicious script from spamming messages, since the script could just
1724 // reload the page to stop blocking.
1725 suppress_javascript_messages_ = false;
1726
[email protected]3c9e1872010-11-18 16:17:491727 // Notify observers about navigation.
1728 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
1729 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551730
1731 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581732 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321733}
1734
[email protected]8cc8d492010-02-02 10:40:491735void TabContents::CloseConstrainedWindows() {
1736 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321737 // We use indices instead of iterators in case CloseWindow does something
1738 // that may invalidate an iterator.
1739 int size = static_cast<int>(child_windows_.size());
1740 for (int i = size - 1; i >= 0; --i) {
1741 ConstrainedWindow* window = child_windows_[i];
[email protected]fa1cf0b82010-01-15 21:49:441742 if (window) {
[email protected]420ae012009-04-24 05:16:321743 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441744 BlockTabContent(false);
1745 }
[email protected]420ae012009-04-24 05:16:321746 }
1747}
1748
1749void TabContents::UpdateStarredStateForCurrentURL() {
1750 BookmarkModel* model = profile()->GetBookmarkModel();
1751 const bool old_state = is_starred_;
1752 is_starred_ = (model && model->IsBookmarked(GetURL()));
1753
1754 if (is_starred_ != old_state && delegate())
1755 delegate()->URLStarredChanged(this, is_starred_);
1756}
1757
1758void TabContents::UpdateAlternateErrorPageURL() {
1759 GURL url = GetAlternateErrorPageURL();
1760 render_view_host()->SetAlternateErrorPageURL(url);
1761}
1762
1763void TabContents::UpdateWebPreferences() {
1764 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1765}
1766
[email protected]d0b8d092010-10-25 04:05:171767void TabContents::UpdateZoomLevel() {
1768 render_view_host()->SetZoomLevel(GetZoomLevel());
1769}
1770
[email protected]420ae012009-04-24 05:16:321771void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1772 RenderViewHost* rvh) {
1773 // If we are creating a RVH for a restored controller, then we might
1774 // have more page IDs than the SiteInstance's current max page ID. We must
1775 // make sure that the max page ID is larger than any restored page ID.
1776 // Note that it is ok for conflicting page IDs to exist in another tab
1777 // (i.e., NavigationController), but if any page ID is larger than the max,
1778 // the back/forward list will get confused.
1779 int max_restored_page_id = controller_.max_restored_page_id();
1780 if (max_restored_page_id > 0) {
1781 int curr_max_page_id = site_instance->max_page_id();
1782 if (max_restored_page_id > curr_max_page_id) {
1783 // Need to update the site instance immediately.
1784 site_instance->UpdateMaxPageID(max_restored_page_id);
1785
1786 // Also tell the renderer to update its internal representation. We
1787 // need to reserve enough IDs to make all restored page IDs less than
1788 // the max.
1789 if (curr_max_page_id < 0)
1790 curr_max_page_id = 0;
1791 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1792 }
1793 }
1794}
1795
[email protected]ec0b6c42010-08-26 03:16:581796scoped_refptr<history::HistoryAddPageArgs>
1797TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541798 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471799 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321800 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581801 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1802 new history::HistoryAddPageArgs(
1803 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1804 params.redirects, params.transition, history::SOURCE_BROWSED,
1805 details.did_replace_entry));
1806 if (PageTransition::IsMainFrame(params.transition) &&
1807 virtual_url != params.url) {
1808 // Hack on the "virtual" URL so that it will appear in history. For some
1809 // types of URLs, we will display a magic URL that is different from where
1810 // the page is actually navigated. We want the user to see in history what
1811 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1812 // only applies to the main frame, as the virtual URL doesn't apply to
1813 // sub-frames.
1814 add_page_args->url = virtual_url;
1815 if (!add_page_args->redirects.empty())
1816 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321817 }
[email protected]ec0b6c42010-08-26 03:16:581818 return add_page_args;
[email protected]420ae012009-04-24 05:16:321819}
1820
1821bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1822 const std::wstring& title) {
1823 // For file URLs without a title, use the pathname instead. In the case of a
1824 // synthesized title, we don't want the update to count toward the "one set
1825 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251826 string16 final_title;
[email protected]420ae012009-04-24 05:16:321827 bool explicit_set;
1828 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251829 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321830 explicit_set = false; // Don't count synthetic titles toward the set limit.
1831 } else {
[email protected]e53668962010-06-23 15:35:251832 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321833 explicit_set = true;
1834 }
1835
[email protected]e53668962010-06-23 15:35:251836 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321837 return false; // Nothing changed, don't bother.
1838
[email protected]e53668962010-06-23 15:35:251839 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321840
[email protected]ec0b6c42010-08-26 03:16:581841 if (!received_page_title_) {
1842 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321843 received_page_title_ = explicit_set;
1844 }
1845
1846 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251847 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321848
[email protected]cbc0e1b2010-04-12 18:33:041849 NotificationService::current()->Notify(
1850 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1851 Source<TabContents>(this),
1852 NotificationService::NoDetails());
1853
[email protected]420ae012009-04-24 05:16:321854 return true;
1855}
1856
1857void TabContents::NotifySwapped() {
1858 // After sending out a swap notification, we need to send a disconnect
1859 // notification so that clients that pick up a pointer to |this| can NULL the
1860 // pointer. See Bug 1230284.
1861 notify_disconnection_ = true;
1862 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341863 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221864 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321865 NotificationService::NoDetails());
1866}
1867
1868void TabContents::NotifyConnected() {
1869 notify_disconnection_ = true;
1870 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341871 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221872 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321873 NotificationService::NoDetails());
1874}
1875
1876void TabContents::NotifyDisconnected() {
1877 if (!notify_disconnection_)
1878 return;
1879
1880 notify_disconnection_ = false;
1881 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341882 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221883 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321884 NotificationService::NoDetails());
1885}
1886
1887void TabContents::GenerateKeywordIfNecessary(
1888 const ViewHostMsg_FrameNavigate_Params& params) {
1889 if (!params.searchable_form_url.is_valid())
1890 return;
1891
1892 if (profile()->IsOffTheRecord())
1893 return;
1894
1895 int last_index = controller_.last_committed_entry_index();
1896 // When there was no previous page, the last index will be 0. This is
1897 // normally due to a form submit that opened in a new tab.
1898 // TODO(brettw) bug 916126: we should support keywords when form submits
1899 // happen in new tabs.
1900 if (last_index <= 0)
1901 return;
1902 const NavigationEntry* previous_entry =
1903 controller_.GetEntryAtIndex(last_index - 1);
1904 if (IsFormSubmit(previous_entry)) {
1905 // Only generate a keyword if the previous page wasn't itself a form
1906 // submit.
1907 return;
1908 }
1909
1910 GURL keyword_url = previous_entry->user_typed_url().is_valid() ?
1911 previous_entry->user_typed_url() : previous_entry->url();
1912 std::wstring keyword =
1913 TemplateURLModel::GenerateKeyword(keyword_url, true); // autodetected
1914 if (keyword.empty())
1915 return;
1916
1917 TemplateURLModel* url_model = profile()->GetTemplateURLModel();
1918 if (!url_model)
1919 return;
1920
1921 if (!url_model->loaded()) {
1922 url_model->Load();
1923 return;
1924 }
1925
1926 const TemplateURL* current_url;
[email protected]ddd231e2010-06-29 20:35:191927 GURL url = params.searchable_form_url;
[email protected]420ae012009-04-24 05:16:321928 if (!url_model->CanReplaceKeyword(keyword, url, &current_url))
1929 return;
1930
1931 if (current_url) {
1932 if (current_url->originating_url().is_valid()) {
1933 // The existing keyword was generated from an OpenSearch description
1934 // document, don't regenerate.
1935 return;
1936 }
1937 url_model->Remove(current_url);
1938 }
1939 TemplateURL* new_url = new TemplateURL();
1940 new_url->set_keyword(keyword);
1941 new_url->set_short_name(keyword);
[email protected]ddd231e2010-06-29 20:35:191942 new_url->SetURL(url.spec(), 0, 0);
[email protected]420ae012009-04-24 05:16:321943 new_url->add_input_encoding(params.searchable_form_encoding);
1944 DCHECK(controller_.GetLastCommittedEntry());
1945 const GURL& favicon_url =
1946 controller_.GetLastCommittedEntry()->favicon().url();
1947 if (favicon_url.is_valid()) {
1948 new_url->SetFavIconURL(favicon_url);
1949 } else {
1950 // The favicon url isn't valid. This means there really isn't a favicon,
1951 // or the favicon url wasn't obtained before the load started. This assumes
1952 // the later.
1953 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1954 // its url.
1955 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1956 }
1957 new_url->set_safe_for_autoreplace(true);
1958 url_model->Add(new_url);
1959}
1960
[email protected]bf5c2ff392009-07-08 16:24:331961void TabContents::OnUserGesture() {
1962 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
[email protected]41291322010-07-15 17:09:011963 DownloadRequestLimiter* limiter =
1964 g_browser_process->download_request_limiter();
1965 if (limiter)
1966 limiter->OnUserGesture(this);
[email protected]d070ec62010-07-27 21:28:261967 ExternalProtocolHandler::PermitLaunchUrl();
[email protected]bf5c2ff392009-07-08 16:24:331968}
1969
1970void TabContents::OnFindReply(int request_id,
1971 int number_of_matches,
1972 const gfx::Rect& selection_rect,
1973 int active_match_ordinal,
1974 bool final_update) {
[email protected]3ce7ced2009-07-24 18:52:421975 // Ignore responses for requests that have been aborted.
1976 if (find_op_aborted_)
1977 return;
1978
[email protected]bf5c2ff392009-07-08 16:24:331979 // Ignore responses for requests other than the one we have most recently
1980 // issued. That way we won't act on stale results when the user has
1981 // already typed in another query.
1982 if (request_id != current_find_request_id_)
1983 return;
1984
1985 if (number_of_matches == -1)
1986 number_of_matches = last_search_result_.number_of_matches();
1987 if (active_match_ordinal == -1)
1988 active_match_ordinal = last_search_result_.active_match_ordinal();
1989
1990 gfx::Rect selection = selection_rect;
1991 if (selection.IsEmpty())
1992 selection = last_search_result_.selection_rect();
1993
1994 // Notify the UI, automation and any other observers that a find result was
1995 // found.
1996 last_search_result_ = FindNotificationDetails(request_id, number_of_matches,
1997 selection, active_match_ordinal,
1998 final_update);
1999 NotificationService::current()->Notify(
2000 NotificationType::FIND_RESULT_AVAILABLE,
2001 Source<TabContents>(this),
2002 Details<FindNotificationDetails>(&last_search_result_));
2003}
2004
2005void TabContents::GoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:542006 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
2007 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
2008 if (!entry)
2009 return;
2010 // Note that we don't call NavigationController::GotToOffset() as we don't
2011 // want to create a pending navigation entry (it might end up lingering
2012 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:522013 entry->set_transition_type(entry->transition_type() |
2014 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542015 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2016 }
[email protected]bf5c2ff392009-07-08 16:24:332017}
2018
[email protected]bf5c2ff392009-07-08 16:24:332019void TabContents::OnMissingPluginStatus(int status) {
2020#if defined(OS_WIN)
2021// TODO(PORT): pull in when plug-ins work
2022 GetPluginInstaller()->OnMissingPluginStatus(status);
2023#endif
2024}
2025
2026void TabContents::OnCrashedPlugin(const FilePath& plugin_path) {
[email protected]bf5c2ff392009-07-08 16:24:332027 DCHECK(!plugin_path.value().empty());
2028
2029 std::wstring plugin_name = plugin_path.ToWStringHack();
[email protected]45446a52010-11-04 17:41:002030 WebPluginInfo plugin_info;
2031 if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath(
2032 plugin_path, &plugin_info) &&
2033 !plugin_info.name.empty()) {
2034 plugin_name = UTF16ToWide(plugin_info.name);
[email protected]996fd702009-09-04 19:12:372035#if defined(OS_MACOSX)
[email protected]45446a52010-11-04 17:41:002036 // Many plugins on the Mac have .plugin in the actual name, which looks
2037 // terrible, so look for that and strip it off if present.
2038 const std::wstring plugin_extension(L".plugin");
2039 if (EndsWith(plugin_name, plugin_extension, true))
2040 plugin_name.erase(plugin_name.length() - plugin_extension.length());
[email protected]996fd702009-09-04 19:12:372041#endif // OS_MACOSX
[email protected]bf5c2ff392009-07-08 16:24:332042 }
[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
[email protected]38789d82010-11-17 06:03:442057void TabContents::OnDidGetApplicationInfo(int32 page_id,
2058 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512059 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332060
[email protected]ed5431872009-11-17 08:39:512061 if (delegate())
2062 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332063}
2064
[email protected]bb461532010-11-26 21:50:232065void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2066 if (delegate())
2067 delegate()->OnInstallApplication(this, info);
2068}
2069
[email protected]851b1eb2010-08-09 13:32:292070void TabContents::OnDisabledOutdatedPlugin(const string16& name,
2071 const GURL& update_url) {
2072 new DisabledPluginInfoBar(this, name, update_url);
2073}
2074
[email protected]a2cf65eb2010-01-18 08:20:382075void TabContents::OnPageContents(const GURL& url,
2076 int renderer_process_id,
2077 int32 page_id,
[email protected]e5106202010-06-11 21:12:362078 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102079 const std::string& language,
2080 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382081 // Don't index any https pages. People generally don't want their bank
2082 // accounts, etc. indexed on their computer, especially since some of these
2083 // things are not marked cachable.
2084 // TODO(brettw) we may want to consider more elaborate heuristics such as
2085 // the cachability of the page. We may also want to consider subframes (this
2086 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272087 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2088 // content indexing for chromeos in some future releases.
2089#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382090 if (!url.SchemeIsSecure()) {
2091 Profile* p = profile();
2092 if (p && !p->IsOffTheRecord()) {
2093 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2094 if (hs)
2095 hs->SetPageContents(url, contents);
2096 }
2097 }
[email protected]ccd40a52010-05-11 16:15:272098#endif
[email protected]a8a81292010-01-21 00:32:452099
[email protected]1c57b7b2010-07-12 17:38:102100 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452101
2102 std::string lang = language;
2103 NotificationService::current()->Notify(
2104 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152105 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452106 Details<std::string>(&lang));
[email protected]a2cf65eb2010-01-18 08:20:382107}
2108
[email protected]7e0831b2010-02-01 08:45:152109void TabContents::OnPageTranslated(int32 page_id,
2110 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162111 const std::string& translated_lang,
2112 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552113 language_state_.set_current_language(translated_lang);
2114 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162115 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152116 NotificationService::current()->Notify(
2117 NotificationType::PAGE_TRANSLATED,
2118 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162119 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152120}
2121
[email protected]ce833282010-11-04 15:48:392122void TabContents::OnSetSuggestions(
2123 int32 page_id,
2124 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262125 if (delegate())
[email protected]ce833282010-11-04 15:48:392126 delegate()->OnSetSuggestions(page_id, suggestions);
2127}
2128
2129void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2130 if (delegate())
2131 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262132}
2133
[email protected]bf5c2ff392009-07-08 16:24:332134void TabContents::DidStartProvisionalLoadForFrame(
2135 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182136 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332137 bool is_main_frame,
[email protected]ea51f1f2010-12-01 10:07:272138 bool is_error_page,
[email protected]bf5c2ff392009-07-08 16:24:332139 const GURL& url) {
2140 ProvisionalLoadDetails details(is_main_frame,
2141 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412142 url, std::string(), false,
2143 is_error_page, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332144 NotificationService::current()->Notify(
2145 NotificationType::FRAME_PROVISIONAL_LOAD_START,
2146 Source<NavigationController>(&controller_),
2147 Details<ProvisionalLoadDetails>(&details));
[email protected]4f8452d12010-09-02 16:13:142148 if (is_main_frame) {
[email protected]ea51f1f2010-12-01 10:07:272149 // If we're displaying a network error page do not reset the content
2150 // settings delegate's cookies so the user has a chance to modify cookie
2151 // settings.
2152 if (!is_error_page)
2153 content_settings_delegate_->ClearCookieSpecificContentSettings();
[email protected]4f8452d12010-09-02 16:13:142154 content_settings_delegate_->ClearGeolocationContentSettings();
2155 }
[email protected]bf5c2ff392009-07-08 16:24:332156}
2157
2158void TabContents::DidStartReceivingResourceResponse(
[email protected]3dbb80b2010-02-09 22:41:202159 const ResourceRequestDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332160 NotificationService::current()->Notify(
2161 NotificationType::RESOURCE_RESPONSE_STARTED,
2162 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202163 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332164}
2165
[email protected]3dbb80b2010-02-09 22:41:202166void TabContents::DidRedirectResource(
2167 const ResourceRedirectDetails& details) {
[email protected]bf5c2ff392009-07-08 16:24:332168 NotificationService::current()->Notify(
2169 NotificationType::RESOURCE_RECEIVED_REDIRECT,
2170 Source<NavigationController>(&controller()),
[email protected]3dbb80b2010-02-09 22:41:202171 Details<const ResourceRequestDetails>(&details));
[email protected]bf5c2ff392009-07-08 16:24:332172}
2173
2174void TabContents::DidLoadResourceFromMemoryCache(
2175 const GURL& url,
2176 const std::string& frame_origin,
2177 const std::string& main_frame_origin,
2178 const std::string& security_info) {
2179 // Send out a notification that we loaded a resource from our memory cache.
[email protected]c88d24f12010-09-02 02:07:442180 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
[email protected]bf5c2ff392009-07-08 16:24:332181 SSLManager::DeserializeSecurityInfo(security_info,
2182 &cert_id, &cert_status,
[email protected]fc7de492010-07-12 14:49:042183 &security_bits,
2184 &connection_status);
[email protected]bf5c2ff392009-07-08 16:24:332185 LoadFromMemoryCacheDetails details(url, frame_origin, main_frame_origin,
[email protected]8cb5d5b2010-02-09 11:36:162186 GetRenderProcessHost()->id(), cert_id,
2187 cert_status);
[email protected]bf5c2ff392009-07-08 16:24:332188
2189 NotificationService::current()->Notify(
2190 NotificationType::LOAD_FROM_MEMORY_CACHE,
2191 Source<NavigationController>(&controller_),
2192 Details<LoadFromMemoryCacheDetails>(&details));
2193}
2194
[email protected]e3d60e5d2009-09-25 21:08:292195void TabContents::DidDisplayInsecureContent() {
[email protected]f17a0ee2010-05-17 17:38:472196 displayed_insecure_content_ = true;
2197 SSLManager::NotifySSLInternalStateChanged();
[email protected]e3d60e5d2009-09-25 21:08:292198}
2199
2200void TabContents::DidRunInsecureContent(const std::string& security_origin) {
[email protected]09843b5f2009-09-26 08:30:592201 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
[email protected]e3d60e5d2009-09-25 21:08:292202}
2203
[email protected]bf5c2ff392009-07-08 16:24:332204void TabContents::DidFailProvisionalLoadWithError(
2205 RenderViewHost* render_view_host,
[email protected]4b8e2b02010-11-30 09:15:182206 int64 frame_id,
[email protected]bf5c2ff392009-07-08 16:24:332207 bool is_main_frame,
2208 int error_code,
2209 const GURL& url,
2210 bool showing_repost_interstitial) {
2211 if (net::ERR_ABORTED == error_code) {
2212 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
2213 // This means that the interstitial won't be torn down properly, which is
2214 // bad. But if we have an interstitial, go back to another tab type, and
2215 // then load the same interstitial again, we could end up getting the first
2216 // interstitial's "failed" message (as a result of the cancel) when we're on
2217 // the second one.
2218 //
2219 // We can't tell this apart, so we think we're tearing down the current page
2220 // which will cause a crash later one. There is also some code in
2221 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
2222 // out because of this problem.
2223 //
2224 // http://code.google.com/p/chromium/issues/detail?id=2855
2225 // Because this will not tear down the interstitial properly, if "back" is
2226 // back to another tab type, the interstitial will still be somewhat alive
2227 // in the previous tab type. If you navigate somewhere that activates the
2228 // tab with the interstitial again, you'll see a flash before the new load
2229 // commits of the interstitial page.
2230 if (showing_interstitial_page()) {
2231 LOG(WARNING) << "Discarding message during interstitial.";
2232 return;
2233 }
2234
2235 // This will discard our pending entry if we cancelled the load (e.g., if we
2236 // decided to download the file instead of load it). Only discard the
2237 // pending entry if the URLs match, otherwise the user initiated a navigate
2238 // before the page loaded so that the discard would discard the wrong entry.
2239 NavigationEntry* pending_entry = controller_.pending_entry();
2240 if (pending_entry && pending_entry->url() == url) {
2241 controller_.DiscardNonCommittedEntries();
2242 // Update the URL display.
2243 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
2244 }
2245
2246 render_manager_.RendererAbortedProvisionalLoad(render_view_host);
2247 }
2248
2249 // Send out a notification that we failed a provisional load with an error.
2250 ProvisionalLoadDetails details(is_main_frame,
2251 controller_.IsURLInPageNavigation(url),
[email protected]dd0aafd2010-12-02 13:13:412252 url, std::string(), false, false, frame_id);
[email protected]bf5c2ff392009-07-08 16:24:332253 details.set_error_code(error_code);
2254
2255 NotificationService::current()->Notify(
2256 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
2257 Source<NavigationController>(&controller_),
2258 Details<ProvisionalLoadDetails>(&details));
2259}
2260
[email protected]4b8e2b02010-11-30 09:15:182261void TabContents::DocumentLoadedInFrame(int64 frame_id) {
[email protected]bf5c2ff392009-07-08 16:24:332262 controller_.DocumentLoadedInFrame();
[email protected]622474d2010-11-04 09:21:082263 NotificationService::current()->Notify(
2264 NotificationType::FRAME_DOM_CONTENT_LOADED,
2265 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182266 Details<int64>(&frame_id));
[email protected]bf5c2ff392009-07-08 16:24:332267}
2268
[email protected]4b8e2b02010-11-30 09:15:182269void TabContents::DidFinishLoad(int64 frame_id) {
[email protected]fdd94a02010-11-05 08:07:172270 NotificationService::current()->Notify(
2271 NotificationType::FRAME_DID_FINISH_LOAD,
2272 Source<NavigationController>(&controller_),
[email protected]4b8e2b02010-11-30 09:15:182273 Details<int64>(&frame_id));
[email protected]fdd94a02010-11-05 08:07:172274}
2275
[email protected]dcd5b332010-08-11 08:55:182276void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562277 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242278 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562279}
2280
[email protected]8d3347f2009-07-09 22:00:212281RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322282 return view_.get();
2283}
2284
[email protected]8d3347f2009-07-09 22:00:212285RenderViewHostDelegate::RendererManagement*
2286TabContents::GetRendererManagementDelegate() {
2287 return &render_manager_;
2288}
2289
[email protected]bf5c2ff392009-07-08 16:24:332290RenderViewHostDelegate::BrowserIntegration*
[email protected]8d3347f2009-07-09 22:00:212291 TabContents::GetBrowserIntegrationDelegate() {
2292 return this;
[email protected]bf5c2ff392009-07-08 16:24:332293}
2294
[email protected]8d3347f2009-07-09 22:00:212295RenderViewHostDelegate::Resource* TabContents::GetResourceDelegate() {
2296 return this;
[email protected]bf5c2ff392009-07-08 16:24:332297}
2298
[email protected]46ba9082010-06-22 10:00:582299RenderViewHostDelegate::ContentSettings*
2300TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552301 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582302}
2303
[email protected]8d3347f2009-07-09 22:00:212304RenderViewHostDelegate::Save* TabContents::GetSaveDelegate() {
[email protected]420ae012009-04-24 05:16:322305 return save_package_.get(); // May be NULL, but we can return NULL.
2306}
2307
[email protected]8d3347f2009-07-09 22:00:212308RenderViewHostDelegate::Printing* TabContents::GetPrintingDelegate() {
[email protected]12802702010-07-09 19:43:092309 return printing_.get();
[email protected]8d3347f2009-07-09 22:00:212310}
2311
2312RenderViewHostDelegate::FavIcon* TabContents::GetFavIconDelegate() {
2313 return &fav_icon_helper_;
2314}
2315
[email protected]e8dbd674b2010-03-11 18:34:402316RenderViewHostDelegate::Autocomplete* TabContents::GetAutocompleteDelegate() {
[email protected]6db0def92010-03-02 19:55:452317 if (autocomplete_history_manager_.get() == NULL)
2318 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
2319 return autocomplete_history_manager_.get();
[email protected]bf5c2ff392009-07-08 16:24:332320}
2321
[email protected]21674df2009-10-28 19:51:212322RenderViewHostDelegate::AutoFill* TabContents::GetAutoFillDelegate() {
[email protected]cf28ec52010-04-09 22:56:342323 return GetAutoFillManager();
[email protected]21674df2009-10-28 19:51:212324}
2325
[email protected]1f18184a2010-07-21 19:34:492326RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2327 return GetSSLHelper();
2328}
2329
[email protected]b5977a0c2010-08-24 19:46:262330RenderViewHostDelegate::FileSelect* TabContents::GetFileSelectDelegate() {
2331 if (file_select_helper_.get() == NULL)
[email protected]ba70d082010-09-10 16:54:492332 file_select_helper_.reset(new FileSelectHelper(profile()));
[email protected]b5977a0c2010-08-24 19:46:262333 return file_select_helper_.get();
2334}
2335
[email protected]fd571bb2010-03-19 01:23:542336AutomationResourceRoutingDelegate*
2337TabContents::GetAutomationResourceRoutingDelegate() {
2338 return delegate();
2339}
2340
[email protected]ced90ae12010-02-20 02:06:162341RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2342 return bookmark_drag_;
2343}
2344
2345void TabContents::SetBookmarkDragDelegate(
2346 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2347 bookmark_drag_ = bookmark_drag;
2348}
2349
[email protected]9fb83e82010-07-02 18:24:552350TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2351 return content_settings_delegate_.get();
2352}
2353
[email protected]93623c5d2009-12-10 21:40:322354RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462355 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512356}
2357
[email protected]57c6a652009-05-04 07:58:342358TabContents* TabContents::GetAsTabContents() {
2359 return this;
2360}
2361
[email protected]7b291f92009-08-14 05:43:532362ViewType::Type TabContents::GetRenderViewType() const {
2363 return ViewType::TAB_CONTENTS;
2364}
2365
2366int TabContents::GetBrowserWindowID() const {
2367 return controller().window_id().id();
2368}
2369
[email protected]420ae012009-04-24 05:16:322370void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062371 NotificationService::current()->Notify(
2372 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2373 Source<TabContents>(this),
2374 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322375 NavigationEntry* entry = controller_.GetActiveEntry();
2376 if (!entry)
2377 return;
2378
2379 // When we're creating views, we're still doing initial setup, so we always
2380 // use the pending DOM UI rather than any possibly existing committed one.
2381 if (render_manager_.pending_dom_ui()) {
2382 render_manager_.pending_dom_ui()->RenderViewCreated(render_view_host);
2383 }
2384
2385 if (entry->IsViewSourceMode()) {
2386 // Put the renderer in view source mode.
2387 render_view_host->Send(
2388 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2389 }
[email protected]0666aef2009-05-13 19:48:082390
2391 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322392}
2393
2394void TabContents::RenderViewReady(RenderViewHost* rvh) {
2395 if (rvh != render_view_host()) {
2396 // Don't notify the world, since this came from a renderer in the
2397 // background.
2398 return;
2399 }
2400
2401 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302402 bool was_crashed = is_crashed();
[email protected]420ae012009-04-24 05:16:322403 SetIsCrashed(false);
[email protected]9d8a4642009-07-29 17:25:302404
2405 // Restore the focus to the tab (otherwise the focus will be on the top
2406 // window).
[email protected]484ae5912010-09-29 19:16:142407 if (was_crashed && !FocusLocationBarByDefault() &&
2408 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302409 Focus();
[email protected]484ae5912010-09-29 19:16:142410 }
[email protected]420ae012009-04-24 05:16:322411}
2412
2413void TabContents::RenderViewGone(RenderViewHost* rvh) {
2414 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092415 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322416 return;
2417 if (rvh != render_view_host()) {
2418 // The pending page's RenderViewHost is gone.
2419 return;
2420 }
2421
2422 SetIsLoading(false, NULL);
2423 NotifyDisconnected();
2424 SetIsCrashed(true);
2425
[email protected]ff9efc62010-02-18 22:10:542426 // Remove all infobars.
[email protected]e5430c92010-02-18 22:39:212427 for (int i = infobar_delegate_count() - 1; i >=0 ; --i)
[email protected]ff9efc62010-02-18 22:10:542428 RemoveInfoBar(GetInfoBarDelegateAt(i));
2429
[email protected]8e537302009-06-10 21:19:582430 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552431 // Only do this if we're not in browser shutdown, so that TabContents
2432 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2433 // visible do not flash a sad tab page.
2434 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
2435 view_->OnTabCrashed();
[email protected]420ae012009-04-24 05:16:322436
2437 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002438 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322439}
2440
[email protected]2e4633c2009-07-09 16:58:062441void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2442 NotificationService::current()->Notify(
2443 NotificationType::RENDER_VIEW_HOST_DELETED,
2444 Source<TabContents>(this),
2445 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482446 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062447}
2448
[email protected]420ae012009-04-24 05:16:322449void TabContents::DidNavigate(RenderViewHost* rvh,
2450 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372451 int extra_invalidate_flags = 0;
2452
2453 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]20ede072009-10-06 00:28:352454 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372455
[email protected]420ae012009-04-24 05:16:322456 render_manager_.DidNavigateMainFrame(rvh);
2457
[email protected]20ede072009-10-06 00:28:352458 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372459 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372460 }
2461
[email protected]420ae012009-04-24 05:16:322462 // Update the site of the SiteInstance if it doesn't have one yet.
2463 if (!GetSiteInstance()->has_site())
2464 GetSiteInstance()->SetSite(params.url);
2465
2466 // Need to update MIME type here because it's referred to in
2467 // UpdateNavigationCommands() called by RendererDidNavigate() to
2468 // determine whether or not to enable the encoding menu.
2469 // It's updated only for the main frame. For a subframe,
2470 // RenderView::UpdateURL does not set params.contents_mime_type.
2471 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2472 // TODO(jungshik): Add a test for the encoding menu to avoid
2473 // regressing it again.
2474 if (PageTransition::IsMainFrame(params.transition))
2475 contents_mime_type_ = params.contents_mime_type;
2476
2477 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372478 bool did_navigate = controller_.RendererDidNavigate(
2479 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392480
[email protected]a9c0bfe2010-09-17 08:35:222481 // Send notification about committed provisional loads. This notification is
2482 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2483 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2484 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072485 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2486 // that is not recorded in the navigation history. For the purpose of
2487 // tracking navigation events, we treat this event as a sub frame navigation
2488 // event.
2489 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2490 ProvisionalLoadDetails load_details(
2491 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412492 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222493 load_details.set_transition_type(params.transition);
2494 // Whether or not a page transition was triggered by going backward or
2495 // forward in the history is only stored in the navigation controller's
2496 // entry list.
2497 if (did_navigate &&
2498 (controller_.GetActiveEntry()->transition_type() &
2499 PageTransition::FORWARD_BACK)) {
2500 load_details.set_transition_type(
2501 params.transition | PageTransition::FORWARD_BACK);
2502 }
2503 NotificationService::current()->Notify(
2504 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2505 Source<NavigationController>(&controller_),
2506 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222507 }
2508
[email protected]3e90d4a2009-07-03 17:38:392509 // Update history. Note that this needs to happen after the entry is complete,
2510 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582511 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392512 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582513 // URLs, we use a data: URL as the real value. We actually want to save the
2514 // about: URL to the history db and keep the data: URL hidden. This is what
2515 // the TabContents' URL getter does.
2516 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2517 CreateHistoryAddPageArgs(GetURL(), details, params));
2518 if (!delegate() ||
2519 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2520 details.type)) {
2521 UpdateHistoryForNavigation(add_page_args);
2522 }
[email protected]3e90d4a2009-07-03 17:38:392523 }
2524
[email protected]76543b92009-08-31 17:27:452525 if (!did_navigate)
2526 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322527
2528 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2529 // for the appropriate notification (best) or you can add it to
2530 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2531 // necessary, please).
2532
2533 // Run post-commit tasks.
2534 if (details.is_main_frame)
2535 DidNavigateMainFramePostCommit(details, params);
2536 DidNavigateAnyFramePostCommit(rvh, details, params);
2537}
2538
2539void TabContents::UpdateState(RenderViewHost* rvh,
2540 int32 page_id,
2541 const std::string& state) {
2542 DCHECK(rvh == render_view_host());
2543
2544 // We must be prepared to handle state updates for any page, these occur
2545 // when the user is scrolling and entering form data, as well as when we're
2546 // leaving a page, in which case our state may have already been moved to
2547 // the next page. The navigation controller will look up the appropriate
2548 // NavigationEntry and update it when it is notified via the delegate.
2549
2550 int entry_index = controller_.GetEntryIndexWithPageID(
2551 GetSiteInstance(), page_id);
2552 if (entry_index < 0)
2553 return;
2554 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2555
2556 if (state == entry->content_state())
2557 return; // Nothing to update.
2558 entry->set_content_state(state);
2559 controller_.NotifyEntryChanged(entry, entry_index);
2560}
2561
2562void TabContents::UpdateTitle(RenderViewHost* rvh,
2563 int32 page_id, const std::wstring& title) {
2564 // If we have a title, that's a pretty good indication that we've started
2565 // getting useful data.
2566 SetNotWaitingForResponse();
2567
2568 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482569 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582570 page_id);
[email protected]420ae012009-04-24 05:16:322571 if (!entry || !UpdateTitleForEntry(entry, title))
2572 return;
2573
2574 // Broadcast notifications when the UI should be updated.
2575 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032576 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322577}
2578
[email protected]420ae012009-04-24 05:16:322579void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402580 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322581 set_encoding(encoding);
2582}
2583
2584void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2585 if (delegate())
2586 delegate()->UpdateTargetURL(this, url);
2587}
2588
2589void TabContents::UpdateThumbnail(const GURL& url,
2590 const SkBitmap& bitmap,
2591 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442592 if (profile()->IsOffTheRecord())
2593 return;
2594
[email protected]420ae012009-04-24 05:16:322595 // Tell History about this thumbnail
[email protected]2ec53b52010-09-21 03:24:492596 if (history::TopSites::IsEnabled()) {
[email protected]e6baed562010-11-02 22:33:442597 history::TopSites* ts = profile()->GetTopSites();
2598 if (ts)
2599 ts->SetPageThumbnail(url, bitmap, score);
[email protected]449478302009-06-09 20:04:282600 } else {
[email protected]e6baed562010-11-02 22:33:442601 HistoryService* hs =
2602 profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
2603 if (hs)
[email protected]449478302009-06-09 20:04:282604 hs->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322605 }
2606}
2607
[email protected]c4e98902010-06-01 10:20:142608void TabContents::UpdateInspectorSetting(const std::string& key,
2609 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052610 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082611}
2612
[email protected]45aafc92010-06-07 14:18:532613void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052614 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532615}
2616
[email protected]420ae012009-04-24 05:16:322617void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292618 // The UI may be in an event-tracking loop, such as between the
2619 // mouse-down and mouse-up in text selection or a button click.
2620 // Defer the close until after tracking is complete, so that we
2621 // don't free objects out from under the UI.
2622 // TODO(shess): This could probably be integrated with the
2623 // IsDoingDrag() test below. Punting for now because I need more
2624 // research to understand how this impacts platforms other than Mac.
2625 // TODO(shess): This could get more fine-grained. For instance,
2626 // closing a tab in another window while selecting text in the
2627 // current window's Omnibox should be just fine.
2628 if (view()->IsEventTracking()) {
2629 view()->CloseTabAfterEventTracking();
2630 return;
2631 }
2632
[email protected]24a4d1062009-07-10 23:10:422633 // If we close the tab while we're in the middle of a drag, we'll crash.
2634 // Instead, cancel the drag and close it as soon as the drag ends.
2635 if (view()->IsDoingDrag()) {
2636 view()->CancelDragAndCloseTab();
2637 return;
2638 }
2639
[email protected]420ae012009-04-24 05:16:322640 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2641 if (delegate() && rvh == render_view_host())
2642 delegate()->CloseContents(this);
2643}
2644
2645void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2646 if (delegate() && delegate()->IsPopup(this))
2647 delegate()->MoveContents(this, new_bounds);
2648}
2649
[email protected]7ab1e7d62009-10-14 23:32:012650void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322651 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492652
[email protected]de4761b2010-12-07 21:05:212653 if (delegate()) {
2654 bool is_print_preview_tab =
2655 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2656 if (content_restrictions_ || is_print_preview_tab) {
2657 content_restrictions_= is_print_preview_tab ?
2658 CONTENT_RESTRICTION_PRINT : 0;
2659 delegate()->ContentRestrictionsChanged(this);
2660 }
[email protected]9e823662010-10-13 23:36:002661 }
[email protected]3c9e1872010-11-18 16:17:492662
2663 // Notify observers about navigation.
2664 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2665 DidStartLoading());
[email protected]420ae012009-04-24 05:16:322666}
2667
[email protected]7ab1e7d62009-10-14 23:32:012668void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322669 scoped_ptr<LoadNotificationDetails> details;
2670
2671 NavigationEntry* entry = controller_.GetActiveEntry();
2672 // An entry may not exist for a stop when loading an initial blank page or
2673 // if an iframe injected by script into a blank page finishes loading.
2674 if (entry) {
[email protected]420ae012009-04-24 05:16:322675 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2676
2677 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542678 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322679 entry->transition_type(),
2680 elapsed,
2681 &controller_,
2682 controller_.GetCurrentEntryIndex()));
2683 }
2684
[email protected]420ae012009-04-24 05:16:322685 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492686
2687 // Notify observers about navigation.
2688 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2689 DidStopLoading());
[email protected]420ae012009-04-24 05:16:322690}
2691
[email protected]25497492010-09-11 15:15:082692void TabContents::DocumentOnLoadCompletedInMainFrame(
2693 RenderViewHost* render_view_host,
2694 int32 page_id) {
2695 NotificationService::current()->Notify(
2696 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2697 Source<TabContents>(this),
2698 Details<int>(&page_id));
2699}
2700
[email protected]420ae012009-04-24 05:16:322701void TabContents::DidRedirectProvisionalLoad(int32 page_id,
2702 const GURL& source_url,
2703 const GURL& target_url) {
2704 NavigationEntry* entry;
2705 if (page_id == -1)
2706 entry = controller_.pending_entry();
2707 else
2708 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
2709 if (!entry || entry->url() != source_url)
2710 return;
2711 entry->set_url(target_url);
2712}
2713
[email protected]420ae012009-04-24 05:16:322714void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2715 WindowOpenDisposition disposition) {
2716 if (render_manager_.dom_ui()) {
2717 // When we're a DOM UI, it will provide a page transition type for us (this
2718 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2719 // generated suggestions).
2720 //
2721 // Note also that we hide the referrer for DOM UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162722 // want web sites to see a referrer of "chrome://blah" (and some
2723 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322724 // send to the site), so we send no referrer.
2725 OpenURL(url, GURL(), disposition,
2726 render_manager_.dom_ui()->link_transition_type());
2727 } else {
2728 OpenURL(url, referrer, disposition, PageTransition::LINK);
2729 }
2730}
2731
[email protected]1ee614862009-07-06 20:29:182732void TabContents::DomOperationResponse(const std::string& json_string,
2733 int automation_id) {
2734}
2735
[email protected]8b8e7c92010-08-19 18:05:562736void TabContents::ProcessDOMUIMessage(
2737 const ViewHostMsg_DomMessage_Params& params) {
[email protected]420ae012009-04-24 05:16:322738 if (!render_manager_.dom_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442739 // This can happen if someone uses window.open() to open an extension URL
2740 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562741 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322742 return;
2743 }
[email protected]8b8e7c92010-08-19 18:05:562744 render_manager_.dom_ui()->ProcessDOMUIMessage(params);
[email protected]420ae012009-04-24 05:16:322745}
2746
2747void TabContents::ProcessExternalHostMessage(const std::string& message,
2748 const std::string& origin,
2749 const std::string& target) {
2750 if (delegate())
2751 delegate()->ForwardMessageToExternalHost(message, origin, target);
2752}
2753
[email protected]420ae012009-04-24 05:16:322754void TabContents::RunJavaScriptMessage(
2755 const std::wstring& message,
2756 const std::wstring& default_prompt,
2757 const GURL& frame_url,
2758 const int flags,
2759 IPC::Message* reply_msg,
2760 bool* did_suppress_message) {
2761 // Suppress javascript messages when requested and when inside a constrained
2762 // popup window (because that activates them and breaks them out of the
2763 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552764 // Also suppress messages when showing an interstitial. The interstitial is
2765 // shown over the previous page, we don't want the hidden page dialogs to
2766 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502767 bool suppress_this_message =
2768 suppress_javascript_messages_ ||
2769 showing_interstitial_page() ||
2770 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322771 if (delegate())
2772 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312773 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322774
2775 *did_suppress_message = suppress_this_message;
2776
2777 if (!suppress_this_message) {
2778 base::TimeDelta time_since_last_message(
2779 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2780 bool show_suppress_checkbox = false;
2781 // Show a checkbox offering to suppress further messages if this message is
2782 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2783 if (time_since_last_message <
2784 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2785 show_suppress_checkbox = true;
2786
[email protected]d6ad7442010-09-05 19:06:522787 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2788 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322789 } else {
2790 // If we are suppressing messages, just reply as is if the user immediately
2791 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542792 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322793 }
2794}
2795
2796void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2797 IPC::Message* reply_msg) {
[email protected]8f55e802010-12-06 18:11:502798 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2799 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2800 std::wstring());
2801 return;
2802 }
[email protected]7ab1e7d62009-10-14 23:32:012803 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222804 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322805}
2806
2807void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2808 const std::string& json_arguments,
2809 IPC::Message* reply_msg) {
2810 if (delegate()) {
2811 HtmlDialogUIDelegate* dialog_delegate =
2812 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222813 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322814 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2815 }
2816}
2817
[email protected]c4aa86962010-11-24 23:08:042818void TabContents::PasswordFormsFound(
2819 const std::vector<webkit_glue::PasswordForm>& forms) {
2820 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2821 PasswordFormsFound(forms));
2822}
2823
2824void TabContents::PasswordFormsVisible(
2825 const std::vector<webkit_glue::PasswordForm>& visible_forms) {
2826 FOR_EACH_OBSERVER(WebNavigationObserver, web_navigation_observers_,
2827 PasswordFormsVisible(visible_forms));
2828}
2829
[email protected]420ae012009-04-24 05:16:322830// Checks to see if we should generate a keyword based on the OSDD, and if
2831// necessary uses TemplateURLFetcher to download the OSDD and create a keyword.
[email protected]2de7e002010-10-11 22:58:202832void TabContents::PageHasOSDD(
2833 RenderViewHost* render_view_host,
2834 int32 page_id,
2835 const GURL& url,
2836 const ViewHostMsg_PageHasOSDD_Type& msg_provider_type) {
[email protected]0b5b85c2010-10-11 23:00:122837 // Make sure page_id is the current page and other basic checks.
[email protected]420ae012009-04-24 05:16:322838 DCHECK(url.is_valid());
2839 if (!IsActiveEntry(page_id))
2840 return;
[email protected]420ae012009-04-24 05:16:322841 if (!profile()->GetTemplateURLFetcher())
2842 return;
[email protected]420ae012009-04-24 05:16:322843 if (profile()->IsOffTheRecord())
2844 return;
2845
[email protected]2de7e002010-10-11 22:58:202846 TemplateURLFetcher::ProviderType provider_type;
2847 switch (msg_provider_type.type) {
2848 case ViewHostMsg_PageHasOSDD_Type::AUTODETECTED_PROVIDER:
2849 provider_type = TemplateURLFetcher::AUTODETECTED_PROVIDER;
2850 break;
2851
2852 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_DEFAULT_PROVIDER:
2853 provider_type = TemplateURLFetcher::EXPLICIT_DEFAULT_PROVIDER;
2854 break;
2855
2856 case ViewHostMsg_PageHasOSDD_Type::EXPLICIT_PROVIDER:
2857 provider_type = TemplateURLFetcher::EXPLICIT_PROVIDER;
2858 break;
2859
2860 default:
2861 NOTREACHED();
2862 return;
2863 }
2864
[email protected]420ae012009-04-24 05:16:322865 const NavigationEntry* entry = controller_.GetLastCommittedEntry();
2866 DCHECK(entry);
2867
2868 const NavigationEntry* base_entry = entry;
2869 if (IsFormSubmit(base_entry)) {
2870 // If the current page is a form submit, find the last page that was not
2871 // a form submit and use its url to generate the keyword from.
2872 int index = controller_.last_committed_entry_index() - 1;
2873 while (index >= 0 && IsFormSubmit(controller_.GetEntryAtIndex(index)))
2874 index--;
2875 if (index >= 0)
2876 base_entry = controller_.GetEntryAtIndex(index);
2877 else
2878 base_entry = NULL;
2879 }
2880
2881 // We want to use the user typed URL if available since that represents what
2882 // the user typed to get here, and fall back on the regular URL if not.
2883 if (!base_entry)
2884 return;
2885 GURL keyword_url = base_entry->user_typed_url().is_valid() ?
2886 base_entry->user_typed_url() : base_entry->url();
2887 if (!keyword_url.is_valid())
2888 return;
[email protected]2de7e002010-10-11 22:58:202889
[email protected]0b5b85c2010-10-11 23:00:122890 std::wstring keyword = TemplateURLModel::GenerateKeyword(
2891 keyword_url,
2892 provider_type == TemplateURLFetcher::AUTODETECTED_PROVIDER);
[email protected]a88dbdd52010-01-15 19:25:532893
[email protected]0b5b85c2010-10-11 23:00:122894 // Download the OpenSearch description document. If this is successful, a
[email protected]420ae012009-04-24 05:16:322895 // new keyword will be created when done.
[email protected]420ae012009-04-24 05:16:322896 profile()->GetTemplateURLFetcher()->ScheduleDownload(
2897 keyword,
2898 url,
2899 base_entry->favicon().url(),
[email protected]0b5b85c2010-10-11 23:00:122900 new TemplateURLFetcherUICallbacks(this),
[email protected]2de7e002010-10-11 22:58:202901 provider_type);
[email protected]420ae012009-04-24 05:16:322902}
2903
[email protected]420ae012009-04-24 05:16:322904GURL TabContents::GetAlternateErrorPageURL() const {
2905 GURL url;
2906 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2907 if (profile()->IsOffTheRecord())
2908 return url;
2909
2910 PrefService* prefs = profile()->GetPrefs();
2911 DCHECK(prefs);
2912 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152913 url = google_util::AppendGoogleLocaleParam(
2914 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322915 url = google_util::AppendGoogleTLDParam(url);
2916 }
2917 return url;
2918}
2919
2920WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062921 Profile* profile = render_view_host()->process()->profile();
[email protected]7ccddb8c2009-08-04 17:36:552922 bool is_dom_ui = false;
[email protected]447021c2010-09-08 21:29:082923 WebPreferences web_prefs =
2924 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_dom_ui);
2925
[email protected]9beff752010-09-22 19:35:432926 // Force accelerated compositing and 2d canvas off for chrome: and
2927 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432928 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2929 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082930 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432931 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082932 }
2933
[email protected]39553442010-09-09 00:01:552934#if defined(OS_MACOSX)
2935 // Disable accelerated compositing if IOSurface's are not supported,
2936 // as is the case in 10.5.
2937 if (!IOSurfaceSupport::Initialize())
2938 web_prefs.accelerated_compositing_enabled = false;
2939#endif
2940
[email protected]447021c2010-09-08 21:29:082941 return web_prefs;
[email protected]420ae012009-04-24 05:16:322942}
2943
[email protected]fa1cf0b82010-01-15 21:49:442944void TabContents::OnIgnoredUIEvent() {
2945 if (constrained_window_count()) {
2946 ConstrainedWindow* window = *constrained_window_begin();
2947 window->FocusConstrainedWindow();
2948 }
2949}
2950
[email protected]420ae012009-04-24 05:16:322951void TabContents::OnJSOutOfMemory() {
2952 AddInfoBar(new SimpleAlertInfoBarDelegate(
[email protected]e23d3a32010-08-13 19:39:582953 this, l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT),
2954 NULL, true));
[email protected]420ae012009-04-24 05:16:322955}
2956
[email protected]420ae012009-04-24 05:16:322957void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2958 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342959 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322960 // delivered to a pending RenderViewHost. We must first run the onunload
2961 // handler of the old RenderViewHost before we can allow it to proceed.
2962 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2963 new_request_id);
2964}
2965
[email protected]420ae012009-04-24 05:16:322966void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2967 bool is_during_unload) {
2968 if (is_during_unload) {
2969 // Hang occurred while firing the beforeunload/unload handler.
2970 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112971 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322972
2973 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2974 return;
2975
2976 // If the tab hangs in the beforeunload/unload handler there's really
2977 // nothing we can do to recover. Pretend the unload listeners have
2978 // all fired and close the tab. If the hang is in the beforeunload handler
2979 // then the user will not have the option of cancelling the close.
2980 Close(rvh);
2981 return;
2982 }
2983
2984 if (render_view_host() && render_view_host()->IsRenderViewLive())
[email protected]e7b8d832009-11-20 22:41:002985 hung_renderer_dialog::ShowForTabContents(this);
[email protected]420ae012009-04-24 05:16:322986}
2987
2988void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002989 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322990}
2991
2992void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562993 net::LoadState load_state,
2994 uint64 upload_position,
2995 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322996 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562997 upload_position_ = upload_position;
2998 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292999 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:193000 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:293001 std::string host = url.host();
[email protected]ce85f602009-11-07 01:34:533002 load_state_host_ =
3003 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL);
[email protected]420ae012009-04-24 05:16:323004 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
3005 SetNotWaitingForResponse();
3006 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:503007 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:323008}
3009
[email protected]1ee614862009-07-06 20:29:183010bool TabContents::IsExternalTabContainer() const {
3011 if (!delegate())
3012 return false;
3013
3014 return delegate()->IsExternalTabContainer();
3015}
3016
[email protected]1ee614862009-07-06 20:29:183017void TabContents::DidInsertCSS() {
3018 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:323019}
3020
[email protected]546ae4e02010-12-08 14:57:193021void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:353022 NotificationService::current()->Notify(
3023 NotificationType::FOCUS_CHANGED_IN_PAGE,
3024 Source<RenderViewHost>(render_view_host()),
[email protected]546ae4e02010-12-08 14:57:193025 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:353026}
3027
[email protected]b75b8292010-10-01 07:28:253028void TabContents::UpdateZoomLimits(int minimum_percent,
3029 int maximum_percent,
3030 bool remember) {
3031 minimum_zoom_percent_ = minimum_percent;
3032 maximum_zoom_percent_ = maximum_percent;
3033 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:383034}
3035
[email protected]9e823662010-10-13 23:36:003036void TabContents::UpdateContentRestrictions(int restrictions) {
3037 content_restrictions_ = restrictions;
3038 delegate()->ContentRestrictionsChanged(this);
[email protected]166e3042010-10-12 22:42:323039}
3040
[email protected]420ae012009-04-24 05:16:323041void TabContents::BeforeUnloadFiredFromRenderManager(
3042 bool proceed,
3043 bool* proceed_to_fire_unload) {
3044 if (delegate())
3045 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
3046}
3047
[email protected]3a3d47472010-07-15 21:03:543048void TabContents::DidStartLoadingFromRenderManager(
3049 RenderViewHost* render_view_host) {
3050 DidStartLoading();
3051}
3052
3053void TabContents::RenderViewGoneFromRenderManager(
3054 RenderViewHost* render_view_host) {
3055 RenderViewGone(render_view_host);
3056}
3057
[email protected]420ae012009-04-24 05:16:323058void TabContents::UpdateRenderViewSizeForRenderManager() {
3059 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:263060 gfx::Size size = view_->GetContainerSize();
3061 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
3062 // here during container initialization and normal window size will be set
3063 // later. In case of tab duplication this resizing to 0x0 prevents setting
3064 // normal size later so just ignore it.
3065 if (!size.IsEmpty())
3066 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:323067}
3068
[email protected]3a3d47472010-07-15 21:03:543069void TabContents::NotifySwappedFromRenderManager() {
3070 NotifySwapped();
3071}
3072
3073NavigationController& TabContents::GetControllerForRenderManager() {
3074 return controller();
3075}
3076
[email protected]420ae012009-04-24 05:16:323077DOMUI* TabContents::CreateDOMUIForRenderManager(const GURL& url) {
[email protected]d82ed61e2009-06-16 02:46:223078 return DOMUIFactory::CreateDOMUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:323079}
3080
3081NavigationEntry*
3082TabContents::GetLastCommittedNavigationEntryForRenderManager() {
3083 return controller_.GetLastCommittedEntry();
3084}
3085
3086bool TabContents::CreateRenderViewForRenderManager(
3087 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:323088 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:523089
[email protected]674b3822010-08-04 04:02:513090 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:323091 return false;
3092
3093 // Now that the RenderView has been created, we need to tell it its size.
3094 rwh_view->SetSize(view_->GetContainerSize());
3095
3096 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
3097 render_view_host);
3098 return true;
3099}
3100
3101void TabContents::Observe(NotificationType type,
3102 const NotificationSource& source,
3103 const NotificationDetails& details) {
3104 switch (type.value) {
3105 case NotificationType::BOOKMARK_MODEL_LOADED:
3106 // BookmarkModel finished loading, fall through to update starred state.
3107 case NotificationType::URLS_STARRED: {
3108 // Somewhere, a URL has been starred.
3109 // Ignore notifications for profiles other than our current one.
3110 Profile* source_profile = Source<Profile>(source).ptr();
3111 if (!source_profile || !source_profile->IsSameProfile(profile()))
3112 return;
3113
3114 UpdateStarredStateForCurrentURL();
3115 break;
3116 }
3117 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:513118 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:323119 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
3120 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
3121 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:533122 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
3123 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:323124 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:173125 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
3126 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:323127 } else {
3128 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
3129 }
3130 break;
3131 }
3132 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
3133 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
3134 break;
3135
3136 case NotificationType::NAV_ENTRY_COMMITTED: {
3137 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
3138
3139 NavigationController::LoadCommittedDetails& committed_details =
3140 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
3141 ExpireInfoBars(committed_details);
3142 break;
3143 }
3144
[email protected]d3ba77272009-09-03 00:06:093145#if defined(OS_LINUX)
3146 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:543147 renderer_preferences_util::UpdateFromSystemSettings(
3148 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:093149 render_view_host()->SyncRendererPrefs();
3150 break;
3151 }
3152#endif
3153
[email protected]6c32ce72010-03-08 05:18:063154 case NotificationType::USER_STYLE_SHEET_UPDATED:
3155 UpdateWebPreferences();
3156 break;
3157
[email protected]79580c62010-02-02 02:36:253158 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:453159 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:253160 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:493161 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:293162 if (entry)
[email protected]da0c8e92010-02-09 23:25:493163 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:293164 if (settings_details.ptr()->update_all() ||
3165 settings_details.ptr()->pattern().Matches(entry_url)) {
3166 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:233167 profile()->GetHostContentSettingsMap()->
3168 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:253169 }
3170 break;
3171 }
3172
[email protected]e5adff72010-06-14 18:13:063173 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:573174 break;
[email protected]a888b29e62010-04-01 13:38:573175
3176 case NotificationType::EXTENSION_UNLOADED:
[email protected]e5adff72010-06-14 18:13:063177 case NotificationType::EXTENSION_UNLOADED_DISABLED:
[email protected]a888b29e62010-04-01 13:38:573178 break;
[email protected]a888b29e62010-04-01 13:38:573179
[email protected]88152052010-10-01 04:05:183180 case NotificationType::GOOGLE_URL_UPDATED:
3181 UpdateAlternateErrorPageURL();
3182 break;
3183
[email protected]420ae012009-04-24 05:16:323184 default:
3185 NOTREACHED();
3186 }
3187}
[email protected]aacd7cc2009-09-02 14:51:103188
[email protected]9adb9692010-10-29 23:14:023189void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:083190 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:433191
[email protected]a888b29e62010-04-01 13:38:573192 if (extension) {
[email protected]98aa0b52010-05-06 17:03:083193 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
3194 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:573195 extension,
[email protected]807871f2010-09-16 01:04:483196 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
3197 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:573198 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
3199 Extension::EXTENSION_ICON_SMALLISH),
3200 ImageLoadingTracker::CACHE);
3201 } else {
[email protected]98aa0b52010-05-06 17:03:083202 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:573203 }
3204}
3205
[email protected]9adb9692010-10-29 23:14:023206const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]a888b29e62010-04-01 13:38:573207 ExtensionsService* extensions_service = profile()->GetExtensionsService();
3208 if (!extensions_service)
3209 return NULL;
3210
[email protected]9adb9692010-10-29 23:14:023211 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:573212 return extension ?
3213 extension : extensions_service->GetExtensionByWebExtent(url);
3214}
3215
[email protected]a888b29e62010-04-01 13:38:573216void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
3217 int index) {
3218 if (image) {
[email protected]98aa0b52010-05-06 17:03:083219 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:573220 NotifyNavigationStateChanged(INVALIDATE_TAB);
3221 }
3222}
3223
[email protected]beb440c2009-11-06 04:08:543224gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
3225 return view_->GetTopLevelNativeWindow();
3226}
3227
3228void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
3229 bool success,
3230 const std::wstring& prompt) {
3231 last_javascript_message_dismissal_ = base::TimeTicks::Now();
3232 if (is_showing_before_unload_dialog_ && !success) {
3233 // If a beforeunload dialog is canceled, we need to stop the throbber from
3234 // spinning, since we forced it to start spinning in Navigate.
3235 DidStopLoading();
3236
3237 tab_close_start_time_ = base::TimeTicks();
3238 }
3239 is_showing_before_unload_dialog_ = false;
3240 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
3241}
3242
3243void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
3244 set_suppress_javascript_messages(suppress_message_boxes);
3245}
3246
[email protected]3a3d47472010-07-15 21:03:543247TabContents* TabContents::AsTabContents() {
3248 return this;
3249}
3250
3251ExtensionHost* TabContents::AsExtensionHost() {
3252 return NULL;
3253}
3254
[email protected]41fc0322009-09-04 22:23:403255void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:103256 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
3257}
[email protected]f45d2a72010-03-08 23:28:353258
3259void TabContents::SetAppIcon(const SkBitmap& app_icon) {
3260 app_icon_ = app_icon;
3261 NotifyNavigationStateChanged(INVALIDATE_TITLE);
3262}