Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(521)

Side by Side Diff: chrome/browser/managed_mode/managed_mode_navigation_observer.cc

Issue 13533017: Fix managed mode allow/block flow (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rename variable Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 256
257 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { 257 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() {
258 RemoveTemporaryException(); 258 RemoveTemporaryException();
259 } 259 }
260 260
261 ManagedModeNavigationObserver::ManagedModeNavigationObserver( 261 ManagedModeNavigationObserver::ManagedModeNavigationObserver(
262 content::WebContents* web_contents) 262 content::WebContents* web_contents)
263 : WebContentsObserver(web_contents), 263 : WebContentsObserver(web_contents),
264 warn_infobar_delegate_(NULL), 264 warn_infobar_delegate_(NULL),
265 preview_infobar_delegate_(NULL), 265 preview_infobar_delegate_(NULL),
266 got_user_gesture_(false),
267 state_(RECORDING_URLS_BEFORE_PREVIEW), 266 state_(RECORDING_URLS_BEFORE_PREVIEW),
268 is_elevated_(false), 267 is_elevated_(false),
269 last_allowed_page_(-1) { 268 last_allowed_page_(-1),
269 finished_redirects_(false) {
270 Profile* profile = 270 Profile* profile =
271 Profile::FromBrowserContext(web_contents->GetBrowserContext()); 271 Profile::FromBrowserContext(web_contents->GetBrowserContext());
272 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); 272 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile);
273 if (!managed_user_service_->ProfileIsManaged()) 273 if (!managed_user_service_->ProfileIsManaged())
274 is_elevated_ = true; 274 is_elevated_ = true;
275 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); 275 url_filter_ = managed_user_service_->GetURLFilterForUIThread();
276 } 276 }
277 277
278 void ManagedModeNavigationObserver::AddTemporaryException() { 278 void ManagedModeNavigationObserver::AddTemporaryException() {
279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
280 DCHECK(web_contents()); 280 DCHECK(web_contents());
281 281
282 BrowserThread::PostTask( 282 BrowserThread::PostTask(
283 BrowserThread::IO, 283 BrowserThread::IO,
284 FROM_HERE, 284 FROM_HERE,
285 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, 285 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException,
286 web_contents()->GetRenderProcessHost()->GetID(), 286 web_contents()->GetRenderProcessHost()->GetID(),
287 web_contents()->GetRenderViewHost()->GetRoutingID(), 287 web_contents()->GetRenderViewHost()->GetRoutingID(),
288 last_url_, 288 last_url_));
289 got_user_gesture_));
290 }
291
292 void ManagedModeNavigationObserver::UpdateExceptionNavigationStatus() {
293 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
294 DCHECK(web_contents());
295
296 BrowserThread::PostTask(
297 BrowserThread::IO,
298 FROM_HERE,
299 base::Bind(&ManagedModeResourceThrottle::UpdateExceptionNavigationStatus,
300 web_contents()->GetRenderProcessHost()->GetID(),
301 web_contents()->GetRenderViewHost()->GetRoutingID(),
302 got_user_gesture_));
303 } 289 }
304 290
305 void ManagedModeNavigationObserver::RemoveTemporaryException() { 291 void ManagedModeNavigationObserver::RemoveTemporaryException() {
306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); 292 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
307 // When closing the browser web_contents() may return NULL so guard against 293 // When closing the browser web_contents() may return NULL so guard against
308 // that. 294 // that.
309 if (!web_contents()) 295 if (!web_contents())
310 return; 296 return;
311 297
312 BrowserThread::PostTask( 298 BrowserThread::PostTask(
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 } 387 }
402 388
403 void ManagedModeNavigationObserver::NavigateToPendingEntry( 389 void ManagedModeNavigationObserver::NavigateToPendingEntry(
404 const GURL& url, 390 const GURL& url,
405 content::NavigationController::ReloadType reload_type) { 391 content::NavigationController::ReloadType reload_type) {
406 DVLOG(1) << "NavigateToPendingEntry " << url.spec(); 392 DVLOG(1) << "NavigateToPendingEntry " << url.spec();
407 // This method gets called only when the user goes back and forward and when 393 // 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 394 // the user types a new URL. So do the main work in
409 // ProvisionalChangeToMainFrameUrl and only check that the user didn't go 395 // ProvisionalChangeToMainFrameUrl and only check that the user didn't go
410 // back to a blocked site here. 396 // back to a blocked site here.
411 if (web_contents()->GetController().GetCurrentEntryIndex() < 397 ManagedModeURLFilter::FilteringBehavior behavior =
412 last_allowed_page_) { 398 url_filter_->GetFilteringBehaviorForURL(url);
399 int current_index = web_contents()->GetController().GetCurrentEntryIndex();
400 // First check that the user didn't go back to a blocked page, then check
401 // that the navigation is allowed.
402 if (last_allowed_page_ < 0 || current_index <= last_allowed_page_ ||
403 (behavior == ManagedModeURLFilter::BLOCK &&
404 !CanTemporarilyNavigateHost(url))) {
413 ClearObserverState(); 405 ClearObserverState();
414 } 406 }
407 finished_redirects_ = false;
415 } 408 }
416 409
417 void ManagedModeNavigationObserver::DidNavigateMainFrame( 410 void ManagedModeNavigationObserver::DidNavigateMainFrame(
418 const content::LoadCommittedDetails& details, 411 const content::LoadCommittedDetails& details,
419 const content::FrameNavigateParams& params) { 412 const content::FrameNavigateParams& params) {
420 if (!ShouldStayElevatedForURL(params.url)) 413 if (!ShouldStayElevatedForURL(params.url))
421 is_elevated_ = false; 414 is_elevated_ = false;
415 DVLOG(1) << "DidNavigateMainFrame " << params.url.spec();
422 416
417 // The page already loaded so we are not redirecting anymore, so the
418 // next call to ProvisionalChangeToMainFrameURL will probably be after a
419 // click.
420 // TODO(sergiu): One case where I think this fails is if we get a client-side
421 // redirect to a different domain as that will not have a temporary
422 // exception. See about that in the future.
423 finished_redirects_ = true;
423 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); 424 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation"));
424 425
425 ManagedModeURLFilter::FilteringBehavior behavior = 426 ManagedModeURLFilter::FilteringBehavior behavior =
426 url_filter_->GetFilteringBehaviorForURL(params.url); 427 url_filter_->GetFilteringBehaviorForURL(params.url);
427 428
429 if (behavior == ManagedModeURLFilter::ALLOW) {
430 // Update the last allowed page so that we can go back to it.
431 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
432 }
433
428 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", 434 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior",
429 behavior, 435 behavior,
430 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); 436 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE);
431 437
432 // The page can be redirected to a different domain, record those URLs as 438 // Record all the URLs this navigation went through.
433 // well. 439 if ((behavior == ManagedModeURLFilter::ALLOW &&
434 if (behavior == ManagedModeURLFilter::BLOCK && 440 state_ == RECORDING_URLS_AFTER_PREVIEW) ||
435 !CanTemporarilyNavigateHost(params.url)) 441 !CanTemporarilyNavigateHost(params.url)) {
436 AddURLToPatternList(params.url); 442 for (std::vector<GURL>::const_iterator it = params.redirects.begin();
443 it != params.redirects.end(); ++it) {
444 DVLOG(1) << "Adding: " << it->spec();
445 AddURLToPatternList(*it);
446 }
447 }
437 448
438 if (behavior == ManagedModeURLFilter::ALLOW && 449 if (behavior == ManagedModeURLFilter::ALLOW &&
439 state_ == RECORDING_URLS_AFTER_PREVIEW) { 450 state_ == RECORDING_URLS_AFTER_PREVIEW) {
440 // The initial page that triggered the interstitial was blocked but the 451 // 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 452 // 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. 453 // 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(); 454 AddSavedURLsToWhitelistAndClearState();
455 // This page is now allowed so save the index as well.
456 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
446 SimpleAlertInfoBarDelegate::Create( 457 SimpleAlertInfoBarDelegate::Create(
447 InfoBarService::FromWebContents(web_contents()), 458 InfoBarService::FromWebContents(web_contents()),
448 NULL, 459 NULL,
449 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE), 460 l10n_util::GetStringUTF16(IDS_MANAGED_MODE_ALREADY_ADDED_MESSAGE),
450 true); 461 true);
451 return; 462 return;
452 } 463 }
453 464
454 // Update the exception to the last host visited. A redirect can follow this 465 // Update the exception to the last host visited. A redirect can follow this
455 // so don't update the state yet. 466 // so don't update the state yet.
456 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { 467 if (state_ == RECORDING_URLS_AFTER_PREVIEW) {
457 AddTemporaryException(); 468 AddTemporaryException();
458 } 469 }
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 } 470 }
464 471
465 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( 472 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl(
466 const GURL& url, 473 const GURL& url,
467 content::RenderViewHost* render_view_host) { 474 content::RenderViewHost* render_view_host) {
468 if (!ShouldStayElevatedForURL(url)) 475 if (!ShouldStayElevatedForURL(url))
469 is_elevated_ = false; 476 is_elevated_ = false;
470 477
471 // This function is the last one to be called before the resource throttle 478 // This function is the last one to be called before the resource throttle
472 // shows the interstitial if the URL must be blocked. 479 // shows the interstitial if the URL must be blocked.
473 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); 480 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec();
481
474 ManagedModeURLFilter::FilteringBehavior behavior = 482 ManagedModeURLFilter::FilteringBehavior behavior =
475 url_filter_->GetFilteringBehaviorForURL(url); 483 url_filter_->GetFilteringBehaviorForURL(url);
476
477 if (behavior != ManagedModeURLFilter::BLOCK) 484 if (behavior != ManagedModeURLFilter::BLOCK)
478 return; 485 return;
479 486
480 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && 487 if (finished_redirects_ && state_ == RECORDING_URLS_AFTER_PREVIEW &&
481 !CanTemporarilyNavigateHost(url)) 488 !CanTemporarilyNavigateHost(url))
482 ClearObserverState(); 489 ClearObserverState();
483
484 if (behavior == ManagedModeURLFilter::BLOCK &&
485 !CanTemporarilyNavigateHost(url))
486 AddURLToPatternList(url);
487
488 got_user_gesture_ = false;
489 } 490 }
490 491
491 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame( 492 void ManagedModeNavigationObserver::DidCommitProvisionalLoadForFrame(
492 int64 frame_id, 493 int64 frame_id,
493 bool is_main_frame, 494 bool is_main_frame,
494 const GURL& url, 495 const GURL& url,
495 content::PageTransition transition_type, 496 content::PageTransition transition_type,
496 content::RenderViewHost* render_view_host) { 497 content::RenderViewHost* render_view_host) {
497 if (!is_main_frame) 498 if (!is_main_frame)
498 return; 499 return;
(...skipping 17 matching lines...) Expand all
516 } 517 }
517 518
518 if (behavior == ManagedModeURLFilter::BLOCK) { 519 if (behavior == ManagedModeURLFilter::BLOCK) {
519 DCHECK_EQ(RECORDING_URLS_AFTER_PREVIEW, state_); 520 DCHECK_EQ(RECORDING_URLS_AFTER_PREVIEW, state_);
520 // Add the infobar. 521 // Add the infobar.
521 if (!preview_infobar_delegate_) { 522 if (!preview_infobar_delegate_) {
522 preview_infobar_delegate_ = ManagedModePreviewInfobarDelegate::Create( 523 preview_infobar_delegate_ = ManagedModePreviewInfobarDelegate::Create(
523 InfoBarService::FromWebContents(web_contents())); 524 InfoBarService::FromWebContents(web_contents()));
524 } 525 }
525 } 526 }
526
527 if (behavior == ManagedModeURLFilter::ALLOW)
528 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex();
529 } 527 }
530
531 void ManagedModeNavigationObserver::DidGetUserGesture() {
532 got_user_gesture_ = true;
533 // Update the exception status so that the resource throttle knows that
534 // there was a manual navigation.
535 UpdateExceptionNavigationStatus();
536 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698