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

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

Issue 1854983002: [Extensions] Add more bindings access checks (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comment Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/file_browser_handler_custom_bindings.h" 5 #include "chrome/renderer/extensions/file_browser_handler_custom_bindings.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "build/build_config.h" 10 #include "build/build_config.h"
11 #include "extensions/renderer/script_context.h" 11 #include "extensions/renderer/script_context.h"
12 #include "extensions/renderer/v8_helpers.h"
13 #include "third_party/WebKit/public/platform/WebString.h" 12 #include "third_party/WebKit/public/platform/WebString.h"
14 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" 13 #include "third_party/WebKit/public/web/WebDOMFileSystem.h"
15 #include "third_party/WebKit/public/web/WebLocalFrame.h" 14 #include "third_party/WebKit/public/web/WebLocalFrame.h"
16 15
17 namespace extensions { 16 namespace extensions {
18 17
19 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings( 18 FileBrowserHandlerCustomBindings::FileBrowserHandlerCustomBindings(
20 ScriptContext* context) 19 ScriptContext* context)
21 : ObjectBackedNativeHandler(context) { 20 : ObjectBackedNativeHandler(context) {
22 RouteFunction( 21 RouteFunction(
23 "GetExternalFileEntry", 22 "GetExternalFileEntry", "fileBrowserHandler",
24 base::Bind(&FileBrowserHandlerCustomBindings::GetExternalFileEntry, 23 base::Bind(
25 base::Unretained(this))); 24 &FileBrowserHandlerCustomBindings::GetExternalFileEntryCallback,
26 RouteFunction("GetEntryURL", 25 base::Unretained(this)));
27 base::Bind(&FileBrowserHandlerCustomBindings::GetEntryURL,
28 base::Unretained(this)));
29 } 26 }
30 27
31 void FileBrowserHandlerCustomBindings::GetExternalFileEntry( 28 void FileBrowserHandlerCustomBindings::GetExternalFileEntry(
32 const v8::FunctionCallbackInfo<v8::Value>& args) { 29 const v8::FunctionCallbackInfo<v8::Value>& args,
33 // TODO(zelidrag): Make this magic work on other platforms when file browser 30 ScriptContext* context) {
34 // matures enough on ChromeOS. 31 // TODO(zelidrag): Make this magic work on other platforms when file browser
32 // matures enough on ChromeOS.
35 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
36 CHECK(args.Length() == 1); 34 CHECK(args.Length() == 1);
37 CHECK(args[0]->IsObject()); 35 CHECK(args[0]->IsObject());
38 v8::Local<v8::Object> file_def = args[0]->ToObject(); 36 v8::Local<v8::Object> file_def = args[0]->ToObject();
39 std::string file_system_name( 37 std::string file_system_name(
40 *v8::String::Utf8Value(file_def->Get( 38 *v8::String::Utf8Value(file_def->Get(
41 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemName")))); 39 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemName"))));
42 GURL file_system_root( 40 GURL file_system_root(
43 *v8::String::Utf8Value(file_def->Get( 41 *v8::String::Utf8Value(file_def->Get(
44 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemRoot")))); 42 v8::String::NewFromUtf8(args.GetIsolate(), "fileSystemRoot"))));
45 std::string file_full_path( 43 std::string file_full_path(
46 *v8::String::Utf8Value(file_def->Get( 44 *v8::String::Utf8Value(file_def->Get(
47 v8::String::NewFromUtf8(args.GetIsolate(), "fileFullPath")))); 45 v8::String::NewFromUtf8(args.GetIsolate(), "fileFullPath"))));
48 bool is_directory = file_def->Get(v8::String::NewFromUtf8( 46 bool is_directory = file_def->Get(v8::String::NewFromUtf8(
49 args.GetIsolate(), "fileIsDirectory"))->ToBoolean()->Value(); 47 args.GetIsolate(), "fileIsDirectory"))->ToBoolean()->Value();
50 blink::WebDOMFileSystem::EntryType entry_type = 48 blink::WebDOMFileSystem::EntryType entry_type =
51 is_directory ? blink::WebDOMFileSystem::EntryTypeDirectory 49 is_directory ? blink::WebDOMFileSystem::EntryTypeDirectory
52 : blink::WebDOMFileSystem::EntryTypeFile; 50 : blink::WebDOMFileSystem::EntryTypeFile;
53 blink::WebLocalFrame* webframe = 51 blink::WebLocalFrame* webframe =
54 blink::WebLocalFrame::frameForContext(context()->v8_context()); 52 blink::WebLocalFrame::frameForContext(context->v8_context());
55 args.GetReturnValue().Set( 53 args.GetReturnValue().Set(
56 blink::WebDOMFileSystem::create( 54 blink::WebDOMFileSystem::create(
57 webframe, 55 webframe,
58 blink::WebFileSystemTypeExternal, 56 blink::WebFileSystemTypeExternal,
59 blink::WebString::fromUTF8(file_system_name), 57 blink::WebString::fromUTF8(file_system_name),
60 file_system_root) 58 file_system_root)
61 .createV8Entry(blink::WebString::fromUTF8(file_full_path), 59 .createV8Entry(blink::WebString::fromUTF8(file_full_path),
62 entry_type, 60 entry_type,
63 args.Holder(), 61 args.Holder(),
64 args.GetIsolate())); 62 args.GetIsolate()));
65 #endif 63 #endif
66 } 64 }
67 65
68 void FileBrowserHandlerCustomBindings::GetEntryURL( 66 void FileBrowserHandlerCustomBindings::GetExternalFileEntryCallback(
69 const v8::FunctionCallbackInfo<v8::Value>& args) { 67 const v8::FunctionCallbackInfo<v8::Value>& args) {
70 CHECK(args.Length() == 1); 68 GetExternalFileEntry(args, context());
71 CHECK(args[0]->IsObject());
72 const blink::WebURL& url =
73 blink::WebDOMFileSystem::createFileSystemURL(args[0]);
74 args.GetReturnValue().Set(v8_helpers::ToV8StringUnsafe(
75 args.GetIsolate(), url.string().utf8().c_str()));
76 } 69 }
77 70
78 } // namespace extensions 71 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698