| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/google/google_url_tracker.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/google/google_util.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 16 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 17 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 17 #include "chrome/common/chrome_notification_types.h" | 18 #include "chrome/common/chrome_notification_types.h" |
| 18 #include "chrome/common/chrome_switches.h" | 19 #include "chrome/common/chrome_switches.h" |
| 19 #include "chrome/common/pref_names.h" | 20 #include "chrome/common/pref_names.h" |
| 20 #include "content/browser/tab_contents/navigation_controller.h" | 21 #include "content/browser/tab_contents/navigation_controller.h" |
| 21 #include "content/common/notification_service.h" | 22 #include "content/common/notification_service.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "net/base/load_flags.h" | 24 #include "net/base/load_flags.h" |
| 25 #include "net/base/net_util.h" |
| 24 #include "net/url_request/url_request_context_getter.h" | 26 #include "net/url_request/url_request_context_getter.h" |
| 25 #include "net/url_request/url_request_status.h" | 27 #include "net/url_request/url_request_status.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 30 InfoBarDelegate* CreateInfobar(TabContents* tab_contents, | 32 InfoBarDelegate* CreateInfobar(TabContents* tab_contents, |
| 31 GoogleURLTracker* google_url_tracker, | 33 GoogleURLTracker* google_url_tracker, |
| 32 const GURL& new_google_url) { | 34 const GURL& new_google_url) { |
| 33 InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents, | 35 InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents, |
| 34 google_url_tracker, new_google_url); | 36 google_url_tracker, new_google_url); |
| 35 TabContentsWrapper* wrapper = | 37 TabContentsWrapper* wrapper = |
| 36 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | 38 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 37 wrapper->AddInfoBar(infobar); | 39 wrapper->AddInfoBar(infobar); |
| 38 return infobar; | 40 return infobar; |
| 39 } | 41 } |
| 40 | 42 |
| 41 } // namespace | 43 } // namespace |
| 42 | 44 |
| 43 // GoogleURLTrackerInfoBarDelegate -------------------------------------------- | 45 // GoogleURLTrackerInfoBarDelegate -------------------------------------------- |
| 44 | 46 |
| 45 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 47 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
| 46 TabContents* tab_contents, | 48 TabContents* tab_contents, |
| 47 GoogleURLTracker* google_url_tracker, | 49 GoogleURLTracker* google_url_tracker, |
| 48 const GURL& new_google_url) | 50 const GURL& new_google_url) |
| 49 : ConfirmInfoBarDelegate(tab_contents), | 51 : ConfirmInfoBarDelegate(tab_contents), |
| 50 google_url_tracker_(google_url_tracker), | 52 google_url_tracker_(google_url_tracker), |
| 51 new_google_url_(new_google_url) { | 53 new_google_url_(new_google_url), |
| 54 tab_contents_(tab_contents) { |
| 52 } | 55 } |
| 53 | 56 |
| 54 bool GoogleURLTrackerInfoBarDelegate::Accept() { | 57 bool GoogleURLTrackerInfoBarDelegate::Accept() { |
| 55 google_url_tracker_->AcceptGoogleURL(new_google_url_); | 58 google_url_tracker_->AcceptGoogleURL(new_google_url_); |
| 56 google_url_tracker_->RedoSearch(); | 59 google_url_tracker_->RedoSearch(); |
| 57 return true; | 60 return true; |
| 58 } | 61 } |
| 59 | 62 |
| 60 bool GoogleURLTrackerInfoBarDelegate::Cancel() { | 63 bool GoogleURLTrackerInfoBarDelegate::Cancel() { |
| 61 google_url_tracker_->CancelGoogleURL(new_google_url_); | 64 google_url_tracker_->CancelGoogleURL(new_google_url_); |
| 62 return true; | 65 return true; |
| 63 } | 66 } |
| 64 | 67 |
| 68 string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const { |
| 69 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
| 70 } |
| 71 |
| 72 bool GoogleURLTrackerInfoBarDelegate::LinkClicked( |
| 73 WindowOpenDisposition disposition) { |
| 74 tab_contents_->OpenURL(google_util::AppendGoogleLocaleParam(GURL( |
| 75 "https://www.google.com/support/chrome/bin/answer.py?answer=1618699")), |
| 76 GURL(), (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 77 PageTransition::LINK); |
| 78 return false; |
| 79 } |
| 80 |
| 65 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 81 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
| 66 google_url_tracker_->InfoBarClosed(); | 82 google_url_tracker_->InfoBarClosed(); |
| 67 } | 83 } |
| 68 | 84 |
| 69 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 85 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
| 70 // TODO(ukai): change new_google_url to google_base_domain? | |
| 71 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, | 86 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, |
| 72 UTF8ToUTF16(new_google_url_.spec())); | 87 GetHost(true), GetHost(false)); |
| 73 } | 88 } |
| 74 | 89 |
| 75 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( | 90 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( |
| 76 InfoBarButton button) const { | 91 InfoBarButton button) const { |
| 77 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 92 bool new_host = (button == BUTTON_OK); |
| 78 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL : | 93 return l10n_util::GetStringFUTF16(new_host ? |
| 79 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL); | 94 IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH : |
| 95 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, GetHost(new_host)); |
| 96 } |
| 97 |
| 98 string16 GoogleURLTrackerInfoBarDelegate::GetHost(bool new_host) const { |
| 99 return net::StripWWW(UTF8ToUTF16( |
| 100 (new_host ? new_google_url_ : google_url_tracker_->GoogleURL()).host())); |
| 80 } | 101 } |
| 81 | 102 |
| 82 | 103 |
| 83 // GoogleURLTracker ----------------------------------------------------------- | 104 // GoogleURLTracker ----------------------------------------------------------- |
| 84 | 105 |
| 85 const char GoogleURLTracker::kDefaultGoogleHomepage[] = | 106 const char GoogleURLTracker::kDefaultGoogleHomepage[] = |
| 86 "http://www.google.com/"; | 107 "http://www.google.com/"; |
| 87 const char GoogleURLTracker::kSearchDomainCheckURL[] = | 108 const char GoogleURLTracker::kSearchDomainCheckURL[] = |
| 88 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; | 109 "https://www.google.com/searchdomaincheck?format=domain&type=chrome"; |
| 89 | 110 |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 355 } | 376 } |
| 356 | 377 |
| 357 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( | 378 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( |
| 358 TabContents* tab_contents) { | 379 TabContents* tab_contents) { |
| 359 if (!need_to_prompt_) | 380 if (!need_to_prompt_) |
| 360 return; | 381 return; |
| 361 DCHECK(!fetched_google_url_.is_empty()); | 382 DCHECK(!fetched_google_url_.is_empty()); |
| 362 | 383 |
| 363 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); | 384 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); |
| 364 } | 385 } |
| OLD | NEW |