| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/alternate_error_tab_observer.h" | 5 #include "chrome/browser/ui/alternate_error_tab_observer.h" |
| 6 | 6 |
| 7 #include "chrome/browser/google/google_util.h" | 7 #include "chrome/browser/google/google_util.h" |
| 8 #include "chrome/browser/prefs/pref_registry_syncable.h" |
| 8 #include "chrome/browser/prefs/pref_service.h" | 9 #include "chrome/browser/prefs/pref_service.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_notification_types.h" | 11 #include "chrome/common/chrome_notification_types.h" |
| 11 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 12 #include "content/public/browser/notification_service.h" | 13 #include "content/public/browser/notification_service.h" |
| 13 #include "content/public/browser/render_view_host.h" | 14 #include "content/public/browser/render_view_host.h" |
| 14 #include "content/public/browser/web_contents.h" | 15 #include "content/public/browser/web_contents.h" |
| 15 | 16 |
| 16 using content::RenderViewHost; | 17 using content::RenderViewHost; |
| 17 using content::WebContents; | 18 using content::WebContents; |
| 18 | 19 |
| 19 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AlternateErrorPageTabObserver); | 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AlternateErrorPageTabObserver); |
| 20 | 21 |
| 21 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( | 22 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( |
| 22 WebContents* web_contents) | 23 WebContents* web_contents) |
| 23 : content::WebContentsObserver(web_contents), | 24 : content::WebContentsObserver(web_contents), |
| 24 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { | 25 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
| 25 PrefServiceSyncable* prefs = profile_->GetPrefs(); | 26 PrefService* prefs = profile_->GetPrefs(); |
| 26 if (prefs) { | 27 if (prefs) { |
| 27 pref_change_registrar_.Init(prefs); | 28 pref_change_registrar_.Init(prefs); |
| 28 pref_change_registrar_.Add( | 29 pref_change_registrar_.Add( |
| 29 prefs::kAlternateErrorPagesEnabled, | 30 prefs::kAlternateErrorPagesEnabled, |
| 30 base::Bind(&AlternateErrorPageTabObserver:: | 31 base::Bind(&AlternateErrorPageTabObserver:: |
| 31 OnAlternateErrorPagesEnabledChanged, | 32 OnAlternateErrorPagesEnabledChanged, |
| 32 base::Unretained(this))); | 33 base::Unretained(this))); |
| 33 } | 34 } |
| 34 | 35 |
| 35 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 36 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 36 content::Source<Profile>(profile_->GetOriginalProfile())); | 37 content::Source<Profile>(profile_->GetOriginalProfile())); |
| 37 } | 38 } |
| 38 | 39 |
| 39 AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() { | 40 AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() { |
| 40 } | 41 } |
| 41 | 42 |
| 42 // static | 43 // static |
| 43 void AlternateErrorPageTabObserver::RegisterUserPrefs( | 44 void AlternateErrorPageTabObserver::RegisterUserPrefs( |
| 44 PrefServiceSyncable* prefs) { | 45 PrefRegistrySyncable* prefs) { |
| 45 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true, | 46 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true, |
| 46 PrefServiceSyncable::SYNCABLE_PREF); | 47 PrefRegistrySyncable::SYNCABLE_PREF); |
| 47 } | 48 } |
| 48 | 49 |
| 49 //////////////////////////////////////////////////////////////////////////////// | 50 //////////////////////////////////////////////////////////////////////////////// |
| 50 // WebContentsObserver overrides | 51 // WebContentsObserver overrides |
| 51 | 52 |
| 52 void AlternateErrorPageTabObserver::RenderViewCreated( | 53 void AlternateErrorPageTabObserver::RenderViewCreated( |
| 53 RenderViewHost* render_view_host) { | 54 RenderViewHost* render_view_host) { |
| 54 UpdateAlternateErrorPageURL(render_view_host); | 55 UpdateAlternateErrorPageURL(render_view_host); |
| 55 } | 56 } |
| 56 | 57 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 85 } | 86 } |
| 86 | 87 |
| 87 void AlternateErrorPageTabObserver::OnAlternateErrorPagesEnabledChanged() { | 88 void AlternateErrorPageTabObserver::OnAlternateErrorPagesEnabledChanged() { |
| 88 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); | 89 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
| 89 } | 90 } |
| 90 | 91 |
| 91 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( | 92 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( |
| 92 RenderViewHost* rvh) { | 93 RenderViewHost* rvh) { |
| 93 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL()); | 94 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL()); |
| 94 } | 95 } |
| OLD | NEW |