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

Side by Side Diff: extensions/browser/api/web_request/web_request_api.cc

Issue 2455393002: PS - Adjusting webRequest API for use in Public Sessions (Closed)
Patch Set: Fixed unittest Created 4 years, 1 month 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
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 "extensions/browser/api/web_request/web_request_api.h" 5 #include "extensions/browser/api/web_request/web_request_api.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <memory> 10 #include <memory>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/bind_helpers.h" 15 #include "base/bind_helpers.h"
16 #include "base/json/json_writer.h" 16 #include "base/json/json_writer.h"
17 #include "base/lazy_instance.h" 17 #include "base/lazy_instance.h"
18 #include "base/macros.h" 18 #include "base/macros.h"
19 #include "base/metrics/histogram.h" 19 #include "base/metrics/histogram.h"
20 #include "base/strings/string_number_conversions.h" 20 #include "base/strings/string_number_conversions.h"
21 #include "base/strings/string_util.h" 21 #include "base/strings/string_util.h"
22 #include "base/strings/utf_string_conversions.h" 22 #include "base/strings/utf_string_conversions.h"
23 #include "base/time/time.h" 23 #include "base/time/time.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chromeos/login/login_state.h"
25 #include "content/public/browser/browser_thread.h" 26 #include "content/public/browser/browser_thread.h"
26 #include "content/public/browser/resource_request_info.h" 27 #include "content/public/browser/resource_request_info.h"
27 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
28 #include "content/public/common/browser_side_navigation_policy.h" 29 #include "content/public/common/browser_side_navigation_policy.h"
29 #include "content/public/common/child_process_host.h" 30 #include "content/public/common/child_process_host.h"
30 #include "extensions/browser/api/activity_log/web_request_constants.h" 31 #include "extensions/browser/api/activity_log/web_request_constants.h"
31 #include "extensions/browser/api/declarative/rules_registry_service.h" 32 #include "extensions/browser/api/declarative/rules_registry_service.h"
32 #include "extensions/browser/api/declarative_webrequest/request_stage.h" 33 #include "extensions/browser/api/declarative_webrequest/request_stage.h"
33 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h" 34 #include "extensions/browser/api/declarative_webrequest/webrequest_constants.h"
34 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h" 35 #include "extensions/browser/api/declarative_webrequest/webrequest_rules_registr y.h"
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 // We hide events from the system context as well as sensitive requests. 332 // We hide events from the system context as well as sensitive requests.
332 bool ShouldHideEvent(void* browser_context, 333 bool ShouldHideEvent(void* browser_context,
333 const InfoMap* extension_info_map, 334 const InfoMap* extension_info_map,
334 const net::URLRequest* request, 335 const net::URLRequest* request,
335 ExtensionNavigationUIData* navigation_ui_data) { 336 ExtensionNavigationUIData* navigation_ui_data) {
336 return (!browser_context || 337 return (!browser_context ||
337 WebRequestPermissions::HideRequest(extension_info_map, request, 338 WebRequestPermissions::HideRequest(extension_info_map, request,
338 navigation_ui_data)); 339 navigation_ui_data));
339 } 340 }
340 341
342 // Returns true if we're in a Public Session.
343 bool IsPublicSession() {
344 #if defined(OS_CHROMEOS)
345 if (chromeos::LoginState::IsInitialized()) {
346 return chromeos::LoginState::Get()->IsPublicSessionUser();
347 }
348 #endif
349 return false;
350 }
351
341 } // namespace 352 } // namespace
342 353
343 WebRequestAPI::WebRequestAPI(content::BrowserContext* context) 354 WebRequestAPI::WebRequestAPI(content::BrowserContext* context)
344 : browser_context_(context) { 355 : browser_context_(context) {
345 EventRouter* event_router = EventRouter::Get(browser_context_); 356 EventRouter* event_router = EventRouter::Get(browser_context_);
346 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) { 357 for (size_t i = 0; i < arraysize(kWebRequestEvents); ++i) {
347 // Observe the webRequest event. 358 // Observe the webRequest event.
348 std::string event_name = kWebRequestEvents[i]; 359 std::string event_name = kWebRequestEvents[i];
349 event_router->RegisterObserver(this, event_name); 360 event_router->RegisterObserver(this, event_name);
350 361
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 std::string event_name = 1121 std::string event_name =
1111 EventRouter::GetBaseEventName((*listener_ids)[0].sub_event_name); 1122 EventRouter::GetBaseEventName((*listener_ids)[0].sub_event_name);
1112 DCHECK(IsWebRequestEvent(event_name)); 1123 DCHECK(IsWebRequestEvent(event_name));
1113 1124
1114 Listeners& event_listeners = listeners_[browser_context][event_name]; 1125 Listeners& event_listeners = listeners_[browser_context][event_name];
1115 void* cross_browser_context = GetCrossBrowserContext(browser_context); 1126 void* cross_browser_context = GetCrossBrowserContext(browser_context);
1116 Listeners* cross_event_listeners = 1127 Listeners* cross_event_listeners =
1117 cross_browser_context ? &listeners_[cross_browser_context][event_name] 1128 cross_browser_context ? &listeners_[cross_browser_context][event_name]
1118 : nullptr; 1129 : nullptr;
1119 1130
1131 // In Public Sessions we want to restrict access to security or privacy
1132 // sensitive data. Data is filtered for *all* listeners, not only extensions
1133 // which are force-installed by policy.
1134 if (IsPublicSession()) {
1135 event_details->FilterForPublicSession();
1136 }
1137
1120 for (const EventListener::ID& id : *listener_ids) { 1138 for (const EventListener::ID& id : *listener_ids) {
1121 // It's possible that the listener is no longer present. Check to make sure 1139 // It's possible that the listener is no longer present. Check to make sure
1122 // it's still there. 1140 // it's still there.
1123 const EventListener* listener = 1141 const EventListener* listener =
1124 FindEventListenerInContainer(id, event_listeners); 1142 FindEventListenerInContainer(id, event_listeners);
1125 if (!listener && cross_event_listeners) { 1143 if (!listener && cross_event_listeners) {
1126 listener = FindEventListenerInContainer(id, *cross_event_listeners); 1144 listener = FindEventListenerInContainer(id, *cross_event_listeners);
1127 } 1145 }
1128 if (!listener) 1146 if (!listener)
1129 continue; 1147 continue;
(...skipping 990 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 APIPermission::kWebRequestBlocking)) { 2138 APIPermission::kWebRequestBlocking)) {
2121 return RespondNow(Error(keys::kBlockingPermissionRequired)); 2139 return RespondNow(Error(keys::kBlockingPermissionRequired));
2122 } 2140 }
2123 2141
2124 // We allow to subscribe to patterns that are broader than the host 2142 // We allow to subscribe to patterns that are broader than the host
2125 // permissions. E.g., we could subscribe to http://www.example.com/* 2143 // permissions. E.g., we could subscribe to http://www.example.com/*
2126 // while having host permissions for http://www.example.com/foo/* and 2144 // while having host permissions for http://www.example.com/foo/* and
2127 // http://www.example.com/bar/*. 2145 // http://www.example.com/bar/*.
2128 // For this reason we do only a coarse check here to warn the extension 2146 // For this reason we do only a coarse check here to warn the extension
2129 // developer if they do something obviously wrong. 2147 // developer if they do something obviously wrong.
2130 if (extension->permissions_data() 2148 // When we are in a Public Session, allow all URLs for webRequests initiated
2149 // by a regular extension.
2150 if (!(IsPublicSession() && extension->is_extension()) &&
2151 extension->permissions_data()
2131 ->GetEffectiveHostPermissions() 2152 ->GetEffectiveHostPermissions()
2132 .is_empty() && 2153 .is_empty() &&
2133 extension->permissions_data() 2154 extension->permissions_data()
2134 ->withheld_permissions() 2155 ->withheld_permissions()
2135 .explicit_hosts() 2156 .explicit_hosts()
2136 .is_empty()) { 2157 .is_empty()) {
2137 return RespondNow(Error(keys::kHostPermissionsRequired)); 2158 return RespondNow(Error(keys::kHostPermissionsRequired));
2138 } 2159 }
2139 } 2160 }
2140 2161
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
2190 base::DictionaryValue* value = NULL; 2211 base::DictionaryValue* value = NULL;
2191 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(3, &value)); 2212 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(3, &value));
2192 2213
2193 if (!value->empty()) { 2214 if (!value->empty()) {
2194 base::Time install_time = 2215 base::Time install_time =
2195 extension_info_map()->GetInstallTime(extension_id_safe()); 2216 extension_info_map()->GetInstallTime(extension_id_safe());
2196 response.reset(new ExtensionWebRequestEventRouter::EventResponse( 2217 response.reset(new ExtensionWebRequestEventRouter::EventResponse(
2197 extension_id_safe(), install_time)); 2218 extension_id_safe(), install_time));
2198 } 2219 }
2199 2220
2221 // In Public Session we only want to allow "cancel".
2222 if (IsPublicSession() &&
2223 (value->HasKey("redirectUrl") ||
2224 value->HasKey(keys::kAuthCredentialsKey) ||
2225 value->HasKey("requestHeaders") ||
2226 value->HasKey("responseHeaders"))) {
2227 OnError(event_name, sub_event_name, request_id, std::move(response));
2228 return RespondNow(Error(keys::kInvalidPublicSessionBlockingResponse));
2229 }
2230
2200 if (value->HasKey("cancel")) { 2231 if (value->HasKey("cancel")) {
2201 // Don't allow cancel mixed with other keys. 2232 // Don't allow cancel mixed with other keys.
2202 if (value->size() != 1) { 2233 if (value->size() != 1) {
2203 OnError(event_name, sub_event_name, request_id, std::move(response)); 2234 OnError(event_name, sub_event_name, request_id, std::move(response));
2204 return RespondNow(Error(keys::kInvalidBlockingResponse)); 2235 return RespondNow(Error(keys::kInvalidBlockingResponse));
2205 } 2236 }
2206 2237
2207 bool cancel = false; 2238 bool cancel = false;
2208 EXTENSION_FUNCTION_VALIDATE(value->GetBoolean("cancel", &cancel)); 2239 EXTENSION_FUNCTION_VALIDATE(value->GetBoolean("cancel", &cancel));
2209 response->cancel = cancel; 2240 response->cancel = cancel;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 // Since EventListeners are segmented by browser_context, check that 2391 // Since EventListeners are segmented by browser_context, check that
2361 // last, as it is exceedingly unlikely to be different. 2392 // last, as it is exceedingly unlikely to be different.
2362 return extension_id == that.extension_id && 2393 return extension_id == that.extension_id &&
2363 sub_event_name == that.sub_event_name && 2394 sub_event_name == that.sub_event_name &&
2364 web_view_instance_id == that.web_view_instance_id && 2395 web_view_instance_id == that.web_view_instance_id &&
2365 embedder_process_id == that.embedder_process_id && 2396 embedder_process_id == that.embedder_process_id &&
2366 browser_context == that.browser_context; 2397 browser_context == that.browser_context;
2367 } 2398 }
2368 2399
2369 } // namespace extensions 2400 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698