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