| OLD | NEW |
| 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 Loading... |
| 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 1769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2120 APIPermission::kWebRequestBlocking)) { | 2131 APIPermission::kWebRequestBlocking)) { |
| 2121 return RespondNow(Error(keys::kBlockingPermissionRequired)); | 2132 return RespondNow(Error(keys::kBlockingPermissionRequired)); |
| 2122 } | 2133 } |
| 2123 | 2134 |
| 2124 // We allow to subscribe to patterns that are broader than the host | 2135 // We allow to subscribe to patterns that are broader than the host |
| 2125 // permissions. E.g., we could subscribe to http://www.example.com/* | 2136 // permissions. E.g., we could subscribe to http://www.example.com/* |
| 2126 // while having host permissions for http://www.example.com/foo/* and | 2137 // while having host permissions for http://www.example.com/foo/* and |
| 2127 // http://www.example.com/bar/*. | 2138 // http://www.example.com/bar/*. |
| 2128 // For this reason we do only a coarse check here to warn the extension | 2139 // For this reason we do only a coarse check here to warn the extension |
| 2129 // developer if they do something obviously wrong. | 2140 // developer if they do something obviously wrong. |
| 2130 if (extension->permissions_data() | 2141 // When we are in a Public Session, allow all URL's for webRequests |
| 2142 // initiated by a regular extension. |
| 2143 if (!(IsPublicSession() && extension->is_extension()) && |
| 2144 extension->permissions_data() |
| 2131 ->GetEffectiveHostPermissions() | 2145 ->GetEffectiveHostPermissions() |
| 2132 .is_empty() && | 2146 .is_empty() && |
| 2133 extension->permissions_data() | 2147 extension->permissions_data() |
| 2134 ->withheld_permissions() | 2148 ->withheld_permissions() |
| 2135 .explicit_hosts() | 2149 .explicit_hosts() |
| 2136 .is_empty()) { | 2150 .is_empty()) { |
| 2137 return RespondNow(Error(keys::kHostPermissionsRequired)); | 2151 return RespondNow(Error(keys::kHostPermissionsRequired)); |
| 2138 } | 2152 } |
| 2139 } | 2153 } |
| 2140 | 2154 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2360 // Since EventListeners are segmented by browser_context, check that | 2374 // Since EventListeners are segmented by browser_context, check that |
| 2361 // last, as it is exceedingly unlikely to be different. | 2375 // last, as it is exceedingly unlikely to be different. |
| 2362 return extension_id == that.extension_id && | 2376 return extension_id == that.extension_id && |
| 2363 sub_event_name == that.sub_event_name && | 2377 sub_event_name == that.sub_event_name && |
| 2364 web_view_instance_id == that.web_view_instance_id && | 2378 web_view_instance_id == that.web_view_instance_id && |
| 2365 embedder_process_id == that.embedder_process_id && | 2379 embedder_process_id == that.embedder_process_id && |
| 2366 browser_context == that.browser_context; | 2380 browser_context == that.browser_context; |
| 2367 } | 2381 } |
| 2368 | 2382 |
| 2369 } // namespace extensions | 2383 } // namespace extensions |
| OLD | NEW |