| 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 "gin/test/file.h" |   5 #include "gin/test/file.h" | 
|   6  |   6  | 
|   7 #include <iostream> |   7 #include <iostream> | 
|   8  |   8  | 
|   9 #include "base/bind.h" |   9 #include "base/bind.h" | 
|  10 #include "base/file_util.h" |  10 #include "base/file_util.h" | 
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  52   const base::FilePath& path = base::FilePath::FromUTF8Unsafe(filename); |  52   const base::FilePath& path = base::FilePath::FromUTF8Unsafe(filename); | 
|  53   if (!base::DirectoryExists(path)) |  53   if (!base::DirectoryExists(path)) | 
|  54     return v8::Null(args->isolate()); |  54     return v8::Null(args->isolate()); | 
|  55  |  55  | 
|  56   std::vector<std::string> names; |  56   std::vector<std::string> names; | 
|  57   base::FileEnumerator e(path, false, base::FileEnumerator::FILES); |  57   base::FileEnumerator e(path, false, base::FileEnumerator::FILES); | 
|  58   for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) { |  58   for (base::FilePath name = e.Next(); !name.empty(); name = e.Next()) { | 
|  59     names.push_back(name.BaseName().AsUTF8Unsafe()); |  59     names.push_back(name.BaseName().AsUTF8Unsafe()); | 
|  60   } |  60   } | 
|  61  |  61  | 
|  62   return gin::Converter<std::vector<std::string>>::ToV8(args->isolate(), names); |  62   return gin::Converter<std::vector<std::string> >::ToV8(args->isolate(), | 
 |  63                                                          names); | 
|  63 } |  64 } | 
|  64  |  65  | 
|  65 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; |  66 gin::WrapperInfo g_wrapper_info = { gin::kEmbedderNativeGin }; | 
|  66  |  67  | 
|  67 }  // namespace |  68 }  // namespace | 
|  68  |  69  | 
|  69 const char File::kModuleName[] = "file"; |  70 const char File::kModuleName[] = "file"; | 
|  70  |  71  | 
|  71 v8::Local<v8::Value> File::GetModule(v8::Isolate* isolate) { |  72 v8::Local<v8::Value> File::GetModule(v8::Isolate* isolate) { | 
|  72   gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); |  73   gin::PerIsolateData* data = gin::PerIsolateData::From(isolate); | 
|  73   v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); |  74   v8::Local<ObjectTemplate> templ = data->GetObjectTemplate(&g_wrapper_info); | 
|  74   if (templ.IsEmpty()) { |  75   if (templ.IsEmpty()) { | 
|  75     templ = gin::ObjectTemplateBuilder(isolate) |  76     templ = gin::ObjectTemplateBuilder(isolate) | 
|  76         .SetMethod("readFileToString", ReadFileToString) |  77         .SetMethod("readFileToString", ReadFileToString) | 
|  77         .SetMethod("getFilesInDirectory", GetFilesInDirectory) |  78         .SetMethod("getFilesInDirectory", GetFilesInDirectory) | 
|  78         .SetMethod("getSourceRootDirectory", GetSourceRootDirectory) |  79         .SetMethod("getSourceRootDirectory", GetSourceRootDirectory) | 
|  79         .Build(); |  80         .Build(); | 
|  80     data->SetObjectTemplate(&g_wrapper_info, templ); |  81     data->SetObjectTemplate(&g_wrapper_info, templ); | 
|  81   } |  82   } | 
|  82   return templ->NewInstance(); |  83   return templ->NewInstance(); | 
|  83 } |  84 } | 
|  84  |  85  | 
|  85 }  // namespace gin |  86 }  // namespace gin | 
| OLD | NEW |