OLD | NEW |
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_url_tracker_navigation_helper.h" |
8 #include "chrome/browser/google/google_util.h" | 9 #include "chrome/browser/google/google_util.h" |
9 #include "chrome/browser/infobars/infobar_service.h" | |
10 #include "components/infobars/core/infobar.h" | 10 #include "components/infobars/core/infobar.h" |
11 #include "content/public/browser/navigation_entry.h" | 11 #include "components/infobars/core/infobar_manager.h" |
12 #include "content/public/browser/page_navigator.h" | |
13 #include "content/public/browser/web_contents.h" | |
14 #include "grit/generated_resources.h" | 12 #include "grit/generated_resources.h" |
15 #include "net/base/net_util.h" | 13 #include "net/base/net_util.h" |
16 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
17 | 15 |
18 | 16 |
19 // static | 17 // static |
20 infobars::InfoBar* GoogleURLTrackerInfoBarDelegate::Create( | 18 infobars::InfoBar* GoogleURLTrackerInfoBarDelegate::Create( |
21 InfoBarService* infobar_service, | 19 infobars::InfoBarManager* infobar_manager, |
22 GoogleURLTracker* google_url_tracker, | 20 GoogleURLTracker* google_url_tracker, |
23 const GURL& search_url) { | 21 const GURL& search_url) { |
24 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 22 return infobar_manager->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
25 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( | 23 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( |
26 google_url_tracker, search_url)))); | 24 google_url_tracker, search_url)))); |
27 } | 25 } |
28 | 26 |
29 bool GoogleURLTrackerInfoBarDelegate::Accept() { | 27 bool GoogleURLTrackerInfoBarDelegate::Accept() { |
30 google_url_tracker_->AcceptGoogleURL(true); | 28 google_url_tracker_->AcceptGoogleURL(true); |
31 return false; | 29 return false; |
32 } | 30 } |
33 | 31 |
34 bool GoogleURLTrackerInfoBarDelegate::Cancel() { | 32 bool GoogleURLTrackerInfoBarDelegate::Cancel() { |
(...skipping 16 matching lines...) Expand all Loading... |
51 GURL new_search_url; | 49 GURL new_search_url; |
52 if (redo_search) { | 50 if (redo_search) { |
53 // Re-do the user's search on the new domain. | 51 // Re-do the user's search on the new domain. |
54 DCHECK(search_url_.is_valid()); | 52 DCHECK(search_url_.is_valid()); |
55 url::Replacements<char> replacements; | 53 url::Replacements<char> replacements; |
56 const std::string& host(google_url_tracker_->fetched_google_url().host()); | 54 const std::string& host(google_url_tracker_->fetched_google_url().host()); |
57 replacements.SetHost(host.data(), url::Component(0, host.length())); | 55 replacements.SetHost(host.data(), url::Component(0, host.length())); |
58 new_search_url = search_url_.ReplaceComponents(replacements); | 56 new_search_url = search_url_.ReplaceComponents(replacements); |
59 } | 57 } |
60 | 58 |
61 content::WebContents* contents = | 59 // Take ownership of |navigation_helper_| in order to ensure that it stays |
62 InfoBarService::WebContentsFromInfoBar(infobar()); | 60 // alive for the duration of this method. |
| 61 scoped_ptr<GoogleURLTrackerNavigationHelper> navigation_helper = |
| 62 navigation_helper_.Pass(); |
63 infobar()->RemoveSelf(); | 63 infobar()->RemoveSelf(); |
64 // WARNING: |this| may be deleted at this point! Do not access any members! | 64 // WARNING: |this| may be deleted at this point! Do not access any members! |
65 | 65 |
66 if (new_search_url.is_valid()) { | 66 if (new_search_url.is_valid()) |
67 contents->OpenURL(content::OpenURLParams( | 67 navigation_helper->OpenURL(new_search_url, CURRENT_TAB, false); |
68 new_search_url, content::Referrer(), CURRENT_TAB, | |
69 content::PAGE_TRANSITION_GENERATED, false)); | |
70 } | |
71 } | 68 } |
72 | 69 |
73 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 70 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
74 GoogleURLTracker* google_url_tracker, | 71 GoogleURLTracker* google_url_tracker, |
75 const GURL& search_url) | 72 const GURL& search_url) |
76 : ConfirmInfoBarDelegate(), | 73 : ConfirmInfoBarDelegate(), |
77 google_url_tracker_(google_url_tracker), | 74 google_url_tracker_(google_url_tracker), |
78 search_url_(search_url), | 75 search_url_(search_url), |
79 pending_id_(0) { | 76 pending_id_(0) { |
80 } | 77 } |
(...skipping 19 matching lines...) Expand all Loading... |
100 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, | 97 IDS_GOOGLE_URL_TRACKER_INFOBAR_DONT_SWITCH, |
101 net::StripWWWFromHost(google_url_tracker_->google_url())); | 98 net::StripWWWFromHost(google_url_tracker_->google_url())); |
102 } | 99 } |
103 | 100 |
104 base::string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const { | 101 base::string16 GoogleURLTrackerInfoBarDelegate::GetLinkText() const { |
105 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | 102 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); |
106 } | 103 } |
107 | 104 |
108 bool GoogleURLTrackerInfoBarDelegate::LinkClicked( | 105 bool GoogleURLTrackerInfoBarDelegate::LinkClicked( |
109 WindowOpenDisposition disposition) { | 106 WindowOpenDisposition disposition) { |
110 InfoBarService::WebContentsFromInfoBar(infobar())->OpenURL( | 107 navigation_helper_->OpenURL( |
111 content::OpenURLParams( | 108 google_util::AppendGoogleLocaleParam(GURL( |
112 google_util::AppendGoogleLocaleParam(GURL( | 109 "https://www.google.com/support/chrome/bin/answer.py?" |
113 "https://www.google.com/support/chrome/bin/answer.py?" | 110 "answer=1618699")), |
114 "answer=1618699")), | 111 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
115 content::Referrer(), | 112 true); |
116 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | |
117 content::PAGE_TRANSITION_LINK, false)); | |
118 return false; | 113 return false; |
119 } | 114 } |
120 | 115 |
121 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( | 116 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( |
122 const NavigationDetails& details) const { | 117 const NavigationDetails& details) const { |
123 return (details.entry_id != contents_unique_id()) && | 118 return (details.entry_id != contents_unique_id()) && |
124 (details.entry_id != pending_id_); | 119 (details.entry_id != pending_id_); |
125 } | 120 } |
OLD | NEW |