| 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" |
| 9 #include "chrome/browser/infobars/infobar_service.h" | 10 #include "chrome/browser/infobars/infobar_service.h" |
| 10 #include "content/public/browser/navigation_details.h" | 11 #include "content/public/browser/navigation_details.h" |
| 11 #include "content/public/browser/navigation_entry.h" | 12 #include "content/public/browser/navigation_entry.h" |
| 12 #include "content/public/browser/page_navigator.h" | 13 #include "content/public/browser/page_navigator.h" |
| 13 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
| 14 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 15 #include "net/base/net_util.h" | 16 #include "net/base/net_util.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 17 | 18 |
| 18 | 19 |
| 19 // static | 20 // static |
| 20 GoogleURLTrackerInfoBarDelegate* GoogleURLTrackerInfoBarDelegate::Create( | 21 InfoBar* GoogleURLTrackerInfoBarDelegate::Create( |
| 21 InfoBarService* infobar_service, | 22 InfoBarService* infobar_service, |
| 22 GoogleURLTracker* google_url_tracker, | 23 GoogleURLTracker* google_url_tracker, |
| 23 const GURL& search_url) { | 24 const GURL& search_url) { |
| 24 return static_cast<GoogleURLTrackerInfoBarDelegate*>( | 25 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( |
| 25 infobar_service->AddInfoBar(scoped_ptr<InfoBarDelegate>( | 26 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( |
| 26 new GoogleURLTrackerInfoBarDelegate( | 27 google_url_tracker, search_url)))); |
| 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; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) { | 40 void GoogleURLTrackerInfoBarDelegate::Update(const GURL& search_url) { |
| 41 StoreActiveEntryUniqueID(); | 41 StoreActiveEntryUniqueID(); |
| 42 search_url_ = search_url; | 42 search_url_ = search_url; |
| 43 pending_id_ = 0; | 43 pending_id_ = 0; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { | 46 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { |
| 47 // It's not obvious whether calling OpenURL() with a search URL would | 47 // It's not obvious whether calling OpenURL() with a search URL would |
| 48 // auto-close us or not. If it did, we wouldn't want to try to | 48 // auto-close us or not. If it did, we wouldn't want to try to RemoveSelf() |
| 49 // RemoveInfoBar() afterwards. So for safety, we always call RemoveInfoBar() | 49 // afterwards. So for safety, we always call RemoveSelf() directly, and then |
| 50 // directly, and then navigate if necessary afterwards. | 50 // navigate if necessary afterwards. |
| 51 GURL new_search_url; | 51 GURL new_search_url; |
| 52 if (redo_search) { | 52 if (redo_search) { |
| 53 // Re-do the user's search on the new domain. | 53 // Re-do the user's search on the new domain. |
| 54 DCHECK(search_url_.is_valid()); | 54 DCHECK(search_url_.is_valid()); |
| 55 url_canon::Replacements<char> replacements; | 55 url_canon::Replacements<char> replacements; |
| 56 const std::string& host(google_url_tracker_->fetched_google_url().host()); | 56 const std::string& host(google_url_tracker_->fetched_google_url().host()); |
| 57 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); | 57 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); |
| 58 new_search_url = search_url_.ReplaceComponents(replacements); | 58 new_search_url = search_url_.ReplaceComponents(replacements); |
| 59 } | 59 } |
| 60 | 60 |
| 61 content::WebContents* contents = web_contents(); | 61 content::WebContents* contents = web_contents(); |
| 62 owner()->RemoveInfoBar(this); | 62 infobar()->RemoveSelf(); |
| 63 // WARNING: |this| may be deleted at this point! Do not access any members! | 63 // WARNING: |this| may be deleted at this point! Do not access any members! |
| 64 | 64 |
| 65 if (new_search_url.is_valid()) { | 65 if (new_search_url.is_valid()) { |
| 66 contents->OpenURL(content::OpenURLParams( | 66 contents->OpenURL(content::OpenURLParams( |
| 67 new_search_url, content::Referrer(), CURRENT_TAB, | 67 new_search_url, content::Referrer(), CURRENT_TAB, |
| 68 content::PAGE_TRANSITION_GENERATED, false)); | 68 content::PAGE_TRANSITION_GENERATED, false)); |
| 69 } | 69 } |
| 70 } | 70 } |
| 71 | 71 |
| 72 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 72 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
| 73 InfoBarService* infobar_service, | |
| 74 GoogleURLTracker* google_url_tracker, | 73 GoogleURLTracker* google_url_tracker, |
| 75 const GURL& search_url) | 74 const GURL& search_url) |
| 76 : ConfirmInfoBarDelegate(infobar_service), | 75 : ConfirmInfoBarDelegate(), |
| 77 google_url_tracker_(google_url_tracker), | 76 google_url_tracker_(google_url_tracker), |
| 78 search_url_(search_url), | 77 search_url_(search_url), |
| 79 pending_id_(0) { | 78 pending_id_(0) { |
| 80 } | 79 } |
| 81 | 80 |
| 82 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 81 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
| 83 } | 82 } |
| 84 | 83 |
| 85 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 84 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
| 86 return l10n_util::GetStringFUTF16( | 85 return l10n_util::GetStringFUTF16( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 115 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 114 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
| 116 content::PAGE_TRANSITION_LINK, false)); | 115 content::PAGE_TRANSITION_LINK, false)); |
| 117 return false; | 116 return false; |
| 118 } | 117 } |
| 119 | 118 |
| 120 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( | 119 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( |
| 121 const content::LoadCommittedDetails& details) const { | 120 const content::LoadCommittedDetails& details) const { |
| 122 int unique_id = details.entry->GetUniqueID(); | 121 int unique_id = details.entry->GetUniqueID(); |
| 123 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); | 122 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); |
| 124 } | 123 } |
| OLD | NEW |