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

Side by Side Diff: extensions/renderer/api_binding_js_util.cc

Issue 2912883004: [Extensions Bindings] Don't allow `event` module with native bindings (Closed)
Patch Set: . Created 3 years, 6 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
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "extensions/renderer/api_binding_js_util.h" 5 #include "extensions/renderer/api_binding_js_util.h"
6 6
7 #include "base/values.h" 7 #include "base/values.h"
8 #include "extensions/renderer/api_event_handler.h" 8 #include "extensions/renderer/api_event_handler.h"
9 #include "extensions/renderer/api_request_handler.h" 9 #include "extensions/renderer/api_request_handler.h"
10 #include "extensions/renderer/api_signature.h" 10 #include "extensions/renderer/api_signature.h"
11 #include "extensions/renderer/api_type_reference_map.h" 11 #include "extensions/renderer/api_type_reference_map.h"
12 #include "extensions/renderer/declarative_event.h"
12 #include "gin/converter.h" 13 #include "gin/converter.h"
13 #include "gin/dictionary.h" 14 #include "gin/dictionary.h"
15 #include "gin/handle.h"
14 #include "gin/object_template_builder.h" 16 #include "gin/object_template_builder.h"
15 17
16 namespace extensions { 18 namespace extensions {
17 19
18 gin::WrapperInfo APIBindingJSUtil::kWrapperInfo = {gin::kEmbedderNativeGin}; 20 gin::WrapperInfo APIBindingJSUtil::kWrapperInfo = {gin::kEmbedderNativeGin};
19 21
20 APIBindingJSUtil::APIBindingJSUtil(const APITypeReferenceMap* type_refs, 22 APIBindingJSUtil::APIBindingJSUtil(APITypeReferenceMap* type_refs,
21 APIRequestHandler* request_handler, 23 APIRequestHandler* request_handler,
22 APIEventHandler* event_handler, 24 APIEventHandler* event_handler,
23 const binding::RunJSFunction& run_js) 25 const binding::RunJSFunction& run_js)
24 : type_refs_(type_refs), 26 : type_refs_(type_refs),
25 request_handler_(request_handler), 27 request_handler_(request_handler),
26 event_handler_(event_handler), 28 event_handler_(event_handler),
27 run_js_(run_js) {} 29 run_js_(run_js) {}
28 30
29 APIBindingJSUtil::~APIBindingJSUtil() {} 31 APIBindingJSUtil::~APIBindingJSUtil() {}
30 32
31 gin::ObjectTemplateBuilder APIBindingJSUtil::GetObjectTemplateBuilder( 33 gin::ObjectTemplateBuilder APIBindingJSUtil::GetObjectTemplateBuilder(
32 v8::Isolate* isolate) { 34 v8::Isolate* isolate) {
33 return Wrappable<APIBindingJSUtil>::GetObjectTemplateBuilder(isolate) 35 return Wrappable<APIBindingJSUtil>::GetObjectTemplateBuilder(isolate)
34 .SetMethod("sendRequest", &APIBindingJSUtil::SendRequest) 36 .SetMethod("sendRequest", &APIBindingJSUtil::SendRequest)
35 .SetMethod("registerEventArgumentMassager", 37 .SetMethod("registerEventArgumentMassager",
36 &APIBindingJSUtil::RegisterEventArgumentMassager) 38 &APIBindingJSUtil::RegisterEventArgumentMassager)
37 .SetMethod("createCustomEvent", &APIBindingJSUtil::CreateCustomEvent) 39 .SetMethod("createCustomEvent", &APIBindingJSUtil::CreateCustomEvent)
40 .SetMethod("createCustomDeclarativeEvent",
41 &APIBindingJSUtil::CreateCustomDeclarativeEvent)
38 .SetMethod("invalidateEvent", &APIBindingJSUtil::InvalidateEvent) 42 .SetMethod("invalidateEvent", &APIBindingJSUtil::InvalidateEvent)
39 .SetMethod("setLastError", &APIBindingJSUtil::SetLastError) 43 .SetMethod("setLastError", &APIBindingJSUtil::SetLastError)
40 .SetMethod("clearLastError", &APIBindingJSUtil::ClearLastError) 44 .SetMethod("clearLastError", &APIBindingJSUtil::ClearLastError)
41 .SetMethod("hasLastError", &APIBindingJSUtil::HasLastError) 45 .SetMethod("hasLastError", &APIBindingJSUtil::HasLastError)
42 .SetMethod("runCallbackWithLastError", 46 .SetMethod("runCallbackWithLastError",
43 &APIBindingJSUtil::RunCallbackWithLastError); 47 &APIBindingJSUtil::RunCallbackWithLastError);
44 } 48 }
45 49
46 void APIBindingJSUtil::SendRequest( 50 void APIBindingJSUtil::SendRequest(
47 gin::Arguments* arguments, 51 gin::Arguments* arguments,
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
128 if (event_name.empty()) { 132 if (event_name.empty()) {
129 event = event_handler_->CreateAnonymousEventInstance(context); 133 event = event_handler_->CreateAnonymousEventInstance(context);
130 } else { 134 } else {
131 event = event_handler_->CreateEventInstance( 135 event = event_handler_->CreateEventInstance(
132 event_name, supports_filters, binding::kNoListenerMax, context); 136 event_name, supports_filters, binding::kNoListenerMax, context);
133 } 137 }
134 138
135 arguments->Return(event); 139 arguments->Return(event);
136 } 140 }
137 141
142 void APIBindingJSUtil::CreateCustomDeclarativeEvent(
143 gin::Arguments* arguments,
144 const std::string& event_name,
145 const std::vector<std::string>& actions_list,
146 const std::vector<std::string>& conditions_list,
147 int webview_id) {
148 v8::Isolate* isolate = arguments->isolate();
149 v8::HandleScope handle_scope(isolate);
150
151 gin::Handle<DeclarativeEvent> event = gin::CreateHandle(
152 isolate, new DeclarativeEvent(event_name, type_refs_, request_handler_,
153 actions_list, conditions_list, webview_id));
154
155 arguments->Return(event.ToV8());
156 }
157
138 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, 158 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments,
139 v8::Local<v8::Object> event) { 159 v8::Local<v8::Object> event) {
140 v8::Isolate* isolate = arguments->isolate(); 160 v8::Isolate* isolate = arguments->isolate();
141 v8::HandleScope handle_scope(isolate); 161 v8::HandleScope handle_scope(isolate);
142 event_handler_->InvalidateCustomEvent(arguments->GetHolderCreationContext(), 162 event_handler_->InvalidateCustomEvent(arguments->GetHolderCreationContext(),
143 event); 163 event);
144 } 164 }
145 165
146 void APIBindingJSUtil::SetLastError(gin::Arguments* arguments, 166 void APIBindingJSUtil::SetLastError(gin::Arguments* arguments,
147 const std::string& error) { 167 const std::string& error) {
(...skipping 29 matching lines...) Expand all
177 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); 197 v8::Local<v8::Context> context = arguments->GetHolderCreationContext();
178 198
179 request_handler_->last_error()->SetError(context, error); 199 request_handler_->last_error()->SetError(context, error);
180 run_js_.Run(callback, context, 0, nullptr); 200 run_js_.Run(callback, context, 0, nullptr);
181 201
182 bool report_if_unchecked = true; 202 bool report_if_unchecked = true;
183 request_handler_->last_error()->ClearError(context, report_if_unchecked); 203 request_handler_->last_error()->ClearError(context, report_if_unchecked);
184 } 204 }
185 205
186 } // namespace extensions 206 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698