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

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

Issue 2909673003: [Extensions Bindings] Request JS execution from messaging bindings (Closed)
Patch Set: lazyboy's 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
« no previous file with comments | « extensions/renderer/api_event_handler.h ('k') | extensions/renderer/dispatcher.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_event_handler.h" 5 #include "extensions/renderer/api_event_handler.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <memory> 9 #include <memory>
10 #include <vector> 10 #include <vector>
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 250
251 void APIEventHandler::RegisterArgumentMassager( 251 void APIEventHandler::RegisterArgumentMassager(
252 v8::Local<v8::Context> context, 252 v8::Local<v8::Context> context,
253 const std::string& event_name, 253 const std::string& event_name,
254 v8::Local<v8::Function> massager) { 254 v8::Local<v8::Function> massager) {
255 APIEventPerContextData* data = GetContextData(context, true); 255 APIEventPerContextData* data = GetContextData(context, true);
256 DCHECK(data->massagers.find(event_name) == data->massagers.end()); 256 DCHECK(data->massagers.find(event_name) == data->massagers.end());
257 data->massagers[event_name].Reset(context->GetIsolate(), massager); 257 data->massagers[event_name].Reset(context->GetIsolate(), massager);
258 } 258 }
259 259
260 bool APIEventHandler::HasListenerForEvent(const std::string& event_name,
261 v8::Local<v8::Context> context) {
262 APIEventPerContextData* data = GetContextData(context, false);
263 if (!data)
264 return false;
265
266 auto iter = data->emitters.find(event_name);
267 if (iter == data->emitters.end())
268 return false;
269 EventEmitter* emitter = nullptr;
270 gin::Converter<EventEmitter*>::FromV8(
271 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter);
272 CHECK(emitter);
273 return emitter->GetNumListeners() > 0;
274 }
275
260 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) { 276 void APIEventHandler::InvalidateContext(v8::Local<v8::Context> context) {
261 gin::PerContextData* per_context_data = gin::PerContextData::From(context); 277 gin::PerContextData* per_context_data = gin::PerContextData::From(context);
262 DCHECK(per_context_data); 278 DCHECK(per_context_data);
263 APIEventPerContextData* data = static_cast<APIEventPerContextData*>( 279 APIEventPerContextData* data = static_cast<APIEventPerContextData*>(
264 per_context_data->GetUserData(kExtensionAPIEventPerContextKey)); 280 per_context_data->GetUserData(kExtensionAPIEventPerContextKey));
265 if (!data) 281 if (!data)
266 return; 282 return;
267 283
268 v8::Isolate* isolate = context->GetIsolate(); 284 v8::Isolate* isolate = context->GetIsolate();
269 v8::HandleScope scope(isolate); 285 v8::HandleScope scope(isolate);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 auto iter = data->emitters.find(event_name); 321 auto iter = data->emitters.find(event_name);
306 DCHECK(iter != data->emitters.end()); 322 DCHECK(iter != data->emitters.end());
307 EventEmitter* emitter = nullptr; 323 EventEmitter* emitter = nullptr;
308 gin::Converter<EventEmitter*>::FromV8( 324 gin::Converter<EventEmitter*>::FromV8(
309 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter); 325 context->GetIsolate(), iter->second.Get(context->GetIsolate()), &emitter);
310 CHECK(emitter); 326 CHECK(emitter);
311 return emitter->GetNumListeners(); 327 return emitter->GetNumListeners();
312 } 328 }
313 329
314 } // namespace extensions 330 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/api_event_handler.h ('k') | extensions/renderer/dispatcher.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698