Merge branch 'master' into roller/chromium/master
This commit is contained in:
parent
8f4e362d8f
commit
57a8781c01
137 changed files with 876 additions and 4289 deletions
|
@ -14,9 +14,4 @@ mojom("mojo") {
|
|||
# interfaces aready included in blink_common.dll
|
||||
overridden_deps = [ "//third_party/blink/public/mojom:mojom_core" ]
|
||||
component_deps = [ "//third_party/blink/public/common" ]
|
||||
|
||||
enabled_features = []
|
||||
if (enable_remote_module) {
|
||||
enabled_features += [ "enable_remote_module" ]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
|
||||
#include <vector>
|
||||
|
||||
#include "base/numerics/safe_math.h"
|
||||
#include "gin/handle.h"
|
||||
#include "gin/object_template_builder.h"
|
||||
#include "gin/wrappable.h"
|
||||
|
@ -13,9 +12,6 @@
|
|||
#include "shell/common/gin_converters/callback_converter.h"
|
||||
#include "shell/common/gin_converters/file_path_converter.h"
|
||||
#include "shell/common/gin_helper/dictionary.h"
|
||||
#include "shell/common/gin_helper/error_thrower.h"
|
||||
#include "shell/common/gin_helper/function_template_extensions.h"
|
||||
#include "shell/common/gin_helper/promise.h"
|
||||
#include "shell/common/node_includes.h"
|
||||
#include "shell/common/node_util.h"
|
||||
|
||||
|
@ -42,8 +38,7 @@ class Archive : public gin::Wrappable<Archive> {
|
|||
.SetMethod("readdir", &Archive::Readdir)
|
||||
.SetMethod("realpath", &Archive::Realpath)
|
||||
.SetMethod("copyFileOut", &Archive::CopyFileOut)
|
||||
.SetMethod("read", &Archive::Read)
|
||||
.SetMethod("readSync", &Archive::ReadSync);
|
||||
.SetMethod("getFd", &Archive::GetFD);
|
||||
}
|
||||
|
||||
const char* GetTypeName() override { return "Archive"; }
|
||||
|
@ -109,68 +104,15 @@ class Archive : public gin::Wrappable<Archive> {
|
|||
return gin::ConvertToV8(isolate, new_path);
|
||||
}
|
||||
|
||||
v8::Local<v8::ArrayBuffer> ReadSync(gin_helper::ErrorThrower thrower,
|
||||
uint64_t offset,
|
||||
uint64_t length) {
|
||||
base::CheckedNumeric<uint64_t> safe_offset(offset);
|
||||
base::CheckedNumeric<uint64_t> safe_end = safe_offset + length;
|
||||
if (!safe_end.IsValid() ||
|
||||
safe_end.ValueOrDie() > archive_->file()->length()) {
|
||||
thrower.ThrowError("Out of bounds read");
|
||||
return v8::Local<v8::ArrayBuffer>();
|
||||
}
|
||||
auto array_buffer = v8::ArrayBuffer::New(thrower.isolate(), length);
|
||||
auto backing_store = array_buffer->GetBackingStore();
|
||||
memcpy(backing_store->Data(), archive_->file()->data() + offset, length);
|
||||
return array_buffer;
|
||||
}
|
||||
|
||||
v8::Local<v8::Promise> Read(v8::Isolate* isolate,
|
||||
uint64_t offset,
|
||||
uint64_t length) {
|
||||
gin_helper::Promise<v8::Local<v8::ArrayBuffer>> promise(isolate);
|
||||
v8::Local<v8::Promise> handle = promise.GetHandle();
|
||||
|
||||
base::CheckedNumeric<uint64_t> safe_offset(offset);
|
||||
base::CheckedNumeric<uint64_t> safe_end = safe_offset + length;
|
||||
if (!safe_end.IsValid() ||
|
||||
safe_end.ValueOrDie() > archive_->file()->length()) {
|
||||
promise.RejectWithErrorMessage("Out of bounds read");
|
||||
return handle;
|
||||
}
|
||||
|
||||
auto backing_store = v8::ArrayBuffer::NewBackingStore(isolate, length);
|
||||
base::ThreadPool::PostTaskAndReplyWithResult(
|
||||
FROM_HERE, {base::MayBlock(), base::TaskPriority::USER_VISIBLE},
|
||||
base::BindOnce(&Archive::ReadOnIO, isolate, archive_,
|
||||
std::move(backing_store), offset, length),
|
||||
base::BindOnce(&Archive::ResolveReadOnUI, std::move(promise)));
|
||||
|
||||
return handle;
|
||||
// Return the file descriptor.
|
||||
int GetFD() const {
|
||||
if (!archive_)
|
||||
return -1;
|
||||
return archive_->GetFD();
|
||||
}
|
||||
|
||||
private:
|
||||
static std::unique_ptr<v8::BackingStore> ReadOnIO(
|
||||
v8::Isolate* isolate,
|
||||
std::shared_ptr<asar::Archive> archive,
|
||||
std::unique_ptr<v8::BackingStore> backing_store,
|
||||
uint64_t offset,
|
||||
uint64_t length) {
|
||||
memcpy(backing_store->Data(), archive->file()->data() + offset, length);
|
||||
return backing_store;
|
||||
}
|
||||
|
||||
static void ResolveReadOnUI(
|
||||
gin_helper::Promise<v8::Local<v8::ArrayBuffer>> promise,
|
||||
std::unique_ptr<v8::BackingStore> backing_store) {
|
||||
v8::HandleScope scope(promise.isolate());
|
||||
v8::Context::Scope context_scope(promise.GetContext());
|
||||
auto array_buffer =
|
||||
v8::ArrayBuffer::New(promise.isolate(), std::move(backing_store));
|
||||
promise.Resolve(array_buffer);
|
||||
}
|
||||
|
||||
std::shared_ptr<asar::Archive> archive_;
|
||||
std::unique_ptr<asar::Archive> archive_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(Archive);
|
||||
};
|
||||
|
|
|
@ -138,6 +138,10 @@ void TriggerFatalErrorForTesting(v8::Isolate* isolate) {
|
|||
v8::ExtensionConfiguration config(1, bDeps);
|
||||
v8::Context::New(isolate, &config);
|
||||
}
|
||||
|
||||
void RunUntilIdle() {
|
||||
base::RunLoop().RunUntilIdle();
|
||||
}
|
||||
#endif
|
||||
|
||||
void Initialize(v8::Local<v8::Object> exports,
|
||||
|
@ -158,6 +162,7 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
dict.SetMethod("getWeaklyTrackedValues", &GetWeaklyTrackedValues);
|
||||
dict.SetMethod("clearWeaklyTrackedValues", &ClearWeaklyTrackedValues);
|
||||
dict.SetMethod("weaklyTrackValue", &WeaklyTrackValue);
|
||||
dict.SetMethod("runUntilIdle", &RunUntilIdle);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -22,10 +22,6 @@ bool IsOffscreenRenderingEnabled() {
|
|||
return BUILDFLAG(ENABLE_OSR);
|
||||
}
|
||||
|
||||
bool IsRemoteModuleEnabled() {
|
||||
return BUILDFLAG(ENABLE_REMOTE_MODULE);
|
||||
}
|
||||
|
||||
bool IsPDFViewerEnabled() {
|
||||
return BUILDFLAG(ENABLE_PDF_VIEWER);
|
||||
}
|
||||
|
@ -78,7 +74,6 @@ void Initialize(v8::Local<v8::Object> exports,
|
|||
dict.SetMethod("isBuiltinSpellCheckerEnabled", &IsBuiltinSpellCheckerEnabled);
|
||||
dict.SetMethod("isDesktopCapturerEnabled", &IsDesktopCapturerEnabled);
|
||||
dict.SetMethod("isOffscreenRenderingEnabled", &IsOffscreenRenderingEnabled);
|
||||
dict.SetMethod("isRemoteModuleEnabled", &IsRemoteModuleEnabled);
|
||||
dict.SetMethod("isPDFViewerEnabled", &IsPDFViewerEnabled);
|
||||
dict.SetMethod("isRunAsNodeEnabled", &IsRunAsNodeEnabled);
|
||||
dict.SetMethod("isFakeLocationProviderEnabled",
|
||||
|
|
|
@ -117,51 +117,78 @@ bool FillFileInfoWithNode(Archive::FileInfo* info,
|
|||
|
||||
} // namespace
|
||||
|
||||
Archive::Archive(const base::FilePath& path) : path_(path) {
|
||||
Archive::Archive(const base::FilePath& path)
|
||||
: path_(path), file_(base::File::FILE_OK) {
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
if (base::PathExists(path_) && !file_.Initialize(path_)) {
|
||||
LOG(ERROR) << "Failed to open ASAR archive at '" << path_.value() << "'";
|
||||
}
|
||||
file_.Initialize(path_, base::File::FLAG_OPEN | base::File::FLAG_READ);
|
||||
#if defined(OS_WIN)
|
||||
fd_ = _open_osfhandle(reinterpret_cast<intptr_t>(file_.GetPlatformFile()), 0);
|
||||
#elif defined(OS_POSIX)
|
||||
fd_ = file_.GetPlatformFile();
|
||||
#endif
|
||||
}
|
||||
|
||||
Archive::~Archive() {}
|
||||
Archive::~Archive() {
|
||||
#if defined(OS_WIN)
|
||||
if (fd_ != -1) {
|
||||
_close(fd_);
|
||||
// Don't close the handle since we already closed the fd.
|
||||
file_.TakePlatformFile();
|
||||
}
|
||||
#endif
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
file_.Close();
|
||||
}
|
||||
|
||||
bool Archive::Init() {
|
||||
if (!file_.IsValid()) {
|
||||
if (file_.error_details() != base::File::FILE_ERROR_NOT_FOUND) {
|
||||
LOG(WARNING) << "Opening " << path_.value() << ": "
|
||||
<< base::File::ErrorToString(file_.error_details());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_.length() < 8) {
|
||||
LOG(ERROR) << "Malformed ASAR file at '" << path_.value()
|
||||
<< "' (too short)";
|
||||
std::vector<char> buf;
|
||||
int len;
|
||||
|
||||
buf.resize(8);
|
||||
{
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
len = file_.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
}
|
||||
if (len != static_cast<int>(buf.size())) {
|
||||
PLOG(ERROR) << "Failed to read header size from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
||||
uint32_t size;
|
||||
base::PickleIterator size_pickle(
|
||||
base::Pickle(reinterpret_cast<const char*>(file_.data()), 8));
|
||||
if (!size_pickle.ReadUInt32(&size)) {
|
||||
LOG(ERROR) << "Failed to read header size at '" << path_.value() << "'";
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size()))
|
||||
.ReadUInt32(&size)) {
|
||||
LOG(ERROR) << "Failed to parse header size from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (file_.length() - 8 < size) {
|
||||
LOG(ERROR) << "Malformed ASAR file at '" << path_.value()
|
||||
<< "' (incorrect header)";
|
||||
buf.resize(size);
|
||||
{
|
||||
base::ThreadRestrictions::ScopedAllowIO allow_io;
|
||||
len = file_.ReadAtCurrentPos(buf.data(), buf.size());
|
||||
}
|
||||
if (len != static_cast<int>(buf.size())) {
|
||||
PLOG(ERROR) << "Failed to read header from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
||||
base::PickleIterator header_pickle(
|
||||
base::Pickle(reinterpret_cast<const char*>(file_.data() + 8), size));
|
||||
std::string header;
|
||||
if (!header_pickle.ReadString(&header)) {
|
||||
LOG(ERROR) << "Failed to read header string at '" << path_.value() << "'";
|
||||
if (!base::PickleIterator(base::Pickle(buf.data(), buf.size()))
|
||||
.ReadString(&header)) {
|
||||
LOG(ERROR) << "Failed to parse header from " << path_.value();
|
||||
return false;
|
||||
}
|
||||
|
||||
base::Optional<base::Value> value = base::JSONReader::Read(header);
|
||||
if (!value || !value->is_dict()) {
|
||||
LOG(ERROR) << "Header was not valid JSON at '" << path_.value() << "'";
|
||||
LOG(ERROR) << "Failed to parse header";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -264,24 +291,11 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
|
|||
return true;
|
||||
}
|
||||
|
||||
base::CheckedNumeric<uint64_t> safe_offset(info.offset);
|
||||
auto safe_end = safe_offset + info.size;
|
||||
if (!safe_end.IsValid() || safe_end.ValueOrDie() > file_.length())
|
||||
return false;
|
||||
|
||||
auto temp_file = std::make_unique<ScopedTemporaryFile>();
|
||||
base::FilePath::StringType ext = path.Extension();
|
||||
if (!temp_file->Init(ext))
|
||||
if (!temp_file->InitFromFile(&file_, ext, info.offset, info.size))
|
||||
return false;
|
||||
|
||||
base::File dest(temp_file->path(),
|
||||
base::File::FLAG_OPEN | base::File::FLAG_WRITE);
|
||||
if (!dest.IsValid())
|
||||
return false;
|
||||
|
||||
dest.WriteAtCurrentPos(
|
||||
reinterpret_cast<const char*>(file_.data() + info.offset), info.size);
|
||||
|
||||
#if defined(OS_POSIX)
|
||||
if (info.executable) {
|
||||
// chmod a+x temp_file;
|
||||
|
@ -294,4 +308,8 @@ bool Archive::CopyFileOut(const base::FilePath& path, base::FilePath* out) {
|
|||
return true;
|
||||
}
|
||||
|
||||
int Archive::GetFD() const {
|
||||
return fd_;
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
#include "base/files/file.h"
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/files/memory_mapped_file.h"
|
||||
|
||||
namespace base {
|
||||
class DictionaryValue;
|
||||
|
@ -62,13 +61,16 @@ class Archive {
|
|||
// For unpacked file, this method will return its real path.
|
||||
bool CopyFileOut(const base::FilePath& path, base::FilePath* out);
|
||||
|
||||
base::MemoryMappedFile* file() { return &file_; }
|
||||
// Returns the file's fd.
|
||||
int GetFD() const;
|
||||
|
||||
base::FilePath path() const { return path_; }
|
||||
base::DictionaryValue* header() const { return header_.get(); }
|
||||
|
||||
private:
|
||||
base::FilePath path_;
|
||||
base::MemoryMappedFile file_;
|
||||
base::File file_;
|
||||
int fd_ = -1;
|
||||
uint32_t header_size_ = 0;
|
||||
std::unique_ptr<base::DictionaryValue> header_;
|
||||
|
||||
|
|
|
@ -48,4 +48,27 @@ bool ScopedTemporaryFile::Init(const base::FilePath::StringType& ext) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool ScopedTemporaryFile::InitFromFile(base::File* src,
|
||||
const base::FilePath::StringType& ext,
|
||||
uint64_t offset,
|
||||
uint64_t size) {
|
||||
if (!src->IsValid())
|
||||
return false;
|
||||
|
||||
if (!Init(ext))
|
||||
return false;
|
||||
|
||||
std::vector<char> buf(size);
|
||||
int len = src->Read(offset, buf.data(), buf.size());
|
||||
if (len != static_cast<int>(size))
|
||||
return false;
|
||||
|
||||
base::File dest(path_, base::File::FLAG_OPEN | base::File::FLAG_WRITE);
|
||||
if (!dest.IsValid())
|
||||
return false;
|
||||
|
||||
return dest.WriteAtCurrentPos(buf.data(), buf.size()) ==
|
||||
static_cast<int>(size);
|
||||
}
|
||||
|
||||
} // namespace asar
|
||||
|
|
|
@ -27,6 +27,12 @@ class ScopedTemporaryFile {
|
|||
// Init an empty temporary file with a certain extension.
|
||||
bool Init(const base::FilePath::StringType& ext);
|
||||
|
||||
// Init an temporary file and fill it with content of |path|.
|
||||
bool InitFromFile(base::File* src,
|
||||
const base::FilePath::StringType& ext,
|
||||
uint64_t offset,
|
||||
uint64_t size);
|
||||
|
||||
base::FilePath path() const { return path_; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -51,4 +51,14 @@ std::string ToRGBHex(SkColor color) {
|
|||
SkColorGetG(color), SkColorGetB(color));
|
||||
}
|
||||
|
||||
std::string ToRGBAHex(SkColor color, bool include_hash) {
|
||||
std::string color_str = base::StringPrintf(
|
||||
"%02X%02X%02X%02X", SkColorGetR(color), SkColorGetG(color),
|
||||
SkColorGetB(color), SkColorGetA(color));
|
||||
if (include_hash) {
|
||||
return "#" + color_str;
|
||||
}
|
||||
return color_str;
|
||||
}
|
||||
|
||||
} // namespace electron
|
||||
|
|
|
@ -17,6 +17,8 @@ SkColor ParseHexColor(const std::string& color_string);
|
|||
// Convert color to RGB hex value like "#ABCDEF"
|
||||
std::string ToRGBHex(SkColor color);
|
||||
|
||||
std::string ToRGBAHex(SkColor color, bool include_hash = true);
|
||||
|
||||
} // namespace electron
|
||||
|
||||
#endif // SHELL_COMMON_COLOR_UTIL_H_
|
||||
|
|
|
@ -193,10 +193,6 @@ const char kHiddenPage[] = "hiddenPage";
|
|||
const char kSpellcheck[] = "spellcheck";
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
|
||||
const char kEnableRemoteModule[] = "enableRemoteModule";
|
||||
#endif
|
||||
|
||||
const char kEnableWebSQL[] = "enableWebSQL";
|
||||
|
||||
const char kEnablePreferredSizeMode[] = "enablePreferredSizeMode";
|
||||
|
|
|
@ -99,10 +99,6 @@ extern const char kHiddenPage[];
|
|||
extern const char kSpellcheck[];
|
||||
#endif
|
||||
|
||||
#if BUILDFLAG(ENABLE_REMOTE_MODULE)
|
||||
extern const char kEnableRemoteModule[];
|
||||
#endif
|
||||
|
||||
} // namespace options
|
||||
|
||||
// Following are actually command line switches, should be moved to other files.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue