diff --git a/BUILD.gn b/BUILD.gn index 96cc73b93c42..6d9f14b79b4c 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -355,7 +355,6 @@ source_set("electron_lib") { "buildflags", "chromium_src:chrome", "chromium_src:chrome_spellchecker", - "native_mate", "shell/common/api:mojo", "//base:base_static", "//base/allocator:buildflags", diff --git a/docs/development/source-code-directory-structure.md b/docs/development/source-code-directory-structure.md index 5a0369c4a32e..5c28b5775a6a 100644 --- a/docs/development/source-code-directory-structure.md +++ b/docs/development/source-code-directory-structure.md @@ -42,8 +42,6 @@ Electron | | └── api/ - Javascript API implementation. | └── renderer/ - Javascript renderer process initialization code. | └── api/ - Javascript API implementation. -├── native_mate/ - A fork of Chromium's gin library that makes it easier to marshal -| types between C++ and JavaScript. ├── spec/ - Automatic tests. └── BUILD.gn - Building rules of Electron. ``` diff --git a/filenames.gni b/filenames.gni index 7490e615304f..336b3ad35ed1 100644 --- a/filenames.gni +++ b/filenames.gni @@ -433,10 +433,8 @@ filenames = { "shell/common/api/atom_api_native_image_mac.mm", "shell/common/api/atom_api_shell.cc", "shell/common/api/atom_api_v8_util.cc", - "shell/common/api/constructor.h", "shell/common/api/electron_bindings.cc", "shell/common/api/electron_bindings.h", - "shell/common/api/constructor.h", "shell/common/api/features.cc", "shell/common/application_info.cc", "shell/common/application_info.h", @@ -496,6 +494,7 @@ filenames = { "shell/common/gin_helper/arguments.h", "shell/common/gin_helper/callback.cc", "shell/common/gin_helper/callback.h", + "shell/common/gin_helper/constructor.h", "shell/common/gin_helper/destroyable.cc", "shell/common/gin_helper/destroyable.h", "shell/common/gin_helper/dictionary.h", @@ -517,6 +516,9 @@ filenames = { "shell/common/gin_helper/promise.cc", "shell/common/gin_helper/trackable_object.cc", "shell/common/gin_helper/trackable_object.h", + "shell/common/gin_helper/wrappable.cc", + "shell/common/gin_helper/wrappable.h", + "shell/common/gin_helper/wrappable_base.h", "shell/common/heap_snapshot.cc", "shell/common/heap_snapshot.h", "shell/common/keyboard_util.cc", diff --git a/native_mate/BUILD.gn b/native_mate/BUILD.gn deleted file mode 100644 index f6bc5ac54072..000000000000 --- a/native_mate/BUILD.gn +++ /dev/null @@ -1,32 +0,0 @@ -config("native_mate_config") { - include_dirs = [ "." ] -} - -source_set("native_mate") { - deps = [ - "//base", - "//net", - "//third_party/electron_node:node_lib", - "//v8:v8_headers", - ] - public_configs = [ ":native_mate_config" ] - include_dirs = [ ".." ] - sources = [ - "native_mate/arguments.cc", - "native_mate/arguments.h", - "native_mate/compat.h", - "native_mate/constructor.h", - "native_mate/converter.cc", - "native_mate/converter.h", - "native_mate/dictionary.cc", - "native_mate/dictionary.h", - "native_mate/function_template.cc", - "native_mate/function_template.h", - "native_mate/handle.h", - "native_mate/object_template_builder.cc", - "native_mate/object_template_builder_deprecated.h", - "native_mate/wrappable.cc", - "native_mate/wrappable.h", - "native_mate/wrappable_base.h", - ] -} diff --git a/native_mate/LICENSE.chromium b/native_mate/LICENSE.chromium deleted file mode 100644 index 972bb2edb099..000000000000 --- a/native_mate/LICENSE.chromium +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2014 The Chromium Authors. All rights reserved. -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions are -// met: -// -// * Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// * Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following disclaimer -// in the documentation and/or other materials provided with the -// distribution. -// * Neither the name of Google Inc. nor the names of its -// contributors may be used to endorse or promote products derived from -// this software without specific prior written permission. -// -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/native_mate/README.md b/native_mate/README.md deleted file mode 100644 index 24f2dc169203..000000000000 --- a/native_mate/README.md +++ /dev/null @@ -1,56 +0,0 @@ -> A fork of Chromium's [gin library][chromium-gin-lib] that makes it easier to -> marshal types between C++ and JavaScript. - -# Overview - -`native-mate` was forked from `gin` so that it could be used in -[Electron][electron] without conflicting with Node's Environment. It has also -been extended to allow Electron to create classes in JavaScript. - -With the help of Chromium's `base` library, `native-mate` makes writing JS -bindings very easy, and most of the intricate details of converting V8 types -to C++ types and back are taken care of auto-magically. In most cases there's -no need to use the raw V8 API to implement an API binding. - -For example, here's an API binding that doesn't use `native-mate`: - -```c++ -// static -void Shell::OpenItem(const v8::FunctionCallbackInfo& args) { - base::FilePath file_path; - if (!FromV8Arguments(args, &file_path)) - return node::ThrowTypeError("Bad argument"); - - platform_util::OpenItem(file_path); -} - -// static -void Shell::Initialize(v8::Handle target) { - NODE_SET_METHOD(target, "openItem", OpenItem); -} -``` - -And here's the same API binding using `native-mate`: - -```c++ -void Initialize(v8::Handle exports) { - mate::Dictionary dict(v8::Isolate::GetCurrent(), exports); - dict.SetMethod("openItem", &platform_util::OpenItem); -} -``` - -# Code Structure - -* `converter.h` - Templatized JS<->C++ conversion routines for many common C++ - types. You can define your own by specializing `Converter`. -* `function_template.h` - Create JavaScript functions that dispatch to any C++ - function, member function pointer, or `base::Callback`. -* `object_template_builder_deprecated.h` - A handy utility for creation of `v8::ObjectTemplate`. -* `wrappable.h` - Base class for C++ classes that want to be owned by the V8 GC. - Wrappable objects are automatically deleted when GC discovers that nothing in - the V8 heap refers to them. This is also an easy way to expose C++ objects to - JavaScript. - - -[chromium-gin-lib]: https://code.google.com/p/chromium/codesearch#chromium/src/gin/README.md&sq=package:chromium -[electron]: https://electronjs.org/ diff --git a/native_mate/native_mate/arguments.cc b/native_mate/native_mate/arguments.cc deleted file mode 100644 index 5d84509dcb79..000000000000 --- a/native_mate/native_mate/arguments.cc +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#include "native_mate/arguments.h" - -#include "base/strings/stringprintf.h" -#include "native_mate/converter.h" - -namespace mate { - -namespace { - -std::string V8TypeAsString(v8::Isolate* isolate, v8::Local value) { - if (value.IsEmpty()) - return ""; - v8::MaybeLocal details = - value->ToDetailString(isolate->GetCurrentContext()); - std::string result; - if (!details.IsEmpty()) - ConvertFromV8(isolate, details.ToLocalChecked(), &result); - return result; -} - -} // namespace - -Arguments::Arguments() = default; - -Arguments::Arguments(const v8::FunctionCallbackInfo& info) - : isolate_(info.GetIsolate()), info_(&info) {} - -Arguments::~Arguments() = default; - -v8::Local Arguments::PeekNext() const { - if (next_ >= info_->Length()) - return v8::Local(); - return (*info_)[next_]; -} - -v8::Local Arguments::ThrowError() const { - if (insufficient_arguments_) - return ThrowTypeError("Insufficient number of arguments."); - - return ThrowTypeError(base::StringPrintf( - "Error processing argument at index %d, conversion failure from %s", - next_, V8TypeAsString(isolate_, (*info_)[next_]).c_str())); -} - -v8::Local Arguments::ThrowError(const std::string& message) const { - isolate_->ThrowException(v8::Exception::Error(StringToV8(isolate_, message))); - return v8::Undefined(isolate_); -} - -v8::Local Arguments::ThrowTypeError( - const std::string& message) const { - isolate_->ThrowException( - v8::Exception::TypeError(StringToV8(isolate_, message))); - return v8::Undefined(isolate_); -} - -} // namespace mate diff --git a/native_mate/native_mate/arguments.h b/native_mate/native_mate/arguments.h deleted file mode 100644 index 45287dca9236..000000000000 --- a/native_mate/native_mate/arguments.h +++ /dev/null @@ -1,111 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_ -#define NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_ - -#include -#include - -#include "base/macros.h" -#include "base/optional.h" -#include "native_mate/converter.h" - -// =============================== NOTICE =============================== -// Do not add code here, native_mate is being removed. Any new code -// should use gin instead. - -namespace mate { - -// Arguments is a wrapper around v8::FunctionCallbackInfo that integrates -// with Converter to make it easier to marshall arguments and return values -// between V8 and C++. -class Arguments { - public: - Arguments(); - explicit Arguments(const v8::FunctionCallbackInfo& info); - ~Arguments(); - - v8::Local GetHolder() const { return info_->Holder(); } - - template - bool GetHolder(T* out) { - return mate::ConvertFromV8(isolate_, info_->Holder(), out); - } - - template - bool GetData(T* out) { - return ConvertFromV8(isolate_, info_->Data(), out); - } - - template - bool GetNext(base::Optional* out) { - if (next_ >= info_->Length()) - return true; - v8::Local val = (*info_)[next_]; - bool success = ConvertFromV8(isolate_, val, out); - if (success) - next_++; - return success; - } - - template - bool GetNext(T* out) { - if (next_ >= info_->Length()) { - insufficient_arguments_ = true; - return false; - } - v8::Local val = (*info_)[next_]; - bool success = mate::ConvertFromV8(isolate_, val, out); - if (success) - next_++; - return success; - } - - template - bool GetRemaining(std::vector* out) { - if (next_ >= info_->Length()) { - insufficient_arguments_ = true; - return false; - } - int remaining = info_->Length() - next_; - out->resize(remaining); - for (int i = 0; i < remaining; ++i) { - v8::Local val = (*info_)[next_++]; - if (!ConvertFromV8(isolate_, val, &out->at(i))) - return false; - } - return true; - } - - v8::Local GetThis() { return info_->This(); } - - bool IsConstructCall() const { return info_->IsConstructCall(); } - - int Length() const { return info_->Length(); } - - template - void Return(const T& val) { - info_->GetReturnValue().Set(ConvertToV8(isolate_, val)); - } - - v8::Local PeekNext() const; - - v8::Local ThrowError() const; - v8::Local ThrowError(const std::string& message) const; - v8::Local ThrowTypeError(const std::string& message) const; - - v8::Isolate* isolate() const { return isolate_; } - const v8::FunctionCallbackInfo& info() const { return *info_; } - - private: - v8::Isolate* isolate_ = nullptr; - const v8::FunctionCallbackInfo* info_ = nullptr; - int next_ = 0; - bool insufficient_arguments_ = false; -}; - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_ARGUMENTS_H_ diff --git a/native_mate/native_mate/converter.cc b/native_mate/native_mate/converter.cc deleted file mode 100644 index 2ed93285eca5..000000000000 --- a/native_mate/native_mate/converter.cc +++ /dev/null @@ -1,269 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#include "native_mate/converter.h" - -#include "v8/include/v8.h" - -namespace mate { - -namespace { - -template -bool FromMaybe(v8::Maybe maybe, U* out) { - if (maybe.IsNothing()) - return false; - *out = static_cast(maybe.FromJust()); - return true; -} - -} // namespace - -v8::Local Converter::ToV8(v8::Isolate* isolate, bool val) { - return v8::Boolean::New(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - bool* out) { - if (!val->IsBoolean()) - return false; - *out = val.As()->Value(); - return true; -} - -#if !defined(OS_LINUX) && !defined(OS_FREEBSD) -v8::Local Converter::ToV8( // NOLINT(runtime/int) - v8::Isolate* isolate, - unsigned long val) { // NOLINT(runtime/int) - return v8::Integer::New(isolate, val); -} - -bool Converter::FromV8( // NOLINT(runtime/int) - v8::Isolate* isolate, - v8::Local val, - unsigned long* out) { // NOLINT(runtime/int) - if (!val->IsNumber()) - return false; - return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out); -} -#endif - -v8::Local Converter::ToV8(v8::Isolate* isolate, - int32_t val) { - return v8::Integer::New(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - int32_t* out) { - if (!val->IsInt32()) - return false; - *out = val.As()->Value(); - return true; -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - uint32_t val) { - return v8::Integer::NewFromUnsigned(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - uint32_t* out) { - if (!val->IsUint32()) - return false; - *out = val.As()->Value(); - return true; -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - int64_t val) { - return v8::Number::New(isolate, static_cast(val)); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - int64_t* out) { - if (!val->IsNumber()) - return false; - // Even though IntegerValue returns int64_t, JavaScript cannot represent - // the full precision of int64_t, which means some rounding might occur. - return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out); -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - uint64_t val) { - return v8::Number::New(isolate, static_cast(val)); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - uint64_t* out) { - if (!val->IsNumber()) - return false; - return FromMaybe(val->IntegerValue(isolate->GetCurrentContext()), out); -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, float val) { - return v8::Number::New(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - float* out) { - if (!val->IsNumber()) - return false; - *out = static_cast(val.As()->Value()); - return true; -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, double val) { - return v8::Number::New(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - double* out) { - if (!val->IsNumber()) - return false; - *out = val.As()->Value(); - return true; -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - const char* val) { - return v8::String::NewFromUtf8(isolate, val, v8::NewStringType::kNormal) - .ToLocalChecked(); -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - base::StringPiece val) { - return v8::String::NewFromUtf8(isolate, val.data(), - v8::NewStringType::kNormal, - static_cast(val.length())) - .ToLocalChecked(); -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - const std::string& val) { - return Converter::ToV8(isolate, val); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - std::string* out) { - if (!val->IsString()) - return false; - v8::Local str = v8::Local::Cast(val); - int length = str->Utf8Length(isolate); - out->resize(length); - str->WriteUtf8(isolate, &(*out)[0], length, nullptr, - v8::String::NO_NULL_TERMINATION); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - if (!val->IsFunction()) - return false; - *out = v8::Local::Cast(val); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - if (!val->IsObject()) - return false; - *out = v8::Local::Cast(val); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - if (!val->IsString()) - return false; - *out = v8::Local::Cast(val); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - if (!val->IsExternal()) - return false; - *out = v8::Local::Cast(val); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - if (!val->IsArray()) - return false; - *out = v8::Local::Cast(val); - return true; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -v8::Local Converter>::ToV8( - v8::Isolate* isolate, - v8::Local val) { - return val; -} - -bool Converter>::FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out) { - *out = val; - return true; -} - -v8::Local StringToSymbol(v8::Isolate* isolate, - base::StringPiece val) { - return v8::String::NewFromUtf8(isolate, val.data(), - v8::NewStringType::kInternalized, - static_cast(val.length())) - .ToLocalChecked(); -} - -} // namespace mate diff --git a/native_mate/native_mate/converter.h b/native_mate/native_mate/converter.h deleted file mode 100644 index f8a736f59c82..000000000000 --- a/native_mate/native_mate/converter.h +++ /dev/null @@ -1,351 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_CONVERTER_H_ -#define NATIVE_MATE_NATIVE_MATE_CONVERTER_H_ - -#include -#include -#include -#include -#include -#include - -#include "base/strings/string_piece.h" -#include "gin/converter.h" -#include "v8/include/v8.h" - -namespace mate { - -template -bool SetProperty(v8::Isolate* isolate, - v8::Local object, - KeyType key, - v8::Local value) { - auto maybe = object->Set(isolate->GetCurrentContext(), key, value); - return !maybe.IsNothing() && maybe.FromJust(); -} - -template -struct ToV8ReturnsMaybe { - static const bool value = false; -}; - -template -struct Converter {}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, void* val) { - return v8::Undefined(isolate); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, std::nullptr_t val) { - return v8::Null(isolate); - } -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, bool val); - static bool FromV8(v8::Isolate* isolate, v8::Local val, bool* out); -}; - -#if !defined(OS_LINUX) && !defined(OS_FREEBSD) -template <> -struct Converter { // NOLINT(runtime/int) - static v8::Local ToV8(v8::Isolate* isolate, - unsigned long val); // NOLINT(runtime/int) - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - unsigned long* out); // NOLINT(runtime/int) -}; -#endif - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, int32_t val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - int32_t* out); -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, uint32_t val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - uint32_t* out); -}; - -template <> -struct Converter { - // Warning: JavaScript cannot represent 64 integers precisely. - static v8::Local ToV8(v8::Isolate* isolate, int64_t val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - int64_t* out); -}; - -template <> -struct Converter { - // Warning: JavaScript cannot represent 64 integers precisely. - static v8::Local ToV8(v8::Isolate* isolate, uint64_t val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - uint64_t* out); -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, float val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - float* out); -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, double val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - double* out); -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, const char* val); -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, base::StringPiece val); - // No conversion out is possible because StringPiece does not contain storage. -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const std::string& val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - std::string* out); -}; - -v8::Local StringToSymbol(v8::Isolate* isolate, - base::StringPiece input); - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - v8::Local* out); -}; - -template <> -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - v8::Local val); - // static bool FromV8(v8::Isolate* isolate, - // v8::Local val, - // v8::Local* out); -}; - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const std::vector& val) { - v8::Local result( - v8::Array::New(isolate, static_cast(val.size()))); - auto context = isolate->GetCurrentContext(); - for (size_t i = 0; i < val.size(); ++i) { - result - ->Set(context, static_cast(i), - Converter::ToV8(isolate, val[i])) - .Check(); - } - return result; - } - - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - std::vector* out) { - if (!val->IsArray()) - return false; - - auto context = isolate->GetCurrentContext(); - std::vector result; - v8::Local array(v8::Local::Cast(val)); - uint32_t length = array->Length(); - for (uint32_t i = 0; i < length; ++i) { - T item; - if (!Converter::FromV8(isolate, - array->Get(context, i).ToLocalChecked(), &item)) - return false; - result.push_back(item); - } - - out->swap(result); - return true; - } -}; - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const std::set& val) { - v8::Local result( - v8::Array::New(isolate, static_cast(val.size()))); - auto context = isolate->GetCurrentContext(); - typename std::set::const_iterator it; - int i; - for (i = 0, it = val.begin(); it != val.end(); ++it, ++i) - result->Set(context, i, Converter::ToV8(isolate, *it)).Check(); - return result; - } - - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - std::set* out) { - if (!val->IsArray()) - return false; - - auto context = isolate->GetCurrentContext(); - std::set result; - v8::Local array(v8::Local::Cast(val)); - uint32_t length = array->Length(); - for (uint32_t i = 0; i < length; ++i) { - T item; - if (!Converter::FromV8(isolate, - array->Get(context, i).ToLocalChecked(), &item)) - return false; - result.insert(item); - } - - out->swap(result); - return true; - } -}; - -// Convenience functions that deduce T. -template -v8::Local ConvertToV8(v8::Isolate* isolate, const T& input) { - return Converter::ToV8(isolate, input); -} - -template -v8::Local ConvertToV8(v8::Isolate* isolate, T&& input) { - return Converter::type>::ToV8( - isolate, std::move(input)); -} - -inline v8::Local ConvertToV8(v8::Isolate* isolate, - const char* input) { - return Converter::ToV8(isolate, input); -} - -template -v8::MaybeLocal ConvertToV8(v8::Local context, - const T& input) { - return Converter::ToV8(context, input); -} - -template ::value> -struct ToV8Traits; - -template -struct ToV8Traits { - static bool TryConvertToV8(v8::Isolate* isolate, - const T& input, - v8::Local* output) { - auto maybe = ConvertToV8(isolate->GetCurrentContext(), input); - if (maybe.IsEmpty()) - return false; - *output = maybe.ToLocalChecked(); - return true; - } -}; - -template -struct ToV8Traits { - static bool TryConvertToV8(v8::Isolate* isolate, - const T& input, - v8::Local* output) { - *output = ConvertToV8(isolate, input); - return true; - } -}; - -template -bool TryConvertToV8(v8::Isolate* isolate, - const T& input, - v8::Local* output) { - return ToV8Traits::TryConvertToV8(isolate, input, output); -} - -template -bool ConvertFromV8(v8::Isolate* isolate, - v8::Local input, - T* result) { - return Converter::FromV8(isolate, input, result); -} - -inline v8::Local StringToV8(v8::Isolate* isolate, - base::StringPiece input) { - return ConvertToV8(isolate, input).As(); -} - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_CONVERTER_H_ diff --git a/native_mate/native_mate/dictionary.cc b/native_mate/native_mate/dictionary.cc deleted file mode 100644 index 9d33c5508b2c..000000000000 --- a/native_mate/native_mate/dictionary.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#include "native_mate/dictionary.h" - -namespace mate { - -Dictionary::Dictionary() = default; - -Dictionary::Dictionary(v8::Isolate* isolate, v8::Local object) - : isolate_(isolate), object_(object) {} - -Dictionary::Dictionary(const Dictionary& other) = default; - -Dictionary::~Dictionary() = default; - -Dictionary Dictionary::CreateEmpty(v8::Isolate* isolate) { - return Dictionary(isolate, v8::Object::New(isolate)); -} - -v8::Local Dictionary::GetHandle() const { - return object_; -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - Dictionary val) { - return val.GetHandle(); -} - -bool Converter::FromV8(v8::Isolate* isolate, - v8::Local val, - Dictionary* out) { - if (!val->IsObject() || val->IsFunction()) - return false; - *out = Dictionary(isolate, v8::Local::Cast(val)); - return true; -} - -} // namespace mate diff --git a/native_mate/native_mate/dictionary.h b/native_mate/native_mate/dictionary.h deleted file mode 100644 index 412acd25a958..000000000000 --- a/native_mate/native_mate/dictionary.h +++ /dev/null @@ -1,136 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_ -#define NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_ - -#include "native_mate/converter.h" -#include "native_mate/object_template_builder_deprecated.h" - -namespace mate { - -namespace internal { - -// Returns true if |maybe| is both a value, and that value is true. -inline bool IsTrue(v8::Maybe maybe) { - return maybe.IsJust() && maybe.FromJust(); -} - -} // namespace internal - -// Dictionary is useful when writing bindings for a function that either -// receives an arbitrary JavaScript object as an argument or returns an -// arbitrary JavaScript object as a result. For example, Dictionary is useful -// when you might use the |dictionary| type in WebIDL: -// -// http://heycam.github.io/webidl/#idl-dictionaries -// -// WARNING: You cannot retain a Dictionary object in the heap. The underlying -// storage for Dictionary is tied to the closest enclosing -// v8::HandleScope. Generally speaking, you should store a Dictionary -// on the stack. -// -class Dictionary { - public: - Dictionary(); - Dictionary(v8::Isolate* isolate, v8::Local object); - Dictionary(const Dictionary& other); - virtual ~Dictionary(); - - static Dictionary CreateEmpty(v8::Isolate* isolate); - - template - bool Get(base::StringPiece key, T* out) const { - // Check for existence before getting, otherwise this method will always - // returns true when T == v8::Local. - v8::Local context = isolate_->GetCurrentContext(); - v8::Local v8_key = StringToV8(isolate_, key); - if (!internal::IsTrue(GetHandle()->Has(context, v8_key))) - return false; - - v8::Local val; - if (!GetHandle()->Get(context, v8_key).ToLocal(&val)) - return false; - return ConvertFromV8(isolate_, val, out); - } - - template - bool Set(base::StringPiece key, const T& val) { - v8::Local v8_value; - if (!TryConvertToV8(isolate_, val, &v8_value)) - return false; - v8::Maybe result = GetHandle()->Set( - isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value); - return !result.IsNothing() && result.FromJust(); - } - - template - bool SetReadOnly(base::StringPiece key, T val) { - v8::Local v8_value; - if (!TryConvertToV8(isolate_, val, &v8_value)) - return false; - v8::Maybe result = GetHandle()->DefineOwnProperty( - isolate_->GetCurrentContext(), StringToV8(isolate_, key), v8_value, - v8::ReadOnly); - return !result.IsNothing() && result.FromJust(); - } - - template - bool SetMethod(base::StringPiece key, const T& callback) { - return GetHandle() - ->Set(isolate_->GetCurrentContext(), StringToV8(isolate_, key), - CallbackTraits::CreateTemplate(isolate_, callback) - ->GetFunction(isolate_->GetCurrentContext()) - .ToLocalChecked()) - .ToChecked(); - } - - bool Delete(base::StringPiece key) { - v8::Maybe result = GetHandle()->Delete(isolate_->GetCurrentContext(), - StringToV8(isolate_, key)); - return !result.IsNothing() && result.FromJust(); - } - - bool IsEmpty() const { return isolate() == NULL; } - - virtual v8::Local GetHandle() const; - - v8::Isolate* isolate() const { return isolate_; } - - protected: - v8::Isolate* isolate_ = nullptr; - - private: - v8::Local object_; -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, Dictionary val); - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - Dictionary* out); -}; - -} // namespace mate - -namespace gin { - -// Keep compatibility with gin. -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, - const mate::Dictionary& in) { - return mate::ConvertToV8(isolate, in); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - mate::Dictionary* out) { - return mate::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace gin - -#endif // NATIVE_MATE_NATIVE_MATE_DICTIONARY_H_ diff --git a/native_mate/native_mate/function_template.cc b/native_mate/native_mate/function_template.cc deleted file mode 100644 index a4bcb1141b74..000000000000 --- a/native_mate/native_mate/function_template.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#include "native_mate/function_template.h" - -namespace mate { - -namespace internal { - -CallbackHolderBase::CallbackHolderBase(v8::Isolate* isolate) - : v8_ref_(isolate, v8::External::New(isolate, this)) { - v8_ref_.SetWeak(this, &CallbackHolderBase::FirstWeakCallback, - v8::WeakCallbackType::kParameter); -} - -CallbackHolderBase::~CallbackHolderBase() { - DCHECK(v8_ref_.IsEmpty()); -} - -v8::Local CallbackHolderBase::GetHandle(v8::Isolate* isolate) { - return v8::Local::New(isolate, v8_ref_); -} - -// static -void CallbackHolderBase::FirstWeakCallback( - const v8::WeakCallbackInfo& data) { - data.GetParameter()->v8_ref_.Reset(); - data.SetSecondPassCallback(SecondWeakCallback); -} - -// static -void CallbackHolderBase::SecondWeakCallback( - const v8::WeakCallbackInfo& data) { - delete data.GetParameter(); -} - -} // namespace internal - -} // namespace mate diff --git a/native_mate/native_mate/function_template.h b/native_mate/native_mate/function_template.h deleted file mode 100644 index babba9506308..000000000000 --- a/native_mate/native_mate/function_template.h +++ /dev/null @@ -1,285 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_ -#define NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_ - -#include "base/callback.h" -#include "native_mate/arguments.h" -#include "native_mate/wrappable_base.h" -#include "shell/common/gin_helper/destroyable.h" -#include "shell/common/gin_helper/error_thrower.h" - -// =============================== NOTICE =============================== -// Do not add code here, native_mate is being removed. Any new code -// should use gin instead. - -namespace mate { - -enum CreateFunctionTemplateFlags { - HolderIsFirstArgument = 1 << 0, -}; - -namespace internal { - -template -struct CallbackParamTraits { - typedef T LocalType; -}; -template -struct CallbackParamTraits { - typedef T LocalType; -}; -template -struct CallbackParamTraits { - typedef T* LocalType; -}; - -// CallbackHolder and CallbackHolderBase are used to pass a base::Callback from -// CreateFunctionTemplate through v8 (via v8::FunctionTemplate) to -// DispatchToCallback, where it is invoked. - -// This simple base class is used so that we can share a single object template -// among every CallbackHolder instance. -class CallbackHolderBase { - public: - v8::Local GetHandle(v8::Isolate* isolate); - - protected: - explicit CallbackHolderBase(v8::Isolate* isolate); - virtual ~CallbackHolderBase(); - - private: - static void FirstWeakCallback( - const v8::WeakCallbackInfo& data); - static void SecondWeakCallback( - const v8::WeakCallbackInfo& data); - - v8::Global v8_ref_; - - DISALLOW_COPY_AND_ASSIGN(CallbackHolderBase); -}; - -template -class CallbackHolder : public CallbackHolderBase { - public: - CallbackHolder(v8::Isolate* isolate, - const base::Callback& callback, - int flags) - : CallbackHolderBase(isolate), callback(callback), flags(flags) {} - base::Callback callback; - int flags = 0; - - private: - virtual ~CallbackHolder() = default; - - DISALLOW_COPY_AND_ASSIGN(CallbackHolder); -}; - -template -bool GetNextArgument(Arguments* args, - int create_flags, - bool is_first, - T* result) { - if (is_first && (create_flags & HolderIsFirstArgument) != 0) { - return args->GetHolder(result); - } else { - return args->GetNext(result); - } -} - -// For advanced use cases, we allow callers to request the unparsed Arguments -// object and poke around in it directly. -inline bool GetNextArgument(Arguments* args, - int create_flags, - bool is_first, - Arguments* result) { - *result = *args; - return true; -} -inline bool GetNextArgument(Arguments* args, - int create_flags, - bool is_first, - Arguments** result) { - *result = args; - return true; -} - -// It's common for clients to just need the isolate, so we make that easy. -inline bool GetNextArgument(Arguments* args, - int create_flags, - bool is_first, - v8::Isolate** result) { - *result = args->isolate(); - return true; -} - -// Allow clients to pass a util::Error to throw errors if they -// don't need the full mate::Arguments -inline bool GetNextArgument(Arguments* args, - int create_flags, - bool is_first, - gin_helper::ErrorThrower* result) { - *result = gin_helper::ErrorThrower(args->isolate()); - return true; -} - -// Classes for generating and storing an argument pack of integer indices -// (based on well-known "indices trick", see: http://goo.gl/bKKojn): -template -struct IndicesHolder {}; - -template -struct IndicesGenerator { - using type = typename IndicesGenerator::type; -}; -template -struct IndicesGenerator<0, indices...> { - using type = IndicesHolder; -}; - -// Class template for extracting and storing single argument for callback -// at position |index|. -template -struct ArgumentHolder { - using ArgLocalType = typename CallbackParamTraits::LocalType; - - ArgLocalType value; - bool ok = false; - - ArgumentHolder(Arguments* args, int create_flags) { - if (index == 0 && (create_flags & HolderIsFirstArgument) && - gin_helper::Destroyable::IsDestroyed(args->GetHolder())) { - args->ThrowError("Object has been destroyed"); - return; - } - ok = GetNextArgument(args, create_flags, index == 0, &value); - if (!ok) { - // Ideally we would include the expected c++ type in the error - // message which we can access via typeid(ArgType).name() - // however we compile with no-rtti, which disables typeid. - args->ThrowError(); - } - } -}; - -// Class template for converting arguments from JavaScript to C++ and running -// the callback with them. -template -class Invoker {}; - -template -class Invoker, ArgTypes...> - : public ArgumentHolder... { - public: - // Invoker<> inherits from ArgumentHolder<> for each argument. - // C++ has always been strict about the class initialization order, - // so it is guaranteed ArgumentHolders will be initialized (and thus, will - // extract arguments from Arguments) in the right order. - Invoker(Arguments* args, int create_flags) - : ArgumentHolder(args, create_flags)..., args_(args) { - // GCC thinks that create_flags is going unused, even though the - // expansion above clearly makes use of it. Per jyasskin@, casting - // to void is the commonly accepted way to convince the compiler - // that you're actually using a parameter/varible. - (void)create_flags; - } - - bool IsOK() { return And(ArgumentHolder::ok...); } - - template - void DispatchToCallback(base::Callback callback) { - v8::MicrotasksScope script_scope(args_->isolate(), - v8::MicrotasksScope::kRunMicrotasks); - args_->Return(callback.Run(ArgumentHolder::value...)); - } - - // In C++, you can declare the function foo(void), but you can't pass a void - // expression to foo. As a result, we must specialize the case of Callbacks - // that have the void return type. - void DispatchToCallback(base::Callback callback) { - v8::MicrotasksScope script_scope(args_->isolate(), - v8::MicrotasksScope::kRunMicrotasks); - callback.Run(ArgumentHolder::value...); - } - - private: - static bool And() { return true; } - template - static bool And(bool arg1, T... args) { - return arg1 && And(args...); - } - - Arguments* args_; -}; - -// DispatchToCallback converts all the JavaScript arguments to C++ types and -// invokes the base::Callback. -template -struct Dispatcher {}; - -template -struct Dispatcher { - static void DispatchToCallback( - const v8::FunctionCallbackInfo& info) { - Arguments args(info); - v8::Local v8_holder; - args.GetData(&v8_holder); - CallbackHolderBase* holder_base = - reinterpret_cast(v8_holder->Value()); - - typedef CallbackHolder HolderT; - HolderT* holder = static_cast(holder_base); - - using Indices = typename IndicesGenerator::type; - Invoker invoker(&args, holder->flags); - if (invoker.IsOK()) - invoker.DispatchToCallback(holder->callback); - } -}; - -} // namespace internal - -// CreateFunctionTemplate creates a v8::FunctionTemplate that will create -// JavaScript functions that execute a provided C++ function or base::Callback. -// JavaScript arguments are automatically converted via gin::Converter, as is -// the return value of the C++ function, if any. -// -// NOTE: V8 caches FunctionTemplates for a lifetime of a web page for its own -// internal reasons, thus it is generally a good idea to cache the template -// returned by this function. Otherwise, repeated method invocations from JS -// will create substantial memory leaks. See http://crbug.com/463487. -template -v8::Local CreateFunctionTemplate( - v8::Isolate* isolate, - const base::Callback callback, - int callback_flags = 0) { - typedef internal::CallbackHolder HolderT; - HolderT* holder = new HolderT(isolate, callback, callback_flags); - - return v8::FunctionTemplate::New( - isolate, &internal::Dispatcher::DispatchToCallback, - ConvertToV8>(isolate, - holder->GetHandle(isolate))); -} - -// CreateFunctionHandler installs a CallAsFunction handler on the given -// object template that forwards to a provided C++ function or base::Callback. -template -void CreateFunctionHandler(v8::Isolate* isolate, - v8::Local tmpl, - const base::Callback callback, - int callback_flags = 0) { - typedef internal::CallbackHolder HolderT; - HolderT* holder = new HolderT(isolate, callback, callback_flags); - tmpl->SetCallAsFunctionHandler(&internal::Dispatcher::DispatchToCallback, - ConvertToV8>( - isolate, holder->GetHandle(isolate))); -} - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_FUNCTION_TEMPLATE_H_ diff --git a/native_mate/native_mate/handle.h b/native_mate/native_mate/handle.h deleted file mode 100644 index 12e411434a7e..000000000000 --- a/native_mate/native_mate/handle.h +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_HANDLE_H_ -#define NATIVE_MATE_NATIVE_MATE_HANDLE_H_ - -#include "native_mate/converter.h" - -namespace mate { - -// You can use mate::Handle on the stack to retain a mate::Wrappable object. -// Currently we don't have a mechanism for retaining a mate::Wrappable object -// in the C++ heap because strong references from C++ to V8 can cause memory -// leaks. -template -class Handle { - public: - Handle() = default; - - Handle(v8::Local wrapper, T* object) - : wrapper_(wrapper), object_(object) {} - - bool IsEmpty() const { return !object_; } - - void Clear() { - wrapper_.Clear(); - object_ = NULL; - } - - T* operator->() const { return object_; } - v8::Local ToV8() const { return wrapper_; } - T* get() const { return object_; } - - private: - v8::Local wrapper_; - T* object_ = nullptr; -}; - -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const mate::Handle& val) { - return val.ToV8(); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - mate::Handle* out) { - T* object = NULL; - if (val->IsNull() || val->IsUndefined()) { - *out = mate::Handle(); - return true; - } - if (!Converter::FromV8(isolate, val, &object)) { - return false; - } - v8::Local context = isolate->GetCurrentContext(); - *out = mate::Handle(val->ToObject(context).ToLocalChecked(), object); - return true; - } -}; - -// This function is a convenient way to create a handle from a raw pointer -// without having to write out the type of the object explicitly. -template -mate::Handle CreateHandle(v8::Isolate* isolate, T* object) { - return mate::Handle(object->GetWrapper(), object); -} - -} // namespace mate - -namespace gin { - -// Keep compatibility with gin. -template -struct Converter> { - static v8::Local ToV8(v8::Isolate* isolate, - const mate::Handle& in) { - return mate::ConvertToV8(isolate, in); - } - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - mate::Handle* out) { - return mate::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace gin - -#endif // NATIVE_MATE_NATIVE_MATE_HANDLE_H_ diff --git a/native_mate/native_mate/object_template_builder.cc b/native_mate/native_mate/object_template_builder.cc deleted file mode 100644 index 4adb90e6fa84..000000000000 --- a/native_mate/native_mate/object_template_builder.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#include "native_mate/object_template_builder_deprecated.h" - -namespace mate { - -ObjectTemplateBuilder::ObjectTemplateBuilder( - v8::Isolate* isolate, - v8::Local templ) - : isolate_(isolate), template_(templ) {} - -ObjectTemplateBuilder::~ObjectTemplateBuilder() = default; - -ObjectTemplateBuilder& ObjectTemplateBuilder::SetImpl(base::StringPiece name, - v8::Local val) { - template_->Set(StringToSymbol(isolate_, name), val); - return *this; -} - -ObjectTemplateBuilder& ObjectTemplateBuilder::SetPropertyImpl( - base::StringPiece name, - v8::Local getter, - v8::Local setter) { - template_->SetAccessorProperty(StringToSymbol(isolate_, name), getter, - setter); - return *this; -} - -v8::Local ObjectTemplateBuilder::Build() { - v8::Local result = template_; - template_.Clear(); - return result; -} - -} // namespace mate diff --git a/native_mate/native_mate/object_template_builder_deprecated.h b/native_mate/native_mate/object_template_builder_deprecated.h deleted file mode 100644 index efe4985e9129..000000000000 --- a/native_mate/native_mate/object_template_builder_deprecated.h +++ /dev/null @@ -1,120 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE.chromium file. - -#ifndef NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_ -#define NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_ - -#include "base/bind.h" -#include "base/callback.h" -#include "base/strings/string_piece.h" -#include "native_mate/converter.h" -#include "native_mate/function_template.h" -#include "v8/include/v8.h" - -namespace mate { - -// Base template - used only for non-member function pointers. Other types -// either go to one of the below specializations, or go here and fail to compile -// because of base::Bind(). -template -struct CallbackTraits { - static v8::Local CreateTemplate(v8::Isolate* isolate, - T callback) { - return mate::CreateFunctionTemplate(isolate, base::Bind(callback)); - } -}; - -// Specialization for base::Callback. -template -struct CallbackTraits> { - static v8::Local CreateTemplate( - v8::Isolate* isolate, - const base::Callback& callback) { - return mate::CreateFunctionTemplate(isolate, callback); - } -}; - -// Specialization for member function pointers. We need to handle this case -// specially because the first parameter for callbacks to MFP should typically -// come from the the JavaScript "this" object the function was called on, not -// from the first normal parameter. -template -struct CallbackTraits< - T, - typename std::enable_if::value>::type> { - static v8::Local CreateTemplate(v8::Isolate* isolate, - T callback) { - int flags = HolderIsFirstArgument; - return mate::CreateFunctionTemplate(isolate, base::Bind(callback), flags); - } -}; - -// This specialization allows people to construct function templates directly if -// they need to do fancier stuff. -template <> -struct CallbackTraits> { - static v8::Local CreateTemplate( - v8::Local templ) { - return templ; - } -}; - -// ObjectTemplateBuilder provides a handy interface to creating -// v8::ObjectTemplate instances with various sorts of properties. -class ObjectTemplateBuilder { - public: - explicit ObjectTemplateBuilder(v8::Isolate* isolate, - v8::Local templ); - ~ObjectTemplateBuilder(); - - // It's against Google C++ style to return a non-const ref, but we take some - // poetic license here in order that all calls to Set() can be via the '.' - // operator and line up nicely. - template - ObjectTemplateBuilder& SetValue(base::StringPiece name, T val) { - return SetImpl(name, ConvertToV8(isolate_, val)); - } - - // In the following methods, T and U can be function pointer, member function - // pointer, base::Callback, or v8::FunctionTemplate. Most clients will want to - // use one of the first two options. Also see mate::CreateFunctionTemplate() - // for creating raw function templates. - template - ObjectTemplateBuilder& SetMethod(base::StringPiece name, T callback) { - return SetImpl(name, CallbackTraits::CreateTemplate(isolate_, callback)); - } - template - ObjectTemplateBuilder& SetProperty(base::StringPiece name, T getter) { - return SetPropertyImpl(name, - CallbackTraits::CreateTemplate(isolate_, getter), - v8::Local()); - } - template - ObjectTemplateBuilder& SetProperty(base::StringPiece name, - T getter, - U setter) { - return SetPropertyImpl(name, - CallbackTraits::CreateTemplate(isolate_, getter), - CallbackTraits::CreateTemplate(isolate_, setter)); - } - - v8::Local Build(); - - private: - ObjectTemplateBuilder& SetImpl(base::StringPiece name, - v8::Local val); - ObjectTemplateBuilder& SetPropertyImpl( - base::StringPiece name, - v8::Local getter, - v8::Local setter); - - v8::Isolate* isolate_; - - // ObjectTemplateBuilder should only be used on the stack. - v8::Local template_; -}; - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_OBJECT_TEMPLATE_BUILDER_DEPRECATED_H_ diff --git a/native_mate/native_mate/promise.cc b/native_mate/native_mate/promise.cc deleted file mode 100644 index 375541ac6547..000000000000 --- a/native_mate/native_mate/promise.cc +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2018 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#include "native_mate/promise.h" - -namespace mate { - -Promise::Promise() = default; - -Promise::Promise(v8::Isolate* isolate) : isolate_(isolate) { - resolver_ = v8::Promise::Resolver::New(isolate); -} - -Promise::~Promise() = default; - -Promise Promise::Create(v8::Isolate* isolate) { - return Promise(isolate); -} - -Promise Promise::Create() { - return Promise::Create(v8::Isolate::GetCurrent()); -} - -void Promise::RejectWithErrorMessage(const std::string& string) { - v8::Local error_message = - v8::String::NewFromUtf8(isolate(), string.c_str(), - v8::NewStringType::kNormal, - static_cast(string.size())) - .ToLocalChecked(); - v8::Local error = v8::Exception::Error(error_message); - resolver_->Reject(mate::ConvertToV8(isolate(), error)); -} - -v8::Local Promise::GetHandle() const { - return resolver_->GetPromise(); -} - -v8::Local Converter::ToV8(v8::Isolate* isolate, - Promise val) { - return val.GetHandle(); -} - -} // namespace mate diff --git a/native_mate/native_mate/promise.h b/native_mate/native_mate/promise.h deleted file mode 100644 index d3e929d3a7d3..000000000000 --- a/native_mate/native_mate/promise.h +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) 2018 GitHub, Inc. -// Use of this source code is governed by the MIT license that can be -// found in the LICENSE file. - -#ifndef NATIVE_MATE_NATIVE_MATE_PROMISE_H_ -#define NATIVE_MATE_NATIVE_MATE_PROMISE_H_ - -#include - -#include "native_mate/converter.h" - -namespace mate { - -class Promise { - public: - Promise(); - explicit Promise(v8::Isolate* isolate); - virtual ~Promise(); - - static Promise Create(v8::Isolate* isolate); - static Promise Create(); - - v8::Isolate* isolate() const { return isolate_; } - - virtual v8::Local GetHandle() const; - - template - void Resolve(T* value) { - resolver_->Resolve(mate::ConvertToV8(isolate(), value)); - } - - template - void Reject(T* value) { - resolver_->Reject(mate::ConvertToV8(isolate(), value)); - } - - void RejectWithErrorMessage(const std::string& error); - - protected: - v8::Isolate* isolate_ = nullptr; - - private: - v8::Local resolver_; -}; - -template <> -struct Converter { - static v8::Local ToV8(v8::Isolate* isolate, Promise val); - // TODO(MarshallOfSound): Implement FromV8 to allow promise chaining - // in native land - // static bool FromV8(v8::Isolate* isolate, - // v8::Local val, - // Promise* out); -}; - -} // namespace mate - -#endif // NATIVE_MATE_NATIVE_MATE_PROMISE_H_ diff --git a/patches/chromium/.patches b/patches/chromium/.patches index c74d29038355..3353e68d718a 100644 --- a/patches/chromium/.patches +++ b/patches/chromium/.patches @@ -15,7 +15,6 @@ web_contents.patch webview_cross_drag.patch disable_user_gesture_requirement_for_beforeunload_dialogs.patch gin_enable_disable_v8_platform.patch -gin_with_namespace.patch blink-worker-enable-csp-in-file-scheme.patch disable-redraw-lock.patch v8_context_snapshot_generator.patch diff --git a/patches/chromium/gin_with_namespace.patch b/patches/chromium/gin_with_namespace.patch deleted file mode 100644 index 4e54d0414a2a..000000000000 --- a/patches/chromium/gin_with_namespace.patch +++ /dev/null @@ -1,83 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Cheng Zhao -Date: Thu, 20 Sep 2018 17:47:44 -0700 -Subject: gin_with_namespace.patch - -When using gin with native_mate together we may have C++ confused with -finding the correct ConvertFromV8. We add gin:: namespace explicitly in -those calls to work around the ambiguous compilation error. - -Note that this is only a work around to make it easier to remove -native_mate, and we should remove this patch once native_mate is erased -from Electron. - -diff --git a/gin/arguments.h b/gin/arguments.h -index eaded13e29919793494dfe2f7f85fad7dcb125cf..03e1495566d1ab561dcd67517053173911288cea 100644 ---- a/gin/arguments.h -+++ b/gin/arguments.h -@@ -28,14 +28,14 @@ class GIN_EXPORT Arguments { - v8::Local holder = is_for_property_ - ? info_for_property_->Holder() - : info_for_function_->Holder(); -- return ConvertFromV8(isolate_, holder, out); -+ return gin::ConvertFromV8(isolate_, holder, out); - } - - template - bool GetData(T* out) { - v8::Local data = is_for_property_ ? info_for_property_->Data() - : info_for_function_->Data(); -- return ConvertFromV8(isolate_, data, out); -+ return gin::ConvertFromV8(isolate_, data, out); - } - - template -@@ -45,7 +45,7 @@ class GIN_EXPORT Arguments { - return false; - } - v8::Local val = (*info_for_function_)[next_++]; -- return ConvertFromV8(isolate_, val, out); -+ return gin::ConvertFromV8(isolate_, val, out); - } - - template -@@ -58,7 +58,7 @@ class GIN_EXPORT Arguments { - out->resize(remaining); - for (int i = 0; i < remaining; ++i) { - v8::Local val = (*info_for_function_)[next_++]; -- if (!ConvertFromV8(isolate_, val, &out->at(i))) -+ if (!gin::ConvertFromV8(isolate_, val, &out->at(i))) - return false; - } - return true; -@@ -80,7 +80,7 @@ class GIN_EXPORT Arguments { - template - void Return(T val) { - v8::Local v8_value; -- if (!TryConvertToV8(isolate_, val, &v8_value)) -+ if (!gin::TryConvertToV8(isolate_, val, &v8_value)) - return; - (is_for_property_ ? info_for_property_->GetReturnValue() - : info_for_function_->GetReturnValue()) -diff --git a/gin/converter.h b/gin/converter.h -index 27b4d0acd016df378e4cb44ccda1a433244fe2c6..b19209a8534a497373c5a2f861b26502e96144c9 100644 ---- a/gin/converter.h -+++ b/gin/converter.h -@@ -250,7 +250,7 @@ std::enable_if_t::value, bool> TryConvertToV8( - v8::Isolate* isolate, - const T& input, - v8::Local* output) { -- return ConvertToV8(isolate, input).ToLocal(output); -+ return gin::ConvertToV8(isolate, input).ToLocal(output); - } - - template -@@ -258,7 +258,7 @@ std::enable_if_t::value, bool> TryConvertToV8( - v8::Isolate* isolate, - const T& input, - v8::Local* output) { -- *output = ConvertToV8(isolate, input); -+ *output = gin::ConvertToV8(isolate, input); - return true; - } - diff --git a/script/lint.js b/script/lint.js index e6ba97697e8d..1ee6ddb46baf 100755 --- a/script/lint.js +++ b/script/lint.js @@ -55,7 +55,7 @@ function cpplint (args) { const LINTERS = [ { key: 'c++', - roots: ['shell', 'native_mate'], + roots: ['shell'], test: filename => filename.endsWith('.cc') || filename.endsWith('.h'), run: (opts, filenames) => { if (opts.fix) { diff --git a/shell/browser/api/atom_api_browser_view.cc b/shell/browser/api/atom_api_browser_view.cc index d59f2ed4df3d..3515da393a46 100644 --- a/shell/browser/api/atom_api_browser_view.cc +++ b/shell/browser/api/atom_api_browser_view.cc @@ -90,8 +90,8 @@ void BrowserView::WebContentsDestroyed() { } // static -mate::WrappableBase* BrowserView::New(gin_helper::ErrorThrower thrower, - gin::Arguments* args) { +gin_helper::WrappableBase* BrowserView::New(gin_helper::ErrorThrower thrower, + gin::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create BrowserView before app is ready"); return nullptr; diff --git a/shell/browser/api/atom_api_browser_view.h b/shell/browser/api/atom_api_browser_view.h index fe8c2ef7332d..8e767a40e839 100644 --- a/shell/browser/api/atom_api_browser_view.h +++ b/shell/browser/api/atom_api_browser_view.h @@ -33,8 +33,8 @@ class WebContents; class BrowserView : public gin_helper::TrackableObject, public content::WebContentsObserver { public: - static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, - gin::Arguments* args); + static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower, + gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_browser_window.cc b/shell/browser/api/atom_api_browser_window.cc index 350544dafceb..192efbacddbc 100644 --- a/shell/browser/api/atom_api_browser_window.cc +++ b/shell/browser/api/atom_api_browser_window.cc @@ -16,9 +16,9 @@ #include "shell/browser/unresponsive_suppressor.h" #include "shell/browser/web_contents_preferences.h" #include "shell/browser/window_list.h" -#include "shell/common/api/constructor.h" #include "shell/common/color_util.h" #include "shell/common/gin_converters/value_converter.h" +#include "shell/common/gin_helper/constructor.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/gin_helper/object_template_builder.h" #include "shell/common/node_includes.h" @@ -445,8 +445,8 @@ void BrowserWindow::OnWindowHide() { } // static -mate::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower, - gin::Arguments* args) { +gin_helper::WrappableBase* BrowserWindow::New(gin_helper::ErrorThrower thrower, + gin::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create BrowserWindow before app is ready"); return nullptr; @@ -502,7 +502,7 @@ void Initialize(v8::Local exports, v8::Isolate* isolate = context->GetIsolate(); gin_helper::Dictionary dict(isolate, exports); dict.Set("BrowserWindow", - mate::CreateConstructor( + gin_helper::CreateConstructor( isolate, base::BindRepeating(&BrowserWindow::New))); } diff --git a/shell/browser/api/atom_api_browser_window.h b/shell/browser/api/atom_api_browser_window.h index 644c91a2c816..b3ef05ec491c 100644 --- a/shell/browser/api/atom_api_browser_window.h +++ b/shell/browser/api/atom_api_browser_window.h @@ -23,8 +23,8 @@ class BrowserWindow : public TopLevelWindow, public content::WebContentsObserver, public ExtendedWebContentsObserver { public: - static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, - gin::Arguments* args); + static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower, + gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_menu.h b/shell/browser/api/atom_api_menu.h index 82e8a4161f6b..46df02603246 100644 --- a/shell/browser/api/atom_api_menu.h +++ b/shell/browser/api/atom_api_menu.h @@ -22,7 +22,7 @@ class Menu : public gin_helper::TrackableObject, public AtomMenuModel::Delegate, public AtomMenuModel::Observer { public: - static mate::WrappableBase* New(gin::Arguments* args); + static gin_helper::WrappableBase* New(gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); @@ -41,7 +41,7 @@ class Menu : public gin_helper::TrackableObject, explicit Menu(gin::Arguments* args); ~Menu() override; - // mate::Wrappable: + // gin_helper::Wrappable: void AfterInit(v8::Isolate* isolate) override; // ui::SimpleMenuModel::Delegate: @@ -150,17 +150,4 @@ struct Converter { } // namespace gin -namespace mate { - -template <> -struct Converter { - static bool FromV8(v8::Isolate* isolate, - v8::Local val, - electron::AtomMenuModel** out) { - return gin::ConvertFromV8(isolate, val, out); - } -}; - -} // namespace mate - #endif // SHELL_BROWSER_API_ATOM_API_MENU_H_ diff --git a/shell/browser/api/atom_api_menu_mac.mm b/shell/browser/api/atom_api_menu_mac.mm index 5452f14476d6..9d0d1eba9924 100644 --- a/shell/browser/api/atom_api_menu_mac.mm +++ b/shell/browser/api/atom_api_menu_mac.mm @@ -177,7 +177,7 @@ void Menu::SendActionToFirstResponder(const std::string& action) { } // static -mate::WrappableBase* Menu::New(gin::Arguments* args) { +gin_helper::WrappableBase* Menu::New(gin::Arguments* args) { return new MenuMac(args); } diff --git a/shell/browser/api/atom_api_menu_views.cc b/shell/browser/api/atom_api_menu_views.cc index 4f82def8dd1a..83098d99a29e 100644 --- a/shell/browser/api/atom_api_menu_views.cc +++ b/shell/browser/api/atom_api_menu_views.cc @@ -84,7 +84,7 @@ void MenuViews::OnClosed(int32_t window_id, base::OnceClosure callback) { } // static -mate::WrappableBase* Menu::New(gin::Arguments* args) { +gin_helper::WrappableBase* Menu::New(gin::Arguments* args) { return new MenuViews(args); } diff --git a/shell/browser/api/atom_api_net.h b/shell/browser/api/atom_api_net.h index 2b9098a48b3d..0c2c04a0219f 100644 --- a/shell/browser/api/atom_api_net.h +++ b/shell/browser/api/atom_api_net.h @@ -5,13 +5,13 @@ #ifndef SHELL_BROWSER_API_ATOM_API_NET_H_ #define SHELL_BROWSER_API_ATOM_API_NET_H_ -#include "native_mate/wrappable.h" +#include "shell/common/gin_helper/wrappable.h" namespace electron { namespace api { -class Net : public mate::Wrappable { +class Net : public gin_helper::Wrappable { public: static v8::Local Create(v8::Isolate* isolate); diff --git a/shell/browser/api/atom_api_notification.cc b/shell/browser/api/atom_api_notification.cc index 149674807de2..11db57ff1b2f 100644 --- a/shell/browser/api/atom_api_notification.cc +++ b/shell/browser/api/atom_api_notification.cc @@ -80,8 +80,8 @@ Notification::~Notification() { } // static -mate::WrappableBase* Notification::New(gin_helper::ErrorThrower thrower, - gin::Arguments* args) { +gin_helper::WrappableBase* Notification::New(gin_helper::ErrorThrower thrower, + gin::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create Notification before app is ready"); return nullptr; diff --git a/shell/browser/api/atom_api_notification.h b/shell/browser/api/atom_api_notification.h index 8d0680935622..badd9e896c46 100644 --- a/shell/browser/api/atom_api_notification.h +++ b/shell/browser/api/atom_api_notification.h @@ -28,8 +28,8 @@ namespace api { class Notification : public gin_helper::TrackableObject, public NotificationDelegate { public: - static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, - gin::Arguments* args); + static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower, + gin::Arguments* args); static bool IsSupported(); static void BuildPrototype(v8::Isolate* isolate, diff --git a/shell/browser/api/atom_api_session.cc b/shell/browser/api/atom_api_session.cc index 2ee2ed4cd6c9..926648df0613 100644 --- a/shell/browser/api/atom_api_session.cc +++ b/shell/browser/api/atom_api_session.cc @@ -216,7 +216,7 @@ void DestroyGlobalHandle(v8::Isolate* isolate, void* ptr = object->GetAlignedPointerFromInternalField(0); if (!ptr) return; - delete static_cast(ptr); + delete static_cast(ptr); object->SetAlignedPointerInInternalField(0, nullptr); } } diff --git a/shell/browser/api/atom_api_session.h b/shell/browser/api/atom_api_session.h index e63bfe1dab74..d35479a7e25b 100644 --- a/shell/browser/api/atom_api_session.h +++ b/shell/browser/api/atom_api_session.h @@ -108,7 +108,7 @@ class Session : public gin_helper::TrackableObject, download::DownloadItem* item) override; private: - // Cached mate::Wrappable objects. + // Cached gin_helper::Wrappable objects. v8::Global cookies_; v8::Global protocol_; v8::Global net_log_; diff --git a/shell/browser/api/atom_api_top_level_window.cc b/shell/browser/api/atom_api_top_level_window.cc index e1bbfdbf242e..47d6e61f83b5 100644 --- a/shell/browser/api/atom_api_top_level_window.cc +++ b/shell/browser/api/atom_api_top_level_window.cc @@ -1055,7 +1055,7 @@ void TopLevelWindow::RemoveFromParentChildWindows() { } // static -mate::WrappableBase* TopLevelWindow::New(gin_helper::Arguments* args) { +gin_helper::WrappableBase* TopLevelWindow::New(gin_helper::Arguments* args) { gin_helper::Dictionary options = gin::Dictionary::CreateEmpty(args->isolate()); args->GetNext(&options); diff --git a/shell/browser/api/atom_api_top_level_window.h b/shell/browser/api/atom_api_top_level_window.h index d89b0ee2ba04..0ead23d09ca3 100644 --- a/shell/browser/api/atom_api_top_level_window.h +++ b/shell/browser/api/atom_api_top_level_window.h @@ -28,7 +28,7 @@ class View; class TopLevelWindow : public gin_helper::TrackableObject, public NativeWindowObserver { public: - static mate::WrappableBase* New(gin_helper::Arguments* args); + static gin_helper::WrappableBase* New(gin_helper::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_tray.cc b/shell/browser/api/atom_api_tray.cc index f0999d3c52dd..e13d0981772f 100644 --- a/shell/browser/api/atom_api_tray.cc +++ b/shell/browser/api/atom_api_tray.cc @@ -65,9 +65,9 @@ Tray::Tray(gin::Handle image, gin_helper::Arguments* args) Tray::~Tray() = default; // static -mate::WrappableBase* Tray::New(gin_helper::ErrorThrower thrower, - gin::Handle image, - gin_helper::Arguments* args) { +gin_helper::WrappableBase* Tray::New(gin_helper::ErrorThrower thrower, + gin::Handle image, + gin_helper::Arguments* args) { if (!Browser::Get()->is_ready()) { thrower.ThrowError("Cannot create Tray before app is ready"); return nullptr; diff --git a/shell/browser/api/atom_api_tray.h b/shell/browser/api/atom_api_tray.h index b6c888e232d1..f578084b60c6 100644 --- a/shell/browser/api/atom_api_tray.h +++ b/shell/browser/api/atom_api_tray.h @@ -34,9 +34,9 @@ class NativeImage; class Tray : public gin_helper::TrackableObject, public TrayIconObserver { public: - static mate::WrappableBase* New(gin_helper::ErrorThrower thrower, - gin::Handle image, - gin_helper::Arguments* args); + static gin_helper::WrappableBase* New(gin_helper::ErrorThrower thrower, + gin::Handle image, + gin_helper::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_url_loader.cc b/shell/browser/api/atom_api_url_loader.cc index 966c5d5a3885..0b9cf17feb42 100644 --- a/shell/browser/api/atom_api_url_loader.cc +++ b/shell/browser/api/atom_api_url_loader.cc @@ -318,7 +318,7 @@ void SimpleURLLoaderWrapper::Cancel() { } // static -mate::WrappableBase* SimpleURLLoaderWrapper::New(gin::Arguments* args) { +gin_helper::WrappableBase* SimpleURLLoaderWrapper::New(gin::Arguments* args) { gin_helper::Dictionary opts; if (!args->GetNext(&opts)) { args->ThrowTypeError("Expected a dictionary"); diff --git a/shell/browser/api/atom_api_url_loader.h b/shell/browser/api/atom_api_url_loader.h index 2236c318ef6a..15ce4b4456cb 100644 --- a/shell/browser/api/atom_api_url_loader.h +++ b/shell/browser/api/atom_api_url_loader.h @@ -38,7 +38,7 @@ class SimpleURLLoaderWrapper public network::SimpleURLLoaderStreamConsumer { public: ~SimpleURLLoaderWrapper() override; - static mate::WrappableBase* New(gin::Arguments* args); + static gin_helper::WrappableBase* New(gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_view.cc b/shell/browser/api/atom_api_view.cc index 3f6a2ffe65f3..068dc2b59f6e 100644 --- a/shell/browser/api/atom_api_view.cc +++ b/shell/browser/api/atom_api_view.cc @@ -43,7 +43,7 @@ void View::AddChildViewAt(gin::Handle child, size_t index) { #endif // static -mate::WrappableBase* View::New(gin::Arguments* args) { +gin_helper::WrappableBase* View::New(gin::Arguments* args) { auto* view = new View(); view->InitWithArgs(args); return view; diff --git a/shell/browser/api/atom_api_view.h b/shell/browser/api/atom_api_view.h index ff7ed2f5722a..0244e64ee67d 100644 --- a/shell/browser/api/atom_api_view.h +++ b/shell/browser/api/atom_api_view.h @@ -19,7 +19,7 @@ namespace api { class View : public gin_helper::TrackableObject { public: - static mate::WrappableBase* New(gin::Arguments* args); + static gin_helper::WrappableBase* New(gin::Arguments* args); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/atom_api_web_contents_view.cc b/shell/browser/api/atom_api_web_contents_view.cc index 1aae461cde15..7f5127b6dd64 100644 --- a/shell/browser/api/atom_api_web_contents_view.cc +++ b/shell/browser/api/atom_api_web_contents_view.cc @@ -8,7 +8,7 @@ #include "shell/browser/api/atom_api_web_contents.h" #include "shell/browser/browser.h" #include "shell/browser/ui/inspectable_web_contents_view.h" -#include "shell/common/api/constructor.h" +#include "shell/common/gin_helper/constructor.h" #include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" @@ -79,7 +79,7 @@ void WebContentsView::WebContentsDestroyed() { } // static -mate::WrappableBase* WebContentsView::New( +gin_helper::WrappableBase* WebContentsView::New( gin_helper::Arguments* args, gin::Handle web_contents) { // Currently we only support InspectableWebContents, e.g. the WebContents @@ -121,7 +121,7 @@ void Initialize(v8::Local exports, v8::Isolate* isolate = context->GetIsolate(); gin_helper::Dictionary dict(isolate, exports); dict.Set("WebContentsView", - mate::CreateConstructor( + gin_helper::CreateConstructor( isolate, base::BindRepeating(&WebContentsView::New))); } diff --git a/shell/browser/api/atom_api_web_contents_view.h b/shell/browser/api/atom_api_web_contents_view.h index 134717c5a7d1..f9a9fa4c1001 100644 --- a/shell/browser/api/atom_api_web_contents_view.h +++ b/shell/browser/api/atom_api_web_contents_view.h @@ -18,8 +18,8 @@ class WebContents; class WebContentsView : public View, public content::WebContentsObserver { public: - static mate::WrappableBase* New(gin_helper::Arguments* args, - gin::Handle web_contents); + static gin_helper::WrappableBase* New(gin_helper::Arguments* args, + gin::Handle web_contents); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); diff --git a/shell/browser/api/views/atom_api_box_layout.cc b/shell/browser/api/views/atom_api_box_layout.cc index 23b4474bf910..91b75698cf42 100644 --- a/shell/browser/api/views/atom_api_box_layout.cc +++ b/shell/browser/api/views/atom_api_box_layout.cc @@ -6,9 +6,9 @@ #include -#include "native_mate/dictionary.h" #include "shell/browser/api/atom_api_view.h" -#include "shell/common/api/constructor.h" +#include "shell/common/gin_helper/constructor.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" namespace mate { @@ -42,14 +42,15 @@ BoxLayout::BoxLayout(views::BoxLayout::Orientation orientation) BoxLayout::~BoxLayout() {} -void BoxLayout::SetFlexForView(mate::Handle view, int flex) { +void BoxLayout::SetFlexForView(gin::Handle view, int flex) { auto* box_layout = static_cast(layout_manager()); box_layout->SetFlexForView(view->view(), flex); } // static -mate::WrappableBase* BoxLayout::New(mate::Arguments* args, - views::BoxLayout::Orientation orientation) { +gin_helper::WrappableBase* BoxLayout::New( + gin_helper::Arguments* args, + views::BoxLayout::Orientation orientation) { auto* layout = new BoxLayout(orientation); layout->InitWith(args->isolate(), args->GetThis()); return layout; @@ -58,8 +59,8 @@ mate::WrappableBase* BoxLayout::New(mate::Arguments* args, // static void BoxLayout::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "BoxLayout")); - mate::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) + prototype->SetClassName(gin_helper::StringTov8(isolate, "BoxLayout")); + gin_helper::ObjectTemplateBuilder(isolate, prototype->PrototypeTemplate()) .SetMethod("setFlexForView", &BoxLayout::SetFlexForView); } @@ -76,8 +77,8 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - dict.Set("BoxLayout", mate::CreateConstructor( + gin_helper::Dictionary dict(isolate, exports); + dict.Set("BoxLayout", gin_helper::CreateConstructor( isolate, base::BindRepeating(&BoxLayout::New))); } diff --git a/shell/browser/api/views/atom_api_box_layout.h b/shell/browser/api/views/atom_api_box_layout.h index 4cffa4a7b5ee..9f84a8360cd9 100644 --- a/shell/browser/api/views/atom_api_box_layout.h +++ b/shell/browser/api/views/atom_api_box_layout.h @@ -5,7 +5,7 @@ #ifndef SHELL_BROWSER_API_VIEWS_ATOM_API_BOX_LAYOUT_H_ #define SHELL_BROWSER_API_VIEWS_ATOM_API_BOX_LAYOUT_H_ -#include "native_mate/handle.h" +#include "gin/handle.h" #include "shell/browser/api/views/atom_api_layout_manager.h" #include "ui/views/layout/box_layout.h" @@ -17,13 +17,14 @@ class View; class BoxLayout : public LayoutManager { public: - static mate::WrappableBase* New(mate::Arguments* args, - views::BoxLayout::Orientation orientation); + static gin_helper::WrappableBase* New( + gin_helper::Arguments* args, + views::BoxLayout::Orientation orientation); static void BuildPrototype(v8::Isolate* isolate, v8::Local prototype); - void SetFlexForView(mate::Handle view, int flex); + void SetFlexForView(gin::Handle view, int flex); protected: explicit BoxLayout(views::BoxLayout::Orientation orientation); diff --git a/shell/browser/api/views/atom_api_button.cc b/shell/browser/api/views/atom_api_button.cc index a93a2b6abe03..e146d44e0947 100644 --- a/shell/browser/api/views/atom_api_button.cc +++ b/shell/browser/api/views/atom_api_button.cc @@ -4,8 +4,8 @@ #include "shell/browser/api/views/atom_api_button.h" -#include "native_mate/dictionary.h" -#include "shell/common/api/constructor.h" +#include "shell/common/gin_helper/constructor.h" +#include "shell/common/gin_helper/dictionary.h" #include "shell/common/node_includes.h" namespace electron { @@ -25,7 +25,7 @@ void Button::ButtonPressed(views::Button* sender, const ui::Event& event) { } // static -mate::WrappableBase* Button::New(mate::Arguments* args) { +gin_helper::WrappableBase* Button::New(gin_helper::Arguments* args) { args->ThrowError("Button can not be created directly"); return nullptr; } @@ -33,7 +33,7 @@ mate::WrappableBase* Button::New(mate::Arguments* args) { // static void Button::BuildPrototype(v8::Isolate* isolate, v8::Local prototype) { - prototype->SetClassName(mate::StringToV8(isolate, "Button")); + prototype->SetClassName(gin_helper::StringTov8(isolate, "Button")); } } // namespace api @@ -49,8 +49,8 @@ void Initialize(v8::Local exports, v8::Local context, void* priv) { v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - dict.Set("Button", mate::CreateConstructor