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