diff --git a/browser/api/atom_api_window.cc b/browser/api/atom_api_window.cc index ca5b73fecc2c..1ac41dde8066 100644 --- a/browser/api/atom_api_window.cc +++ b/browser/api/atom_api_window.cc @@ -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 Window::LoadURL(const v8::Arguments &args) { return v8::Undefined(); } +// static +v8::Handle Window::GetURL(const v8::Arguments &args) { + Window* self = ObjectWrap::Unwrap(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 Window::CanGoBack(const v8::Arguments &args) { Window* self = ObjectWrap::Unwrap(args.This()); @@ -565,6 +579,7 @@ void Window::Initialize(v8::Handle 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); diff --git a/browser/api/atom_api_window.h b/browser/api/atom_api_window.h index 91c707eee3b5..4fc32a9fdb4f 100644 --- a/browser/api/atom_api_window.h +++ b/browser/api/atom_api_window.h @@ -79,6 +79,7 @@ class Window : public EventEmitter, // APIs for NavigationController. static v8::Handle LoadURL(const v8::Arguments &args); + static v8::Handle GetURL(const v8::Arguments &args); static v8::Handle CanGoBack(const v8::Arguments &args); static v8::Handle CanGoForward(const v8::Arguments &args); static v8::Handle CanGoToOffset(const v8::Arguments &args); diff --git a/browser/api/lib/window.coffee b/browser/api/lib/window.coffee index c372f491b6ac..c8f2bd5b5e7f 100644 --- a/browser/api/lib/window.coffee +++ b/browser/api/lib/window.coffee @@ -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 diff --git a/browser/default_app/main.js b/browser/default_app/main.js index 65fcb1549f39..f0fd53cca7a6 100644 --- a/browser/default_app/main.js +++ b/browser/default_app/main.js @@ -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();