| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "chrome/browser/extensions/external_extension_loader.h" | |
| 10 | |
| 11 #include <string> | |
| 12 | |
| 13 #include "base/compiler_specific.h" | |
| 14 #include "base/memory/scoped_ptr.h" | |
| 15 #include "base/values.h" | |
| 16 | |
| 17 // A specialization of the ExternalExtensionLoader that uses a json file to | |
| 18 // look up which external extensions are registered. | |
| 19 // Instances of this class are expected to be created and destroyed on the UI | |
| 20 // thread and they are expecting public method calls from the UI thread. | |
| 21 class ExternalPrefExtensionLoader : public ExternalExtensionLoader { | |
| 22 public: | |
| 23 enum Options { | |
| 24 NONE = 0, | |
| 25 | |
| 26 // Ensure that only root can force an external install by checking | |
| 27 // that all components of the path to external extensions files are | |
| 28 // owned by root and not writable by any non-root user. | |
| 29 ENSURE_PATH_CONTROLLED_BY_ADMIN = 1 << 0 | |
| 30 }; | |
| 31 | |
| 32 // |base_path_id| is the directory containing the external_extensions.json | |
| 33 // file or the standalone extension manifest files. Relative file paths to | |
| 34 // extension files are resolved relative to this path. | |
| 35 explicit ExternalPrefExtensionLoader(int base_path_id, Options options); | |
| 36 | |
| 37 virtual const FilePath GetBaseCrxFilePath() OVERRIDE; | |
| 38 | |
| 39 protected: | |
| 40 virtual void StartLoading() OVERRIDE; | |
| 41 bool IsOptionSet(Options option) { | |
| 42 return (options_ & option) != 0; | |
| 43 } | |
| 44 | |
| 45 private: | |
| 46 friend class base::RefCountedThreadSafe<ExternalExtensionLoader>; | |
| 47 | |
| 48 virtual ~ExternalPrefExtensionLoader() {} | |
| 49 | |
| 50 // Actually searches for and loads candidate standalone extension preference | |
| 51 // files in the path corresponding to |base_path_id|. | |
| 52 // Must be called on the file thread. | |
| 53 void LoadOnFileThread(); | |
| 54 | |
| 55 // Extracts the information contained in an external_extension.json file | |
| 56 // regarding which extensions to install. |prefs| will be modified to | |
| 57 // receive the extracted extension information. | |
| 58 // Must be called from the File thread. | |
| 59 void ReadExternalExtensionPrefFile(DictionaryValue * prefs); | |
| 60 | |
| 61 // Extracts the information contained in standalone external extension | |
| 62 // json files (<extension id>.json) regarding what external extensions | |
| 63 // to install. |prefs| will be modified to receive the extracted extension | |
| 64 // information. | |
| 65 // Must be called from the File thread. | |
| 66 void ReadStandaloneExtensionPrefFiles(DictionaryValue * prefs); | |
| 67 | |
| 68 // The resource id of the base path with the information about the json | |
| 69 // file containing which extensions to load. | |
| 70 int base_path_id_; | |
| 71 | |
| 72 Options options_; | |
| 73 | |
| 74 // The path (coresponding to |base_path_id_| containing the json files | |
| 75 // describing which extensions to load. | |
| 76 FilePath base_path_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(ExternalPrefExtensionLoader); | |
| 79 }; | |
| 80 | |
| 81 // A simplified version of ExternalPrefExtensionLoader that loads the dictionary | |
| 82 // from json data specified in a string. | |
| 83 class ExternalTestingExtensionLoader : public ExternalExtensionLoader { | |
| 84 public: | |
| 85 ExternalTestingExtensionLoader( | |
| 86 const std::string& json_data, | |
| 87 const FilePath& fake_base_path); | |
| 88 | |
| 89 virtual const FilePath GetBaseCrxFilePath() OVERRIDE; | |
| 90 | |
| 91 protected: | |
| 92 virtual void StartLoading() OVERRIDE; | |
| 93 | |
| 94 private: | |
| 95 friend class base::RefCountedThreadSafe<ExternalExtensionLoader>; | |
| 96 | |
| 97 virtual ~ExternalTestingExtensionLoader(); | |
| 98 | |
| 99 FilePath fake_base_path_; | |
| 100 scoped_ptr<DictionaryValue> testing_prefs_; | |
| 101 | |
| 102 DISALLOW_COPY_AND_ASSIGN(ExternalTestingExtensionLoader); | |
| 103 }; | |
| 104 | |
| 105 #endif // CHROME_BROWSER_EXTENSIONS_EXTERNAL_PREF_EXTENSION_LOADER_H_ | |
| OLD | NEW |