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

Side by Side Diff: chrome/browser/ui/alternate_error_tab_observer.cc

Issue 8865004: Create CoreTabHelper, move remaining core TCW functionality into it. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: lots of helpers now 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/alternate_error_tab_observer.h"
6
7 #include "chrome/browser/google/google_util.h"
8 #include "chrome/browser/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/common/chrome_notification_types.h"
12 #include "chrome/common/pref_names.h"
13 #include "content/browser/renderer_host/render_view_host.h"
14 #include "content/public/browser/notification_service.h"
15
16 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver(
17 TabContentsWrapper* wrapper)
18 : TabContentsObserver(wrapper->tab_contents()),
19 wrapper_(wrapper) {
20 PrefService* prefs = wrapper_->profile()->GetPrefs();
21 if (prefs) {
22 pref_change_registrar_.Init(prefs);
23 pref_change_registrar_.Add(prefs::kAlternateErrorPagesEnabled, this);
24 }
25
26 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
27 content::NotificationService::AllSources());
28 }
29
30 AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() {
31 }
32
33 // static
34 void AlternateErrorPageTabObserver::RegisterUserPrefs(PrefService* prefs) {
35 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
36 true,
37 PrefService::SYNCABLE_PREF);
38 }
39
40 ////////////////////////////////////////////////////////////////////////////////
41 // TabContentsObserver overrides
42
43 void AlternateErrorPageTabObserver::RenderViewCreated(
44 RenderViewHost* render_view_host) {
45 UpdateAlternateErrorPageURL(render_view_host);
46 }
47
48 ////////////////////////////////////////////////////////////////////////////////
49 // content::NotificationObserver overrides
50
51 void AlternateErrorPageTabObserver::Observe(int type,
52 const content::NotificationSource& source,
53 const content::NotificationDetails& details) {
54 switch (type) {
55 case chrome::NOTIFICATION_GOOGLE_URL_UPDATED:
56 UpdateAlternateErrorPageURL(tab_contents()->render_view_host());
57 break;
58 case chrome::NOTIFICATION_PREF_CHANGED: {
59 std::string* pref_name = content::Details<std::string>(details).ptr();
60 DCHECK(content::Source<PrefService>(source).ptr() ==
61 wrapper_->profile()->GetPrefs());
62 if (*pref_name == prefs::kAlternateErrorPagesEnabled) {
63 UpdateAlternateErrorPageURL(tab_contents()->render_view_host());
64 } else {
65 NOTREACHED() << "unexpected pref change notification" << *pref_name;
66 }
67 break;
68 }
69 default:
70 NOTREACHED();
71 }
72 }
73
74 ////////////////////////////////////////////////////////////////////////////////
75 // Internal helpers
76
77 GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const {
78 GURL url;
79 // Disable alternate error pages when in Incognito mode.
80 if (wrapper_->profile()->IsOffTheRecord())
81 return url;
82
83 PrefService* prefs = wrapper_->profile()->GetPrefs();
84 if (prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)) {
85 url = google_util::AppendGoogleLocaleParam(
86 GURL(google_util::kLinkDoctorBaseURL));
87 url = google_util::AppendGoogleTLDParam(url);
88 }
89 return url;
90 }
91
92 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL(
93 RenderViewHost* rvh) {
94 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
95 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698