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

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

Issue 2973903002: [Extensions Bindings] Introduce a supportsLazyListeners property (Closed)
Patch Set: onMessage event fix Created 3 years, 5 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/bindings/api_binding_js_util.h" 5 #include "extensions/renderer/bindings/api_binding_js_util.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "base/values.h" 8 #include "base/values.h"
9 #include "extensions/renderer/bindings/api_event_handler.h" 9 #include "extensions/renderer/bindings/api_event_handler.h"
10 #include "extensions/renderer/bindings/api_request_handler.h" 10 #include "extensions/renderer/bindings/api_request_handler.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 v8::Isolate* isolate = arguments->isolate(); 110 v8::Isolate* isolate = arguments->isolate();
111 v8::HandleScope handle_scope(isolate); 111 v8::HandleScope handle_scope(isolate);
112 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); 112 v8::Local<v8::Context> context = arguments->GetHolderCreationContext();
113 113
114 event_handler_->RegisterArgumentMassager(context, event_name, massager); 114 event_handler_->RegisterArgumentMassager(context, event_name, massager);
115 } 115 }
116 116
117 void APIBindingJSUtil::CreateCustomEvent(gin::Arguments* arguments, 117 void APIBindingJSUtil::CreateCustomEvent(gin::Arguments* arguments,
118 v8::Local<v8::Value> v8_event_name, 118 v8::Local<v8::Value> v8_event_name,
119 v8::Local<v8::Value> unused_schema, 119 v8::Local<v8::Value> unused_schema,
120 bool supports_filters) { 120 bool supports_filters,
121 bool supports_lazy_listeners) {
121 v8::Isolate* isolate = arguments->isolate(); 122 v8::Isolate* isolate = arguments->isolate();
122 v8::HandleScope handle_scope(isolate); 123 v8::HandleScope handle_scope(isolate);
123 v8::Local<v8::Context> context = arguments->GetHolderCreationContext(); 124 v8::Local<v8::Context> context = arguments->GetHolderCreationContext();
124 125
125 std::string event_name; 126 std::string event_name;
126 if (!v8_event_name->IsUndefined()) { 127 if (!v8_event_name->IsUndefined()) {
127 if (!v8_event_name->IsString()) { 128 if (!v8_event_name->IsString()) {
128 NOTREACHED(); 129 NOTREACHED();
129 return; 130 return;
130 } 131 }
131 event_name = gin::V8ToString(v8_event_name); 132 event_name = gin::V8ToString(v8_event_name);
132 } 133 }
133 134
134 DCHECK(!supports_filters || !event_name.empty()) 135 DCHECK(!supports_filters || !event_name.empty())
135 << "Events that support filters cannot be anonymous."; 136 << "Events that support filters cannot be anonymous.";
137 DCHECK(!supports_lazy_listeners || !event_name.empty())
138 << "Events that support lazy listeners cannot be anonymous.";
136 139
137 v8::Local<v8::Value> event; 140 v8::Local<v8::Value> event;
138 if (event_name.empty()) { 141 if (event_name.empty()) {
139 event = event_handler_->CreateAnonymousEventInstance(context); 142 event = event_handler_->CreateAnonymousEventInstance(context);
140 } else { 143 } else {
141 bool notify_on_change = true; 144 bool notify_on_change = true;
142 event = event_handler_->CreateEventInstance(event_name, supports_filters, 145 event = event_handler_->CreateEventInstance(
143 binding::kNoListenerMax, 146 event_name, supports_filters, supports_lazy_listeners,
144 notify_on_change, context); 147 binding::kNoListenerMax, notify_on_change, context);
145 } 148 }
146 149
147 arguments->Return(event); 150 arguments->Return(event);
148 } 151 }
149 152
150 void APIBindingJSUtil::CreateCustomDeclarativeEvent( 153 void APIBindingJSUtil::CreateCustomDeclarativeEvent(
151 gin::Arguments* arguments, 154 gin::Arguments* arguments,
152 const std::string& event_name, 155 const std::string& event_name,
153 const std::vector<std::string>& actions_list, 156 const std::vector<std::string>& actions_list,
154 const std::vector<std::string>& conditions_list, 157 const std::vector<std::string>& conditions_list,
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 exception_handler_->HandleException(context, full_message, exception); 240 exception_handler_->HandleException(context, full_message, exception);
238 } 241 }
239 242
240 void APIBindingJSUtil::SetExceptionHandler(gin::Arguments* arguments, 243 void APIBindingJSUtil::SetExceptionHandler(gin::Arguments* arguments,
241 v8::Local<v8::Function> handler) { 244 v8::Local<v8::Function> handler) {
242 exception_handler_->SetHandlerForContext( 245 exception_handler_->SetHandlerForContext(
243 arguments->GetHolderCreationContext(), handler); 246 arguments->GetHolderCreationContext(), handler);
244 } 247 }
245 248
246 } // namespace extensions 249 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/bindings/api_binding_js_util.h ('k') | extensions/renderer/bindings/api_event_handler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698