| OLD | NEW |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 } else { | 134 } else { |
| 131 bool notify_on_change = true; | 135 bool notify_on_change = true; |
| 132 event = event_handler_->CreateEventInstance(event_name, supports_filters, | 136 event = event_handler_->CreateEventInstance(event_name, supports_filters, |
| 133 binding::kNoListenerMax, | 137 binding::kNoListenerMax, |
| 134 notify_on_change, context); | 138 notify_on_change, context); |
| 135 } | 139 } |
| 136 | 140 |
| 137 arguments->Return(event); | 141 arguments->Return(event); |
| 138 } | 142 } |
| 139 | 143 |
| 144 void APIBindingJSUtil::CreateCustomDeclarativeEvent( |
| 145 gin::Arguments* arguments, |
| 146 const std::string& event_name, |
| 147 const std::vector<std::string>& actions_list, |
| 148 const std::vector<std::string>& conditions_list, |
| 149 int webview_instance_id) { |
| 150 v8::Isolate* isolate = arguments->isolate(); |
| 151 v8::HandleScope handle_scope(isolate); |
| 152 |
| 153 gin::Handle<DeclarativeEvent> event = gin::CreateHandle( |
| 154 isolate, |
| 155 new DeclarativeEvent(event_name, type_refs_, request_handler_, |
| 156 actions_list, conditions_list, webview_instance_id)); |
| 157 |
| 158 arguments->Return(event.ToV8()); |
| 159 } |
| 160 |
| 140 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, | 161 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, |
| 141 v8::Local<v8::Object> event) { | 162 v8::Local<v8::Object> event) { |
| 142 v8::Isolate* isolate = arguments->isolate(); | 163 v8::Isolate* isolate = arguments->isolate(); |
| 143 v8::HandleScope handle_scope(isolate); | 164 v8::HandleScope handle_scope(isolate); |
| 144 event_handler_->InvalidateCustomEvent(arguments->GetHolderCreationContext(), | 165 event_handler_->InvalidateCustomEvent(arguments->GetHolderCreationContext(), |
| 145 event); | 166 event); |
| 146 } | 167 } |
| 147 | 168 |
| 148 void APIBindingJSUtil::SetLastError(gin::Arguments* arguments, | 169 void APIBindingJSUtil::SetLastError(gin::Arguments* arguments, |
| 149 const std::string& error) { | 170 const std::string& error) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 179 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 200 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
| 180 | 201 |
| 181 request_handler_->last_error()->SetError(context, error); | 202 request_handler_->last_error()->SetError(context, error); |
| 182 run_js_.Run(callback, context, 0, nullptr); | 203 run_js_.Run(callback, context, 0, nullptr); |
| 183 | 204 |
| 184 bool report_if_unchecked = true; | 205 bool report_if_unchecked = true; |
| 185 request_handler_->last_error()->ClearError(context, report_if_unchecked); | 206 request_handler_->last_error()->ClearError(context, report_if_unchecked); |
| 186 } | 207 } |
| 187 | 208 |
| 188 } // namespace extensions | 209 } // namespace extensions |
| OLD | NEW |