'lib_sources': [
'app/atom_main_delegate.cc',
'app/atom_main_delegate.h',
+ 'browser/api/atom_api_event_emitter.cc',
+ 'browser/api/atom_api_event_emitter.h',
'browser/api/atom_api_extensions.cc',
'browser/api/atom_api_extensions.h',
'browser/api/atom_api_window.cc',
'browser/api/atom_bindings.h',
'browser/atom_browser_client.cc',
'browser/atom_browser_client.h',
+ 'browser/atom_browser_context.cc',
+ 'browser/atom_browser_context.h',
'browser/atom_browser_main_parts.cc',
'browser/atom_browser_main_parts.h',
'browser/atom_event_processing_window.h',
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/api/atom_api_event_emitter.h"
+
+namespace atom {
+
+namespace api {
+
+EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
+ Wrap(wrapper);
+}
+
+EventEmitter::~EventEmitter() {
+}
+
+} // namespace api
+
+} // namespace atom
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_API_ATOM_API_EVENT_EMITTER_H_
+#define ATOM_BROWSER_API_ATOM_API_EVENT_EMITTER_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "vendor/node/src/node_object_wrap.h"
+
+namespace atom {
+
+namespace api {
+
+// Class interiting EventEmitter should assume it's a javascript object which
+// interits require('events').EventEmitter, this class provides many helper
+// methods to do event processing in C++.
+class EventEmitter : public node::ObjectWrap {
+ public:
+ virtual ~EventEmitter();
+
+ // Small accessor to return handle_, this follows Google C++ Style.
+ v8::Persistent<v8::Object>& handle() { return handle_; }
+
+ protected:
+ explicit EventEmitter(v8::Handle<v8::Object> wrapper);
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(EventEmitter);
+};
+
+} // namespace api
+
+} // namespace atom
+
+#endif // ATOM_BROWSER_API_ATOM_API_EVENT_EMITTER_H_
#include "browser/api/atom_api_window.h"
+#include "base/values.h"
+#include "browser/atom_browser_context.h"
+#include "browser/native_window.h"
+#include "content/public/renderer/v8_value_converter.h"
+
+using content::V8ValueConverter;
+
namespace atom {
-static void Initialize(v8::Handle<v8::Object> target) {
- target->Set(v8::String::New("hello"), v8::String::New("world"));
+namespace api {
+
+Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
+ : EventEmitter(wrapper),
+ window_(NativeWindow::Create(AtomBrowserContext::Get(), options)) {
+}
+
+Window::~Window() {
+}
+
+// static
+v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
+ v8::HandleScope scope;
+
+ if (!args[0]->IsObject())
+ return node::ThrowTypeError("Bad argument");
+
+ scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
+ scoped_ptr<base::Value> options(
+ converter->FromV8Value(args[0], v8::Context::GetCurrent()));
+
+ if (!options || !options->IsType(base::Value::TYPE_DICTIONARY))
+ return node::ThrowTypeError("Bad argument");
+
+ new Window(args.This(), static_cast<base::DictionaryValue*>(options.get()));
+
+ return args.This();
}
+// static
+void Window::Initialize(v8::Handle<v8::Object> target) {
+ v8::HandleScope scope;
+
+ v8::Local<v8::FunctionTemplate> t = v8::FunctionTemplate::New(Window::New);
+ t->InstanceTemplate()->SetInternalFieldCount(1);
+ t->SetClassName(v8::String::NewSymbol("Window"));
+ target->Set(v8::String::NewSymbol("Window"), t->GetFunction());
+}
+
+} // namespace api
+
} // namespace atom
-NODE_MODULE(atom_api_window, atom::Initialize)
+NODE_MODULE(atom_api_window, atom::api::Window::Initialize)
#ifndef ATOM_BROWSER_API_ATOM_API_WINDOW_H_
#define ATOM_BROWSER_API_ATOM_API_WINDOW_H_
-#include "vendor/node/src/node.h"
-#include "vendor/node/src/node_object_wrap.h"
+#include "browser/api/atom_api_event_emitter.h"
+
+namespace base {
+class DictionaryValue;
+}
namespace atom {
+class NativeWindow;
+
+namespace api {
+
+class Window : public EventEmitter {
+ public:
+ virtual ~Window();
+
+ static void Initialize(v8::Handle<v8::Object> target);
+
+ NativeWindow* window() { return window_.get(); }
+
+ protected:
+ explicit Window(v8::Handle<v8::Object> wrapper,
+ base::DictionaryValue* options);
+
+ private:
+ static v8::Handle<v8::Value> New(const v8::Arguments &args);
+
+ scoped_ptr<NativeWindow> window_;
+
+ DISALLOW_COPY_AND_ASSIGN(Window);
+};
+
+} // namespace api
+
} // namespace atom
#endif // ATOM_BROWSER_API_ATOM_API_WINDOW_H_
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "browser/atom_browser_context.h"
+
+namespace atom {
+
+// static
+AtomBrowserContext* AtomBrowserContext::self_;
+
+AtomBrowserContext::AtomBrowserContext() {
+ DCHECK(!self_);
+
+ self_ = this;
+}
+
+AtomBrowserContext::~AtomBrowserContext() {
+}
+
+// static
+AtomBrowserContext* AtomBrowserContext::Get() {
+ DCHECK(self_);
+
+ return self_;
+}
+
+} // namespace atom
--- /dev/null
+// Copyright (c) 2013 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
+#define ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
+
+#include "brightray/browser/browser_context.h"
+
+namespace atom {
+
+class AtomBrowserContext : public brightray::BrowserContext {
+ public:
+ AtomBrowserContext();
+ virtual ~AtomBrowserContext();
+
+ // We assume there is only one BrowserContext per browser process.
+ static AtomBrowserContext* Get();
+
+ private:
+ static AtomBrowserContext* self_;
+
+ DISALLOW_COPY_AND_ASSIGN(AtomBrowserContext);
+};
+
+} // namespace atom
+
+#endif // ATOM_BROWSER_ATOM_BROWSER_CONTEXT_H_
#include "base/values.h"
#include "browser/api/atom_bindings.h"
+#include "browser/atom_browser_context.h"
#include "browser/native_window.h"
#include "brightray/browser/browser_context.h"
#include "brightray/browser/inspectable_web_contents.h"
AtomBrowserMainParts::~AtomBrowserMainParts() {
}
+brightray::BrowserContext* AtomBrowserMainParts::CreateBrowserContext() {
+ return new AtomBrowserContext();
+}
+
void AtomBrowserMainParts::PostEarlyInitialization() {
brightray::BrowserMainParts::PostEarlyInitialization();
virtual ~AtomBrowserMainParts();
protected:
+ // Implementations of brightray::BrowserMainParts.
+ virtual brightray::BrowserContext* CreateBrowserContext() OVERRIDE;
+
+ // Implementations of content::BrowserMainParts.
virtual void PostEarlyInitialization() OVERRIDE;
virtual void PreMainMessageLoopStart() OVERRIDE;
virtual void PreMainMessageLoopRun() OVERRIDE;
#include "browser/native_window_mac.h"
+#include <string>
+
// FIXME: The foundation_util.h is aborting our compilation, do not
// include it.
#define BASE_MAC_FOUNDATION_UTIL_H_