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