| 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" |
| 21 #include "chrome/browser/profiles/profile.h" | 22 #include "chrome/browser/profiles/profile.h" |
| 22 #include "chrome/browser/ui/browser.h" | 23 #include "chrome/browser/ui/browser.h" |
| 23 #include "chrome/browser/ui/browser_commands.h" | 24 #include "chrome/browser/ui/browser_commands.h" |
| 24 #include "chrome/browser/ui/browser_finder.h" | 25 #include "chrome/browser/ui/browser_finder.h" |
| 25 #include "chrome/browser/ui/browser_list.h" | 26 #include "chrome/browser/ui/browser_list.h" |
| 26 #include "chrome/browser/ui/host_desktop.h" | 27 #include "chrome/browser/ui/host_desktop.h" |
| 27 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 28 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 29 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 29 #include "chrome/common/url_constants.h" | 31 #include "chrome/common/url_constants.h" |
| 30 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 31 #include "content/public/browser/render_process_host.h" | 33 #include "content/public/browser/render_process_host.h" |
| 32 #include "content/public/browser/render_view_host.h" | 34 #include "content/public/browser/render_view_host.h" |
| 33 #include "content/public/browser/user_metrics.h" | 35 #include "content/public/browser/user_metrics.h" |
| 34 #include "content/public/browser/web_contents_delegate.h" | 36 #include "content/public/browser/web_contents_delegate.h" |
| 35 #include "content/public/browser/web_contents_view.h" | 37 #include "content/public/browser/web_contents_view.h" |
| 36 #include "content/public/common/frame_navigate_params.h" | 38 #include "content/public/common/frame_navigate_params.h" |
| 37 #include "grit/generated_resources.h" | 39 #include "grit/generated_resources.h" |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 RemoveTemporaryException(); | 258 RemoveTemporaryException(); |
| 257 } | 259 } |
| 258 | 260 |
| 259 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 261 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
| 260 content::WebContents* web_contents) | 262 content::WebContents* web_contents) |
| 261 : WebContentsObserver(web_contents), | 263 : WebContentsObserver(web_contents), |
| 262 warn_infobar_delegate_(NULL), | 264 warn_infobar_delegate_(NULL), |
| 263 preview_infobar_delegate_(NULL), | 265 preview_infobar_delegate_(NULL), |
| 264 got_user_gesture_(false), | 266 got_user_gesture_(false), |
| 265 state_(RECORDING_URLS_BEFORE_PREVIEW), | 267 state_(RECORDING_URLS_BEFORE_PREVIEW), |
| 268 is_elevated_(false), |
| 266 last_allowed_page_(-1) { | 269 last_allowed_page_(-1) { |
| 267 Profile* profile = | 270 Profile* profile = |
| 268 Profile::FromBrowserContext(web_contents->GetBrowserContext()); | 271 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 269 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); | 272 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
| 273 if (!managed_user_service_->ProfileIsManaged()) |
| 274 is_elevated_ = true; |
| 270 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); | 275 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); |
| 271 } | 276 } |
| 272 | 277 |
| 273 void ManagedModeNavigationObserver::AddTemporaryException() { | 278 void ManagedModeNavigationObserver::AddTemporaryException() { |
| 274 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 279 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 275 DCHECK(web_contents()); | 280 DCHECK(web_contents()); |
| 276 | 281 |
| 277 BrowserThread::PostTask( | 282 BrowserThread::PostTask( |
| 278 BrowserThread::IO, | 283 BrowserThread::IO, |
| 279 FROM_HERE, | 284 FROM_HERE, |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 334 urls, ManagedUserService::MANUAL_ALLOW); | 339 urls, ManagedUserService::MANUAL_ALLOW); |
| 335 if (last_url_.is_valid()) { | 340 if (last_url_.is_valid()) { |
| 336 std::vector<std::string> hosts; | 341 std::vector<std::string> hosts; |
| 337 hosts.push_back(last_url_.host()); | 342 hosts.push_back(last_url_.host()); |
| 338 managed_user_service_->SetManualBehaviorForHosts( | 343 managed_user_service_->SetManualBehaviorForHosts( |
| 339 hosts, ManagedUserService::MANUAL_ALLOW); | 344 hosts, ManagedUserService::MANUAL_ALLOW); |
| 340 } | 345 } |
| 341 ClearObserverState(); | 346 ClearObserverState(); |
| 342 } | 347 } |
| 343 | 348 |
| 349 bool ManagedModeNavigationObserver::is_elevated() const { |
| 350 return is_elevated_; |
| 351 } |
| 352 |
| 353 void ManagedModeNavigationObserver::set_elevated(bool is_elevated) { |
| 354 is_elevated_ = is_elevated; |
| 355 } |
| 356 |
| 344 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | 357 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
| 345 navigated_urls_.insert(url); | 358 navigated_urls_.insert(url); |
| 346 last_url_ = url; | 359 last_url_ = url; |
| 347 } | 360 } |
| 348 | 361 |
| 349 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { | 362 void ManagedModeNavigationObserver::SetStateToRecordingAfterPreview() { |
| 350 state_ = RECORDING_URLS_AFTER_PREVIEW; | 363 state_ = RECORDING_URLS_AFTER_PREVIEW; |
| 351 } | 364 } |
| 352 | 365 |
| 353 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( | 366 bool ManagedModeNavigationObserver::CanTemporarilyNavigateHost( |
| 354 const GURL& url) { | 367 const GURL& url) { |
| 355 return last_url_.host() == url.host(); | 368 return last_url_.host() == url.host(); |
| 356 } | 369 } |
| 357 | 370 |
| 371 bool ManagedModeNavigationObserver::ShouldStayElevatedForURL( |
| 372 const GURL& navigation_url) { |
| 373 std::string url = navigation_url.spec(); |
| 374 // Handle chrome:// URLs specially. |
| 375 if (navigation_url.host() == "chrome") { |
| 376 // The path contains the actual host name, but starts with a "/". Remove |
| 377 // the "/". |
| 378 url = navigation_url.path().substr(1); |
| 379 } |
| 380 |
| 381 // Check if any of the special URLs is a prefix of |url|. |
| 382 return StartsWithASCII(url, chrome::kChromeUIHistoryHost, false) || |
| 383 StartsWithASCII(url, chrome::kChromeUIExtensionsHost, false) || |
| 384 StartsWithASCII(url, chrome::kChromeUISettingsHost, false) || |
| 385 StartsWithASCII(url, extension_urls::kGalleryBrowsePrefix, false); |
| 386 } |
| 387 |
| 358 void ManagedModeNavigationObserver::ClearObserverState() { | 388 void ManagedModeNavigationObserver::ClearObserverState() { |
| 359 if (preview_infobar_delegate_) { | 389 if (preview_infobar_delegate_) { |
| 360 InfoBarService* infobar_service = | 390 InfoBarService* infobar_service = |
| 361 InfoBarService::FromWebContents(web_contents()); | 391 InfoBarService::FromWebContents(web_contents()); |
| 362 infobar_service->RemoveInfoBar(preview_infobar_delegate_); | 392 infobar_service->RemoveInfoBar(preview_infobar_delegate_); |
| 363 preview_infobar_delegate_ = NULL; | 393 preview_infobar_delegate_ = NULL; |
| 364 } | 394 } |
| 365 navigated_urls_.clear(); | 395 navigated_urls_.clear(); |
| 366 last_url_ = GURL(); | 396 last_url_ = GURL(); |
| 367 state_ = RECORDING_URLS_BEFORE_PREVIEW; | 397 state_ = RECORDING_URLS_BEFORE_PREVIEW; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 380 // back to a blocked site here. | 410 // back to a blocked site here. |
| 381 if (web_contents()->GetController().GetCurrentEntryIndex() < | 411 if (web_contents()->GetController().GetCurrentEntryIndex() < |
| 382 last_allowed_page_) { | 412 last_allowed_page_) { |
| 383 ClearObserverState(); | 413 ClearObserverState(); |
| 384 } | 414 } |
| 385 } | 415 } |
| 386 | 416 |
| 387 void ManagedModeNavigationObserver::DidNavigateMainFrame( | 417 void ManagedModeNavigationObserver::DidNavigateMainFrame( |
| 388 const content::LoadCommittedDetails& details, | 418 const content::LoadCommittedDetails& details, |
| 389 const content::FrameNavigateParams& params) { | 419 const content::FrameNavigateParams& params) { |
| 420 if (!ShouldStayElevatedForURL(params.url)) |
| 421 is_elevated_ = false; |
| 390 | 422 |
| 391 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); | 423 content::RecordAction(UserMetricsAction("ManagedMode_MainFrameNavigation")); |
| 392 | 424 |
| 393 ManagedModeURLFilter::FilteringBehavior behavior = | 425 ManagedModeURLFilter::FilteringBehavior behavior = |
| 394 url_filter_->GetFilteringBehaviorForURL(params.url); | 426 url_filter_->GetFilteringBehaviorForURL(params.url); |
| 395 | 427 |
| 396 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", | 428 UMA_HISTOGRAM_ENUMERATION("ManagedMode.FilteringBehavior", |
| 397 behavior, | 429 behavior, |
| 398 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); | 430 ManagedModeURLFilter::HISTOGRAM_BOUNDING_VALUE); |
| 399 | 431 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 423 // so don't update the state yet. | 455 // so don't update the state yet. |
| 424 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { | 456 if (state_ == RECORDING_URLS_AFTER_PREVIEW) { |
| 425 AddTemporaryException(); | 457 AddTemporaryException(); |
| 426 } | 458 } |
| 427 | 459 |
| 428 // The navigation is complete, unless there is a redirect. So set the | 460 // The navigation is complete, unless there is a redirect. So set the |
| 429 // new navigation to false to detect user interaction. | 461 // new navigation to false to detect user interaction. |
| 430 got_user_gesture_ = false; | 462 got_user_gesture_ = false; |
| 431 } | 463 } |
| 432 | 464 |
| 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( | 465 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 446 const GURL& url, | 466 const GURL& url, |
| 447 content::RenderViewHost* render_view_host) { | 467 content::RenderViewHost* render_view_host) { |
| 468 if (!ShouldStayElevatedForURL(url)) |
| 469 is_elevated_ = false; |
| 470 |
| 448 // This function is the last one to be called before the resource throttle | 471 // This function is the last one to be called before the resource throttle |
| 449 // shows the interstitial if the URL must be blocked. | 472 // shows the interstitial if the URL must be blocked. |
| 450 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); | 473 DVLOG(1) << "ProvisionalChangeToMainFrameURL " << url.spec(); |
| 451 ManagedModeURLFilter::FilteringBehavior behavior = | 474 ManagedModeURLFilter::FilteringBehavior behavior = |
| 452 url_filter_->GetFilteringBehaviorForURL(url); | 475 url_filter_->GetFilteringBehaviorForURL(url); |
| 453 | 476 |
| 454 if (behavior != ManagedModeURLFilter::BLOCK) | 477 if (behavior != ManagedModeURLFilter::BLOCK) |
| 455 return; | 478 return; |
| 456 | 479 |
| 457 if (state_ == RECORDING_URLS_AFTER_PREVIEW && got_user_gesture_ && | 480 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) | 527 if (behavior == ManagedModeURLFilter::ALLOW) |
| 505 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | 528 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
| 506 } | 529 } |
| 507 | 530 |
| 508 void ManagedModeNavigationObserver::DidGetUserGesture() { | 531 void ManagedModeNavigationObserver::DidGetUserGesture() { |
| 509 got_user_gesture_ = true; | 532 got_user_gesture_ = true; |
| 510 // Update the exception status so that the resource throttle knows that | 533 // Update the exception status so that the resource throttle knows that |
| 511 // there was a manual navigation. | 534 // there was a manual navigation. |
| 512 UpdateExceptionNavigationStatus(); | 535 UpdateExceptionNavigationStatus(); |
| 513 } | 536 } |
| OLD | NEW |