blob: 223668c882be6db5dfdb65a77ed6eefa76ff79aa [file] [log] [blame]
[email protected]61d68ef12011-01-13 14:02:561// Copyright (c) 2011 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"
[email protected]39526562011-02-05 03:41:516
[email protected]b75b8292010-10-01 07:28:257#include <cmath>
8
[email protected]8cc8d492010-02-02 10:40:499#include "base/auto_reset.h"
[email protected]835d7c82010-10-14 04:38:3810#include "base/metrics/histogram.h"
[email protected]724159a2010-12-30 01:11:1811#include "base/metrics/stats_counters.h"
[email protected]96d185d2009-04-24 03:28:5412#include "base/string16.h"
[email protected]996fd702009-09-04 19:12:3713#include "base/string_util.h"
[email protected]96d185d2009-04-24 03:28:5414#include "base/time.h"
[email protected]3c733bde2010-12-21 19:56:3115#include "base/utf_string_conversions.h"
[email protected]6db0def92010-03-02 19:55:4516#include "chrome/browser/autocomplete_history_manager.h"
[email protected]21674df2009-10-28 19:51:2117#include "chrome/browser/autofill/autofill_manager.h"
[email protected]c65e2f152010-10-14 15:30:4018#include "chrome/browser/blocked_content_container.h"
[email protected]96d185d2009-04-24 03:28:5419#include "chrome/browser/browser_process.h"
[email protected]cf68b092010-01-15 20:05:5520#include "chrome/browser/browser_shutdown.h"
[email protected]aacd7cc2009-09-02 14:51:1021#include "chrome/browser/character_encoding.h"
[email protected]724159a2010-12-30 01:11:1822#include "chrome/browser/child_process_security_policy.h"
[email protected]5f24f212010-12-02 14:47:4523#include "chrome/browser/content_settings/content_settings_details.h"
[email protected]9d01a6a2010-11-30 12:03:3324#include "chrome/browser/content_settings/host_content_settings_map.h"
[email protected]96d185d2009-04-24 03:28:5425#include "chrome/browser/debugger/devtools_manager.h"
[email protected]c8f74942010-09-03 10:04:1426#include "chrome/browser/defaults.h"
[email protected]74da5bd2011-01-27 22:03:2727#include "chrome/browser/desktop_notification_handler.h"
[email protected]420ae012009-04-24 05:16:3228#include "chrome/browser/dom_operation_notification_details.h"
[email protected]7ade2732011-02-10 00:13:5829#include "chrome/browser/dom_ui/web_ui.h"
[email protected]bcef0dc02009-02-28 00:35:0230#include "chrome/browser/download/download_item_model.h"
[email protected]420ae012009-04-24 05:16:3231#include "chrome/browser/download/download_manager.h"
[email protected]41291322010-07-15 17:09:0132#include "chrome/browser/download/download_request_limiter.h"
[email protected]eaa7dd182010-12-14 11:09:0033#include "chrome/browser/extensions/extension_service.h"
[email protected]3c733bde2010-12-21 19:56:3134#include "chrome/browser/external_protocol_handler.h"
35#include "chrome/browser/favicon_service.h"
36#include "chrome/browser/file_select_helper.h"
37#include "chrome/browser/google/google_util.h"
[email protected]ef0d04c2010-12-15 23:34:2138#include "chrome/browser/history/history.h"
[email protected]ec0b6c42010-08-26 03:16:5839#include "chrome/browser/history/history_types.h"
[email protected]523623c2010-05-19 16:03:4240#include "chrome/browser/history/top_sites.h"
[email protected]b75b8292010-10-01 07:28:2541#include "chrome/browser/host_zoom_map.h"
[email protected]8897c382009-05-06 17:53:2642#include "chrome/browser/hung_renderer_dialog.h"
[email protected]6ee12c42010-09-14 09:36:0743#include "chrome/browser/in_process_webkit/session_storage_namespace.h"
[email protected]420ae012009-04-24 05:16:3244#include "chrome/browser/load_from_memory_cache_details.h"
45#include "chrome/browser/load_notification_details.h"
[email protected]84abba62009-10-07 17:01:4446#include "chrome/browser/metrics/metric_event_duration_details.h"
[email protected]724159a2010-12-30 01:11:1847#include "chrome/browser/metrics/user_metrics.h"
[email protected]ea0e80892009-08-22 00:36:0548#include "chrome/browser/modal_html_dialog_delegate.h"
[email protected]c8865482009-07-23 20:40:1049#include "chrome/browser/omnibox_search_hint.h"
[email protected]c8f73ab2011-01-22 00:05:1750#include "chrome/browser/pdf_unsupported_feature.h"
[email protected]14a000d2010-04-29 21:44:2451#include "chrome/browser/platform_util.h"
[email protected]67c052e2011-01-31 16:33:5852#include "chrome/browser/plugin_observer.h"
[email protected]37858e52010-08-26 00:22:0253#include "chrome/browser/prefs/pref_service.h"
[email protected]33f74972010-12-08 16:40:3654#include "chrome/browser/prerender/prerender_manager.h"
[email protected]973407b2011-01-26 23:18:2355#include "chrome/browser/prerender/prerender_plt_recorder.h"
[email protected]eb15e24e2011-02-03 22:34:3456#include "chrome/browser/printing/print_preview_message_handler.h"
[email protected]dbeebd52010-11-16 20:34:1657#include "chrome/browser/printing/print_preview_tab_controller.h"
[email protected]12802702010-07-09 19:43:0958#include "chrome/browser/printing/print_view_manager.h"
[email protected]8ecad5e2010-12-02 21:18:3359#include "chrome/browser/profiles/profile.h"
[email protected]1db6ff152009-10-12 15:32:0760#include "chrome/browser/renderer_host/render_process_host.h"
[email protected]8cb5d5b2010-02-09 11:36:1661#include "chrome/browser/renderer_host/render_view_host.h"
[email protected]96d185d2009-04-24 03:28:5462#include "chrome/browser/renderer_host/render_widget_host_view.h"
[email protected]fd694982009-07-03 17:32:3763#include "chrome/browser/renderer_host/resource_request_details.h"
[email protected]1db6ff152009-10-12 15:32:0764#include "chrome/browser/renderer_host/site_instance.h"
[email protected]96d185d2009-04-24 03:28:5465#include "chrome/browser/renderer_host/web_cache_manager.h"
[email protected]93623c5d2009-12-10 21:40:3266#include "chrome/browser/renderer_preferences_util.h"
[email protected]c37e3b62010-01-22 00:15:1767#include "chrome/browser/sessions/session_types.h"
[email protected]bd1ad682009-05-15 22:19:1768#include "chrome/browser/tab_contents/infobar_delegate.h"
[email protected]7e383692009-06-12 19:14:5469#include "chrome/browser/tab_contents/interstitial_page.h"
[email protected]f3ec7742009-01-15 00:59:1670#include "chrome/browser/tab_contents/navigation_entry.h"
[email protected]de34a962009-06-26 23:22:4371#include "chrome/browser/tab_contents/provisional_load_details.h"
[email protected]f3ec7742009-01-15 00:59:1672#include "chrome/browser/tab_contents/tab_contents_delegate.h"
[email protected]585b30362011-01-28 02:30:1773#include "chrome/browser/tab_contents/tab_contents_observer.h"
[email protected]1f18184a2010-07-21 19:34:4974#include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
[email protected]fdd61c62009-04-22 19:22:5775#include "chrome/browser/tab_contents/tab_contents_view.h"
[email protected]d54169e92011-01-21 09:19:5276#include "chrome/browser/tab_contents/thumbnail_generator.h"
[email protected]152b8ba32010-03-29 19:40:1677#include "chrome/browser/translate/page_translated_details.h"
[email protected]1caa1522010-12-01 20:23:3578#include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
[email protected]54ec6472010-04-09 19:39:5879#include "chrome/common/bindings_policy.h"
[email protected]35f7d212009-04-29 21:19:2780#include "chrome/common/chrome_switches.h"
[email protected]de4761b2010-12-07 21:05:2181#include "chrome/common/content_restriction.h"
[email protected]3b355642010-02-05 16:01:4982#include "chrome/common/extensions/extension.h"
[email protected]5d246db22009-10-27 06:17:5783#include "chrome/common/extensions/extension_action.h"
[email protected]807871f2010-09-16 01:04:4884#include "chrome/common/extensions/extension_icon_set.h"
[email protected]942690b132010-05-11 06:42:1485#include "chrome/common/extensions/extension_resource.h"
[email protected]12802702010-07-09 19:43:0986#include "chrome/common/extensions/url_pattern.h"
87#include "chrome/common/navigation_types.h"
88#include "chrome/common/net/url_request_context_getter.h"
[email protected]bfd04a62009-02-01 18:16:5689#include "chrome/common/notification_service.h"
initial.commit09911bf2008-07-26 23:55:2990#include "chrome/common/pref_names.h"
[email protected]420ae012009-04-24 05:16:3291#include "chrome/common/render_messages.h"
[email protected]939856a2010-08-24 20:29:0292#include "chrome/common/render_messages_params.h"
[email protected]96d185d2009-04-24 03:28:5493#include "chrome/common/url_constants.h"
[email protected]ea68c06a2010-04-23 17:25:3794#include "grit/chromium_strings.h"
[email protected]8897c382009-05-06 17:53:2695#include "grit/generated_resources.h"
[email protected]420ae012009-04-24 05:16:3296#include "grit/locale_settings.h"
[email protected]fd626782010-01-22 05:26:0697#include "grit/platform_locale_settings.h"
[email protected]ea68c06a2010-04-23 17:25:3798#include "grit/theme_resources.h"
[email protected]d686e812009-06-03 19:10:2999#include "net/base/net_util.h"
[email protected]420ae012009-04-24 05:16:32100#include "net/base/registry_controlled_domain.h"
[email protected]8bd0fe62011-01-17 06:44:37101#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
[email protected]c051a1b2011-01-21 23:30:17102#include "ui/base/l10n/l10n_util.h"
[email protected]42ce29d2011-01-20 23:19:46103#include "ui/base/resource/resource_bundle.h"
[email protected]08397d52011-02-05 01:53:38104#include "ui/gfx/codec/png_codec.h"
[email protected]d5e311b2010-07-20 17:15:03105#include "webkit/glue/password_form.h"
[email protected]3c733bde2010-12-21 19:56:31106#include "webkit/glue/webpreferences.h"
107
108#if defined(OS_MACOSX)
109#include "app/surface/io_surface_support_mac.h"
110#endif // defined(OS_MACOSX)
[email protected]3e45ba92009-02-20 21:09:00111
[email protected]61d68ef12011-01-13 14:02:56112#if defined(OS_CHROMEOS)
113#include "chrome/browser/chromeos/locale_change_guard.h"
114#endif // defined(OS_CHROMEOS)
115
[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#if defined(OS_WIN)
196
197BOOL CALLBACK InvalidateWindow(HWND hwnd, LPARAM lparam) {
198 // Note: erase is required to properly paint some widgets borders. This can
199 // be seen with textfields.
200 InvalidateRect(hwnd, NULL, TRUE);
201 return TRUE;
202}
203#endif
204
[email protected]5e369672009-11-03 23:48:30205ViewMsg_Navigate_Params::NavigationType GetNavigationType(
[email protected]1ccb3568d2010-02-19 10:51:16206 Profile* profile, const NavigationEntry& entry,
207 NavigationController::ReloadType reload_type) {
208 switch (reload_type) {
209 case NavigationController::RELOAD:
210 return ViewMsg_Navigate_Params::RELOAD;
211 case NavigationController::RELOAD_IGNORING_CACHE:
212 return ViewMsg_Navigate_Params::RELOAD_IGNORING_CACHE;
213 case NavigationController::NO_RELOAD:
214 break; // Fall through to rest of function.
215 }
[email protected]5e369672009-11-03 23:48:30216
217 if (entry.restore_type() == NavigationEntry::RESTORE_LAST_SESSION &&
218 profile->DidLastSessionExitCleanly())
219 return ViewMsg_Navigate_Params::RESTORE;
220
221 return ViewMsg_Navigate_Params::NORMAL;
222}
223
[email protected]876bc832010-09-07 16:29:54224void MakeNavigateParams(const NavigationEntry& entry,
225 const NavigationController& controller,
[email protected]1ccb3568d2010-02-19 10:51:16226 NavigationController::ReloadType reload_type,
227 ViewMsg_Navigate_Params* params) {
[email protected]056de2d2009-06-26 16:41:34228 params->page_id = entry.page_id();
[email protected]876bc832010-09-07 16:29:54229 params->pending_history_list_offset = controller.GetIndexOfEntry(&entry);
[email protected]3cc72b12010-03-18 23:03:00230 params->current_history_list_offset = controller.last_committed_entry_index();
231 params->current_history_list_length = controller.entry_count();
[email protected]056de2d2009-06-26 16:41:34232 params->url = entry.url();
233 params->referrer = entry.referrer();
234 params->transition = entry.transition_type();
235 params->state = entry.content_state();
[email protected]3cc72b12010-03-18 23:03:00236 params->navigation_type =
237 GetNavigationType(controller.profile(), entry, reload_type);
[email protected]056de2d2009-06-26 16:41:34238 params->request_time = base::Time::Now();
239}
240
[email protected]420ae012009-04-24 05:16:32241} // namespace
242
[email protected]f4f50ef2011-01-21 19:01:19243
244// TabContents ----------------------------------------------------------------
[email protected]420ae012009-04-24 05:16:32245
[email protected]420ae012009-04-24 05:16:32246TabContents::TabContents(Profile* profile,
247 SiteInstance* site_instance,
248 int routing_id,
[email protected]6ee12c42010-09-14 09:36:07249 const TabContents* base_tab_contents,
250 SessionStorageNamespace* session_storage_namespace)
[email protected]b680ad22009-04-15 23:19:42251 : delegate_(NULL),
[email protected]6ee12c42010-09-14 09:36:07252 ALLOW_THIS_IN_INITIALIZER_LIST(controller_(
253 this, profile, session_storage_namespace)),
[email protected]66ba4932009-06-04 19:22:13254 ALLOW_THIS_IN_INITIALIZER_LIST(view_(
[email protected]d82ed61e2009-06-16 02:46:22255 TabContentsView::Create(this))),
256 ALLOW_THIS_IN_INITIALIZER_LIST(render_manager_(this, this)),
[email protected]6f821dd2010-02-23 00:54:06257 bookmark_drag_(NULL),
[email protected]d5f942ba2008-09-26 19:30:34258 is_loading_(false),
[email protected]443b80e2010-12-14 00:42:23259 crashed_status_(base::TERMINATION_STATUS_STILL_RUNNING),
260 crashed_error_code_(0),
[email protected]d5f942ba2008-09-26 19:30:34261 waiting_for_response_(false),
[email protected]d5f942ba2008-09-26 19:30:34262 max_page_id_(-1),
[email protected]fdd61c62009-04-22 19:22:57263 load_state_(net::LOAD_STATE_IDLE),
[email protected]094e5b22009-09-25 04:23:56264 upload_size_(0),
265 upload_position_(0),
[email protected]fdd61c62009-04-22 19:22:57266 received_page_title_(false),
[email protected]c65e2f152010-10-14 15:30:40267 blocked_contents_(NULL),
268 all_contents_blocked_(false),
[email protected]8cc8d492010-02-02 10:40:49269 dont_notify_render_view_(false),
[email protected]f17a0ee2010-05-17 17:38:47270 displayed_insecure_content_(false),
[email protected]98aa0b52010-05-06 17:03:08271 extension_app_(NULL),
[email protected]fdd61c62009-04-22 19:22:57272 capturing_contents_(false),
273 is_being_destroyed_(false),
274 notify_disconnection_(false),
[email protected]fdd61c62009-04-22 19:22:57275#if defined(OS_WIN)
276 message_box_active_(CreateEvent(NULL, TRUE, FALSE, NULL)),
277#endif
[email protected]c2e74fe82009-09-03 17:57:44278 suppress_javascript_messages_(false),
[email protected]7ab1e7d62009-10-14 23:32:01279 is_showing_before_unload_dialog_(false),
[email protected]80a8fad2011-01-29 04:02:38280 opener_web_ui_type_(WebUIFactory::kNoWebUI),
[email protected]777a7b62010-05-11 13:28:16281 language_state_(&controller_),
[email protected]ebf40a72010-07-22 01:46:38282 closed_by_user_gesture_(false),
[email protected]b75b8292010-10-01 07:28:25283 minimum_zoom_percent_(
284 static_cast<int>(WebKit::WebView::minTextSizeMultiplier * 100)),
285 maximum_zoom_percent_(
286 static_cast<int>(WebKit::WebView::maxTextSizeMultiplier * 100)),
[email protected]9e823662010-10-13 23:36:00287 temporary_zoom_settings_(false),
288 content_restrictions_(0) {
[email protected]7ff431e2010-01-07 18:18:54289 renderer_preferences_util::UpdateFromSystemSettings(
290 &renderer_preferences_, profile);
291
[email protected]9fb83e82010-07-02 18:24:55292 content_settings_delegate_.reset(
293 new TabSpecificContentSettings(this, profile));
294
[email protected]12636df2009-09-28 22:32:21295 render_manager_.Init(profile, site_instance, routing_id);
[email protected]420ae012009-04-24 05:16:32296
[email protected]34ac70502009-09-25 17:07:23297 // We have the initial size of the view be based on the size of the passed in
298 // tab contents (normally a tab from the same window).
299 view_->CreateView(base_tab_contents ?
300 base_tab_contents->view()->GetContainerSize() : gfx::Size());
[email protected]420ae012009-04-24 05:16:32301
302 // Register for notifications about all interested prefs change.
303 PrefService* prefs = profile->GetPrefs();
[email protected]2fb7dc982010-09-29 12:24:28304 pref_change_registrar_.Init(prefs);
[email protected]420ae012009-04-24 05:16:32305 if (prefs) {
306 for (int i = 0; i < kPrefsToObserveLength; ++i)
[email protected]2fb7dc982010-09-29 12:24:28307 pref_change_registrar_.Add(kPrefsToObserve[i], this);
[email protected]420ae012009-04-24 05:16:32308 }
309
[email protected]420ae012009-04-24 05:16:32310 registrar_.Add(this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
311 NotificationService::AllSources());
[email protected]d3ba77272009-09-03 00:06:09312#if defined(OS_LINUX)
313 registrar_.Add(this, NotificationType::BROWSER_THEME_CHANGED,
314 NotificationService::AllSources());
315#endif
[email protected]420ae012009-04-24 05:16:32316
[email protected]6c32ce72010-03-08 05:18:06317 registrar_.Add(this, NotificationType::USER_STYLE_SHEET_UPDATED,
318 NotificationService::AllSources());
319
[email protected]79580c62010-02-02 02:36:25320 // Register for notifications about content setting changes.
321 registrar_.Add(this, NotificationType::CONTENT_SETTINGS_CHANGED,
322 NotificationService::AllSources());
323
[email protected]a888b29e62010-04-01 13:38:57324 // Listen for extension changes so we can update extension_for_current_page_.
325 registrar_.Add(this, NotificationType::EXTENSION_LOADED,
326 NotificationService::AllSources());
327 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
328 NotificationService::AllSources());
[email protected]a888b29e62010-04-01 13:38:57329
[email protected]88152052010-10-01 04:05:18330 // Listen for Google URL changes
331 registrar_.Add(this, NotificationType::GOOGLE_URL_UPDATED,
332 NotificationService::AllSources());
333
[email protected]c8865482009-07-23 20:40:10334 // Set-up the showing of the omnibox search infobar if applicable.
335 if (OmniboxSearchHint::IsEnabled(profile))
336 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
[email protected]403415a2011-01-10 18:57:53337
[email protected]b5a1d11c2011-02-17 03:09:42338 // Can only add observers after render_manager_.Init() is called, since that's
339 // what sets up the render_view_host which TabContentObserver's constructor
340 // uses to get the routing_id.
341 AddObservers();
[email protected]332af7732009-03-11 13:21:35342}
initial.commit09911bf2008-07-26 23:55:29343
344TabContents::~TabContents() {
[email protected]420ae012009-04-24 05:16:32345 is_being_destroyed_ = true;
346
[email protected]bfe4c1582009-10-02 18:11:09347 // We don't want any notifications while we're running our destructor.
[email protected]420ae012009-04-24 05:16:32348 registrar_.RemoveAll();
[email protected]2fb7dc982010-09-29 12:24:28349 pref_change_registrar_.RemoveAll();
[email protected]420ae012009-04-24 05:16:32350
[email protected]420ae012009-04-24 05:16:32351 NotifyDisconnected();
[email protected]e7b8d832009-11-20 22:41:00352 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:32353
[email protected]420ae012009-04-24 05:16:32354 // First cleanly close all child windows.
355 // TODO(mpcomplete): handle case if MaybeCloseChildWindows() already asked
356 // some of these to close. CloseWindows is async, so it might get called
357 // twice before it runs.
[email protected]8cc8d492010-02-02 10:40:49358 CloseConstrainedWindows();
[email protected]420ae012009-04-24 05:16:32359
[email protected]c65e2f152010-10-14 15:30:40360 // Close all blocked contents.
361 if (blocked_contents_)
362 blocked_contents_->Destroy();
[email protected]66ba4932009-06-04 19:22:13363
[email protected]420ae012009-04-24 05:16:32364 // Notify any observer that have a reference on this tab contents.
365 NotificationService::current()->Notify(
366 NotificationType::TAB_CONTENTS_DESTROYED,
367 Source<TabContents>(this),
368 NotificationService::NoDetails());
369
[email protected]1e5e74f2009-05-27 20:55:12370 // Notify any lasting InfobarDelegates that have not yet been removed that
371 // whatever infobar they were handling in this TabContents has closed,
372 // because the TabContents is going away entirely.
373 // This must happen after the TAB_CONTENTS_DESTROYED notification as the
374 // notification may trigger infobars calls that access their delegate. (and
375 // some implementations of InfoBarDelegate do delete themselves on
376 // InfoBarClosed()).
[email protected]ec8f51162011-02-08 04:20:40377 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]1e5e74f2009-05-27 20:55:12378 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i);
379 delegate->InfoBarClosed();
380 }
381 infobar_delegates_.clear();
382
[email protected]420ae012009-04-24 05:16:32383 // TODO(brettw) this should be moved to the view.
384#if defined(OS_WIN)
385 // If we still have a window handle, destroy it. GetNativeView can return
386 // NULL if this contents was part of a window that closed.
[email protected]50bd6452010-11-27 19:39:42387 if (GetNativeView()) {
388 RenderViewHost* host = render_view_host();
389 if (host && host->view()) {
390 host->view()->WillWmDestroy();
391 }
[email protected]420ae012009-04-24 05:16:32392 ::DestroyWindow(GetNativeView());
[email protected]50bd6452010-11-27 19:39:42393 }
[email protected]420ae012009-04-24 05:16:32394#endif
[email protected]7ab1e7d62009-10-14 23:32:01395
396 // OnCloseStarted isn't called in unit tests.
397 if (!tab_close_start_time_.is_null()) {
398 UMA_HISTOGRAM_TIMES("Tab.Close",
399 base::TimeTicks::Now() - tab_close_start_time_);
400 }
[email protected]b5a1d11c2011-02-17 03:09:42401
402 FOR_EACH_OBSERVER(TabContentsObserver, observers_, set_tab_contents(NULL));
403}
404
405void TabContents::AddObservers() {
406 printing_.reset(new printing::PrintViewManager(this));
407 print_preview_.reset(new printing::PrintPreviewMessageHandler(this));
408 fav_icon_helper_.reset(new FavIconHelper(this));
409 autofill_manager_.reset(new AutoFillManager(this));
410 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(this));
411 prerender_plt_recorder_.reset(new prerender::PrerenderPLTRecorder(this));
412 desktop_notification_handler_.reset(
413 new DesktopNotificationHandlerForTC(this, GetRenderProcessHost()));
414 plugin_observer_.reset(new PluginObserver(this));
initial.commit09911bf2008-07-26 23:55:29415}
416
[email protected]d5f942ba2008-09-26 19:30:34417// static
418void TabContents::RegisterUserPrefs(PrefService* prefs) {
[email protected]420ae012009-04-24 05:16:32419 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
420
421 WebPreferences pref_defaults;
422 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
423 pref_defaults.javascript_enabled);
424 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
425 pref_defaults.web_security_enabled);
426 prefs->RegisterBooleanPref(
427 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, true);
428 prefs->RegisterBooleanPref(prefs::kWebKitLoadsImagesAutomatically,
429 pref_defaults.loads_images_automatically);
430 prefs->RegisterBooleanPref(prefs::kWebKitPluginsEnabled,
431 pref_defaults.plugins_enabled);
432 prefs->RegisterBooleanPref(prefs::kWebKitDomPasteEnabled,
433 pref_defaults.dom_paste_enabled);
434 prefs->RegisterBooleanPref(prefs::kWebKitShrinksStandaloneImagesToFit,
435 pref_defaults.shrinks_standalone_images_to_fit);
[email protected]c4e98902010-06-01 10:20:14436 prefs->RegisterDictionaryPref(prefs::kWebKitInspectorSettings);
[email protected]420ae012009-04-24 05:16:32437 prefs->RegisterBooleanPref(prefs::kWebKitTextAreasAreResizable,
438 pref_defaults.text_areas_are_resizable);
439 prefs->RegisterBooleanPref(prefs::kWebKitJavaEnabled,
440 pref_defaults.java_enabled);
[email protected]1661a3c02010-05-20 16:32:36441 prefs->RegisterBooleanPref(prefs::kWebkitTabsToLinks,
442 pref_defaults.tabs_to_links);
[email protected]420ae012009-04-24 05:16:32443
444 prefs->RegisterLocalizedStringPref(prefs::kAcceptLanguages,
445 IDS_ACCEPT_LANGUAGES);
446 prefs->RegisterLocalizedStringPref(prefs::kDefaultCharset,
447 IDS_DEFAULT_ENCODING);
448 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitStandardFontIsSerif,
449 IDS_STANDARD_FONT_IS_SERIF);
450 prefs->RegisterLocalizedStringPref(prefs::kWebKitFixedFontFamily,
451 IDS_FIXED_FONT_FAMILY);
452 prefs->RegisterLocalizedStringPref(prefs::kWebKitSerifFontFamily,
453 IDS_SERIF_FONT_FAMILY);
454 prefs->RegisterLocalizedStringPref(prefs::kWebKitSansSerifFontFamily,
455 IDS_SANS_SERIF_FONT_FAMILY);
456 prefs->RegisterLocalizedStringPref(prefs::kWebKitCursiveFontFamily,
457 IDS_CURSIVE_FONT_FAMILY);
458 prefs->RegisterLocalizedStringPref(prefs::kWebKitFantasyFontFamily,
459 IDS_FANTASY_FONT_FAMILY);
460 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFontSize,
461 IDS_DEFAULT_FONT_SIZE);
462 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitDefaultFixedFontSize,
463 IDS_DEFAULT_FIXED_FONT_SIZE);
464 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumFontSize,
465 IDS_MINIMUM_FONT_SIZE);
466 prefs->RegisterLocalizedIntegerPref(prefs::kWebKitMinimumLogicalFontSize,
467 IDS_MINIMUM_LOGICAL_FONT_SIZE);
468 prefs->RegisterLocalizedBooleanPref(prefs::kWebKitUsesUniversalDetector,
469 IDS_USES_UNIVERSAL_DETECTOR);
470 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
471 IDS_STATIC_ENCODING_LIST);
initial.commit09911bf2008-07-26 23:55:29472}
473
[email protected]724159a2010-12-30 01:11:18474bool TabContents::OnMessageReceived(const IPC::Message& message) {
[email protected]585b30362011-01-28 02:30:17475 ObserverListBase<TabContentsObserver>::Iterator it(observers_);
476 TabContentsObserver* observer;
[email protected]0f180ee2011-01-21 18:23:10477 while ((observer = it.GetNext()) != NULL)
478 if (observer->OnMessageReceived(message))
[email protected]403415a2011-01-10 18:57:53479 return true;
[email protected]403415a2011-01-10 18:57:53480
[email protected]724159a2010-12-30 01:11:18481 bool handled = true;
482 bool message_is_ok = true;
483 IPC_BEGIN_MESSAGE_MAP_EX(TabContents, message, message_is_ok)
484 IPC_MESSAGE_HANDLER(ViewHostMsg_DidStartProvisionalLoadForFrame,
485 OnDidStartProvisionalLoadForFrame)
486 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRedirectProvisionalLoad,
487 OnDidRedirectProvisionalLoad)
488 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFailProvisionalLoadWithError,
489 OnDidFailProvisionalLoadWithError)
490 IPC_MESSAGE_HANDLER(ViewHostMsg_DidLoadResourceFromMemoryCache,
491 OnDidLoadResourceFromMemoryCache)
492 IPC_MESSAGE_HANDLER(ViewHostMsg_DidDisplayInsecureContent,
493 OnDidDisplayInsecureContent)
494 IPC_MESSAGE_HANDLER(ViewHostMsg_DidRunInsecureContent,
495 OnDidRunInsecureContent)
496 IPC_MESSAGE_HANDLER(ViewHostMsg_DocumentLoadedInFrame,
497 OnDocumentLoadedInFrame)
498 IPC_MESSAGE_HANDLER(ViewHostMsg_DidFinishLoad, OnDidFinishLoad)
[email protected]c8f73ab2011-01-22 00:05:17499 IPC_MESSAGE_HANDLER(ViewHostMsg_UpdateContentRestrictions,
500 OnUpdateContentRestrictions)
501 IPC_MESSAGE_HANDLER(ViewHostMsg_PDFHasUnsupportedFeature,
502 OnPDFHasUnsupportedFeature)
[email protected]7d472472011-01-22 01:30:25503 IPC_MESSAGE_HANDLER(ViewHostMsg_GoToEntryAtOffset, OnGoToEntryAtOffset)
[email protected]7d472472011-01-22 01:30:25504 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetApplicationInfo,
505 OnDidGetApplicationInfo)
506 IPC_MESSAGE_HANDLER(ViewHostMsg_InstallApplication,
507 OnInstallApplication)
508 IPC_MESSAGE_HANDLER(ViewHostMsg_PageContents, OnPageContents)
509 IPC_MESSAGE_HANDLER(ViewHostMsg_PageTranslated, OnPageTranslated)
510 IPC_MESSAGE_HANDLER(ViewHostMsg_SetSuggestions, OnSetSuggestions)
511 IPC_MESSAGE_HANDLER(ViewHostMsg_InstantSupportDetermined,
512 OnInstantSupportDetermined)
[email protected]34f128d2011-01-25 19:07:44513 IPC_MESSAGE_HANDLER(ViewHostMsg_RunFileChooser, OnRunFileChooser)
[email protected]724159a2010-12-30 01:11:18514 IPC_MESSAGE_UNHANDLED(handled = false)
515 IPC_END_MESSAGE_MAP_EX()
516
517 if (!message_is_ok) {
518 UserMetrics::RecordAction(UserMetricsAction("BadMessageTerminate_RVD"));
519 GetRenderProcessHost()->ReceivedBadMessage();
520 }
521
522 return handled;
523}
524
[email protected]13367f72009-07-08 16:39:02525// Returns true if contains content rendered by an extension.
526bool TabContents::HostsExtension() const {
527 return GetURL().SchemeIs(chrome::kExtensionScheme);
[email protected]d5f942ba2008-09-26 19:30:34528}
529
[email protected]1f18184a2010-07-21 19:34:49530TabContentsSSLHelper* TabContents::GetSSLHelper() {
531 if (ssl_helper_.get() == NULL)
532 ssl_helper_.reset(new TabContentsSSLHelper(this));
533 return ssl_helper_.get();
534}
535
[email protected]8cb5d5b2010-02-09 11:36:16536RenderProcessHost* TabContents::GetRenderProcessHost() const {
537 return render_manager_.current_host()->process();
538}
539
[email protected]9adb9692010-10-29 23:14:02540void TabContents::SetExtensionApp(const Extension* extension) {
[email protected]867a73e12010-03-19 20:45:46541 DCHECK(!extension || extension->GetFullLaunchURL().is_valid());
[email protected]98aa0b52010-05-06 17:03:08542 extension_app_ = extension;
[email protected]fca656c2010-02-10 20:30:10543
[email protected]98aa0b52010-05-06 17:03:08544 UpdateExtensionAppIcon(extension_app_);
[email protected]a888b29e62010-04-01 13:38:57545
[email protected]fca656c2010-02-10 20:30:10546 NotificationService::current()->Notify(
547 NotificationType::TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
548 Source<TabContents>(this),
549 NotificationService::NoDetails());
[email protected]3b355642010-02-05 16:01:49550}
551
[email protected]98aa0b52010-05-06 17:03:08552void TabContents::SetExtensionAppById(const std::string& extension_app_id) {
553 if (extension_app_id.empty())
[email protected]911f8152010-03-18 16:46:40554 return;
555
[email protected]eaa7dd182010-12-14 11:09:00556 ExtensionService* extension_service = profile()->GetExtensionService();
[email protected]fa6a9102010-11-22 15:38:50557 if (!extension_service || !extension_service->is_ready())
558 return;
559
560 const Extension* extension =
561 extension_service->GetExtensionById(extension_app_id, false);
562 if (extension)
563 SetExtensionApp(extension);
[email protected]911f8152010-03-18 16:46:40564}
565
[email protected]98aa0b52010-05-06 17:03:08566SkBitmap* TabContents::GetExtensionAppIcon() {
[email protected]98aa0b52010-05-06 17:03:08567 if (extension_app_icon_.empty())
[email protected]8eb043b2010-04-30 07:19:51568 return NULL;
569
[email protected]98aa0b52010-05-06 17:03:08570 return &extension_app_icon_;
[email protected]8eb043b2010-04-30 07:19:51571}
572
[email protected]d5f942ba2008-09-26 19:30:34573const GURL& TabContents::GetURL() const {
574 // We may not have a navigation entry yet
[email protected]ce3fa3c2009-04-20 19:55:57575 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]ebe89e062009-08-13 23:16:54576 return entry ? entry->virtual_url() : GURL::EmptyGURL();
[email protected]d5f942ba2008-09-26 19:30:34577}
578
[email protected]96d185d2009-04-24 03:28:54579const string16& TabContents::GetTitle() const {
[email protected]4c6092c5b2009-06-06 00:23:55580 // Transient entries take precedence. They are used for interstitial pages
581 // that are shown on top of existing pages.
582 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]45d0ef7f2011-01-05 13:46:23583 if (entry) {
584 return entry->GetTitleForDisplay(profile()->GetPrefs()->
585 GetString(prefs::kAcceptLanguages));
586 }
[email protected]7ade2732011-02-10 00:13:58587 WebUI* our_web_ui = render_manager_.pending_web_ui() ?
588 render_manager_.pending_web_ui() : render_manager_.web_ui();
589 if (our_web_ui) {
[email protected]96d185d2009-04-24 03:28:54590 // Don't override the title in view source mode.
[email protected]4c6092c5b2009-06-06 00:23:55591 entry = controller_.GetActiveEntry();
[email protected]96d185d2009-04-24 03:28:54592 if (!(entry && entry->IsViewSourceMode())) {
[email protected]e0112912011-02-02 22:54:35593 // Give the Web UI the chance to override our title.
[email protected]7ade2732011-02-10 00:13:58594 const string16& title = our_web_ui->overridden_title();
[email protected]96d185d2009-04-24 03:28:54595 if (!title.empty())
596 return title;
597 }
598 }
599
600 // We use the title for the last committed entry rather than a pending
601 // navigation entry. For example, when the user types in a URL, we want to
602 // keep the old page's title until the new load has committed and we get a new
603 // title.
[email protected]96d185d2009-04-24 03:28:54604 entry = controller_.GetLastCommittedEntry();
[email protected]45d0ef7f2011-01-05 13:46:23605 if (entry) {
606 return entry->GetTitleForDisplay(profile()->GetPrefs()->
607 GetString(prefs::kAcceptLanguages));
608 }
[email protected]96d185d2009-04-24 03:28:54609 return EmptyString16();
610}
611
[email protected]bbbc1ef2010-02-12 18:03:41612// static
613string16 TabContents::GetDefaultTitle() {
614 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE);
615}
616
[email protected]d5f942ba2008-09-26 19:30:34617int32 TabContents::GetMaxPageID() {
618 if (GetSiteInstance())
619 return GetSiteInstance()->max_page_id();
620 else
621 return max_page_id_;
622}
623
624void TabContents::UpdateMaxPageID(int32 page_id) {
625 // Ensure both the SiteInstance and RenderProcessHost update their max page
[email protected]57c6a652009-05-04 07:58:34626 // IDs in sync. Only TabContents will also have site instances, except during
[email protected]d5f942ba2008-09-26 19:30:34627 // testing.
628 if (GetSiteInstance())
629 GetSiteInstance()->UpdateMaxPageID(page_id);
[email protected]8cb5d5b2010-02-09 11:36:16630 GetRenderProcessHost()->UpdateMaxPageID(page_id);
[email protected]d5f942ba2008-09-26 19:30:34631}
632
[email protected]96d185d2009-04-24 03:28:54633SiteInstance* TabContents::GetSiteInstance() const {
634 return render_manager_.current_host()->site_instance();
635}
636
[email protected]96d185d2009-04-24 03:28:54637bool TabContents::ShouldDisplayURL() {
[email protected]8ab24cc2009-11-13 20:56:15638 // Don't hide the url in view source mode and with interstitials.
[email protected]96d185d2009-04-24 03:28:54639 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]8ab24cc2009-11-13 20:56:15640 if (entry && (entry->IsViewSourceMode() ||
[email protected]cccd3762010-11-12 18:40:01641 entry->page_type() == INTERSTITIAL_PAGE)) {
[email protected]96d185d2009-04-24 03:28:54642 return true;
[email protected]8ab24cc2009-11-13 20:56:15643 }
[email protected]83e3895b2009-06-11 00:07:16644
[email protected]2b9a06402011-02-16 04:57:10645 // We always display the URL for non-WebUI URLs to prevent spoofing.
646 if (entry && !WebUIFactory::HasWebUIScheme(entry->url()))
647 return true;
648
[email protected]d0980792011-02-13 19:41:40649 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58650 if (web_ui)
651 return !web_ui->should_hide_url();
[email protected]96d185d2009-04-24 03:28:54652 return true;
653}
654
[email protected]d5f942ba2008-09-26 19:30:34655SkBitmap TabContents::GetFavIcon() const {
656 // Like GetTitle(), we also want to use the favicon for the last committed
657 // entry rather than a pending navigation entry.
[email protected]ce3fa3c2009-04-20 19:55:57658 NavigationEntry* entry = controller_.GetTransientEntry();
[email protected]cbab76d2008-10-13 22:42:47659 if (entry)
660 return entry->favicon().bitmap();
661
[email protected]ce3fa3c2009-04-20 19:55:57662 entry = controller_.GetLastCommittedEntry();
[email protected]d5f942ba2008-09-26 19:30:34663 if (entry)
664 return entry->favicon().bitmap();
[email protected]d5f942ba2008-09-26 19:30:34665 return SkBitmap();
666}
667
[email protected]0b303cc2009-09-28 22:35:15668bool TabContents::FavIconIsValid() const {
669 NavigationEntry* entry = controller_.GetTransientEntry();
670 if (entry)
671 return entry->favicon().is_valid();
672
673 entry = controller_.GetLastCommittedEntry();
674 if (entry)
675 return entry->favicon().is_valid();
676
677 return false;
678}
679
[email protected]96d185d2009-04-24 03:28:54680bool TabContents::ShouldDisplayFavIcon() {
681 // Always display a throbber during pending loads.
682 if (controller_.GetLastCommittedEntry() && controller_.pending_entry())
683 return true;
684
[email protected]d0980792011-02-13 19:41:40685 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:58686 if (web_ui)
687 return !web_ui->hide_favicon();
[email protected]96d185d2009-04-24 03:28:54688 return true;
689}
690
[email protected]42197a22010-12-28 23:29:42691string16 TabContents::GetStatusText() const {
[email protected]96d185d2009-04-24 03:28:54692 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
[email protected]42197a22010-12-28 23:29:42693 return string16();
[email protected]96d185d2009-04-24 03:28:54694
695 switch (load_state_) {
696 case net::LOAD_STATE_WAITING_FOR_CACHE:
[email protected]42197a22010-12-28 23:29:42697 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
[email protected]8a1f3312010-05-25 19:25:04698 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
[email protected]42197a22010-12-28 23:29:42699 return
700 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
[email protected]96d185d2009-04-24 03:28:54701 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
[email protected]42197a22010-12-28 23:29:42702 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
[email protected]96d185d2009-04-24 03:28:54703 case net::LOAD_STATE_RESOLVING_HOST:
[email protected]42197a22010-12-28 23:29:42704 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
[email protected]96d185d2009-04-24 03:28:54705 case net::LOAD_STATE_CONNECTING:
[email protected]42197a22010-12-28 23:29:42706 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
[email protected]375e3112010-05-27 20:32:06707 case net::LOAD_STATE_SSL_HANDSHAKE:
[email protected]42197a22010-12-28 23:29:42708 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
[email protected]96d185d2009-04-24 03:28:54709 case net::LOAD_STATE_SENDING_REQUEST:
[email protected]094e5b22009-09-25 04:23:56710 if (upload_size_)
[email protected]42197a22010-12-28 23:29:42711 return l10n_util::GetStringFUTF16Int(
[email protected]094e5b22009-09-25 04:23:56712 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
713 static_cast<int>((100 * upload_position_) / upload_size_));
714 else
[email protected]42197a22010-12-28 23:29:42715 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
[email protected]96d185d2009-04-24 03:28:54716 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
[email protected]42197a22010-12-28 23:29:42717 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
718 load_state_host_);
[email protected]96d185d2009-04-24 03:28:54719 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
720 case net::LOAD_STATE_IDLE:
721 case net::LOAD_STATE_READING_RESPONSE:
722 break;
723 }
724
[email protected]42197a22010-12-28 23:29:42725 return string16();
[email protected]96d185d2009-04-24 03:28:54726}
727
[email protected]585b30362011-01-28 02:30:17728void TabContents::AddObserver(TabContentsObserver* observer) {
729 observers_.AddObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49730}
731
[email protected]585b30362011-01-28 02:30:17732void TabContents::RemoveObserver(TabContentsObserver* observer) {
733 observers_.RemoveObserver(observer);
[email protected]3c9e1872010-11-18 16:17:49734}
735
[email protected]443b80e2010-12-14 00:42:23736void TabContents::SetIsCrashed(base::TerminationStatus status, int error_code) {
737 if (status == crashed_status_)
[email protected]d5f942ba2008-09-26 19:30:34738 return;
739
[email protected]443b80e2010-12-14 00:42:23740 crashed_status_ = status;
741 crashed_error_code_ = error_code;
[email protected]c9cd2222009-05-06 05:16:50742 NotifyNavigationStateChanged(INVALIDATE_TAB);
[email protected]d5f942ba2008-09-26 19:30:34743}
744
[email protected]744ef172009-10-16 21:53:46745void TabContents::PageActionStateChanged() {
746 NotifyNavigationStateChanged(TabContents::INVALIDATE_PAGE_ACTIONS);
[email protected]d7eaf572009-07-01 21:57:00747}
[email protected]ce5c4502009-05-06 16:46:11748
[email protected]d5f942ba2008-09-26 19:30:34749void TabContents::NotifyNavigationStateChanged(unsigned changed_flags) {
750 if (delegate_)
751 delegate_->NavigationStateChanged(this, changed_flags);
752}
753
[email protected]96d185d2009-04-24 03:28:54754void TabContents::DidBecomeSelected() {
755 controller_.SetActive(true);
[email protected]8cb5d5b2010-02-09 11:36:16756 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
757 if (rwhv) {
758 rwhv->DidBecomeSelected();
[email protected]789e9152009-08-04 21:59:43759#if defined(OS_MACOSX)
[email protected]8cb5d5b2010-02-09 11:36:16760 rwhv->SetActive(true);
[email protected]789e9152009-08-04 21:59:43761#endif
762 }
[email protected]96d185d2009-04-24 03:28:54763
[email protected]8cb5d5b2010-02-09 11:36:16764 WebCacheManager::GetInstance()->ObserveActivity(GetRenderProcessHost()->id());
[email protected]5ac20162010-11-24 23:33:11765 last_selected_time_ = base::TimeTicks::Now();
[email protected]61d68ef12011-01-13 14:02:56766#if defined(OS_CHROMEOS)
767 chromeos::LocaleChangeGuard::Check(this);
768#endif
[email protected]96d185d2009-04-24 03:28:54769}
770
[email protected]a94454b2010-12-16 04:16:03771void TabContents::FadeForInstant(bool animate) {
[email protected]1b072562010-12-13 19:37:45772 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
773 SkColor whitish = SkColorSetARGB(192, 255, 255, 255);
774 if (rwhv)
[email protected]a94454b2010-12-16 04:16:03775 rwhv->SetVisuallyDeemphasized(&whitish, animate);
[email protected]1b072562010-12-13 19:37:45776}
777
778void TabContents::CancelInstantFade() {
779 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
780 if (rwhv)
781 rwhv->SetVisuallyDeemphasized(NULL, false);
782}
783
[email protected]96d185d2009-04-24 03:28:54784void TabContents::WasHidden() {
785 if (!capturing_contents()) {
786 // |render_view_host()| can be NULL if the user middle clicks a link to open
787 // a tab in then background, then closes the tab before selecting it. This
788 // is because closing the tab calls TabContents::Destroy(), which removes
789 // the |render_view_host()|; then when we actually destroy the window,
790 // OnWindowPosChanged() notices and calls HideContents() (which calls us).
[email protected]8cb5d5b2010-02-09 11:36:16791 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
792 if (rwhv)
793 rwhv->WasHidden();
[email protected]96d185d2009-04-24 03:28:54794 }
795
796 NotificationService::current()->Notify(
797 NotificationType::TAB_CONTENTS_HIDDEN,
798 Source<TabContents>(this),
799 NotificationService::NoDetails());
800}
801
[email protected]d5f942ba2008-09-26 19:30:34802void TabContents::Activate() {
803 if (delegate_)
804 delegate_->ActivateContents(this);
805}
806
[email protected]ea42e7782010-08-23 23:58:12807void TabContents::Deactivate() {
808 if (delegate_)
809 delegate_->DeactivateContents(this);
810}
811
[email protected]96d185d2009-04-24 03:28:54812void TabContents::ShowContents() {
[email protected]8cb5d5b2010-02-09 11:36:16813 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
814 if (rwhv)
815 rwhv->DidBecomeSelected();
[email protected]96d185d2009-04-24 03:28:54816}
817
818void TabContents::HideContents() {
819 // TODO(pkasting): http://b/1239839 Right now we purposefully don't call
820 // our superclass HideContents(), because some callers want to be very picky
821 // about the order in which these get called. In addition to making the code
822 // here practically impossible to understand, this also means we end up
823 // calling TabContents::WasHidden() twice if callers call both versions of
[email protected]57c6a652009-05-04 07:58:34824 // HideContents() on a TabContents.
[email protected]96d185d2009-04-24 03:28:54825 WasHidden();
826}
827
[email protected]5aab5e22010-12-08 22:13:29828bool TabContents::NeedToFireBeforeUnload() {
829 // TODO(creis): Should we fire even for interstitial pages?
830 return notify_disconnection() &&
831 !showing_interstitial_page() &&
832 !render_view_host()->SuddenTerminationAllowed();
833}
834
[email protected]c0588052008-10-27 23:01:50835void TabContents::OpenURL(const GURL& url, const GURL& referrer,
[email protected]d5f942ba2008-09-26 19:30:34836 WindowOpenDisposition disposition,
837 PageTransition::Type transition) {
838 if (delegate_)
[email protected]c0588052008-10-27 23:01:50839 delegate_->OpenURLFromTab(this, url, referrer, disposition, transition);
[email protected]d5f942ba2008-09-26 19:30:34840}
841
[email protected]1ccb3568d2010-02-19 10:51:16842bool TabContents::NavigateToPendingEntry(
843 NavigationController::ReloadType reload_type) {
[email protected]876bc832010-09-07 16:29:54844 return NavigateToEntry(*controller_.pending_entry(), reload_type);
845}
[email protected]96d185d2009-04-24 03:28:54846
[email protected]876bc832010-09-07 16:29:54847bool TabContents::NavigateToEntry(
848 const NavigationEntry& entry,
849 NavigationController::ReloadType reload_type) {
[email protected]96d185d2009-04-24 03:28:54850 RenderViewHost* dest_render_view_host = render_manager_.Navigate(entry);
851 if (!dest_render_view_host)
852 return false; // Unable to create the desired render view host.
853
[email protected]770dd8b2010-05-24 18:11:39854 if (delegate_ && delegate_->ShouldEnablePreferredSizeNotifications()) {
855 dest_render_view_host->EnablePreferredSizeChangedMode(
856 kPreferredSizeWidth | kPreferredSizeHeightThisIsSlow);
857 }
[email protected]9fb325e2010-05-06 18:23:24858
[email protected]80a8fad2011-01-29 04:02:38859 // For security, we should never send non-Web-UI URLs to a Web UI renderer.
[email protected]05fdd492010-11-15 17:52:07860 // Double check that here.
[email protected]54ec6472010-04-09 19:39:58861 int enabled_bindings = dest_render_view_host->enabled_bindings();
[email protected]c09163a2011-02-15 00:05:55862 bool is_allowed_in_web_ui_renderer =
[email protected]80a8fad2011-01-29 04:02:38863 WebUIFactory::IsURLAcceptableForWebUI(profile(), entry.url());
[email protected]c09163a2011-02-15 00:05:55864 CHECK(!BindingsPolicy::is_web_ui_enabled(enabled_bindings) ||
865 is_allowed_in_web_ui_renderer);
[email protected]54ec6472010-04-09 19:39:58866
[email protected]96d185d2009-04-24 03:28:54867 // Tell DevTools agent that it is attached prior to the navigation.
[email protected]d9f9b792009-06-24 13:17:12868 DevToolsManager* devtools_manager = DevToolsManager::GetInstance();
[email protected]7e8e6b62009-05-08 11:28:32869 if (devtools_manager) { // NULL in unit tests.
[email protected]3cc72b12010-03-18 23:03:00870 devtools_manager->OnNavigatingToPendingEntry(render_view_host(),
871 dest_render_view_host,
872 entry.url());
[email protected]7e8e6b62009-05-08 11:28:32873 }
[email protected]96d185d2009-04-24 03:28:54874
875 // Used for page load time metrics.
876 current_load_start_ = base::TimeTicks::Now();
877
878 // Navigate in the desired RenderViewHost.
[email protected]056de2d2009-06-26 16:41:34879 ViewMsg_Navigate_Params navigate_params;
[email protected]876bc832010-09-07 16:29:54880 MakeNavigateParams(entry, controller_, reload_type, &navigate_params);
[email protected]52c68652010-12-07 17:47:04881 if (delegate_) {
882 navigate_params.extra_headers =
883 delegate_->GetNavigationHeaders(navigate_params.url);
884 }
[email protected]056de2d2009-06-26 16:41:34885 dest_render_view_host->Navigate(navigate_params);
[email protected]96d185d2009-04-24 03:28:54886
887 if (entry.page_id() == -1) {
888 // HACK!! This code suppresses javascript: URLs from being added to
889 // session history, which is what we want to do for javascript: URLs that
890 // do not generate content. What we really need is a message from the
891 // renderer telling us that a new page was not created. The same message
892 // could be used for mailto: URLs and the like.
893 if (entry.url().SchemeIs(chrome::kJavaScriptScheme))
894 return false;
895 }
896
[email protected]3c9e1872010-11-18 16:17:49897 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:17898 FOR_EACH_OBSERVER(TabContentsObserver, observers_, NavigateToPendingEntry());
[email protected]96d185d2009-04-24 03:28:54899
[email protected]1ccb3568d2010-02-19 10:51:16900 if (reload_type != NavigationController::NO_RELOAD &&
901 !profile()->IsOffTheRecord()) {
[email protected]0189bc722009-08-28 21:56:48902 FaviconService* favicon_service =
903 profile()->GetFaviconService(Profile::IMPLICIT_ACCESS);
904 if (favicon_service)
905 favicon_service->SetFaviconOutOfDateForPage(entry.url());
[email protected]96d185d2009-04-24 03:28:54906 }
907
[email protected]d5f942ba2008-09-26 19:30:34908 return true;
909}
910
[email protected]96d185d2009-04-24 03:28:54911void TabContents::Stop() {
912 render_manager_.Stop();
[email protected]12802702010-07-09 19:43:09913 printing_->Stop();
[email protected]96d185d2009-04-24 03:28:54914}
915
[email protected]96d185d2009-04-24 03:28:54916void TabContents::DisassociateFromPopupCount() {
917 render_view_host()->DisassociateFromPopupCount();
918}
919
920TabContents* TabContents::Clone() {
921 // We create a new SiteInstance so that the new tab won't share processes
922 // with the old one. This can be changed in the future if we need it to share
923 // processes for some reason.
[email protected]420ae012009-04-24 05:16:32924 TabContents* tc = new TabContents(profile(),
[email protected]96d185d2009-04-24 03:28:54925 SiteInstance::CreateSiteInstance(profile()),
[email protected]6ee12c42010-09-14 09:36:07926 MSG_ROUTING_NONE, this, NULL);
[email protected]96d185d2009-04-24 03:28:54927 tc->controller().CopyStateFrom(controller_);
[email protected]98aa0b52010-05-06 17:03:08928 tc->extension_app_ = extension_app_;
[email protected]98aa0b52010-05-06 17:03:08929 tc->extension_app_icon_ = extension_app_icon_;
[email protected]96d185d2009-04-24 03:28:54930 return tc;
931}
932
[email protected]4d677202009-07-19 07:37:12933void TabContents::ShowPageInfo(const GURL& url,
934 const NavigationEntry::SSLStatus& ssl,
935 bool show_history) {
936 if (!delegate_)
937 return;
938
[email protected]bb678332009-07-21 00:15:50939 delegate_->ShowPageInfo(profile(), url, ssl, show_history);
[email protected]4d677202009-07-19 07:37:12940}
941
[email protected]ef0d04c2010-12-15 23:34:21942void TabContents::SaveFavicon() {
943 NavigationEntry* entry = controller_.GetActiveEntry();
944 if (!entry || entry->url().is_empty())
945 return;
946
947 // Make sure the page is in history, otherwise adding the favicon does
948 // nothing.
949 HistoryService* history = profile()->GetOriginalProfile()->GetHistoryService(
950 Profile::IMPLICIT_ACCESS);
951 if (!history)
952 return;
953 history->AddPageNoVisitForBookmark(entry->url());
954
955 FaviconService* service = profile()->GetOriginalProfile()->GetFaviconService(
956 Profile::IMPLICIT_ACCESS);
957 if (!service)
958 return;
959 const NavigationEntry::FaviconStatus& favicon(entry->favicon());
960 if (!favicon.is_valid() || favicon.url().is_empty() ||
961 favicon.bitmap().empty()) {
962 return;
963 }
964 std::vector<unsigned char> image_data;
965 gfx::PNGCodec::EncodeBGRASkBitmap(favicon.bitmap(), false, &image_data);
966 service->SetFavicon(entry->url(), favicon.url(), image_data);
967}
968
initial.commit09911bf2008-07-26 23:55:29969ConstrainedWindow* TabContents::CreateConstrainedDialog(
[email protected]e8382172009-06-19 22:16:28970 ConstrainedWindowDelegate* delegate) {
initial.commit09911bf2008-07-26 23:55:29971 ConstrainedWindow* window =
[email protected]e8382172009-06-19 22:16:28972 ConstrainedWindow::CreateConstrainedDialog(this, delegate);
initial.commit09911bf2008-07-26 23:55:29973 child_windows_.push_back(window);
[email protected]fa1cf0b82010-01-15 21:49:44974
975 if (child_windows_.size() == 1) {
976 window->ShowConstrainedWindow();
977 BlockTabContent(true);
978 }
979
initial.commit09911bf2008-07-26 23:55:29980 return window;
981}
982
[email protected]fa1cf0b82010-01-15 21:49:44983void TabContents::BlockTabContent(bool blocked) {
[email protected]8dccd7cb2010-02-25 05:19:55984 RenderWidgetHostView* rwhv = GetRenderWidgetHostView();
[email protected]1b072562010-12-13 19:37:45985 // 70% opaque grey.
986 SkColor greyish = SkColorSetARGB(178, 0, 0, 0);
[email protected]8dccd7cb2010-02-25 05:19:55987 if (rwhv)
[email protected]1b072562010-12-13 19:37:45988 rwhv->SetVisuallyDeemphasized(blocked ? &greyish : NULL, false);
[email protected]fa1cf0b82010-01-15 21:49:44989 render_view_host()->set_ignore_input_events(blocked);
990 if (delegate_)
991 delegate_->SetTabContentBlocked(this, blocked);
992}
993
initial.commit09911bf2008-07-26 23:55:29994void TabContents::AddNewContents(TabContents* new_contents,
995 WindowOpenDisposition disposition,
996 const gfx::Rect& initial_pos,
[email protected]7e7414ae2010-01-26 20:19:29997 bool user_gesture) {
[email protected]c65e2f152010-10-14 15:30:40998 if (all_contents_blocked_) {
999 if (!blocked_contents_)
1000 blocked_contents_ = new BlockedContentContainer(this);
1001 blocked_contents_->AddTabContents(
1002 new_contents, disposition, initial_pos, user_gesture);
1003 return;
1004 }
1005
initial.commit09911bf2008-07-26 23:55:291006 if (!delegate_)
1007 return;
1008
[email protected]35f7d212009-04-29 21:19:271009 if ((disposition == NEW_POPUP) && !user_gesture &&
1010 !CommandLine::ForCurrentProcess()->HasSwitch(
1011 switches::kDisablePopupBlocking)) {
[email protected]2c4410d2009-05-06 23:46:221012 // Unrequested popups from normal pages are constrained unless they're in
[email protected]b6c874582009-05-08 19:38:311013 // the whitelist. The popup owner will handle checking this.
[email protected]7e7414ae2010-01-26 20:19:291014 delegate_->GetConstrainingContents(this)->AddPopup(
1015 new_contents, initial_pos);
[email protected]b6c874582009-05-08 19:38:311016 } else {
[email protected]0aa55312008-10-17 21:53:081017 new_contents->DisassociateFromPopupCount();
initial.commit09911bf2008-07-26 23:55:291018 delegate_->AddNewContents(this, new_contents, disposition, initial_pos,
1019 user_gesture);
[email protected]7f37dd92009-09-15 16:35:491020 NotificationService::current()->Notify(
1021 NotificationType::TAB_ADDED,
1022 Source<TabContentsDelegate>(delegate_),
1023 Details<TabContents>(this));
initial.commit09911bf2008-07-26 23:55:291024 }
initial.commit09911bf2008-07-26 23:55:291025
[email protected]8cc8d492010-02-02 10:40:491026 // TODO(pkasting): Why is this necessary?
[email protected]c65e2f152010-10-14 15:30:401027 PopupNotificationVisibilityChanged(blocked_contents_ != NULL);
initial.commit09911bf2008-07-26 23:55:291028}
1029
[email protected]bcd9dc42010-01-23 16:38:181030bool TabContents::ExecuteCode(int request_id, const std::string& extension_id,
[email protected]20ad2692009-11-20 18:27:201031 bool is_js_code, const std::string& code_string,
1032 bool all_frames) {
[email protected]ebd0eae72010-02-16 23:50:511033 RenderViewHost* host = render_view_host();
1034 if (!host)
1035 return false;
1036
1037 return host->Send(new ViewMsg_ExecuteCode(host->routing_id(),
[email protected]be7e5cb2010-10-04 12:53:171038 ViewMsg_ExecuteCode_Params(request_id, extension_id,
[email protected]ebd0eae72010-02-16 23:50:511039 is_js_code, code_string, all_frames)));
[email protected]912256b32009-09-18 09:47:351040}
1041
[email protected]96d185d2009-04-24 03:28:541042void TabContents::PopupNotificationVisibilityChanged(bool visible) {
[email protected]8cc8d492010-02-02 10:40:491043 if (is_being_destroyed_)
1044 return;
[email protected]9fb83e82010-07-02 18:24:551045 content_settings_delegate_->SetPopupsBlocked(visible);
[email protected]8cc8d492010-02-02 10:40:491046 if (!dont_notify_render_view_)
[email protected]e8345242010-05-06 03:00:401047 render_view_host()->AllowScriptToClose(!visible);
[email protected]96d185d2009-04-24 03:28:541048}
1049
[email protected]5c9e97a2009-09-09 23:48:301050gfx::NativeView TabContents::GetContentNativeView() const {
[email protected]96d185d2009-04-24 03:28:541051 return view_->GetContentNativeView();
1052}
1053
1054gfx::NativeView TabContents::GetNativeView() const {
1055 return view_->GetNativeView();
1056}
1057
1058void TabContents::GetContainerBounds(gfx::Rect *out) const {
1059 view_->GetContainerBounds(out);
1060}
1061
1062void TabContents::Focus() {
1063 view_->Focus();
1064}
1065
[email protected]90daadb42009-06-08 21:27:281066void TabContents::FocusThroughTabTraversal(bool reverse) {
[email protected]7e383692009-06-12 19:14:541067 if (showing_interstitial_page()) {
1068 render_manager_.interstitial_page()->FocusThroughTabTraversal(reverse);
1069 return;
1070 }
[email protected]96d185d2009-04-24 03:28:541071 render_view_host()->SetInitialFocus(reverse);
1072}
1073
1074bool TabContents::FocusLocationBarByDefault() {
[email protected]d0980792011-02-13 19:41:401075 WebUI* web_ui = GetWebUIForCurrentState();
[email protected]7ade2732011-02-10 00:13:581076 if (web_ui)
1077 return web_ui->focus_location_bar_by_default();
[email protected]3e3f0eb2009-06-22 18:33:431078 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]e0d481582009-09-15 21:06:251079 if (entry && entry->url() == GURL(chrome::kAboutBlankURL))
[email protected]3e3f0eb2009-06-22 18:33:431080 return true;
[email protected]96d185d2009-04-24 03:28:541081 return false;
1082}
1083
[email protected]a26dc362010-04-23 01:48:581084void TabContents::SetFocusToLocationBar(bool select_all) {
[email protected]a11aaf22010-03-30 00:03:381085 if (delegate())
[email protected]a26dc362010-04-23 01:48:581086 delegate()->SetFocusToLocationBar(select_all);
[email protected]a11aaf22010-03-30 00:03:381087}
1088
[email protected]616ed5a2008-11-21 22:27:241089void TabContents::AddInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321090 if (delegate_ && !delegate_->infobars_enabled()) {
1091 delegate->InfoBarClosed();
1092 return;
1093 }
1094
[email protected]616ed5a2008-11-21 22:27:241095 // Look through the existing InfoBarDelegates we have for a match. If we've
1096 // already got one that matches, then we don't add the new one.
[email protected]ec8f51162011-02-08 04:20:401097 for (size_t i = 0; i < infobar_count(); ++i) {
[email protected]6d27a7b2009-12-18 23:25:451098 if (GetInfoBarDelegateAt(i)->EqualsDelegate(delegate)) {
1099 // Tell the new infobar to close so that it can clean itself up.
1100 delegate->InfoBarClosed();
[email protected]616ed5a2008-11-21 22:27:241101 return;
[email protected]6d27a7b2009-12-18 23:25:451102 }
[email protected]616ed5a2008-11-21 22:27:241103 }
1104
1105 infobar_delegates_.push_back(delegate);
[email protected]bfd04a62009-02-01 18:16:561106 NotificationService::current()->Notify(
[email protected]f4f50ef2011-01-21 19:01:191107 NotificationType::TAB_CONTENTS_INFOBAR_ADDED, Source<TabContents>(this),
[email protected]bfd04a62009-02-01 18:16:561108 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241109
1110 // Add ourselves as an observer for navigations the first time a delegate is
1111 // added. We use this notification to expire InfoBars that need to expire on
1112 // page transitions.
1113 if (infobar_delegates_.size() == 1) {
[email protected]bfd04a62009-02-01 18:16:561114 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED,
[email protected]ce3fa3c2009-04-20 19:55:571115 Source<NavigationController>(&controller_));
[email protected]616ed5a2008-11-21 22:27:241116 }
1117}
1118
1119void TabContents::RemoveInfoBar(InfoBarDelegate* delegate) {
[email protected]f7019302010-03-26 19:58:321120 if (delegate_ && !delegate_->infobars_enabled()) {
1121 return;
1122 }
1123
[email protected]616ed5a2008-11-21 22:27:241124 std::vector<InfoBarDelegate*>::iterator it =
1125 find(infobar_delegates_.begin(), infobar_delegates_.end(), delegate);
1126 if (it != infobar_delegates_.end()) {
1127 InfoBarDelegate* delegate = *it;
[email protected]bfd04a62009-02-01 18:16:561128 NotificationService::current()->Notify(
1129 NotificationType::TAB_CONTENTS_INFOBAR_REMOVED,
1130 Source<TabContents>(this),
1131 Details<InfoBarDelegate>(delegate));
[email protected]616ed5a2008-11-21 22:27:241132
[email protected]f4f50ef2011-01-21 19:01:191133 infobar_delegates_.erase(it);
1134 // Remove ourselves as an observer if we are tracking no more InfoBars.
1135 if (infobar_delegates_.empty()) {
1136 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED,
1137 Source<NavigationController>(&controller_));
[email protected]6a02963e2009-01-06 16:58:031138 }
[email protected]616ed5a2008-11-21 22:27:241139 }
1140}
[email protected]3edd9522009-03-04 22:19:411141
[email protected]f81821c2009-08-07 01:29:471142void TabContents::ReplaceInfoBar(InfoBarDelegate* old_delegate,
1143 InfoBarDelegate* new_delegate) {
[email protected]f7019302010-03-26 19:58:321144 if (delegate_ && !delegate_->infobars_enabled()) {
1145 new_delegate->InfoBarClosed();
1146 return;
1147 }
1148
[email protected]f81821c2009-08-07 01:29:471149 std::vector<InfoBarDelegate*>::iterator it =
1150 find(infobar_delegates_.begin(), infobar_delegates_.end(), old_delegate);
1151 DCHECK(it != infobar_delegates_.end());
1152
1153 // Notify the container about the change of plans.
1154 scoped_ptr<std::pair<InfoBarDelegate*, InfoBarDelegate*> > details(
1155 new std::pair<InfoBarDelegate*, InfoBarDelegate*>(
1156 old_delegate, new_delegate));
1157 NotificationService::current()->Notify(
1158 NotificationType::TAB_CONTENTS_INFOBAR_REPLACED,
1159 Source<TabContents>(this),
1160 Details<std::pair<InfoBarDelegate*, InfoBarDelegate*> >(details.get()));
1161
[email protected]f4f50ef2011-01-21 19:01:191162 // Remove the old one.
1163 infobar_delegates_.erase(it);
[email protected]f81821c2009-08-07 01:29:471164
1165 // Add the new one.
[email protected]cdadf6f2010-08-20 16:36:081166 DCHECK(find(infobar_delegates_.begin(),
1167 infobar_delegates_.end(), new_delegate) ==
1168 infobar_delegates_.end());
[email protected]f81821c2009-08-07 01:29:471169 infobar_delegates_.push_back(new_delegate);
1170}
1171
[email protected]20ede072009-10-06 00:28:351172bool TabContents::ShouldShowBookmarkBar() {
[email protected]aa9196f2009-10-22 16:20:271173 if (showing_interstitial_page())
1174 return false;
1175
[email protected]c8f74942010-09-03 10:04:141176 // Do not show bookmarks bar if bookmarks aren't enabled.
1177 if (!browser_defaults::bookmarks_enabled)
1178 return false;
1179
[email protected]d0980792011-02-13 19:41:401180 // See GetWebUIForCurrentState() comment for more info. This case is very
[email protected]96d185d2009-04-24 03:28:541181 // similar, but for non-first loads, we want to use the committed entry. This
1182 // is so the bookmarks bar disappears at the same time the page does.
1183 if (controller_.GetLastCommittedEntry()) {
[email protected]e0112912011-02-02 22:54:351184 // Not the first load, always use the committed Web UI.
[email protected]7ade2732011-02-10 00:13:581185 return (render_manager_.web_ui() == NULL) ?
1186 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541187 }
1188
1189 // When it's the first load, we know either the pending one or the committed
[email protected]d0980792011-02-13 19:41:401190 // one will have the Web UI in it (see GetWebUIForCurrentState), and only one
[email protected]96d185d2009-04-24 03:28:541191 // of them will be valid, so we can just check both.
[email protected]7ade2732011-02-10 00:13:581192 if (render_manager_.pending_web_ui())
1193 return render_manager_.pending_web_ui()->force_bookmark_bar_visible();
1194 return (render_manager_.web_ui() == NULL) ?
1195 false : render_manager_.web_ui()->force_bookmark_bar_visible();
[email protected]96d185d2009-04-24 03:28:541196}
1197
[email protected]3edd9522009-03-04 22:19:411198void TabContents::ToolbarSizeChanged(bool is_animating) {
1199 TabContentsDelegate* d = delegate();
1200 if (d)
1201 d->ToolbarSizeChanged(this, is_animating);
1202}
[email protected]616ed5a2008-11-21 22:27:241203
[email protected]fc6fb7fb2009-11-07 02:35:041204bool TabContents::CanDownload(int request_id) {
1205 TabContentsDelegate* d = delegate();
1206 if (d)
1207 return d->CanDownload(request_id);
1208 return true;
1209}
1210
[email protected]d5f942ba2008-09-26 19:30:341211void TabContents::OnStartDownload(DownloadItem* download) {
1212 DCHECK(download);
[email protected]d5f942ba2008-09-26 19:30:341213
1214 // Download in a constrained popup is shown in the tab that opened it.
[email protected]b6c874582009-05-08 19:38:311215 TabContents* tab_contents = delegate()->GetConstrainingContents(this);
[email protected]d5f942ba2008-09-26 19:30:341216
[email protected]5b928b62010-08-03 11:46:511217 if (tab_contents && tab_contents->delegate())
1218 tab_contents->delegate()->OnStartDownload(download, this);
[email protected]3edd9522009-03-04 22:19:411219}
[email protected]3edd9522009-03-04 22:19:411220
[email protected]d5f942ba2008-09-26 19:30:341221void TabContents::WillClose(ConstrainedWindow* window) {
[email protected]d6219912010-11-17 19:47:371222 ConstrainedWindowList::iterator i(
1223 std::find(child_windows_.begin(), child_windows_.end(), window));
1224 bool removed_topmost_window = i == child_windows_.begin();
1225 if (i != child_windows_.end())
1226 child_windows_.erase(i);
1227 if (child_windows_.empty()) {
[email protected]fa1cf0b82010-01-15 21:49:441228 BlockTabContent(false);
[email protected]d6219912010-11-17 19:47:371229 } else {
1230 if (removed_topmost_window)
1231 child_windows_[0]->ShowConstrainedWindow();
1232 BlockTabContent(true);
[email protected]fa1cf0b82010-01-15 21:49:441233 }
[email protected]66ba4932009-06-04 19:22:131234}
[email protected]d5f942ba2008-09-26 19:30:341235
[email protected]c65e2f152010-10-14 15:30:401236void TabContents::WillCloseBlockedContentContainer(
1237 BlockedContentContainer* container) {
1238 DCHECK(blocked_contents_ == container);
1239 blocked_contents_ = NULL;
[email protected]8cc8d492010-02-02 10:40:491240 PopupNotificationVisibilityChanged(false);
[email protected]d5f942ba2008-09-26 19:30:341241}
1242
[email protected]d5f942ba2008-09-26 19:30:341243void TabContents::DidMoveOrResize(ConstrainedWindow* window) {
[email protected]332af7732009-03-11 13:21:351244#if defined(OS_WIN)
[email protected]92edc472009-02-10 20:32:061245 UpdateWindow(GetNativeView());
[email protected]332af7732009-03-11 13:21:351246#endif
[email protected]d5f942ba2008-09-26 19:30:341247}
1248
[email protected]420ae012009-04-24 05:16:321249void TabContents::OnSavePage() {
1250 // If we can not save the page, try to download it.
1251 if (!SavePackage::IsSavableContents(contents_mime_type())) {
1252 DownloadManager* dlm = profile()->GetDownloadManager();
1253 const GURL& current_page_url = GetURL();
1254 if (dlm && current_page_url.is_valid())
[email protected]d82ed61e2009-06-16 02:46:221255 dlm->DownloadUrl(current_page_url, GURL(), "", this);
[email protected]420ae012009-04-24 05:16:321256 return;
1257 }
1258
1259 Stop();
1260
1261 // Create the save package and possibly prompt the user for the name to save
1262 // the page as. The user prompt is an asynchronous operation that runs on
1263 // another thread.
[email protected]b5a1d11c2011-02-17 03:09:421264 save_package_ = new SavePackage(this);
[email protected]420ae012009-04-24 05:16:321265 save_package_->GetSaveInfo();
1266}
1267
1268// Used in automated testing to bypass prompting the user for file names.
1269// Instead, the names and paths are hard coded rather than running them through
1270// file name sanitation and extension / mime checking.
[email protected]828cabe2009-09-26 22:47:111271bool TabContents::SavePage(const FilePath& main_file, const FilePath& dir_path,
[email protected]420ae012009-04-24 05:16:321272 SavePackage::SavePackageType save_type) {
1273 // Stop the page from navigating.
1274 Stop();
1275
[email protected]b5a1d11c2011-02-17 03:09:421276 save_package_ = new SavePackage(this, save_type, main_file, dir_path);
[email protected]cdf6cc82009-08-04 21:48:591277 return save_package_->Init();
[email protected]420ae012009-04-24 05:16:321278}
1279
[email protected]89d6e6e2009-12-03 23:06:511280void TabContents::EmailPageLocation() {
1281 std::string title = EscapeQueryParamValue(UTF16ToUTF8(GetTitle()), false);
1282 std::string page_url = EscapeQueryParamValue(GetURL().spec(), false);
1283 std::string mailto = std::string("mailto:?subject=Fwd:%20") +
1284 title + "&body=%0A%0A" + page_url;
1285 platform_util::OpenExternal(GURL(mailto));
1286}
1287
[email protected]420ae012009-04-24 05:16:321288void TabContents::PrintPreview() {
[email protected]dbeebd52010-11-16 20:34:161289 if (CommandLine::ForCurrentProcess()->HasSwitch(
1290 switches::kEnablePrintPreview)) {
1291 if (showing_interstitial_page())
1292 return;
[email protected]83a58a22011-02-05 03:44:481293
1294 printing::PrintPreviewTabController* tab_controller =
1295 printing::PrintPreviewTabController::GetInstance();
1296 if (!tab_controller)
1297 return;
1298 tab_controller->GetOrCreatePreviewTab(this, controller().window_id().id());
1299
[email protected]dbeebd52010-11-16 20:34:161300 render_view_host()->PrintPreview();
1301 } else {
1302 PrintNow();
1303 }
[email protected]420ae012009-04-24 05:16:321304}
1305
1306bool TabContents::PrintNow() {
1307 // We can't print interstitial page for now.
1308 if (showing_interstitial_page())
1309 return false;
1310
1311 return render_view_host()->PrintPages();
1312}
1313
[email protected]82270452009-06-19 15:58:011314void TabContents::PrintingDone(int document_cookie, bool success) {
1315 render_view_host()->PrintingDone(document_cookie, success);
1316}
1317
[email protected]420ae012009-04-24 05:16:321318bool TabContents::IsActiveEntry(int32 page_id) {
1319 NavigationEntry* active_entry = controller_.GetActiveEntry();
1320 return (active_entry != NULL &&
1321 active_entry->site_instance() == GetSiteInstance() &&
1322 active_entry->page_id() == page_id);
1323}
1324
[email protected]b2fe07d12010-02-09 14:38:081325void TabContents::SetOverrideEncoding(const std::string& encoding) {
[email protected]8cb5d5b2010-02-09 11:36:161326 set_encoding(encoding);
1327 render_view_host()->SetPageEncoding(encoding);
1328}
1329
[email protected]b2fe07d12010-02-09 14:38:081330void TabContents::ResetOverrideEncoding() {
[email protected]8cb5d5b2010-02-09 11:36:161331 reset_encoding();
1332 render_view_host()->ResetPageEncodingToDefault();
1333}
1334
1335void TabContents::WindowMoveOrResizeStarted() {
1336 render_view_host()->WindowMoveOrResizeStarted();
1337}
1338
[email protected]c65e2f152010-10-14 15:30:401339void TabContents::SetAllContentsBlocked(bool value) {
1340 if (all_contents_blocked_ == value)
1341 return;
1342
1343 all_contents_blocked_ = value;
1344 if (!all_contents_blocked_ && blocked_contents_) {
1345 std::vector<TabContents*> blocked;
1346 blocked_contents_->GetBlockedContents(&blocked);
1347 for (size_t i = 0; i < blocked.size(); ++i)
1348 blocked_contents_->LaunchForContents(blocked[i]);
1349 }
1350}
1351
[email protected]3f8eb7f2009-10-02 23:58:051352void TabContents::LogNewTabTime(const std::string& event_name) {
1353 // Not all new tab pages get timed. In those cases, we don't have a
1354 // new_tab_start_time_.
1355 if (new_tab_start_time_.is_null())
1356 return;
1357
1358 base::TimeDelta duration = base::TimeTicks::Now() - new_tab_start_time_;
[email protected]84abba62009-10-07 17:01:441359 MetricEventDurationDetails details(event_name,
1360 static_cast<int>(duration.InMilliseconds()));
1361
[email protected]7ab1e7d62009-10-14 23:32:011362 if (event_name == "Tab.NewTabScriptStart") {
1363 UMA_HISTOGRAM_TIMES("Tab.NewTabScriptStart", duration);
1364 } else if (event_name == "Tab.NewTabDOMContentLoaded") {
1365 UMA_HISTOGRAM_TIMES("Tab.NewTabDOMContentLoaded", duration);
1366 } else if (event_name == "Tab.NewTabOnload") {
1367 UMA_HISTOGRAM_TIMES("Tab.NewTabOnload", duration);
[email protected]3f8eb7f2009-10-02 23:58:051368 // The new tab page has finished loading; reset it.
1369 new_tab_start_time_ = base::TimeTicks();
[email protected]84abba62009-10-07 17:01:441370 } else {
1371 NOTREACHED();
[email protected]3f8eb7f2009-10-02 23:58:051372 }
[email protected]84abba62009-10-07 17:01:441373 NotificationService::current()->Notify(
1374 NotificationType::METRIC_EVENT_DURATION,
1375 Source<TabContents>(this),
1376 Details<MetricEventDurationDetails>(&details));
[email protected]3f8eb7f2009-10-02 23:58:051377}
1378
[email protected]7ab1e7d62009-10-14 23:32:011379void TabContents::OnCloseStarted() {
1380 if (tab_close_start_time_.is_null())
1381 tab_close_start_time_ = base::TimeTicks::Now();
1382}
1383
[email protected]46624bf2010-06-09 16:04:191384bool TabContents::ShouldAcceptDragAndDrop() const {
1385#if defined(OS_CHROMEOS)
1386 // ChromeOS panels (pop-ups) do not take drag-n-drop.
1387 // See http://crosbug.com/2413
[email protected]b83af492010-10-09 03:21:201388 if (delegate() && delegate()->IsPopup(this))
1389 return false;
1390 return true;
[email protected]46624bf2010-06-09 16:04:191391#else
1392 return true;
1393#endif
1394}
1395
[email protected]7813bd72011-02-05 02:19:341396void TabContents::SystemDragEnded() {
1397 if (render_view_host())
1398 render_view_host()->DragSourceSystemDragEnded();
1399 if (delegate())
1400 delegate()->DragEnded();
1401}
1402
[email protected]ec0b6c42010-08-26 03:16:581403void TabContents::UpdateHistoryForNavigation(
1404 scoped_refptr<history::HistoryAddPageArgs> add_page_args) {
1405 if (profile()->IsOffTheRecord())
1406 return;
1407
1408 // Add to history service.
1409 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1410 if (hs)
1411 hs->AddPage(*add_page_args);
1412}
1413
1414void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) {
1415 if (profile()->IsOffTheRecord())
1416 return;
1417
1418 HistoryService* hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS);
1419 if (hs)
1420 hs->SetPageTitle(entry.virtual_url(), entry.title());
1421}
1422
[email protected]d0b8d092010-10-25 04:05:171423double TabContents::GetZoomLevel() const {
[email protected]b75b8292010-10-01 07:28:251424 HostZoomMap* zoom_map = profile()->GetHostZoomMap();
1425 if (!zoom_map)
[email protected]d0b8d092010-10-25 04:05:171426 return 0;
[email protected]b75b8292010-10-01 07:28:251427
1428 double zoom_level;
1429 if (temporary_zoom_settings_) {
1430 zoom_level = zoom_map->GetTemporaryZoomLevel(
1431 GetRenderProcessHost()->id(), render_view_host()->routing_id());
1432 } else {
1433 zoom_level = zoom_map->GetZoomLevel(GetURL());
1434 }
[email protected]d0b8d092010-10-25 04:05:171435 return zoom_level;
1436}
[email protected]b75b8292010-10-01 07:28:251437
[email protected]d0b8d092010-10-25 04:05:171438int TabContents::GetZoomPercent(bool* enable_increment,
1439 bool* enable_decrement) {
1440 *enable_decrement = *enable_increment = false;
[email protected]b75b8292010-10-01 07:28:251441 int percent = static_cast<int>(
[email protected]d0b8d092010-10-25 04:05:171442 WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100);
[email protected]b75b8292010-10-01 07:28:251443 *enable_decrement = percent > minimum_zoom_percent_;
1444 *enable_increment = percent < maximum_zoom_percent_;
1445 return percent;
1446}
1447
[email protected]3c733bde2010-12-21 19:56:311448void TabContents::ViewSource() {
[email protected]1788e772010-12-15 16:40:501449 if (!delegate_)
1450 return;
1451
1452 NavigationEntry* active_entry = controller().GetActiveEntry();
1453 if (!active_entry)
1454 return;
1455
1456 delegate_->ViewSourceForTab(this, active_entry->url());
[email protected]77d8d622010-12-15 10:30:121457}
1458
[email protected]724159a2010-12-30 01:11:181459void TabContents::OnDidStartProvisionalLoadForFrame(int64 frame_id,
1460 bool is_main_frame,
1461 const GURL& url) {
1462 bool is_error_page = (url.spec() == chrome::kUnreachableWebDataURL);
1463 GURL validated_url(url);
1464 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1465 GetRenderProcessHost()->id(), &validated_url);
1466
1467 ProvisionalLoadDetails details(
1468 is_main_frame,
1469 controller_.IsURLInPageNavigation(validated_url),
1470 validated_url, std::string(), false, is_error_page, frame_id);
1471 NotificationService::current()->Notify(
1472 NotificationType::FRAME_PROVISIONAL_LOAD_START,
1473 Source<NavigationController>(&controller_),
1474 Details<ProvisionalLoadDetails>(&details));
1475 if (is_main_frame) {
1476 // If we're displaying a network error page do not reset the content
1477 // settings delegate's cookies so the user has a chance to modify cookie
1478 // settings.
1479 if (!is_error_page)
1480 content_settings_delegate_->ClearCookieSpecificContentSettings();
1481 content_settings_delegate_->ClearGeolocationContentSettings();
[email protected]e7d50892011-01-19 21:47:381482
1483 // Check if the URL we are about to load has been prerendered by any chance,
1484 // and use it if possible.
1485 MaybeUsePreloadedPage(url);
[email protected]724159a2010-12-30 01:11:181486 }
1487}
1488
1489void TabContents::OnDidRedirectProvisionalLoad(int32 page_id,
1490 const GURL& source_url,
1491 const GURL& target_url) {
1492 NavigationEntry* entry;
1493 if (page_id == -1)
1494 entry = controller_.pending_entry();
1495 else
1496 entry = controller_.GetEntryWithPageID(GetSiteInstance(), page_id);
1497 if (!entry || entry->url() != source_url)
1498 return;
1499 entry->set_url(target_url);
[email protected]e7d50892011-01-19 21:47:381500
1501 // Check if the URL we are about to load has been prerendered by any chance,
1502 // and use it if possible.
1503 MaybeUsePreloadedPage(target_url);
[email protected]724159a2010-12-30 01:11:181504}
1505
1506void TabContents::OnDidFailProvisionalLoadWithError(
1507 int64 frame_id,
1508 bool is_main_frame,
1509 int error_code,
1510 const GURL& url,
1511 bool showing_repost_interstitial) {
1512 VLOG(1) << "Failed Provisional Load: " << url.possibly_invalid_spec()
1513 << ", error_code: " << error_code
1514 << " is_main_frame: " << is_main_frame
1515 << " showing_repost_interstitial: " << showing_repost_interstitial
1516 << " frame_id: " << frame_id;
1517 GURL validated_url(url);
1518 render_view_host()->FilterURL(ChildProcessSecurityPolicy::GetInstance(),
1519 GetRenderProcessHost()->id(), &validated_url);
1520
1521 if (net::ERR_ABORTED == error_code) {
1522 // EVIL HACK ALERT! Ignore failed loads when we're showing interstitials.
1523 // This means that the interstitial won't be torn down properly, which is
1524 // bad. But if we have an interstitial, go back to another tab type, and
1525 // then load the same interstitial again, we could end up getting the first
1526 // interstitial's "failed" message (as a result of the cancel) when we're on
1527 // the second one.
1528 //
1529 // We can't tell this apart, so we think we're tearing down the current page
1530 // which will cause a crash later one. There is also some code in
1531 // RenderViewHostManager::RendererAbortedProvisionalLoad that is commented
1532 // out because of this problem.
1533 //
1534 // http://code.google.com/p/chromium/issues/detail?id=2855
1535 // Because this will not tear down the interstitial properly, if "back" is
1536 // back to another tab type, the interstitial will still be somewhat alive
1537 // in the previous tab type. If you navigate somewhere that activates the
1538 // tab with the interstitial again, you'll see a flash before the new load
1539 // commits of the interstitial page.
1540 if (showing_interstitial_page()) {
1541 LOG(WARNING) << "Discarding message during interstitial.";
1542 return;
1543 }
1544
1545 // This will discard our pending entry if we cancelled the load (e.g., if we
1546 // decided to download the file instead of load it). Only discard the
1547 // pending entry if the URLs match, otherwise the user initiated a navigate
1548 // before the page loaded so that the discard would discard the wrong entry.
1549 NavigationEntry* pending_entry = controller_.pending_entry();
1550 if (pending_entry && pending_entry->url() == validated_url) {
1551 controller_.DiscardNonCommittedEntries();
1552 // Update the URL display.
1553 NotifyNavigationStateChanged(TabContents::INVALIDATE_URL);
1554 }
1555
1556 render_manager_.RendererAbortedProvisionalLoad(render_view_host());
1557 }
1558
1559 // Send out a notification that we failed a provisional load with an error.
1560 ProvisionalLoadDetails details(
1561 is_main_frame, controller_.IsURLInPageNavigation(validated_url),
1562 validated_url, std::string(), false, false, frame_id);
1563 details.set_error_code(error_code);
1564
1565 NotificationService::current()->Notify(
1566 NotificationType::FAIL_PROVISIONAL_LOAD_WITH_ERROR,
1567 Source<NavigationController>(&controller_),
1568 Details<ProvisionalLoadDetails>(&details));
1569}
1570
1571void TabContents::OnDidLoadResourceFromMemoryCache(
1572 const GURL& url,
[email protected]724159a2010-12-30 01:11:181573 const std::string& security_info) {
1574 static base::StatsCounter cache("WebKit.CacheHit");
1575 cache.Increment();
1576
1577 // Send out a notification that we loaded a resource from our memory cache.
1578 int cert_id = 0, cert_status = 0, security_bits = -1, connection_status = 0;
1579 SSLManager::DeserializeSecurityInfo(security_info,
1580 &cert_id, &cert_status,
1581 &security_bits,
1582 &connection_status);
[email protected]7a8c55e2011-02-15 08:21:161583 LoadFromMemoryCacheDetails details(url, GetRenderProcessHost()->id(),
1584 cert_id, cert_status);
[email protected]724159a2010-12-30 01:11:181585
1586 NotificationService::current()->Notify(
1587 NotificationType::LOAD_FROM_MEMORY_CACHE,
1588 Source<NavigationController>(&controller_),
1589 Details<LoadFromMemoryCacheDetails>(&details));
1590}
1591
1592void TabContents::OnDidDisplayInsecureContent() {
1593 displayed_insecure_content_ = true;
1594 SSLManager::NotifySSLInternalStateChanged();
1595}
1596
1597void TabContents::OnDidRunInsecureContent(
[email protected]92771112011-01-20 00:13:021598 const std::string& security_origin, const GURL& target_url) {
[email protected]9941cf52011-02-08 16:17:231599 LOG(INFO) << security_origin << " ran insecure content from "
1600 << target_url.possibly_invalid_spec();
[email protected]724159a2010-12-30 01:11:181601 controller_.ssl_manager()->DidRunInsecureContent(security_origin);
1602}
1603
1604void TabContents::OnDocumentLoadedInFrame(int64 frame_id) {
1605 controller_.DocumentLoadedInFrame();
1606 NotificationService::current()->Notify(
1607 NotificationType::FRAME_DOM_CONTENT_LOADED,
1608 Source<NavigationController>(&controller_),
1609 Details<int64>(&frame_id));
1610}
1611
1612void TabContents::OnDidFinishLoad(int64 frame_id) {
1613 NotificationService::current()->Notify(
1614 NotificationType::FRAME_DID_FINISH_LOAD,
1615 Source<NavigationController>(&controller_),
1616 Details<int64>(&frame_id));
1617}
1618
[email protected]c8f73ab2011-01-22 00:05:171619void TabContents::OnUpdateContentRestrictions(int restrictions) {
1620 content_restrictions_ = restrictions;
1621 delegate()->ContentRestrictionsChanged(this);
1622}
1623
1624void TabContents::OnPDFHasUnsupportedFeature() {
1625 PDFHasUnsupportedFeature(this);
1626}
1627
[email protected]96d185d2009-04-24 03:28:541628// Notifies the RenderWidgetHost instance about the fact that the page is
1629// loading, or done loading and calls the base implementation.
1630void TabContents::SetIsLoading(bool is_loading,
1631 LoadNotificationDetails* details) {
1632 if (is_loading == is_loading_)
1633 return;
1634
1635 if (!is_loading) {
1636 load_state_ = net::LOAD_STATE_IDLE;
1637 load_state_host_.clear();
[email protected]094e5b22009-09-25 04:23:561638 upload_size_ = 0;
1639 upload_position_ = 0;
[email protected]96d185d2009-04-24 03:28:541640 }
1641
1642 render_manager_.SetIsLoading(is_loading);
1643
1644 is_loading_ = is_loading;
1645 waiting_for_response_ = is_loading;
1646
[email protected]6ebdc9b2010-09-27 16:55:571647 if (delegate_)
1648 delegate_->LoadingStateChanged(this);
[email protected]329581b2009-04-28 06:52:351649 NotifyNavigationStateChanged(INVALIDATE_LOAD);
[email protected]96d185d2009-04-24 03:28:541650
1651 NotificationType type = is_loading ? NotificationType::LOAD_START :
1652 NotificationType::LOAD_STOP;
[email protected]ce5c4502009-05-06 16:46:111653 NotificationDetails det = NotificationService::NoDetails();
[email protected]96d185d2009-04-24 03:28:541654 if (details)
1655 det = Details<LoadNotificationDetails>(details);
1656 NotificationService::current()->Notify(type,
1657 Source<NavigationController>(&controller_),
1658 det);
1659}
1660
[email protected]b6c874582009-05-08 19:38:311661void TabContents::AddPopup(TabContents* new_contents,
[email protected]7e7414ae2010-01-26 20:19:291662 const gfx::Rect& initial_pos) {
[email protected]57eda82a2010-05-05 21:28:061663 // A page can't spawn popups (or do anything else, either) until its load
1664 // commits, so when we reach here, the popup was spawned by the
1665 // NavigationController's last committed entry, not the active entry. For
1666 // example, if a page opens a popup in an onunload() handler, then the active
1667 // entry is the page to be loaded as we navigate away from the unloading
1668 // page. For this reason, we can't use GetURL() to get the opener URL,
1669 // because it returns the active entry.
1670 NavigationEntry* entry = controller_.GetLastCommittedEntry();
1671 GURL creator = entry ? entry->virtual_url() : GURL::EmptyGURL();
1672
1673 if (creator.is_valid() &&
[email protected]8cc8d492010-02-02 10:40:491674 profile()->GetHostContentSettingsMap()->GetContentSetting(
[email protected]ca352452010-08-06 11:14:091675 creator, CONTENT_SETTINGS_TYPE_POPUPS, "") == CONTENT_SETTING_ALLOW) {
[email protected]8cc8d492010-02-02 10:40:491676 AddNewContents(new_contents, NEW_POPUP, initial_pos, true);
1677 } else {
[email protected]c65e2f152010-10-14 15:30:401678 if (!blocked_contents_)
1679 blocked_contents_ = new BlockedContentContainer(this);
1680 blocked_contents_->AddTabContents(new_contents, NEW_POPUP, initial_pos,
1681 true);
[email protected]55126132010-08-19 14:53:281682 content_settings_delegate_->OnContentBlocked(CONTENT_SETTINGS_TYPE_POPUPS,
1683 std::string());
[email protected]8cc8d492010-02-02 10:40:491684 }
[email protected]b9681312008-11-07 00:08:261685}
[email protected]616ed5a2008-11-21 22:27:241686
[email protected]616ed5a2008-11-21 22:27:241687void TabContents::ExpireInfoBars(
1688 const NavigationController::LoadCommittedDetails& details) {
1689 // Only hide InfoBars when the user has done something that makes the main
1690 // frame load. We don't want various automatic or subframe navigations making
1691 // it disappear.
1692 if (!details.is_user_initiated_main_frame_load())
1693 return;
1694
[email protected]ec8f51162011-02-08 04:20:401695 // NOTE: It is not safe to change the following code to count upwards or use
1696 // iterators, as the RemoveInfoBar() call synchronously modifies our delegate
1697 // list.
1698 for (size_t i = infobar_count(); i > 0; --i) {
1699 InfoBarDelegate* delegate = GetInfoBarDelegateAt(i - 1);
[email protected]f86a07022008-11-25 01:06:051700 if (delegate->ShouldExpire(details))
[email protected]616ed5a2008-11-21 22:27:241701 RemoveInfoBar(delegate);
[email protected]616ed5a2008-11-21 22:27:241702 }
1703}
[email protected]fdd61c62009-04-22 19:22:571704
[email protected]d0980792011-02-13 19:41:401705WebUI* TabContents::GetWebUIForCurrentState() {
[email protected]7ade2732011-02-10 00:13:581706 // When there is a pending navigation entry, we want to use the pending WebUI
[email protected]96d185d2009-04-24 03:28:541707 // that goes along with it to control the basic flags. For example, we want to
1708 // show the pending URL in the URL bar, so we want the display_url flag to
1709 // be from the pending entry.
1710 //
1711 // The confusion comes because there are multiple possibilities for the
1712 // initial load in a tab as a side effect of the way the RenderViewHostManager
1713 // works.
1714 //
[email protected]e0112912011-02-02 22:54:351715 // - For the very first tab the load looks "normal". The new tab Web UI is
[email protected]96d185d2009-04-24 03:28:541716 // the pending one, and we want it to apply here.
1717 //
1718 // - For subsequent new tabs, they'll get a new SiteInstance which will then
1719 // get switched to the one previously associated with the new tab pages.
[email protected]7ade2732011-02-10 00:13:581720 // This switching will cause the manager to commit the RVH/WebUI. So we'll
[email protected]e0112912011-02-02 22:54:351721 // have a committed Web UI in this case.
[email protected]96d185d2009-04-24 03:28:541722 //
1723 // This condition handles all of these cases:
1724 //
1725 // - First load in first tab: no committed nav entry + pending nav entry +
1726 // pending dom ui:
[email protected]e0112912011-02-02 22:54:351727 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541728 //
1729 // - First load in second tab: no committed nav entry + pending nav entry +
[email protected]e0112912011-02-02 22:54:351730 // no pending Web UI:
1731 // -> Use the committed Web UI if any.
[email protected]96d185d2009-04-24 03:28:541732 //
1733 // - Second navigation in any tab: committed nav entry + pending nav entry:
[email protected]e0112912011-02-02 22:54:351734 // -> Use pending Web UI if any.
[email protected]96d185d2009-04-24 03:28:541735 //
1736 // - Normal state with no load: committed nav entry + no pending nav entry:
[email protected]e0112912011-02-02 22:54:351737 // -> Use committed Web UI.
[email protected]96d185d2009-04-24 03:28:541738 if (controller_.pending_entry() &&
1739 (controller_.GetLastCommittedEntry() ||
[email protected]7ade2732011-02-10 00:13:581740 render_manager_.pending_web_ui()))
1741 return render_manager_.pending_web_ui();
1742 return render_manager_.web_ui();
[email protected]96d185d2009-04-24 03:28:541743}
[email protected]420ae012009-04-24 05:16:321744
1745void TabContents::DidNavigateMainFramePostCommit(
1746 const NavigationController::LoadCommittedDetails& details,
1747 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]80a8fad2011-01-29 04:02:381748 if (opener_web_ui_type_ != WebUIFactory::kNoWebUI) {
1749 // If this is a window.open navigation, use the same WebUI as the renderer
[email protected]c2e74fe82009-09-03 17:57:441750 // that opened the window, as long as both renderers have the same
1751 // privileges.
[email protected]80a8fad2011-01-29 04:02:381752 if (opener_web_ui_type_ ==
1753 WebUIFactory::GetWebUIType(profile(), GetURL())) {
[email protected]7ade2732011-02-10 00:13:581754 WebUI* web_ui = WebUIFactory::CreateWebUIForURL(this, GetURL());
1755 // web_ui might be NULL if the URL refers to a non-existent extension.
1756 if (web_ui) {
[email protected]d0980792011-02-13 19:41:401757 render_manager_.SetWebUIPostCommit(web_ui);
[email protected]7ade2732011-02-10 00:13:581758 web_ui->RenderViewCreated(render_view_host());
[email protected]c2e74fe82009-09-03 17:57:441759 }
1760 }
[email protected]80a8fad2011-01-29 04:02:381761 opener_web_ui_type_ = WebUIFactory::kNoWebUI;
[email protected]c2e74fe82009-09-03 17:57:441762 }
1763
[email protected]420ae012009-04-24 05:16:321764 if (details.is_user_initiated_main_frame_load()) {
1765 // Clear the status bubble. This is a workaround for a bug where WebKit
1766 // doesn't let us know that the cursor left an element during a
1767 // transition (this is also why the mouse cursor remains as a hand after
1768 // clicking on a link); see bugs 1184641 and 980803. We don't want to
1769 // clear the bubble when a user navigates to a named anchor in the same
1770 // page.
1771 UpdateTargetURL(details.entry->page_id(), GURL());
[email protected]420ae012009-04-24 05:16:321772 }
1773
[email protected]420ae012009-04-24 05:16:321774 // Allow the new page to set the title again.
1775 received_page_title_ = false;
1776
1777 // Get the favicon, either from history or request it from the net.
[email protected]b5a1d11c2011-02-17 03:09:421778 fav_icon_helper_->FetchFavIcon(details.entry->url());
[email protected]420ae012009-04-24 05:16:321779
[email protected]0de80162010-02-03 04:52:351780 // Clear all page actions, blocked content notifications and browser actions
1781 // for this tab, unless this is an in-page navigation.
[email protected]a6e82fc2010-02-24 22:28:141782 if (!details.is_in_page) {
[email protected]eaa7dd182010-12-14 11:09:001783 ExtensionService* service = profile()->GetExtensionService();
[email protected]92c6f9b92009-10-24 04:35:081784 if (service) {
1785 for (size_t i = 0; i < service->extensions()->size(); ++i) {
[email protected]5d246db22009-10-27 06:17:571786 ExtensionAction* browser_action =
[email protected]92c6f9b92009-10-24 04:35:081787 service->extensions()->at(i)->browser_action();
[email protected]56ce6e52009-10-27 00:10:521788 if (browser_action) {
1789 browser_action->ClearAllValuesForTab(controller().session_id().id());
1790 NotificationService::current()->Notify(
1791 NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
[email protected]5d246db22009-10-27 06:17:571792 Source<ExtensionAction>(browser_action),
[email protected]56ce6e52009-10-27 00:10:521793 NotificationService::NoDetails());
1794 }
[email protected]92c6f9b92009-10-24 04:35:081795
[email protected]5d246db22009-10-27 06:17:571796 ExtensionAction* page_action =
[email protected]56ce6e52009-10-27 00:10:521797 service->extensions()->at(i)->page_action();
1798 if (page_action) {
1799 page_action->ClearAllValuesForTab(controller().session_id().id());
1800 PageActionStateChanged();
1801 }
[email protected]92c6f9b92009-10-24 04:35:081802 }
[email protected]aece2c7f2009-08-27 20:43:171803 }
[email protected]0de80162010-02-03 04:52:351804
1805 // Close blocked popups.
[email protected]c65e2f152010-10-14 15:30:401806 if (blocked_contents_) {
[email protected]0fbd70332010-06-01 19:28:341807 AutoReset<bool> auto_reset(&dont_notify_render_view_, true);
[email protected]c65e2f152010-10-14 15:30:401808 blocked_contents_->Destroy();
1809 blocked_contents_ = NULL;
[email protected]0de80162010-02-03 04:52:351810 }
1811
1812 // Clear "blocked" flags.
[email protected]da4f8a12010-08-19 08:33:411813 content_settings_delegate_->ClearBlockedContentSettingsExceptForCookies();
[email protected]9fb83e82010-07-02 18:24:551814 content_settings_delegate_->GeolocationDidNavigate(details);
[email protected]f17a0ee2010-05-17 17:38:471815
1816 // Once the main frame is navigated, we're no longer considered to have
1817 // displayed insecure content.
1818 displayed_insecure_content_ = false;
[email protected]aece2c7f2009-08-27 20:43:171819 }
[email protected]ce5c4502009-05-06 16:46:111820
[email protected]8cc8d492010-02-02 10:40:491821 // Close constrained windows if necessary.
1822 if (!net::RegistryControlledDomainService::SameDomainOrHost(
1823 details.previous_url, details.entry->url()))
1824 CloseConstrainedWindows();
1825
[email protected]3c9e1872010-11-18 16:17:491826 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171827 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491828 DidNavigateMainFramePostCommit(details, params));
[email protected]420ae012009-04-24 05:16:321829}
1830
1831void TabContents::DidNavigateAnyFramePostCommit(
1832 RenderViewHost* render_view_host,
1833 const NavigationController::LoadCommittedDetails& details,
1834 const ViewHostMsg_FrameNavigate_Params& params) {
1835 // If we navigate, start showing messages again. This does nothing to prevent
1836 // a malicious script from spamming messages, since the script could just
1837 // reload the page to stop blocking.
1838 suppress_javascript_messages_ = false;
1839
[email protected]3c9e1872010-11-18 16:17:491840 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:171841 FOR_EACH_OBSERVER(TabContentsObserver, observers_,
[email protected]3c9e1872010-11-18 16:17:491842 DidNavigateAnyFramePostCommit(details, params));
[email protected]3b1c1812010-02-12 21:53:551843
1844 // Let the LanguageState clear its state.
[email protected]80fc6112010-08-13 20:10:581845 language_state_.DidNavigate(details);
[email protected]420ae012009-04-24 05:16:321846}
1847
[email protected]8cc8d492010-02-02 10:40:491848void TabContents::CloseConstrainedWindows() {
1849 // Clear out any constrained windows since we are leaving this page entirely.
[email protected]420ae012009-04-24 05:16:321850 // We use indices instead of iterators in case CloseWindow does something
1851 // that may invalidate an iterator.
[email protected]61d68ef12011-01-13 14:02:561852 for (size_t i = 0; i < child_windows_.size(); ++i) {
1853 ConstrainedWindow* window = child_windows_[child_windows_.size() - 1 - i];
[email protected]fa1cf0b82010-01-15 21:49:441854 if (window) {
[email protected]420ae012009-04-24 05:16:321855 window->CloseConstrainedWindow();
[email protected]fa1cf0b82010-01-15 21:49:441856 BlockTabContent(false);
1857 }
[email protected]420ae012009-04-24 05:16:321858 }
1859}
1860
[email protected]420ae012009-04-24 05:16:321861void TabContents::UpdateAlternateErrorPageURL() {
1862 GURL url = GetAlternateErrorPageURL();
1863 render_view_host()->SetAlternateErrorPageURL(url);
1864}
1865
1866void TabContents::UpdateWebPreferences() {
1867 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1868}
1869
[email protected]d0b8d092010-10-25 04:05:171870void TabContents::UpdateZoomLevel() {
1871 render_view_host()->SetZoomLevel(GetZoomLevel());
1872}
1873
[email protected]420ae012009-04-24 05:16:321874void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
1875 RenderViewHost* rvh) {
1876 // If we are creating a RVH for a restored controller, then we might
1877 // have more page IDs than the SiteInstance's current max page ID. We must
1878 // make sure that the max page ID is larger than any restored page ID.
1879 // Note that it is ok for conflicting page IDs to exist in another tab
1880 // (i.e., NavigationController), but if any page ID is larger than the max,
1881 // the back/forward list will get confused.
1882 int max_restored_page_id = controller_.max_restored_page_id();
1883 if (max_restored_page_id > 0) {
1884 int curr_max_page_id = site_instance->max_page_id();
1885 if (max_restored_page_id > curr_max_page_id) {
1886 // Need to update the site instance immediately.
1887 site_instance->UpdateMaxPageID(max_restored_page_id);
1888
1889 // Also tell the renderer to update its internal representation. We
1890 // need to reserve enough IDs to make all restored page IDs less than
1891 // the max.
1892 if (curr_max_page_id < 0)
1893 curr_max_page_id = 0;
1894 rvh->ReservePageIDRange(max_restored_page_id - curr_max_page_id);
1895 }
1896 }
1897}
1898
[email protected]ec0b6c42010-08-26 03:16:581899scoped_refptr<history::HistoryAddPageArgs>
1900TabContents::CreateHistoryAddPageArgs(
[email protected]ebe89e062009-08-13 23:16:541901 const GURL& virtual_url,
[email protected]befd8d822009-07-01 04:51:471902 const NavigationController::LoadCommittedDetails& details,
[email protected]420ae012009-04-24 05:16:321903 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]ec0b6c42010-08-26 03:16:581904 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
1905 new history::HistoryAddPageArgs(
1906 params.url, base::Time::Now(), this, params.page_id, params.referrer,
1907 params.redirects, params.transition, history::SOURCE_BROWSED,
1908 details.did_replace_entry));
1909 if (PageTransition::IsMainFrame(params.transition) &&
1910 virtual_url != params.url) {
1911 // Hack on the "virtual" URL so that it will appear in history. For some
1912 // types of URLs, we will display a magic URL that is different from where
1913 // the page is actually navigated. We want the user to see in history what
1914 // they saw in the URL bar, so we add the virtual URL as a redirect. This
1915 // only applies to the main frame, as the virtual URL doesn't apply to
1916 // sub-frames.
1917 add_page_args->url = virtual_url;
1918 if (!add_page_args->redirects.empty())
1919 add_page_args->redirects.back() = virtual_url;
[email protected]420ae012009-04-24 05:16:321920 }
[email protected]ec0b6c42010-08-26 03:16:581921 return add_page_args;
[email protected]420ae012009-04-24 05:16:321922}
1923
1924bool TabContents::UpdateTitleForEntry(NavigationEntry* entry,
1925 const std::wstring& title) {
1926 // For file URLs without a title, use the pathname instead. In the case of a
1927 // synthesized title, we don't want the update to count toward the "one set
1928 // per page of the title to history."
[email protected]e53668962010-06-23 15:35:251929 string16 final_title;
[email protected]420ae012009-04-24 05:16:321930 bool explicit_set;
1931 if (entry->url().SchemeIsFile() && title.empty()) {
[email protected]e53668962010-06-23 15:35:251932 final_title = UTF8ToUTF16(entry->url().ExtractFileName());
[email protected]420ae012009-04-24 05:16:321933 explicit_set = false; // Don't count synthetic titles toward the set limit.
1934 } else {
[email protected]e53668962010-06-23 15:35:251935 TrimWhitespace(WideToUTF16Hack(title), TRIM_ALL, &final_title);
[email protected]420ae012009-04-24 05:16:321936 explicit_set = true;
1937 }
1938
[email protected]e53668962010-06-23 15:35:251939 if (final_title == entry->title())
[email protected]420ae012009-04-24 05:16:321940 return false; // Nothing changed, don't bother.
1941
[email protected]e53668962010-06-23 15:35:251942 entry->set_title(final_title);
[email protected]420ae012009-04-24 05:16:321943
[email protected]ec0b6c42010-08-26 03:16:581944 if (!received_page_title_) {
1945 UpdateHistoryPageTitle(*entry);
[email protected]420ae012009-04-24 05:16:321946 received_page_title_ = explicit_set;
1947 }
1948
1949 // Lastly, set the title for the view.
[email protected]e53668962010-06-23 15:35:251950 view_->SetPageTitle(UTF16ToWideHack(final_title));
[email protected]420ae012009-04-24 05:16:321951
[email protected]cbc0e1b2010-04-12 18:33:041952 NotificationService::current()->Notify(
1953 NotificationType::TAB_CONTENTS_TITLE_UPDATED,
1954 Source<TabContents>(this),
1955 NotificationService::NoDetails());
1956
[email protected]420ae012009-04-24 05:16:321957 return true;
1958}
1959
1960void TabContents::NotifySwapped() {
1961 // After sending out a swap notification, we need to send a disconnect
1962 // notification so that clients that pick up a pointer to |this| can NULL the
1963 // pointer. See Bug 1230284.
1964 notify_disconnection_ = true;
1965 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341966 NotificationType::TAB_CONTENTS_SWAPPED,
[email protected]d82ed61e2009-06-16 02:46:221967 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321968 NotificationService::NoDetails());
1969}
1970
1971void TabContents::NotifyConnected() {
1972 notify_disconnection_ = true;
1973 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341974 NotificationType::TAB_CONTENTS_CONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221975 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321976 NotificationService::NoDetails());
1977}
1978
1979void TabContents::NotifyDisconnected() {
1980 if (!notify_disconnection_)
1981 return;
1982
1983 notify_disconnection_ = false;
1984 NotificationService::current()->Notify(
[email protected]57c6a652009-05-04 07:58:341985 NotificationType::TAB_CONTENTS_DISCONNECTED,
[email protected]d82ed61e2009-06-16 02:46:221986 Source<TabContents>(this),
[email protected]420ae012009-04-24 05:16:321987 NotificationService::NoDetails());
1988}
1989
[email protected]7d472472011-01-22 01:30:251990void TabContents::OnGoToEntryAtOffset(int offset) {
[email protected]876bc832010-09-07 16:29:541991 if (!delegate_ || delegate_->OnGoToEntryOffset(offset)) {
1992 NavigationEntry* entry = controller_.GetEntryAtOffset(offset);
1993 if (!entry)
1994 return;
1995 // Note that we don't call NavigationController::GotToOffset() as we don't
1996 // want to create a pending navigation entry (it might end up lingering
1997 // http://crbug.com/51680).
[email protected]784688a62010-09-13 07:06:521998 entry->set_transition_type(entry->transition_type() |
1999 PageTransition::FORWARD_BACK);
[email protected]876bc832010-09-07 16:29:542000 NavigateToEntry(*entry, NavigationController::NO_RELOAD);
2001 }
[email protected]bf5c2ff392009-07-08 16:24:332002}
2003
[email protected]38789d82010-11-17 06:03:442004void TabContents::OnDidGetApplicationInfo(int32 page_id,
2005 const WebApplicationInfo& info) {
[email protected]ed5431872009-11-17 08:39:512006 web_app_info_ = info;
[email protected]bf5c2ff392009-07-08 16:24:332007
[email protected]ed5431872009-11-17 08:39:512008 if (delegate())
2009 delegate()->OnDidGetApplicationInfo(this, page_id);
[email protected]bf5c2ff392009-07-08 16:24:332010}
2011
[email protected]bb461532010-11-26 21:50:232012void TabContents::OnInstallApplication(const WebApplicationInfo& info) {
2013 if (delegate())
2014 delegate()->OnInstallApplication(this, info);
2015}
2016
[email protected]a2cf65eb2010-01-18 08:20:382017void TabContents::OnPageContents(const GURL& url,
[email protected]a2cf65eb2010-01-18 08:20:382018 int32 page_id,
[email protected]e5106202010-06-11 21:12:362019 const string16& contents,
[email protected]1c57b7b2010-07-12 17:38:102020 const std::string& language,
2021 bool page_translatable) {
[email protected]a2cf65eb2010-01-18 08:20:382022 // Don't index any https pages. People generally don't want their bank
2023 // accounts, etc. indexed on their computer, especially since some of these
2024 // things are not marked cachable.
2025 // TODO(brettw) we may want to consider more elaborate heuristics such as
2026 // the cachability of the page. We may also want to consider subframes (this
2027 // test will still index subframes if the subframe is SSL).
[email protected]ccd40a52010-05-11 16:15:272028 // TODO(zelidrag) bug chromium-os:2808 - figure out if we want to reenable
2029 // content indexing for chromeos in some future releases.
2030#if !defined(OS_CHROMEOS)
[email protected]a2cf65eb2010-01-18 08:20:382031 if (!url.SchemeIsSecure()) {
2032 Profile* p = profile();
2033 if (p && !p->IsOffTheRecord()) {
2034 HistoryService* hs = p->GetHistoryService(Profile::IMPLICIT_ACCESS);
2035 if (hs)
2036 hs->SetPageContents(url, contents);
2037 }
2038 }
[email protected]ccd40a52010-05-11 16:15:272039#endif
[email protected]a8a81292010-01-21 00:32:452040
[email protected]1c57b7b2010-07-12 17:38:102041 language_state_.LanguageDetermined(language, page_translatable);
[email protected]a8a81292010-01-21 00:32:452042
2043 std::string lang = language;
2044 NotificationService::current()->Notify(
2045 NotificationType::TAB_LANGUAGE_DETERMINED,
[email protected]7e0831b2010-02-01 08:45:152046 Source<TabContents>(this),
[email protected]a8a81292010-01-21 00:32:452047 Details<std::string>(&lang));
[email protected]d54169e92011-01-21 09:19:522048
2049 // Generate the thumbnail here if the in-browser thumbnailing is enabled.
2050 if (CommandLine::ForCurrentProcess()->HasSwitch(
2051 switches::kEnableInBrowserThumbnailing)) {
2052 ThumbnailGenerator::UpdateThumbnailIfNecessary(this, url);
2053 }
[email protected]a2cf65eb2010-01-18 08:20:382054}
2055
[email protected]7e0831b2010-02-01 08:45:152056void TabContents::OnPageTranslated(int32 page_id,
2057 const std::string& original_lang,
[email protected]152b8ba32010-03-29 19:40:162058 const std::string& translated_lang,
2059 TranslateErrors::Type error_type) {
[email protected]3b1c1812010-02-12 21:53:552060 language_state_.set_current_language(translated_lang);
2061 language_state_.set_translation_pending(false);
[email protected]152b8ba32010-03-29 19:40:162062 PageTranslatedDetails details(original_lang, translated_lang, error_type);
[email protected]7e0831b2010-02-01 08:45:152063 NotificationService::current()->Notify(
2064 NotificationType::PAGE_TRANSLATED,
2065 Source<TabContents>(this),
[email protected]152b8ba32010-03-29 19:40:162066 Details<PageTranslatedDetails>(&details));
[email protected]7e0831b2010-02-01 08:45:152067}
2068
[email protected]ce833282010-11-04 15:48:392069void TabContents::OnSetSuggestions(
2070 int32 page_id,
2071 const std::vector<std::string>& suggestions) {
[email protected]15d9c0c2010-09-10 22:36:262072 if (delegate())
[email protected]ce833282010-11-04 15:48:392073 delegate()->OnSetSuggestions(page_id, suggestions);
2074}
2075
2076void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) {
2077 if (delegate())
2078 delegate()->OnInstantSupportDetermined(page_id, result);
[email protected]15d9c0c2010-09-10 22:36:262079}
2080
[email protected]34f128d2011-01-25 19:07:442081void TabContents::OnRunFileChooser(
2082 const ViewHostMsg_RunFileChooser_Params& params) {
2083 if (file_select_helper_.get() == NULL)
2084 file_select_helper_.reset(new FileSelectHelper(profile()));
2085 file_select_helper_->RunFileChooser(render_view_host(), params);
2086}
2087
2088
[email protected]dcd5b332010-08-11 08:55:182089void TabContents::OnContentSettingsAccessed(bool content_was_blocked) {
[email protected]614c0e12010-03-25 10:12:562090 if (delegate_)
[email protected]20ad6a92010-04-21 14:07:242091 delegate_->OnContentSettingsChange(this);
[email protected]614c0e12010-03-25 10:12:562092}
2093
[email protected]8d3347f2009-07-09 22:00:212094RenderViewHostDelegate::View* TabContents::GetViewDelegate() {
[email protected]420ae012009-04-24 05:16:322095 return view_.get();
2096}
2097
[email protected]8d3347f2009-07-09 22:00:212098RenderViewHostDelegate::RendererManagement*
2099TabContents::GetRendererManagementDelegate() {
2100 return &render_manager_;
2101}
2102
[email protected]46ba9082010-06-22 10:00:582103RenderViewHostDelegate::ContentSettings*
2104TabContents::GetContentSettingsDelegate() {
[email protected]9fb83e82010-07-02 18:24:552105 return content_settings_delegate_.get();
[email protected]46ba9082010-06-22 10:00:582106}
2107
[email protected]1f18184a2010-07-21 19:34:492108RenderViewHostDelegate::SSL* TabContents::GetSSLDelegate() {
2109 return GetSSLHelper();
2110}
2111
[email protected]fd571bb2010-03-19 01:23:542112AutomationResourceRoutingDelegate*
2113TabContents::GetAutomationResourceRoutingDelegate() {
2114 return delegate();
2115}
2116
[email protected]ced90ae12010-02-20 02:06:162117RenderViewHostDelegate::BookmarkDrag* TabContents::GetBookmarkDragDelegate() {
2118 return bookmark_drag_;
2119}
2120
2121void TabContents::SetBookmarkDragDelegate(
2122 RenderViewHostDelegate::BookmarkDrag* bookmark_drag) {
2123 bookmark_drag_ = bookmark_drag;
2124}
2125
[email protected]9fb83e82010-07-02 18:24:552126TabSpecificContentSettings* TabContents::GetTabSpecificContentSettings() const {
2127 return content_settings_delegate_.get();
2128}
2129
[email protected]93623c5d2009-12-10 21:40:322130RendererPreferences TabContents::GetRendererPrefs(Profile* profile) const {
[email protected]840b1512009-07-21 16:53:462131 return renderer_preferences_;
[email protected]80d96fa2009-06-10 22:34:512132}
2133
[email protected]57c6a652009-05-04 07:58:342134TabContents* TabContents::GetAsTabContents() {
2135 return this;
2136}
2137
[email protected]7b291f92009-08-14 05:43:532138ViewType::Type TabContents::GetRenderViewType() const {
2139 return ViewType::TAB_CONTENTS;
2140}
2141
2142int TabContents::GetBrowserWindowID() const {
2143 return controller().window_id().id();
2144}
2145
[email protected]420ae012009-04-24 05:16:322146void TabContents::RenderViewCreated(RenderViewHost* render_view_host) {
[email protected]2e4633c2009-07-09 16:58:062147 NotificationService::current()->Notify(
2148 NotificationType::RENDER_VIEW_HOST_CREATED_FOR_TAB,
2149 Source<TabContents>(this),
2150 Details<RenderViewHost>(render_view_host));
[email protected]420ae012009-04-24 05:16:322151 NavigationEntry* entry = controller_.GetActiveEntry();
2152 if (!entry)
2153 return;
2154
2155 // When we're creating views, we're still doing initial setup, so we always
[email protected]e0112912011-02-02 22:54:352156 // use the pending Web UI rather than any possibly existing committed one.
[email protected]7ade2732011-02-10 00:13:582157 if (render_manager_.pending_web_ui()) {
2158 render_manager_.pending_web_ui()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322159 }
2160
2161 if (entry->IsViewSourceMode()) {
2162 // Put the renderer in view source mode.
2163 render_view_host->Send(
2164 new ViewMsg_EnableViewSourceMode(render_view_host->routing_id()));
2165 }
[email protected]0666aef2009-05-13 19:48:082166
2167 view()->RenderViewCreated(render_view_host);
[email protected]420ae012009-04-24 05:16:322168}
2169
2170void TabContents::RenderViewReady(RenderViewHost* rvh) {
2171 if (rvh != render_view_host()) {
2172 // Don't notify the world, since this came from a renderer in the
2173 // background.
2174 return;
2175 }
2176
2177 NotifyConnected();
[email protected]9d8a4642009-07-29 17:25:302178 bool was_crashed = is_crashed();
[email protected]443b80e2010-12-14 00:42:232179 SetIsCrashed(base::TERMINATION_STATUS_STILL_RUNNING, 0);
[email protected]9d8a4642009-07-29 17:25:302180
2181 // Restore the focus to the tab (otherwise the focus will be on the top
2182 // window).
[email protected]484ae5912010-09-29 19:16:142183 if (was_crashed && !FocusLocationBarByDefault() &&
2184 (!delegate_ || delegate_->ShouldFocusPageAfterCrash())) {
[email protected]9d8a4642009-07-29 17:25:302185 Focus();
[email protected]484ae5912010-09-29 19:16:142186 }
[email protected]420ae012009-04-24 05:16:322187}
2188
[email protected]443b80e2010-12-14 00:42:232189void TabContents::RenderViewGone(RenderViewHost* rvh,
2190 base::TerminationStatus status,
2191 int error_code) {
[email protected]420ae012009-04-24 05:16:322192 // Ask the print preview if this renderer was valuable.
[email protected]12802702010-07-09 19:43:092193 if (!printing_->OnRenderViewGone(rvh))
[email protected]420ae012009-04-24 05:16:322194 return;
2195 if (rvh != render_view_host()) {
2196 // The pending page's RenderViewHost is gone.
2197 return;
2198 }
2199
2200 SetIsLoading(false, NULL);
2201 NotifyDisconnected();
[email protected]443b80e2010-12-14 00:42:232202 SetIsCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322203
[email protected]ff9efc62010-02-18 22:10:542204 // Remove all infobars.
[email protected]ec8f51162011-02-08 04:20:402205 while (!infobar_delegates_.empty())
2206 RemoveInfoBar(GetInfoBarDelegateAt(infobar_count() - 1));
[email protected]ff9efc62010-02-18 22:10:542207
[email protected]8e537302009-06-10 21:19:582208 // Tell the view that we've crashed so it can prepare the sad tab page.
[email protected]cf68b092010-01-15 20:05:552209 // Only do this if we're not in browser shutdown, so that TabContents
2210 // objects that are not in a browser (e.g., HTML dialogs) and thus are
2211 // visible do not flash a sad tab page.
2212 if (browser_shutdown::GetShutdownType() == browser_shutdown::NOT_VALID)
[email protected]a8f024392011-01-13 21:50:162213 view_->OnTabCrashed(status, error_code);
[email protected]420ae012009-04-24 05:16:322214
2215 // Hide any visible hung renderer warning for this web contents' process.
[email protected]e7b8d832009-11-20 22:41:002216 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322217}
2218
[email protected]2e4633c2009-07-09 16:58:062219void TabContents::RenderViewDeleted(RenderViewHost* rvh) {
2220 NotificationService::current()->Notify(
2221 NotificationType::RENDER_VIEW_HOST_DELETED,
2222 Source<TabContents>(this),
2223 Details<RenderViewHost>(rvh));
[email protected]fb7b79f72009-11-06 18:00:482224 render_manager_.RenderViewDeleted(rvh);
[email protected]2e4633c2009-07-09 16:58:062225}
2226
[email protected]420ae012009-04-24 05:16:322227void TabContents::DidNavigate(RenderViewHost* rvh,
2228 const ViewHostMsg_FrameNavigate_Params& params) {
[email protected]8030f012009-09-25 18:09:372229 int extra_invalidate_flags = 0;
2230
2231 if (PageTransition::IsMainFrame(params.transition)) {
[email protected]e7d50892011-01-19 21:47:382232 if (MaybeUsePreloadedPage(params.url)) {
2233 return;
[email protected]33f74972010-12-08 16:40:362234 }
2235
[email protected]20ede072009-10-06 00:28:352236 bool was_bookmark_bar_visible = ShouldShowBookmarkBar();
[email protected]8030f012009-09-25 18:09:372237
[email protected]420ae012009-04-24 05:16:322238 render_manager_.DidNavigateMainFrame(rvh);
2239
[email protected]20ede072009-10-06 00:28:352240 if (was_bookmark_bar_visible != ShouldShowBookmarkBar())
[email protected]8030f012009-09-25 18:09:372241 extra_invalidate_flags |= INVALIDATE_BOOKMARK_BAR;
[email protected]8030f012009-09-25 18:09:372242 }
2243
[email protected]420ae012009-04-24 05:16:322244 // Update the site of the SiteInstance if it doesn't have one yet.
2245 if (!GetSiteInstance()->has_site())
2246 GetSiteInstance()->SetSite(params.url);
2247
2248 // Need to update MIME type here because it's referred to in
2249 // UpdateNavigationCommands() called by RendererDidNavigate() to
2250 // determine whether or not to enable the encoding menu.
2251 // It's updated only for the main frame. For a subframe,
2252 // RenderView::UpdateURL does not set params.contents_mime_type.
2253 // (see http://code.google.com/p/chromium/issues/detail?id=2929 )
2254 // TODO(jungshik): Add a test for the encoding menu to avoid
2255 // regressing it again.
2256 if (PageTransition::IsMainFrame(params.transition))
2257 contents_mime_type_ = params.contents_mime_type;
2258
2259 NavigationController::LoadCommittedDetails details;
[email protected]8030f012009-09-25 18:09:372260 bool did_navigate = controller_.RendererDidNavigate(
2261 params, extra_invalidate_flags, &details);
[email protected]3e90d4a2009-07-03 17:38:392262
[email protected]a9c0bfe2010-09-17 08:35:222263 // Send notification about committed provisional loads. This notification is
2264 // different from the NAV_ENTRY_COMMITTED notification which doesn't include
2265 // the actual URL navigated to and isn't sent for AUTO_SUBFRAME navigations.
2266 if (details.type != NavigationType::NAV_IGNORE) {
[email protected]dabb0d12010-10-05 12:50:072267 // For AUTO_SUBFRAME navigations, an event for the main frame is generated
2268 // that is not recorded in the navigation history. For the purpose of
2269 // tracking navigation events, we treat this event as a sub frame navigation
2270 // event.
2271 bool is_main_frame = did_navigate ? details.is_main_frame : false;
2272 ProvisionalLoadDetails load_details(
2273 is_main_frame, details.is_in_page, params.url, std::string(), false,
[email protected]dd0aafd2010-12-02 13:13:412274 false, params.frame_id);
[email protected]a9c0bfe2010-09-17 08:35:222275 load_details.set_transition_type(params.transition);
2276 // Whether or not a page transition was triggered by going backward or
2277 // forward in the history is only stored in the navigation controller's
2278 // entry list.
2279 if (did_navigate &&
2280 (controller_.GetActiveEntry()->transition_type() &
2281 PageTransition::FORWARD_BACK)) {
2282 load_details.set_transition_type(
2283 params.transition | PageTransition::FORWARD_BACK);
2284 }
2285 NotificationService::current()->Notify(
2286 NotificationType::FRAME_PROVISIONAL_LOAD_COMMITTED,
2287 Source<NavigationController>(&controller_),
2288 Details<ProvisionalLoadDetails>(&load_details));
[email protected]a9c0bfe2010-09-17 08:35:222289 }
2290
[email protected]3e90d4a2009-07-03 17:38:392291 // Update history. Note that this needs to happen after the entry is complete,
2292 // which WillNavigate[Main,Sub]Frame will do before this function is called.
[email protected]ec0b6c42010-08-26 03:16:582293 if (params.should_update_history) {
[email protected]3e90d4a2009-07-03 17:38:392294 // Most of the time, the displayURL matches the loaded URL, but for about:
[email protected]ec0b6c42010-08-26 03:16:582295 // URLs, we use a data: URL as the real value. We actually want to save the
2296 // about: URL to the history db and keep the data: URL hidden. This is what
2297 // the TabContents' URL getter does.
2298 scoped_refptr<history::HistoryAddPageArgs> add_page_args(
2299 CreateHistoryAddPageArgs(GetURL(), details, params));
2300 if (!delegate() ||
2301 delegate()->ShouldAddNavigationToHistory(*add_page_args,
2302 details.type)) {
2303 UpdateHistoryForNavigation(add_page_args);
2304 }
[email protected]3e90d4a2009-07-03 17:38:392305 }
2306
[email protected]76543b92009-08-31 17:27:452307 if (!did_navigate)
2308 return; // No navigation happened.
[email protected]420ae012009-04-24 05:16:322309
2310 // DO NOT ADD MORE STUFF TO THIS FUNCTION! Your component should either listen
2311 // for the appropriate notification (best) or you can add it to
2312 // DidNavigateMainFramePostCommit / DidNavigateAnyFramePostCommit (only if
2313 // necessary, please).
2314
2315 // Run post-commit tasks.
2316 if (details.is_main_frame)
2317 DidNavigateMainFramePostCommit(details, params);
2318 DidNavigateAnyFramePostCommit(rvh, details, params);
2319}
2320
2321void TabContents::UpdateState(RenderViewHost* rvh,
2322 int32 page_id,
2323 const std::string& state) {
2324 DCHECK(rvh == render_view_host());
2325
2326 // We must be prepared to handle state updates for any page, these occur
2327 // when the user is scrolling and entering form data, as well as when we're
2328 // leaving a page, in which case our state may have already been moved to
2329 // the next page. The navigation controller will look up the appropriate
2330 // NavigationEntry and update it when it is notified via the delegate.
2331
2332 int entry_index = controller_.GetEntryIndexWithPageID(
2333 GetSiteInstance(), page_id);
2334 if (entry_index < 0)
2335 return;
2336 NavigationEntry* entry = controller_.GetEntryAtIndex(entry_index);
2337
2338 if (state == entry->content_state())
2339 return; // Nothing to update.
2340 entry->set_content_state(state);
2341 controller_.NotifyEntryChanged(entry, entry_index);
2342}
2343
2344void TabContents::UpdateTitle(RenderViewHost* rvh,
2345 int32 page_id, const std::wstring& title) {
2346 // If we have a title, that's a pretty good indication that we've started
2347 // getting useful data.
2348 SetNotWaitingForResponse();
2349
2350 DCHECK(rvh == render_view_host());
[email protected]371cc8b2010-09-01 16:03:482351 NavigationEntry* entry = controller_.GetEntryWithPageID(rvh->site_instance(),
[email protected]ec0b6c42010-08-26 03:16:582352 page_id);
[email protected]420ae012009-04-24 05:16:322353 if (!entry || !UpdateTitleForEntry(entry, title))
2354 return;
2355
2356 // Broadcast notifications when the UI should be updated.
2357 if (entry == controller_.GetEntryAtOffset(0))
[email protected]f1cd5e82009-10-23 17:19:032358 NotifyNavigationStateChanged(INVALIDATE_TITLE);
[email protected]420ae012009-04-24 05:16:322359}
2360
[email protected]420ae012009-04-24 05:16:322361void TabContents::UpdateEncoding(RenderViewHost* render_view_host,
[email protected]41fc0322009-09-04 22:23:402362 const std::string& encoding) {
[email protected]420ae012009-04-24 05:16:322363 set_encoding(encoding);
2364}
2365
2366void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) {
2367 if (delegate())
2368 delegate()->UpdateTargetURL(this, url);
2369}
2370
2371void TabContents::UpdateThumbnail(const GURL& url,
2372 const SkBitmap& bitmap,
2373 const ThumbnailScore& score) {
[email protected]e6baed562010-11-02 22:33:442374 if (profile()->IsOffTheRecord())
2375 return;
2376
[email protected]420ae012009-04-24 05:16:322377 // Tell History about this thumbnail
[email protected]54097492f2011-01-18 08:32:072378 history::TopSites* ts = profile()->GetTopSites();
2379 if (ts)
2380 ts->SetPageThumbnail(url, bitmap, score);
[email protected]420ae012009-04-24 05:16:322381}
2382
[email protected]c4e98902010-06-01 10:20:142383void TabContents::UpdateInspectorSetting(const std::string& key,
2384 const std::string& value) {
[email protected]24d27d72010-10-12 16:30:052385 RenderViewHostDelegateHelper::UpdateInspectorSetting(profile(), key, value);
[email protected]0df30122009-06-03 12:13:082386}
2387
[email protected]45aafc92010-06-07 14:18:532388void TabContents::ClearInspectorSettings() {
[email protected]24d27d72010-10-12 16:30:052389 RenderViewHostDelegateHelper::ClearInspectorSettings(profile());
[email protected]45aafc92010-06-07 14:18:532390}
2391
[email protected]420ae012009-04-24 05:16:322392void TabContents::Close(RenderViewHost* rvh) {
[email protected]07707302009-11-06 00:50:292393 // The UI may be in an event-tracking loop, such as between the
2394 // mouse-down and mouse-up in text selection or a button click.
2395 // Defer the close until after tracking is complete, so that we
2396 // don't free objects out from under the UI.
2397 // TODO(shess): This could probably be integrated with the
2398 // IsDoingDrag() test below. Punting for now because I need more
2399 // research to understand how this impacts platforms other than Mac.
2400 // TODO(shess): This could get more fine-grained. For instance,
2401 // closing a tab in another window while selecting text in the
2402 // current window's Omnibox should be just fine.
2403 if (view()->IsEventTracking()) {
2404 view()->CloseTabAfterEventTracking();
2405 return;
2406 }
2407
[email protected]24a4d1062009-07-10 23:10:422408 // If we close the tab while we're in the middle of a drag, we'll crash.
2409 // Instead, cancel the drag and close it as soon as the drag ends.
2410 if (view()->IsDoingDrag()) {
2411 view()->CancelDragAndCloseTab();
2412 return;
2413 }
2414
[email protected]420ae012009-04-24 05:16:322415 // Ignore this if it comes from a RenderViewHost that we aren't showing.
2416 if (delegate() && rvh == render_view_host())
2417 delegate()->CloseContents(this);
2418}
2419
2420void TabContents::RequestMove(const gfx::Rect& new_bounds) {
2421 if (delegate() && delegate()->IsPopup(this))
2422 delegate()->MoveContents(this, new_bounds);
2423}
2424
[email protected]7ab1e7d62009-10-14 23:32:012425void TabContents::DidStartLoading() {
[email protected]420ae012009-04-24 05:16:322426 SetIsLoading(true, NULL);
[email protected]3c9e1872010-11-18 16:17:492427
[email protected]de4761b2010-12-07 21:05:212428 if (delegate()) {
2429 bool is_print_preview_tab =
2430 printing::PrintPreviewTabController::IsPrintPreviewTab(this);
2431 if (content_restrictions_ || is_print_preview_tab) {
2432 content_restrictions_= is_print_preview_tab ?
2433 CONTENT_RESTRICTION_PRINT : 0;
2434 delegate()->ContentRestrictionsChanged(this);
2435 }
[email protected]9e823662010-10-13 23:36:002436 }
[email protected]3c9e1872010-11-18 16:17:492437
2438 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172439 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStartLoading());
[email protected]420ae012009-04-24 05:16:322440}
2441
[email protected]7ab1e7d62009-10-14 23:32:012442void TabContents::DidStopLoading() {
[email protected]420ae012009-04-24 05:16:322443 scoped_ptr<LoadNotificationDetails> details;
2444
2445 NavigationEntry* entry = controller_.GetActiveEntry();
2446 // An entry may not exist for a stop when loading an initial blank page or
2447 // if an iframe injected by script into a blank page finishes loading.
2448 if (entry) {
[email protected]420ae012009-04-24 05:16:322449 base::TimeDelta elapsed = base::TimeTicks::Now() - current_load_start_;
2450
2451 details.reset(new LoadNotificationDetails(
[email protected]ebe89e062009-08-13 23:16:542452 entry->virtual_url(),
[email protected]420ae012009-04-24 05:16:322453 entry->transition_type(),
2454 elapsed,
2455 &controller_,
2456 controller_.GetCurrentEntryIndex()));
2457 }
2458
[email protected]420ae012009-04-24 05:16:322459 SetIsLoading(false, details.get());
[email protected]3c9e1872010-11-18 16:17:492460
2461 // Notify observers about navigation.
[email protected]585b30362011-01-28 02:30:172462 FOR_EACH_OBSERVER(TabContentsObserver, observers_, DidStopLoading());
[email protected]420ae012009-04-24 05:16:322463}
2464
[email protected]1a3c3cb2010-12-16 21:03:402465void TabContents::DidChangeLoadProgress(double progress) {
2466 if (delegate())
2467 delegate()->LoadProgressChanged(progress);
2468}
2469
[email protected]25497492010-09-11 15:15:082470void TabContents::DocumentOnLoadCompletedInMainFrame(
2471 RenderViewHost* render_view_host,
2472 int32 page_id) {
2473 NotificationService::current()->Notify(
2474 NotificationType::LOAD_COMPLETED_MAIN_FRAME,
2475 Source<TabContents>(this),
2476 Details<int>(&page_id));
2477}
2478
[email protected]420ae012009-04-24 05:16:322479void TabContents::RequestOpenURL(const GURL& url, const GURL& referrer,
2480 WindowOpenDisposition disposition) {
[email protected]7ade2732011-02-10 00:13:582481 if (render_manager_.web_ui()) {
[email protected]e0112912011-02-02 22:54:352482 // When we're a Web UI, it will provide a page transition type for us (this
[email protected]420ae012009-04-24 05:16:322483 // is so the new tab page can specify AUTO_BOOKMARK for automatically
2484 // generated suggestions).
2485 //
[email protected]e0112912011-02-02 22:54:352486 // Note also that we hide the referrer for Web UI pages. We don't really
[email protected]60e448982009-05-06 04:21:162487 // want web sites to see a referrer of "chrome://blah" (and some
2488 // chrome: URLs might have search terms or other stuff we don't want to
[email protected]420ae012009-04-24 05:16:322489 // send to the site), so we send no referrer.
2490 OpenURL(url, GURL(), disposition,
[email protected]7ade2732011-02-10 00:13:582491 render_manager_.web_ui()->link_transition_type());
[email protected]420ae012009-04-24 05:16:322492 } else {
2493 OpenURL(url, referrer, disposition, PageTransition::LINK);
2494 }
2495}
2496
[email protected]1ee614862009-07-06 20:29:182497void TabContents::DomOperationResponse(const std::string& json_string,
2498 int automation_id) {
2499}
2500
[email protected]badcca352011-02-12 01:08:082501void TabContents::ProcessWebUIMessage(
[email protected]8b8e7c92010-08-19 18:05:562502 const ViewHostMsg_DomMessage_Params& params) {
[email protected]7ade2732011-02-10 00:13:582503 if (!render_manager_.web_ui()) {
[email protected]c2e74fe82009-09-03 17:57:442504 // This can happen if someone uses window.open() to open an extension URL
2505 // from a non-extension context.
[email protected]8b8e7c92010-08-19 18:05:562506 render_view_host()->BlockExtensionRequest(params.request_id);
[email protected]420ae012009-04-24 05:16:322507 return;
2508 }
[email protected]badcca352011-02-12 01:08:082509 render_manager_.web_ui()->ProcessWebUIMessage(params);
[email protected]420ae012009-04-24 05:16:322510}
2511
2512void TabContents::ProcessExternalHostMessage(const std::string& message,
2513 const std::string& origin,
2514 const std::string& target) {
2515 if (delegate())
2516 delegate()->ForwardMessageToExternalHost(message, origin, target);
2517}
2518
[email protected]420ae012009-04-24 05:16:322519void TabContents::RunJavaScriptMessage(
2520 const std::wstring& message,
2521 const std::wstring& default_prompt,
2522 const GURL& frame_url,
2523 const int flags,
2524 IPC::Message* reply_msg,
2525 bool* did_suppress_message) {
2526 // Suppress javascript messages when requested and when inside a constrained
2527 // popup window (because that activates them and breaks them out of the
2528 // constrained window jail).
[email protected]91ed49a2009-07-07 21:29:552529 // Also suppress messages when showing an interstitial. The interstitial is
2530 // shown over the previous page, we don't want the hidden page dialogs to
2531 // interfere with the interstitial.
[email protected]8f55e802010-12-06 18:11:502532 bool suppress_this_message =
2533 suppress_javascript_messages_ ||
2534 showing_interstitial_page() ||
2535 (delegate() && delegate()->ShouldSuppressDialogs());
[email protected]420ae012009-04-24 05:16:322536 if (delegate())
2537 suppress_this_message |=
[email protected]b6c874582009-05-08 19:38:312538 (delegate()->GetConstrainingContents(this) != this);
[email protected]420ae012009-04-24 05:16:322539
2540 *did_suppress_message = suppress_this_message;
2541
2542 if (!suppress_this_message) {
2543 base::TimeDelta time_since_last_message(
2544 base::TimeTicks::Now() - last_javascript_message_dismissal_);
2545 bool show_suppress_checkbox = false;
2546 // Show a checkbox offering to suppress further messages if this message is
2547 // being displayed within kJavascriptMessageExpectedDelay of the last one.
2548 if (time_since_last_message <
2549 base::TimeDelta::FromMilliseconds(kJavascriptMessageExpectedDelay))
2550 show_suppress_checkbox = true;
2551
[email protected]d6ad7442010-09-05 19:06:522552 RunJavascriptMessageBox(profile(), this, frame_url, flags, message,
2553 default_prompt, show_suppress_checkbox, reply_msg);
[email protected]420ae012009-04-24 05:16:322554 } else {
2555 // If we are suppressing messages, just reply as is if the user immediately
2556 // pressed "Cancel".
[email protected]beb440c2009-11-06 04:08:542557 OnMessageBoxClosed(reply_msg, false, std::wstring());
[email protected]420ae012009-04-24 05:16:322558 }
2559}
2560
2561void TabContents::RunBeforeUnloadConfirm(const std::wstring& message,
2562 IPC::Message* reply_msg) {
[email protected]5aab5e22010-12-08 22:13:292563 if (delegate())
2564 delegate()->WillRunBeforeUnloadConfirm();
[email protected]8f55e802010-12-06 18:11:502565 if (delegate() && delegate()->ShouldSuppressDialogs()) {
2566 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true,
2567 std::wstring());
2568 return;
2569 }
[email protected]7ab1e7d62009-10-14 23:32:012570 is_showing_before_unload_dialog_ = true;
[email protected]d82ed61e2009-06-16 02:46:222571 RunBeforeUnloadDialog(this, message, reply_msg);
[email protected]420ae012009-04-24 05:16:322572}
2573
2574void TabContents::ShowModalHTMLDialog(const GURL& url, int width, int height,
2575 const std::string& json_arguments,
2576 IPC::Message* reply_msg) {
2577 if (delegate()) {
2578 HtmlDialogUIDelegate* dialog_delegate =
2579 new ModalHtmlDialogDelegate(url, width, height, json_arguments,
[email protected]d82ed61e2009-06-16 02:46:222580 reply_msg, this);
[email protected]420ae012009-04-24 05:16:322581 delegate()->ShowHtmlDialog(dialog_delegate, NULL);
2582 }
2583}
2584
[email protected]420ae012009-04-24 05:16:322585GURL TabContents::GetAlternateErrorPageURL() const {
2586 GURL url;
2587 // Disable alternate error pages when in OffTheRecord/Incognito mode.
2588 if (profile()->IsOffTheRecord())
2589 return url;
2590
2591 PrefService* prefs = profile()->GetPrefs();
2592 DCHECK(prefs);
2593 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
[email protected]a33457b82009-09-21 23:07:152594 url = google_util::AppendGoogleLocaleParam(
2595 GURL(google_util::kLinkDoctorBaseURL));
[email protected]420ae012009-04-24 05:16:322596 url = google_util::AppendGoogleTLDParam(url);
2597 }
2598 return url;
2599}
2600
2601WebPreferences TabContents::GetWebkitPrefs() {
[email protected]6c32ce72010-03-08 05:18:062602 Profile* profile = render_view_host()->process()->profile();
[email protected]7ade2732011-02-10 00:13:582603 bool is_web_ui = false;
[email protected]447021c2010-09-08 21:29:082604 WebPreferences web_prefs =
[email protected]7ade2732011-02-10 00:13:582605 RenderViewHostDelegateHelper::GetWebkitPrefs(profile, is_web_ui);
[email protected]447021c2010-09-08 21:29:082606
[email protected]9beff752010-09-22 19:35:432607 // Force accelerated compositing and 2d canvas off for chrome: and
2608 // chrome-extension: pages.
[email protected]27c790d42010-10-22 09:28:432609 if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) ||
2610 GetURL().SchemeIs(chrome::kChromeUIScheme)) {
[email protected]447021c2010-09-08 21:29:082611 web_prefs.accelerated_compositing_enabled = false;
[email protected]9beff752010-09-22 19:35:432612 web_prefs.accelerated_2d_canvas_enabled = false;
[email protected]447021c2010-09-08 21:29:082613 }
2614
[email protected]39553442010-09-09 00:01:552615#if defined(OS_MACOSX)
2616 // Disable accelerated compositing if IOSurface's are not supported,
2617 // as is the case in 10.5.
2618 if (!IOSurfaceSupport::Initialize())
2619 web_prefs.accelerated_compositing_enabled = false;
2620#endif
2621
[email protected]447021c2010-09-08 21:29:082622 return web_prefs;
[email protected]420ae012009-04-24 05:16:322623}
2624
[email protected]7d472472011-01-22 01:30:252625void TabContents::OnUserGesture() {
2626 // See comment in RenderViewHostDelegate::OnUserGesture as to why we do this.
2627 DownloadRequestLimiter* limiter =
2628 g_browser_process->download_request_limiter();
2629 if (limiter)
2630 limiter->OnUserGesture(this);
2631 ExternalProtocolHandler::PermitLaunchUrl();
2632}
2633
[email protected]fa1cf0b82010-01-15 21:49:442634void TabContents::OnIgnoredUIEvent() {
2635 if (constrained_window_count()) {
2636 ConstrainedWindow* window = *constrained_window_begin();
2637 window->FocusConstrainedWindow();
2638 }
2639}
2640
[email protected]420ae012009-04-24 05:16:322641void TabContents::OnJSOutOfMemory() {
[email protected]f4f50ef2011-01-21 19:01:192642 AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL,
2643 l10n_util::GetStringUTF16(IDS_JS_OUT_OF_MEMORY_PROMPT), true));
[email protected]420ae012009-04-24 05:16:322644}
2645
[email protected]420ae012009-04-24 05:16:322646void TabContents::OnCrossSiteResponse(int new_render_process_host_id,
2647 int new_request_id) {
[email protected]57c6a652009-05-04 07:58:342648 // Allows the TabContents to react when a cross-site response is ready to be
[email protected]420ae012009-04-24 05:16:322649 // delivered to a pending RenderViewHost. We must first run the onunload
2650 // handler of the old RenderViewHost before we can allow it to proceed.
2651 render_manager_.OnCrossSiteResponse(new_render_process_host_id,
2652 new_request_id);
2653}
2654
[email protected]420ae012009-04-24 05:16:322655void TabContents::RendererUnresponsive(RenderViewHost* rvh,
2656 bool is_during_unload) {
2657 if (is_during_unload) {
2658 // Hang occurred while firing the beforeunload/unload handler.
2659 // Pretend the handler fired so tab closing continues as if it had.
[email protected]829e7612009-04-25 01:15:112660 rvh->set_sudden_termination_allowed(true);
[email protected]420ae012009-04-24 05:16:322661
2662 if (!render_manager_.ShouldCloseTabOnUnresponsiveRenderer())
2663 return;
2664
2665 // If the tab hangs in the beforeunload/unload handler there's really
2666 // nothing we can do to recover. Pretend the unload listeners have
2667 // all fired and close the tab. If the hang is in the beforeunload handler
2668 // then the user will not have the option of cancelling the close.
2669 Close(rvh);
2670 return;
2671 }
2672
[email protected]61b50092011-02-03 18:02:192673 if (render_view_host() && render_view_host()->IsRenderViewLive() &&
2674 (!delegate() || delegate()->ShouldShowHungRendererDialog())) {
[email protected]e7b8d832009-11-20 22:41:002675 hung_renderer_dialog::ShowForTabContents(this);
[email protected]61b50092011-02-03 18:02:192676 }
[email protected]420ae012009-04-24 05:16:322677}
2678
2679void TabContents::RendererResponsive(RenderViewHost* render_view_host) {
[email protected]e7b8d832009-11-20 22:41:002680 hung_renderer_dialog::HideForTabContents(this);
[email protected]420ae012009-04-24 05:16:322681}
2682
2683void TabContents::LoadStateChanged(const GURL& url,
[email protected]094e5b22009-09-25 04:23:562684 net::LoadState load_state,
2685 uint64 upload_position,
2686 uint64 upload_size) {
[email protected]420ae012009-04-24 05:16:322687 load_state_ = load_state;
[email protected]094e5b22009-09-25 04:23:562688 upload_position_ = upload_position;
2689 upload_size_ = upload_size;
[email protected]d686e812009-06-03 19:10:292690 std::wstring languages =
[email protected]ddd231e2010-06-29 20:35:192691 UTF8ToWide(profile()->GetPrefs()->GetString(prefs::kAcceptLanguages));
[email protected]d686e812009-06-03 19:10:292692 std::string host = url.host();
[email protected]42197a22010-12-28 23:29:422693 load_state_host_ = WideToUTF16Hack(
2694 net::IDNToUnicode(host.c_str(), host.size(), languages, NULL));
[email protected]420ae012009-04-24 05:16:322695 if (load_state_ == net::LOAD_STATE_READING_RESPONSE)
2696 SetNotWaitingForResponse();
2697 if (is_loading())
[email protected]c9cd2222009-05-06 05:16:502698 NotifyNavigationStateChanged(INVALIDATE_LOAD | INVALIDATE_TAB);
[email protected]420ae012009-04-24 05:16:322699}
2700
[email protected]1ee614862009-07-06 20:29:182701bool TabContents::IsExternalTabContainer() const {
2702 if (!delegate())
2703 return false;
2704
2705 return delegate()->IsExternalTabContainer();
2706}
2707
[email protected]1ee614862009-07-06 20:29:182708void TabContents::DidInsertCSS() {
2709 // This RVHDelegate function is used for extensions and not us.
[email protected]420ae012009-04-24 05:16:322710}
2711
[email protected]546ae4e02010-12-08 14:57:192712void TabContents::FocusedNodeChanged(bool is_editable_node) {
[email protected]130efb02009-09-18 18:54:352713 NotificationService::current()->Notify(
2714 NotificationType::FOCUS_CHANGED_IN_PAGE,
[email protected]4e85c112011-01-26 22:27:212715 Source<TabContents>(this),
[email protected]546ae4e02010-12-08 14:57:192716 Details<const bool>(&is_editable_node));
[email protected]130efb02009-09-18 18:54:352717}
2718
[email protected]b75b8292010-10-01 07:28:252719void TabContents::UpdateZoomLimits(int minimum_percent,
2720 int maximum_percent,
2721 bool remember) {
2722 minimum_zoom_percent_ = minimum_percent;
2723 maximum_zoom_percent_ = maximum_percent;
2724 temporary_zoom_settings_ = !remember;
[email protected]ebf40a72010-07-22 01:46:382725}
2726
[email protected]7d472472011-01-22 01:30:252727void TabContents::WorkerCrashed() {
2728 AddInfoBar(new SimpleAlertInfoBarDelegate(this, NULL,
2729 l10n_util::GetStringUTF16(IDS_WEBWORKER_CRASHED_PROMPT), true));
2730}
2731
[email protected]420ae012009-04-24 05:16:322732void TabContents::BeforeUnloadFiredFromRenderManager(
2733 bool proceed,
2734 bool* proceed_to_fire_unload) {
2735 if (delegate())
2736 delegate()->BeforeUnloadFired(this, proceed, proceed_to_fire_unload);
2737}
2738
[email protected]3a3d47472010-07-15 21:03:542739void TabContents::DidStartLoadingFromRenderManager(
2740 RenderViewHost* render_view_host) {
2741 DidStartLoading();
2742}
2743
2744void TabContents::RenderViewGoneFromRenderManager(
2745 RenderViewHost* render_view_host) {
[email protected]443b80e2010-12-14 00:42:232746 DCHECK(crashed_status_ != base::TERMINATION_STATUS_STILL_RUNNING);
2747 RenderViewGone(render_view_host, crashed_status_, crashed_error_code_);
[email protected]3a3d47472010-07-15 21:03:542748}
2749
[email protected]420ae012009-04-24 05:16:322750void TabContents::UpdateRenderViewSizeForRenderManager() {
2751 // TODO(brettw) this is a hack. See TabContentsView::SizeContents.
[email protected]0323ee42010-02-17 22:03:262752 gfx::Size size = view_->GetContainerSize();
2753 // 0x0 isn't a valid window size (minimal window size is 1x1) but it may be
2754 // here during container initialization and normal window size will be set
2755 // later. In case of tab duplication this resizing to 0x0 prevents setting
2756 // normal size later so just ignore it.
2757 if (!size.IsEmpty())
2758 view_->SizeContents(size);
[email protected]420ae012009-04-24 05:16:322759}
2760
[email protected]3a3d47472010-07-15 21:03:542761void TabContents::NotifySwappedFromRenderManager() {
2762 NotifySwapped();
2763}
2764
2765NavigationController& TabContents::GetControllerForRenderManager() {
2766 return controller();
2767}
2768
[email protected]d0980792011-02-13 19:41:402769WebUI* TabContents::CreateWebUIForRenderManager(const GURL& url) {
[email protected]80a8fad2011-01-29 04:02:382770 return WebUIFactory::CreateWebUIForURL(this, url);
[email protected]420ae012009-04-24 05:16:322771}
2772
2773NavigationEntry*
2774TabContents::GetLastCommittedNavigationEntryForRenderManager() {
2775 return controller_.GetLastCommittedEntry();
2776}
2777
2778bool TabContents::CreateRenderViewForRenderManager(
2779 RenderViewHost* render_view_host) {
[email protected]420ae012009-04-24 05:16:322780 RenderWidgetHostView* rwh_view = view_->CreateViewForWidget(render_view_host);
[email protected]1a98a932009-11-17 00:12:522781
[email protected]674b3822010-08-04 04:02:512782 if (!render_view_host->CreateRenderView(string16()))
[email protected]420ae012009-04-24 05:16:322783 return false;
2784
2785 // Now that the RenderView has been created, we need to tell it its size.
2786 rwh_view->SetSize(view_->GetContainerSize());
2787
2788 UpdateMaxPageIDIfNecessary(render_view_host->site_instance(),
2789 render_view_host);
2790 return true;
2791}
2792
2793void TabContents::Observe(NotificationType type,
2794 const NotificationSource& source,
2795 const NotificationDetails& details) {
2796 switch (type.value) {
[email protected]420ae012009-04-24 05:16:322797 case NotificationType::PREF_CHANGED: {
[email protected]57ecc4b2010-08-11 03:02:512798 std::string* pref_name_in = Details<std::string>(details).ptr();
[email protected]420ae012009-04-24 05:16:322799 DCHECK(Source<PrefService>(source).ptr() == profile()->GetPrefs());
2800 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) {
2801 UpdateAlternateErrorPageURL();
[email protected]88e14382010-10-14 21:45:532802 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
2803 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
[email protected]420ae012009-04-24 05:16:322804 UpdateWebPreferences();
[email protected]d0b8d092010-10-25 04:05:172805 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
2806 UpdateZoomLevel();
[email protected]420ae012009-04-24 05:16:322807 } else {
2808 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
2809 }
2810 break;
2811 }
2812 case NotificationType::RENDER_WIDGET_HOST_DESTROYED:
2813 view_->RenderWidgetHostDestroyed(Source<RenderWidgetHost>(source).ptr());
2814 break;
2815
2816 case NotificationType::NAV_ENTRY_COMMITTED: {
2817 DCHECK(&controller_ == Source<NavigationController>(source).ptr());
2818
2819 NavigationController::LoadCommittedDetails& committed_details =
2820 *(Details<NavigationController::LoadCommittedDetails>(details).ptr());
2821 ExpireInfoBars(committed_details);
2822 break;
2823 }
2824
[email protected]d3ba77272009-09-03 00:06:092825#if defined(OS_LINUX)
2826 case NotificationType::BROWSER_THEME_CHANGED: {
[email protected]7ff431e2010-01-07 18:18:542827 renderer_preferences_util::UpdateFromSystemSettings(
2828 &renderer_preferences_, profile());
[email protected]d3ba77272009-09-03 00:06:092829 render_view_host()->SyncRendererPrefs();
2830 break;
2831 }
2832#endif
2833
[email protected]6c32ce72010-03-08 05:18:062834 case NotificationType::USER_STYLE_SHEET_UPDATED:
2835 UpdateWebPreferences();
2836 break;
2837
[email protected]79580c62010-02-02 02:36:252838 case NotificationType::CONTENT_SETTINGS_CHANGED: {
[email protected]5f24f212010-12-02 14:47:452839 Details<const ContentSettingsDetails> settings_details(details);
[email protected]79580c62010-02-02 02:36:252840 NavigationEntry* entry = controller_.GetActiveEntry();
[email protected]da0c8e92010-02-09 23:25:492841 GURL entry_url;
[email protected]0314ae02010-04-08 09:18:292842 if (entry)
[email protected]da0c8e92010-02-09 23:25:492843 entry_url = entry->url();
[email protected]0314ae02010-04-08 09:18:292844 if (settings_details.ptr()->update_all() ||
2845 settings_details.ptr()->pattern().Matches(entry_url)) {
2846 render_view_host()->SendContentSettings(entry_url,
[email protected]b9a4ea7f2010-06-25 07:11:232847 profile()->GetHostContentSettingsMap()->
2848 GetContentSettings(entry_url));
[email protected]79580c62010-02-02 02:36:252849 }
2850 break;
2851 }
2852
[email protected]e5adff72010-06-14 18:13:062853 case NotificationType::EXTENSION_LOADED:
[email protected]a888b29e62010-04-01 13:38:572854 break;
[email protected]a888b29e62010-04-01 13:38:572855
2856 case NotificationType::EXTENSION_UNLOADED:
[email protected]a888b29e62010-04-01 13:38:572857 break;
[email protected]a888b29e62010-04-01 13:38:572858
[email protected]88152052010-10-01 04:05:182859 case NotificationType::GOOGLE_URL_UPDATED:
2860 UpdateAlternateErrorPageURL();
2861 break;
2862
[email protected]420ae012009-04-24 05:16:322863 default:
2864 NOTREACHED();
2865 }
2866}
[email protected]aacd7cc2009-09-02 14:51:102867
[email protected]9adb9692010-10-29 23:14:022868void TabContents::UpdateExtensionAppIcon(const Extension* extension) {
[email protected]98aa0b52010-05-06 17:03:082869 extension_app_icon_.reset();
[email protected]f075fe0a22010-04-26 04:06:432870
[email protected]a888b29e62010-04-01 13:38:572871 if (extension) {
[email protected]98aa0b52010-05-06 17:03:082872 extension_app_image_loader_.reset(new ImageLoadingTracker(this));
2873 extension_app_image_loader_->LoadImage(
[email protected]a888b29e62010-04-01 13:38:572874 extension,
[email protected]807871f2010-09-16 01:04:482875 extension->GetIconResource(Extension::EXTENSION_ICON_SMALLISH,
2876 ExtensionIconSet::MATCH_EXACTLY),
[email protected]a888b29e62010-04-01 13:38:572877 gfx::Size(Extension::EXTENSION_ICON_SMALLISH,
2878 Extension::EXTENSION_ICON_SMALLISH),
2879 ImageLoadingTracker::CACHE);
2880 } else {
[email protected]98aa0b52010-05-06 17:03:082881 extension_app_image_loader_.reset(NULL);
[email protected]a888b29e62010-04-01 13:38:572882 }
2883}
2884
[email protected]9adb9692010-10-29 23:14:022885const Extension* TabContents::GetExtensionContaining(const GURL& url) {
[email protected]eaa7dd182010-12-14 11:09:002886 ExtensionService* extensions_service = profile()->GetExtensionService();
[email protected]a888b29e62010-04-01 13:38:572887 if (!extensions_service)
2888 return NULL;
2889
[email protected]9adb9692010-10-29 23:14:022890 const Extension* extension = extensions_service->GetExtensionByURL(url);
[email protected]a888b29e62010-04-01 13:38:572891 return extension ?
2892 extension : extensions_service->GetExtensionByWebExtent(url);
2893}
2894
[email protected]a888b29e62010-04-01 13:38:572895void TabContents::OnImageLoaded(SkBitmap* image, ExtensionResource resource,
2896 int index) {
2897 if (image) {
[email protected]98aa0b52010-05-06 17:03:082898 extension_app_icon_ = *image;
[email protected]a888b29e62010-04-01 13:38:572899 NotifyNavigationStateChanged(INVALIDATE_TAB);
2900 }
2901}
2902
[email protected]beb440c2009-11-06 04:08:542903gfx::NativeWindow TabContents::GetMessageBoxRootWindow() {
2904 return view_->GetTopLevelNativeWindow();
2905}
2906
2907void TabContents::OnMessageBoxClosed(IPC::Message* reply_msg,
2908 bool success,
2909 const std::wstring& prompt) {
2910 last_javascript_message_dismissal_ = base::TimeTicks::Now();
2911 if (is_showing_before_unload_dialog_ && !success) {
2912 // If a beforeunload dialog is canceled, we need to stop the throbber from
2913 // spinning, since we forced it to start spinning in Navigate.
2914 DidStopLoading();
2915
2916 tab_close_start_time_ = base::TimeTicks();
2917 }
2918 is_showing_before_unload_dialog_ = false;
2919 render_view_host()->JavaScriptMessageBoxClosed(reply_msg, success, prompt);
2920}
2921
2922void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) {
2923 set_suppress_javascript_messages(suppress_message_boxes);
2924}
2925
[email protected]3a3d47472010-07-15 21:03:542926TabContents* TabContents::AsTabContents() {
2927 return this;
2928}
2929
2930ExtensionHost* TabContents::AsExtensionHost() {
2931 return NULL;
2932}
2933
[email protected]41fc0322009-09-04 22:23:402934void TabContents::set_encoding(const std::string& encoding) {
[email protected]aacd7cc2009-09-02 14:51:102935 encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding);
2936}
[email protected]f45d2a72010-03-08 23:28:352937
2938void TabContents::SetAppIcon(const SkBitmap& app_icon) {
2939 app_icon_ = app_icon;
2940 NotifyNavigationStateChanged(INVALIDATE_TITLE);
2941}
[email protected]33f74972010-12-08 16:40:362942
2943void TabContents::SwapInRenderViewHost(RenderViewHost* rvh) {
2944 render_manager_.SwapInRenderViewHost(rvh);
2945}
2946
2947void TabContents::CreateViewAndSetSizeForRVH(RenderViewHost* rvh) {
2948 RenderWidgetHostView* rwh_view = view()->CreateViewForWidget(rvh);
2949 rwh_view->SetSize(view()->GetContainerSize());
2950}
[email protected]e7d50892011-01-19 21:47:382951
2952bool TabContents::MaybeUsePreloadedPage(const GURL& url) {
[email protected]4c154ff82011-02-15 11:23:592953 prerender::PrerenderManager* pm = profile()->GetPrerenderManager();
[email protected]e7d50892011-01-19 21:47:382954 if (pm != NULL) {
[email protected]973407b2011-01-26 23:18:232955 if (pm->MaybeUsePreloadedPage(this, url))
[email protected]e7d50892011-01-19 21:47:382956 return true;
[email protected]e7d50892011-01-19 21:47:382957 }
2958 return false;
2959}