rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 1 | // Copyright 2017 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 EXTENSIONS_RENDERER_CHROME_SETTING_H_ |
| 6 | #define EXTENSIONS_RENDERER_CHROME_SETTING_H_ |
| 7 | |
| 8 | #include <string> |
| 9 | |
| 10 | #include "base/macros.h" |
rdevlin.cronin | d4bcb1e | 2017-06-23 21:01:04 | [diff] [blame] | 11 | #include "extensions/renderer/bindings/argument_spec.h" |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 12 | #include "gin/wrappable.h" |
| 13 | #include "v8/include/v8.h" |
| 14 | |
| 15 | namespace base { |
| 16 | class DictionaryValue; |
rdevlin.cronin | d4427b79 | 2017-04-20 00:25:56 | [diff] [blame] | 17 | class ListValue; |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | namespace gin { |
| 21 | class Arguments; |
| 22 | } |
| 23 | |
| 24 | namespace extensions { |
| 25 | class APIEventHandler; |
| 26 | class APIRequestHandler; |
rdevlin.cronin | 72276223 | 2017-06-22 16:40:23 | [diff] [blame] | 27 | class BindingAccessChecker; |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 28 | |
| 29 | // The custom implementation of the ChromeSetting type exposed to APIs. |
| 30 | class ChromeSetting final : public gin::Wrappable<ChromeSetting> { |
| 31 | public: |
| 32 | ~ChromeSetting() override; |
| 33 | |
| 34 | // Creates a ChromeSetting object for the given property. |
rdevlin.cronin | 72276223 | 2017-06-22 16:40:23 | [diff] [blame] | 35 | static v8::Local<v8::Object> Create( |
| 36 | v8::Isolate* isolate, |
| 37 | const std::string& property_name, |
| 38 | const base::ListValue* property_values, |
| 39 | APIRequestHandler* request_handler, |
| 40 | APIEventHandler* event_handler, |
| 41 | APITypeReferenceMap* type_refs, |
| 42 | const BindingAccessChecker* access_checker); |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 43 | |
| 44 | static gin::WrapperInfo kWrapperInfo; |
| 45 | |
| 46 | gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 47 | v8::Isolate* isolate) override; |
Devlin Cronin | d00988c | 2018-04-19 15:45:11 | [diff] [blame] | 48 | const char* GetTypeName() override; |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 49 | |
| 50 | private: |
| 51 | ChromeSetting(APIRequestHandler* request_handler, |
| 52 | APIEventHandler* event_handler, |
| 53 | const APITypeReferenceMap* type_refs, |
rdevlin.cronin | 72276223 | 2017-06-22 16:40:23 | [diff] [blame] | 54 | const BindingAccessChecker* access_checker, |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 55 | const std::string& pref_name, |
| 56 | const base::DictionaryValue& argument_spec); |
| 57 | |
| 58 | // JS function handlers: |
| 59 | void Get(gin::Arguments* arguments); |
| 60 | void Set(gin::Arguments* arguments); |
| 61 | void Clear(gin::Arguments* arguments); |
| 62 | |
| 63 | // Returns the onChange event associated with the ChromeSetting. |
| 64 | v8::Local<v8::Value> GetOnChangeEvent(gin::Arguments* arguments); |
| 65 | |
| 66 | // Common function handling endpoint. |
| 67 | void HandleFunction(const std::string& function_name, |
| 68 | gin::Arguments* arguments); |
| 69 | |
| 70 | APIRequestHandler* request_handler_; |
| 71 | |
| 72 | APIEventHandler* event_handler_; |
| 73 | |
| 74 | const APITypeReferenceMap* type_refs_; |
| 75 | |
rdevlin.cronin | 72276223 | 2017-06-22 16:40:23 | [diff] [blame] | 76 | const BindingAccessChecker* const access_checker_; |
| 77 | |
rdevlin.cronin | 7f16f205 | 2017-03-01 03:27:15 | [diff] [blame] | 78 | // The name of the preference this ChromeSetting is managing. |
| 79 | std::string pref_name_; |
| 80 | |
| 81 | // The type of argument that calling set() on the ChromeSetting expects (since |
| 82 | // different settings can take a different type of argument depending on the |
| 83 | // preference it manages). |
| 84 | ArgumentSpec argument_spec_; |
| 85 | |
| 86 | DISALLOW_COPY_AND_ASSIGN(ChromeSetting); |
| 87 | }; |
| 88 | |
| 89 | } // namespace extensions |
| 90 | |
| 91 | #endif // EXTENSIONS_RENDERER_CHROME_SETTING_H_ |