Chromium Code Reviews| 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, |
| 21 GoogleURLTrackerNavigationHelper* navigation_helper, | |
| 23 const GURL& search_url) { | 22 const GURL& search_url) { |
| 24 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 23 return infobar_manager->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
| 25 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( | 24 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( |
| 26 google_url_tracker, search_url)))); | 25 google_url_tracker, navigation_helper, search_url)))); |
| 27 } | 26 } |
| 28 | 27 |
| 29 bool GoogleURLTrackerInfoBarDelegate::Accept() { | 28 bool GoogleURLTrackerInfoBarDelegate::Accept() { |
| 30 google_url_tracker_->AcceptGoogleURL(true); | 29 google_url_tracker_->AcceptGoogleURL(true); |
| 31 return false; | 30 return false; |
| 32 } | 31 } |
| 33 | 32 |
| 34 bool GoogleURLTrackerInfoBarDelegate::Cancel() { | 33 bool GoogleURLTrackerInfoBarDelegate::Cancel() { |
| 35 google_url_tracker_->CancelGoogleURL(); | 34 google_url_tracker_->CancelGoogleURL(); |
| 36 return false; | 35 return false; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 51 GURL new_search_url; | 50 GURL new_search_url; |
| 52 if (redo_search) { | 51 if (redo_search) { |
| 53 // Re-do the user's search on the new domain. | 52 // Re-do the user's search on the new domain. |
| 54 DCHECK(search_url_.is_valid()); | 53 DCHECK(search_url_.is_valid()); |
| 55 url::Replacements<char> replacements; | 54 url::Replacements<char> replacements; |
| 56 const std::string& host(google_url_tracker_->fetched_google_url().host()); | 55 const std::string& host(google_url_tracker_->fetched_google_url().host()); |
| 57 replacements.SetHost(host.data(), url::Component(0, host.length())); | 56 replacements.SetHost(host.data(), url::Component(0, host.length())); |
| 58 new_search_url = search_url_.ReplaceComponents(replacements); | 57 new_search_url = search_url_.ReplaceComponents(replacements); |
| 59 } | 58 } |
| 60 | 59 |
| 61 content::WebContents* contents = | 60 GoogleURLTrackerNavigationHelper* navigation_helper = navigation_helper_; |
| 62 InfoBarService::WebContentsFromInfoBar(infobar()); | |
| 63 infobar()->RemoveSelf(); | 61 infobar()->RemoveSelf(); |
| 64 // WARNING: |this| may be deleted at this point! Do not access any members! | 62 // WARNING: |this| may be deleted at this point! Do not access any members! |
| 65 | 63 |
| 66 if (new_search_url.is_valid()) { | 64 if (new_search_url.is_valid()) |
| 67 contents->OpenURL(content::OpenURLParams( | 65 navigation_helper->OpenURL(new_search_url, CURRENT_TAB, false); |
|
Peter Kasting
2014/05/19 13:59:22
I don't think this is safe.
RemoveSelf() above ca
blundell
2014/05/19 14:06:54
Oof, yes you're right. I'm inclined to go back to
Peter Kasting
2014/05/19 14:16:25
Off-the-cuff ideas, you should second-guess me as
| |
| 68 new_search_url, content::Referrer(), CURRENT_TAB, | |
| 69 content::PAGE_TRANSITION_GENERATED, false)); | |
| 70 } | |
| 71 } | 66 } |
| 72 | 67 |
| 73 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 68 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
| 74 GoogleURLTracker* google_url_tracker, | 69 GoogleURLTracker* google_url_tracker, |
| 70 GoogleURLTrackerNavigationHelper* navigation_helper, | |
| 75 const GURL& search_url) | 71 const GURL& search_url) |
| 76 : ConfirmInfoBarDelegate(), | 72 : ConfirmInfoBarDelegate(), |
| 77 google_url_tracker_(google_url_tracker), | 73 google_url_tracker_(google_url_tracker), |
| 74 navigation_helper_(navigation_helper), | |
| 78 search_url_(search_url), | 75 search_url_(search_url), |
| 79 pending_id_(0) { | 76 pending_id_(0) { |
| 80 } | 77 } |
| 81 | 78 |
| 82 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 79 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
| 83 } | 80 } |
| 84 | 81 |
| 85 base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 82 base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
| 86 return l10n_util::GetStringFUTF16( | 83 return l10n_util::GetStringFUTF16( |
| 87 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, | 84 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, |
| (...skipping 12 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 |