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

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: Updated IsPublicSession function 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1082 matching lines...) Expand 10 before | Expand all | Expand 10 after
1433 std::find(types.begin(), types.end(), resource_type) == types.end()) { 1444 std::find(types.begin(), types.end(), resource_type) == types.end()) {
1434 continue; 1445 continue;
1435 } 1446 }
1436 1447
1437 if (!is_web_view_guest) { 1448 if (!is_web_view_guest) {
1438 PermissionsData::AccessType access = 1449 PermissionsData::AccessType access =
1439 WebRequestPermissions::CanExtensionAccessURL( 1450 WebRequestPermissions::CanExtensionAccessURL(
1440 extension_info_map, listener->id.extension_id, url, 1451 extension_info_map, listener->id.extension_id, url,
1441 frame_data.tab_id, crosses_incognito, 1452 frame_data.tab_id, crosses_incognito,
1442 WebRequestPermissions::REQUIRE_HOST_PERMISSION); 1453 WebRequestPermissions::REQUIRE_HOST_PERMISSION);
1454
1455 // When we are in a Public Session, allow all URL's for webRequests
1456 // initiated by a regular extension.
1457 if (access != PermissionsData::ACCESS_ALLOWED && extension_info_map) {
1458 const extensions::Extension* extension =
1459 extension_info_map->extensions().GetByID(listener->id.extension_id);
1460 if (IsPublicSession() && extension && extension->is_extension()) {
Devlin 2016/11/03 00:33:46 We want to do this for *all* extensions? Is it al
Ivan Šandrk 2016/11/03 14:45:12 Yes, for all regular extensions. Yes, users aren't
Devlin 2016/11/05 06:04:37 If security/privacy are on board with this, then t
Ivan Šandrk 2016/11/07 10:50:02 S&P are fine. Done.
1461 access = PermissionsData::ACCESS_ALLOWED;
1462 }
1463 }
1464
1443 if (access != PermissionsData::ACCESS_ALLOWED) { 1465 if (access != PermissionsData::ACCESS_ALLOWED) {
1444 if (access == PermissionsData::ACCESS_WITHHELD && 1466 if (access == PermissionsData::ACCESS_WITHHELD &&
1445 web_request_event_router_delegate_) { 1467 web_request_event_router_delegate_) {
1446 web_request_event_router_delegate_->NotifyWebRequestWithheld( 1468 web_request_event_router_delegate_->NotifyWebRequestWithheld(
1447 render_process_id, render_frame_id, listener->id.extension_id); 1469 render_process_id, render_frame_id, listener->id.extension_id);
1448 } 1470 }
1449 continue; 1471 continue;
1450 } 1472 }
1451 } 1473 }
1452 1474
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 APIPermission::kWebRequestBlocking)) { 2142 APIPermission::kWebRequestBlocking)) {
2121 return RespondNow(Error(keys::kBlockingPermissionRequired)); 2143 return RespondNow(Error(keys::kBlockingPermissionRequired));
2122 } 2144 }
2123 2145
2124 // We allow to subscribe to patterns that are broader than the host 2146 // We allow to subscribe to patterns that are broader than the host
2125 // permissions. E.g., we could subscribe to http://www.example.com/* 2147 // permissions. E.g., we could subscribe to http://www.example.com/*
2126 // while having host permissions for http://www.example.com/foo/* and 2148 // while having host permissions for http://www.example.com/foo/* and
2127 // http://www.example.com/bar/*. 2149 // http://www.example.com/bar/*.
2128 // For this reason we do only a coarse check here to warn the extension 2150 // For this reason we do only a coarse check here to warn the extension
2129 // developer if they do something obviously wrong. 2151 // developer if they do something obviously wrong.
2130 if (extension->permissions_data() 2152 // When we are in a Public Session, allow all URL's for webRequests
2153 // initiated by a regular extension.
2154 if (!(IsPublicSession() && extension->is_extension()) &&
2155 extension->permissions_data()
2131 ->GetEffectiveHostPermissions() 2156 ->GetEffectiveHostPermissions()
2132 .is_empty() && 2157 .is_empty() &&
2133 extension->permissions_data() 2158 extension->permissions_data()
2134 ->withheld_permissions() 2159 ->withheld_permissions()
2135 .explicit_hosts() 2160 .explicit_hosts()
2136 .is_empty()) { 2161 .is_empty()) {
2137 return RespondNow(Error(keys::kHostPermissionsRequired)); 2162 return RespondNow(Error(keys::kHostPermissionsRequired));
2138 } 2163 }
2139 } 2164 }
2140 2165
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 // Since EventListeners are segmented by browser_context, check that 2385 // Since EventListeners are segmented by browser_context, check that
2361 // last, as it is exceedingly unlikely to be different. 2386 // last, as it is exceedingly unlikely to be different.
2362 return extension_id == that.extension_id && 2387 return extension_id == that.extension_id &&
2363 sub_event_name == that.sub_event_name && 2388 sub_event_name == that.sub_event_name &&
2364 web_view_instance_id == that.web_view_instance_id && 2389 web_view_instance_id == that.web_view_instance_id &&
2365 embedder_process_id == that.embedder_process_id && 2390 embedder_process_id == that.embedder_process_id &&
2366 browser_context == that.browser_context; 2391 browser_context == that.browser_context;
2367 } 2392 }
2368 2393
2369 } // namespace extensions 2394 } // namespace extensions
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698