Add Window.url API.
This commit is contained in:
parent
d3e4db7ba3
commit
53dd742632
4 changed files with 25 additions and 5 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include "browser/atom_browser_context.h"
|
#include "browser/atom_browser_context.h"
|
||||||
#include "browser/native_window.h"
|
#include "browser/native_window.h"
|
||||||
#include "common/v8_value_converter_impl.h"
|
#include "common/v8_value_converter_impl.h"
|
||||||
|
#include "content/public/browser/navigation_entry.h"
|
||||||
#include "content/public/browser/web_contents.h"
|
#include "content/public/browser/web_contents.h"
|
||||||
#include "ui/gfx/point.h"
|
#include "ui/gfx/point.h"
|
||||||
#include "ui/gfx/rect.h"
|
#include "ui/gfx/rect.h"
|
||||||
|
@ -413,6 +414,19 @@ v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments &args) {
|
||||||
return v8::Undefined();
|
return v8::Undefined();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Handle<v8::Value> Window::GetURL(const v8::Arguments &args) {
|
||||||
|
Window* self = ObjectWrap::Unwrap<Window>(args.This());
|
||||||
|
|
||||||
|
NavigationController& controller =
|
||||||
|
self->window_->GetWebContents()->GetController();
|
||||||
|
std::string url;
|
||||||
|
if (controller.GetActiveEntry())
|
||||||
|
url = controller.GetActiveEntry()->GetVirtualURL().spec();
|
||||||
|
|
||||||
|
return v8::String::New(url.c_str(), url.size());
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Handle<v8::Value> Window::CanGoBack(const v8::Arguments &args) {
|
v8::Handle<v8::Value> Window::CanGoBack(const v8::Arguments &args) {
|
||||||
Window* self = ObjectWrap::Unwrap<Window>(args.This());
|
Window* self = ObjectWrap::Unwrap<Window>(args.This());
|
||||||
|
@ -565,6 +579,7 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
|
NODE_SET_PROTOTYPE_METHOD(t, "stop", Stop);
|
||||||
|
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "loadURL", LoadURL);
|
NODE_SET_PROTOTYPE_METHOD(t, "loadURL", LoadURL);
|
||||||
|
NODE_SET_PROTOTYPE_METHOD(t, "getURL", GetURL);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack);
|
NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "canGoForward", CanGoForward);
|
NODE_SET_PROTOTYPE_METHOD(t, "canGoForward", CanGoForward);
|
||||||
NODE_SET_PROTOTYPE_METHOD(t, "canGoToOffset", CanGoToOffset);
|
NODE_SET_PROTOTYPE_METHOD(t, "canGoToOffset", CanGoToOffset);
|
||||||
|
|
|
@ -79,6 +79,7 @@ class Window : public EventEmitter,
|
||||||
|
|
||||||
// APIs for NavigationController.
|
// APIs for NavigationController.
|
||||||
static v8::Handle<v8::Value> LoadURL(const v8::Arguments &args);
|
static v8::Handle<v8::Value> LoadURL(const v8::Arguments &args);
|
||||||
|
static v8::Handle<v8::Value> GetURL(const v8::Arguments &args);
|
||||||
static v8::Handle<v8::Value> CanGoBack(const v8::Arguments &args);
|
static v8::Handle<v8::Value> CanGoBack(const v8::Arguments &args);
|
||||||
static v8::Handle<v8::Value> CanGoForward(const v8::Arguments &args);
|
static v8::Handle<v8::Value> CanGoForward(const v8::Arguments &args);
|
||||||
static v8::Handle<v8::Value> CanGoToOffset(const v8::Arguments &args);
|
static v8::Handle<v8::Value> CanGoToOffset(const v8::Arguments &args);
|
||||||
|
|
|
@ -8,10 +8,12 @@ for prop, func of EventEmitter.prototype
|
||||||
|
|
||||||
# Convient accessors.
|
# Convient accessors.
|
||||||
setupGetterAndSetter = (constructor, name, getter, setter) ->
|
setupGetterAndSetter = (constructor, name, getter, setter) ->
|
||||||
constructor.prototype.__defineGetter__ name, ->
|
if getter?
|
||||||
this[getter].apply(this, arguments)
|
constructor.prototype.__defineGetter__ name, ->
|
||||||
constructor.prototype.__defineSetter__ name, ->
|
this[getter].apply(this, arguments)
|
||||||
this[setter].apply(this, arguments)
|
if setter?
|
||||||
|
constructor.prototype.__defineSetter__ name, ->
|
||||||
|
this[setter].apply(this, arguments)
|
||||||
|
|
||||||
setupGetterAndSetter Window, 'fullscreen', 'isFullscreen', 'setFullscreen'
|
setupGetterAndSetter Window, 'fullscreen', 'isFullscreen', 'setFullscreen'
|
||||||
setupGetterAndSetter Window, 'size', 'getSize', 'setSize'
|
setupGetterAndSetter Window, 'size', 'getSize', 'setSize'
|
||||||
|
@ -22,5 +24,6 @@ setupGetterAndSetter Window, 'alwaysOnTop', 'isAlwaysOnTop', 'setAlwaysOnTop'
|
||||||
setupGetterAndSetter Window, 'position', 'getPosition', 'setPosition'
|
setupGetterAndSetter Window, 'position', 'getPosition', 'setPosition'
|
||||||
setupGetterAndSetter Window, 'title', 'getTitle', 'setTitle'
|
setupGetterAndSetter Window, 'title', 'getTitle', 'setTitle'
|
||||||
setupGetterAndSetter Window, 'kiosk', 'isKiosk', 'setKiosk'
|
setupGetterAndSetter Window, 'kiosk', 'isKiosk', 'setKiosk'
|
||||||
|
setupGetterAndSetter Window, 'url', 'getURL', 'loadURL'
|
||||||
|
|
||||||
module.exports = Window
|
module.exports = Window
|
||||||
|
|
|
@ -5,7 +5,8 @@ var mainWindow = null;
|
||||||
|
|
||||||
atom.browserMainParts.preMainMessageLoopRun = function() {
|
atom.browserMainParts.preMainMessageLoopRun = function() {
|
||||||
mainWindow = new Window({ width: 800, height: 600 });
|
mainWindow = new Window({ width: 800, height: 600 });
|
||||||
mainWindow.loadURL('file://' + __dirname + '/index.html');
|
mainWindow.url = 'file://' + __dirname + '/index.html';
|
||||||
|
|
||||||
mainWindow.on('page-title-updated', function(event, title) {
|
mainWindow.on('page-title-updated', function(event, title) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue