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

Side by Side Diff: chrome/browser/ui/navigation_correction_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: Remove bonus line from a merge conflict 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/navigation_correction_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(NavigationCorrectionTabObserver);
24 25
25 AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( 26 NavigationCorrectionTabObserver::NavigationCorrectionTabObserver(
26 WebContents* web_contents) 27 WebContents* web_contents)
27 : content::WebContentsObserver(web_contents), 28 : content::WebContentsObserver(web_contents),
28 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { 29 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) {
29 PrefService* prefs = profile_->GetPrefs(); 30 PrefService* prefs = profile_->GetPrefs();
30 if (prefs) { 31 if (prefs) {
31 pref_change_registrar_.Init(prefs); 32 pref_change_registrar_.Init(prefs);
32 pref_change_registrar_.Add( 33 pref_change_registrar_.Add(
33 prefs::kAlternateErrorPagesEnabled, 34 prefs::kAlternateErrorPagesEnabled,
34 base::Bind(&AlternateErrorPageTabObserver:: 35 base::Bind(&NavigationCorrectionTabObserver::OnEnabledChanged,
35 OnAlternateErrorPagesEnabledChanged,
36 base::Unretained(this))); 36 base::Unretained(this)));
37 } 37 }
38 38
39 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED, 39 registrar_.Add(this, chrome::NOTIFICATION_GOOGLE_URL_UPDATED,
40 content::Source<Profile>(profile_->GetOriginalProfile())); 40 content::Source<Profile>(profile_->GetOriginalProfile()));
41 } 41 }
42 42
43 AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() { 43 NavigationCorrectionTabObserver::~NavigationCorrectionTabObserver() {
44 } 44 }
45 45
46 // static 46 // static
47 void AlternateErrorPageTabObserver::RegisterProfilePrefs( 47 void NavigationCorrectionTabObserver::RegisterProfilePrefs(
48 user_prefs::PrefRegistrySyncable* prefs) { 48 user_prefs::PrefRegistrySyncable* prefs) {
49 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, 49 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled,
50 true, 50 true,
51 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); 51 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF);
52 } 52 }
53 53
54 //////////////////////////////////////////////////////////////////////////////// 54 ////////////////////////////////////////////////////////////////////////////////
55 // WebContentsObserver overrides 55 // WebContentsObserver overrides
56 56
57 void AlternateErrorPageTabObserver::RenderViewCreated( 57 void NavigationCorrectionTabObserver::RenderViewCreated(
58 RenderViewHost* render_view_host) { 58 RenderViewHost* render_view_host) {
59 UpdateAlternateErrorPageURL(render_view_host); 59 UpdateNavigationCorrectionInfo(render_view_host);
60 } 60 }
61 61
62 //////////////////////////////////////////////////////////////////////////////// 62 ////////////////////////////////////////////////////////////////////////////////
63 // content::NotificationObserver overrides 63 // content::NotificationObserver overrides
64 64
65 void AlternateErrorPageTabObserver::Observe( 65 void NavigationCorrectionTabObserver::Observe(
66 int type, 66 int type,
67 const content::NotificationSource& source, 67 const content::NotificationSource& source,
68 const content::NotificationDetails& details) { 68 const content::NotificationDetails& details) {
69 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); 69 DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type);
70 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 70 UpdateNavigationCorrectionInfo(web_contents()->GetRenderViewHost());
71 } 71 }
72 72
73 //////////////////////////////////////////////////////////////////////////////// 73 ////////////////////////////////////////////////////////////////////////////////
74 // Internal helpers 74 // Internal helpers
75 75
76 GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const { 76 GURL NavigationCorrectionTabObserver::GetNavigationCorrectionURL() const {
77 GURL url; 77 // Disable navigation corrections when the preference is disabled or when in
78 // Disable alternate error pages when in Incognito mode. 78 // Incognito mode.
79 if (profile_->IsOffTheRecord()) 79 if (!profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled) ||
80 return url; 80 profile_->IsOffTheRecord()) {
81 return GURL();
82 }
81 83
82 if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { 84 return google_util::LinkDoctorBaseURL();
83 url = google_util::LinkDoctorBaseURL();
84 if (!url.is_valid())
85 return url;
86 url = google_util::AppendGoogleLocaleParam(url);
87 url = google_util::AppendGoogleTLDParam(profile_, url);
88 }
89 return url;
90 } 85 }
91 86
92 void AlternateErrorPageTabObserver::OnAlternateErrorPagesEnabledChanged() { 87 void NavigationCorrectionTabObserver::OnEnabledChanged() {
93 UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); 88 UpdateNavigationCorrectionInfo(web_contents()->GetRenderViewHost());
94 } 89 }
95 90
96 void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( 91 void NavigationCorrectionTabObserver::UpdateNavigationCorrectionInfo(
97 RenderViewHost* rvh) { 92 RenderViewHost* rvh) {
98 RenderFrameHost* rfh = rvh->GetMainFrame(); 93 RenderFrameHost* rfh = rvh->GetMainFrame();
99 rfh->Send(new ChromeViewMsg_SetAltErrorPageURL( 94 rfh->Send(new ChromeViewMsg_SetNavigationCorrectionInfo(
100 rfh->GetRoutingID(), GetAlternateErrorPageURL())); 95 rfh->GetRoutingID(), GetNavigationCorrectionURL(),
96 google_util::GetGoogleLocale(),
97 google_util::GetGoogleCountryCode(profile_), google_apis::GetAPIKey(),
98 google_util::GetGoogleSearchURL(profile_)));
101 } 99 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/navigation_correction_tab_observer.h ('k') | chrome/browser/ui/tab_helpers.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698