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" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 v8::Local<v8::Function> massager) { | 68 v8::Local<v8::Function> massager) { |
69 v8::Isolate* isolate = arguments->isolate(); | 69 v8::Isolate* isolate = arguments->isolate(); |
70 v8::HandleScope handle_scope(isolate); | 70 v8::HandleScope handle_scope(isolate); |
71 v8::Local<v8::Object> holder; | 71 v8::Local<v8::Object> holder; |
72 CHECK(arguments->GetHolder(&holder)); | 72 CHECK(arguments->GetHolder(&holder)); |
73 v8::Local<v8::Context> context = holder->CreationContext(); | 73 v8::Local<v8::Context> context = holder->CreationContext(); |
74 | 74 |
75 event_handler_->RegisterArgumentMassager(context, event_name, massager); | 75 event_handler_->RegisterArgumentMassager(context, event_name, massager); |
76 } | 76 } |
77 | 77 |
78 void APIBindingJSUtil::CreateCustomEvent( | 78 void APIBindingJSUtil::CreateCustomEvent(gin::Arguments* arguments, |
79 gin::Arguments* arguments, | 79 v8::Local<v8::Value> v8_event_name, |
80 v8::Local<v8::Value> v8_event_name, | 80 v8::Local<v8::Value> unused_schema, |
81 v8::Local<v8::Value> unused_schema, | 81 bool supports_filters) { |
82 v8::Local<v8::Value> unused_event_options) { | |
83 v8::Isolate* isolate = arguments->isolate(); | 82 v8::Isolate* isolate = arguments->isolate(); |
84 v8::HandleScope handle_scope(isolate); | 83 v8::HandleScope handle_scope(isolate); |
85 v8::Local<v8::Object> holder; | 84 v8::Local<v8::Object> holder; |
86 CHECK(arguments->GetHolder(&holder)); | 85 CHECK(arguments->GetHolder(&holder)); |
87 v8::Local<v8::Context> context = holder->CreationContext(); | 86 v8::Local<v8::Context> context = holder->CreationContext(); |
88 | 87 |
89 std::string event_name; | 88 std::string event_name; |
90 if (!v8_event_name->IsUndefined()) { | 89 if (!v8_event_name->IsUndefined()) { |
91 if (!v8_event_name->IsString()) { | 90 if (!v8_event_name->IsString()) { |
92 NOTREACHED(); | 91 NOTREACHED(); |
93 return; | 92 return; |
94 } | 93 } |
95 event_name = gin::V8ToString(v8_event_name); | 94 event_name = gin::V8ToString(v8_event_name); |
96 } | 95 } |
97 | 96 |
| 97 DCHECK(!supports_filters || !event_name.empty()) |
| 98 << "Events that support filters cannot be anonymous."; |
| 99 |
98 v8::Local<v8::Value> event; | 100 v8::Local<v8::Value> event; |
99 if (event_name.empty()) | 101 if (event_name.empty()) { |
100 event = event_handler_->CreateAnonymousEventInstance(context); | 102 event = event_handler_->CreateAnonymousEventInstance(context); |
101 else | 103 } else { |
102 event = event_handler_->CreateEventInstance(event_name, context); | 104 event = event_handler_->CreateEventInstance(event_name, supports_filters, |
| 105 context); |
| 106 } |
103 | 107 |
104 arguments->Return(event); | 108 arguments->Return(event); |
105 } | 109 } |
106 | 110 |
107 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, | 111 void APIBindingJSUtil::InvalidateEvent(gin::Arguments* arguments, |
108 v8::Local<v8::Object> event) { | 112 v8::Local<v8::Object> event) { |
109 v8::Isolate* isolate = arguments->isolate(); | 113 v8::Isolate* isolate = arguments->isolate(); |
110 v8::HandleScope handle_scope(isolate); | 114 v8::HandleScope handle_scope(isolate); |
111 v8::Local<v8::Object> holder; | 115 v8::Local<v8::Object> holder; |
112 CHECK(arguments->GetHolder(&holder)); | 116 CHECK(arguments->GetHolder(&holder)); |
113 v8::Local<v8::Context> context = holder->CreationContext(); | 117 v8::Local<v8::Context> context = holder->CreationContext(); |
114 event_handler_->InvalidateCustomEvent(context, event); | 118 event_handler_->InvalidateCustomEvent(context, event); |
115 } | 119 } |
116 | 120 |
117 } // namespace extensions | 121 } // namespace extensions |
OLD | NEW |