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

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

Issue 1047943002: Cache --whitelisted-extension-id in SimpleFeature. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 <map> 7 #include <map>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/alias.h" 12 #include "base/debug/alias.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/sha1.h" 14 #include "base/sha1.h"
15 #include "base/stl_util.h" 15 #include "base/stl_util.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 17 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "extensions/common/extension_api.h" 19 #include "extensions/common/extension_api.h"
20 #include "extensions/common/features/feature_provider.h" 20 #include "extensions/common/features/feature_provider.h"
21 #include "extensions/common/switches.h" 21 #include "extensions/common/switches.h"
22 22
23 namespace extensions { 23 namespace extensions {
24 24
25 // static
26 std::string* SimpleFeature::whitelisted_extension_id_ = NULL;
27
25 namespace { 28 namespace {
26 29
27 Feature::Availability IsAvailableToManifestForBind( 30 Feature::Availability IsAvailableToManifestForBind(
28 const std::string& extension_id, 31 const std::string& extension_id,
29 Manifest::Type type, 32 Manifest::Type type,
30 Manifest::Location location, 33 Manifest::Location location,
31 int manifest_version, 34 int manifest_version,
32 Feature::Platform platform, 35 Feature::Platform platform,
33 const Feature* feature) { 36 const Feature* feature) {
34 return feature->IsAvailableToManifest( 37 return feature->IsAvailableToManifest(
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (IsIdInBlacklist(extension_id)) 340 if (IsIdInBlacklist(extension_id))
338 return CreateAvailability(FOUND_IN_BLACKLIST, type); 341 return CreateAvailability(FOUND_IN_BLACKLIST, type);
339 342
340 // TODO(benwells): don't grant all component extensions. 343 // TODO(benwells): don't grant all component extensions.
341 // See http://crbug.com/370375 for more details. 344 // See http://crbug.com/370375 for more details.
342 // Component extensions can access any feature. 345 // Component extensions can access any feature.
343 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. 346 // NOTE: Deliberately does not match EXTERNAL_COMPONENT.
344 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) 347 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT)
345 return CreateAvailability(IS_AVAILABLE, type); 348 return CreateAvailability(IS_AVAILABLE, type);
346 349
347 if (!whitelist_.empty()) { 350 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) &&
348 if (!IsIdInWhitelist(extension_id)) { 351 extension_id != whitelisted_extension_id()) {
tapted 2015/03/31 03:26:49 I'm not sure we know for certain whether `extensio
jackhou1 2015/03/31 04:37:45 Added check for empty whitelisted_extension_id.
349 // TODO(aa): This is gross. There should be a better way to test the 352 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
350 // whitelist.
351 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
352 if (!command_line->HasSwitch(switches::kWhitelistedExtensionID))
353 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
354
355 std::string whitelist_switch_value =
356 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
357 switches::kWhitelistedExtensionID);
358 if (extension_id != whitelist_switch_value)
359 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
360 }
361 } 353 }
362 354
363 if (!MatchesManifestLocation(location)) 355 if (!MatchesManifestLocation(location))
364 return CreateAvailability(INVALID_LOCATION, type); 356 return CreateAvailability(INVALID_LOCATION, type);
365 357
366 if (!platforms_.empty() && !ContainsKey(platforms_, platform)) 358 if (!platforms_.empty() && !ContainsKey(platforms_, platform))
367 return CreateAvailability(INVALID_PLATFORM, type); 359 return CreateAvailability(INVALID_PLATFORM, type);
368 360
369 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 361 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
370 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); 362 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type);
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 ExtensionAPI::GetSharedInstance()->GetFeatureDependency(dep_name); 568 ExtensionAPI::GetSharedInstance()->GetFeatureDependency(dep_name);
577 if (!dependency) 569 if (!dependency)
578 return CreateAvailability(NOT_PRESENT); 570 return CreateAvailability(NOT_PRESENT);
579 Availability dependency_availability = checker.Run(dependency); 571 Availability dependency_availability = checker.Run(dependency);
580 if (!dependency_availability.is_available()) 572 if (!dependency_availability.is_available())
581 return dependency_availability; 573 return dependency_availability;
582 } 574 }
583 return CreateAvailability(IS_AVAILABLE); 575 return CreateAvailability(IS_AVAILABLE);
584 } 576 }
585 577
578 // static
579 const std::string& SimpleFeature::whitelisted_extension_id() {
580 if (!whitelisted_extension_id_) {
tapted 2015/03/31 03:26:49 use CR_DEFINE_STATIC_LOCAL(std::string, whiteli
jackhou1 2015/03/31 04:37:45 Done.
581 whitelisted_extension_id_ = new std::string(
582 base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
583 switches::kWhitelistedExtensionID));
584 }
585 return *whitelisted_extension_id_;
586 }
587
586 } // namespace extensions 588 } // namespace extensions
OLDNEW
« extensions/common/features/simple_feature.h ('K') | « extensions/common/features/simple_feature.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698