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

Side by Side Diff: extensions/common/features/simple_feature.cc

Issue 1880933002: Begin to enable extension APIs in Extension Service Worker. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/common/features/simple_feature.h" 5 #include "extensions/common/features/simple_feature.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP; 256 extension_types["hosted_app"] = Manifest::TYPE_HOSTED_APP;
257 extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP; 257 extension_types["platform_app"] = Manifest::TYPE_PLATFORM_APP;
258 extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE; 258 extension_types["shared_module"] = Manifest::TYPE_SHARED_MODULE;
259 259
260 contexts["blessed_extension"] = Feature::BLESSED_EXTENSION_CONTEXT; 260 contexts["blessed_extension"] = Feature::BLESSED_EXTENSION_CONTEXT;
261 contexts["unblessed_extension"] = Feature::UNBLESSED_EXTENSION_CONTEXT; 261 contexts["unblessed_extension"] = Feature::UNBLESSED_EXTENSION_CONTEXT;
262 contexts["content_script"] = Feature::CONTENT_SCRIPT_CONTEXT; 262 contexts["content_script"] = Feature::CONTENT_SCRIPT_CONTEXT;
263 contexts["web_page"] = Feature::WEB_PAGE_CONTEXT; 263 contexts["web_page"] = Feature::WEB_PAGE_CONTEXT;
264 contexts["blessed_web_page"] = Feature::BLESSED_WEB_PAGE_CONTEXT; 264 contexts["blessed_web_page"] = Feature::BLESSED_WEB_PAGE_CONTEXT;
265 contexts["webui"] = Feature::WEBUI_CONTEXT; 265 contexts["webui"] = Feature::WEBUI_CONTEXT;
266 contexts["extension_service_worker"] = Feature::SERVICE_WORKER_CONTEXT;
Devlin 2016/04/13 19:46:31 We should have this behind a flag (or just an inte
lazyboy 2016/04/14 02:07:53 I've added a bool in feature_util, used that to gu
Devlin 2016/04/14 22:34:52 See suggestion in ipc messages.
266 267
267 locations["component"] = SimpleFeature::COMPONENT_LOCATION; 268 locations["component"] = SimpleFeature::COMPONENT_LOCATION;
268 locations["external_component"] = 269 locations["external_component"] =
269 SimpleFeature::EXTERNAL_COMPONENT_LOCATION; 270 SimpleFeature::EXTERNAL_COMPONENT_LOCATION;
270 locations["policy"] = SimpleFeature::POLICY_LOCATION; 271 locations["policy"] = SimpleFeature::POLICY_LOCATION;
271 272
272 platforms["chromeos"] = Feature::CHROMEOS_PLATFORM; 273 platforms["chromeos"] = Feature::CHROMEOS_PLATFORM;
273 platforms["linux"] = Feature::LINUX_PLATFORM; 274 platforms["linux"] = Feature::LINUX_PLATFORM;
274 platforms["mac"] = Feature::MACOSX_PLATFORM; 275 platforms["mac"] = Feature::MACOSX_PLATFORM;
275 platforms["win"] = Feature::WIN_PLATFORM; 276 platforms["win"] = Feature::WIN_PLATFORM;
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 if (extension) { 433 if (extension) {
433 Availability result = IsAvailableToManifest(extension->id(), 434 Availability result = IsAvailableToManifest(extension->id(),
434 extension->GetType(), 435 extension->GetType(),
435 extension->location(), 436 extension->location(),
436 extension->manifest_version(), 437 extension->manifest_version(),
437 platform); 438 platform);
438 if (!result.is_available()) 439 if (!result.is_available())
439 return result; 440 return result;
440 } 441 }
441 442
443 // TODO(lazyboy): This isn't quite right for Extension Service Worker
444 // extension API calls, since there's no guarantee that the extension is
445 // "active" in current renderer process when the API permission check is
446 // done.
442 if (!contexts_.empty() && !ContainsValue(contexts_, context)) 447 if (!contexts_.empty() && !ContainsValue(contexts_, context))
443 return CreateAvailability(INVALID_CONTEXT, context); 448 return CreateAvailability(INVALID_CONTEXT, context);
444 449
445 // TODO(kalman): Consider checking |matches_| regardless of context type. 450 // TODO(kalman): Consider checking |matches_| regardless of context type.
446 // Fewer surprises, and if the feature configuration wants to isolate 451 // Fewer surprises, and if the feature configuration wants to isolate
447 // "matches" from say "blessed_extension" then they can use complex features. 452 // "matches" from say "blessed_extension" then they can use complex features.
448 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) && 453 if ((context == WEB_PAGE_CONTEXT || context == WEBUI_CONTEXT) &&
449 !matches_.MatchesURL(url)) { 454 !matches_.MatchesURL(url)) {
450 return CreateAvailability(INVALID_URL, url); 455 return CreateAvailability(INVALID_URL, url);
451 } 456 }
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
629 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) { 634 bool SimpleFeature::IsValidExtensionId(const std::string& extension_id) {
630 // Belt-and-suspenders philosophy here. We should be pretty confident by this 635 // Belt-and-suspenders philosophy here. We should be pretty confident by this
631 // point that we've validated the extension ID format, but in case something 636 // point that we've validated the extension ID format, but in case something
632 // slips through, we avoid a class of attack where creative ID manipulation 637 // slips through, we avoid a class of attack where creative ID manipulation
633 // leads to hash collisions. 638 // leads to hash collisions.
634 // 128 bits / 4 = 32 mpdecimal characters 639 // 128 bits / 4 = 32 mpdecimal characters
635 return (extension_id.length() == 32); 640 return (extension_id.length() == 32);
636 } 641 }
637 642
638 } // namespace extensions 643 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698