Index: chrome/browser/ui/navigation_correction_tab_observer.cc |
=================================================================== |
--- chrome/browser/ui/navigation_correction_tab_observer.cc (revision 251807) |
+++ chrome/browser/ui/navigation_correction_tab_observer.cc (working copy) |
@@ -2,7 +2,7 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/ui/alternate_error_tab_observer.h" |
+#include "chrome/browser/ui/navigation_correction_tab_observer.h" |
#include "base/prefs/pref_service.h" |
#include "chrome/browser/chrome_notification_types.h" |
@@ -15,14 +15,15 @@ |
#include "content/public/browser/render_frame_host.h" |
#include "content/public/browser/render_view_host.h" |
#include "content/public/browser/web_contents.h" |
+#include "google_apis/google_api_keys.h" |
using content::RenderFrameHost; |
using content::RenderViewHost; |
using content::WebContents; |
-DEFINE_WEB_CONTENTS_USER_DATA_KEY(AlternateErrorPageTabObserver); |
+DEFINE_WEB_CONTENTS_USER_DATA_KEY(NavigationCorrectionTabObserver); |
-AlternateErrorPageTabObserver::AlternateErrorPageTabObserver( |
+NavigationCorrectionTabObserver::NavigationCorrectionTabObserver( |
WebContents* web_contents) |
: content::WebContentsObserver(web_contents), |
profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())) { |
@@ -31,8 +32,7 @@ |
pref_change_registrar_.Init(prefs); |
pref_change_registrar_.Add( |
prefs::kAlternateErrorPagesEnabled, |
- base::Bind(&AlternateErrorPageTabObserver:: |
- OnAlternateErrorPagesEnabledChanged, |
+ base::Bind(&NavigationCorrectionTabObserver::OnEnabledChanged, |
base::Unretained(this))); |
} |
@@ -40,11 +40,11 @@ |
content::Source<Profile>(profile_->GetOriginalProfile())); |
} |
-AlternateErrorPageTabObserver::~AlternateErrorPageTabObserver() { |
+NavigationCorrectionTabObserver::~NavigationCorrectionTabObserver() { |
} |
// static |
-void AlternateErrorPageTabObserver::RegisterProfilePrefs( |
+void NavigationCorrectionTabObserver::RegisterProfilePrefs( |
user_prefs::PrefRegistrySyncable* prefs) { |
prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, |
true, |
@@ -54,48 +54,46 @@ |
//////////////////////////////////////////////////////////////////////////////// |
// WebContentsObserver overrides |
-void AlternateErrorPageTabObserver::RenderViewCreated( |
+void NavigationCorrectionTabObserver::RenderViewCreated( |
RenderViewHost* render_view_host) { |
- UpdateAlternateErrorPageURL(render_view_host); |
+ UpdateNavigationCorrectionInfo(render_view_host); |
} |
//////////////////////////////////////////////////////////////////////////////// |
// content::NotificationObserver overrides |
-void AlternateErrorPageTabObserver::Observe( |
+void NavigationCorrectionTabObserver::Observe( |
int type, |
const content::NotificationSource& source, |
const content::NotificationDetails& details) { |
DCHECK_EQ(chrome::NOTIFICATION_GOOGLE_URL_UPDATED, type); |
- UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
+ UpdateNavigationCorrectionInfo(web_contents()->GetRenderViewHost()); |
} |
//////////////////////////////////////////////////////////////////////////////// |
// Internal helpers |
-GURL AlternateErrorPageTabObserver::GetAlternateErrorPageURL() const { |
- GURL url; |
- // Disable alternate error pages when in Incognito mode. |
- if (profile_->IsOffTheRecord()) |
- return url; |
- |
- if (profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled)) { |
- url = google_util::LinkDoctorBaseURL(); |
- if (!url.is_valid()) |
- return url; |
- url = google_util::AppendGoogleLocaleParam(url); |
- url = google_util::AppendGoogleTLDParam(profile_, url); |
+GURL NavigationCorrectionTabObserver::GetNavigationCorrectionURL() const { |
+ // Disable navigation corrections when the preference is disabled or when in |
+ // Incognito mode. |
+ if (!profile_->GetPrefs()->GetBoolean(prefs::kAlternateErrorPagesEnabled) || |
+ profile_->IsOffTheRecord()) { |
+ return GURL(); |
} |
- return url; |
+ |
+ return google_util::LinkDoctorBaseURL(); |
} |
-void AlternateErrorPageTabObserver::OnAlternateErrorPagesEnabledChanged() { |
- UpdateAlternateErrorPageURL(web_contents()->GetRenderViewHost()); |
+void NavigationCorrectionTabObserver::OnEnabledChanged() { |
+ UpdateNavigationCorrectionInfo(web_contents()->GetRenderViewHost()); |
} |
-void AlternateErrorPageTabObserver::UpdateAlternateErrorPageURL( |
+void NavigationCorrectionTabObserver::UpdateNavigationCorrectionInfo( |
RenderViewHost* rvh) { |
RenderFrameHost* rfh = rvh->GetMainFrame(); |
- rfh->Send(new ChromeViewMsg_SetAltErrorPageURL( |
- rfh->GetRoutingID(), GetAlternateErrorPageURL())); |
+ rfh->Send(new ChromeViewMsg_SetNavigationCorrectionInfo( |
+ rfh->GetRoutingID(), GetNavigationCorrectionURL(), |
+ google_util::GetGoogleLocale(), |
+ google_util::GetGoogleCountryCode(profile_), google_apis::GetAPIKey(), |
+ google_util::GetGoogleSearchURL(profile_))); |
} |