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

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: Address comments. 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
« no previous file with comments | « extensions/common/features/simple_feature.h ('k') | 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 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/macros.h"
14 #include "base/sha1.h" 15 #include "base/sha1.h"
15 #include "base/stl_util.h" 16 #include "base/stl_util.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_util.h" 18 #include "base/strings/string_util.h"
18 #include "base/strings/stringprintf.h" 19 #include "base/strings/stringprintf.h"
19 #include "extensions/common/extension_api.h" 20 #include "extensions/common/extension_api.h"
20 #include "extensions/common/features/feature_provider.h" 21 #include "extensions/common/features/feature_provider.h"
21 #include "extensions/common/switches.h" 22 #include "extensions/common/switches.h"
22 23
23 namespace extensions { 24 namespace extensions {
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (IsIdInBlacklist(extension_id)) 338 if (IsIdInBlacklist(extension_id))
338 return CreateAvailability(FOUND_IN_BLACKLIST, type); 339 return CreateAvailability(FOUND_IN_BLACKLIST, type);
339 340
340 // TODO(benwells): don't grant all component extensions. 341 // TODO(benwells): don't grant all component extensions.
341 // See http://crbug.com/370375 for more details. 342 // See http://crbug.com/370375 for more details.
342 // Component extensions can access any feature. 343 // Component extensions can access any feature.
343 // NOTE: Deliberately does not match EXTERNAL_COMPONENT. 344 // NOTE: Deliberately does not match EXTERNAL_COMPONENT.
344 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT) 345 if (component_extensions_auto_granted_ && location == Manifest::COMPONENT)
345 return CreateAvailability(IS_AVAILABLE, type); 346 return CreateAvailability(IS_AVAILABLE, type);
346 347
347 if (!whitelist_.empty()) { 348 if (!whitelist_.empty() && !IsIdInWhitelist(extension_id) &&
348 if (!IsIdInWhitelist(extension_id)) { 349 (whitelisted_extension_id().empty() ||
tapted 2015/03/31 04:46:07 hm - two function calls isn't quite as nice.. If
jackhou1 2015/03/31 05:28:22 Done.
349 // TODO(aa): This is gross. There should be a better way to test the 350 extension_id != whitelisted_extension_id())) {
350 // whitelist. 351 return CreateAvailability(NOT_FOUND_IN_WHITELIST, type);
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 } 352 }
362 353
363 if (!MatchesManifestLocation(location)) 354 if (!MatchesManifestLocation(location))
364 return CreateAvailability(INVALID_LOCATION, type); 355 return CreateAvailability(INVALID_LOCATION, type);
365 356
366 if (!platforms_.empty() && !ContainsKey(platforms_, platform)) 357 if (!platforms_.empty() && !ContainsKey(platforms_, platform))
367 return CreateAvailability(INVALID_PLATFORM, type); 358 return CreateAvailability(INVALID_PLATFORM, type);
368 359
369 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_) 360 if (min_manifest_version_ != 0 && manifest_version < min_manifest_version_)
370 return CreateAvailability(INVALID_MIN_MANIFEST_VERSION, type); 361 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); 567 ExtensionAPI::GetSharedInstance()->GetFeatureDependency(dep_name);
577 if (!dependency) 568 if (!dependency)
578 return CreateAvailability(NOT_PRESENT); 569 return CreateAvailability(NOT_PRESENT);
579 Availability dependency_availability = checker.Run(dependency); 570 Availability dependency_availability = checker.Run(dependency);
580 if (!dependency_availability.is_available()) 571 if (!dependency_availability.is_available())
581 return dependency_availability; 572 return dependency_availability;
582 } 573 }
583 return CreateAvailability(IS_AVAILABLE); 574 return CreateAvailability(IS_AVAILABLE);
584 } 575 }
585 576
577 // static
578 const std::string& SimpleFeature::whitelisted_extension_id() {
579 CR_DEFINE_STATIC_LOCAL(
580 std::string, whitelisted_extension_id,
581 (base::CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
582 switches::kWhitelistedExtensionID)));
583 return whitelisted_extension_id;
584 }
585
586 } // namespace extensions 586 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/common/features/simple_feature.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698