| 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/bindings/api_binding_js_util.h" | 5 #include "extensions/renderer/bindings/api_binding_js_util.h" |
| 6 | 6 |
| 7 #include "base/values.h" | 7 #include "base/values.h" |
| 8 #include "extensions/renderer/bindings/api_event_handler.h" | 8 #include "extensions/renderer/bindings/api_event_handler.h" |
| 9 #include "extensions/renderer/bindings/api_request_handler.h" | 9 #include "extensions/renderer/bindings/api_request_handler.h" |
| 10 #include "extensions/renderer/bindings/api_signature.h" | 10 #include "extensions/renderer/bindings/api_signature.h" |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 v8::Isolate* isolate = arguments->isolate(); | 104 v8::Isolate* isolate = arguments->isolate(); |
| 105 v8::HandleScope handle_scope(isolate); | 105 v8::HandleScope handle_scope(isolate); |
| 106 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 106 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
| 107 | 107 |
| 108 event_handler_->RegisterArgumentMassager(context, event_name, massager); | 108 event_handler_->RegisterArgumentMassager(context, event_name, massager); |
| 109 } | 109 } |
| 110 | 110 |
| 111 void APIBindingJSUtil::CreateCustomEvent(gin::Arguments* arguments, | 111 void APIBindingJSUtil::CreateCustomEvent(gin::Arguments* arguments, |
| 112 v8::Local<v8::Value> v8_event_name, | 112 v8::Local<v8::Value> v8_event_name, |
| 113 v8::Local<v8::Value> unused_schema, | 113 v8::Local<v8::Value> unused_schema, |
| 114 bool supports_filters) { | 114 bool supports_filters, |
| 115 bool supports_lazy_listeners) { |
| 115 v8::Isolate* isolate = arguments->isolate(); | 116 v8::Isolate* isolate = arguments->isolate(); |
| 116 v8::HandleScope handle_scope(isolate); | 117 v8::HandleScope handle_scope(isolate); |
| 117 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 118 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
| 118 | 119 |
| 119 std::string event_name; | 120 std::string event_name; |
| 120 if (!v8_event_name->IsUndefined()) { | 121 if (!v8_event_name->IsUndefined()) { |
| 121 if (!v8_event_name->IsString()) { | 122 if (!v8_event_name->IsString()) { |
| 122 NOTREACHED(); | 123 NOTREACHED(); |
| 123 return; | 124 return; |
| 124 } | 125 } |
| 125 event_name = gin::V8ToString(v8_event_name); | 126 event_name = gin::V8ToString(v8_event_name); |
| 126 } | 127 } |
| 127 | 128 |
| 128 DCHECK(!supports_filters || !event_name.empty()) | 129 DCHECK(!supports_filters || !event_name.empty()) |
| 129 << "Events that support filters cannot be anonymous."; | 130 << "Events that support filters cannot be anonymous."; |
| 131 DCHECK(!supports_lazy_listeners || !event_name.empty()) |
| 132 << "Events that support lazy listeners cannot be anonymous."; |
| 130 | 133 |
| 131 v8::Local<v8::Value> event; | 134 v8::Local<v8::Value> event; |
| 132 if (event_name.empty()) { | 135 if (event_name.empty()) { |
| 133 event = event_handler_->CreateAnonymousEventInstance(context); | 136 event = event_handler_->CreateAnonymousEventInstance(context); |
| 134 } else { | 137 } else { |
| 135 bool notify_on_change = true; | 138 bool notify_on_change = true; |
| 136 event = event_handler_->CreateEventInstance(event_name, supports_filters, | 139 event = event_handler_->CreateEventInstance( |
| 137 binding::kNoListenerMax, | 140 event_name, supports_filters, supports_lazy_listeners, |
| 138 notify_on_change, context); | 141 binding::kNoListenerMax, notify_on_change, context); |
| 139 } | 142 } |
| 140 | 143 |
| 141 arguments->Return(event); | 144 arguments->Return(event); |
| 142 } | 145 } |
| 143 | 146 |
| 144 void APIBindingJSUtil::CreateCustomDeclarativeEvent( | 147 void APIBindingJSUtil::CreateCustomDeclarativeEvent( |
| 145 gin::Arguments* arguments, | 148 gin::Arguments* arguments, |
| 146 const std::string& event_name, | 149 const std::string& event_name, |
| 147 const std::vector<std::string>& actions_list, | 150 const std::vector<std::string>& actions_list, |
| 148 const std::vector<std::string>& conditions_list, | 151 const std::vector<std::string>& conditions_list, |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); | 203 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); |
| 201 | 204 |
| 202 request_handler_->last_error()->SetError(context, error); | 205 request_handler_->last_error()->SetError(context, error); |
| 203 run_js_.Run(callback, context, 0, nullptr); | 206 run_js_.Run(callback, context, 0, nullptr); |
| 204 | 207 |
| 205 bool report_if_unchecked = true; | 208 bool report_if_unchecked = true; |
| 206 request_handler_->last_error()->ClearError(context, report_if_unchecked); | 209 request_handler_->last_error()->ClearError(context, report_if_unchecked); |
| 207 } | 210 } |
| 208 | 211 |
| 209 } // namespace extensions | 212 } // namespace extensions |
| OLD | NEW |