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

Side by Side Diff: chrome/browser/managed_mode/managed_mode_resource_throttle.cc

Issue 12887005: Show interstitial from ManagedModeNavigationObserver instead of ManagedModeResourceThrottle. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 9 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 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 "base/lazy_instance.h"
8 #include "base/location.h"
8 #include "chrome/browser/managed_mode/managed_mode.h" 9 #include "chrome/browser/managed_mode/managed_mode.h"
9 #include "chrome/browser/managed_mode/managed_mode_interstitial.h" 10 #include "chrome/browser/managed_mode/managed_mode_navigation_observer.h"
10 #include "chrome/browser/managed_mode/managed_mode_url_filter.h" 11 #include "chrome/browser/managed_mode/managed_mode_url_filter.h"
12 #include "content/public/browser/browser_thread.h"
11 #include "content/public/browser/resource_controller.h" 13 #include "content/public/browser/resource_controller.h"
12 #include "net/url_request/url_request.h" 14 #include "net/url_request/url_request.h"
13 15
16 using content::BrowserThread;
17
14 namespace { 18 namespace {
15 19
16 // Uniquely identifies a tab, used to set a temporary exception on it. 20 // Uniquely identifies a tab, used to set a temporary exception on it.
17 struct WebContentsId { 21 struct WebContentsId {
18 WebContentsId(int render_process_host_id, int render_view_id) 22 WebContentsId(int render_process_host_id, int render_view_id)
19 : render_process_host_id(render_process_host_id), 23 : render_process_host_id(render_process_host_id),
20 render_view_id(render_view_id) {} 24 render_view_id(render_view_id) {}
21 25
22 bool operator<(const WebContentsId& key) const { 26 bool operator<(const WebContentsId& key) const {
23 if (render_process_host_id != key.render_process_host_id) 27 if (render_process_host_id != key.render_process_host_id)
(...skipping 13 matching lines...) Expand all
37 }; 41 };
38 42
39 // This map contains <render_process_host_id_, render_view_id> pairs mapped 43 // This map contains <render_process_host_id_, render_view_id> pairs mapped
40 // to |TemporaryExceptionData| which identifies individual tabs. If a 44 // to |TemporaryExceptionData| which identifies individual tabs. If a
41 // |TemporaryExceptionData| is present for a specific pair then the user 45 // |TemporaryExceptionData| is present for a specific pair then the user
42 // clicked preview, is navigating around and has not clicked one of the options 46 // clicked preview, is navigating around and has not clicked one of the options
43 // on the infobar. 47 // on the infobar.
44 typedef std::map<WebContentsId, TemporaryExceptionData> PreviewMap; 48 typedef std::map<WebContentsId, TemporaryExceptionData> PreviewMap;
45 base::LazyInstance<PreviewMap> g_in_preview_mode = LAZY_INSTANCE_INITIALIZER; 49 base::LazyInstance<PreviewMap> g_in_preview_mode = LAZY_INSTANCE_INITIALIZER;
46 50
47 } 51 } // namespace
48 52
49 ManagedModeResourceThrottle::ManagedModeResourceThrottle( 53 ManagedModeResourceThrottle::ManagedModeResourceThrottle(
50 const net::URLRequest* request, 54 const net::URLRequest* request,
51 int render_process_host_id, 55 int render_process_host_id,
52 int render_view_id, 56 int render_view_id,
53 bool is_main_frame, 57 bool is_main_frame,
54 const ManagedModeURLFilter* url_filter) 58 const ManagedModeURLFilter* url_filter)
55 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)), 59 : ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)),
56 request_(request), 60 request_(request),
57 render_process_host_id_(render_process_host_id), 61 render_process_host_id_(render_process_host_id),
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 WebContentsId web_contents_id(render_process_host_id_, render_view_id_); 124 WebContentsId web_contents_id(render_process_host_id_, render_view_id_);
121 PreviewMap::iterator it = preview_map->find(web_contents_id); 125 PreviewMap::iterator it = preview_map->find(web_contents_id);
122 if (it != preview_map->end() && 126 if (it != preview_map->end() &&
123 (!it->second.new_navigation || url.host() == it->second.host)) { 127 (!it->second.new_navigation || url.host() == it->second.host)) {
124 temporarily_allowed_ = true; 128 temporarily_allowed_ = true;
125 RemoveTemporaryException(render_process_host_id_, render_view_id_); 129 RemoveTemporaryException(render_process_host_id_, render_view_id_);
126 return; 130 return;
127 } 131 }
128 132
129 *defer = true; 133 *defer = true;
130 ManagedModeInterstitial::ShowInterstitial( 134
131 render_process_host_id_, render_view_id_, url, 135 BrowserThread::PostTask(
132 base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult, 136 BrowserThread::UI, FROM_HERE,
133 weak_ptr_factory_.GetWeakPtr())); 137 base::Bind(&ManagedModeNavigationObserver::DidBlockRequest,
138 render_process_host_id_, render_view_id_, url,
Adrian Kuegel 2013/03/28 14:28:34 Could |render_view_id_| and |url| be in an extra l
Bernhard Bauer 2013/03/28 15:03:30 See my comments in https://codereview.chromium.org
Adrian Kuegel 2013/03/28 15:11:11 I think it is readable enough as it is.
139 base::Bind(&ManagedModeResourceThrottle::OnInterstitialResult,
140 weak_ptr_factory_.GetWeakPtr())));
134 } 141 }
135 142
136 void ManagedModeResourceThrottle::WillStartRequest(bool* defer) { 143 void ManagedModeResourceThrottle::WillStartRequest(bool* defer) {
137 ShowInterstitialIfNeeded(false, request_->url(), defer); 144 ShowInterstitialIfNeeded(false, request_->url(), defer);
138 } 145 }
139 146
140 void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url, 147 void ManagedModeResourceThrottle::WillRedirectRequest(const GURL& new_url,
141 bool* defer) { 148 bool* defer) {
142 ShowInterstitialIfNeeded(true, new_url, defer); 149 ShowInterstitialIfNeeded(true, new_url, defer);
143 } 150 }
144 151
145 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) { 152 void ManagedModeResourceThrottle::OnInterstitialResult(bool continue_request) {
146 if (continue_request) { 153 if (continue_request) {
147 temporarily_allowed_ = true; 154 temporarily_allowed_ = true;
148 controller()->Resume(); 155 controller()->Resume();
149 } else { 156 } else {
150 controller()->Cancel(); 157 controller()->Cancel();
151 } 158 }
152 } 159 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698