| 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/string_number_conversions.h" | 9 #include "base/string_number_conversions.h" |
| 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" | 10 #include "chrome/browser/api/infobars/confirm_infobar_delegate.h" |
| 11 #include "chrome/browser/api/infobars/infobar_service.h" | 11 #include "chrome/browser/api/infobars/infobar_service.h" |
| 12 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" | 12 #include "chrome/browser/api/infobars/simple_alert_infobar_delegate.h" |
| 13 #include "chrome/browser/managed_mode/managed_mode.h" | 13 #include "chrome/browser/managed_mode/managed_mode.h" |
| 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" | 14 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| 15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" | 15 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
| 16 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" | 16 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| 17 #include "chrome/browser/managed_mode/managed_user_service.h" |
| 18 #include "chrome/browser/managed_mode/managed_user_service_factory.h" |
| 17 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 20 #include "chrome/browser/ui/browser_commands.h" | 22 #include "chrome/browser/ui/browser_commands.h" |
| 21 #include "chrome/browser/ui/browser_finder.h" | 23 #include "chrome/browser/ui/browser_finder.h" |
| 22 #include "chrome/browser/ui/browser_list.h" | 24 #include "chrome/browser/ui/browser_list.h" |
| 23 #include "chrome/common/jstemplate_builder.h" | 25 #include "chrome/common/jstemplate_builder.h" |
| 24 #include "chrome/common/pref_names.h" | 26 #include "chrome/common/pref_names.h" |
| 25 #include "chrome/common/url_constants.h" | 27 #include "chrome/common/url_constants.h" |
| 26 #include "content/public/browser/browser_thread.h" | 28 #include "content/public/browser/browser_thread.h" |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 | 226 |
| 225 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); | 227 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ManagedModeNavigationObserver); |
| 226 | 228 |
| 227 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { | 229 ManagedModeNavigationObserver::~ManagedModeNavigationObserver() { |
| 228 RemoveTemporaryException(); | 230 RemoveTemporaryException(); |
| 229 } | 231 } |
| 230 | 232 |
| 231 ManagedModeNavigationObserver::ManagedModeNavigationObserver( | 233 ManagedModeNavigationObserver::ManagedModeNavigationObserver( |
| 232 content::WebContents* web_contents) | 234 content::WebContents* web_contents) |
| 233 : WebContentsObserver(web_contents), | 235 : WebContentsObserver(web_contents), |
| 234 url_filter_(ManagedMode::GetURLFilterForUIThread()), | |
| 235 warn_infobar_delegate_(NULL), | 236 warn_infobar_delegate_(NULL), |
| 236 preview_infobar_delegate_(NULL), | 237 preview_infobar_delegate_(NULL), |
| 237 state_(RECORDING_URLS_BEFORE_PREVIEW), | 238 state_(RECORDING_URLS_BEFORE_PREVIEW), |
| 238 last_allowed_page_(-1) {} | 239 last_allowed_page_(-1) { |
| 240 Profile* profile = |
| 241 Profile::FromBrowserContext(web_contents->GetBrowserContext()); |
| 242 managed_user_service_ = ManagedUserServiceFactory::GetForProfile(profile); |
| 243 url_filter_ = managed_user_service_->GetURLFilterForUIThread(); |
| 244 } |
| 239 | 245 |
| 240 void ManagedModeNavigationObserver::AddTemporaryException() { | 246 void ManagedModeNavigationObserver::AddTemporaryException() { |
| 241 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 247 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 242 DCHECK(web_contents()); | 248 DCHECK(web_contents()); |
| 243 | 249 |
| 244 BrowserThread::PostTask( | 250 BrowserThread::PostTask( |
| 245 BrowserThread::IO, | 251 BrowserThread::IO, |
| 246 FROM_HERE, | 252 FROM_HERE, |
| 247 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, | 253 base::Bind(&ManagedModeResourceThrottle::AddTemporaryException, |
| 248 web_contents()->GetRenderProcessHost()->GetID(), | 254 web_contents()->GetRenderProcessHost()->GetID(), |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 ++it) { | 288 ++it) { |
| 283 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); | 289 whitelist.AppendString(it->scheme() + "://." + it->host() + it->path()); |
| 284 } | 290 } |
| 285 if (last_url_.is_valid()) { | 291 if (last_url_.is_valid()) { |
| 286 if (last_url_.SchemeIs("https")) { | 292 if (last_url_.SchemeIs("https")) { |
| 287 whitelist.AppendString("https://" + last_url_.host()); | 293 whitelist.AppendString("https://" + last_url_.host()); |
| 288 } else { | 294 } else { |
| 289 whitelist.AppendString(last_url_.host()); | 295 whitelist.AppendString(last_url_.host()); |
| 290 } | 296 } |
| 291 } | 297 } |
| 292 ManagedMode::AddToManualList(true, whitelist); | 298 managed_user_service_->AddToManualList(true, whitelist); |
| 293 ClearObserverState(); | 299 ClearObserverState(); |
| 294 } | 300 } |
| 295 | 301 |
| 296 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { | 302 void ManagedModeNavigationObserver::AddURLToPatternList(const GURL& url) { |
| 297 DCHECK(state_ != NOT_RECORDING_URLS); | 303 DCHECK(state_ != NOT_RECORDING_URLS); |
| 298 navigated_urls_.insert(url); | 304 navigated_urls_.insert(url); |
| 299 } | 305 } |
| 300 | 306 |
| 301 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { | 307 void ManagedModeNavigationObserver::AddURLAsLastPattern(const GURL& url) { |
| 302 DCHECK(state_ != NOT_RECORDING_URLS); | 308 DCHECK(state_ != NOT_RECORDING_URLS); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 // A temporary exception should be added only if an interstitial was shown, | 385 // A temporary exception should be added only if an interstitial was shown, |
| 380 // the user clicked preview and the final page was not allowed. This | 386 // the user clicked preview and the final page was not allowed. This |
| 381 // temporary exception stops the interstitial from showing on further | 387 // temporary exception stops the interstitial from showing on further |
| 382 // navigations to that host so that the user can navigate around to | 388 // navigations to that host so that the user can navigate around to |
| 383 // inspect it. | 389 // inspect it. |
| 384 state_ = NOT_RECORDING_URLS; | 390 state_ = NOT_RECORDING_URLS; |
| 385 AddTemporaryException(); | 391 AddTemporaryException(); |
| 386 } | 392 } |
| 387 } | 393 } |
| 388 | 394 |
| 389 void ManagedModeNavigationObserver::DidStartProvisionalLoadForFrame( | |
| 390 int64 frame_id, | |
| 391 int64 parent_frame_id, | |
| 392 bool is_main_frame, | |
| 393 const GURL& validated_url, | |
| 394 bool is_error_page, | |
| 395 bool is_iframe_srcdoc, | |
| 396 content::RenderViewHost* render_view_host) { | |
| 397 if (!is_main_frame) | |
| 398 return; | |
| 399 } | |
| 400 | |
| 401 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( | 395 void ManagedModeNavigationObserver::ProvisionalChangeToMainFrameUrl( |
| 402 const GURL& url, | 396 const GURL& url, |
| 403 content::RenderViewHost* render_view_host) { | 397 content::RenderViewHost* render_view_host) { |
| 404 // This function is the last one to be called before the resource throttle | 398 // This function is the last one to be called before the resource throttle |
| 405 // shows the interstitial if the URL must be blocked. | 399 // shows the interstitial if the URL must be blocked. |
| 406 ManagedModeURLFilter::FilteringBehavior behavior = | 400 ManagedModeURLFilter::FilteringBehavior behavior = |
| 407 url_filter_->GetFilteringBehaviorForURL(url); | 401 url_filter_->GetFilteringBehaviorForURL(url); |
| 408 | 402 |
| 409 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) | 403 if (state_ == NOT_RECORDING_URLS && !CanTemporarilyNavigateHost(url)) |
| 410 ClearObserverState(); | 404 ClearObserverState(); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 case NOT_RECORDING_URLS: | 450 case NOT_RECORDING_URLS: |
| 457 // Check that the infobar is present. | 451 // Check that the infobar is present. |
| 458 DCHECK(preview_infobar_delegate_); | 452 DCHECK(preview_infobar_delegate_); |
| 459 break; | 453 break; |
| 460 } | 454 } |
| 461 } | 455 } |
| 462 | 456 |
| 463 if (behavior == ManagedModeURLFilter::ALLOW) | 457 if (behavior == ManagedModeURLFilter::ALLOW) |
| 464 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); | 458 last_allowed_page_ = web_contents()->GetController().GetCurrentEntryIndex(); |
| 465 } | 459 } |
| OLD | NEW |