Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: extensions/renderer/chrome_setting.h

Issue 2718543004: [Extensions Bindings] Add ChromeSetting custom type (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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> CreateChromeSetting(
jbroman 2017/02/24 18:08:45 nit: could just call it "Create", given it will be
Devlin 2017/02/24 20:12:28 Done.
34 v8::Local<v8::Context> context,
35 const std::string& property_name,
36 APIRequestHandler* request_handler,
37 APIEventHandler* event_handler,
38 APITypeReferenceMap* type_refs);
39
40 static gin::WrapperInfo kWrapperInfo;
41
42 gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
43 v8::Isolate* isolate) override;
44
45 private:
46 ChromeSetting(APIRequestHandler* request_handler,
47 APIEventHandler* event_handler,
48 const APITypeReferenceMap* type_refs,
49 const std::string& pref_name,
50 const base::DictionaryValue& argument_spec);
51
52 // JS function handlers:
53 void Get(gin::Arguments* arguments);
54 void Set(gin::Arguments* arguments);
55 void Clear(gin::Arguments* arguments);
56
57 // Returns the onChange event associated with the ChromeSetting.
58 v8::Local<v8::Value> GetOnChangeEvent(gin::Arguments* arguments);
59
60 // Common function handling endpoint.
61 void HandleFunction(const std::string& function_name,
62 gin::Arguments* arguments);
63
64 APIRequestHandler* request_handler_;
65
66 APIEventHandler* event_handler_;
67
68 const APITypeReferenceMap* type_refs_;
69
70 // The name of the preference this ChromeSetting is managing.
71 std::string pref_name_;
72
73 // The type of argument that calling set() on the ChromeSetting expects (since
74 // different settings can take a different type of argument depending on the
75 // preference it manages).
76 ArgumentSpec argument_spec_;
77
78 // A reference to the onChange event.
79 v8::Global<v8::Value> event_;
jbroman 2017/02/24 18:08:45 This can cause a leak. Suppose the extension autho
Devlin 2017/02/24 20:12:28 Done.
80
81 DISALLOW_COPY_AND_ASSIGN(ChromeSetting);
82 };
83
84 } // namespace extensions
85
86 #endif // EXTENSIONS_RENDERER_CHROME_SETTING_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698