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

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

Issue 11114009: Split the existing GoogleURLTrackerInfoBarDelegate into two classes (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 2 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/google/google_url_tracker_infobar_delegate.h" 5 #include "chrome/browser/google/google_url_tracker_infobar_delegate.h"
6 6
7 #include "chrome/browser/google/google_url_tracker.h" 7 #include "chrome/browser/google/google_url_tracker.h"
8 #include "chrome/browser/google/google_util.h" 8 #include "chrome/browser/google/google_util.h"
9 #include "chrome/browser/infobars/infobar_tab_helper.h" 9 #include "chrome/browser/infobars/infobar_tab_helper.h"
10 #include "content/public/browser/navigation_details.h" 10 #include "content/public/browser/navigation_details.h"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/page_navigator.h" 12 #include "content/public/browser/page_navigator.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
15 #include "net/base/net_util.h" 15 #include "net/base/net_util.h"
16 #include "ui/base/l10n/l10n_util.h" 16 #include "ui/base/l10n/l10n_util.h"
17 17
18 18
19 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( 19 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
20 InfoBarTabHelper* infobar_helper, 20 InfoBarTabHelper* infobar_helper,
21 GoogleURLTracker* google_url_tracker, 21 GoogleURLTracker* google_url_tracker,
22 const GURL& new_google_url) 22 const GURL& search_url)
23 : ConfirmInfoBarDelegate(infobar_helper), 23 : ConfirmInfoBarDelegate(infobar_helper),
24 map_key_(infobar_helper),
25 google_url_tracker_(google_url_tracker), 24 google_url_tracker_(google_url_tracker),
26 new_google_url_(new_google_url), 25 search_url_(search_url),
27 showing_(false),
28 pending_id_(0) { 26 pending_id_(0) {
29 } 27 }
30 28
31 bool GoogleURLTrackerInfoBarDelegate::Accept() { 29 bool GoogleURLTrackerInfoBarDelegate::Accept() {
32 google_url_tracker_->AcceptGoogleURL(new_google_url_, true); 30 google_url_tracker_->AcceptGoogleURL(true);
33 return false; 31 return false;
34 } 32 }
35 33
36 bool GoogleURLTrackerInfoBarDelegate::Cancel() { 34 bool GoogleURLTrackerInfoBarDelegate::Cancel() {
37 google_url_tracker_->CancelGoogleURL(new_google_url_); 35 google_url_tracker_->CancelGoogleURL();
38 return false; 36 return false;
39 } 37 }
40 38
41 string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const { 39 string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const {
42 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); 40 return l10n_util::GetStringUTF16(IDS_LEARN_MORE);
43 } 41 }
44 42
45 bool GoogleURLTrackerInfoBarDelegate::LinkClicked( 43 bool GoogleURLTrackerInfoBarDelegate::LinkClicked(
46 WindowOpenDisposition disposition) { 44 WindowOpenDisposition disposition) {
47 content::OpenURLParams params(google_util::AppendGoogleLocaleParam(GURL( 45 content::OpenURLParams params(google_util::AppendGoogleLocaleParam(GURL(
48 "https://www.google.com/support/chrome/bin/answer.py?answer=1618699")), 46 "https://www.google.com/support/chrome/bin/answer.py?answer=1618699")),
49 content::Referrer(), 47 content::Referrer(),
50 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 48 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
51 content::PAGE_TRANSITION_LINK, false); 49 content::PAGE_TRANSITION_LINK, false);
52 owner()->GetWebContents()->OpenURL(params); 50 owner()->GetWebContents()->OpenURL(params);
53 return false; 51 return false;
54 } 52 }
55 53
56 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( 54 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal(
57 const content::LoadCommittedDetails& details) const { 55 const content::LoadCommittedDetails& details) const {
58 int unique_id = details.entry->GetUniqueID(); 56 int unique_id = details.entry->GetUniqueID();
59 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); 57 return (unique_id != contents_unique_id()) && (unique_id != pending_id_);
60 } 58 }
61 59
62 void GoogleURLTrackerInfoBarDelegate::SetGoogleURL(const GURL& new_google_url) { 60 void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) {
63 DCHECK_EQ(net::StripWWWFromHost(new_google_url_),
64 net::StripWWWFromHost(new_google_url));
65 new_google_url_ = new_google_url;
66 }
67
68 void GoogleURLTrackerInfoBarDelegate::Show(const GURL& search_url) {
69 if (!owner())
70 return;
71 StoreActiveEntryUniqueID(owner()); 61 StoreActiveEntryUniqueID(owner());
72 search_url_ = search_url; 62 search_url_ = search_url;
73 pending_id_ = 0; 63 pending_id_ = 0;
74 if (!showing_) {
75 showing_ = true;
76 owner()->AddInfoBar(this); // May delete |this| on failure!
77 }
78 } 64 }
79 65
80 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { 66 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
81 if (!showing_) {
82 // We haven't been added to a tab, so just delete ourselves.
83 delete this;
84 return;
85 }
86
87 // Synchronously remove ourselves from the URL tracker's list, because the
88 // RemoveInfoBar() call below may result in either a synchronous or an
89 // asynchronous call back to InfoBarClosed(), and it's easier to handle when
90 // we just guarantee the removal is synchronous.
91 google_url_tracker_->InfoBarClosed(map_key_);
92 google_url_tracker_ = NULL;
93
94 // If we're already animating closed, we won't have an owner. Do nothing in
95 // this case.
96 // TODO(pkasting): For now, this can also happen if we were showing in a
97 // background tab that was then closed, in which case we'll have leaked and
98 // subsequently reached here due to GoogleURLTracker::CloseAllInfoBars().
99 // This case will no longer happen once infobars are refactored to own their
100 // delegates.
101 if (!owner())
102 return;
103
104 if (redo_search) { 67 if (redo_search) {
105 // Re-do the user's search on the new domain. 68 // Re-do the user's search on the new domain.
106 DCHECK(search_url_.is_valid()); 69 DCHECK(search_url_.is_valid());
107 url_canon::Replacements<char> replacements; 70 url_canon::Replacements<char> replacements;
108 const std::string& host(new_google_url_.host()); 71 const std::string& host(google_url_tracker_->fetched_google_url().host());
109 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); 72 replacements.SetHost(host.data(), url_parse::Component(0, host.length()));
110 GURL new_search_url(search_url_.ReplaceComponents(replacements)); 73 GURL new_search_url(search_url_.ReplaceComponents(replacements));
111 if (new_search_url.is_valid()) { 74 if (new_search_url.is_valid()) {
112 content::OpenURLParams params(new_search_url, content::Referrer(), 75 owner()->GetWebContents()->OpenURL(content::OpenURLParams(
113 CURRENT_TAB, content::PAGE_TRANSITION_GENERATED, false); 76 new_search_url, content::Referrer(), CURRENT_TAB,
114 owner()->GetWebContents()->OpenURL(params); 77 content::PAGE_TRANSITION_GENERATED, false));
115 } 78 }
116 } 79 }
117 80
118 owner()->RemoveInfoBar(this); 81 owner()->RemoveInfoBar(this);
119 } 82 }
120 83
121 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { 84 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
122 if (google_url_tracker_)
123 google_url_tracker_->InfoBarClosed(map_key_);
124 } 85 }
125 86
126 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { 87 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
127 return l10n_util::GetStringFUTF16( 88 return l10n_util::GetStringFUTF16(
128 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, 89 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
129 net::StripWWWFromHost(new_google_url_), 90 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()),
130 net::StripWWWFromHost(google_url_tracker_->google_url_)); 91 net::StripWWWFromHost(google_url_tracker_->google_url()));
131 } 92 }
132 93
133 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( 94 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel(
134 InfoBarButton button) const { 95 InfoBarButton button) const {
135 bool new_host = (button == BUTTON_OK); 96 if (button == BUTTON_OK) {
97 return l10n_util::GetStringFUTF16(
98 IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH,
99 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()));
100 }
136 return l10n_util::GetStringFUTF16( 101 return l10n_util::GetStringFUTF16(
137 new_host ? 102 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH,
138 IDS_GOOGLE_URL_TRACKER_INFOBAR_SWITCH : 103 net::StripWWWFromHost(google_url_tracker_->google_url()));
139 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH,
140 net::StripWWWFromHost(new_host ?
141 new_google_url_ : google_url_tracker_->google_url_));
142 } 104 }
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