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

Side by Side 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: Removing default in switch. Created 8 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_resource_throttle.h" 5 #include "chrome/browser/managed_mode/managed_mode_resource_throttle.h"
6 6
7 #include "base/lazy_instance.h"
7 #include "chrome/browser/managed_mode/managed_mode.h" 8 #include "chrome/browser/managed_mode/managed_mode.h"
8 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" 9 #include "chrome/browser/managed_mode/managed_mode_interstitial.h"
9 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
10 #include "chrome/browser/policy/url_blacklist_manager.h"
11 #include "content/public/browser/resource_controller.h" 11 #include "content/public/browser/resource_controller.h"
12 #include "net/url_request/url_request.h" 12 #include "net/url_request/url_request.h"
13 13
14 namespace {
15
16 // This map contains <render_process_host_id_, render_view_id> pairs mapped
17 // to hostnames which identify individual tabs. If a hostname
18 // is present for a specific pair then the user clicked preview, is
19 // navigating around and has not clicked one of the options on the infobar.
20 typedef std::map<std::pair<int, int>, std::string> PreviewMap;
21 base::LazyInstance<PreviewMap> g_in_preview_mode = LAZY_INSTANCE_INITIALIZER;
22
23 }
24
14 ManagedModeResourceThrottle::ManagedModeResourceThrottle( 25 ManagedModeResourceThrottle::ManagedModeResourceThrottle(
15 const net::URLRequest* request, 26 const net::URLRequest* request,
16 int render_process_host_id, 27 int render_process_host_id,
17 int render_view_id, 28 int render_view_id,
18 bool is_main_frame) 29 bool is_main_frame)
19 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 30 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
20 request_(request), 31 request_(request),
21 render_process_host_id_(render_process_host_id), 32 render_process_host_id_(render_process_host_id),
22 render_view_id_(render_view_id), 33 render_view_id_(render_view_id),
23 is_main_frame_(is_main_frame), 34 is_main_frame_(is_main_frame),
35 after_interstitial_(false),
24 url_filter_(ManagedMode::GetURLFilterForIOThread()) {} 36 url_filter_(ManagedMode::GetURLFilterForIOThread()) {}
25 37
26 ManagedModeResourceThrottle::~ManagedModeResourceThrottle() {} 38 ManagedModeResourceThrottle::~ManagedModeResourceThrottle() {}
27 39
28 void ManagedModeResourceThrottle::WillStartRequest(bool* defer) { 40 // static
29 if (url_filter_->GetFilteringBehaviorForURL(request_->url()) != 41 void ManagedModeResourceThrottle::AddTemporaryException(
42 int render_process_host_id,
43 int render_view_id,
44 const GURL& url) {
45 g_in_preview_mode.Get().insert(
46 std::make_pair(std::make_pair(render_process_host_id, render_view_id),
47 url.host()));
Pam (message me for reviews) 2012/12/06 15:11:56 Is there not a more readable way to write this? st
Sergiu 2013/01/04 15:44:07 Done.
48 }
49
50 // static
51 void ManagedModeResourceThrottle::RemoveTemporaryException(
52 int render_process_host_id,
53 int render_view_id) {
54 g_in_preview_mode.Get().erase(std::make_pair(render_process_host_id,
55 render_view_id));
56 }
57
58 void ManagedModeResourceThrottle::ShowInterstitialIfNeeded(bool is_redirect,
59 const GURL& url,
60 bool* defer) {
61 // Only treat main frame requests for now (without subresources).
Pam (message me for reviews) 2012/12/06 15:11:56 This makes it sound like you only treat main-frame
Sergiu 2013/01/04 15:44:07 Done.
62 if (!is_main_frame_)
63 return;
64
65 if (url_filter_->GetFilteringBehaviorForURL(url) !=
30 ManagedModeURLFilter::BLOCK) 66 ManagedModeURLFilter::BLOCK)
31 return; 67 return;
Pam (message me for reviews) 2012/12/06 15:11:56 Using brackets with a multi-line condition would b
Sergiu 2013/01/04 15:44:07 Done.
32 68
33 if (is_main_frame_) { 69 // Do not show interstitial for redirects in preview mode and URLs which have
34 *defer = true; 70 // the same hostname as the one on which the user clicked "Preview" on.
35 ManagedModeInterstitial::ShowInterstitial( 71 PreviewMap* preview_map = g_in_preview_mode.Pointer();
36 render_process_host_id_, render_view_id_, request_->url(), 72 if (after_interstitial_) {
37 base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult, 73 DCHECK(is_redirect);
38 weak_ptr_factory_.GetWeakPtr())); 74 return;
39 } else {
40 // NOTREACHED();
41 // XXX
42 } 75 }
76
77 PreviewMap::iterator it = preview_map->find(
78 std::make_pair(render_process_host_id_, render_view_id_));
79 if (it != preview_map->end() && url.host() == it->second)
80 return;
81
82 *defer = true;
83 ManagedModeInterstitial::ShowInterstitial(
84 render_process_host_id_, render_view_id_, url,
85 base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult,
86 weak_ptr_factory_.GetWeakPtr()));
87 }
88
89 void ManagedModeResourceThrottle::WillStartRequest(bool* defer) {
90 ShowInterstitialIfNeeded(false, request_->url(), defer);
91 }
92
93 void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url,
94 bool* defer) {
95 ShowInterstitialIfNeeded(true, new_url, defer);
43 } 96 }
44 97
45 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) { 98 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) {
46 if (continue_request) { 99 if (continue_request) {
100 after_interstitial_ = true;
47 controller()->Resume(); 101 controller()->Resume();
48 } else { 102 } else {
49 controller()->Cancel(); 103 controller()->Cancel();
50 } 104 }
51 } 105 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698