Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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.h" | 5 #include "chrome/browser/google/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "app/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/prefs/pref_service.h" | 15 #include "chrome/browser/prefs/pref_service.h" |
| 16 #include "chrome/browser/profile.h" | 16 #include "chrome/browser/profile.h" |
| 17 #include "chrome/browser/search_engines/template_url.h" | 17 #include "chrome/browser/search_engines/template_url.h" |
| 18 #include "chrome/browser/tab_contents/navigation_controller.h" | 18 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 19 #include "chrome/browser/tab_contents/tab_contents.h" | 19 #include "chrome/browser/tab_contents/tab_contents.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/net/url_fetcher_protect.h" | 21 #include "chrome/common/net/url_fetcher_protect.h" |
| 22 #include "chrome/common/notification_service.h" | 22 #include "chrome/common/notification_service.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "grit/generated_resources.h" | 24 #include "grit/generated_resources.h" |
| 25 #include "net/base/load_flags.h" | 25 #include "net/base/load_flags.h" |
| 26 #include "net/url_request/url_request_status.h" | 26 #include "net/url_request/url_request_status.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 InfoBarDelegate* CreateInfobar(TabContents* tab_contents, | 30 GoogleURLTrackerInfoBarDelegate* CreateInfobar( |
| 31 GoogleURLTracker* google_url_tracker, | 31 TabContents* tab_contents, |
| 32 const GURL& new_google_url) { | 32 const GURL& search_url, |
| 33 InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(tab_contents, | 33 GoogleURLTracker* google_url_tracker, |
| 34 const GURL& new_google_url) { | |
| 35 return new GoogleURLTrackerInfoBarDelegate(tab_contents, search_url, | |
| 34 google_url_tracker, new_google_url); | 36 google_url_tracker, new_google_url); |
| 35 tab_contents->AddInfoBar(infobar); | |
| 36 return infobar; | |
| 37 } | 37 } |
| 38 | 38 |
| 39 } // namespace | 39 } // namespace |
| 40 | 40 |
| 41 // GoogleURLTrackerInfoBarDelegate -------------------------------------------- | 41 // GoogleURLTrackerInfoBarDelegate -------------------------------------------- |
| 42 | 42 |
| 43 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( | 43 GoogleURLTrackerInfoBarDelegate::GoogleURLTrackerInfoBarDelegate( |
| 44 TabContents* tab_contents, | 44 TabContents* tab_contents, |
| 45 const GURL& search_url, | |
| 45 GoogleURLTracker* google_url_tracker, | 46 GoogleURLTracker* google_url_tracker, |
| 46 const GURL& new_google_url) | 47 const GURL& new_google_url) |
| 47 : ConfirmInfoBarDelegate(tab_contents), | 48 : ConfirmInfoBarDelegate(tab_contents), |
| 49 tab_contents_(tab_contents), | |
| 50 search_url_(search_url), | |
| 48 google_url_tracker_(google_url_tracker), | 51 google_url_tracker_(google_url_tracker), |
| 49 new_google_url_(new_google_url) { | 52 new_google_url_(new_google_url), |
| 53 showing_(false) { | |
| 50 } | 54 } |
| 51 | 55 |
| 52 bool GoogleURLTrackerInfoBarDelegate::Accept() { | 56 bool GoogleURLTrackerInfoBarDelegate::Accept() { |
| 53 google_url_tracker_->AcceptGoogleURL(new_google_url_); | 57 google_url_tracker_->AcceptGoogleURL(new_google_url_); |
| 54 google_url_tracker_->RedoSearch(); | 58 return false; |
| 55 return true; | |
| 56 } | 59 } |
| 57 | 60 |
| 58 bool GoogleURLTrackerInfoBarDelegate::Cancel() { | 61 bool GoogleURLTrackerInfoBarDelegate::Cancel() { |
| 59 google_url_tracker_->CancelGoogleURL(new_google_url_); | 62 google_url_tracker_->CancelGoogleURL(new_google_url_); |
| 60 return true; | 63 return false; |
| 61 } | 64 } |
| 62 | 65 |
| 63 void GoogleURLTrackerInfoBarDelegate::InfoBarClosed() { | 66 void GoogleURLTrackerInfoBarDelegate::InfoBarClosed() { |
| 64 google_url_tracker_->InfoBarClosed(); | 67 if (google_url_tracker_) |
| 68 google_url_tracker_->InfoBarClosed(this, tab_contents_); | |
| 65 delete this; | 69 delete this; |
| 66 } | 70 } |
| 67 | 71 |
| 72 void GoogleURLTrackerInfoBarDelegate::Show() { | |
| 73 tab_contents_->AddInfoBar(this); | |
| 74 showing_ = true; | |
| 75 } | |
| 76 | |
| 77 void GoogleURLTrackerInfoBarDelegate::Close(bool redo_search) { | |
| 78 if (!showing_) { | |
| 79 // We haven't been added to a tab, so just delete ourselves. | |
| 80 InfoBarClosed(); | |
| 81 return; | |
| 82 } | |
| 83 | |
| 84 if (redo_search) { | |
| 85 // Re-do the user's search on the new domain. | |
| 86 url_canon::Replacements<char> replacements; | |
| 87 const std::string& host(new_google_url_.host()); | |
| 88 replacements.SetHost(host.data(), url_parse::Component(0, host.length())); | |
| 89 GURL new_search_url(search_url_.ReplaceComponents(replacements)); | |
| 90 if (new_search_url.is_valid()) { | |
| 91 tab_contents_->OpenURL(new_search_url, GURL(), CURRENT_TAB, | |
| 92 PageTransition::GENERATED); | |
| 93 } | |
| 94 } | |
| 95 | |
| 96 // Synchronously remove ourselves from the URL tracker's list, because the | |
| 97 // RemoveInfoBar() call below may result in either a synchronous or an | |
| 98 // asynchronous call back to InfoBarClosed(), and it's easier to handle when | |
| 99 // we just guarantee the removal is synchronous. | |
| 100 google_url_tracker_->InfoBarClosed(this, tab_contents_); | |
| 101 google_url_tracker_ = NULL; | |
| 102 | |
| 103 tab_contents_->RemoveInfoBar(this); | |
| 104 } | |
| 105 | |
| 68 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { | 106 GoogleURLTrackerInfoBarDelegate::~GoogleURLTrackerInfoBarDelegate() { |
| 69 } | 107 } |
| 70 | 108 |
| 71 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { | 109 string16 GoogleURLTrackerInfoBarDelegate::GetMessageText() const { |
| 72 // TODO(ukai): change new_google_url to google_base_domain? | 110 // Strip the "www." off the hostname since it's just noise. This should |
| 111 // always be present since we added it in OnURLFetchComplete(). | |
| 112 std::string host(new_google_url_.host()); | |
| 113 DCHECK(StartsWithASCII(host, "www.", true)); | |
| 73 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, | 114 return l10n_util::GetStringFUTF16(IDS_GOOGLE_URL_TRACKER_INFOBAR_MESSAGE, |
| 74 UTF8ToUTF16(new_google_url_.spec())); | 115 UTF8ToUTF16(host.substr(4))); |
| 75 } | 116 } |
| 76 | 117 |
| 77 int GoogleURLTrackerInfoBarDelegate::GetButtons() const { | 118 int GoogleURLTrackerInfoBarDelegate::GetButtons() const { |
| 78 return BUTTON_OK | BUTTON_CANCEL; | 119 return BUTTON_OK | BUTTON_CANCEL; |
| 79 } | 120 } |
| 80 | 121 |
| 81 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( | 122 string16 GoogleURLTrackerInfoBarDelegate::GetButtonLabel( |
| 82 InfoBarButton button) const { | 123 InfoBarButton button) const { |
| 83 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 124 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? |
| 84 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL : | 125 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL : |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 97 : infobar_creator_(&CreateInfobar), | 138 : infobar_creator_(&CreateInfobar), |
| 98 google_url_(g_browser_process->local_state()->GetString( | 139 google_url_(g_browser_process->local_state()->GetString( |
| 99 prefs::kLastKnownGoogleURL)), | 140 prefs::kLastKnownGoogleURL)), |
| 100 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), | 141 ALLOW_THIS_IN_INITIALIZER_LIST(runnable_method_factory_(this)), |
| 101 fetcher_id_(0), | 142 fetcher_id_(0), |
| 102 queue_wakeup_task_(true), | 143 queue_wakeup_task_(true), |
| 103 in_startup_sleep_(true), | 144 in_startup_sleep_(true), |
| 104 already_fetched_(false), | 145 already_fetched_(false), |
| 105 need_to_fetch_(false), | 146 need_to_fetch_(false), |
| 106 request_context_available_(!!Profile::GetDefaultRequestContext()), | 147 request_context_available_(!!Profile::GetDefaultRequestContext()), |
| 107 need_to_prompt_(false), | 148 need_to_prompt_(false) { |
| 108 controller_(NULL), | 149 if (!request_context_available_) { |
| 109 infobar_(NULL) { | 150 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 110 registrar_.Add(this, NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 151 NotificationService::AllSources()); |
| 111 NotificationService::AllSources()); | 152 } |
| 112 | 153 |
| 113 net::NetworkChangeNotifier::AddObserver(this); | 154 net::NetworkChangeNotifier::AddObserver(this); |
| 114 | 155 |
| 115 // Configure to max_retries at most kMaxRetries times for 5xx errors. | 156 // Configure to max_retries at most kMaxRetries times for 5xx errors. |
| 116 URLFetcherProtectEntry* protect = | 157 URLFetcherProtectEntry* protect = |
| 117 URLFetcherProtectManager::GetInstance()->Register( | 158 URLFetcherProtectManager::GetInstance()->Register( |
| 118 GURL(kSearchDomainCheckURL).host()); | 159 GURL(kSearchDomainCheckURL).host()); |
| 119 static const int kMaxRetries = 5; | 160 static const int kMaxRetries = 5; |
| 120 protect->SetMaxRetries(kMaxRetries); | 161 protect->SetMaxRetries(kMaxRetries); |
| 121 | 162 |
| 122 MessageLoop::current()->PostTask(FROM_HERE, | 163 MessageLoop::current()->PostTask(FROM_HERE, |
| 123 runnable_method_factory_.NewRunnableMethod( | 164 runnable_method_factory_.NewRunnableMethod( |
| 124 &GoogleURLTracker::QueueWakeupTask)); | 165 &GoogleURLTracker::QueueWakeupTask)); |
| 125 } | 166 } |
| 126 | 167 |
| 127 GoogleURLTracker::~GoogleURLTracker() { | 168 GoogleURLTracker::~GoogleURLTracker() { |
| 128 runnable_method_factory_.RevokeAll(); | 169 runnable_method_factory_.RevokeAll(); |
| 129 net::NetworkChangeNotifier::RemoveObserver(this); | 170 net::NetworkChangeNotifier::RemoveObserver(this); |
| 171 // We should only reach here after any tabs and their infobars have been torn | |
| 172 // down. | |
| 173 DCHECK(infobars_.empty()); | |
| 130 } | 174 } |
| 131 | 175 |
| 132 // static | 176 // static |
| 133 GURL GoogleURLTracker::GoogleURL() { | 177 GURL GoogleURLTracker::GoogleURL() { |
| 134 const GoogleURLTracker* const tracker = | 178 const GoogleURLTracker* const tracker = |
| 135 g_browser_process->google_url_tracker(); | 179 g_browser_process->google_url_tracker(); |
| 136 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage); | 180 return tracker ? tracker->google_url_ : GURL(kDefaultGoogleHomepage); |
| 137 } | 181 } |
| 138 | 182 |
| 139 // static | 183 // static |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 std::string url_str; | 278 std::string url_str; |
| 235 TrimWhitespace(data, TRIM_ALL, &url_str); | 279 TrimWhitespace(data, TRIM_ALL, &url_str); |
| 236 | 280 |
| 237 if (!StartsWithASCII(url_str, ".google.", false)) | 281 if (!StartsWithASCII(url_str, ".google.", false)) |
| 238 return; | 282 return; |
| 239 | 283 |
| 240 fetched_google_url_ = GURL("http://www" + url_str); | 284 fetched_google_url_ = GURL("http://www" + url_str); |
| 241 GURL last_prompted_url( | 285 GURL last_prompted_url( |
| 242 g_browser_process->local_state()->GetString( | 286 g_browser_process->local_state()->GetString( |
| 243 prefs::kLastPromptedGoogleURL)); | 287 prefs::kLastPromptedGoogleURL)); |
| 244 need_to_prompt_ = false; | |
| 245 | 288 |
| 246 if (last_prompted_url.is_empty()) { | 289 if (last_prompted_url.is_empty()) { |
| 247 // On the very first run of Chrome, when we've never looked up the URL at | 290 // On the very first run of Chrome, when we've never looked up the URL at |
| 248 // all, we should just silently switch over to whatever we get immediately. | 291 // all, we should just silently switch over to whatever we get immediately. |
| 249 AcceptGoogleURL(fetched_google_url_); | 292 AcceptGoogleURL(fetched_google_url_); |
| 250 return; | 293 return; |
| 251 } | 294 } |
| 252 | 295 |
| 253 // If the URL hasn't changed, then whether |need_to_prompt_| is true or false, | 296 // If the URL hasn't changed, then whether |need_to_prompt_| is true or false, |
| 254 // nothing has changed, so just bail. | 297 // nothing has changed, so just bail. |
| 255 if (fetched_google_url_ == last_prompted_url) | 298 if (fetched_google_url_ == last_prompted_url) |
| 256 return; | 299 return; |
| 257 | 300 |
| 258 if (fetched_google_url_ == google_url_) { | 301 if (fetched_google_url_ == google_url_) { |
| 259 // The user came back to their original location after having temporarily | 302 // The user came back to their original location after having temporarily |
| 260 // moved. Reset the prompted URL so we'll prompt again if they move again. | 303 // moved. Reset the prompted URL so we'll prompt again if they move again. |
| 261 CancelGoogleURL(fetched_google_url_); | 304 CancelGoogleURL(fetched_google_url_); |
| 262 return; | 305 return; |
| 263 } | 306 } |
| 264 | 307 |
| 265 need_to_prompt_ = true; | 308 need_to_prompt_ = true; |
| 309 | |
| 310 // Any open infobars are pointing at the wrong Google URL. (This can happen | |
| 311 // if an infobar has been sitting open and then our IP address changes.) | |
| 312 CloseAllInfobars(false); | |
| 266 } | 313 } |
| 267 | 314 |
| 268 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { | 315 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { |
| 269 google_url_ = new_google_url; | 316 google_url_ = new_google_url; |
| 270 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, | 317 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, |
| 271 google_url_.spec()); | 318 google_url_.spec()); |
| 272 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 319 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 273 google_url_.spec()); | 320 google_url_.spec()); |
| 274 NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, | 321 NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, |
| 275 NotificationService::AllSources(), | 322 NotificationService::AllSources(), |
| 276 NotificationService::NoDetails()); | 323 NotificationService::NoDetails()); |
| 277 need_to_prompt_ = false; | 324 need_to_prompt_ = false; |
| 325 CloseAllInfobars(true); | |
| 278 } | 326 } |
| 279 | 327 |
| 280 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { | 328 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { |
| 281 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 329 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 282 new_google_url.spec()); | 330 new_google_url.spec()); |
| 331 need_to_prompt_ = false; | |
| 332 CloseAllInfobars(false); | |
| 283 } | 333 } |
| 284 | 334 |
| 285 void GoogleURLTracker::InfoBarClosed() { | 335 void GoogleURLTracker::InfoBarClosed(GoogleURLTrackerInfoBarDelegate* infobar, |
| 286 registrar_.RemoveAll(); | 336 TabContents* tab_contents) { |
| 287 controller_ = NULL; | 337 Infobars::iterator i(infobars_.find(tab_contents)); |
| 288 infobar_ = NULL; | 338 if ((i != infobars_.end()) && (i->second == infobar)) |
| 289 search_url_ = GURL(); | 339 infobars_.erase(i); |
| 290 } | |
| 291 | |
| 292 void GoogleURLTracker::RedoSearch() { | |
| 293 // Re-do the user's search on the new domain. | |
| 294 DCHECK(controller_); | |
| 295 url_canon::Replacements<char> replacements; | |
| 296 replacements.SetHost(google_url_.host().data(), | |
| 297 url_parse::Component(0, google_url_.host().length())); | |
| 298 GURL new_search_url(search_url_.ReplaceComponents(replacements)); | |
| 299 if (new_search_url.is_valid()) | |
| 300 controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB, | |
| 301 PageTransition::GENERATED); | |
| 302 } | 340 } |
| 303 | 341 |
| 304 void GoogleURLTracker::Observe(NotificationType type, | 342 void GoogleURLTracker::Observe(NotificationType type, |
| 305 const NotificationSource& source, | 343 const NotificationSource& source, |
| 306 const NotificationDetails& details) { | 344 const NotificationDetails& details) { |
| 307 switch (type.value) { | 345 switch (type.value) { |
| 308 case NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE: | 346 case NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE: |
| 309 registrar_.Remove(this, | 347 registrar_.Remove(this, |
| 310 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, | 348 NotificationType::DEFAULT_REQUEST_CONTEXT_AVAILABLE, |
| 311 NotificationService::AllSources()); | 349 NotificationService::AllSources()); |
| 312 request_context_available_ = true; | 350 request_context_available_ = true; |
| 313 StartFetchIfDesirable(); | 351 StartFetchIfDesirable(); |
| 314 break; | 352 break; |
| 315 | 353 |
| 316 case NotificationType::NAV_ENTRY_PENDING: | 354 case NotificationType::NAV_ENTRY_PENDING: { |
| 317 OnNavigationPending(source, controller_->pending_entry()->url()); | 355 NavigationController* controller = |
| 356 Source<NavigationController>(source).ptr(); | |
| 357 OnNavigationPending(source, controller->tab_contents(), | |
| 358 controller->pending_entry()->url()); | |
| 318 break; | 359 break; |
| 360 } | |
| 319 | 361 |
| 320 case NotificationType::NAV_ENTRY_COMMITTED: | 362 case NotificationType::NAV_ENTRY_COMMITTED: |
| 321 case NotificationType::TAB_CLOSED: | 363 case NotificationType::TAB_CLOSED: |
| 322 OnNavigationCommittedOrTabClosed( | 364 OnNavigationCommittedOrTabClosed(source, |
| 323 Source<NavigationController>(source).ptr()->tab_contents(), | 365 Source<NavigationController>(source).ptr()->tab_contents(), |
| 324 type.value); | 366 type.value); |
| 325 break; | 367 break; |
| 326 | 368 |
| 327 default: | 369 default: |
| 328 NOTREACHED() << "Unknown notification received:" << type.value; | 370 NOTREACHED() << "Unknown notification received:" << type.value; |
| 329 } | 371 } |
| 330 } | 372 } |
| 331 | 373 |
| 332 void GoogleURLTracker::OnIPAddressChanged() { | 374 void GoogleURLTracker::OnIPAddressChanged() { |
| 333 already_fetched_ = false; | 375 already_fetched_ = false; |
| 334 StartFetchIfDesirable(); | 376 StartFetchIfDesirable(); |
| 335 } | 377 } |
| 336 | 378 |
| 337 void GoogleURLTracker::SearchCommitted() { | 379 void GoogleURLTracker::SearchCommitted() { |
| 338 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { | 380 if (need_to_prompt_) { |
| 339 // This notification will fire a bit later in the same call chain we're | 381 // This notification will fire a bit later in the same call chain we're |
| 340 // currently in. | 382 // currently in. |
| 341 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 383 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, |
| 342 NotificationService::AllSources()); | 384 NotificationService::AllSources()); |
| 343 } | 385 } |
| 344 } | 386 } |
| 345 | 387 |
| 346 void GoogleURLTracker::OnNavigationPending(const NotificationSource& source, | 388 void GoogleURLTracker::OnNavigationPending(const NotificationSource& source, |
| 389 TabContents* tab_contents, | |
| 347 const GURL& pending_url) { | 390 const GURL& pending_url) { |
| 348 controller_ = Source<NavigationController>(source).ptr(); | |
| 349 search_url_ = pending_url; | |
| 350 registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING, | 391 registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING, |
| 351 NotificationService::AllSources()); | 392 NotificationService::AllSources()); |
| 352 // Start listening for the commit notification. We also need to listen for the | 393 |
| 353 // tab close command since that means the load will never commit. | 394 if (registrar_.IsRegistered(this, NotificationType::TAB_CLOSED, source)) { |
| 354 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 395 // If the previous load hasn't committed and the user triggers a new load, |
| 355 Source<NavigationController>(controller_)); | 396 // we don't need to re-register our listeners; just kill the old, |
| 356 registrar_.Add(this, NotificationType::TAB_CLOSED, | 397 // never-shown infobar (to be replaced by a new one below). |
| 357 Source<NavigationController>(controller_)); | 398 Infobars::iterator i(infobars_.find(tab_contents)); |
| 399 DCHECK(i != infobars_.end()); | |
| 400 i->second->Close(false); | |
| 401 } else { | |
| 402 // Start listening for the commit notification. We also need to listen for | |
| 403 // the tab close command since that means the load will never commit. Note | |
| 404 // that in this case we don't need to close any previous infobar for this | |
| 405 // TabContents since this navigation will close it. | |
| 406 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, source); | |
| 407 registrar_.Add(this, NotificationType::TAB_CLOSED, source); | |
| 408 } | |
| 409 | |
| 410 infobars_[tab_contents] = | |
| 411 (*infobar_creator_)(tab_contents, pending_url, this, fetched_google_url_); | |
| 358 } | 412 } |
| 359 | 413 |
| 360 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( | 414 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( |
| 415 const NotificationSource& source, | |
| 361 TabContents* tab_contents, | 416 TabContents* tab_contents, |
| 362 NotificationType::Type type) { | 417 NotificationType::Type type) { |
| 363 registrar_.RemoveAll(); | 418 registrar_.Remove(this, NotificationType::NAV_ENTRY_COMMITTED, source); |
| 419 registrar_.Remove(this, NotificationType::TAB_CLOSED, source); | |
| 364 | 420 |
| 365 if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 421 Infobars::iterator i(infobars_.find(tab_contents)); |
| 366 ShowGoogleURLInfoBarIfNecessary(tab_contents); | 422 DCHECK(i != infobars_.end()); |
| 367 } else { | 423 DCHECK(need_to_prompt_); |
|
Ilya Sherman
2010/11/16 00:17:47
Why does |need_to_prompt_| have to be true?
Suppo
Peter Kasting
2010/11/16 00:38:23
Talked over this in person to ensure both of us th
| |
| 368 controller_ = NULL; | 424 if (type == NotificationType::NAV_ENTRY_COMMITTED) |
| 369 infobar_ = NULL; | 425 i->second->Show(); |
| 370 } | 426 else |
| 427 i->second->Close(false); // Close manually since it's not added to a tab. | |
| 371 } | 428 } |
| 372 | 429 |
| 373 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( | 430 void GoogleURLTracker::CloseAllInfobars(bool redo_searches) { |
| 374 TabContents* tab_contents) { | 431 // Close all infobars, whether they've been added to tabs or not. |
| 375 if (!need_to_prompt_) | 432 while (!infobars_.empty()) |
| 376 return; | 433 infobars_.begin()->second->Close(redo_searches); |
| 377 DCHECK(!fetched_google_url_.is_empty()); | |
| 378 | 434 |
| 379 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); | 435 // Any registered listeners for NAV_ENTRY_COMMITTED and TAB_CLOSED are now |
| 436 // irrelevant as the associated infobars are gone. | |
| 437 registrar_.RemoveAll(); | |
| 438 // We can't have had a listener for DEFAULT_REQUEST_CONTEXT_AVAILABLE, or we | |
| 439 // could never have triggered the search domain check and thus couldn't have | |
| 440 // reached here. | |
| 441 DCHECK(request_context_available_); | |
| 380 } | 442 } |
| OLD | NEW |