Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / extensions / common / extension.cc
blobb6803857ef917a2aacf79637f471ed28957358dc
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "extensions/common/extension.h"
7 #include "base/base64.h"
8 #include "base/basictypes.h"
9 #include "base/command_line.h"
10 #include "base/files/file_path.h"
11 #include "base/i18n/rtl.h"
12 #include "base/logging.h"
13 #include "base/memory/singleton.h"
14 #include "base/stl_util.h"
15 #include "base/strings/string16.h"
16 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_piece.h"
18 #include "base/strings/string_util.h"
19 #include "base/strings/stringprintf.h"
20 #include "base/strings/utf_string_conversions.h"
21 #include "base/values.h"
22 #include "base/version.h"
23 #include "components/crx_file/id_util.h"
24 #include "content/public/common/url_constants.h"
25 #include "extensions/common/constants.h"
26 #include "extensions/common/error_utils.h"
27 #include "extensions/common/feature_switch.h"
28 #include "extensions/common/manifest.h"
29 #include "extensions/common/manifest_constants.h"
30 #include "extensions/common/manifest_handler.h"
31 #include "extensions/common/manifest_handlers/permissions_parser.h"
32 #include "extensions/common/permissions/permission_set.h"
33 #include "extensions/common/permissions/permissions_data.h"
34 #include "extensions/common/permissions/permissions_info.h"
35 #include "extensions/common/switches.h"
36 #include "extensions/common/url_pattern.h"
37 #include "net/base/filename_util.h"
38 #include "url/url_util.h"
40 namespace extensions {
42 namespace keys = manifest_keys;
43 namespace values = manifest_values;
44 namespace errors = manifest_errors;
46 namespace {
48 const int kModernManifestVersion = 2;
49 const int kPEMOutputColumns = 64;
51 // KEY MARKERS
52 const char kKeyBeginHeaderMarker[] = "-----BEGIN";
53 const char kKeyBeginFooterMarker[] = "-----END";
54 const char kKeyInfoEndMarker[] = "KEY-----";
55 const char kPublic[] = "PUBLIC";
56 const char kPrivate[] = "PRIVATE";
58 bool ContainsReservedCharacters(const base::FilePath& path) {
59 // We should disallow backslash '\\' as file path separator even on Windows,
60 // because the backslash is not regarded as file path separator on Linux/Mac.
61 // Extensions are cross-platform.
62 // Since FilePath uses backslash '\\' as file path separator on Windows, so we
63 // need to check manually.
64 if (path.value().find('\\') != path.value().npos)
65 return true;
66 return !net::IsSafePortableRelativePath(path);
69 } // namespace
71 const int Extension::kInitFromValueFlagBits = 13;
73 const char Extension::kMimeType[] = "application/x-chrome-extension";
75 const int Extension::kValidWebExtentSchemes =
76 URLPattern::SCHEME_HTTP | URLPattern::SCHEME_HTTPS;
78 const int Extension::kValidHostPermissionSchemes = URLPattern::SCHEME_CHROMEUI |
79 URLPattern::SCHEME_HTTP |
80 URLPattern::SCHEME_HTTPS |
81 URLPattern::SCHEME_FILE |
82 URLPattern::SCHEME_FTP;
85 // Extension
88 // static
89 scoped_refptr<Extension> Extension::Create(const base::FilePath& path,
90 Manifest::Location location,
91 const base::DictionaryValue& value,
92 int flags,
93 std::string* utf8_error) {
94 return Extension::Create(path,
95 location,
96 value,
97 flags,
98 std::string(), // ID is ignored if empty.
99 utf8_error);
102 // TODO(sungguk): Continue removing std::string errors and replacing
103 // with base::string16. See http://crbug.com/71980.
104 scoped_refptr<Extension> Extension::Create(const base::FilePath& path,
105 Manifest::Location location,
106 const base::DictionaryValue& value,
107 int flags,
108 const std::string& explicit_id,
109 std::string* utf8_error) {
110 DCHECK(utf8_error);
111 base::string16 error;
112 scoped_ptr<extensions::Manifest> manifest(
113 new extensions::Manifest(
114 location, scoped_ptr<base::DictionaryValue>(value.DeepCopy())));
116 if (!InitExtensionID(manifest.get(), path, explicit_id, flags, &error)) {
117 *utf8_error = base::UTF16ToUTF8(error);
118 return NULL;
121 std::vector<InstallWarning> install_warnings;
122 if (!manifest->ValidateManifest(utf8_error, &install_warnings)) {
123 return NULL;
126 scoped_refptr<Extension> extension = new Extension(path, manifest.Pass());
127 extension->install_warnings_.swap(install_warnings);
129 if (!extension->InitFromValue(flags, &error)) {
130 *utf8_error = base::UTF16ToUTF8(error);
131 return NULL;
134 return extension;
137 Manifest::Type Extension::GetType() const {
138 return converted_from_user_script() ?
139 Manifest::TYPE_USER_SCRIPT : manifest_->type();
142 // static
143 GURL Extension::GetResourceURL(const GURL& extension_url,
144 const std::string& relative_path) {
145 DCHECK(extension_url.SchemeIs(extensions::kExtensionScheme));
146 DCHECK_EQ("/", extension_url.path());
148 std::string path = relative_path;
150 // If the relative path starts with "/", it is "absolute" relative to the
151 // extension base directory, but extension_url is already specified to refer
152 // to that base directory, so strip the leading "/" if present.
153 if (relative_path.size() > 0 && relative_path[0] == '/')
154 path = relative_path.substr(1);
156 GURL ret_val = GURL(extension_url.spec() + path);
157 DCHECK(base::StartsWith(ret_val.spec(), extension_url.spec(),
158 base::CompareCase::INSENSITIVE_ASCII));
160 return ret_val;
163 bool Extension::ResourceMatches(const URLPatternSet& pattern_set,
164 const std::string& resource) const {
165 return pattern_set.MatchesURL(extension_url_.Resolve(resource));
168 ExtensionResource Extension::GetResource(
169 const std::string& relative_path) const {
170 std::string new_path = relative_path;
171 // We have some legacy data where resources have leading slashes.
172 // See: http://crbug.com/121164
173 if (!new_path.empty() && new_path.at(0) == '/')
174 new_path.erase(0, 1);
175 base::FilePath relative_file_path = base::FilePath::FromUTF8Unsafe(new_path);
176 if (ContainsReservedCharacters(relative_file_path))
177 return ExtensionResource();
178 ExtensionResource r(id(), path(), relative_file_path);
179 if ((creation_flags() & Extension::FOLLOW_SYMLINKS_ANYWHERE)) {
180 r.set_follow_symlinks_anywhere();
182 return r;
185 ExtensionResource Extension::GetResource(
186 const base::FilePath& relative_file_path) const {
187 if (ContainsReservedCharacters(relative_file_path))
188 return ExtensionResource();
189 ExtensionResource r(id(), path(), relative_file_path);
190 if ((creation_flags() & Extension::FOLLOW_SYMLINKS_ANYWHERE)) {
191 r.set_follow_symlinks_anywhere();
193 return r;
196 // TODO(rafaelw): Move ParsePEMKeyBytes, ProducePEM & FormatPEMForOutput to a
197 // util class in base:
198 // http://code.google.com/p/chromium/issues/detail?id=13572
199 // static
200 bool Extension::ParsePEMKeyBytes(const std::string& input,
201 std::string* output) {
202 DCHECK(output);
203 if (!output)
204 return false;
205 if (input.length() == 0)
206 return false;
208 std::string working = input;
209 if (base::StartsWith(working, kKeyBeginHeaderMarker,
210 base::CompareCase::SENSITIVE)) {
211 working = base::CollapseWhitespaceASCII(working, true);
212 size_t header_pos = working.find(kKeyInfoEndMarker,
213 sizeof(kKeyBeginHeaderMarker) - 1);
214 if (header_pos == std::string::npos)
215 return false;
216 size_t start_pos = header_pos + sizeof(kKeyInfoEndMarker) - 1;
217 size_t end_pos = working.rfind(kKeyBeginFooterMarker);
218 if (end_pos == std::string::npos)
219 return false;
220 if (start_pos >= end_pos)
221 return false;
223 working = working.substr(start_pos, end_pos - start_pos);
224 if (working.length() == 0)
225 return false;
228 return base::Base64Decode(working, output);
231 // static
232 bool Extension::ProducePEM(const std::string& input, std::string* output) {
233 DCHECK(output);
234 if (input.empty())
235 return false;
236 base::Base64Encode(input, output);
237 return true;
240 // static
241 bool Extension::FormatPEMForFileOutput(const std::string& input,
242 std::string* output,
243 bool is_public) {
244 DCHECK(output);
245 if (input.length() == 0)
246 return false;
247 *output = "";
248 output->append(kKeyBeginHeaderMarker);
249 output->append(" ");
250 output->append(is_public ? kPublic : kPrivate);
251 output->append(" ");
252 output->append(kKeyInfoEndMarker);
253 output->append("\n");
254 for (size_t i = 0; i < input.length(); ) {
255 int slice = std::min<int>(input.length() - i, kPEMOutputColumns);
256 output->append(input.substr(i, slice));
257 output->append("\n");
258 i += slice;
260 output->append(kKeyBeginFooterMarker);
261 output->append(" ");
262 output->append(is_public ? kPublic : kPrivate);
263 output->append(" ");
264 output->append(kKeyInfoEndMarker);
265 output->append("\n");
267 return true;
270 // static
271 GURL Extension::GetBaseURLFromExtensionId(const std::string& extension_id) {
272 return GURL(std::string(extensions::kExtensionScheme) +
273 url::kStandardSchemeSeparator + extension_id + "/");
276 bool Extension::ShowConfigureContextMenus() const {
277 // Normally we don't show a context menu for component actions, but when
278 // re-design is enabled we show them in the toolbar (if they have an action),
279 // and it is weird to have a random button that has no context menu when the
280 // rest do.
281 if (location() == Manifest::COMPONENT ||
282 location() == Manifest::EXTERNAL_COMPONENT)
283 return FeatureSwitch::extension_action_redesign()->IsEnabled();
285 return true;
288 bool Extension::OverlapsWithOrigin(const GURL& origin) const {
289 if (url() == origin)
290 return true;
292 if (web_extent().is_empty())
293 return false;
295 // Note: patterns and extents ignore port numbers.
296 URLPattern origin_only_pattern(kValidWebExtentSchemes);
297 if (!origin_only_pattern.SetScheme(origin.scheme()))
298 return false;
299 origin_only_pattern.SetHost(origin.host());
300 origin_only_pattern.SetPath("/*");
302 URLPatternSet origin_only_pattern_list;
303 origin_only_pattern_list.AddPattern(origin_only_pattern);
305 return web_extent().OverlapsWith(origin_only_pattern_list);
308 bool Extension::RequiresSortOrdinal() const {
309 return is_app() && (display_in_launcher_ || display_in_new_tab_page_);
312 bool Extension::ShouldDisplayInAppLauncher() const {
313 // Only apps should be displayed in the launcher.
314 return is_app() && display_in_launcher_;
317 bool Extension::ShouldDisplayInNewTabPage() const {
318 // Only apps should be displayed on the NTP.
319 return is_app() && display_in_new_tab_page_;
322 bool Extension::ShouldDisplayInExtensionSettings() const {
323 // Don't show for themes since the settings UI isn't really useful for them.
324 if (is_theme())
325 return false;
327 // Don't show component extensions and invisible apps.
328 if (ShouldNotBeVisible())
329 return false;
331 // Always show unpacked extensions and apps.
332 if (Manifest::IsUnpackedLocation(location()))
333 return true;
335 // Unless they are unpacked, never show hosted apps. Note: We intentionally
336 // show packaged apps and platform apps because there are some pieces of
337 // functionality that are only available in chrome://extensions/ but which
338 // are needed for packaged and platform apps. For example, inspecting
339 // background pages. See http://crbug.com/116134.
340 if (is_hosted_app())
341 return false;
343 return true;
346 bool Extension::ShouldNotBeVisible() const {
347 // Don't show component extensions because they are only extensions as an
348 // implementation detail of Chrome.
349 if (extensions::Manifest::IsComponentLocation(location()) &&
350 !base::CommandLine::ForCurrentProcess()->HasSwitch(
351 switches::kShowComponentExtensionOptions)) {
352 return true;
355 // Always show unpacked extensions and apps.
356 if (Manifest::IsUnpackedLocation(location()))
357 return false;
359 // Don't show apps that aren't visible in either launcher or ntp.
360 if (is_app() && !ShouldDisplayInAppLauncher() && !ShouldDisplayInNewTabPage())
361 return true;
363 return false;
366 Extension::ManifestData* Extension::GetManifestData(const std::string& key)
367 const {
368 DCHECK(finished_parsing_manifest_ || thread_checker_.CalledOnValidThread());
369 ManifestDataMap::const_iterator iter = manifest_data_.find(key);
370 if (iter != manifest_data_.end())
371 return iter->second.get();
372 return NULL;
375 void Extension::SetManifestData(const std::string& key,
376 Extension::ManifestData* data) {
377 DCHECK(!finished_parsing_manifest_ && thread_checker_.CalledOnValidThread());
378 manifest_data_[key] = linked_ptr<ManifestData>(data);
381 Manifest::Location Extension::location() const {
382 return manifest_->location();
385 const std::string& Extension::id() const {
386 return manifest_->extension_id();
389 const std::string Extension::VersionString() const {
390 return version()->GetString();
393 const std::string Extension::GetVersionForDisplay() const {
394 if (version_name_.size() > 0)
395 return version_name_;
396 return VersionString();
399 void Extension::AddInstallWarning(const InstallWarning& new_warning) {
400 install_warnings_.push_back(new_warning);
403 void Extension::AddInstallWarnings(
404 const std::vector<InstallWarning>& new_warnings) {
405 install_warnings_.insert(install_warnings_.end(),
406 new_warnings.begin(), new_warnings.end());
409 bool Extension::is_app() const {
410 return manifest()->is_app();
413 bool Extension::is_platform_app() const {
414 return manifest()->is_platform_app();
417 bool Extension::is_hosted_app() const {
418 return manifest()->is_hosted_app();
421 bool Extension::is_legacy_packaged_app() const {
422 return manifest()->is_legacy_packaged_app();
425 bool Extension::is_extension() const {
426 return manifest()->is_extension();
429 bool Extension::is_shared_module() const {
430 return manifest()->is_shared_module();
433 bool Extension::is_theme() const {
434 return manifest()->is_theme();
437 bool Extension::can_be_incognito_enabled() const {
438 // Only component platform apps are supported in incognito.
439 return !is_platform_app() || location() == Manifest::COMPONENT;
442 void Extension::AddWebExtentPattern(const URLPattern& pattern) {
443 // Bookmark apps are permissionless.
444 if (from_bookmark())
445 return;
447 extent_.AddPattern(pattern);
450 // static
451 bool Extension::InitExtensionID(extensions::Manifest* manifest,
452 const base::FilePath& path,
453 const std::string& explicit_id,
454 int creation_flags,
455 base::string16* error) {
456 if (!explicit_id.empty()) {
457 manifest->set_extension_id(explicit_id);
458 return true;
461 if (manifest->HasKey(keys::kPublicKey)) {
462 std::string public_key;
463 std::string public_key_bytes;
464 if (!manifest->GetString(keys::kPublicKey, &public_key) ||
465 !ParsePEMKeyBytes(public_key, &public_key_bytes)) {
466 *error = base::ASCIIToUTF16(errors::kInvalidKey);
467 return false;
469 std::string extension_id = crx_file::id_util::GenerateId(public_key_bytes);
470 manifest->set_extension_id(extension_id);
471 return true;
474 if (creation_flags & REQUIRE_KEY) {
475 *error = base::ASCIIToUTF16(errors::kInvalidKey);
476 return false;
477 } else {
478 // If there is a path, we generate the ID from it. This is useful for
479 // development mode, because it keeps the ID stable across restarts and
480 // reloading the extension.
481 std::string extension_id = crx_file::id_util::GenerateIdForPath(path);
482 if (extension_id.empty()) {
483 NOTREACHED() << "Could not create ID from path.";
484 return false;
486 manifest->set_extension_id(extension_id);
487 return true;
491 Extension::Extension(const base::FilePath& path,
492 scoped_ptr<extensions::Manifest> manifest)
493 : manifest_version_(0),
494 converted_from_user_script_(false),
495 manifest_(manifest.release()),
496 finished_parsing_manifest_(false),
497 display_in_launcher_(true),
498 display_in_new_tab_page_(true),
499 wants_file_access_(false),
500 creation_flags_(0) {
501 DCHECK(path.empty() || path.IsAbsolute());
502 path_ = crx_file::id_util::MaybeNormalizePath(path);
505 Extension::~Extension() {
508 bool Extension::InitFromValue(int flags, base::string16* error) {
509 DCHECK(error);
511 creation_flags_ = flags;
513 // Important to load manifest version first because many other features
514 // depend on its value.
515 if (!LoadManifestVersion(error))
516 return false;
518 if (!LoadRequiredFeatures(error))
519 return false;
521 // We don't need to validate because InitExtensionID already did that.
522 manifest_->GetString(keys::kPublicKey, &public_key_);
524 extension_url_ = Extension::GetBaseURLFromExtensionId(id());
526 // Load App settings. LoadExtent at least has to be done before
527 // ParsePermissions(), because the valid permissions depend on what type of
528 // package this is.
529 if (is_app() && !LoadAppFeatures(error))
530 return false;
532 permissions_parser_.reset(new PermissionsParser());
533 if (!permissions_parser_->Parse(this, error))
534 return false;
536 if (manifest_->HasKey(keys::kConvertedFromUserScript)) {
537 manifest_->GetBoolean(keys::kConvertedFromUserScript,
538 &converted_from_user_script_);
541 if (!LoadSharedFeatures(error))
542 return false;
544 permissions_parser_->Finalize(this);
545 permissions_parser_.reset();
547 finished_parsing_manifest_ = true;
549 permissions_data_.reset(new PermissionsData(this));
551 return true;
554 bool Extension::LoadRequiredFeatures(base::string16* error) {
555 if (!LoadName(error) ||
556 !LoadVersion(error))
557 return false;
558 return true;
561 bool Extension::LoadName(base::string16* error) {
562 base::string16 localized_name;
563 if (!manifest_->GetString(keys::kName, &localized_name)) {
564 *error = base::ASCIIToUTF16(errors::kInvalidName);
565 return false;
567 non_localized_name_ = base::UTF16ToUTF8(localized_name);
568 base::i18n::AdjustStringForLocaleDirection(&localized_name);
569 name_ = base::UTF16ToUTF8(localized_name);
570 return true;
573 bool Extension::LoadVersion(base::string16* error) {
574 std::string version_str;
575 if (!manifest_->GetString(keys::kVersion, &version_str)) {
576 *error = base::ASCIIToUTF16(errors::kInvalidVersion);
577 return false;
579 version_.reset(new Version(version_str));
580 if (!version_->IsValid() || version_->components().size() > 4) {
581 *error = base::ASCIIToUTF16(errors::kInvalidVersion);
582 return false;
584 if (manifest_->HasKey(keys::kVersionName)) {
585 if (!manifest_->GetString(keys::kVersionName, &version_name_)) {
586 *error = base::ASCIIToUTF16(errors::kInvalidVersionName);
587 return false;
590 return true;
593 bool Extension::LoadAppFeatures(base::string16* error) {
594 if (!LoadExtent(keys::kWebURLs, &extent_,
595 errors::kInvalidWebURLs, errors::kInvalidWebURL, error)) {
596 return false;
598 if (manifest_->HasKey(keys::kDisplayInLauncher) &&
599 !manifest_->GetBoolean(keys::kDisplayInLauncher, &display_in_launcher_)) {
600 *error = base::ASCIIToUTF16(errors::kInvalidDisplayInLauncher);
601 return false;
603 if (manifest_->HasKey(keys::kDisplayInNewTabPage)) {
604 if (!manifest_->GetBoolean(keys::kDisplayInNewTabPage,
605 &display_in_new_tab_page_)) {
606 *error = base::ASCIIToUTF16(errors::kInvalidDisplayInNewTabPage);
607 return false;
609 } else {
610 // Inherit default from display_in_launcher property.
611 display_in_new_tab_page_ = display_in_launcher_;
613 return true;
616 bool Extension::LoadExtent(const char* key,
617 URLPatternSet* extent,
618 const char* list_error,
619 const char* value_error,
620 base::string16* error) {
621 const base::Value* temp_pattern_value = NULL;
622 if (!manifest_->Get(key, &temp_pattern_value))
623 return true;
625 const base::ListValue* pattern_list = NULL;
626 if (!temp_pattern_value->GetAsList(&pattern_list)) {
627 *error = base::ASCIIToUTF16(list_error);
628 return false;
631 for (size_t i = 0; i < pattern_list->GetSize(); ++i) {
632 std::string pattern_string;
633 if (!pattern_list->GetString(i, &pattern_string)) {
634 *error = ErrorUtils::FormatErrorMessageUTF16(value_error,
635 base::UintToString(i),
636 errors::kExpectString);
637 return false;
640 URLPattern pattern(kValidWebExtentSchemes);
641 URLPattern::ParseResult parse_result = pattern.Parse(pattern_string);
642 if (parse_result == URLPattern::PARSE_ERROR_EMPTY_PATH) {
643 pattern_string += "/";
644 parse_result = pattern.Parse(pattern_string);
647 if (parse_result != URLPattern::PARSE_SUCCESS) {
648 *error = ErrorUtils::FormatErrorMessageUTF16(
649 value_error,
650 base::UintToString(i),
651 URLPattern::GetParseResultString(parse_result));
652 return false;
655 // Do not allow authors to claim "<all_urls>".
656 if (pattern.match_all_urls()) {
657 *error = ErrorUtils::FormatErrorMessageUTF16(
658 value_error,
659 base::UintToString(i),
660 errors::kCannotClaimAllURLsInExtent);
661 return false;
664 // Do not allow authors to claim "*" for host.
665 if (pattern.host().empty()) {
666 *error = ErrorUtils::FormatErrorMessageUTF16(
667 value_error,
668 base::UintToString(i),
669 errors::kCannotClaimAllHostsInExtent);
670 return false;
673 // We do not allow authors to put wildcards in their paths. Instead, we
674 // imply one at the end.
675 if (pattern.path().find('*') != std::string::npos) {
676 *error = ErrorUtils::FormatErrorMessageUTF16(
677 value_error,
678 base::UintToString(i),
679 errors::kNoWildCardsInPaths);
680 return false;
682 pattern.SetPath(pattern.path() + '*');
684 extent->AddPattern(pattern);
687 return true;
690 bool Extension::LoadSharedFeatures(base::string16* error) {
691 if (!LoadDescription(error) ||
692 !ManifestHandler::ParseExtension(this, error) ||
693 !LoadShortName(error))
694 return false;
696 return true;
699 bool Extension::LoadDescription(base::string16* error) {
700 if (manifest_->HasKey(keys::kDescription) &&
701 !manifest_->GetString(keys::kDescription, &description_)) {
702 *error = base::ASCIIToUTF16(errors::kInvalidDescription);
703 return false;
705 return true;
708 bool Extension::LoadManifestVersion(base::string16* error) {
709 // Get the original value out of the dictionary so that we can validate it
710 // more strictly.
711 if (manifest_->value()->HasKey(keys::kManifestVersion)) {
712 int manifest_version = 1;
713 if (!manifest_->GetInteger(keys::kManifestVersion, &manifest_version) ||
714 manifest_version < 1) {
715 *error = base::ASCIIToUTF16(errors::kInvalidManifestVersion);
716 return false;
720 manifest_version_ = manifest_->GetManifestVersion();
721 if (manifest_version_ < kModernManifestVersion &&
722 ((creation_flags_ & REQUIRE_MODERN_MANIFEST_VERSION &&
723 !base::CommandLine::ForCurrentProcess()->HasSwitch(
724 switches::kAllowLegacyExtensionManifests)) ||
725 GetType() == Manifest::TYPE_PLATFORM_APP)) {
726 *error = ErrorUtils::FormatErrorMessageUTF16(
727 errors::kInvalidManifestVersionOld,
728 base::IntToString(kModernManifestVersion),
729 is_platform_app() ? "apps" : "extensions");
730 return false;
733 return true;
736 bool Extension::LoadShortName(base::string16* error) {
737 if (manifest_->HasKey(keys::kShortName)) {
738 base::string16 localized_short_name;
739 if (!manifest_->GetString(keys::kShortName, &localized_short_name) ||
740 localized_short_name.empty()) {
741 *error = base::ASCIIToUTF16(errors::kInvalidShortName);
742 return false;
745 base::i18n::AdjustStringForLocaleDirection(&localized_short_name);
746 short_name_ = base::UTF16ToUTF8(localized_short_name);
747 } else {
748 short_name_ = name_;
750 return true;
753 ExtensionInfo::ExtensionInfo(const base::DictionaryValue* manifest,
754 const std::string& id,
755 const base::FilePath& path,
756 Manifest::Location location)
757 : extension_id(id),
758 extension_path(path),
759 extension_location(location) {
760 if (manifest)
761 extension_manifest.reset(manifest->DeepCopy());
764 ExtensionInfo::~ExtensionInfo() {}
766 InstalledExtensionInfo::InstalledExtensionInfo(
767 const Extension* extension,
768 bool is_update,
769 bool from_ephemeral,
770 const std::string& old_name)
771 : extension(extension),
772 is_update(is_update),
773 from_ephemeral(from_ephemeral),
774 old_name(old_name) {}
776 UnloadedExtensionInfo::UnloadedExtensionInfo(
777 const Extension* extension,
778 UnloadedExtensionInfo::Reason reason)
779 : reason(reason),
780 extension(extension) {}
782 UpdatedExtensionPermissionsInfo::UpdatedExtensionPermissionsInfo(
783 const Extension* extension,
784 const PermissionSet* permissions,
785 Reason reason)
786 : reason(reason),
787 extension(extension),
788 permissions(permissions) {}
790 } // namespace extensions