OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/extensions/extension_management_internal.h" |
| 6 |
| 7 #include "base/logging.h" |
| 8 #include "base/values.h" |
| 9 #include "chrome/browser/extensions/extension_management_constants.h" |
| 10 #include "extensions/common/url_pattern_set.h" |
| 11 #include "url/gurl.h" |
| 12 |
| 13 namespace extensions { |
| 14 |
| 15 namespace internal { |
| 16 |
| 17 namespace { |
| 18 const char kMalformedPreferenceWarning[] = |
| 19 "Malformed extension management preference."; |
| 20 } // namespace |
| 21 |
| 22 IndividualSettings::IndividualSettings() { |
| 23 Reset(); |
| 24 } |
| 25 |
| 26 IndividualSettings::~IndividualSettings() { |
| 27 } |
| 28 |
| 29 bool IndividualSettings::Parse(const base::DictionaryValue* dict, |
| 30 ParsingScope scope) { |
| 31 std::string installation_mode_str; |
| 32 if (dict->GetStringWithoutPathExpansion(schema_constants::kInstallationMode, |
| 33 &installation_mode_str)) { |
| 34 if (installation_mode_str == schema_constants::kAllowed) { |
| 35 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
| 36 } else if (installation_mode_str == schema_constants::kBlocked) { |
| 37 installation_mode = ExtensionManagement::INSTALLATION_BLOCKED; |
| 38 } else if (installation_mode_str == schema_constants::kForceInstalled) { |
| 39 installation_mode = ExtensionManagement::INSTALLATION_FORCED; |
| 40 } else if (installation_mode_str == schema_constants::kNormalInstalled) { |
| 41 installation_mode = ExtensionManagement::INSTALLATION_RECOMMENDED; |
| 42 } else { |
| 43 // Invalid value for 'installation_mode'. |
| 44 LOG(WARNING) << kMalformedPreferenceWarning; |
| 45 return false; |
| 46 } |
| 47 |
| 48 // Only proceed to fetch update url if force or recommended install mode |
| 49 // is set. |
| 50 if (installation_mode == ExtensionManagement::INSTALLATION_FORCED || |
| 51 installation_mode == ExtensionManagement::INSTALLATION_RECOMMENDED) { |
| 52 if (scope != SCOPE_INDIVIDUAL) { |
| 53 // Only individual extensions are allowed to be automatically installed. |
| 54 LOG(WARNING) << kMalformedPreferenceWarning; |
| 55 return false; |
| 56 } |
| 57 std::string update_url_str; |
| 58 if (dict->GetStringWithoutPathExpansion(schema_constants::kUpdateUrl, |
| 59 &update_url_str) && |
| 60 GURL(update_url_str).is_valid()) { |
| 61 update_url = update_url_str; |
| 62 } else { |
| 63 // No valid update URL for extension. |
| 64 LOG(WARNING) << kMalformedPreferenceWarning; |
| 65 return false; |
| 66 } |
| 67 } |
| 68 } |
| 69 |
| 70 return true; |
| 71 } |
| 72 |
| 73 void IndividualSettings::Reset() { |
| 74 installation_mode = ExtensionManagement::INSTALLATION_ALLOWED; |
| 75 update_url.clear(); |
| 76 } |
| 77 |
| 78 GlobalSettings::GlobalSettings() { |
| 79 Reset(); |
| 80 } |
| 81 |
| 82 GlobalSettings::~GlobalSettings() { |
| 83 } |
| 84 |
| 85 void GlobalSettings::Reset() { |
| 86 has_restricted_install_sources = false; |
| 87 install_sources.ClearPatterns(); |
| 88 has_restricted_allowed_types = false; |
| 89 allowed_types.clear(); |
| 90 } |
| 91 |
| 92 } // namespace internal |
| 93 |
| 94 } // namespace extensions |
OLD | NEW |