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" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "content/public/browser/notification_service.h" | 25 #include "content/public/browser/notification_service.h" |
26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
27 #include "content/public/common/url_fetcher.h" | 27 #include "content/public/common/url_fetcher.h" |
28 #include "grit/generated_resources.h" | 28 #include "grit/generated_resources.h" |
29 #include "net/base/load_flags.h" | 29 #include "net/base/load_flags.h" |
30 #include "net/base/net_util.h" | 30 #include "net/base/net_util.h" |
31 #include "net/url_request/url_request_context_getter.h" | 31 #include "net/url_request/url_request_context_getter.h" |
32 #include "net/url_request/url_request_status.h" | 32 #include "net/url_request/url_request_status.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 | 34 |
| 35 using content::NavigationController; |
35 using content::OpenURLParams; | 36 using content::OpenURLParams; |
36 using content::Referrer; | 37 using content::Referrer; |
37 using content::WebContents; | 38 using content::WebContents; |
38 | 39 |
39 namespace { | 40 namespace { |
40 | 41 |
41 InfoBarDelegate* CreateInfobar(InfoBarTabHelper* infobar_helper, | 42 InfoBarDelegate* CreateInfobar(InfoBarTabHelper* infobar_helper, |
42 GoogleURLTracker* google_url_tracker, | 43 GoogleURLTracker* google_url_tracker, |
43 const GURL& new_google_url) { | 44 const GURL& new_google_url) { |
44 InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(infobar_helper, | 45 InfoBarDelegate* infobar = new GoogleURLTrackerInfoBarDelegate(infobar_helper, |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 content::PAGE_TRANSITION_GENERATED, false); | 317 content::PAGE_TRANSITION_GENERATED, false); |
317 controller_->GetWebContents()->OpenURL(params); | 318 controller_->GetWebContents()->OpenURL(params); |
318 } | 319 } |
319 } | 320 } |
320 | 321 |
321 void GoogleURLTracker::Observe(int type, | 322 void GoogleURLTracker::Observe(int type, |
322 const content::NotificationSource& source, | 323 const content::NotificationSource& source, |
323 const content::NotificationDetails& details) { | 324 const content::NotificationDetails& details) { |
324 switch (type) { | 325 switch (type) { |
325 case content::NOTIFICATION_NAV_ENTRY_PENDING: { | 326 case content::NOTIFICATION_NAV_ENTRY_PENDING: { |
326 content::NavigationController* controller = | 327 NavigationController* controller = |
327 content::Source<content::NavigationController>(source).ptr(); | 328 content::Source<NavigationController>(source).ptr(); |
328 OnNavigationPending(source, controller->GetPendingEntry()->GetURL()); | 329 OnNavigationPending(source, controller->GetPendingEntry()->GetURL()); |
329 break; | 330 break; |
330 } | 331 } |
331 | 332 |
332 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: | 333 case content::NOTIFICATION_NAV_ENTRY_COMMITTED: |
333 case content::NOTIFICATION_TAB_CLOSED: | 334 case content::NOTIFICATION_TAB_CLOSED: |
334 OnNavigationCommittedOrTabClosed( | 335 OnNavigationCommittedOrTabClosed( |
335 content::Source<content::NavigationController>(source).ptr()-> | 336 content::Source<NavigationController>(source).ptr()-> |
336 GetWebContents(), type); | 337 GetWebContents(), type); |
337 break; | 338 break; |
338 | 339 |
339 default: | 340 default: |
340 NOTREACHED() << "Unknown notification received:" << type; | 341 NOTREACHED() << "Unknown notification received:" << type; |
341 } | 342 } |
342 } | 343 } |
343 | 344 |
344 void GoogleURLTracker::OnIPAddressChanged() { | 345 void GoogleURLTracker::OnIPAddressChanged() { |
345 already_fetched_ = false; | 346 already_fetched_ = false; |
346 StartFetchIfDesirable(); | 347 StartFetchIfDesirable(); |
347 } | 348 } |
348 | 349 |
349 void GoogleURLTracker::SearchCommitted() { | 350 void GoogleURLTracker::SearchCommitted() { |
350 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { | 351 if (registrar_.IsEmpty() && (need_to_prompt_ || fetcher_.get())) { |
351 // This notification will fire a bit later in the same call chain we're | 352 // This notification will fire a bit later in the same call chain we're |
352 // currently in. | 353 // currently in. |
353 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 354 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
354 content::NotificationService::AllSources()); | 355 content::NotificationService::AllSources()); |
355 } | 356 } |
356 } | 357 } |
357 | 358 |
358 void GoogleURLTracker::OnNavigationPending( | 359 void GoogleURLTracker::OnNavigationPending( |
359 const content::NotificationSource& source, | 360 const content::NotificationSource& source, |
360 const GURL& pending_url) { | 361 const GURL& pending_url) { |
361 controller_ = content::Source<content::NavigationController>(source).ptr(); | 362 controller_ = content::Source<NavigationController>(source).ptr(); |
362 search_url_ = pending_url; | 363 search_url_ = pending_url; |
363 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, | 364 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_PENDING, |
364 content::NotificationService::AllSources()); | 365 content::NotificationService::AllSources()); |
365 // Start listening for the commit notification. We also need to listen for the | 366 // Start listening for the commit notification. We also need to listen for the |
366 // tab close command since that means the load will never commit. | 367 // tab close command since that means the load will never commit. |
367 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, | 368 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
368 content::Source<content::NavigationController>(controller_)); | 369 content::Source<NavigationController>(controller_)); |
369 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, | 370 registrar_.Add(this, content::NOTIFICATION_TAB_CLOSED, |
370 content::Source<content::NavigationController>(controller_)); | 371 content::Source<NavigationController>(controller_)); |
371 } | 372 } |
372 | 373 |
373 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( | 374 void GoogleURLTracker::OnNavigationCommittedOrTabClosed( |
374 WebContents* web_contents, | 375 WebContents* web_contents, |
375 int type) { | 376 int type) { |
376 registrar_.RemoveAll(); | 377 registrar_.RemoveAll(); |
377 | 378 |
378 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { | 379 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED) { |
379 ShowGoogleURLInfoBarIfNecessary(web_contents); | 380 ShowGoogleURLInfoBarIfNecessary(web_contents); |
380 } else { | 381 } else { |
(...skipping 10 matching lines...) Expand all Loading... |
391 | 392 |
392 // |tab_contents| can be NULL during tests. | 393 // |tab_contents| can be NULL during tests. |
393 InfoBarTabHelper* infobar_helper = NULL; | 394 InfoBarTabHelper* infobar_helper = NULL; |
394 if (web_contents) { | 395 if (web_contents) { |
395 TabContentsWrapper* wrapper = | 396 TabContentsWrapper* wrapper = |
396 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); | 397 TabContentsWrapper::GetCurrentWrapperForContents(web_contents); |
397 infobar_helper = wrapper->infobar_tab_helper(); | 398 infobar_helper = wrapper->infobar_tab_helper(); |
398 } | 399 } |
399 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); | 400 infobar_ = (*infobar_creator_)(infobar_helper, this, fetched_google_url_); |
400 } | 401 } |
OLD | NEW |