OLD | NEW |
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 #include "chrome/common/extensions/extension_set.h" | |
14 #include "extensions/common/constants.h" | 13 #include "extensions/common/constants.h" |
15 #include "extensions/common/extension.h" | 14 #include "extensions/common/extension.h" |
| 15 #include "extensions/common/extension_set.h" |
16 #include "extensions/common/manifest_handlers/shared_module_info.h" | 16 #include "extensions/common/manifest_handlers/shared_module_info.h" |
17 | 17 |
18 using extensions::Extension; | 18 using extensions::Extension; |
19 using extensions::Manifest; | 19 using extensions::Manifest; |
20 | 20 |
21 namespace chrome { | 21 namespace chrome { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 std::string HashHost(const std::string& host) { | 25 std::string HashHost(const std::string& host) { |
26 const std::string id_hash = base::SHA1HashString(host); | 26 const std::string id_hash = base::SHA1HashString(host); |
27 DCHECK_EQ(id_hash.length(), base::kSHA1Length); | 27 DCHECK_EQ(id_hash.length(), base::kSHA1Length); |
28 return base::HexEncode(id_hash.c_str(), id_hash.length()); | 28 return base::HexEncode(id_hash.c_str(), id_hash.length()); |
29 } | 29 } |
30 | 30 |
31 bool HostIsInSet(const std::string& host, const std::set<std::string>& set) { | 31 bool HostIsInSet(const std::string& host, const std::set<std::string>& set) { |
32 return set.count(host) > 0 || set.count(HashHost(host)) > 0; | 32 return set.count(host) > 0 || set.count(HashHost(host)) > 0; |
33 } | 33 } |
34 | 34 |
35 } // namespace | 35 } // namespace |
36 | 36 |
37 bool IsExtensionOrSharedModuleWhitelisted( | 37 bool IsExtensionOrSharedModuleWhitelisted( |
38 const GURL& url, | 38 const GURL& url, |
39 const ExtensionSet* extension_set, | 39 const extensions::ExtensionSet* extension_set, |
40 const std::set<std::string>& whitelist) { | 40 const std::set<std::string>& whitelist) { |
41 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme)) | 41 if (!url.is_valid() || !url.SchemeIs(extensions::kExtensionScheme)) |
42 return false; | 42 return false; |
43 | 43 |
44 const std::string host = url.host(); | 44 const std::string host = url.host(); |
45 if (HostIsInSet(host, whitelist)) | 45 if (HostIsInSet(host, whitelist)) |
46 return true; | 46 return true; |
47 | 47 |
48 // Check the modules that are imported by this extension to see if any of them | 48 // Check the modules that are imported by this extension to see if any of them |
49 // is whitelisted. | 49 // is whitelisted. |
(...skipping 13 matching lines...) Expand all Loading... |
63 HostIsInSet(it->extension_id, whitelist)) { | 63 HostIsInSet(it->extension_id, whitelist)) { |
64 return true; | 64 return true; |
65 } | 65 } |
66 } | 66 } |
67 } | 67 } |
68 | 68 |
69 return false; | 69 return false; |
70 } | 70 } |
71 | 71 |
72 bool IsHostAllowedByCommandLine(const GURL& url, | 72 bool IsHostAllowedByCommandLine(const GURL& url, |
73 const ExtensionSet* extension_set, | 73 const extensions::ExtensionSet* extension_set, |
74 const char* command_line_switch) { | 74 const char* command_line_switch) { |
75 if (!url.is_valid()) | 75 if (!url.is_valid()) |
76 return false; | 76 return false; |
77 | 77 |
78 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 78 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
79 const std::string allowed_list = | 79 const std::string allowed_list = |
80 command_line.GetSwitchValueASCII(command_line_switch); | 80 command_line.GetSwitchValueASCII(command_line_switch); |
81 if (allowed_list.empty()) | 81 if (allowed_list.empty()) |
82 return false; | 82 return false; |
83 | 83 |
(...skipping 12 matching lines...) Expand all Loading... |
96 base::StringTokenizer t(allowed_list, ","); | 96 base::StringTokenizer t(allowed_list, ","); |
97 while (t.GetNext()) { | 97 while (t.GetNext()) { |
98 if (t.token() == host) | 98 if (t.token() == host) |
99 return true; | 99 return true; |
100 } | 100 } |
101 | 101 |
102 return false; | 102 return false; |
103 } | 103 } |
104 | 104 |
105 } // namespace chrome | 105 } // namespace chrome |
OLD | NEW |