 Chromium Code Reviews
 Chromium Code Reviews Issue 1658913002:
  Make extensions use a correct same-origin check.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1658913002:
  Make extensions use a correct same-origin check.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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/file_system_natives.h" | 5 #include "extensions/renderer/file_system_natives.h" | 
| 6 | 6 | 
| 7 #include <string> | 7 #include <string> | 
| 8 | 8 | 
| 9 #include "extensions/common/constants.h" | 9 #include "extensions/common/constants.h" | 
| 10 #include "extensions/renderer/script_context.h" | 10 #include "extensions/renderer/script_context.h" | 
| 11 #include "storage/common/fileapi/file_system_types.h" | 11 #include "storage/common/fileapi/file_system_types.h" | 
| 12 #include "storage/common/fileapi/file_system_util.h" | 12 #include "storage/common/fileapi/file_system_util.h" | 
| 13 #include "third_party/WebKit/public/platform/WebString.h" | 13 #include "third_party/WebKit/public/platform/WebString.h" | 
| 14 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 14 #include "third_party/WebKit/public/web/WebDOMFileSystem.h" | 
| 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 15 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 
| 16 #include "url/origin.h" | |
| 16 | 17 | 
| 17 namespace extensions { | 18 namespace extensions { | 
| 18 | 19 | 
| 19 FileSystemNatives::FileSystemNatives(ScriptContext* context) | 20 FileSystemNatives::FileSystemNatives(ScriptContext* context) | 
| 20 : ObjectBackedNativeHandler(context) { | 21 : ObjectBackedNativeHandler(context) { | 
| 21 RouteFunction( | 22 RouteFunction( | 
| 22 "GetFileEntry", | 23 "GetFileEntry", | 
| 23 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this))); | 24 base::Bind(&FileSystemNatives::GetFileEntry, base::Unretained(this))); | 
| 24 RouteFunction("GetIsolatedFileSystem", | 25 RouteFunction("GetIsolatedFileSystem", | 
| 25 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, | 26 base::Bind(&FileSystemNatives::GetIsolatedFileSystem, | 
| 26 base::Unretained(this))); | 27 base::Unretained(this))); | 
| 27 RouteFunction("CrackIsolatedFileSystemName", | 28 RouteFunction("CrackIsolatedFileSystemName", | 
| 28 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, | 29 base::Bind(&FileSystemNatives::CrackIsolatedFileSystemName, | 
| 29 base::Unretained(this))); | 30 base::Unretained(this))); | 
| 30 } | 31 } | 
| 31 | 32 | 
| 32 void FileSystemNatives::GetIsolatedFileSystem( | 33 void FileSystemNatives::GetIsolatedFileSystem( | 
| 33 const v8::FunctionCallbackInfo<v8::Value>& args) { | 34 const v8::FunctionCallbackInfo<v8::Value>& args) { | 
| 34 CHECK(args.Length() == 1 || args.Length() == 2); | 35 CHECK(args.Length() == 1 || args.Length() == 2); | 
| 35 CHECK(args[0]->IsString()); | 36 CHECK(args[0]->IsString()); | 
| 36 std::string file_system_id(*v8::String::Utf8Value(args[0])); | 37 std::string file_system_id(*v8::String::Utf8Value(args[0])); | 
| 37 blink::WebLocalFrame* webframe = | 38 blink::WebLocalFrame* webframe = | 
| 38 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 39 blink::WebLocalFrame::frameForContext(context()->v8_context()); | 
| 39 DCHECK(webframe); | 40 DCHECK(webframe); | 
| 40 | 41 | 
| 41 GURL context_url = | 42 GURL context_url = | 
| 42 extensions::ScriptContext::GetDataSourceURLForFrame(webframe); | 43 extensions::ScriptContext::GetDataSourceURLForFrame(webframe); | 
| 43 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); | 44 CHECK(context_url.SchemeIs(extensions::kExtensionScheme)); | 
| 44 | 45 | 
| 45 std::string name(storage::GetIsolatedFileSystemName(context_url.GetOrigin(), | 46 const GURL origin = GURL(url::Origin(context_url).Serialize()); | 
| 
brettw
2016/02/03 19:12:38
This would be better as:
  const GURL origin(url::
 
palmer
2016/02/03 20:47:58
Done.
 | |
| 46 file_system_id)); | 47 std::string name(storage::GetIsolatedFileSystemName(origin, file_system_id)); | 
| 47 | 48 | 
| 48 // The optional second argument is the subfolder within the isolated file | 49 // The optional second argument is the subfolder within the isolated file | 
| 49 // system at which to root the DOMFileSystem we're returning to the caller. | 50 // system at which to root the DOMFileSystem we're returning to the caller. | 
| 50 std::string optional_root_name; | 51 std::string optional_root_name; | 
| 51 if (args.Length() == 2) { | 52 if (args.Length() == 2) { | 
| 52 CHECK(args[1]->IsString()); | 53 CHECK(args[1]->IsString()); | 
| 53 optional_root_name = *v8::String::Utf8Value(args[1]); | 54 optional_root_name = *v8::String::Utf8Value(args[1]); | 
| 54 } | 55 } | 
| 55 | 56 | 
| 56 GURL root_url(storage::GetIsolatedFileSystemRootURIString( | 57 GURL root_url(storage::GetIsolatedFileSystemRootURIString( | 
| 57 context_url.GetOrigin(), file_system_id, optional_root_name)); | 58 origin, file_system_id, optional_root_name)); | 
| 58 | 59 | 
| 59 args.GetReturnValue().Set( | 60 args.GetReturnValue().Set( | 
| 60 blink::WebDOMFileSystem::create(webframe, | 61 blink::WebDOMFileSystem::create(webframe, | 
| 61 blink::WebFileSystemTypeIsolated, | 62 blink::WebFileSystemTypeIsolated, | 
| 62 blink::WebString::fromUTF8(name), | 63 blink::WebString::fromUTF8(name), | 
| 63 root_url) | 64 root_url) | 
| 64 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); | 65 .toV8Value(context()->v8_context()->Global(), args.GetIsolate())); | 
| 65 } | 66 } | 
| 66 | 67 | 
| 67 void FileSystemNatives::GetFileEntry( | 68 void FileSystemNatives::GetFileEntry( | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) | 115 if (!storage::CrackIsolatedFileSystemName(filesystem_name, &filesystem_id)) | 
| 115 return; | 116 return; | 
| 116 | 117 | 
| 117 args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), | 118 args.GetReturnValue().Set(v8::String::NewFromUtf8(args.GetIsolate(), | 
| 118 filesystem_id.c_str(), | 119 filesystem_id.c_str(), | 
| 119 v8::String::kNormalString, | 120 v8::String::kNormalString, | 
| 120 filesystem_id.size())); | 121 filesystem_id.size())); | 
| 121 } | 122 } | 
| 122 | 123 | 
| 123 } // namespace extensions | 124 } // namespace extensions | 
| OLD | NEW |