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

Unified Diff: chrome/browser/managed_mode/managed_mode_resource_throttle.cc

Issue 11299035: Support manual (white|black)list, previewing and allowing after interstitial (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Minor changes Created 7 years, 11 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 side-by-side diff with in-line comments
Download patch
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 5d95d093fcef713e300d3e6bbdecf3a8f232d6a0..a8f60eeab48cd573d89765340e4dc5c3c419f295 100644
--- a/chrome/browser/managed_mode/managed_mode_resource_throttle.cc
+++ b/chrome/browser/managed_mode/managed_mode_resource_throttle.cc
@@ -4,12 +4,24 @@
#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 "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;
+base::LazyInstance<PreviewMap> g_in_preview_mode = LAZY_INSTANCE_INITIALIZER;
+
+}
+
ManagedModeResourceThrottle::ManagedModeResourceThrottle(
const net::URLRequest* request,
int render_process_host_id,
@@ -20,27 +32,72 @@ ManagedModeResourceThrottle::ManagedModeResourceThrottle(
render_process_host_id_(render_process_host_id),
render_view_id_(render_view_id),
is_main_frame_(is_main_frame),
+ temporarily_allowed_(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 GURL& url) {
+ g_in_preview_mode.Get()[std::make_pair(render_process_host_id,
+ render_view_id)] = url.host();
+}
+
+// static
+void ManagedModeResourceThrottle::RemoveTemporaryException(
+ int render_process_host_id,
+ int render_view_id) {
+ g_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 (ignoring 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()));
+ // 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 = g_in_preview_mode.Pointer();
+ if (temporarily_allowed_) {
+ 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) {
+ temporarily_allowed_ = true;
controller()->Resume();
} else {
controller()->Cancel();
« no previous file with comments | « chrome/browser/managed_mode/managed_mode_resource_throttle.h ('k') | chrome/browser/managed_mode/managed_mode_url_filter.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698