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

Side by Side Diff: extensions/common/manifest_handlers/shared_module_info.cc

Issue 263703002: Allow shared modules to whitelist extensions that import them. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: feedback Created 6 years, 7 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 | Annotate | Revision Log
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 "extensions/common/manifest_handlers/shared_module_info.h" 5 #include "extensions/common/manifest_handlers/shared_module_info.h"
6 6
7 #include "base/lazy_instance.h" 7 #include "base/lazy_instance.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/strings/string_number_conversions.h"
10 #include "base/strings/string_util.h" 10 #include "base/strings/string_util.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 } 77 }
78 78
79 // static 79 // static
80 bool SharedModuleInfo::IsExportAllowed(const Extension* extension, 80 bool SharedModuleInfo::IsExportAllowed(const Extension* extension,
81 const std::string& relative_path) { 81 const std::string& relative_path) {
82 return GetSharedModuleInfo(extension). 82 return GetSharedModuleInfo(extension).
83 exported_set_.MatchesURL(extension->url().Resolve(relative_path)); 83 exported_set_.MatchesURL(extension->url().Resolve(relative_path));
84 } 84 }
85 85
86 // static 86 // static
87 bool SharedModuleInfo::IsExportAllowedByWhitelist(const Extension* extension,
88 const std::string& other_id) {
89 const SharedModuleInfo& info = GetSharedModuleInfo(extension);
90 if (info.export_whitelist_.empty())
91 return true;
92 if (info.export_whitelist_.find(other_id) != info.export_whitelist_.end())
93 return true;
94 return false;
95 }
96
97 // static
87 bool SharedModuleInfo::ImportsExtensionById(const Extension* extension, 98 bool SharedModuleInfo::ImportsExtensionById(const Extension* extension,
88 const std::string& other_id) { 99 const std::string& other_id) {
89 const SharedModuleInfo& info = GetSharedModuleInfo(extension); 100 const SharedModuleInfo& info = GetSharedModuleInfo(extension);
90 for (size_t i = 0; i < info.imports_.size(); i++) { 101 for (size_t i = 0; i < info.imports_.size(); i++) {
91 if (info.imports_[i].extension_id == other_id) 102 if (info.imports_[i].extension_id == other_id)
92 return true; 103 return true;
93 } 104 }
94 return false; 105 return false;
95 } 106 }
96 107
(...skipping 24 matching lines...) Expand all
121 const base::DictionaryValue* export_value = NULL; 132 const base::DictionaryValue* export_value = NULL;
122 if (!extension->manifest()->GetDictionary(keys::kExport, &export_value)) { 133 if (!extension->manifest()->GetDictionary(keys::kExport, &export_value)) {
123 *error = base::ASCIIToUTF16(errors::kInvalidExport); 134 *error = base::ASCIIToUTF16(errors::kInvalidExport);
124 return false; 135 return false;
125 } 136 }
126 const base::ListValue* resources_list = NULL; 137 const base::ListValue* resources_list = NULL;
127 if (!export_value->GetList(keys::kResources, &resources_list)) { 138 if (!export_value->GetList(keys::kResources, &resources_list)) {
128 *error = base::ASCIIToUTF16(errors::kInvalidExportResources); 139 *error = base::ASCIIToUTF16(errors::kInvalidExportResources);
129 return false; 140 return false;
130 } 141 }
142 if (export_value->HasKey(keys::kWhitelist)) {
143 const base::ListValue* whitelist = NULL;
144 if (!export_value->GetList(keys::kWhitelist, &whitelist)) {
145 *error = base::ASCIIToUTF16(errors::kInvalidExportWhitelist);
146 return false;
147 }
148 for (size_t i = 0; i < whitelist->GetSize(); ++i) {
149 std::string extension_id;
150 if (!whitelist->GetString(i, &extension_id) ||
151 !Extension::IdIsValid(extension_id)) {
152 *error = ErrorUtils::FormatErrorMessageUTF16(
153 errors::kInvalidExportWhitelistString, base::IntToString(i));
154 return false;
155 }
156 export_whitelist_.insert(extension_id);
157 }
158 }
131 for (size_t i = 0; i < resources_list->GetSize(); ++i) { 159 for (size_t i = 0; i < resources_list->GetSize(); ++i) {
132 std::string resource_path; 160 std::string resource_path;
133 if (!resources_list->GetString(i, &resource_path)) { 161 if (!resources_list->GetString(i, &resource_path)) {
134 *error = ErrorUtils::FormatErrorMessageUTF16( 162 *error = ErrorUtils::FormatErrorMessageUTF16(
135 errors::kInvalidExportResourcesString, base::IntToString(i)); 163 errors::kInvalidExportResourcesString, base::IntToString(i));
136 return false; 164 return false;
137 } 165 }
138 const GURL& resolved_path = extension->url().Resolve(resource_path); 166 const GURL& resolved_path = extension->url().Resolve(resource_path);
139 if (!resolved_path.is_valid()) { 167 if (!resolved_path.is_valid()) {
140 *error = ErrorUtils::FormatErrorMessageUTF16( 168 *error = ErrorUtils::FormatErrorMessageUTF16(
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 247
220 const std::vector<std::string> SharedModuleHandler::Keys() const { 248 const std::vector<std::string> SharedModuleHandler::Keys() const {
221 static const char* keys[] = { 249 static const char* keys[] = {
222 keys::kExport, 250 keys::kExport,
223 keys::kImport 251 keys::kImport
224 }; 252 };
225 return std::vector<std::string>(keys, keys + arraysize(keys)); 253 return std::vector<std::string>(keys, keys + arraysize(keys));
226 } 254 }
227 255
228 } // namespace extensions 256 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698