Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(24)

Side by Side Diff: chrome/browser/ui/prefs/prefs_tab_helper.cc

Issue 8775064: Make PerTabPrefsTabHelper into PrefsTabHelper, move all prefs code into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 5 #include "chrome/browser/ui/prefs/prefs_tab_helper.h"
6 6
7 #include "base/utf_string_conversions.h"
8
9 #include "base/command_line.h"
10 #include "base/lazy_instance.h"
11 #include "base/stringprintf.h" 7 #include "base/stringprintf.h"
12 #include "chrome/browser/autocomplete_history_manager.h" 8 #include "base/string_util.h"
13 #include "chrome/browser/autofill/autofill_external_delegate.h"
14 #include "chrome/browser/autofill/autofill_manager.h"
15 #include "chrome/browser/automation/automation_tab_helper.h"
16 #include "chrome/browser/browser_process.h" 9 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/content_settings/tab_specific_content_settings.h"
18 #include "chrome/browser/download/download_request_limiter_observer.h"
19 #include "chrome/browser/extensions/extension_tab_helper.h"
20 #include "chrome/browser/extensions/extension_webnavigation_api.h"
21 #include "chrome/browser/external_protocol/external_protocol_observer.h"
22 #include "chrome/browser/favicon/favicon_tab_helper.h"
23 #include "chrome/browser/google/google_util.h"
24 #include "chrome/browser/history/history_tab_helper.h"
25 #include "chrome/browser/infobars/infobar_tab_helper.h"
26 #include "chrome/browser/omnibox_search_hint.h"
27 #include "chrome/browser/password_manager/password_manager.h"
28 #include "chrome/browser/password_manager_delegate_impl.h"
29 #include "chrome/browser/pdf_unsupported_feature.h"
30 #include "chrome/browser/plugin_observer.h"
31 #include "chrome/browser/prefs/pref_service.h" 10 #include "chrome/browser/prefs/pref_service.h"
32 #include "chrome/browser/prerender/prerender_tab_helper.h" 11 #include "chrome/browser/profiles/profile.h"
33 #include "chrome/browser/printing/print_preview_message_handler.h"
34 #include "chrome/browser/printing/print_view_manager.h"
35 #include "chrome/browser/renderer_host/web_cache_manager.h"
36 #include "chrome/browser/renderer_preferences_util.h" 12 #include "chrome/browser/renderer_preferences_util.h"
37 #include "chrome/browser/sessions/restore_tab_helper.h"
38 #include "chrome/browser/safe_browsing/client_side_detection_host.h"
39 #include "chrome/browser/tab_contents/tab_contents_ssl_helper.h"
40 #include "chrome/browser/tab_contents/thumbnail_generator.h"
41 #include "chrome/browser/themes/theme_service.h" 13 #include "chrome/browser/themes/theme_service.h"
42 #include "chrome/browser/themes/theme_service_factory.h" 14 #include "chrome/browser/themes/theme_service_factory.h"
43 #include "chrome/browser/translate/translate_tab_helper.h"
44 #include "chrome/browser/ui/blocked_content/blocked_content_tab_helper.h"
45 #include "chrome/browser/ui/bookmarks/bookmark_tab_helper.h"
46 #include "chrome/browser/ui/constrained_window_tab_helper.h" 15 #include "chrome/browser/ui/constrained_window_tab_helper.h"
47 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
48 #include "chrome/browser/ui/intents/web_intent_picker_factory_impl.h"
49 #include "chrome/browser/ui/intents/web_intent_picker_controller.h"
50 #include "chrome/browser/ui/sad_tab_observer.h"
51 #include "chrome/browser/ui/search_engines/search_engine_tab_helper.h"
52 #include "chrome/browser/ui/sync/tab_contents_wrapper_synced_tab_delegate.h"
53 #include "chrome/browser/ui/tab_contents/per_tab_prefs_tab_helper.h"
54 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper_delegate.h"
55 #include "chrome/common/chrome_notification_types.h" 17 #include "chrome/common/chrome_notification_types.h"
56 #include "chrome/common/chrome_switches.h"
57 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
58 #include "chrome/common/render_messages.h"
59 #include "content/browser/renderer_host/render_view_host.h" 19 #include "content/browser/renderer_host/render_view_host.h"
60 #include "content/browser/tab_contents/tab_contents_view.h" 20 #include "content/public/browser/notification_details.h"
61 #include "content/public/browser/notification_service.h" 21 #include "content/public/browser/notification_service.h"
62 #include "grit/generated_resources.h"
63 #include "grit/locale_settings.h" 22 #include "grit/locale_settings.h"
64 #include "grit/platform_locale_settings.h" 23 #include "grit/platform_locale_settings.h"
65 #include "ui/base/l10n/l10n_util.h"
66 #include "webkit/glue/webpreferences.h" 24 #include "webkit/glue/webpreferences.h"
67 25
68 namespace { 26 namespace {
69 27
70 static base::LazyInstance<base::PropertyAccessor<TabContentsWrapper*> > 28 const char* kPerTabPrefsToObserve[] = {
71 g_tab_contents_wrapper_property_accessor = LAZY_INSTANCE_INITIALIZER; 29 prefs::kWebKitJavascriptEnabled
30 };
31
32 const int kPerTabPrefsToObserveLength = arraysize(kPerTabPrefsToObserve);
33
34 void RegisterPerTabUserPrefs(PrefService* prefs) {
35 WebPreferences pref_defaults;
36
37 prefs->RegisterBooleanPref(prefs::kWebKitJavascriptEnabled,
38 pref_defaults.javascript_enabled,
39 PrefService::UNSYNCABLE_PREF);
40 }
72 41
73 // The list of prefs we want to observe. 42 // The list of prefs we want to observe.
74 const char* kPrefsToObserve[] = { 43 const char* kPrefsToObserve[] = {
75 prefs::kAlternateErrorPagesEnabled,
76 prefs::kDefaultCharset, 44 prefs::kDefaultCharset,
77 prefs::kDefaultZoomLevel,
78 prefs::kEnableReferrers, 45 prefs::kEnableReferrers,
79 #if defined (ENABLE_SAFE_BROWSING)
80 prefs::kSafeBrowsingEnabled,
81 #endif
82 prefs::kWebKitAllowDisplayingInsecureContent, 46 prefs::kWebKitAllowDisplayingInsecureContent,
83 prefs::kWebKitAllowRunningInsecureContent, 47 prefs::kWebKitAllowRunningInsecureContent,
84 prefs::kWebKitCursiveFontFamily, 48 prefs::kWebKitCursiveFontFamily,
85 prefs::kWebKitDefaultFixedFontSize, 49 prefs::kWebKitDefaultFixedFontSize,
86 prefs::kWebKitDefaultFontSize, 50 prefs::kWebKitDefaultFontSize,
87 prefs::kWebKitFantasyFontFamily, 51 prefs::kWebKitFantasyFontFamily,
88 prefs::kWebKitFixedFontFamily, 52 prefs::kWebKitFixedFontFamily,
89 prefs::kWebKitGlobalJavascriptEnabled, 53 prefs::kWebKitGlobalJavascriptEnabled,
90 prefs::kWebKitJavaEnabled, 54 prefs::kWebKitJavaEnabled,
91 prefs::kWebKitLoadsImagesAutomatically, 55 prefs::kWebKitLoadsImagesAutomatically,
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) || defined(OS_WIN) 202 #if defined(OS_CHROMEOS) || defined(OS_MACOSX) || defined(OS_WIN)
239 // To avoid Clang warning, only define kPerScriptFontDefaultsLength when it is 203 // To avoid Clang warning, only define kPerScriptFontDefaultsLength when it is
240 // non-zero. When it is zero, code like 204 // non-zero. When it is zero, code like
241 // for (size_t i = 0; i < kPerScriptFontDefaultsLength; ++i) 205 // for (size_t i = 0; i < kPerScriptFontDefaultsLength; ++i)
242 // causes a warning due to comparison of unsigned expression < 0. 206 // causes a warning due to comparison of unsigned expression < 0.
243 const size_t kPerScriptFontDefaultsLength = arraysize(kPerScriptFontDefaults); 207 const size_t kPerScriptFontDefaultsLength = arraysize(kPerScriptFontDefaults);
244 #endif 208 #endif
245 209
246 } // namespace 210 } // namespace
247 211
248 //////////////////////////////////////////////////////////////////////////////// 212 PrefsTabHelper::PrefsTabHelper(TabContentsWrapper* wrapper)
249 // TabContentsWrapper, public: 213 : TabContentsObserver(wrapper->tab_contents()),
250 214 wrapper_(wrapper) {
251 TabContentsWrapper::TabContentsWrapper(TabContents* contents) 215 PrefService* prefs = wrapper->profile()->GetPrefs();
252 : TabContentsObserver(contents),
253 delegate_(NULL),
254 in_destructor_(false),
255 tab_contents_(contents) {
256 DCHECK(contents);
257 DCHECK(!GetCurrentWrapperForContents(contents));
258 // Stash this in the property bag so it can be retrieved without having to
259 // go to a Browser.
260 property_accessor()->SetProperty(contents->property_bag(), this);
261
262 // Create the tab helpers.
263 autocomplete_history_manager_.reset(new AutocompleteHistoryManager(contents));
264 autofill_manager_ = new AutofillManager(this);
265 if (CommandLine::ForCurrentProcess()->HasSwitch(
266 switches::kExternalAutofillPopup)) {
267 autofill_external_delegate_.reset(
268 AutofillExternalDelegate::Create(this, autofill_manager_.get()));
269 autofill_manager_->SetExternalDelegate(autofill_external_delegate_.get());
270 autocomplete_history_manager_->SetExternalDelegate(
271 autofill_external_delegate_.get());
272 }
273 automation_tab_helper_.reset(new AutomationTabHelper(contents));
274 blocked_content_tab_helper_.reset(new BlockedContentTabHelper(this));
275 bookmark_tab_helper_.reset(new BookmarkTabHelper(this));
276 constrained_window_tab_helper_.reset(new ConstrainedWindowTabHelper(this));
277 extension_tab_helper_.reset(new ExtensionTabHelper(this));
278 favicon_tab_helper_.reset(new FaviconTabHelper(contents));
279 find_tab_helper_.reset(new FindTabHelper(contents));
280 history_tab_helper_.reset(new HistoryTabHelper(contents));
281 infobar_tab_helper_.reset(new InfoBarTabHelper(contents));
282 password_manager_delegate_.reset(new PasswordManagerDelegateImpl(this));
283 password_manager_.reset(
284 new PasswordManager(contents, password_manager_delegate_.get()));
285 per_tab_prefs_tab_helper_.reset(new PerTabPrefsTabHelper(this));
286 prerender_tab_helper_.reset(new prerender::PrerenderTabHelper(this));
287 print_view_manager_.reset(new printing::PrintViewManager(this));
288 restore_tab_helper_.reset(new RestoreTabHelper(this));
289 #if defined(ENABLE_SAFE_BROWSING)
290 if (profile()->GetPrefs()->GetBoolean(prefs::kSafeBrowsingEnabled) &&
291 g_browser_process->safe_browsing_detection_service()) {
292 safebrowsing_detection_host_.reset(
293 safe_browsing::ClientSideDetectionHost::Create(contents));
294 }
295 #endif
296 search_engine_tab_helper_.reset(new SearchEngineTabHelper(contents));
297 ssl_helper_.reset(new TabContentsSSLHelper(this));
298 synced_tab_delegate_.reset(new TabContentsWrapperSyncedTabDelegate(this));
299 content_settings_.reset(new TabSpecificContentSettings(contents));
300 translate_tab_helper_.reset(new TranslateTabHelper(contents));
301 web_intent_picker_controller_.reset(new WebIntentPickerController(
302 this, new WebIntentPickerFactoryImpl()));
303
304 // Create the per-tab observers.
305 download_request_limiter_observer_.reset(
306 new DownloadRequestLimiterObserver(contents));
307 webnavigation_observer_.reset(
308 new ExtensionWebNavigationTabObserver(contents));
309 external_protocol_observer_.reset(new ExternalProtocolObserver(contents));
310 plugin_observer_.reset(new PluginObserver(this));
311 print_preview_.reset(new printing::PrintPreviewMessageHandler(contents));
312 sad_tab_observer_.reset(new SadTabObserver(contents));
313 // Start the in-browser thumbnailing if the feature is enabled.
314 if (switches::IsInBrowserThumbnailingEnabled()) {
315 thumbnail_generation_observer_.reset(new ThumbnailGenerator);
316 thumbnail_generation_observer_->StartThumbnailing(tab_contents_.get());
317 }
318
319 // Set-up the showing of the omnibox search infobar if applicable.
320 if (OmniboxSearchHint::IsEnabled(profile()))
321 omnibox_search_hint_.reset(new OmniboxSearchHint(this));
322
323 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
324 content::NotificationService::AllSources());
325 registrar_.Add(this, chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED,
326 content::NotificationService::AllSources());
327 #if defined(OS_POSIX) && !defined(OS_MACOSX)
328 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
329 content::Source<ThemeService>(
330 ThemeServiceFactory::GetForProfile(profile())));
331 #endif
332
333 // Register for notifications about all interested prefs change.
334 PrefService* prefs = profile()->GetPrefs();
335 pref_change_registrar_.Init(prefs); 216 pref_change_registrar_.Init(prefs);
336 if (prefs) { 217 if (prefs) {
337 for (int i = 0; i < kPrefsToObserveLength; ++i) 218 for (int i = 0; i < kPrefsToObserveLength; ++i)
338 pref_change_registrar_.Add(kPrefsToObserve[i], this); 219 pref_change_registrar_.Add(kPrefsToObserve[i], this);
339 220
340 RegisterFontFamilyMapObserver(&pref_change_registrar_, 221 RegisterFontFamilyMapObserver(&pref_change_registrar_,
341 prefs::kWebKitStandardFontFamilyMap, this); 222 prefs::kWebKitStandardFontFamilyMap, this);
342 RegisterFontFamilyMapObserver(&pref_change_registrar_, 223 RegisterFontFamilyMapObserver(&pref_change_registrar_,
343 prefs::kWebKitFixedFontFamilyMap, this); 224 prefs::kWebKitFixedFontFamilyMap, this);
344 RegisterFontFamilyMapObserver(&pref_change_registrar_, 225 RegisterFontFamilyMapObserver(&pref_change_registrar_,
345 prefs::kWebKitSerifFontFamilyMap, this); 226 prefs::kWebKitSerifFontFamilyMap, this);
346 RegisterFontFamilyMapObserver(&pref_change_registrar_, 227 RegisterFontFamilyMapObserver(&pref_change_registrar_,
347 prefs::kWebKitSansSerifFontFamilyMap, this); 228 prefs::kWebKitSansSerifFontFamilyMap, this);
348 RegisterFontFamilyMapObserver(&pref_change_registrar_, 229 RegisterFontFamilyMapObserver(&pref_change_registrar_,
349 prefs::kWebKitCursiveFontFamilyMap, this); 230 prefs::kWebKitCursiveFontFamilyMap, this);
350 RegisterFontFamilyMapObserver(&pref_change_registrar_, 231 RegisterFontFamilyMapObserver(&pref_change_registrar_,
351 prefs::kWebKitFantasyFontFamilyMap, this); 232 prefs::kWebKitFantasyFontFamilyMap, this);
352 } 233 }
353 234
235 per_tab_prefs_.reset(
236 wrapper_->profile()->GetPrefs()->CreatePrefServiceWithPerTabPrefStore());
237 RegisterPerTabUserPrefs(per_tab_prefs_.get());
238 per_tab_pref_change_registrar_.Init(per_tab_prefs_.get());
239 for (int i = 0; i < kPerTabPrefsToObserveLength; ++i) {
240 per_tab_pref_change_registrar_.Add(kPerTabPrefsToObserve[i], this);
241 }
242
354 renderer_preferences_util::UpdateFromSystemSettings( 243 renderer_preferences_util::UpdateFromSystemSettings(
355 tab_contents()->GetMutableRendererPrefs(), profile()); 244 tab_contents()->GetMutableRendererPrefs(), wrapper->profile());
mnaganov (inactive) 2011/12/02 20:01:32 nit: Should use wrapper_
245
246 registrar_.Add(this, chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED,
247 content::NotificationService::AllSources());
248 #if defined(OS_POSIX) && !defined(OS_MACOSX)
249 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
250 content::Source<ThemeService>(
251 ThemeServiceFactory::GetForProfile(wrapper->profile())));
252 #endif
356 } 253 }
357 254
358 TabContentsWrapper::~TabContentsWrapper() { 255 PrefsTabHelper::~PrefsTabHelper() {
359 in_destructor_ = true;
360
361 // Need to tear down infobars before the TabContents goes away.
362 infobar_tab_helper_.reset();
363 }
364
365 base::PropertyAccessor<TabContentsWrapper*>*
366 TabContentsWrapper::property_accessor() {
367 return g_tab_contents_wrapper_property_accessor.Pointer();
368 } 256 }
369 257
370 // static 258 // static
371 void TabContentsWrapper::RegisterUserPrefs(PrefService* prefs) { 259 void PrefsTabHelper::RegisterUserPrefs(PrefService* prefs) {
372 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
373 true,
374 PrefService::SYNCABLE_PREF);
375
376 WebPreferences pref_defaults; 260 WebPreferences pref_defaults;
377 prefs->RegisterBooleanPref(prefs::kWebKitGlobalJavascriptEnabled, 261 prefs->RegisterBooleanPref(prefs::kWebKitGlobalJavascriptEnabled,
378 pref_defaults.javascript_enabled, 262 pref_defaults.javascript_enabled,
379 PrefService::UNSYNCABLE_PREF); 263 PrefService::UNSYNCABLE_PREF);
380 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled, 264 prefs->RegisterBooleanPref(prefs::kWebKitWebSecurityEnabled,
381 pref_defaults.web_security_enabled, 265 pref_defaults.web_security_enabled,
382 PrefService::UNSYNCABLE_PREF); 266 PrefService::UNSYNCABLE_PREF);
383 prefs->RegisterBooleanPref( 267 prefs->RegisterBooleanPref(
384 prefs::kWebKitJavascriptCanOpenWindowsAutomatically, 268 prefs::kWebKitJavascriptCanOpenWindowsAutomatically,
385 true, 269 true,
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 IDS_USES_UNIVERSAL_DETECTOR, 373 IDS_USES_UNIVERSAL_DETECTOR,
490 PrefService::SYNCABLE_PREF); 374 PrefService::SYNCABLE_PREF);
491 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings, 375 prefs->RegisterLocalizedStringPref(prefs::kStaticEncodings,
492 IDS_STATIC_ENCODING_LIST, 376 IDS_STATIC_ENCODING_LIST,
493 PrefService::UNSYNCABLE_PREF); 377 PrefService::UNSYNCABLE_PREF);
494 prefs->RegisterStringPref(prefs::kRecentlySelectedEncoding, 378 prefs->RegisterStringPref(prefs::kRecentlySelectedEncoding,
495 "", 379 "",
496 PrefService::UNSYNCABLE_PREF); 380 PrefService::UNSYNCABLE_PREF);
497 } 381 }
498 382
499 string16 TabContentsWrapper::GetDefaultTitle() { 383 void PrefsTabHelper::OverrideWebPreferences(WebPreferences* prefs) {
500 return l10n_util::GetStringUTF16(IDS_DEFAULT_TAB_TITLE); 384 prefs->javascript_enabled =
385 per_tab_prefs_->GetBoolean(prefs::kWebKitJavascriptEnabled);
501 } 386 }
502 387
503 string16 TabContentsWrapper::GetStatusText() const { 388 void PrefsTabHelper::RenderViewCreated(RenderViewHost* render_view_host) {
504 if (!tab_contents()->IsLoading() || 389 UpdateWebPreferences();
505 tab_contents()->load_state().state == net::LOAD_STATE_IDLE) {
506 return string16();
507 }
508
509 switch (tab_contents()->load_state().state) {
510 case net::LOAD_STATE_WAITING_FOR_DELEGATE:
511 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_DELEGATE,
512 tab_contents()->load_state().param);
513 case net::LOAD_STATE_WAITING_FOR_CACHE:
514 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_CACHE);
515 case net::LOAD_STATE_WAITING_FOR_APPCACHE:
516 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_WAITING_FOR_APPCACHE);
517 case net::LOAD_STATE_ESTABLISHING_PROXY_TUNNEL:
518 return
519 l10n_util::GetStringUTF16(IDS_LOAD_STATE_ESTABLISHING_PROXY_TUNNEL);
520 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
521 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
522 case net::LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT:
523 return l10n_util::GetStringUTF16(
524 IDS_LOAD_STATE_RESOLVING_HOST_IN_PROXY_SCRIPT);
525 case net::LOAD_STATE_RESOLVING_HOST:
526 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_RESOLVING_HOST);
527 case net::LOAD_STATE_CONNECTING:
528 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_CONNECTING);
529 case net::LOAD_STATE_SSL_HANDSHAKE:
530 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SSL_HANDSHAKE);
531 case net::LOAD_STATE_SENDING_REQUEST:
532 if (tab_contents()->upload_size())
533 return l10n_util::GetStringFUTF16Int(
534 IDS_LOAD_STATE_SENDING_REQUEST_WITH_PROGRESS,
535 static_cast<int>((100 * tab_contents()->upload_position()) /
536 tab_contents()->upload_size()));
537 else
538 return l10n_util::GetStringUTF16(IDS_LOAD_STATE_SENDING_REQUEST);
539 case net::LOAD_STATE_WAITING_FOR_RESPONSE:
540 return l10n_util::GetStringFUTF16(IDS_LOAD_STATE_WAITING_FOR_RESPONSE,
541 tab_contents()->load_state_host());
542 // Ignore net::LOAD_STATE_READING_RESPONSE and net::LOAD_STATE_IDLE
543 case net::LOAD_STATE_IDLE:
544 case net::LOAD_STATE_READING_RESPONSE:
545 break;
546 }
547
548 return string16();
549 } 390 }
550 391
551 TabContentsWrapper* TabContentsWrapper::Clone() { 392 void PrefsTabHelper::TabContentsDestroyed(TabContents* tab) {
552 TabContents* new_contents = tab_contents()->Clone(); 393 per_tab_pref_change_registrar_.RemoveAll();
553 TabContentsWrapper* new_wrapper = new TabContentsWrapper(new_contents);
554
555 new_wrapper->extension_tab_helper()->CopyStateFrom(
556 *extension_tab_helper_.get());
557 return new_wrapper;
558 } 394 }
559 395
560 void TabContentsWrapper::CaptureSnapshot() { 396 void PrefsTabHelper::Observe(int type,
561 Send(new ChromeViewMsg_CaptureSnapshot(routing_id())); 397 const content::NotificationSource& source,
562 } 398 const content::NotificationDetails& details) {
563
564 // static
565 TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
566 TabContents* contents) {
567 TabContentsWrapper** wrapper =
568 property_accessor()->GetProperty(contents->property_bag());
569
570 return wrapper ? *wrapper : NULL;
571 }
572
573 // static
574 const TabContentsWrapper* TabContentsWrapper::GetCurrentWrapperForContents(
575 const TabContents* contents) {
576 TabContentsWrapper* const* wrapper =
577 property_accessor()->GetProperty(contents->property_bag());
578
579 return wrapper ? *wrapper : NULL;
580 }
581
582 Profile* TabContentsWrapper::profile() const {
583 return Profile::FromBrowserContext(tab_contents()->browser_context());
584 }
585
586 ////////////////////////////////////////////////////////////////////////////////
587 // TabContentsWrapper implementation:
588
589 void TabContentsWrapper::RenderViewCreated(RenderViewHost* render_view_host) {
590 UpdateAlternateErrorPageURL(render_view_host);
591 }
592
593 void TabContentsWrapper::DidBecomeSelected() {
594 WebCacheManager::GetInstance()->ObserveActivity(
595 tab_contents()->GetRenderProcessHost()->GetID());
596 }
597
598 bool TabContentsWrapper::OnMessageReceived(const IPC::Message& message) {
599 bool handled = true;
600 IPC_BEGIN_MESSAGE_MAP(TabContentsWrapper, message)
601 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_Snapshot, OnSnapshot)
602 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_PDFHasUnsupportedFeature,
603 OnPDFHasUnsupportedFeature)
604 IPC_MESSAGE_UNHANDLED(handled = false)
605 IPC_END_MESSAGE_MAP()
606 return handled;
607 }
608
609 void TabContentsWrapper::TabContentsDestroyed(TabContents* tab) {
610 // Destruction of the TabContents should only be done by us from our
611 // destructor. Otherwise it's very likely we (or one of the helpers we own)
612 // will attempt to access the TabContents and we'll crash.
613 DCHECK(in_destructor_);
614 }
615
616 void TabContentsWrapper::Observe(int type,
617 const content::NotificationSource& source,
618 const content::NotificationDetails& details) {
619 switch (type) { 399 switch (type) {
620 case chrome::NOTIFICATION_GOOGLE_URL_UPDATED:
621 UpdateAlternateErrorPageURL(render_view_host());
622 break;
623 case chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED: 400 case chrome::NOTIFICATION_USER_STYLE_SHEET_UPDATED:
624 UpdateWebPreferences(); 401 UpdateWebPreferences();
625 break; 402 break;
626 #if defined(OS_POSIX) && !defined(OS_MACOSX) 403 #if defined(OS_POSIX) && !defined(OS_MACOSX)
627 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { 404 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: {
628 UpdateRendererPreferences(); 405 UpdateRendererPreferences();
629 break; 406 break;
630 } 407 }
631 #endif 408 #endif
632 case chrome::NOTIFICATION_PREF_CHANGED: { 409 case chrome::NOTIFICATION_PREF_CHANGED: {
633 std::string* pref_name_in = content::Details<std::string>(details).ptr(); 410 std::string* pref_name_in = content::Details<std::string>(details).ptr();
634 DCHECK(content::Source<PrefService>(source).ptr() == 411 DCHECK(content::Source<PrefService>(source).ptr() ==
635 profile()->GetPrefs() || 412 wrapper_->profile()->GetPrefs() ||
636 content::Source<PrefService>(source).ptr() == 413 content::Source<PrefService>(source).ptr() == per_tab_prefs_);
637 per_tab_prefs_tab_helper_->prefs()); 414 if ((*pref_name_in == prefs::kDefaultCharset) ||
638 if (*pref_name_in == prefs::kAlternateErrorPagesEnabled) { 415 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
639 UpdateAlternateErrorPageURL(render_view_host());
640 } else if ((*pref_name_in == prefs::kDefaultCharset) ||
641 StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) {
642 UpdateWebPreferences(); 416 UpdateWebPreferences();
643 } else if (*pref_name_in == prefs::kDefaultZoomLevel) {
644 tab_contents()->render_view_host()->SetZoomLevel(
645 tab_contents()->GetZoomLevel());
646 } else if (*pref_name_in == prefs::kEnableReferrers) { 417 } else if (*pref_name_in == prefs::kEnableReferrers) {
647 UpdateRendererPreferences(); 418 UpdateRendererPreferences();
648 } else if (*pref_name_in == prefs::kSafeBrowsingEnabled) {
649 UpdateSafebrowsingDetectionHost();
650 } else { 419 } else {
651 NOTREACHED() << "unexpected pref change notification" << *pref_name_in; 420 NOTREACHED() << "unexpected pref change notification" << *pref_name_in;
652 } 421 }
653 break; 422 break;
654 } 423 }
655 default: 424 default:
656 NOTREACHED(); 425 NOTREACHED();
657 } 426 }
658 } 427 }
659 428
660 //////////////////////////////////////////////////////////////////////////////// 429 void PrefsTabHelper::UpdateWebPreferences() {
661 // Internal helpers
662
663 void TabContentsWrapper::OnSnapshot(const SkBitmap& bitmap) {
664 content::NotificationService::current()->Notify(
665 chrome::NOTIFICATION_TAB_SNAPSHOT_TAKEN,
666 content::Source<TabContentsWrapper>(this),
667 content::Details<const SkBitmap>(&bitmap));
668 }
669
670 void TabContentsWrapper::OnPDFHasUnsupportedFeature() {
671 PDFHasUnsupportedFeature(this);
672 }
673
674 GURL TabContentsWrapper::GetAlternateErrorPageURL() const {
675 GURL url;
676 // Disable alternate error pages when in Incognito mode.
677 if (profile()->IsOffTheRecord())
678 return url;
679
680 PrefService* prefs = profile()->GetPrefs();
681 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
682 url = google_util::AppendGoogleLocaleParam(
683 GURL(google_util::kLinkDoctorBaseURL));
684 url = google_util::AppendGoogleTLDParam(url);
685 }
686 return url;
687 }
688
689 void TabContentsWrapper::UpdateAlternateErrorPageURL(RenderViewHost* rvh) {
690 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
691 }
692
693 void TabContentsWrapper::UpdateWebPreferences() {
694 RenderViewHostDelegate* rvhd = tab_contents(); 430 RenderViewHostDelegate* rvhd = tab_contents();
695 WebPreferences prefs = rvhd->GetWebkitPrefs(); 431 WebPreferences prefs = rvhd->GetWebkitPrefs();
696 per_tab_prefs_tab_helper_->OverrideWebPreferences(&prefs); 432 OverrideWebPreferences(&prefs);
697 tab_contents()->render_view_host()->UpdateWebkitPreferences(prefs); 433 tab_contents()->render_view_host()->UpdateWebkitPreferences(prefs);
698 } 434 }
699 435
700 void TabContentsWrapper::UpdateRendererPreferences() { 436 void PrefsTabHelper::UpdateRendererPreferences() {
701 renderer_preferences_util::UpdateFromSystemSettings( 437 renderer_preferences_util::UpdateFromSystemSettings(
702 tab_contents()->GetMutableRendererPrefs(), profile()); 438 tab_contents()->GetMutableRendererPrefs(), wrapper_->profile());
703 render_view_host()->SyncRendererPrefs(); 439 tab_contents()->render_view_host()->SyncRendererPrefs();
704 } 440 }
705
706 void TabContentsWrapper::UpdateSafebrowsingDetectionHost() {
707 #if defined(ENABLE_SAFE_BROWSING)
708 PrefService* prefs = profile()->GetPrefs();
709 bool safe_browsing = prefs->GetBoolean(prefs::kSafeBrowsingEnabled);
710 if (safe_browsing &&
711 g_browser_process->safe_browsing_detection_service()) {
712 if (!safebrowsing_detection_host_.get()) {
713 safebrowsing_detection_host_.reset(
714 safe_browsing::ClientSideDetectionHost::Create(tab_contents()));
715 }
716 } else {
717 safebrowsing_detection_host_.reset();
718 }
719 render_view_host()->Send(
720 new ChromeViewMsg_SetClientSidePhishingDetection(routing_id(),
721 safe_browsing));
722 #endif
723 }
724
725 void TabContentsWrapper::ExitFullscreenMode() {
726 if (tab_contents() && render_view_host())
727 tab_contents()->render_view_host()->ExitFullscreen();
728 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698