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

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

Issue 1115563002: extensions/renderer: Use v8::Local instead of v8::Handle. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/event_bindings.h" 5 #include "extensions/renderer/event_bindings.h"
6 6
7 #include <map> 7 #include <map>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 76
77 bool IsLazyBackgroundPage(content::RenderView* render_view, 77 bool IsLazyBackgroundPage(content::RenderView* render_view,
78 const Extension* extension) { 78 const Extension* extension) {
79 if (!render_view) 79 if (!render_view)
80 return false; 80 return false;
81 ExtensionHelper* helper = ExtensionHelper::Get(render_view); 81 ExtensionHelper* helper = ExtensionHelper::Get(render_view);
82 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) && 82 return (extension && BackgroundInfo::HasLazyBackgroundPage(extension) &&
83 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE); 83 helper->view_type() == VIEW_TYPE_EXTENSION_BACKGROUND_PAGE);
84 } 84 }
85 85
86 EventFilteringInfo ParseFromObject(v8::Handle<v8::Object> object, 86 EventFilteringInfo ParseFromObject(v8::Local<v8::Object> object,
87 v8::Isolate* isolate) { 87 v8::Isolate* isolate) {
88 EventFilteringInfo info; 88 EventFilteringInfo info;
89 v8::Handle<v8::String> url(v8::String::NewFromUtf8(isolate, "url")); 89 v8::Local<v8::String> url(v8::String::NewFromUtf8(isolate, "url"));
90 if (object->Has(url)) { 90 if (object->Has(url)) {
91 v8::Handle<v8::Value> url_value(object->Get(url)); 91 v8::Local<v8::Value> url_value(object->Get(url));
92 info.SetURL(GURL(*v8::String::Utf8Value(url_value))); 92 info.SetURL(GURL(*v8::String::Utf8Value(url_value)));
93 } 93 }
94 v8::Handle<v8::String> instance_id( 94 v8::Local<v8::String> instance_id(
95 v8::String::NewFromUtf8(isolate, "instanceId")); 95 v8::String::NewFromUtf8(isolate, "instanceId"));
96 if (object->Has(instance_id)) { 96 if (object->Has(instance_id)) {
97 v8::Handle<v8::Value> instance_id_value(object->Get(instance_id)); 97 v8::Local<v8::Value> instance_id_value(object->Get(instance_id));
98 info.SetInstanceID(instance_id_value->IntegerValue()); 98 info.SetInstanceID(instance_id_value->IntegerValue());
99 } 99 }
100 v8::Handle<v8::String> service_type( 100 v8::Local<v8::String> service_type(
101 v8::String::NewFromUtf8(isolate, "serviceType")); 101 v8::String::NewFromUtf8(isolate, "serviceType"));
102 if (object->Has(service_type)) { 102 if (object->Has(service_type)) {
103 v8::Handle<v8::Value> service_type_value(object->Get(service_type)); 103 v8::Local<v8::Value> service_type_value(object->Get(service_type));
104 info.SetServiceType(*v8::String::Utf8Value(service_type_value)); 104 info.SetServiceType(*v8::String::Utf8Value(service_type_value));
105 } 105 }
106 return info; 106 return info;
107 } 107 }
108 108
109 // Add a filter to |event_name| in |extension_id|, returning true if it 109 // Add a filter to |event_name| in |extension_id|, returning true if it
110 // was the first filter for that event in that extension. 110 // was the first filter for that event in that extension.
111 bool AddFilter(const std::string& event_name, 111 bool AddFilter(const std::string& event_name,
112 const std::string& extension_id, 112 const std::string& extension_id,
113 base::DictionaryValue* filter) { 113 base::DictionaryValue* filter) {
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
308 v8::Isolate* isolate = args.GetIsolate(); 308 v8::Isolate* isolate = args.GetIsolate();
309 typedef std::set<EventFilter::MatcherID> MatcherIDs; 309 typedef std::set<EventFilter::MatcherID> MatcherIDs;
310 EventFilter& event_filter = g_event_filter.Get(); 310 EventFilter& event_filter = g_event_filter.Get();
311 std::string event_name = *v8::String::Utf8Value(args[0]); 311 std::string event_name = *v8::String::Utf8Value(args[0]);
312 EventFilteringInfo info = 312 EventFilteringInfo info =
313 ParseFromObject(args[1]->ToObject(isolate), isolate); 313 ParseFromObject(args[1]->ToObject(isolate), isolate);
314 // Only match events routed to this context's RenderView or ones that don't 314 // Only match events routed to this context's RenderView or ones that don't
315 // have a routingId in their filter. 315 // have a routingId in their filter.
316 MatcherIDs matched_event_filters = event_filter.MatchEvent( 316 MatcherIDs matched_event_filters = event_filter.MatchEvent(
317 event_name, info, context()->GetRenderView()->GetRoutingID()); 317 event_name, info, context()->GetRenderView()->GetRoutingID());
318 v8::Handle<v8::Array> array( 318 v8::Local<v8::Array> array(
319 v8::Array::New(isolate, matched_event_filters.size())); 319 v8::Array::New(isolate, matched_event_filters.size()));
320 int i = 0; 320 int i = 0;
321 for (MatcherIDs::iterator it = matched_event_filters.begin(); 321 for (MatcherIDs::iterator it = matched_event_filters.begin();
322 it != matched_event_filters.end(); 322 it != matched_event_filters.end();
323 ++it) { 323 ++it) {
324 array->Set(v8::Integer::New(isolate, i++), v8::Integer::New(isolate, *it)); 324 array->Set(v8::Integer::New(isolate, i++), v8::Integer::New(isolate, *it));
325 } 325 }
326 args.GetReturnValue().Set(array); 326 args.GetReturnValue().Set(array);
327 } 327 }
328 328
329 scoped_ptr<EventMatcher> EventBindings::ParseEventMatcher( 329 scoped_ptr<EventMatcher> EventBindings::ParseEventMatcher(
330 base::DictionaryValue* filter_dict) { 330 base::DictionaryValue* filter_dict) {
331 return scoped_ptr<EventMatcher>(new EventMatcher( 331 return scoped_ptr<EventMatcher>(new EventMatcher(
332 scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy()), 332 scoped_ptr<base::DictionaryValue>(filter_dict->DeepCopy()),
333 context()->GetRenderView()->GetRoutingID())); 333 context()->GetRenderView()->GetRoutingID()));
334 } 334 }
335 335
336 void EventBindings::OnInvalidated() { 336 void EventBindings::OnInvalidated() {
337 // Detach all attached events that weren't attached. Iterate over a copy 337 // Detach all attached events that weren't attached. Iterate over a copy
338 // because it will be mutated. 338 // because it will be mutated.
339 std::set<std::string> attached_event_names_safe = attached_event_names_; 339 std::set<std::string> attached_event_names_safe = attached_event_names_;
340 for (const std::string& event_name : attached_event_names_safe) { 340 for (const std::string& event_name : attached_event_names_safe) {
341 DetachEvent(event_name, false /* is_manual */); 341 DetachEvent(event_name, false /* is_manual */);
342 } 342 }
343 DCHECK(attached_event_names_.empty()) 343 DCHECK(attached_event_names_.empty())
344 << "Events cannot be attached during invalidation"; 344 << "Events cannot be attached during invalidation";
345 } 345 }
346 346
347 } // namespace extensions 347 } // namespace extensions
OLDNEW
« no previous file with comments | « extensions/renderer/dom_activity_logger.cc ('k') | extensions/renderer/extension_frame_helper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698