OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "chrome/common/extensions/extension_messages.h" | 10 #include "chrome/common/extensions/extension_messages.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 0, NULL) { | 78 0, NULL) { |
79 } | 79 } |
80 ~ExtensionImpl() {} | 80 ~ExtensionImpl() {} |
81 | 81 |
82 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( | 82 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( |
83 v8::Handle<v8::String> name) { | 83 v8::Handle<v8::String> name) { |
84 if (name->Equals(v8::String::New("AttachEvent"))) { | 84 if (name->Equals(v8::String::New("AttachEvent"))) { |
85 return v8::FunctionTemplate::New(AttachEvent); | 85 return v8::FunctionTemplate::New(AttachEvent); |
86 } else if (name->Equals(v8::String::New("DetachEvent"))) { | 86 } else if (name->Equals(v8::String::New("DetachEvent"))) { |
87 return v8::FunctionTemplate::New(DetachEvent); | 87 return v8::FunctionTemplate::New(DetachEvent); |
| 88 } else if (name->Equals(v8::String::New("GetExternalFileEntry"))) { |
| 89 return v8::FunctionTemplate::New(GetExternalFileEntry); |
88 } | 90 } |
89 return ExtensionBase::GetNativeFunction(name); | 91 return ExtensionBase::GetNativeFunction(name); |
90 } | 92 } |
91 | 93 |
92 // Attach an event name to an object. | 94 // Attach an event name to an object. |
93 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { | 95 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { |
94 DCHECK(args.Length() == 1); | 96 DCHECK(args.Length() == 1); |
95 // TODO(erikkay) should enforce that event name is a string in the bindings | 97 // TODO(erikkay) should enforce that event name is a string in the bindings |
96 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); | 98 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); |
97 | 99 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 event_name)); | 143 event_name)); |
142 } | 144 } |
143 | 145 |
144 if (--context_info->num_connected_events == 0) { | 146 if (--context_info->num_connected_events == 0) { |
145 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback); | 147 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback); |
146 } | 148 } |
147 } | 149 } |
148 | 150 |
149 return v8::Undefined(); | 151 return v8::Undefined(); |
150 } | 152 } |
| 153 |
| 154 // Attach an event name to an object. |
| 155 static v8::Handle<v8::Value> GetExternalFileEntry( |
| 156 const v8::Arguments& args) { |
| 157 // TODO(zelidrag): Make this magic work on other platforms when file browser |
| 158 // matures enough on ChromeOS. |
| 159 #if defined(OS_CHROMEOS) |
| 160 DCHECK(args.Length() == 1); |
| 161 DCHECK(args[0]->IsObject()); |
| 162 v8::Local<v8::Object> file_def = args[0]->ToObject(); |
| 163 std::string file_system_name( |
| 164 *v8::String::Utf8Value(file_def->Get( |
| 165 v8::String::New("fileSystemName")))); |
| 166 std::string file_system_path( |
| 167 *v8::String::Utf8Value(file_def->Get( |
| 168 v8::String::New("fileSystemRoot")))); |
| 169 std::string file_full_path( |
| 170 *v8::String::Utf8Value(file_def->Get( |
| 171 v8::String::New("fileFullPath")))); |
| 172 bool is_directory = |
| 173 file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value(); |
| 174 WebFrame* webframe = WebFrame::frameForCurrentContext(); |
| 175 return webframe->createFileEntry( |
| 176 WebKit::WebFileSystem::TypeExternal, |
| 177 WebKit::WebString::fromUTF8(file_system_name.c_str()), |
| 178 WebKit::WebString::fromUTF8(file_system_path.c_str()), |
| 179 WebKit::WebString::fromUTF8(file_full_path.c_str()), |
| 180 is_directory); |
| 181 #else |
| 182 return v8::Undefined(); |
| 183 #endif |
| 184 } |
151 }; | 185 }; |
152 | 186 |
153 // Returns true if the extension running in the given |context| has sufficient | 187 // Returns true if the extension running in the given |context| has sufficient |
154 // permissions to access the data. | 188 // permissions to access the data. |
155 static bool HasSufficientPermissions(ContextInfo* context, | 189 static bool HasSufficientPermissions(ContextInfo* context, |
156 const GURL& event_url) { | 190 const GURL& event_url) { |
157 v8::Context::Scope context_scope(context->context); | 191 v8::Context::Scope context_scope(context->context); |
158 | 192 |
159 // During unit tests, we might be invoked without a v8 context. In these | 193 // During unit tests, we might be invoked without a v8 context. In these |
160 // cases, we only allow empty event_urls and short-circuit before retrieving | 194 // cases, we only allow empty event_urls and short-circuit before retrieving |
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 // TODO(rafaelw): Consider only doing this check if function_name == | 411 // TODO(rafaelw): Consider only doing this check if function_name == |
378 // "Event.dispatchJSON". | 412 // "Event.dispatchJSON". |
379 #ifndef NDEBUG | 413 #ifndef NDEBUG |
380 if (!retval.IsEmpty() && !retval->IsUndefined()) { | 414 if (!retval.IsEmpty() && !retval->IsUndefined()) { |
381 std::string error = *v8::String::AsciiValue(retval); | 415 std::string error = *v8::String::AsciiValue(retval); |
382 DCHECK(false) << error; | 416 DCHECK(false) << error; |
383 } | 417 } |
384 #endif | 418 #endif |
385 } | 419 } |
386 } | 420 } |
OLD | NEW |