| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/browser/component_updater/origin_trials_component_installer.h" | 5 #include "chrome/browser/component_updater/origin_trials_component_installer.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/path_service.h" | 12 #include "base/path_service.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
| 17 #include "components/component_updater/component_updater_paths.h" | 17 #include "components/component_updater/component_updater_paths.h" |
| 18 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
| 19 #include "components/prefs/scoped_user_pref_update.h" | 19 #include "components/prefs/scoped_user_pref_update.h" |
| 20 | 20 |
| 21 // The client-side configuration for the origin trial framework can be | 21 // The client-side configuration for the origin trial framework can be |
| 22 // overridden by an installed component named 'OriginTrials' (extension id | 22 // overridden by an installed component named 'OriginTrials' (extension id |
| 23 // kfoklmclfodeliojeaekpoflbkkhojea. This component currently consists of just a | 23 // llkgjffcdpffmhiakmfcdcblohccpfmo. This component currently consists of just a |
| 24 // manifest.json file, which can contain a custom key named 'origin-trials'. The | 24 // manifest.json file, which can contain a custom key named 'origin-trials'. The |
| 25 // value of this key is a dictionary: | 25 // value of this key is a dictionary: |
| 26 // | 26 // |
| 27 // { | 27 // { |
| 28 // "public-key": "<base64-encoding of replacement public key>", | 28 // "public-key": "<base64-encoding of replacement public key>", |
| 29 // "disabled-features": [<list of features to disable>], | 29 // "disabled-features": [<list of features to disable>], |
| 30 // "revoked-tokens": "<base64-encoded data>" | 30 // "revoked-tokens": "<base64-encoded data>" |
| 31 // } | 31 // } |
| 32 // | 32 // |
| 33 // TODO(iclelland): Implement support for revoked tokens. | |
| 34 // | |
| 35 // If the component is not present in the user data directory, the default | 33 // If the component is not present in the user data directory, the default |
| 36 // configuration will be used. | 34 // configuration will be used. |
| 37 | 35 |
| 38 namespace component_updater { | 36 namespace component_updater { |
| 39 | 37 |
| 40 namespace { | 38 namespace { |
| 41 | 39 |
| 42 static const char kManifestOriginTrialsKey[] = "origin-trials"; | 40 static const char kManifestOriginTrialsKey[] = "origin-trials"; |
| 43 static const char kManifestPublicKeyPath[] = "origin-trials.public-key"; | 41 static const char kManifestPublicKeyPath[] = "origin-trials.public-key"; |
| 44 static const char kManifestDisabledFeaturesPath[] = | 42 static const char kManifestDisabledFeaturesPath[] = |
| 45 "origin-trials.disabled-features"; | 43 "origin-trials.disabled-features"; |
| 44 static const char kManifestDisabledTokensPath[] = |
| 45 "origin-trials.disabled-tokens"; |
| 46 | 46 |
| 47 // Extension id is llkgjffcdpffmhiakmfcdcblohccpfmo | 47 // Extension id is llkgjffcdpffmhiakmfcdcblohccpfmo |
| 48 const uint8_t kSha256Hash[] = {0xbb, 0xa6, 0x95, 0x52, 0x3f, 0x55, 0xc7, 0x80, | 48 const uint8_t kSha256Hash[] = {0xbb, 0xa6, 0x95, 0x52, 0x3f, 0x55, 0xc7, 0x80, |
| 49 0xac, 0x52, 0x32, 0x1b, 0xe7, 0x22, 0xf5, 0xce, | 49 0xac, 0x52, 0x32, 0x1b, 0xe7, 0x22, 0xf5, 0xce, |
| 50 0x6a, 0xfd, 0x9c, 0x9e, 0xa9, 0x2a, 0x0b, 0x50, | 50 0x6a, 0xfd, 0x9c, 0x9e, 0xa9, 0x2a, 0x0b, 0x50, |
| 51 0x60, 0x2b, 0x7f, 0x6c, 0x64, 0x80, 0x09, 0x04}; | 51 0x60, 0x2b, 0x7f, 0x6c, 0x64, 0x80, 0x09, 0x04}; |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 bool OriginTrialsComponentInstallerTraits::VerifyInstallation( | 55 bool OriginTrialsComponentInstallerTraits::VerifyInstallation( |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 base::ListValue* override_disabled_feature_list = nullptr; | 94 base::ListValue* override_disabled_feature_list = nullptr; |
| 95 const bool manifest_has_disabled_features = manifest->GetList( | 95 const bool manifest_has_disabled_features = manifest->GetList( |
| 96 kManifestDisabledFeaturesPath, &override_disabled_feature_list); | 96 kManifestDisabledFeaturesPath, &override_disabled_feature_list); |
| 97 if (manifest_has_disabled_features && | 97 if (manifest_has_disabled_features && |
| 98 !override_disabled_feature_list->empty()) { | 98 !override_disabled_feature_list->empty()) { |
| 99 ListPrefUpdate update(local_state, prefs::kOriginTrialDisabledFeatures); | 99 ListPrefUpdate update(local_state, prefs::kOriginTrialDisabledFeatures); |
| 100 update->Swap(override_disabled_feature_list); | 100 update->Swap(override_disabled_feature_list); |
| 101 } else { | 101 } else { |
| 102 local_state->ClearPref(prefs::kOriginTrialDisabledFeatures); | 102 local_state->ClearPref(prefs::kOriginTrialDisabledFeatures); |
| 103 } | 103 } |
| 104 base::ListValue* disabled_tokens_list = nullptr; |
| 105 const bool manifest_has_disabled_tokens = |
| 106 manifest->GetList(kManifestDisabledTokensPath, &disabled_tokens_list); |
| 107 if (manifest_has_disabled_tokens && !disabled_tokens_list->empty()) { |
| 108 ListPrefUpdate update(local_state, prefs::kOriginTrialDisabledTokens); |
| 109 update->Swap(disabled_tokens_list); |
| 110 } else { |
| 111 local_state->ClearPref(prefs::kOriginTrialDisabledTokens); |
| 112 } |
| 104 } | 113 } |
| 105 | 114 |
| 106 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() | 115 base::FilePath OriginTrialsComponentInstallerTraits::GetRelativeInstallDir() |
| 107 const { | 116 const { |
| 108 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); | 117 return base::FilePath(FILE_PATH_LITERAL("OriginTrials")); |
| 109 } | 118 } |
| 110 | 119 |
| 111 void OriginTrialsComponentInstallerTraits::GetHash( | 120 void OriginTrialsComponentInstallerTraits::GetHash( |
| 112 std::vector<uint8_t>* hash) const { | 121 std::vector<uint8_t>* hash) const { |
| 113 if (!hash) | 122 if (!hash) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 133 const base::FilePath& user_data_dir) { | 142 const base::FilePath& user_data_dir) { |
| 134 std::unique_ptr<ComponentInstallerTraits> traits( | 143 std::unique_ptr<ComponentInstallerTraits> traits( |
| 135 new OriginTrialsComponentInstallerTraits()); | 144 new OriginTrialsComponentInstallerTraits()); |
| 136 // |cus| will take ownership of |installer| during installer->Register(cus). | 145 // |cus| will take ownership of |installer| during installer->Register(cus). |
| 137 DefaultComponentInstaller* installer = | 146 DefaultComponentInstaller* installer = |
| 138 new DefaultComponentInstaller(std::move(traits)); | 147 new DefaultComponentInstaller(std::move(traits)); |
| 139 installer->Register(cus, base::Closure()); | 148 installer->Register(cus, base::Closure()); |
| 140 } | 149 } |
| 141 | 150 |
| 142 } // namespace component_updater | 151 } // namespace component_updater |
| OLD | NEW |