Chromium Code Reviews| 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/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
| 12 #include "chrome/browser/infobars/confirm_infobar_delegate.h" | 13 #include "chrome/browser/infobars/confirm_infobar_delegate.h" |
| 13 #include "chrome/browser/infobars/infobar_service.h" | 14 #include "chrome/browser/infobars/infobar_service.h" |
| 14 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" | 15 #include "chrome/browser/infobars/simple_alert_infobar_delegate.h" |
| 15 #include "chrome/browser/managed_mode/managed_mode.h" | 16 #include "chrome/browser/managed_mode/managed_mode.h" |
| 16 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 17 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 17 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 18 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
| 18 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 19 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 19 #include "chrome/browser/managed_mode/managed_user_service.h" | 20 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 20 #include "chrome/browser/managed_mode/managed_user_service_factory.h" | 21 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 36 #include "content/public/common/frame_navigate_params.h" | 37 #include "content/public/common/frame_navigate_params.h" |
| 37 #include "grit/generated_resources.h" | 38 #include "grit/generated_resources.h" |
| 38 #include "grit/locale_settings.h" | 39 #include "grit/locale_settings.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 40 #include "ui/base/l10n/l10n_util.h" |
| 40 | 41 |
| 41 using content::BrowserThread; | 42 using content::BrowserThread; |
| 42 using content::UserMetricsAction; | 43 using content::UserMetricsAction; |
| 43 | 44 |
| 44 namespace { | 45 namespace { |
| 45 | 46 |
| 47 const char kChromeWebstoreURL[] = "chrome.google.com/webstore/"; | |
| 48 | |
| 46 // For use in histograms. | 49 // For use in histograms. |
| 47 enum PreviewInfobarCommand { | 50 enum PreviewInfobarCommand { |
| 48 INFOBAR_ACCEPT, | 51 INFOBAR_ACCEPT, |
| 49 INFOBAR_CANCEL, | 52 INFOBAR_CANCEL, |
| 50 INFOBAR_HISTOGRAM_BOUNDING_VALUE | 53 INFOBAR_HISTOGRAM_BOUNDING_VALUE |
| 51 }; | 54 }; |
| 52 | 55 |
| 53 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { | 56 class ManagedModeWarningInfobarDelegate : public ConfirmInfoBarDelegate { |
| 54 public: | 57 public: |
| 55 // Creates a managed mode warning delegate and adds it to |infobar_service|. | 58 // Creates a managed mode warning delegate and adds it to |infobar_service|. |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 256 RemoveTemporaryException(); | 259 RemoveTemporaryException(); |
| 257 } | 260 } |
| 258 | 261 |
| 259 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 262 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
| 260 content::WebContents* web_contents) | 263 content::WebContents* web_contents) |
| 261 : WebContentsObserver(web_contents), | 264 : WebContentsObserver(web_contents), |
| 262 warn_infobar_delegate_(NULL), | 265 warn_infobar_delegate_(NULL), |
| 263 preview_infobar_delegate_(NULL), | 266 preview_infobar_delegate_(NULL), |
| 264 got_user_gesture_(false), | 267 got_user_gesture_(false), |
| 265 state_(RECORDING_URLS_BEFORE_PREVIEW), | 268 state_(RECORDING_URLS_BEFORE_PREVIEW), |
| 269 is_elevated_(false), | |
| 266 last_allowed_page_(-1) { | 270 last_allowed_page_(-1) { |
| 267 Profile* profile = | 271 Profile* profile = |
| 268 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 272 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 269 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); | 273 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
| 274 if (!managed_user_service_->ProfileIsManaged()) | |
| 275 is_elevated_ = true; | |
| 270 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); | 276 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); |
| 271 } | 277 } |
| 272 | 278 |
| 273 void ManagedModeNavigationObserver::AddTemporaryException() { | 279 void ManagedModeNavigationObserver::AddTemporaryException() { |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 280 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 275 DCHECK(web_contents()); | 281 DCHECK(web_contents()); |
| 276 | 282 |
| 277 BrowserThread::PostTask( | 283 BrowserThread::PostTask( |
| 278 BrowserThread::IO, | 284 BrowserThread::IO, |
| 279 FROM_HERE, | 285 FROM_HERE, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 334 urls, ManagedUserService::MANUAL_ALLOW); | 340 urls, ManagedUserService::MANUAL_ALLOW); |
| 335 if (last_url_.is_valid()) { | 341 if (last_url_.is_valid()) { |
| 336 std::vector<std::string> hosts; | 342 std::vector<std::string> hosts; |
| 337 hosts.push_back(last_url_.host()); | 343 hosts.push_back(last_url_.host()); |
| 338 managed_user_service_->SetManualBehaviorForHosts( | 344 managed_user_service_->SetManualBehaviorForHosts( |
| 339 hosts, ManagedUserService::MANUAL_ALLOW); | 345 hosts, ManagedUserService::MANUAL_ALLOW); |
| 340 } | 346 } |
| 341 ClearObserverState(); | 347 ClearObserverState(); |
| 342 } | 348 } |
| 343 | 349 |
| 350 bool ManagedModeNavigationObserver::is_elevated() const { | |
| 351 return is_elevated_; | |
| 352 } | |
| 353 | |
| 354 void ManagedModeNavigationObserver::set_elevated(bool is_elevated) { | |
| 355 is_elevated_ = is_elevated; | |
| 356 } | |
| 357 | |
| 344 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | 358 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
| 345 navigated_urls_.insert(url); | 359 navigated_urls_.insert(url); |
| 346 last_url_ = url; | 360 last_url_ = url; |
| 347 } | 361 } |
| 348 | 362 |
| 349 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | 363 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { |
| 350 state_ = RECORDING_URLS_AFTER_PREVIEW; | 364 state_ = RECORDING_URLS_AFTER_PREVIEW; |
| 351 } | 365 } |
| 352 | 366 |
| 353 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( | 367 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( |
| 354 const GURL& url) { | 368 const GURL& url) { |
| 355 return last_url_.host() == url.host(); | 369 return last_url_.host() == url.host(); |
| 356 } | 370 } |
| 357 | 371 |
| 372 namespace { | |
| 373 } | |
| 374 | |
| 375 bool ManagedModeNavigationObserver::ShouldStayElevatedForURL( | |
| 376 const GURL& navigation_url) { | |
| 377 // chrome:// URLs have chrome as a host type in the GURL. But all | |
| 378 // chrome URLs in url_constants.h are specified with a chrome:// prefix. | |
| 379 // Therefore we insert a ":/" between host and path for the chrome:// URLs. | |
| 380 std::string url = navigation_url.spec(); | |
| 381 if (navigation_url.host() == "chrome") { | |
| 382 // The path contains the actual host name, but starts with a "/". Remove | |
| 383 // the "/". | |
| 384 url = navigation_url.path().substr(1); | |
| 385 } | |
| 386 | |
| 387 // Check if any of the special urls is a prefix of url. | |
|
Bernhard Bauer
2013/03/22 09:24:28
Nit: it's "URL" (plural URLs) if you talk about an
Adrian Kuegel
2013/03/22 09:46:21
Done.
| |
| 388 return StartsWithASCII(url, chrome::kChromeUIHistoryHost, false) || | |
| 389 StartsWithASCII(url, chrome::kChromeUIExtensionsHost, false) || | |
|
Bernhard Bauer
2013/03/22 09:24:28
Nit: Might be nicer to align these?
Adrian Kuegel
2013/03/22 09:46:21
Done.
| |
| 390 StartsWithASCII(url, chrome::kChromeUISettingsHost, false) || | |
| 391 StartsWithASCII(url, kChromeWebstoreURL, false); | |
| 392 } | |
| 393 | |
| 358 void ManagedModeNavigationObserver::ClearObserverState() { | 394 void ManagedModeNavigationObserver::ClearObserverState() { |
| 359 if (preview_infobar_delegate_) { | 395 if (preview_infobar_delegate_) { |
| 360 InfoBarService* infobar_service = | 396 InfoBarService* infobar_service = |
| 361 InfoBarService::FromWebContents(web_contents()); | 397 InfoBarService::FromWebContents(web_contents()); |
| 362 infobar_service->RemoveInfoBar(preview_infobar_delegate_); | 398 infobar_service->RemoveInfoBar(preview_infobar_delegate_); |
| 363 preview_infobar_delegate_ = NULL; | 399 preview_infobar_delegate_ = NULL; |
| 364 } | 400 } |
| 365 navigated_urls_.clear(); | 401 navigated_urls_.clear(); |
| 366 last_url_ = GURL(); | 402 last_url_ = GURL(); |
| 367 state_ = RECORDING_URLS_BEFORE_PREVIEW; | 403 state_ = RECORDING_URLS_BEFORE_PREVIEW; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 380 // back to a blocked site here. | 416 // back to a blocked site here. |
| 381 if (web_contents()->GetController().GetCurrentEntryIndex() < | 417 if (web_contents()->GetController().GetCurrentEntryIndex() < |
| 382 last_allowed_page_) { | 418 last_allowed_page_) { |
| 383 ClearObserverState(); | 419 ClearObserverState(); |
| 384 } | 420 } |
| 385 } | 421 } |
| 386 | 422 |
| 387 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 423 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
| 388 const content::LoadCommittedDetails& details, | 424 const content::LoadCommittedDetails& details, |
| 389 const content::FrameNavigateParams& params) { | 425 const content::FrameNavigateParams& params) { |
| 426 if (!ShouldStayElevatedForURL(params.url)) | |
| 427 is_elevated_ = false; | |
| 390 | 428 |
| 391 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); | 429 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); |
| 392 | 430 |
| 393 ManagedModeURLFilter::FilteringBehavior behavior = | 431 ManagedModeURLFilter::FilteringBehavior behavior = |
| 394 url_filter_->GetFilteringBehaviorForURL(params.url); | 432 url_filter_->GetFilteringBehaviorForURL(params.url); |
| 395 | 433 |
| 396 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", | 434 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", |
| 397 behavior, | 435 behavior, |
| 398 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); | 436 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); |
| 399 | 437 |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 423 // so don't update the state yet. | 461 // so don't update the state yet. |
| 424 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | 462 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { |
| 425 AddTemporaryException(); | 463 AddTemporaryException(); |
| 426 } | 464 } |
| 427 | 465 |
| 428 // The navigation is complete, unless there is a redirect. So set the | 466 // The navigation is complete, unless there is a redirect. So set the |
| 429 // new navigation to false to detect user interaction. | 467 // new navigation to false to detect user interaction. |
| 430 got_user_gesture_ = false; | 468 got_user_gesture_ = false; |
| 431 } | 469 } |
| 432 | 470 |
| 433 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | |
| 434 int64 frame_id, | |
| 435 int64 parent_frame_id, | |
| 436 bool is_main_frame, | |
| 437 const GURL& validated_url, | |
| 438 bool is_error_page, | |
| 439 bool is_iframe_srcdoc, | |
| 440 content::RenderViewHost* render_view_host) { | |
| 441 if (!is_main_frame) | |
| 442 return; | |
| 443 } | |
| 444 | |
| 445 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 471 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 446 const GURL& url, | 472 const GURL& url, |
| 447 content::RenderViewHost* render_view_host) { | 473 content::RenderViewHost* render_view_host) { |
| 474 if (!ShouldStayElevatedForURL(url)) | |
| 475 is_elevated_ = false; | |
| 476 | |
| 448 // This function is the last one to be called before the resource throttle | 477 // This function is the last one to be called before the resource throttle |
| 449 // shows the interstitial if the URL must be blocked. | 478 // shows the interstitial if the URL must be blocked. |
| 450 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); | 479 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); |
| 451 ManagedModeURLFilter::FilteringBehavior behavior = | 480 ManagedModeURLFilter::FilteringBehavior behavior = |
| 452 url_filter_->GetFilteringBehaviorForURL(url); | 481 url_filter_->GetFilteringBehaviorForURL(url); |
| 453 | 482 |
| 454 if (behavior != ManagedModeURLFilter::BLOCK) | 483 if (behavior != ManagedModeURLFilter::BLOCK) |
| 455 return; | 484 return; |
| 456 | 485 |
| 457 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && | 486 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 504 if (behavior == ManagedModeURLFilter::ALLOW) | 533 if (behavior == ManagedModeURLFilter::ALLOW) |
| 505 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | 534 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
| 506 } | 535 } |
| 507 | 536 |
| 508 void ManagedModeNavigationObserver::DidGetUserGesture() { | 537 void ManagedModeNavigationObserver::DidGetUserGesture() { |
| 509 got_user_gesture_ = true; | 538 got_user_gesture_ = true; |
| 510 // Update the exception status so that the resource throttle knows that | 539 // Update the exception status so that the resource throttle knows that |
| 511 // there was a manual navigation. | 540 // there was a manual navigation. |
| 512 UpdateExceptionNavigationStatus(); | 541 UpdateExceptionNavigationStatus(); |
| 513 } | 542 } |
| OLD | NEW |