OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/managed_mode/managed_mode_navigation_observer.h" | 5 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
11 #include "base/string_util.h" | 11 #include "base/string_util.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
14 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
15 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" | 15 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" |
16 #include "chrome/browser/managed_mode/managed_mode.h" | 16 #include "chrome/browser/managed_mode/managed_mode.h" |
17 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 17 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
18 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 18 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
19 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 19 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
20 #include "chrome/browser/managed_mode/managed_user_service.h" | 20 #include "chrome/browser/managed_mode/managed_user_service.h" |
21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
22 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/tab_contents/tab_util.h" |
23 #include "chrome/browser/ui/browser.h" | 24 #include "chrome/browser/ui/browser.h" |
24 #include "chrome/browser/ui/browser_commands.h" | 25 #include "chrome/browser/ui/browser_commands.h" |
25 #include "chrome/browser/ui/browser_finder.h" | 26 #include "chrome/browser/ui/browser_finder.h" |
26 #include "chrome/browser/ui/browser_list.h" | 27 #include "chrome/browser/ui/browser_list.h" |
27 #include "chrome/browser/ui/host_desktop.h" | 28 #include "chrome/browser/ui/host_desktop.h" |
28 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 29 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
29 #include "chrome/common/extensions/extension_constants.h" | 30 #include "chrome/common/extensions/extension_constants.h" |
30 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
31 #include "chrome/common/url_constants.h" | 32 #include "chrome/common/url_constants.h" |
32 #include "content/public/browser/browser_thread.h" | 33 #include "content/public/browser/browser_thread.h" |
| 34 #include "content/public/browser/notification_details.h" |
| 35 #include "content/public/browser/notification_source.h" |
| 36 #include "content/public/browser/notification_types.h" |
33 #include "content/public/browser/render_process_host.h" | 37 #include "content/public/browser/render_process_host.h" |
34 #include "content/public/browser/render_view_host.h" | 38 #include "content/public/browser/render_view_host.h" |
| 39 #include "content/public/browser/resource_request_details.h" |
35 #include "content/public/browser/user_metrics.h" | 40 #include "content/public/browser/user_metrics.h" |
36 #include "content/public/browser/web_contents_delegate.h" | 41 #include "content/public/browser/web_contents_delegate.h" |
37 #include "content/public/browser/web_contents_view.h" | 42 #include "content/public/browser/web_contents_view.h" |
38 #include "content/public/common/frame_navigate_params.h" | 43 #include "content/public/common/frame_navigate_params.h" |
39 #include "grit/generated_resources.h" | 44 #include "grit/generated_resources.h" |
40 #include "grit/locale_settings.h" | 45 #include "grit/locale_settings.h" |
41 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
42 | 47 |
43 using content::BrowserThread; | 48 using content::BrowserThread; |
44 using content::UserMetricsAction; | 49 using content::UserMetricsAction; |
(...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 } | 264 } |
260 | 265 |
261 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 266 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
262 content::WebContents* web_contents) | 267 content::WebContents* web_contents) |
263 : WebContentsObserver(web_contents), | 268 : WebContentsObserver(web_contents), |
264 warn_infobar_delegate_(NULL), | 269 warn_infobar_delegate_(NULL), |
265 preview_infobar_delegate_(NULL), | 270 preview_infobar_delegate_(NULL), |
266 got_user_gesture_(false), | 271 got_user_gesture_(false), |
267 state_(RECORDING_URLS_BEFORE_PREVIEW), | 272 state_(RECORDING_URLS_BEFORE_PREVIEW), |
268 is_elevated_(false), | 273 is_elevated_(false), |
| 274 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), |
269 last_allowed_page_(-1) { | 275 last_allowed_page_(-1) { |
270 Profile* profile = | 276 Profile* profile = |
271 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 277 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
272 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); | 278 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
273 if (!managed_user_service_->ProfileIsManaged()) | 279 if (!managed_user_service_->ProfileIsManaged()) |
274 is_elevated_ = true; | 280 is_elevated_ = true; |
275 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); | 281 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); |
| 282 registrar_.Add(this, content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, |
| 283 content::Source<content::WebContents>(web_contents)); |
| 284 } |
| 285 |
| 286 // static |
| 287 void ManagedModeNavigationObserver::DidBlockRequest( |
| 288 int render_process_id, |
| 289 int render_view_id, |
| 290 const GURL& url, |
| 291 const ManagedModeNavigationObserver::SuccessCallback& callback) { |
| 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 293 // The tab might have been closed. |
| 294 content::WebContents* web_contents = |
| 295 tab_util::GetWebContentsByID(render_process_id, render_view_id); |
| 296 if (!web_contents) { |
| 297 BrowserThread::PostTask( |
| 298 BrowserThread::IO, FROM_HERE, base::Bind(callback, false)); |
| 299 return; |
| 300 } |
| 301 |
| 302 ManagedModeNavigationObserver* navigation_observer = |
| 303 ManagedModeNavigationObserver::FromWebContents(web_contents); |
| 304 if (!navigation_observer) { |
| 305 BrowserThread::PostTask( |
| 306 BrowserThread::IO, FROM_HERE, base::Bind(callback, false)); |
| 307 return; |
| 308 } |
| 309 navigation_observer->AddInterstitialCallback(url, callback); |
| 310 } |
| 311 |
| 312 void ManagedModeNavigationObserver::ShowInterstitial(const GURL& url) { |
| 313 // If we already have callbacks queued up, we don't need to show the |
| 314 // interstitial again. |
| 315 if (!callbacks_.empty()) |
| 316 return; |
| 317 |
| 318 new ManagedModeInterstitial( |
| 319 web_contents(), url, |
| 320 base::Bind(&ManagedModeNavigationObserver::OnInterstitialResult, |
| 321 weak_ptr_factory_.GetWeakPtr())); |
| 322 } |
| 323 |
| 324 void ManagedModeNavigationObserver::AddInterstitialCallback( |
| 325 const GURL& url, |
| 326 const ManagedModeNavigationObserver::SuccessCallback& callback) { |
| 327 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { |
| 328 // Return immediately if we are in preview mode. |
| 329 BrowserThread::PostTask( |
| 330 BrowserThread::IO, FROM_HERE, base::Bind(callback, true)); |
| 331 return; |
| 332 } |
| 333 |
| 334 ShowInterstitial(url); |
| 335 callbacks_.push_back(callback); |
276 } | 336 } |
277 | 337 |
278 void ManagedModeNavigationObserver::AddTemporaryException() { | 338 void ManagedModeNavigationObserver::AddTemporaryException() { |
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 339 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
280 DCHECK(web_contents()); | 340 DCHECK(web_contents()); |
281 | 341 |
282 BrowserThread::PostTask( | 342 BrowserThread::PostTask( |
283 BrowserThread::IO, | 343 BrowserThread::IO, |
284 FROM_HERE, | 344 FROM_HERE, |
285 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | 345 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { | 385 void ManagedModeNavigationObserver::PreviewInfobarDismissed() { |
326 DCHECK(preview_infobar_delegate_); | 386 DCHECK(preview_infobar_delegate_); |
327 preview_infobar_delegate_ = NULL; | 387 preview_infobar_delegate_ = NULL; |
328 } | 388 } |
329 | 389 |
330 void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() { | 390 void ManagedModeNavigationObserver::AddSavedURLsToWhitelistAndClearState() { |
331 std::vector<GURL> urls; | 391 std::vector<GURL> urls; |
332 for (std::set<GURL>::const_iterator it = navigated_urls_.begin(); | 392 for (std::set<GURL>::const_iterator it = navigated_urls_.begin(); |
333 it != navigated_urls_.end(); | 393 it != navigated_urls_.end(); |
334 ++it) { | 394 ++it) { |
335 if (it->host() != last_url_.host()) | 395 if (!CanTemporarilyNavigateHost(*it)) |
336 urls.push_back(*it); | 396 urls.push_back(*it); |
337 } | 397 } |
338 managed_user_service_->SetManualBehaviorForURLs( | 398 managed_user_service_->SetManualBehaviorForURLs( |
339 urls, ManagedUserService::MANUAL_ALLOW); | 399 urls, ManagedUserService::MANUAL_ALLOW); |
340 if (last_url_.is_valid()) { | 400 if (!last_url_.is_empty()) { |
341 std::vector<std::string> hosts; | 401 std::vector<std::string> hosts; |
342 hosts.push_back(last_url_.host()); | 402 hosts.push_back(last_url_.host()); |
343 managed_user_service_->SetManualBehaviorForHosts( | 403 managed_user_service_->SetManualBehaviorForHosts( |
344 hosts, ManagedUserService::MANUAL_ALLOW); | 404 hosts, ManagedUserService::MANUAL_ALLOW); |
345 } | 405 } |
346 ClearObserverState(); | 406 ClearObserverState(); |
347 } | 407 } |
348 | 408 |
349 bool ManagedModeNavigationObserver::is_elevated() const { | 409 bool ManagedModeNavigationObserver::is_elevated() const { |
350 return is_elevated_; | 410 return is_elevated_; |
351 } | 411 } |
352 | 412 |
353 void ManagedModeNavigationObserver::set_elevated(bool is_elevated) { | 413 void ManagedModeNavigationObserver::set_elevated(bool is_elevated) { |
354 is_elevated_ = is_elevated; | 414 is_elevated_ = is_elevated; |
355 } | 415 } |
356 | 416 |
357 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | 417 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
358 navigated_urls_.insert(url); | 418 navigated_urls_.insert(url); |
359 last_url_ = url; | 419 last_url_ = url; |
360 } | 420 } |
361 | 421 |
362 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | |
363 state_ = RECORDING_URLS_AFTER_PREVIEW; | |
364 } | |
365 | |
366 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( | 422 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( |
367 const GURL& url) { | 423 const GURL& url) { |
368 return last_url_.host() == url.host(); | 424 return last_url_.host() == url.host(); |
369 } | 425 } |
370 | 426 |
371 bool ManagedModeNavigationObserver::ShouldStayElevatedForURL( | 427 bool ManagedModeNavigationObserver::ShouldStayElevatedForURL( |
372 const GURL& navigation_url) { | 428 const GURL& navigation_url) { |
373 std::string url = navigation_url.spec(); | 429 std::string url = navigation_url.spec(); |
374 // Handle chrome:// URLs specially. | 430 // Handle chrome:// URLs specially. |
375 if (navigation_url.host() == "chrome") { | 431 if (navigation_url.host() == "chrome") { |
(...skipping 17 matching lines...) Expand all Loading... |
393 preview_infobar_delegate_ = NULL; | 449 preview_infobar_delegate_ = NULL; |
394 } | 450 } |
395 navigated_urls_.clear(); | 451 navigated_urls_.clear(); |
396 last_url_ = GURL(); | 452 last_url_ = GURL(); |
397 state_ = RECORDING_URLS_BEFORE_PREVIEW; | 453 state_ = RECORDING_URLS_BEFORE_PREVIEW; |
398 // TODO(sergiu): Remove these logging calls once this is stable. | 454 // TODO(sergiu): Remove these logging calls once this is stable. |
399 DVLOG(1) << "Clearing observer state"; | 455 DVLOG(1) << "Clearing observer state"; |
400 RemoveTemporaryException(); | 456 RemoveTemporaryException(); |
401 } | 457 } |
402 | 458 |
| 459 void ManagedModeNavigationObserver::OnInterstitialResult(bool result) { |
| 460 DCHECK_EQ(RECORDING_URLS_BEFORE_PREVIEW, state_); |
| 461 if (result) |
| 462 state_ = RECORDING_URLS_AFTER_PREVIEW; |
| 463 |
| 464 for (std::vector<SuccessCallback>::const_iterator it = callbacks_.begin(); |
| 465 it != callbacks_.end(); ++it) { |
| 466 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
| 467 base::Bind(*it, result)); |
| 468 } |
| 469 callbacks_.clear(); |
| 470 } |
| 471 |
403 void ManagedModeNavigationObserver::NavigateToPendingEntry( | 472 void ManagedModeNavigationObserver::NavigateToPendingEntry( |
404 const GURL& url, | 473 const GURL& url, |
405 content::NavigationController::ReloadType reload_type) { | 474 content::NavigationController::ReloadType reload_type) { |
406 DVLOG(1) << "NavigateToPendingEntry " << url.spec(); | 475 DVLOG(1) << "NavigateToPendingEntry " << url.spec(); |
407 // This method gets called only when the user goes back and forward and when | 476 // This method gets called only when the user goes back and forward and when |
408 // the user types a new URL. So do the main work in | 477 // the user types a new URL. So do the main work in |
409 // ProvisionalChangeToMainFrameUrl and only check that the user didn't go | 478 // ProvisionalChangeToMainFrameUrl and only check that the user didn't go |
410 // back to a blocked site here. | 479 // back to a blocked site here. |
411 if (web_contents()->GetController().GetCurrentEntryIndex() < | 480 if (web_contents()->GetController().GetCurrentEntryIndex() < |
412 last_allowed_page_) { | 481 last_allowed_page_) { |
413 ClearObserverState(); | 482 ClearObserverState(); |
414 } | 483 } |
415 } | 484 } |
416 | 485 |
417 void ManagedModeNavigationObserver::DidNavigateMainFrame( | |
418 const content::LoadCommittedDetails& details, | |
419 const content::FrameNavigateParams& params) { | |
420 if (!ShouldStayElevatedForURL(params.url)) | |
421 is_elevated_ = false; | |
422 | |
423 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); | |
424 | |
425 ManagedModeURLFilter::FilteringBehavior behavior = | |
426 url_filter_->GetFilteringBehaviorForURL(params.url); | |
427 | |
428 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", | |
429 behavior, | |
430 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); | |
431 | |
432 // The page can be redirected to a different domain, record those URLs as | |
433 // well. | |
434 if (behavior == ManagedModeURLFilter::BLOCK && | |
435 !CanTemporarilyNavigateHost(params.url)) | |
436 AddURLToPatternList(params.url); | |
437 | |
438 if (behavior == ManagedModeURLFilter::ALLOW && | |
439 state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
440 // The initial page that triggered the interstitial was blocked but the | |
441 // final page is already in the whitelist so add the series of URLs | |
442 // which lead to the final page to the whitelist as well. | |
443 // Update the |last_url_| since it was not added to the list before. | |
444 last_url_ = params.url; | |
445 AddSavedURLsToWhitelistAndClearState(); | |
446 SimpleAlertInfoBarDelegate::Create( | |
447 InfoBarService::FromWebContents(web_contents()), | |
448 NULL, | |
449 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), | |
450 true); | |
451 return; | |
452 } | |
453 | |
454 // Update the exception to the last host visited. A redirect can follow this | |
455 // so don't update the state yet. | |
456 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | |
457 AddTemporaryException(); | |
458 } | |
459 | |
460 // The navigation is complete, unless there is a redirect. So set the | |
461 // new navigation to false to detect user interaction. | |
462 got_user_gesture_ = false; | |
463 } | |
464 | |
465 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 486 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
466 const GURL& url, | 487 const GURL& url, |
467 content::RenderViewHost* render_view_host) { | 488 content::RenderViewHost* render_view_host) { |
468 if (!ShouldStayElevatedForURL(url)) | 489 if (!ShouldStayElevatedForURL(url)) |
469 is_elevated_ = false; | 490 is_elevated_ = false; |
470 | 491 |
471 // This function is the last one to be called before the resource throttle | |
472 // shows the interstitial if the URL must be blocked. | |
473 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); | |
474 ManagedModeURLFilter::FilteringBehavior behavior = | 492 ManagedModeURLFilter::FilteringBehavior behavior = |
475 url_filter_->GetFilteringBehaviorForURL(url); | 493 url_filter_->GetFilteringBehaviorForURL(url); |
476 | |
477 if (behavior != ManagedModeURLFilter::BLOCK) | 494 if (behavior != ManagedModeURLFilter::BLOCK) |
478 return; | 495 return; |
479 | 496 |
480 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && | 497 if (state_ == RECORDING_URLS_BEFORE_PREVIEW) { |
481 !CanTemporarilyNavigateHost(url)) | 498 ShowInterstitial(url); |
482 ClearObserverState(); | 499 } else { |
| 500 if (got_user_gesture_ && !CanTemporarilyNavigateHost(url)) |
| 501 ClearObserverState(); |
483 | 502 |
484 if (behavior == ManagedModeURLFilter::BLOCK && | 503 got_user_gesture_ = false; |
485 !CanTemporarilyNavigateHost(url)) | 504 } |
486 AddURLToPatternList(url); | |
487 | |
488 got_user_gesture_ = false; | |
489 } | 505 } |
490 | 506 |
491 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( | 507 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( |
492 int64 frame_id, | 508 int64 frame_id, |
493 bool is_main_frame, | 509 bool is_main_frame, |
494 const GURL& url, | 510 const GURL& url, |
495 content::PageTransition transition_type, | 511 content::PageTransition transition_type, |
496 content::RenderViewHost* render_view_host) { | 512 content::RenderViewHost* render_view_host) { |
497 if (!is_main_frame) | 513 if (!is_main_frame) |
498 return; | 514 return; |
(...skipping 22 matching lines...) Expand all Loading... |
521 if (!preview_infobar_delegate_) { | 537 if (!preview_infobar_delegate_) { |
522 preview_infobar_delegate_ = ManagedModePreviewInfobarDelegate::Create( | 538 preview_infobar_delegate_ = ManagedModePreviewInfobarDelegate::Create( |
523 InfoBarService::FromWebContents(web_contents())); | 539 InfoBarService::FromWebContents(web_contents())); |
524 } | 540 } |
525 } | 541 } |
526 | 542 |
527 if (behavior == ManagedModeURLFilter::ALLOW) | 543 if (behavior == ManagedModeURLFilter::ALLOW) |
528 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | 544 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
529 } | 545 } |
530 | 546 |
| 547 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
| 548 const content::LoadCommittedDetails& details, |
| 549 const content::FrameNavigateParams& params) { |
| 550 if (!ShouldStayElevatedForURL(params.url)) |
| 551 is_elevated_ = false; |
| 552 |
| 553 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); |
| 554 |
| 555 ManagedModeURLFilter::FilteringBehavior behavior = |
| 556 url_filter_->GetFilteringBehaviorForURL(params.url); |
| 557 |
| 558 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", |
| 559 behavior, |
| 560 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); |
| 561 |
| 562 // The page can be redirected to a different domain, record those URLs as |
| 563 // well. |
| 564 if (behavior == ManagedModeURLFilter::BLOCK && |
| 565 !CanTemporarilyNavigateHost(params.url)) |
| 566 AddURLToPatternList(params.url); |
| 567 |
| 568 if (behavior == ManagedModeURLFilter::ALLOW && |
| 569 state_ == RECORDING_URLS_AFTER_PREVIEW) { |
| 570 // The initial page that triggered the interstitial was blocked but the |
| 571 // final page is already in the whitelist so add the series of URLs |
| 572 // which lead to the final page to the whitelist as well. |
| 573 // Update the |last_url_| since it was not added to the list before. |
| 574 last_url_ = params.url; |
| 575 AddSavedURLsToWhitelistAndClearState(); |
| 576 SimpleAlertInfoBarDelegate::Create( |
| 577 InfoBarService::FromWebContents(web_contents()), |
| 578 NULL, |
| 579 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), |
| 580 true); |
| 581 return; |
| 582 } |
| 583 |
| 584 // Update the exception to the last host visited. A redirect can follow this |
| 585 // so don't update the state yet. |
| 586 if (state_ == RECORDING_URLS_AFTER_PREVIEW) |
| 587 AddTemporaryException(); |
| 588 |
| 589 // The navigation is complete, unless there is a redirect. So set the |
| 590 // new navigation to false to detect user interaction. |
| 591 got_user_gesture_ = false; |
| 592 } |
| 593 |
531 void ManagedModeNavigationObserver::DidGetUserGesture() { | 594 void ManagedModeNavigationObserver::DidGetUserGesture() { |
532 got_user_gesture_ = true; | 595 got_user_gesture_ = true; |
533 // Update the exception status so that the resource throttle knows that | 596 // Update the exception status so that the resource throttle knows that |
534 // there was a manual navigation. | 597 // there was a manual navigation. |
535 UpdateExceptionNavigationStatus(); | 598 UpdateExceptionNavigationStatus(); |
536 } | 599 } |
| 600 |
| 601 void ManagedModeNavigationObserver::Observe( |
| 602 int type, |
| 603 const content::NotificationSource& source, |
| 604 const content::NotificationDetails& details) { |
| 605 DCHECK_EQ(content::NOTIFICATION_RESOURCE_RECEIVED_REDIRECT, type); |
| 606 const GURL& url = |
| 607 content::Details<content::ResourceRedirectDetails>(details)->url; |
| 608 ManagedModeURLFilter::FilteringBehavior behavior = |
| 609 url_filter_->GetFilteringBehaviorForURL(url); |
| 610 if (behavior == ManagedModeURLFilter::BLOCK && |
| 611 state_ == RECORDING_URLS_AFTER_PREVIEW && |
| 612 !CanTemporarilyNavigateHost(url)) { |
| 613 AddURLToPatternList(url); |
| 614 } |
| 615 } |
OLD | NEW |