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; |
(...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 owner()->RemoveInfoBar(this); | 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 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, | |
75 GoogleURLTracker* google_url_tracker, | 74 GoogleURLTracker* google_url_tracker, |
76 const GURL& search_url) | 75 const GURL& search_url) |
77 : ConfirmInfoBarDelegate(infobar_service), | 76 : ConfirmInfoBarDelegate(), |
78 google_url_tracker_(google_url_tracker), | 77 google_url_tracker_(google_url_tracker), |
79 search_url_(search_url), | 78 search_url_(search_url), |
80 pending_id_(0) { | 79 pending_id_(0) { |
81 } | 80 } |
82 | 81 |
83 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 82 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
84 } | 83 } |
85 | 84 |
86 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 85 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
87 return l10n_util::GetStringFUTF16( | 86 return l10n_util::GetStringFUTF16( |
(...skipping 28 matching lines...) Expand all Loading... |
116 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, | 115 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, |
117 content::PAGE_TRANSITION_LINK, false)); | 116 content::PAGE_TRANSITION_LINK, false)); |
118 return false; | 117 return false; |
119 } | 118 } |
120 | 119 |
121 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( | 120 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( |
122 const content::LoadCommittedDetails& details) const { | 121 const content::LoadCommittedDetails& details) const { |
123 int unique_id = details.entry->GetUniqueID(); | 122 int unique_id = details.entry->GetUniqueID(); |
124 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); | 123 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); |
125 } | 124 } |
OLD | NEW |