Merge branch 'master' into nativeimage_ico_support_windows

This commit is contained in:
Eran Tiktin 2015-08-20 17:11:52 +03:00
commit 2bc087b5d5
163 changed files with 3511 additions and 909 deletions

View file

@ -34,6 +34,10 @@ IPC_MESSAGE_ROUTED2(AtomViewMsg_Message,
base::string16 /* channel */,
base::ListValue /* arguments */)
IPC_MESSAGE_ROUTED2(AtomViewMsg_ExecuteJavaScript,
base::string16 /* code */,
bool /* has user gesture */)
// Sent by the renderer when the draggable regions are updated.
IPC_MESSAGE_ROUTED1(AtomViewHostMsg_UpdateDraggableRegions,
std::vector<atom::DraggableRegion> /* regions */)

View file

@ -8,9 +8,9 @@
#include "atom_natives.h" // NOLINT: This file is generated with coffee2c.
#include "atom/common/asar/archive.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "native_mate/arguments.h"
#include "native_mate/callback.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "native_mate/wrappable.h"

View file

@ -82,7 +82,7 @@ bool AddImageSkiaRep(gfx::ImageSkia* image,
if (!decoded)
return false;
image->AddRepresentation(gfx::ImageSkiaRep(*decoded.release(), scale_factor));
image->AddRepresentation(gfx::ImageSkiaRep(*decoded, scale_factor));
return true;
}
@ -117,7 +117,7 @@ bool PopulateImageSkiaRepsFromPath(gfx::ImageSkia* image,
}
#if defined(OS_MACOSX)
bool IsTemplateImage(const base::FilePath& path) {
bool IsTemplateFilename(const base::FilePath& path) {
return (MatchPattern(path.value(), "*Template.*") ||
MatchPattern(path.value(), "*Template@*x.*"));
}
@ -143,6 +143,7 @@ mate::ObjectTemplateBuilder NativeImage::GetObjectTemplateBuilder(
.SetMethod("isEmpty", &NativeImage::IsEmpty)
.SetMethod("getSize", &NativeImage::GetSize)
.SetMethod("setTemplateImage", &NativeImage::SetTemplateImage)
.SetMethod("isTemplateImage", &NativeImage::IsTemplateImage)
.Build());
return mate::ObjectTemplateBuilder(
@ -184,6 +185,10 @@ gfx::Size NativeImage::GetSize() {
#if !defined(OS_MACOSX)
void NativeImage::SetTemplateImage(bool setAsTemplate) {
}
bool NativeImage::IsTemplateImage() {
return false;
}
#endif
// static
@ -249,7 +254,7 @@ mate::Handle<NativeImage> NativeImage::CreateFromPath(
gfx::Image image(image_skia);
mate::Handle<NativeImage> handle = Create(isolate, image);
#if defined(OS_MACOSX)
if (IsTemplateImage(path))
if (IsTemplateFilename(path))
handle->SetTemplateImage(true);
#endif
return handle;

View file

@ -67,6 +67,8 @@ class NativeImage : public mate::Wrappable {
// Mark the image as template image.
void SetTemplateImage(bool setAsTemplate);
// Determine if the image is a template image.
bool IsTemplateImage();
gfx::Image image_;

View file

@ -14,6 +14,10 @@ void NativeImage::SetTemplateImage(bool setAsTemplate) {
[image_.AsNSImage() setTemplate:setAsTemplate];
}
bool NativeImage::IsTemplateImage() {
return [image_.AsNSImage() isTemplate];
}
} // namespace api
} // namespace atom

View file

@ -98,6 +98,10 @@ void AtomBindings::OnCallNextTick(uv_async_t* handle) {
if (tick_info->in_tick())
continue;
if (tick_info->length() == 0) {
env->isolate()->RunMicrotasks();
}
if (tick_info->length() == 0) {
tick_info->set_index(0);
continue;

View file

@ -0,0 +1,32 @@
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/api/locker.h"
#include "base/memory/scoped_ptr.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
#include "atom/common/node_includes.h"
namespace mate {
namespace internal {
v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
v8::Local<v8::Object> obj,
ValueVector* args) {
// Perform microtask checkpoint after running JavaScript.
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
// Use node::MakeCallback to call the callback, and it will also run pending
// tasks in Node.js.
return node::MakeCallback(
isolate, obj, "emit", args->size(), &args->front());
}
} // namespace internal
} // namespace mate

View file

@ -2,8 +2,8 @@
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#define ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#ifndef ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
#define ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_
#include <vector>
@ -50,4 +50,4 @@ v8::Local<v8::Value> EmitEvent(v8::Isolate* isolate,
} // namespace mate
#endif // ATOM_COMMON_EVENT_EMITTER_CALLER_H_
#endif // ATOM_COMMON_API_EVENT_EMITTER_CALLER_H_

View file

@ -1,3 +1,5 @@
savedGlobal = global # the "global.global" might be deleted later
module.exports =
class CallbacksRegistry
constructor: ->
@ -16,10 +18,10 @@ class CallbacksRegistry
@callbacks[id] ? ->
call: (id, args...) ->
@get(id).call global, args...
@get(id).call savedGlobal, args...
apply: (id, args...) ->
@get(id).apply global, args...
@get(id).apply savedGlobal, args...
remove: (id) ->
delete @callbacks[id]

17
atom/common/api/locker.cc Normal file
View file

@ -0,0 +1,17 @@
// Copyright 2014 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 "atom/common/api/locker.h"
namespace mate {
Locker::Locker(v8::Isolate* isolate) {
if (IsBrowserProcess())
locker_.reset(new v8::Locker(isolate));
}
Locker::~Locker() {
}
} // namespace mate

34
atom/common/api/locker.h Normal file
View file

@ -0,0 +1,34 @@
// Copyright 2014 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 ATOM_COMMON_API_LOCKER_H_
#define ATOM_COMMON_API_LOCKER_H_
#include "base/memory/scoped_ptr.h"
#include "v8/include/v8.h"
namespace mate {
// Only lock when lockers are used in current thread.
class Locker {
public:
explicit Locker(v8::Isolate* isolate);
~Locker();
// Returns whether current process is browser process, currently we detect it
// by checking whether current has used V8 Lock, but it might be a bad idea.
static inline bool IsBrowserProcess() { return v8::Locker::IsActive(); }
private:
void* operator new(size_t size);
void operator delete(void*, size_t);
scoped_ptr<v8::Locker> locker_;
DISALLOW_COPY_AND_ASSIGN(Locker);
};
} // namespace mate
#endif // ATOM_COMMON_API_LOCKER_H_

View file

@ -7,7 +7,7 @@
#define ATOM_MAJOR_VERSION 0
#define ATOM_MINOR_VERSION 30
#define ATOM_PATCH_VERSION 0
#define ATOM_PATCH_VERSION 4
#define ATOM_VERSION_IS_RELEASE 1

View file

@ -21,6 +21,7 @@ const MINIDUMP_TYPE kSmallDumpType = static_cast<MINIDUMP_TYPE>(
MiniDumpWithProcessThreadData | // Get PEB and TEB.
MiniDumpWithUnloadedModules); // Get unloaded modules when available.
const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
const wchar_t kPipeNameFormat[] = L"\\\\.\\pipe\\$1 Crash Service";
} // namespace
@ -47,12 +48,15 @@ void CrashReporterWin::InitBreakpad(const std::string& product_name,
base::string16 pipe_name = ReplaceStringPlaceholders(
kPipeNameFormat, base::UTF8ToUTF16(product_name), NULL);
base::string16 wait_name = ReplaceStringPlaceholders(
kWaitEventFormat, base::UTF8ToUTF16(product_name), NULL);
// Wait until the crash service is started.
HANDLE waiting_event =
::CreateEventW(NULL, TRUE, FALSE, L"g_atom_shell_crash_service");
if (waiting_event != INVALID_HANDLE_VALUE)
WaitForSingleObject(waiting_event, 1000);
HANDLE wait_event = ::CreateEventW(NULL, TRUE, FALSE, wait_name.c_str());
if (wait_event != NULL) {
WaitForSingleObject(wait_event, 1000);
CloseHandle(wait_event);
}
// ExceptionHandler() attaches our handler and ~ExceptionHandler() detaches
// it, so we must explicitly reset *before* we instantiate our new handler

View file

@ -14,6 +14,7 @@
#include "base/files/file_util.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/time/time.h"
#include "base/win/windows_version.h"
#include "vendor/breakpad/src/client/windows/crash_generation/client_info.h"
@ -24,6 +25,9 @@ namespace breakpad {
namespace {
const wchar_t kWaitEventFormat[] = L"$1CrashServiceWaitEvent";
const wchar_t kClassNameFormat[] = L"$1CrashServiceWindow";
const wchar_t kTestPipeName[] = L"\\\\.\\pipe\\ChromeCrashServices";
const wchar_t kGoogleReportURL[] = L"https://clients2.google.com/cr/report";
@ -111,13 +115,18 @@ LRESULT __stdcall CrashSvcWndProc(HWND hwnd, UINT message,
// This is the main and only application window.
HWND g_top_window = NULL;
bool CreateTopWindow(HINSTANCE instance, bool visible) {
bool CreateTopWindow(HINSTANCE instance,
const base::string16& application_name,
bool visible) {
base::string16 class_name = ReplaceStringPlaceholders(
kClassNameFormat, application_name, NULL);
WNDCLASSEXW wcx = {0};
wcx.cbSize = sizeof(wcx);
wcx.style = CS_HREDRAW | CS_VREDRAW;
wcx.lpfnWndProc = CrashSvcWndProc;
wcx.hInstance = instance;
wcx.lpszClassName = L"crash_svc_class";
wcx.lpszClassName = class_name.c_str();
ATOM atom = ::RegisterClassExW(&wcx);
DWORD style = visible ? WS_POPUPWINDOW | WS_VISIBLE : WS_OVERLAPPED;
@ -193,7 +202,8 @@ CrashService::~CrashService() {
delete sender_;
}
bool CrashService::Initialize(const base::FilePath& operating_dir,
bool CrashService::Initialize(const base::string16& application_name,
const base::FilePath& operating_dir,
const base::FilePath& dumps_path) {
using google_breakpad::CrashReportSender;
using google_breakpad::CrashGenerationServer;
@ -260,6 +270,7 @@ bool CrashService::Initialize(const base::FilePath& operating_dir,
}
if (!CreateTopWindow(::GetModuleHandleW(NULL),
application_name,
!cmd_line.HasSwitch(kNoWindow))) {
LOG(ERROR) << "could not create window";
if (security_attributes.lpSecurityDescriptor)
@ -298,11 +309,10 @@ bool CrashService::Initialize(const base::FilePath& operating_dir,
// Create or open an event to signal the browser process that the crash
// service is initialized.
HANDLE running_event =
::CreateEventW(NULL, TRUE, TRUE, L"g_atom_shell_crash_service");
// If the browser already had the event open, the CreateEvent call did not
// signal it. We need to do it manually.
::SetEvent(running_event);
base::string16 wait_name = ReplaceStringPlaceholders(
kWaitEventFormat, application_name, NULL);
HANDLE wait_event = ::CreateEventW(NULL, TRUE, FALSE, wait_name.c_str());
::SetEvent(wait_event);
return true;
}

View file

@ -37,7 +37,8 @@ class CrashService {
// other members in that case. |operating_dir| is where the CrashService
// should store breakpad's checkpoint file. |dumps_path| is the directory
// where the crash dumps should be stored.
bool Initialize(const base::FilePath& operating_dir,
bool Initialize(const base::string16& application_name,
const base::FilePath& operating_dir,
const base::FilePath& dumps_path);
// Command line switches:

View file

@ -77,7 +77,8 @@ int Main(const wchar_t* cmd) {
cmd_line.AppendSwitchNative("pipe-name", pipe_name);
breakpad::CrashService crash_service;
if (!crash_service.Initialize(operating_dir, operating_dir))
if (!crash_service.Initialize(application_name, operating_dir,
operating_dir))
return 2;
VLOG(1) << "Ready to process crash requests";

View file

@ -1,33 +0,0 @@
// Copyright (c) 2015 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/common/event_emitter_caller.h"
namespace mate {
namespace internal {
v8::Local<v8::Value> CallEmitWithArgs(v8::Isolate* isolate,
v8::Local<v8::Object> obj,
ValueVector* args) {
v8::Local<v8::String> emit_name = StringToSymbol(isolate, "emit");
v8::Local<v8::Value> emit = obj->Get(emit_name);
if (emit.IsEmpty() || !emit->IsFunction()) {
isolate->ThrowException(v8::Exception::TypeError(
StringToV8(isolate, "\"emit\" is not a function")));
return v8::Undefined(isolate);
}
v8::MaybeLocal<v8::Value> result = emit.As<v8::Function>()->Call(
isolate->GetCurrentContext(), obj, args->size(), &args->front());
if (result.IsEmpty()) {
return v8::Undefined(isolate);
}
return result.ToLocalChecked();
}
} // namespace internal
} // namespace mate

View file

@ -0,0 +1,104 @@
// Copyright (c) 2015 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_H_
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_H_
#include <vector>
#include "atom/common/api/locker.h"
#include "base/bind.h"
#include "base/callback.h"
#include "native_mate/function_template.h"
#include "native_mate/scoped_persistent.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
namespace mate {
namespace internal {
typedef scoped_refptr<RefCountedPersistent<v8::Function> > SafeV8Function;
template <typename Sig>
struct V8FunctionInvoker {};
template <typename... ArgTypes>
struct V8FunctionInvoker<v8::Local<v8::Value>(ArgTypes...)> {
static v8::Local<v8::Value> Go(v8::Isolate* isolate, SafeV8Function function,
ArgTypes... raw) {
Locker locker(isolate);
v8::EscapableHandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args = { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> ret(holder->Call(holder, args.size(), &args.front()));
return handle_scope.Escape(ret);
}
};
template <typename... ArgTypes>
struct V8FunctionInvoker<void(ArgTypes...)> {
static void Go(v8::Isolate* isolate, SafeV8Function function,
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
std::vector<v8::Local<v8::Value>> args = { ConvertToV8(isolate, raw)... };
holder->Call(holder, args.size(), &args.front());
}
};
template <typename ReturnType, typename... ArgTypes>
struct V8FunctionInvoker<ReturnType(ArgTypes...)> {
static ReturnType Go(v8::Isolate* isolate, SafeV8Function function,
ArgTypes... raw) {
Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
Locker::IsBrowserProcess() ?
nullptr : new blink::WebScopedRunV8Script(isolate));
v8::Local<v8::Function> holder = function->NewHandle();
v8::Local<v8::Context> context = holder->CreationContext();
v8::Context::Scope context_scope(context);
ReturnType ret;
std::vector<v8::Local<v8::Value>> args = { ConvertToV8(isolate, raw)... };
v8::Local<v8::Value> val(holder->Call(holder, args.size(), &args.front()));
Converter<ReturnType>::FromV8(isolate, val, &ret);
return ret;
}
};
} // namespace internal
template<typename Sig>
struct Converter<base::Callback<Sig> > {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Callback<Sig>& val) {
return CreateFunctionTemplate(isolate, val)->GetFunction();
}
static bool FromV8(v8::Isolate* isolate,
v8::Local<v8::Value> val,
base::Callback<Sig>* out) {
if (!val->IsFunction())
return false;
internal::SafeV8Function function(
new RefCountedPersistent<v8::Function>(isolate, val));
*out = base::Bind(&internal::V8FunctionInvoker<Sig>::Go, isolate, function);
return true;
}
};
} // namespace mate
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_CALLBACK_H_

View file

@ -7,8 +7,9 @@
#include <string>
#include <vector>
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/api/locker.h"
#include "atom/common/atom_command_line.h"
#include "atom/common/event_emitter_caller.h"
#include "atom/common/native_mate_converters/file_path_converter.h"
#include "base/command_line.h"
#include "base/base_paths.h"
@ -17,8 +18,8 @@
#include "base/path_service.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/common/content_paths.h"
#include "native_mate/locker.h"
#include "native_mate/dictionary.h"
#include "third_party/WebKit/public/web/WebScopedMicrotaskSuppression.h"
#include "atom/common/node_includes.h"
@ -227,6 +228,10 @@ void NodeBindings::UvRunOnce() {
// Enter node context while dealing with uv events.
v8::Context::Scope context_scope(env->context());
// Perform microtask checkpoint after running JavaScript.
scoped_ptr<blink::WebScopedRunV8Script> script_scope(
is_browser_ ? nullptr : new blink::WebScopedRunV8Script(env->isolate()));
// Deal with uv events.
int r = uv_run(uv_loop_, UV_RUN_NOWAIT);
if (r == 0 || uv_loop_->stop_flag != 0)