OLD | NEW |
(Empty) | |
| 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" |
| 11 #include "extensions/renderer/argument_spec.h" |
| 12 #include "gin/wrappable.h" |
| 13 #include "v8/include/v8.h" |
| 14 |
| 15 namespace base { |
| 16 class DictionaryValue; |
| 17 } |
| 18 |
| 19 namespace gin { |
| 20 class Arguments; |
| 21 } |
| 22 |
| 23 namespace extensions { |
| 24 class APIEventHandler; |
| 25 class APIRequestHandler; |
| 26 |
| 27 // The custom implementation of the ChromeSetting type exposed to APIs. |
| 28 class ChromeSetting final : public gin::Wrappable<ChromeSetting> { |
| 29 public: |
| 30 ~ChromeSetting() override; |
| 31 |
| 32 // Creates a ChromeSetting object for the given property. |
| 33 static v8::Local<v8::Object> Create(v8::Local<v8::Context> context, |
| 34 const std::string& property_name, |
| 35 APIRequestHandler* request_handler, |
| 36 APIEventHandler* event_handler, |
| 37 APITypeReferenceMap* type_refs); |
| 38 |
| 39 static gin::WrapperInfo kWrapperInfo; |
| 40 |
| 41 gin::ObjectTemplateBuilder GetObjectTemplateBuilder( |
| 42 v8::Isolate* isolate) override; |
| 43 |
| 44 private: |
| 45 ChromeSetting(APIRequestHandler* request_handler, |
| 46 APIEventHandler* event_handler, |
| 47 const APITypeReferenceMap* type_refs, |
| 48 const std::string& pref_name, |
| 49 const base::DictionaryValue& argument_spec); |
| 50 |
| 51 // JS function handlers: |
| 52 void Get(gin::Arguments* arguments); |
| 53 void Set(gin::Arguments* arguments); |
| 54 void Clear(gin::Arguments* arguments); |
| 55 |
| 56 // Returns the onChange event associated with the ChromeSetting. |
| 57 v8::Local<v8::Value> GetOnChangeEvent(gin::Arguments* arguments); |
| 58 |
| 59 // Common function handling endpoint. |
| 60 void HandleFunction(const std::string& function_name, |
| 61 gin::Arguments* arguments); |
| 62 |
| 63 APIRequestHandler* request_handler_; |
| 64 |
| 65 APIEventHandler* event_handler_; |
| 66 |
| 67 const APITypeReferenceMap* type_refs_; |
| 68 |
| 69 // The name of the preference this ChromeSetting is managing. |
| 70 std::string pref_name_; |
| 71 |
| 72 // The type of argument that calling set() on the ChromeSetting expects (since |
| 73 // different settings can take a different type of argument depending on the |
| 74 // preference it manages). |
| 75 ArgumentSpec argument_spec_; |
| 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(ChromeSetting); |
| 78 }; |
| 79 |
| 80 } // namespace extensions |
| 81 |
| 82 #endif // EXTENSIONS_RENDERER_CHROME_SETTING_H_ |
OLD | NEW |