Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(321)

Side by Side Diff: chrome/browser/google/google_url_tracker_infobar_delegate.cc

Issue 190063006: Infobar Componentization Proof of Concept (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: minor fixes Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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.h"
10 #include "chrome/browser/infobars/infobar_service.h" 10 #include "chrome/browser/infobars/infobar_service.h"
11 #include "content/public/browser/navigation_details.h" 11 #include "content/public/browser/navigation_details.h"
12 #include "content/public/browser/navigation_entry.h" 12 #include "content/public/browser/navigation_entry.h"
13 #include "content/public/browser/page_navigator.h" 13 #include "content/public/browser/page_navigator.h"
14 #include "content/public/browser/web_contents.h" 14 #include "content/public/browser/web_contents.h"
15 #include "grit/generated_resources.h" 15 #include "grit/generated_resources.h"
16 #include "net/base/net_util.h" 16 #include "net/base/net_util.h"
17 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
18 18
19 19
20 // static 20 // static
21 InfoBar* GoogleURLTrackerInfoBarDelegate::Create( 21 InfoBar* GoogleURLTrackerInfoBarDelegate::Create(
22 InfoBarService* infobar_service, 22 InfoBarService* infobar_service,
23 GoogleURLTracker* google_url_tracker, 23 GoogleURLTracker* google_url_tracker,
24 const GURL& search_url) { 24 const GURL& search_url) {
25 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar( 25 return infobar_service->AddInfoBar(ConfirmInfoBarDelegate::CreateInfoBar(
26 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate( 26 scoped_ptr<ConfirmInfoBarDelegate>(new GoogleURLTrackerInfoBarDelegate(
27 google_url_tracker, search_url)))); 27 infobar_service->web_contents(), 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 content::NavigationEntry* active_entry =
42 web_contents()->GetController().GetActiveEntry();
43 int entry_id = active_entry ? active_entry->GetUniqueID() : 0;
44 StoreActiveEntryUniqueID(entry_id);
42 search_url_ = search_url; 45 search_url_ = search_url;
43 pending_id_ = 0; 46 pending_id_ = 0;
44 } 47 }
45 48
46 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { 49 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) {
47 // Calling OpenURL() will auto-close us asynchronously. It's easier for 50 // Calling OpenURL() will auto-close us asynchronously. It's easier for
48 // various classes (e.g. GoogleURLTrackerMapEntry) to reason about things if 51 // various classes (e.g. GoogleURLTrackerMapEntry) to reason about things if
49 // the closure always happens synchronously, so we always call RemoveInfoBar() 52 // the closure always happens synchronously, so we always call RemoveInfoBar()
50 // directly, then OpenURL() if desirable. (This calling order is safer if 53 // directly, then OpenURL() if desirable. (This calling order is safer if
51 // for some reason in the future OpenURL() were to close us synchronously.) 54 // for some reason in the future OpenURL() were to close us synchronously.)
(...skipping 12 matching lines...) Expand all
64 // WARNING: |this| may be deleted at this point! Do not access any members! 67 // WARNING: |this| may be deleted at this point! Do not access any members!
65 68
66 if (new_search_url.is_valid()) { 69 if (new_search_url.is_valid()) {
67 contents->OpenURL(content::OpenURLParams( 70 contents->OpenURL(content::OpenURLParams(
68 new_search_url, content::Referrer(), CURRENT_TAB, 71 new_search_url, content::Referrer(), CURRENT_TAB,
69 content::PAGE_TRANSITION_GENERATED, false)); 72 content::PAGE_TRANSITION_GENERATED, false));
70 } 73 }
71 } 74 }
72 75
73 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( 76 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate(
77 content::WebContents* web_contents,
74 GoogleURLTracker* google_url_tracker, 78 GoogleURLTracker* google_url_tracker,
75 const GURL& search_url) 79 const GURL& search_url)
76 : ConfirmInfoBarDelegate(), 80 : ContentConfirmInfoBarDelegate(web_contents),
77 google_url_tracker_(google_url_tracker), 81 google_url_tracker_(google_url_tracker),
78 search_url_(search_url), 82 search_url_(search_url),
79 pending_id_(0) { 83 pending_id_(0) {}
80 }
81 84
82 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { 85 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() {
83 } 86 }
84 87
85 base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { 88 base::string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const {
86 return l10n_util::GetStringFUTF16( 89 return l10n_util::GetStringFUTF16(
87 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, 90 IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE,
88 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()), 91 net::StripWWWFromHost(google_url_tracker_->fetched_google_url()),
89 net::StripWWWFromHost(google_url_tracker_->google_url())); 92 net::StripWWWFromHost(google_url_tracker_->google_url()));
90 } 93 }
(...skipping 20 matching lines...) Expand all
111 google_util::AppendGoogleLocaleParam(GURL( 114 google_util::AppendGoogleLocaleParam(GURL(
112 "https://www.google.com/support/chrome/bin/answer.py?" 115 "https://www.google.com/support/chrome/bin/answer.py?"
113 "answer=1618699")), 116 "answer=1618699")),
114 content::Referrer(), 117 content::Referrer(),
115 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition, 118 (disposition == CURRENT_TAB) ? NEW_FOREGROUND_TAB : disposition,
116 content::PAGE_TRANSITION_LINK, false)); 119 content::PAGE_TRANSITION_LINK, false));
117 return false; 120 return false;
118 } 121 }
119 122
120 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal( 123 bool GoogleURLTrackerInfoBarDelegate::ShouldExpireInternal(
121 const content::LoadCommittedDetails& details) const { 124 const NavigationDetails& details) const {
122 int unique_id = details.entry->GetUniqueID(); 125 return (details.entry_id != contents_unique_id()) &&
123 return (unique_id != contents_unique_id()) && (unique_id != pending_id_); 126 (details.entry_id != pending_id_);
124 } 127 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698