| 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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/prefs/pref_service.h" | 14 #include "chrome/browser/prefs/pref_service.h" |
| 15 #include "chrome/browser/search_engines/template_url.h" | 15 #include "chrome/browser/search_engines/template_url.h" |
| 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" | 16 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 17 #include "chrome/common/chrome_notification_types.h" |
| 17 #include "chrome/common/chrome_switches.h" | 18 #include "chrome/common/chrome_switches.h" |
| 18 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
| 19 #include "content/browser/tab_contents/navigation_controller.h" | 20 #include "content/browser/tab_contents/navigation_controller.h" |
| 20 #include "content/common/notification_service.h" | 21 #include "content/common/notification_service.h" |
| 21 #include "grit/generated_resources.h" | 22 #include "grit/generated_resources.h" |
| 22 #include "net/base/load_flags.h" | 23 #include "net/base/load_flags.h" |
| 23 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
| 24 #include "net/url_request/url_request_status.h" | 25 #include "net/url_request/url_request_status.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 26 #include "ui/base/l10n/l10n_util.h" |
| 26 | 27 |
| (...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 | 251 |
| 251 need_to_prompt_ = true; | 252 need_to_prompt_ = true; |
| 252 } | 253 } |
| 253 | 254 |
| 254 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { | 255 void GoogleURLTracker::AcceptGoogleURL(const GURL& new_google_url) { |
| 255 google_url_ = new_google_url; | 256 google_url_ = new_google_url; |
| 256 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, | 257 g_browser_process->local_state()->SetString(prefs::kLastKnownGoogleURL, |
| 257 google_url_.spec()); | 258 google_url_.spec()); |
| 258 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 259 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 259 google_url_.spec()); | 260 google_url_.spec()); |
| 260 NotificationService::current()->Notify(NotificationType::GOOGLE_URL_UPDATED, | 261 NotificationService::current()->Notify(chrome::GOOGLE_URL_UPDATED, |
| 261 NotificationService::AllSources(), | 262 NotificationService::AllSources(), |
| 262 NotificationService::NoDetails()); | 263 NotificationService::NoDetails()); |
| 263 need_to_prompt_ = false; | 264 need_to_prompt_ = false; |
| 264 } | 265 } |
| 265 | 266 |
| 266 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { | 267 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { |
| 267 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 268 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
| 268 new_google_url.spec()); | 269 new_google_url.spec()); |
| 269 need_to_prompt_ = false; | 270 need_to_prompt_ = false; |
| 270 } | 271 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 // Start listening for the commit notification. We also need to listen for the | 335 // Start listening for the commit notification. We also need to listen for the |
| 335 // tab close command since that means the load will never commit. | 336 // tab close command since that means the load will never commit. |
| 336 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 337 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, |
| 337 Source<NavigationController>(controller_)); | 338 Source<NavigationController>(controller_)); |
| 338 registrar_.Add(this, NotificationType::TAB_CLOSED, | 339 registrar_.Add(this, NotificationType::TAB_CLOSED, |
| 339 Source<NavigationController>(controller_)); | 340 Source<NavigationController>(controller_)); |
| 340 } | 341 } |
| 341 | 342 |
| 342 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( | 343 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( |
| 343 TabContents* tab_contents, | 344 TabContents* tab_contents, |
| 344 NotificationType::Type type) { | 345 int type) { |
| 345 registrar_.RemoveAll(); | 346 registrar_.RemoveAll(); |
| 346 | 347 |
| 347 if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 348 if (type == NotificationType::NAV_ENTRY_COMMITTED) { |
| 348 ShowGoogleURLInfoBarIfNecessary(tab_contents); | 349 ShowGoogleURLInfoBarIfNecessary(tab_contents); |
| 349 } else { | 350 } else { |
| 350 controller_ = NULL; | 351 controller_ = NULL; |
| 351 infobar_ = NULL; | 352 infobar_ = NULL; |
| 352 } | 353 } |
| 353 } | 354 } |
| 354 | 355 |
| 355 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( | 356 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( |
| 356 TabContents* tab_contents) { | 357 TabContents* tab_contents) { |
| 357 if (!need_to_prompt_) | 358 if (!need_to_prompt_) |
| 358 return; | 359 return; |
| 359 DCHECK(!fetched_google_url_.is_empty()); | 360 DCHECK(!fetched_google_url_.is_empty()); |
| 360 | 361 |
| 361 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); | 362 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); |
| 362 } | 363 } |
| OLD | NEW |