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( |
261 NotificationService::AllSources(), | 262 chrome::NOTIFICATION_GOOGLE_URL_UPDATED, |
262 NotificationService::NoDetails()); | 263 NotificationService::AllSources(), |
| 264 NotificationService::NoDetails()); |
263 need_to_prompt_ = false; | 265 need_to_prompt_ = false; |
264 } | 266 } |
265 | 267 |
266 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { | 268 void GoogleURLTracker::CancelGoogleURL(const GURL& new_google_url) { |
267 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, | 269 g_browser_process->local_state()->SetString(prefs::kLastPromptedGoogleURL, |
268 new_google_url.spec()); | 270 new_google_url.spec()); |
269 need_to_prompt_ = false; | 271 need_to_prompt_ = false; |
270 } | 272 } |
271 | 273 |
272 void GoogleURLTracker::InfoBarClosed() { | 274 void GoogleURLTracker::InfoBarClosed() { |
273 registrar_.RemoveAll(); | 275 registrar_.RemoveAll(); |
274 controller_ = NULL; | 276 controller_ = NULL; |
275 infobar_ = NULL; | 277 infobar_ = NULL; |
276 search_url_ = GURL(); | 278 search_url_ = GURL(); |
277 } | 279 } |
278 | 280 |
279 void GoogleURLTracker::RedoSearch() { | 281 void GoogleURLTracker::RedoSearch() { |
280 // Re-do the user's search on the new domain. | 282 // Re-do the user's search on the new domain. |
281 DCHECK(controller_); | 283 DCHECK(controller_); |
282 url_canon::Replacements<char> replacements; | 284 url_canon::Replacements<char> replacements; |
283 replacements.SetHost(google_url_.host().data(), | 285 replacements.SetHost(google_url_.host().data(), |
284 url_parse::Component(0, google_url_.host().length())); | 286 url_parse::Component(0, google_url_.host().length())); |
285 GURL new_search_url(search_url_.ReplaceComponents(replacements)); | 287 GURL new_search_url(search_url_.ReplaceComponents(replacements)); |
286 if (new_search_url.is_valid()) | 288 if (new_search_url.is_valid()) |
287 controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB, | 289 controller_->tab_contents()->OpenURL(new_search_url, GURL(), CURRENT_TAB, |
288 PageTransition::GENERATED); | 290 PageTransition::GENERATED); |
289 } | 291 } |
290 | 292 |
291 void GoogleURLTracker::Observe(NotificationType type, | 293 void GoogleURLTracker::Observe(int type, |
292 const NotificationSource& source, | 294 const NotificationSource& source, |
293 const NotificationDetails& details) { | 295 const NotificationDetails& details) { |
294 switch (type.value) { | 296 switch (type) { |
295 case NotificationType::NAV_ENTRY_PENDING: { | 297 case content::NOTIFICATION_NAV_ENTRY_PENDING: { |
296 NavigationController* controller = | 298 NavigationController* controller = |
297 Source<NavigationController>(source).ptr(); | 299 Source<NavigationController>(source).ptr(); |
298 OnNavigationPending(source, controller->pending_entry()->url()); | 300 OnNavigationPending(source, controller->pending_entry()->url()); |
299 break; | 301 break; |
300 } | 302 } |
301 | 303 |
302 case NotificationType::NAV_ENTRY_COMMITTED: | 304 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
303 case NotificationType::TAB_CLOSED: | 305 case content::NOTIFICATION_TAB_CLOSED: |
304 OnNavigationCommittedOrTabClosed( | 306 OnNavigationCommittedOrTabClosed( |
305 Source<NavigationController>(source).ptr()->tab_contents(), | 307 Source<NavigationController>(source).ptr()->tab_contents(), |
306 type.value); | 308 type); |
307 break; | 309 break; |
308 | 310 |
309 default: | 311 default: |
310 NOTREACHED() << "Unknown notification received:" << type.value; | 312 NOTREACHED() << "Unknown notification received:" << type; |
311 } | 313 } |
312 } | 314 } |
313 | 315 |
314 void GoogleURLTracker::OnIPAddressChanged() { | 316 void GoogleURLTracker::OnIPAddressChanged() { |
315 already_fetched_ = false; | 317 already_fetched_ = false; |
316 StartFetchIfDesirable(); | 318 StartFetchIfDesirable(); |
317 } | 319 } |
318 | 320 |
319 void GoogleURLTracker::SearchCommitted() { | 321 void GoogleURLTracker::SearchCommitted() { |
320 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { | 322 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { |
321 // This notification will fire a bit later in the same call chain we're | 323 // This notification will fire a bit later in the same call chain we're |
322 // currently in. | 324 // currently in. |
323 registrar_.Add(this, NotificationType::NAV_ENTRY_PENDING, | 325 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
324 NotificationService::AllSources()); | 326 NotificationService::AllSources()); |
325 } | 327 } |
326 } | 328 } |
327 | 329 |
328 void GoogleURLTracker::OnNavigationPending(const NotificationSource& source, | 330 void GoogleURLTracker::OnNavigationPending(const NotificationSource& source, |
329 const GURL& pending_url) { | 331 const GURL& pending_url) { |
330 controller_ = Source<NavigationController>(source).ptr(); | 332 controller_ = Source<NavigationController>(source).ptr(); |
331 search_url_ = pending_url; | 333 search_url_ = pending_url; |
332 registrar_.Remove(this, NotificationType::NAV_ENTRY_PENDING, | 334 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
333 NotificationService::AllSources()); | 335 NotificationService::AllSources()); |
334 // Start listening for the commit notification. We also need to listen for the | 336 // 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. | 337 // tab close command since that means the load will never commit. |
336 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, | 338 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
337 Source<NavigationController>(controller_)); | 339 Source<NavigationController>(controller_)); |
338 registrar_.Add(this, NotificationType::TAB_CLOSED, | 340 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
339 Source<NavigationController>(controller_)); | 341 Source<NavigationController>(controller_)); |
340 } | 342 } |
341 | 343 |
342 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( | 344 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( |
343 TabContents* tab_contents, | 345 TabContents* tab_contents, |
344 NotificationType::Type type) { | 346 int type) { |
345 registrar_.RemoveAll(); | 347 registrar_.RemoveAll(); |
346 | 348 |
347 if (type == NotificationType::NAV_ENTRY_COMMITTED) { | 349 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
348 ShowGoogleURLInfoBarIfNecessary(tab_contents); | 350 ShowGoogleURLInfoBarIfNecessary(tab_contents); |
349 } else { | 351 } else { |
350 controller_ = NULL; | 352 controller_ = NULL; |
351 infobar_ = NULL; | 353 infobar_ = NULL; |
352 } | 354 } |
353 } | 355 } |
354 | 356 |
355 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( | 357 void GoogleURLTracker::ShowGoogleURLInfoBarIfNecessary( |
356 TabContents* tab_contents) { | 358 TabContents* tab_contents) { |
357 if (!need_to_prompt_) | 359 if (!need_to_prompt_) |
358 return; | 360 return; |
359 DCHECK(!fetched_google_url_.is_empty()); | 361 DCHECK(!fetched_google_url_.is_empty()); |
360 | 362 |
361 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); | 363 infobar_ = (*infobar_creator_)(tab_contents, this, fetched_google_url_); |
362 } | 364 } |
OLD | NEW |