Chromium Code Reviews| Index: chrome/browser/managed_mode/managed_mode_resource_throttle.cc |
| diff --git a/chrome/browser/managed_mode/managed_mode_resource_throttle.cc b/chrome/browser/managed_mode/managed_mode_resource_throttle.cc |
| index 7e6b28e4c09c574cdb002f896663425db5e6bad1..c04a878683367fee123c972f431b77370bea3b50 100644 |
| --- a/chrome/browser/managed_mode/managed_mode_resource_throttle.cc |
| +++ b/chrome/browser/managed_mode/managed_mode_resource_throttle.cc |
| @@ -4,13 +4,25 @@ |
| #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h" |
| +#include "base/lazy_instance.h" |
| #include "chrome/browser/managed_mode/managed_mode.h" |
| #include "chrome/browser/managed_mode/managed_mode_interstitial.h" |
| #include "chrome/browser/managed_mode/managed_mode_url_filter.h" |
| -#include "chrome/browser/policy/url_blacklist_manager.h" |
| #include "content/public/browser/resource_controller.h" |
| #include "net/url_request/url_request.h" |
| +namespace { |
| + |
| +// This map contains <render_process_host_id_, render_view_id> pairs mapped |
| +// to hostnames which identify individual tabs. If a hostname |
| +// is present for a specific pair then the user clicked preview, is |
| +// navigating around and has not clicked one of the options on the infobar. |
| +typedef std::map<std::pair<int, int>, std::string> PreviewMap; |
| +static base::LazyInstance<PreviewMap> |
|
Bernhard Bauer
2012/11/27 18:44:46
"static" isn't necessary if you're in an anonymous
Sergiu
2012/11/28 12:53:25
Done.
|
| + in_preview_mode = LAZY_INSTANCE_INITIALIZER; |
|
Bernhard Bauer
2012/11/27 18:44:46
Maybe name this |g_in_preview_mode|?
Sergiu
2012/11/28 12:53:25
Done.
|
| + |
| +} |
| + |
| ManagedModeResourceThrottle::ManagedModeResourceThrottle( |
| const net::URLRequest* request, |
| int render_process_host_id, |
| @@ -21,29 +33,72 @@ ManagedModeResourceThrottle::ManagedModeResourceThrottle( |
| render_process_host_id_(render_process_host_id), |
| render_view_id_(render_view_id), |
| is_main_frame_(is_main_frame), |
| + after_interstitial_(false), |
| url_filter_(ManagedMode::GetURLFilterForIOThread()) {} |
| ManagedModeResourceThrottle::~ManagedModeResourceThrottle() {} |
| -void ManagedModeResourceThrottle::WillStartRequest(bool* defer) { |
| - if (url_filter_->GetFilteringBehaviorForURL(request_->url()) != |
| +// static |
| +void ManagedModeResourceThrottle::AddTemporaryException( |
| + int render_process_host_id, |
| + int render_view_id, |
| + const std::string& host) { |
| + in_preview_mode.Get().insert( |
| + std::make_pair(std::make_pair(render_process_host_id, render_view_id), |
| + host)); |
| +} |
| + |
| +// static |
| +void ManagedModeResourceThrottle::RemoveTemporaryException( |
| + int render_process_host_id, |
| + int render_view_id) { |
| + in_preview_mode.Get().erase(std::make_pair(render_process_host_id, |
| + render_view_id)); |
| +} |
| + |
| +void ManagedModeResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect, |
| + const GURL& url, |
| + bool* defer) { |
| + // Only treat main frame requests for now (without subresources). |
| + if (!is_main_frame_) |
| + return; |
| + |
| + if (url_filter_->GetFilteringBehaviorForURL(url) != |
| ManagedModeURLFilter::BLOCK) |
| return; |
| - if (is_main_frame_) { |
| - *defer = true; |
| - ManagedModeInterstitial::ShowInterstitial( |
| - render_process_host_id_, render_view_id_, request_->url(), |
| - base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult, |
| - weak_ptr_factory_.GetWeakPtr())); |
| - } else { |
| - // NOTREACHED(); |
| - // XXX |
| + // Do not show interstitial for redirects in preview mode and URLs which have |
| + // the same hostname as the one on which the user clicked "Preview" on. |
| + PreviewMap* preview_map = in_preview_mode.Pointer(); |
| + if (after_interstitial_) { |
| + DCHECK(is_redirect); |
| + return; |
| } |
| + |
| + PreviewMap::iterator it = preview_map->find( |
| + std::make_pair(render_process_host_id_, render_view_id_)); |
| + if (it != preview_map->end() && url.host() == it->second) |
| + return; |
| + |
| + *defer = true; |
| + ManagedModeInterstitial::ShowInterstitial( |
| + render_process_host_id_, render_view_id_, url, |
| + base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult, |
| + weak_ptr_factory_.GetWeakPtr())); |
| +} |
| + |
| +void ManagedModeResourceThrottle::WillStartRequest(bool* defer) { |
| + ShowInterstitialIfNeeded(false, request_->url(), defer); |
| +} |
| + |
| +void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url, |
| + bool* defer) { |
| + ShowInterstitialIfNeeded(true, new_url, defer); |
| } |
| void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) { |
| if (continue_request) { |
| + after_interstitial_ = true; |
| controller()->Resume(); |
| } else { |
| controller()->Cancel(); |