OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "chrome/renderer/extensions/event_bindings.h" | 5 #include "chrome/renderer/extensions/event_bindings.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/singleton.h" | 8 #include "base/singleton.h" |
9 #include "chrome/common/render_messages.h" | 9 #include "chrome/common/render_messages.h" |
10 #include "chrome/common/url_constants.h" | 10 #include "chrome/common/url_constants.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 } | 69 } |
70 | 70 |
71 // Attach an event name to an object. | 71 // Attach an event name to an object. |
72 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { | 72 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { |
73 DCHECK(args.Length() == 1); | 73 DCHECK(args.Length() == 1); |
74 // TODO(erikkay) should enforce that event name is a string in the bindings | 74 // TODO(erikkay) should enforce that event name is a string in the bindings |
75 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 75 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
76 | 76 |
77 if (args[0]->IsString()) { | 77 if (args[0]->IsString()) { |
78 std::string event_name(*v8::String::AsciiValue(args[0])); | 78 std::string event_name(*v8::String::AsciiValue(args[0])); |
79 if (EventIncrementListenerCount(event_name) == 1) { | 79 bool has_permission = |
| 80 ExtensionProcessBindings::CurrentContextHasPermission(event_name); |
| 81 |
| 82 // Increment the count even if the caller doesn't have permission, so that |
| 83 // refcounts stay balanced. |
| 84 if (EventIncrementListenerCount(event_name) == 1 && has_permission) { |
80 EventBindings::GetRenderThread()->Send( | 85 EventBindings::GetRenderThread()->Send( |
81 new ViewHostMsg_ExtensionAddListener(event_name)); | 86 new ViewHostMsg_ExtensionAddListener(event_name)); |
82 } | 87 } |
| 88 |
| 89 if (!has_permission) { |
| 90 return ExtensionProcessBindings::ThrowPermissionDeniedException( |
| 91 event_name); |
| 92 } |
83 } | 93 } |
84 | 94 |
85 return v8::Undefined(); | 95 return v8::Undefined(); |
86 } | 96 } |
87 | 97 |
88 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { | 98 static v8::Handle<v8::Value> DetachEvent(const v8::Arguments& args) { |
89 DCHECK(args.Length() == 1); | 99 DCHECK(args.Length() == 1); |
90 // TODO(erikkay) should enforce that event name is a string in the bindings | 100 // TODO(erikkay) should enforce that event name is a string in the bindings |
91 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 101 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
92 | 102 |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 void EventBindings::CallFunction(const std::string& function_name, | 277 void EventBindings::CallFunction(const std::string& function_name, |
268 int argc, v8::Handle<v8::Value>* argv, | 278 int argc, v8::Handle<v8::Value>* argv, |
269 RenderView* render_view) { | 279 RenderView* render_view) { |
270 for (ContextList::iterator it = GetContexts().begin(); | 280 for (ContextList::iterator it = GetContexts().begin(); |
271 it != GetContexts().end(); ++it) { | 281 it != GetContexts().end(); ++it) { |
272 if (render_view && render_view != (*it)->render_view) | 282 if (render_view && render_view != (*it)->render_view) |
273 continue; | 283 continue; |
274 CallFunctionInContext((*it)->context, function_name, argc, argv); | 284 CallFunctionInContext((*it)->context, function_name, argc, argv); |
275 } | 285 } |
276 } | 286 } |
OLD | NEW |