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

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: Moved a part of code and added unit tests for URL whitelisting (part 1/2) 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 1081 matching lines...) Expand 10 before | Expand all | Expand 10 after
1432 if (!types.empty() && 1443 if (!types.empty() &&
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);
Andrew T Wilson (Slow) 2016/11/09 08:36:00 Remove blank line
Ivan Šandrk 2016/11/09 12:12:13 Done.
1454
1443 if (access != PermissionsData::ACCESS_ALLOWED) { 1455 if (access != PermissionsData::ACCESS_ALLOWED) {
1444 if (access == PermissionsData::ACCESS_WITHHELD && 1456 if (access == PermissionsData::ACCESS_WITHHELD &&
1445 web_request_event_router_delegate_) { 1457 web_request_event_router_delegate_) {
1446 web_request_event_router_delegate_->NotifyWebRequestWithheld( 1458 web_request_event_router_delegate_->NotifyWebRequestWithheld(
1447 render_process_id, render_frame_id, listener->id.extension_id); 1459 render_process_id, render_frame_id, listener->id.extension_id);
1448 } 1460 }
1449 continue; 1461 continue;
1450 } 1462 }
1451 } 1463 }
1452 1464
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
2120 APIPermission::kWebRequestBlocking)) { 2132 APIPermission::kWebRequestBlocking)) {
2121 return RespondNow(Error(keys::kBlockingPermissionRequired)); 2133 return RespondNow(Error(keys::kBlockingPermissionRequired));
2122 } 2134 }
2123 2135
2124 // We allow to subscribe to patterns that are broader than the host 2136 // We allow to subscribe to patterns that are broader than the host
2125 // permissions. E.g., we could subscribe to http://www.example.com/* 2137 // permissions. E.g., we could subscribe to http://www.example.com/*
2126 // while having host permissions for http://www.example.com/foo/* and 2138 // while having host permissions for http://www.example.com/foo/* and
2127 // http://www.example.com/bar/*. 2139 // http://www.example.com/bar/*.
2128 // For this reason we do only a coarse check here to warn the extension 2140 // For this reason we do only a coarse check here to warn the extension
2129 // developer if they do something obviously wrong. 2141 // developer if they do something obviously wrong.
2130 if (extension->permissions_data() 2142 // When we are in a Public Session, allow all URL's for webRequests
2143 // initiated by a regular extension.
2144 if (!(IsPublicSession() && extension->is_extension()) &&
2145 extension->permissions_data()
2131 ->GetEffectiveHostPermissions() 2146 ->GetEffectiveHostPermissions()
2132 .is_empty() && 2147 .is_empty() &&
2133 extension->permissions_data() 2148 extension->permissions_data()
2134 ->withheld_permissions() 2149 ->withheld_permissions()
2135 .explicit_hosts() 2150 .explicit_hosts()
2136 .is_empty()) { 2151 .is_empty()) {
2137 return RespondNow(Error(keys::kHostPermissionsRequired)); 2152 return RespondNow(Error(keys::kHostPermissionsRequired));
2138 } 2153 }
2139 } 2154 }
2140 2155
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 // Since EventListeners are segmented by browser_context, check that 2375 // Since EventListeners are segmented by browser_context, check that
2361 // last, as it is exceedingly unlikely to be different. 2376 // last, as it is exceedingly unlikely to be different.
2362 return extension_id == that.extension_id && 2377 return extension_id == that.extension_id &&
2363 sub_event_name == that.sub_event_name && 2378 sub_event_name == that.sub_event_name &&
2364 web_view_instance_id == that.web_view_instance_id && 2379 web_view_instance_id == that.web_view_instance_id &&
2365 embedder_process_id == that.embedder_process_id && 2380 embedder_process_id == that.embedder_process_id &&
2366 browser_context == that.browser_context; 2381 browser_context == that.browser_context;
2367 } 2382 }
2368 2383
2369 } // namespace extensions 2384 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698