| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/bind.h" | 9 #include "base/bind.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/google/google_util.h" | 15 #include "chrome/browser/google/google_util.h" |
| 16 #include "chrome/browser/infobars/infobar_tab_helper.h" | 16 #include "chrome/browser/infobars/infobar_tab_helper.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 17 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/search_engines/template_url.h" | 18 #include "chrome/browser/search_engines/template_url.h" |
| 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 20 #include "chrome/common/chrome_notification_types.h" | 20 #include "chrome/common/chrome_notification_types.h" |
| 21 #include "chrome/common/chrome_switches.h" | 21 #include "chrome/common/chrome_switches.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "content/browser/tab_contents/navigation_controller.h" | 23 #include "content/browser/tab_contents/navigation_controller.h" |
| 24 #include "content/browser/tab_contents/tab_contents.h" | 24 #include "content/browser/tab_contents/tab_contents.h" |
| 25 #include "content/common/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
| 26 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
| 27 #include "net/base/load_flags.h" | 27 #include "net/base/load_flags.h" |
| 28 #include "net/base/net_util.h" | 28 #include "net/base/net_util.h" |
| 29 #include "net/url_request/url_request_context_getter.h" | 29 #include "net/url_request/url_request_context_getter.h" |
| 30 #include "net/url_request/url_request_status.h" | 30 #include "net/url_request/url_request_status.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 InfoBarDelegate* CreateInfobar(InfoBarTabHelper* infobar_helper, | 35 InfoBarDelegate* CreateInfobar(InfoBarTabHelper* infobar_helper, |
| (...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 | 271 |
| 272 need_to_prompt_ = true; | 272 need_to_prompt_ = true; |
| 273 } | 273 } |
| 274 | 274 |
| 275 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { | 275 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { |
| 276 google_url_ = new_google_url; | 276 google_url_ = new_google_url; |
| 277 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, | 277 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, |
| 278 google_url_.spec()); | 278 google_url_.spec()); |
| 279 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 279 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 280 google_url_.spec()); | 280 google_url_.spec()); |
| 281 NotificationService::current()->Notify( | 281 content::NotificationService::current()->Notify( |
| 282 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, | 282 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
| 283 NotificationService::AllSources(), | 283 content::NotificationService::AllSources(), |
| 284 NotificationService::NoDetails()); | 284 content::NotificationService::NoDetails()); |
| 285 need_to_prompt_ = false; | 285 need_to_prompt_ = false; |
| 286 } | 286 } |
| 287 | 287 |
| 288 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { | 288 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { |
| 289 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 289 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 290 new_google_url.spec()); | 290 new_google_url.spec()); |
| 291 need_to_prompt_ = false; | 291 need_to_prompt_ = false; |
| 292 } | 292 } |
| 293 | 293 |
| 294 void GoogleURLTracker::InfoBarClosed() { | 294 void GoogleURLTracker::InfoBarClosed() { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 void GoogleURLTracker::OnIPAddressChanged() { | 336 void GoogleURLTracker::OnIPAddressChanged() { |
| 337 already_fetched_ = false; | 337 already_fetched_ = false; |
| 338 StartFetchIfDesirable(); | 338 StartFetchIfDesirable(); |
| 339 } | 339 } |
| 340 | 340 |
| 341 void GoogleURLTracker::SearchCommitted() { | 341 void GoogleURLTracker::SearchCommitted() { |
| 342 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { | 342 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { |
| 343 // This notification will fire a bit later in the same call chain we're | 343 // This notification will fire a bit later in the same call chain we're |
| 344 // currently in. | 344 // currently in. |
| 345 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 345 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 346 NotificationService::AllSources()); | 346 content::NotificationService::AllSources()); |
| 347 } | 347 } |
| 348 } | 348 } |
| 349 | 349 |
| 350 void GoogleURLTracker::OnNavigationPending( | 350 void GoogleURLTracker::OnNavigationPending( |
| 351 const content::NotificationSource& source, | 351 const content::NotificationSource& source, |
| 352 const GURL& pending_url) { | 352 const GURL& pending_url) { |
| 353 controller_ = content::Source<NavigationController>(source).ptr(); | 353 controller_ = content::Source<NavigationController>(source).ptr(); |
| 354 search_url_ = pending_url; | 354 search_url_ = pending_url; |
| 355 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 355 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
| 356 NotificationService::AllSources()); | 356 content::NotificationService::AllSources()); |
| 357 // Start listening for the commit notification. We also need to listen for the | 357 // Start listening for the commit notification. We also need to listen for the |
| 358 // tab close command since that means the load will never commit. | 358 // tab close command since that means the load will never commit. |
| 359 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 359 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 360 content::Source<NavigationController>(controller_)); | 360 content::Source<NavigationController>(controller_)); |
| 361 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 361 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
| 362 content::Source<NavigationController>(controller_)); | 362 content::Source<NavigationController>(controller_)); |
| 363 } | 363 } |
| 364 | 364 |
| 365 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( | 365 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( |
| 366 TabContents* tab_contents, | 366 TabContents* tab_contents, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 383 | 383 |
| 384 // |tab_contents| can be NULL during tests. | 384 // |tab_contents| can be NULL during tests. |
| 385 InfoBarTabHelper* infobar_helper = NULL; | 385 InfoBarTabHelper* infobar_helper = NULL; |
| 386 if (tab_contents) { | 386 if (tab_contents) { |
| 387 TabContentsWrapper* wrapper = | 387 TabContentsWrapper* wrapper = |
| 388 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); | 388 TabContentsWrapper::GetCurrentWrapperForContents(tab_contents); |
| 389 infobar_helper = wrapper->infobar_tab_helper(); | 389 infobar_helper = wrapper->infobar_tab_helper(); |
| 390 } | 390 } |
| 391 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); | 391 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); |
| 392 } | 392 } |
| OLD | NEW |