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

Side by Side Diff: chrome/browser/google/google_url_tracker_infobar_delegate.cc

Issue 316203003: Componentize GoogleURLTracker(InfoBarDelegate,MapEntry,NavHelper) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nits Created 6 years, 6 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
6
7 #include "chrome/browser/google/google_url_tracker.h"
8 #include "chrome/browser/google/google_url_tracker_navigation_helper.h"
9 #include "chrome/browser/google/google_util.h"
10 #include "components/infobars/core/infobar.h"
11 #include "components/infobars/core/infobar_manager.h"
12 #include "grit/generated_resources.h"
13 #include "net/base/net_util.h"
14 #include "ui/base/l10n/l10n_util.h"
15
16
17 // static
18 infobars::InfoBar* GoogleURLTrackerInfoBarDelegate::Create(
19 infobars::InfoBarManager* infobar_manager,
20 GoogleURLTracker* google_url_tracker,
21 const GURL& search_url) {
22 return infobar_manager->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
23 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate(
24 google_url_tracker, search_url))));
25 }
26
27 bool GoogleURLTrackerInfoBarDelegate::Accept() {
28 google_url_tracker_->AcceptGoogleURL(true);
29 return false;
30 }
31
32 bool GoogleURLTrackerInfoBarDelegate::Cancel() {
33 google_url_tracker_->CancelGoogleURL();
34 return false;
35 }
36
37 void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) {
38 StoreActiveEntryUniqueID();
39 search_url_ = search_url;
40 pending_id_ = 0;
41 }
42
43 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
44 // Calling OpenURL() will auto-close us asynchronously. It's easier for
45 // various classes (e.g. GoogleURLTrackerMapEntry) to reason about things if
46 // the closure always happens synchronously, so we always call RemoveInfoBar()
47 // directly, then OpenURL() if desirable. (This calling order is safer if
48 // for some reason in the future OpenURL() were to close us synchronously.)
49 GURL new_search_url;
50 if (redo_search) {
51 // Re-do the user's search on the new domain.
52 DCHECK(search_url_.is_valid());
53 url::Replacements<char> replacements;
54 const std::string& host(google_url_tracker_->fetched_google_url().host());
55 replacements.SetHost(host.data(), url::Component(0, host.length()));
56 new_search_url = search_url_.ReplaceComponents(replacements);
57 }
58
59 // Take ownership of |navigation_helper_| in order to ensure that it stays
60 // alive for the duration of this method.
61 scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper =
62 navigation_helper_.Pass();
63 infobar()->RemoveSelf();
64 // WARNING: |this| may be deleted at this point! Do not access any members!
65
66 if (new_search_url.is_valid())
67 navigation_helper->OpenURL(new_search_url, CURRENT_TAB, false);
68 }
69
70 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
71 GoogleURLTracker* google_url_tracker,
72 const GURL& search_url)
73 : ConfirmInfoBarDelegate(),
74 google_url_tracker_(google_url_tracker),
75 navigation_helper_weak_ptr_(NULL),
76 search_url_(search_url),
77 pending_id_(0) {
78 }
79
80 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
81 }
82
83 base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
84 return l10n_util::GetStringFUTF16(
85 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
86 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()),
87 net::StripWWWFromHost(google_url_tracker_->google_url()));
88 }
89
90 base::string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
91 InfoBarButton button) const {
92 if (button == BUTTON_OK) {
93 return l10n_util::GetStringFUTF16(
94 IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH,
95 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()));
96 }
97 return l10n_util::GetStringFUTF16(
98 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH,
99 net::StripWWWFromHost(google_url_tracker_->google_url()));
100 }
101
102 base::string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const {
103 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
104 }
105
106 bool GoogleURLTrackerInfoBarDelegate::LinkClicked(
107 WindowOpenDisposition disposition) {
108 navigation_helper_->OpenURL(
109 google_util::AppendGoogleLocaleParam(GURL(
110 "https://www.google.com/support/chrome/bin/answer.py?"
111 "answer=1618699")),
112 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
113 true);
114 return false;
115 }
116
117 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal(
118 const NavigationDetails& details) const {
119 return (details.entry_id != contents_unique_id()) &&
120 (details.entry_id != pending_id_);
121 }
OLDNEW
« no previous file with comments | « chrome/browser/google/google_url_tracker_infobar_delegate.h ('k') | chrome/browser/google/google_url_tracker_map_entry.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698