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

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

Issue 10907268: Switch AlternateErrorPageTabObserver to use WebContentsUserData. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months 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) 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 int AlternateErrorPageTabObserver::kUserDataKey;
20
19 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( 21 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver(
20 WebContents* web_contents, 22 WebContents* web_contents)
21 Profile* profile)
22 : content::WebContentsObserver(web_contents), 23 : content::WebContentsObserver(web_contents),
23 profile_(profile) { 24 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
24 PrefService* prefs = profile_->GetPrefs(); 25 PrefService* prefs = profile_->GetPrefs();
25 if (prefs) { 26 if (prefs) {
26 pref_change_registrar_.Init(prefs); 27 pref_change_registrar_.Init(prefs);
27 pref_change_registrar_.Add(prefs::kAlternateErrorPagesEnabled, this); 28 pref_change_registrar_.Add(prefs::kAlternateErrorPagesEnabled, this);
28 } 29 }
29 30
30 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 31 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
31 content::Source<Profile>(profile_->GetOriginalProfile())); 32 content::Source<Profile>(profile_->GetOriginalProfile()));
32 } 33 }
33 34
(...skipping 10 matching lines...) Expand all
44 // WebContentsObserver overrides 45 // WebContentsObserver overrides
45 46
46 void AlternateErrorPageTabObserver::RenderViewCreated( 47 void AlternateErrorPageTabObserver::RenderViewCreated(
47 RenderViewHost* render_view_host) { 48 RenderViewHost* render_view_host) {
48 UpdateAlternateErrorPageURL(render_view_host); 49 UpdateAlternateErrorPageURL(render_view_host);
49 } 50 }
50 51
51 //////////////////////////////////////////////////////////////////////////////// 52 ////////////////////////////////////////////////////////////////////////////////
52 // content::NotificationObserver overrides 53 // content::NotificationObserver overrides
53 54
54 void AlternateErrorPageTabObserver::Observe(int type, 55 void AlternateErrorPageTabObserver::Observe(
55 const content::NotificationSource& source, 56 int type,
56 const content::NotificationDetails& details) { 57 const content::NotificationSource& source,
58 const content::NotificationDetails& details) {
57 if (type == chrome::NOTIFICATION_PREF_CHANGED) { 59 if (type == chrome::NOTIFICATION_PREF_CHANGED) {
58 DCHECK_EQ(profile_->GetPrefs(), content::Source<PrefService>(source).ptr()); 60 DCHECK_EQ(profile_->GetPrefs(), content::Source<PrefService>(source).ptr());
59 DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled), 61 DCHECK_EQ(std::string(prefs::kAlternateErrorPagesEnabled),
60 *content::Details<std::string>(details).ptr()); 62 *content::Details<std::string>(details).ptr());
61 } else { 63 } else {
62 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 64 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
63 } 65 }
64 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 66 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost());
65 } 67 }
66 68
(...skipping 13 matching lines...) Expand all
80 url = google_util::AppendGoogleLocaleParam(url); 82 url = google_util::AppendGoogleLocaleParam(url);
81 url = google_util::AppendGoogleTLDParam(profile_, url); 83 url = google_util::AppendGoogleTLDParam(profile_, url);
82 } 84 }
83 return url; 85 return url;
84 } 86 }
85 87
86 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( 88 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL(
87 RenderViewHost* rvh) { 89 RenderViewHost* rvh) {
88 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL()); 90 rvh->SetAltErrorPageURL(GetAlternateErrorPageURL());
89 } 91 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/alternate_error_tab_observer.h ('k') | chrome/browser/ui/tab_contents/tab_contents.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698