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

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

Issue 137623011: Switch to using the new Link Doctor API. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 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/link_doctor_tab_observer.h"
6 6
7 #include "base/prefs/pref_service.h" 7 #include "base/prefs/pref_service.h"
8 #include "chrome/browser/chrome_notification_types.h" 8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/google/google_util.h" 9 #include "chrome/browser/google/google_util.h"
10 #include "chrome/browser/profiles/profile.h" 10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/common/pref_names.h" 11 #include "chrome/common/pref_names.h"
12 #include "chrome/common/render_messages.h" 12 #include "chrome/common/render_messages.h"
13 #include "components/user_prefs/pref_registry_syncable.h" 13 #include "components/user_prefs/pref_registry_syncable.h"
14 #include "content/public/browser/notification_service.h" 14 #include "content/public/browser/notification_service.h"
15 #include "content/public/browser/render_frame_host.h" 15 #include "content/public/browser/render_frame_host.h"
16 #include "content/public/browser/render_view_host.h" 16 #include "content/public/browser/render_view_host.h"
17 #include "content/public/browser/web_contents.h" 17 #include "content/public/browser/web_contents.h"
18 #include "google_apis/google_api_keys.h"
18 19
19 using content::RenderFrameHost; 20 using content::RenderFrameHost;
20 using content::RenderViewHost; 21 using content::RenderViewHost;
21 using content::WebContents; 22 using content::WebContents;
22 23
23 DEFINE_WEB_CONTENTS_USER_DATA_KEY(AlternateErrorPageTabObserver); 24 DEFINE_WEB_CONTENTS_USER_DATA_KEY(LinkDoctorTabObserver);
24 25
25 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( 26 LinkDoctorTabObserver::LinkDoctorTabObserver(WebContents* web_contents)
26 WebContents* web_contents)
27 : content::WebContentsObserver(web_contents), 27 : content::WebContentsObserver(web_contents),
28 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { 28 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
29 PrefService* prefs = profile_->GetPrefs(); 29 PrefService* prefs = profile_->GetPrefs();
30 if (prefs) { 30 if (prefs) {
31 pref_change_registrar_.Init(prefs); 31 pref_change_registrar_.Init(prefs);
32 pref_change_registrar_.Add( 32 pref_change_registrar_.Add(
33 prefs::kAlternateErrorPagesEnabled, 33 prefs::kAlternateErrorPagesEnabled,
34 base::Bind(&AlternateErrorPageTabObserver:: 34 base::Bind(&LinkDoctorTabObserver::OnLinkDoctorEnabledChanged,
35 OnAlternateErrorPagesEnabledChanged,
36 base::Unretained(this))); 35 base::Unretained(this)));
37 } 36 }
38 37
39 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 38 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
40 content::Source<Profile>(profile_->GetOriginalProfile())); 39 content::Source<Profile>(profile_->GetOriginalProfile()));
41 } 40 }
42 41
43 AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() { 42 LinkDoctorTabObserver::~LinkDoctorTabObserver() {
44 } 43 }
45 44
46 // static 45 // static
47 void AlternateErrorPageTabObserver::RegisterProfilePrefs( 46 void LinkDoctorTabObserver::RegisterProfilePrefs(
48 user_prefs::PrefRegistrySyncable* prefs) { 47 user_prefs::PrefRegistrySyncable* prefs) {
49 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, 48 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
50 true, 49 true,
51 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 50 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
52 } 51 }
53 52
54 //////////////////////////////////////////////////////////////////////////////// 53 ////////////////////////////////////////////////////////////////////////////////
55 // WebContentsObserver overrides 54 // WebContentsObserver overrides
56 55
57 void AlternateErrorPageTabObserver::RenderViewCreated( 56 void LinkDoctorTabObserver::RenderViewCreated(
58 RenderViewHost* render_view_host) { 57 RenderViewHost* render_view_host) {
59 UpdateAlternateErrorPageURL(render_view_host); 58 UpdateLinkDoctorInfo(render_view_host);
60 } 59 }
61 60
62 //////////////////////////////////////////////////////////////////////////////// 61 ////////////////////////////////////////////////////////////////////////////////
63 // content::NotificationObserver overrides 62 // content::NotificationObserver overrides
64 63
65 void AlternateErrorPageTabObserver::Observe( 64 void LinkDoctorTabObserver::Observe(
66 int type, 65 int type,
67 const content::NotificationSource& source, 66 const content::NotificationSource& source,
68 const content::NotificationDetails& details) { 67 const content::NotificationDetails& details) {
69 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 68 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
70 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 69 UpdateLinkDoctorInfo(web_contents()->GetRenderViewHost());
71 } 70 }
72 71
73 //////////////////////////////////////////////////////////////////////////////// 72 ////////////////////////////////////////////////////////////////////////////////
74 // Internal helpers 73 // Internal helpers
75 74
76 GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const { 75 GURL LinkDoctorTabObserver::GetLinkDoctorURL() const {
77 GURL url; 76 GURL url;
Peter Kasting 2014/02/10 23:19:46 Nit: Remove this temp; return GURL() or google_uti
mmenke 2014/02/11 16:02:19 Done.
78 // Disable alternate error pages when in Incognito mode. 77 // Disable aLink Doctor suggestions when in Incognito mode.
Peter Kasting 2014/02/10 23:19:46 Nit: aLink -> Link
mmenke 2014/02/11 16:02:19 Done.
79 if (profile_->IsOffTheRecord()) 78 if (profile_->IsOffTheRecord())
Peter Kasting 2014/02/10 23:19:46 Nit: I'd combine this statement (and its comment)
mmenke 2014/02/11 16:02:19 Done.
80 return url; 79 return url;
81 80
82 if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { 81 // Don't use Link Doctor suggestions when disabled.
83 url = google_util::LinkDoctorBaseURL(); 82 if (!profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled))
84 if (!url.is_valid()) 83 return url;
85 return url; 84
86 url = google_util::AppendGoogleLocaleParam(url); 85 url = google_util::LinkDoctorBaseURL();
87 url = google_util::AppendGoogleTLDParam(profile_, url);
88 }
89 return url; 86 return url;
90 } 87 }
91 88
92 void AlternateErrorPageTabObserver::OnAlternateErrorPagesEnabledChanged() { 89 void LinkDoctorTabObserver::OnLinkDoctorEnabledChanged() {
93 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 90 UpdateLinkDoctorInfo(web_contents()->GetRenderViewHost());
94 } 91 }
95 92
96 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( 93 void LinkDoctorTabObserver::UpdateLinkDoctorInfo(
97 RenderViewHost* rvh) { 94 RenderViewHost* rvh) {
98 RenderFrameHost* rfh = rvh->GetMainFrame(); 95 RenderFrameHost* rfh = rvh->GetMainFrame();
99 rfh->Send(new ChromeViewMsg_SetAltErrorPageURL( 96 rfh->Send(new ChromeViewMsg_SetLinkDoctorInfo(
100 rfh->GetRoutingID(), GetAlternateErrorPageURL())); 97 rfh->GetRoutingID(),
Peter Kasting 2014/02/10 23:19:46 Nit: Indent 4, not 14 You may list more than one
mmenke 2014/02/11 16:02:19 Done.
98 GetLinkDoctorURL(),
99 google_util::GetGoogleLocale(),
100 google_util::GetGoogleCountryCode(profile_),
101 google_apis::GetAPIKey(),
102 google_util::GetGoogleSearchURL(profile_)));
101 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698