Add Window.url API.

This commit is contained in:
Cheng Zhao 2013-04-19 00:06:10 +08:00
parent d3e4db7ba3
commit 53dd742632
4 changed files with 25 additions and 5 deletions

View file

@ -8,6 +8,7 @@
#include "browser/atom_browser_context.h"
#include "browser/native_window.h"
#include "common/v8_value_converter_impl.h"
#include "content/public/browser/navigation_entry.h"
#include "content/public/browser/web_contents.h"
#include "ui/gfx/point.h"
#include "ui/gfx/rect.h"
@ -413,6 +414,19 @@ v8::Handle<v8::Value> Window::LoadURL(const v8::Arguments &args) {
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
v8::Handle<v8::Value> Window::CanGoBack(const v8::Arguments &args) {
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, "loadURL", LoadURL);
NODE_SET_PROTOTYPE_METHOD(t, "getURL", GetURL);
NODE_SET_PROTOTYPE_METHOD(t, "canGoBack", CanGoBack);
NODE_SET_PROTOTYPE_METHOD(t, "canGoForward", CanGoForward);
NODE_SET_PROTOTYPE_METHOD(t, "canGoToOffset", CanGoToOffset);

View file

@ -79,6 +79,7 @@ class Window : public EventEmitter,
// APIs for NavigationController.
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> CanGoForward(const v8::Arguments &args);
static v8::Handle<v8::Value> CanGoToOffset(const v8::Arguments &args);

View file

@ -8,10 +8,12 @@ for prop, func of EventEmitter.prototype
# Convient accessors.
setupGetterAndSetter = (constructor, name, getter, setter) ->
constructor.prototype.__defineGetter__ name, ->
this[getter].apply(this, arguments)
constructor.prototype.__defineSetter__ name, ->
this[setter].apply(this, arguments)
if getter?
constructor.prototype.__defineGetter__ name, ->
this[getter].apply(this, arguments)
if setter?
constructor.prototype.__defineSetter__ name, ->
this[setter].apply(this, arguments)
setupGetterAndSetter Window, 'fullscreen', 'isFullscreen', 'setFullscreen'
setupGetterAndSetter Window, 'size', 'getSize', 'setSize'
@ -22,5 +24,6 @@ setupGetterAndSetter Window, 'alwaysOnTop', 'isAlwaysOnTop', 'setAlwaysOnTop'
setupGetterAndSetter Window, 'position', 'getPosition', 'setPosition'
setupGetterAndSetter Window, 'title', 'getTitle', 'setTitle'
setupGetterAndSetter Window, 'kiosk', 'isKiosk', 'setKiosk'
setupGetterAndSetter Window, 'url', 'getURL', 'loadURL'
module.exports = Window

View file

@ -5,7 +5,8 @@ var mainWindow = null;
atom.browserMainParts.preMainMessageLoopRun = function() {
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) {
event.preventDefault();