Use JavaScript to open the main window.
This commit is contained in:
parent
b313d94a2f
commit
60528e53ee
11 changed files with 479 additions and 25 deletions
|
@ -7,7 +7,8 @@
|
|||
#include "base/values.h"
|
||||
#include "browser/atom_browser_context.h"
|
||||
#include "browser/native_window.h"
|
||||
#include "content/public/renderer/v8_value_converter.h"
|
||||
#include "common/v8_value_converter_impl.h"
|
||||
#include "content/public/browser/web_contents.h"
|
||||
|
||||
using content::V8ValueConverter;
|
||||
|
||||
|
@ -18,6 +19,12 @@ namespace api {
|
|||
Window::Window(v8::Handle<v8::Object> wrapper, base::DictionaryValue* options)
|
||||
: EventEmitter(wrapper),
|
||||
window_(NativeWindow::Create(AtomBrowserContext::Get(), options)) {
|
||||
window_->InitFromOptions(options);
|
||||
window_->GetWebContents()->GetController().LoadURL(
|
||||
GURL("https://github.com"),
|
||||
content::Referrer(),
|
||||
content::PAGE_TRANSITION_AUTO_TOPLEVEL,
|
||||
std::string());
|
||||
}
|
||||
|
||||
Window::~Window() {
|
||||
|
@ -30,7 +37,7 @@ v8::Handle<v8::Value> Window::New(const v8::Arguments &args) {
|
|||
if (!args[0]->IsObject())
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
scoped_ptr<V8ValueConverter> converter(V8ValueConverter::create());
|
||||
scoped_ptr<V8ValueConverter> converter(new V8ValueConverterImpl());
|
||||
scoped_ptr<base::Value> options(
|
||||
converter->FromV8Value(args[0], v8::Context::GetCurrent()));
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "browser/api/atom_bindings.h"
|
||||
|
||||
#include "base/logging.h"
|
||||
#include "vendor/node/src/node.h"
|
||||
#include "vendor/node/src/node_internals.h"
|
||||
|
||||
|
@ -31,6 +32,21 @@ void AtomBindings::BindTo(v8::Handle<v8::Object> process) {
|
|||
node::SetMethod(process, "atom_binding", Binding);
|
||||
}
|
||||
|
||||
void AtomBindings::AfterLoad() {
|
||||
v8::HandleScope scope;
|
||||
v8::Context::Scope context_scope(node::g_context);
|
||||
|
||||
v8::Handle<v8::Object> global = node::g_context->Global();
|
||||
v8::Handle<v8::Object> atom =
|
||||
global->Get(v8::String::New("__atom"))->ToObject();
|
||||
DCHECK(!atom.IsEmpty());
|
||||
|
||||
browser_main_parts_ = v8::Persistent<v8::Object>::New(
|
||||
node_isolate,
|
||||
atom->Get(v8::String::New("browserMainParts"))->ToObject());
|
||||
DCHECK(!browser_main_parts_.IsEmpty());
|
||||
}
|
||||
|
||||
// static
|
||||
v8::Handle<v8::Value> AtomBindings::Binding(const v8::Arguments& args) {
|
||||
v8::HandleScope scope;
|
||||
|
|
|
@ -17,13 +17,23 @@ class AtomBindings {
|
|||
|
||||
// Add process.atom_binding function, which behaves like process.binding but
|
||||
// load native code from atom-shell instead.
|
||||
void BindTo(v8::Handle<v8::Object> process);
|
||||
virtual void BindTo(v8::Handle<v8::Object> process);
|
||||
|
||||
// Called when the node.js main script has been loaded.
|
||||
virtual void AfterLoad();
|
||||
|
||||
// The require('atom').browserMainParts object.
|
||||
v8::Handle<v8::Object> browser_main_parts() {
|
||||
return browser_main_parts_;
|
||||
}
|
||||
|
||||
private:
|
||||
static v8::Handle<v8::Value> Binding(const v8::Arguments& args);
|
||||
|
||||
static v8::Persistent<v8::Object> binding_cache_;
|
||||
|
||||
v8::Persistent<v8::Object> browser_main_parts_;
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(AtomBindings);
|
||||
};
|
||||
|
||||
|
|
3
browser/api/lib/window.coffee
Normal file
3
browser/api/lib/window.coffee
Normal file
|
@ -0,0 +1,3 @@
|
|||
Window = process.atom_binding('window').Window
|
||||
|
||||
module.exports = Window
|
Loading…
Add table
Add a link
Reference in a new issue