| 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_util.h" | 8 #include "chrome/browser/google/google_util.h" |
| 9 #include "chrome/browser/infobars/infobar.h" | |
| 10 #include "chrome/browser/infobars/infobar_service.h" | 9 #include "chrome/browser/infobars/infobar_service.h" |
| 11 #include "content/public/browser/navigation_details.h" | 10 #include "content/public/browser/navigation_details.h" |
| 12 #include "content/public/browser/navigation_entry.h" | 11 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/browser/page_navigator.h" | 12 #include "content/public/browser/page_navigator.h" |
| 14 #include "content/public/browser/web_contents.h" | 13 #include "content/public/browser/web_contents.h" |
| 15 #include "grit/generated_resources.h" | 14 #include "grit/generated_resources.h" |
| 16 #include "net/base/net_util.h" | 15 #include "net/base/net_util.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 18 | 17 |
| 19 | 18 |
| 20 // static | 19 // static |
| 21 InfoBar* GoogleURLTrackerInfoBarDelegate::Create( | 20 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerInfoBarDelegate::Create( |
| 22 InfoBarService* infobar_service, | 21 InfoBarService* infobar_service, |
| 23 GoogleURLTracker* google_url_tracker, | 22 GoogleURLTracker* google_url_tracker, |
| 24 const GURL& search_url) { | 23 const GURL& search_url) { |
| 25 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( | 24 return static_cast<GoogleURLTrackerInfoBarDelegate*>( |
| 26 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( | 25 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( |
| 27 google_url_tracker, search_url)))); | 26 new GoogleURLTrackerInfoBarDelegate( |
| 27 infobar_service, google_url_tracker, search_url)))); |
| 28 } | 28 } |
| 29 | 29 |
| 30 bool GoogleURLTrackerInfoBarDelegate::Accept() { | 30 bool GoogleURLTrackerInfoBarDelegate::Accept() { |
| 31 google_url_tracker_->AcceptGoogleURL(true); | 31 google_url_tracker_->AcceptGoogleURL(true); |
| 32 return false; | 32 return false; |
| 33 } | 33 } |
| 34 | 34 |
| 35 bool GoogleURLTrackerInfoBarDelegate::Cancel() { | 35 bool GoogleURLTrackerInfoBarDelegate::Cancel() { |
| 36 google_url_tracker_->CancelGoogleURL(); | 36 google_url_tracker_->CancelGoogleURL(); |
| 37 return false; | 37 return false; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 53 if (redo_search) { | 53 if (redo_search) { |
| 54 // Re-do the user's search on the new domain. | 54 // Re-do the user's search on the new domain. |
| 55 DCHECK(search_url_.is_valid()); | 55 DCHECK(search_url_.is_valid()); |
| 56 url_canon::Replacements<char> replacements; | 56 url_canon::Replacements<char> replacements; |
| 57 const std::string& host(google_url_tracker_->fetched_google_url().host()); | 57 const std::string& host(google_url_tracker_->fetched_google_url().host()); |
| 58 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); | 58 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); |
| 59 new_search_url = search_url_.ReplaceComponents(replacements); | 59 new_search_url = search_url_.ReplaceComponents(replacements); |
| 60 } | 60 } |
| 61 | 61 |
| 62 content::WebContents* contents = web_contents(); | 62 content::WebContents* contents = web_contents(); |
| 63 infobar()->RemoveSelf(); | 63 owner()->RemoveInfoBar(this); |
| 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 contents->OpenURL(content::OpenURLParams( |
| 68 new_search_url, content::Referrer(), CURRENT_TAB, | 68 new_search_url, content::Referrer(), CURRENT_TAB, |
| 69 content::PAGE_TRANSITION_GENERATED, false)); | 69 content::PAGE_TRANSITION_GENERATED, false)); |
| 70 } | 70 } |
| 71 } | 71 } |
| 72 | 72 |
| 73 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 73 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
| 74 InfoBarService* infobar_service, |
| 74 GoogleURLTracker* google_url_tracker, | 75 GoogleURLTracker* google_url_tracker, |
| 75 const GURL& search_url) | 76 const GURL& search_url) |
| 76 : ConfirmInfoBarDelegate(), | 77 : ConfirmInfoBarDelegate(infobar_service), |
| 77 google_url_tracker_(google_url_tracker), | 78 google_url_tracker_(google_url_tracker), |
| 78 search_url_(search_url), | 79 search_url_(search_url), |
| 79 pending_id_(0) { | 80 pending_id_(0) { |
| 80 } | 81 } |
| 81 | 82 |
| 82 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 83 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
| 83 } | 84 } |
| 84 | 85 |
| 85 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 86 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
| 86 return l10n_util::GetStringFUTF16( | 87 return l10n_util::GetStringFUTF16( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 115 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 116 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 116 content::PAGE_TRANSITION_LINK, false)); | 117 content::PAGE_TRANSITION_LINK, false)); |
| 117 return false; | 118 return false; |
| 118 } | 119 } |
| 119 | 120 |
| 120 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( | 121 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( |
| 121 const content::LoadCommittedDetails& details) const { | 122 const content::LoadCommittedDetails& details) const { |
| 122 int unique_id = details.entry->GetUniqueID(); | 123 int unique_id = details.entry->GetUniqueID(); |
| 123 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); | 124 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); |
| 124 } | 125 } |
| OLD | NEW |