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

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

Issue 6749021: Added new fileBrowserPrivate and fileHandler extension APIs (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 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 | Annotate | Revision Log
OLDNEW
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 "chrome/common/extensions/extension_messages.h" 9 #include "chrome/common/extensions/extension_messages.h"
10 #include "chrome/common/extensions/extension_set.h" 10 #include "chrome/common/extensions/extension_set.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 0, NULL) { 77 0, NULL) {
78 } 78 }
79 ~ExtensionImpl() {} 79 ~ExtensionImpl() {}
80 80
81 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction( 81 virtual v8::Handle<v8::FunctionTemplate> GetNativeFunction(
82 v8::Handle<v8::String> name) { 82 v8::Handle<v8::String> name) {
83 if (name->Equals(v8::String::New("AttachEvent"))) { 83 if (name->Equals(v8::String::New("AttachEvent"))) {
84 return v8::FunctionTemplate::New(AttachEvent); 84 return v8::FunctionTemplate::New(AttachEvent);
85 } else if (name->Equals(v8::String::New("DetachEvent"))) { 85 } else if (name->Equals(v8::String::New("DetachEvent"))) {
86 return v8::FunctionTemplate::New(DetachEvent); 86 return v8::FunctionTemplate::New(DetachEvent);
87 } else if (name->Equals(v8::String::New("GetLocalFileEntry"))) {
88 return v8::FunctionTemplate::New(GetLocalFileEntry);
87 } 89 }
88 return ExtensionBase::GetNativeFunction(name); 90 return ExtensionBase::GetNativeFunction(name);
89 } 91 }
90 92
91 // Attach an event name to an object. 93 // Attach an event name to an object.
92 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) { 94 static v8::Handle<v8::Value> AttachEvent(const v8::Arguments& args) {
93 DCHECK(args.Length() == 1); 95 DCHECK(args.Length() == 1);
94 // TODO(erikkay) should enforce that event name is a string in the bindings 96 // TODO(erikkay) should enforce that event name is a string in the bindings
95 DCHECK(args[0]->IsString() || args[0]->IsUndefined()); 97 DCHECK(args[0]->IsString() || args[0]->IsUndefined());
96 98
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 event_name)); 142 event_name));
141 } 143 }
142 144
143 if (--context_info->num_connected_events == 0) { 145 if (--context_info->num_connected_events == 0) {
144 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback); 146 context_info->context.MakeWeak(NULL, &ContextWeakReferenceCallback);
145 } 147 }
146 } 148 }
147 149
148 return v8::Undefined(); 150 return v8::Undefined();
149 } 151 }
152
153 // Attach an event name to an object.
154 static v8::Handle<v8::Value> GetLocalFileEntry(
155 const v8::Arguments& args) {
156 // TODO(zelidrag): Make this magic work on other platforms when file browser
157 // matures enough on ChromeOS.
158 #if defined(OS_CHROMEOS)
159 DCHECK(args.Length() == 1);
160 DCHECK(args[0]->IsObject());
161 v8::Local<v8::Object> file_def = args[0]->ToObject();
162 std::string file_system_name(
163 *v8::String::Utf8Value(file_def->Get(
164 v8::String::New("fileSystemName"))));
165 std::string file_system_path(
166 *v8::String::Utf8Value(file_def->Get(
167 v8::String::New("fileSystemRoot"))));
168 std::string file_full_path(
169 *v8::String::Utf8Value(file_def->Get(
170 v8::String::New("fileFullPath"))));
171 bool is_directory =
172 file_def->Get(v8::String::New("fileIsDirectory"))->ToBoolean()->Value();
173 WebFrame* webframe = WebFrame::frameForCurrentContext();
174 return webframe->createFileEntry(
175 fileapi::kFileSystemTypeLocal,
176 WebKit::WebString::fromUTF8(file_system_name.c_str()),
177 WebKit::WebString::fromUTF8(file_system_path.c_str()),
178 WebKit::WebString::fromUTF8(file_full_path.c_str()),
179 is_directory);
180 #else
181 return v8::Undefined();
182 #endif
183 }
150 }; 184 };
151 185
152 // Returns true if the extension running in the given |context| has sufficient 186 // Returns true if the extension running in the given |context| has sufficient
153 // permissions to access the data. 187 // permissions to access the data.
154 static bool HasSufficientPermissions(ContextInfo* context, 188 static bool HasSufficientPermissions(ContextInfo* context,
155 const GURL& event_url) { 189 const GURL& event_url) {
156 v8::Context::Scope context_scope(context->context); 190 v8::Context::Scope context_scope(context->context);
157 191
158 // During unit tests, we might be invoked without a v8 context. In these 192 // During unit tests, we might be invoked without a v8 context. In these
159 // cases, we only allow empty event_urls and short-circuit before retrieving 193 // cases, we only allow empty event_urls and short-circuit before retrieving
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 // TODO(rafaelw): Consider only doing this check if function_name == 407 // TODO(rafaelw): Consider only doing this check if function_name ==
374 // "Event.dispatchJSON". 408 // "Event.dispatchJSON".
375 #ifndef NDEBUG 409 #ifndef NDEBUG
376 if (!retval.IsEmpty() && !retval->IsUndefined()) { 410 if (!retval.IsEmpty() && !retval->IsUndefined()) {
377 std::string error = *v8::String::AsciiValue(retval); 411 std::string error = *v8::String::AsciiValue(retval);
378 DCHECK(false) << error; 412 DCHECK(false) << error;
379 } 413 }
380 #endif 414 #endif
381 } 415 }
382 } 416 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698