This source file includes following definitions.
- Create
- Accept
- Cancel
- Update
- Close
- pending_id_
- GetMessageText
- GetButtonLabel
- GetLinkText
- LinkClicked
- ShouldExpireInternal
#include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
#include "chrome/browser/google/google_url_tracker.h"
#include "chrome/browser/google/google_util.h"
#include "chrome/browser/infobars/infobar.h"
#include "chrome/browser/infobars/infobar_service.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/page_navigator.h"
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "net/base/net_util.h"
#include "ui/base/l10n/l10n_util.h"
InfoBar* GoogleURLTrackerInfoBarDelegate::Create(
InfoBarService* infobar_service,
GoogleURLTracker* google_url_tracker,
const GURL& search_url) {
return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate(
google_url_tracker, search_url))));
}
bool GoogleURLTrackerInfoBarDelegate::Accept() {
google_url_tracker_->AcceptGoogleURL(true);
return false;
}
bool GoogleURLTrackerInfoBarDelegate::Cancel() {
google_url_tracker_->CancelGoogleURL();
return false;
}
void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) {
StoreActiveEntryUniqueID();
search_url_ = search_url;
pending_id_ = 0;
}
void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
GURL new_search_url;
if (redo_search) {
DCHECK(search_url_.is_valid());
url_canon::Replacements<char> replacements;
const std::string& host(google_url_tracker_->fetched_google_url().host());
replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
new_search_url = search_url_.ReplaceComponents(replacements);
}
content::WebContents* contents = web_contents();
infobar()->RemoveSelf();
if (new_search_url.is_valid()) {
contents->OpenURL(content::OpenURLParams(
new_search_url, content::Referrer(), CURRENT_TAB,
content::PAGE_TRANSITION_GENERATED, false));
}
}
GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
GoogleURLTracker* google_url_tracker,
const GURL& search_url)
: ConfirmInfoBarDelegate(),
google_url_tracker_(google_url_tracker),
search_url_(search_url),
pending_id_(0) {
}
GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
}
base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
return l10n_util::GetStringFUTF16(
IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
net::StripWWWFromHost(google_url_tracker_->fetched_google_url()),
net::StripWWWFromHost(google_url_tracker_->google_url()));
}
base::string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
InfoBarButton button) const {
if (button == BUTTON_OK) {
return l10n_util::GetStringFUTF16(
IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH,
net::StripWWWFromHost(google_url_tracker_->fetched_google_url()));
}
return l10n_util::GetStringFUTF16(
IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH,
net::StripWWWFromHost(google_url_tracker_->google_url()));
}
base::string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const {
return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
}
bool GoogleURLTrackerInfoBarDelegate::LinkClicked(
WindowOpenDisposition disposition) {
web_contents()->OpenURL(content::OpenURLParams(
google_util::AppendGoogleLocaleParam(GURL(
"https://www.google.com/support/chrome/bin/answer.py?"
"answer=1618699")),
content::Referrer(),
(disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
content::PAGE_TRANSITION_LINK, false));
return false;
}
bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal(
const NavigationDetails& details) const {
return (details.entry_id != contents_unique_id()) &&
(details.entry_id != pending_id_);
}