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

Side by Side Diff: chrome/common/pepper_permission_util.cc

Issue 831813004: Get nacl building again for android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove process launcher change Created 5 years, 11 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/common/pepper_permission_util.h" 5 #include "chrome/common/pepper_permission_util.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/sha1.h" 10 #include "base/sha1.h"
11 #include "base/strings/string_number_conversions.h" 11 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/string_tokenizer.h" 12 #include "base/strings/string_tokenizer.h"
13 #if defined(ENABLE_EXTENSIONS)
Lei Zhang 2015/01/21 21:32:22 It looks like all the callers to IsExtensionOrShar
sehr 2015/01/22 19:57:22 Great suggestion. Done.
13 #include "extensions/common/constants.h" 14 #include "extensions/common/constants.h"
14 #include "extensions/common/extension.h" 15 #include "extensions/common/extension.h"
15 #include "extensions/common/extension_set.h" 16 #include "extensions/common/extension_set.h"
16 #include "extensions/common/manifest_handlers/shared_module_info.h" 17 #include "extensions/common/manifest_handlers/shared_module_info.h"
17 18
18 using extensions::Extension; 19 using extensions::Extension;
19 using extensions::Manifest; 20 using extensions::Manifest;
20 using extensions::SharedModuleInfo; 21 using extensions::SharedModuleInfo;
22 #endif // defined(ENABLE_EXTENSIONS)
21 23
22 namespace chrome { 24 namespace chrome {
23 25
26 #if defined(ENABLE_EXTENSIONS)
24 namespace { 27 namespace {
25 28
26 std::string HashHost(const std::string& host) { 29 std::string HashHost(const std::string& host) {
27 const std::string id_hash = base::SHA1HashString(host); 30 const std::string id_hash = base::SHA1HashString(host);
28 DCHECK_EQ(id_hash.length(), base::kSHA1Length); 31 DCHECK_EQ(id_hash.length(), base::kSHA1Length);
29 return base::HexEncode(id_hash.c_str(), id_hash.length()); 32 return base::HexEncode(id_hash.c_str(), id_hash.length());
30 } 33 }
31 34
32 bool HostIsInSet(const std::string& host, const std::set<std::string>& set) { 35 bool HostIsInSet(const std::string& host, const std::set<std::string>& set) {
33 return set.count(host) > 0 || set.count(HashHost(host)) > 0; 36 return set.count(host) > 0 || set.count(HashHost(host)) > 0;
34 } 37 }
35 38
36 } // namespace 39 } // namespace
40 #endif // defined(ENABLE_EXTENSIONS)
37 41
38 bool IsExtensionOrSharedModuleWhitelisted( 42 bool IsExtensionOrSharedModuleWhitelisted(
39 const GURL& url, 43 const GURL& url,
40 const extensions::ExtensionSet* extension_set, 44 const extensions::ExtensionSet* extension_set,
41 const std::set<std::string>& whitelist) { 45 const std::set<std::string>& whitelist) {
46 #if defined(ENABLE_EXTENSIONS)
42 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme)) 47 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme))
43 return false; 48 return false;
44 49
45 const std::string host = url.host(); 50 const std::string host = url.host();
46 if (HostIsInSet(host, whitelist)) 51 if (HostIsInSet(host, whitelist))
47 return true; 52 return true;
48 53
49 // Check the modules that are imported by this extension to see if any of them 54 // Check the modules that are imported by this extension to see if any of them
50 // is whitelisted. 55 // is whitelisted.
51 const Extension* extension = extension_set ? extension_set->GetByID(host) 56 const Extension* extension = extension_set ? extension_set->GetByID(host)
52 : NULL; 57 : NULL;
53 if (!extension) 58 if (!extension)
54 return false; 59 return false;
55 60
56 typedef std::vector<SharedModuleInfo::ImportInfo> ImportInfoVector; 61 typedef std::vector<SharedModuleInfo::ImportInfo> ImportInfoVector;
57 const ImportInfoVector& imports = SharedModuleInfo::GetImports(extension); 62 const ImportInfoVector& imports = SharedModuleInfo::GetImports(extension);
58 for (ImportInfoVector::const_iterator it = imports.begin(); 63 for (ImportInfoVector::const_iterator it = imports.begin();
59 it != imports.end(); 64 it != imports.end();
60 ++it) { 65 ++it) {
61 const Extension* imported_extension = 66 const Extension* imported_extension =
62 extension_set->GetByID(it->extension_id); 67 extension_set->GetByID(it->extension_id);
63 if (imported_extension && 68 if (imported_extension &&
64 SharedModuleInfo::IsSharedModule(imported_extension) && 69 SharedModuleInfo::IsSharedModule(imported_extension) &&
65 HostIsInSet(it->extension_id, whitelist)) { 70 HostIsInSet(it->extension_id, whitelist)) {
66 return true; 71 return true;
67 } 72 }
68 } 73 }
74 #endif // defined(ENABLE_EXTENSIONS)
69 75
70 return false; 76 return false;
71 } 77 }
72 78
73 bool IsHostAllowedByCommandLine(const GURL& url, 79 bool IsHostAllowedByCommandLine(const GURL& url,
74 const extensions::ExtensionSet* extension_set, 80 const extensions::ExtensionSet* extension_set,
75 const char* command_line_switch) { 81 const char* command_line_switch) {
82 #if defined(ENABLE_EXTENSIONS)
76 if (!url.is_valid()) 83 if (!url.is_valid())
77 return false; 84 return false;
78 85
79 const base::CommandLine& command_line = 86 const base::CommandLine& command_line =
80 *base::CommandLine::ForCurrentProcess(); 87 *base::CommandLine::ForCurrentProcess();
81 const std::string allowed_list = 88 const std::string allowed_list =
82 command_line.GetSwitchValueASCII(command_line_switch); 89 command_line.GetSwitchValueASCII(command_line_switch);
83 if (allowed_list.empty()) 90 if (allowed_list.empty())
84 return false; 91 return false;
85 92
86 const std::string host = url.host(); 93 const std::string host = url.host();
87 if (allowed_list == "*") { 94 if (allowed_list == "*") {
88 // For now, we only allow packaged and platform apps in this wildcard. 95 // For now, we only allow packaged and platform apps in this wildcard.
89 if (!extension_set || !url.SchemeIs(extensions::kExtensionScheme)) 96 if (!extension_set || !url.SchemeIs(extensions::kExtensionScheme))
90 return false; 97 return false;
91 98
92 const Extension* extension = extension_set->GetByID(host); 99 const Extension* extension = extension_set->GetByID(host);
93 return extension && 100 return extension &&
94 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP || 101 (extension->GetType() == Manifest::TYPE_LEGACY_PACKAGED_APP ||
95 extension->GetType() == Manifest::TYPE_PLATFORM_APP); 102 extension->GetType() == Manifest::TYPE_PLATFORM_APP);
96 } 103 }
97 104
98 base::StringTokenizer t(allowed_list, ","); 105 base::StringTokenizer t(allowed_list, ",");
99 while (t.GetNext()) { 106 while (t.GetNext()) {
100 if (t.token() == host) 107 if (t.token() == host)
101 return true; 108 return true;
102 } 109 }
103 110
111 #endif // defined(ENABLE_EXTENSIONS)
104 return false; 112 return false;
105 } 113 }
106 114
107 } // namespace chrome 115 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698