2013-04-14 07:36:48 +00:00
|
|
|
// 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.
|
|
|
|
|
2014-03-16 00:30:26 +00:00
|
|
|
#include "atom/browser/api/atom_api_window.h"
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "atom/browser/native_window.h"
|
|
|
|
#include "atom/common/native_mate_converters/function_converter.h"
|
|
|
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
|
|
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
|
|
|
#include "atom/common/native_mate_converters/value_converter.h"
|
2013-12-27 07:41:00 +00:00
|
|
|
#include "base/bind.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "base/callback.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
#include "base/process/kill.h"
|
2013-04-18 16:06:10 +00:00
|
|
|
#include "content/public/browser/navigation_entry.h"
|
2013-04-17 12:05:43 +00:00
|
|
|
#include "content/public/browser/web_contents.h"
|
2013-04-23 09:21:34 +00:00
|
|
|
#include "content/public/browser/render_process_host.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "native_mate/constructor.h"
|
|
|
|
#include "native_mate/dictionary.h"
|
2013-04-17 14:49:49 +00:00
|
|
|
#include "ui/gfx/point.h"
|
2014-04-22 15:07:21 +00:00
|
|
|
#include "ui/gfx/rect.h"
|
2013-04-17 14:49:49 +00:00
|
|
|
#include "ui/gfx/size.h"
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2014-04-17 05:45:14 +00:00
|
|
|
#include "atom/common/node_includes.h"
|
2013-12-11 07:48:19 +00:00
|
|
|
|
2013-04-18 07:09:53 +00:00
|
|
|
using content::NavigationController;
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace mate {
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Converter<gfx::Rect> {
|
|
|
|
static bool FromV8(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::Value> val,
|
|
|
|
gfx::Rect* out) {
|
|
|
|
if (!val->IsObject())
|
|
|
|
return false;
|
|
|
|
mate::Dictionary dict(isolate, val->ToObject());
|
|
|
|
int x, y, width, height;
|
|
|
|
if (!dict.Get("x", &x) || !dict.Get("y", &y) ||
|
|
|
|
!dict.Get("width", &width) || !dict.Get("height", &height))
|
|
|
|
return false;
|
|
|
|
*out = gfx::Rect(x, y, width, height);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mate
|
2013-04-29 11:38:18 +00:00
|
|
|
|
2013-04-14 07:36:48 +00:00
|
|
|
namespace atom {
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
namespace api {
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
void OnCapturePageDone(
|
|
|
|
const base::Callback<void(v8::Handle<v8::Value>)>& callback,
|
|
|
|
const std::vector<unsigned char>& data) {
|
|
|
|
v8::Locker locker(node_isolate);
|
|
|
|
v8::HandleScope handle_scope(node_isolate);
|
|
|
|
|
|
|
|
v8::Local<v8::Value> buffer = node::Buffer::New(
|
|
|
|
reinterpret_cast<const char*>(data.data()),
|
|
|
|
data.size());
|
|
|
|
callback.Run(buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
Window::Window(base::DictionaryValue* options)
|
|
|
|
: window_(NativeWindow::Create(options)) {
|
2013-04-17 12:05:43 +00:00
|
|
|
window_->InitFromOptions(options);
|
2013-04-18 15:50:47 +00:00
|
|
|
window_->AddObserver(this);
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Window::~Window() {
|
2013-05-02 10:19:07 +00:00
|
|
|
Emit("destroyed");
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2013-04-18 15:50:47 +00:00
|
|
|
void Window::OnPageTitleUpdated(bool* prevent_default,
|
|
|
|
const std::string& title) {
|
2013-05-01 15:28:01 +00:00
|
|
|
base::ListValue args;
|
|
|
|
args.AppendString(title);
|
2014-04-22 15:07:21 +00:00
|
|
|
*prevent_default = Emit("page-title-updated", args);
|
2013-05-01 15:28:01 +00:00
|
|
|
}
|
|
|
|
|
2013-08-29 03:47:07 +00:00
|
|
|
void Window::OnLoadingStateChanged(bool is_loading) {
|
|
|
|
base::ListValue args;
|
|
|
|
args.AppendBoolean(is_loading);
|
2014-04-22 15:07:21 +00:00
|
|
|
Emit("loading-state-changed", args);
|
2013-08-29 03:47:07 +00:00
|
|
|
}
|
|
|
|
|
2013-05-01 15:28:01 +00:00
|
|
|
void Window::WillCloseWindow(bool* prevent_default) {
|
2013-05-02 10:19:07 +00:00
|
|
|
*prevent_default = Emit("close");
|
2013-05-01 15:28:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnWindowClosed() {
|
2013-05-02 10:19:07 +00:00
|
|
|
Emit("closed");
|
2014-04-23 00:50:26 +00:00
|
|
|
|
2014-04-23 01:25:04 +00:00
|
|
|
if (window_) {
|
|
|
|
window_->RemoveObserver(this);
|
|
|
|
|
|
|
|
// Free memory when native window is closed, the delete is delayed so other
|
|
|
|
// observers would not get a invalid pointer of NativeWindow.
|
|
|
|
base::MessageLoop::current()->DeleteSoon(FROM_HERE, window_.release());
|
|
|
|
}
|
2013-04-18 15:50:47 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 09:58:39 +00:00
|
|
|
void Window::OnWindowBlur() {
|
|
|
|
Emit("blur");
|
|
|
|
}
|
|
|
|
|
2013-06-06 11:45:48 +00:00
|
|
|
void Window::OnRendererUnresponsive() {
|
|
|
|
Emit("unresponsive");
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::OnRendererResponsive() {
|
|
|
|
Emit("responsive");
|
|
|
|
}
|
|
|
|
|
2013-12-06 07:53:40 +00:00
|
|
|
void Window::OnRenderViewDeleted(int process_id, int routing_id) {
|
|
|
|
base::ListValue args;
|
|
|
|
args.AppendInteger(process_id);
|
|
|
|
args.AppendInteger(routing_id);
|
2014-04-22 15:07:21 +00:00
|
|
|
Emit("render-view-deleted", args);
|
2013-12-06 06:44:25 +00:00
|
|
|
}
|
|
|
|
|
2013-06-10 12:50:25 +00:00
|
|
|
void Window::OnRendererCrashed() {
|
|
|
|
Emit("crashed");
|
|
|
|
}
|
|
|
|
|
2013-04-15 16:25:08 +00:00
|
|
|
// static
|
2014-04-22 15:07:21 +00:00
|
|
|
mate::Wrappable* Window::New(mate::Arguments* args,
|
|
|
|
const base::DictionaryValue& options) {
|
|
|
|
scoped_ptr<base::DictionaryValue> copied_options(options.DeepCopy());
|
|
|
|
Window* window = new Window(copied_options.get());
|
|
|
|
window->Wrap(args->isolate(), args->GetThis());
|
2013-04-15 16:25:08 +00:00
|
|
|
|
2013-10-05 13:05:59 +00:00
|
|
|
// Give js code a chance to do initialization.
|
2014-04-22 15:07:21 +00:00
|
|
|
node::MakeCallback(args->GetThis(), "_init", 0, NULL);
|
2013-04-17 14:49:49 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
return window;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Destroy() {
|
|
|
|
base::KillProcess(window_->GetRenderProcessHandle(), 0, false);
|
|
|
|
window_->CloseImmediately();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Close() {
|
|
|
|
window_->Close();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Focus() {
|
|
|
|
window_->Focus(true);
|
2013-05-16 14:56:52 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsFocused() {
|
|
|
|
return window_->IsFocused();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Show() {
|
|
|
|
window_->Show();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Hide() {
|
|
|
|
window_->Hide();
|
2013-10-03 00:27:59 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsVisible() {
|
|
|
|
return window_->IsVisible();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Maximize() {
|
|
|
|
window_->Maximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Unmaximize() {
|
|
|
|
window_->Unmaximize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Minimize() {
|
|
|
|
window_->Minimize();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Restore() {
|
|
|
|
window_->Restore();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetFullscreen(bool fullscreen) {
|
|
|
|
window_->SetFullscreen(fullscreen);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsFullscreen() {
|
|
|
|
return window_->IsFullscreen();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetSize(int width, int height) {
|
|
|
|
window_->SetSize(gfx::Size(width, height));
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetMinimumSize(int width, int height) {
|
|
|
|
window_->SetMinimumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetMinimumSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMinimumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetMaximumSize(int width, int height) {
|
|
|
|
window_->SetMaximumSize(gfx::Size(width, height));
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetMaximumSize() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Size size = window_->GetMaximumSize();
|
|
|
|
result[0] = size.width();
|
|
|
|
result[1] = size.height();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetResizable(bool resizable) {
|
|
|
|
window_->SetResizable(resizable);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsResizable() {
|
|
|
|
return window_->IsResizable();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetAlwaysOnTop(bool top) {
|
|
|
|
window_->SetAlwaysOnTop(top);
|
2013-04-18 07:38:04 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsAlwaysOnTop() {
|
|
|
|
return window_->IsAlwaysOnTop();
|
2013-05-10 12:34:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Center() {
|
|
|
|
window_->Center();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetPosition(int x, int y) {
|
|
|
|
window_->SetPosition(gfx::Point(x, y));
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::vector<int> Window::GetPosition() {
|
|
|
|
std::vector<int> result(2);
|
|
|
|
gfx::Point pos = window_->GetPosition();
|
|
|
|
result[0] = pos.x();
|
|
|
|
result[1] = pos.y();
|
|
|
|
return result;
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetTitle(const std::string& title) {
|
|
|
|
window_->SetTitle(title);
|
2013-04-18 06:30:05 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
std::string Window::GetTitle() {
|
|
|
|
return window_->GetTitle();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::FlashFrame(bool flash) {
|
|
|
|
window_->FlashFrame(flash);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::SetKiosk(bool kiosk) {
|
|
|
|
window_->SetKiosk(kiosk);
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsKiosk() {
|
|
|
|
return window_->IsKiosk();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::OpenDevTools() {
|
|
|
|
window_->OpenDevTools();
|
2013-04-17 14:49:49 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::CloseDevTools() {
|
|
|
|
window_->CloseDevTools();
|
2013-11-05 02:32:45 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsDevToolsOpened() {
|
|
|
|
return window_->IsDevToolsOpened();
|
2013-07-18 11:21:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::InspectElement(int x, int y) {
|
|
|
|
window_->InspectElement(x, y);
|
2014-02-24 04:08:33 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::DebugDevTools() {
|
|
|
|
if (window_->IsDevToolsOpened())
|
|
|
|
NativeWindow::Debug(window_->GetDevToolsWebContents());
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::FocusOnWebView() {
|
|
|
|
window_->FocusOnWebView();
|
2013-05-24 09:51:15 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::BlurWebView() {
|
|
|
|
window_->BlurWebView();
|
2013-08-16 04:56:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsWebViewFocused() {
|
|
|
|
return window_->IsWebViewFocused();
|
|
|
|
}
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::CapturePage(mate::Arguments* args) {
|
2013-11-22 06:23:19 +00:00
|
|
|
gfx::Rect rect;
|
2014-04-22 15:07:21 +00:00
|
|
|
base::Callback<void(v8::Handle<v8::Value>)> callback;
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-04-23 01:09:28 +00:00
|
|
|
if (!(args->Length() == 1 && args->GetNext(&callback)) ||
|
|
|
|
!(args->Length() == 2 && args->GetNext(&rect)
|
|
|
|
&& args->GetNext(&callback))) {
|
2014-04-22 15:07:21 +00:00
|
|
|
args->ThrowError();
|
|
|
|
return;
|
|
|
|
}
|
2013-11-22 06:23:19 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
window_->CapturePage(rect, base::Bind(&OnCapturePageDone, callback));
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
string16 Window::GetPageTitle() {
|
|
|
|
return window_->GetWebContents()->GetTitle();
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsLoading() {
|
|
|
|
return window_->GetWebContents()->IsLoading();
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsWaitingForResponse() {
|
|
|
|
return window_->GetWebContents()->IsWaitingForResponse();
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::Stop() {
|
|
|
|
window_->GetWebContents()->Stop();
|
2013-04-23 09:21:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
int Window::GetRoutingID() {
|
|
|
|
return window_->GetWebContents()->GetRoutingID();
|
2013-04-23 09:21:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
int Window::GetProcessID() {
|
|
|
|
return window_->GetWebContents()->GetRenderProcessHost()->GetID();
|
2013-06-10 12:50:25 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
bool Window::IsCrashed() {
|
|
|
|
return window_->GetWebContents()->IsCrashed();
|
2014-04-04 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
mate::Dictionary Window::GetDevTools(v8::Isolate* isolate) {
|
|
|
|
content::WebContents* web_contents = window_->GetDevToolsWebContents();
|
|
|
|
mate::Dictionary dict(isolate);
|
|
|
|
dict.Set("processId", web_contents->GetRenderProcessHost()->GetID());
|
|
|
|
dict.Set("routingId", web_contents->GetRoutingID());
|
|
|
|
return dict;
|
2014-04-08 04:50:12 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::ExecuteJavaScriptInDevTools(const std::string& code) {
|
|
|
|
window_->ExecuteJavaScriptInDevTools(code);
|
|
|
|
}
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Window::LoadURL(const GURL& url) {
|
|
|
|
NavigationController& controller = window_->GetWebContents()->GetController();
|
2013-12-05 02:08:11 +00:00
|
|
|
|
|
|
|
content::NavigationController::LoadURLParams params(url);
|
|
|
|
params.transition_type = content::PAGE_TRANSITION_TYPED;
|
|
|
|
params.override_user_agent = content::NavigationController::UA_OVERRIDE_TRUE;
|
|
|
|
controller.LoadURLWithParams(params);
|
2013-04-18 07:09:53 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
GURL Window::GetURL() {
|
|
|
|
NavigationController& controller = window_->GetWebContents()->GetController();
|
|
|
|
if (!controller.GetActiveEntry())
|
|
|
|
return GURL();
|
|
|
|
return controller.GetActiveEntry()->GetVirtualURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::CanGoBack() {
|
|
|
|
return window_->GetWebContents()->GetController().CanGoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::CanGoForward() {
|
|
|
|
return window_->GetWebContents()->GetController().CanGoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Window::CanGoToOffset(int offset) {
|
|
|
|
return window_->GetWebContents()->GetController().CanGoToOffset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::GoBack() {
|
|
|
|
window_->GetWebContents()->GetController().GoBack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::GoForward() {
|
|
|
|
window_->GetWebContents()->GetController().GoForward();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::GoToIndex(int index) {
|
|
|
|
window_->GetWebContents()->GetController().GoToIndex(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::GoToOffset(int offset) {
|
|
|
|
window_->GetWebContents()->GetController().GoToOffset(offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::Reload() {
|
|
|
|
window_->GetWebContents()->GetController().Reload(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Window::ReloadIgnoringCache() {
|
|
|
|
window_->GetWebContents()->GetController().ReloadIgnoringCache(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
// static
|
|
|
|
void Window::BuildPrototype(v8::Isolate* isolate,
|
|
|
|
v8::Handle<v8::ObjectTemplate> prototype) {
|
|
|
|
mate::ObjectTemplateBuilder(isolate, prototype)
|
|
|
|
.SetMethod("destroy", &Window::Destroy)
|
|
|
|
.SetMethod("close", &Window::Close)
|
|
|
|
.SetMethod("focus", &Window::Focus)
|
|
|
|
.SetMethod("isFocused", &Window::IsFocused)
|
|
|
|
.SetMethod("show", &Window::Show)
|
|
|
|
.SetMethod("hide", &Window::Hide)
|
|
|
|
.SetMethod("isVisible", &Window::IsVisible)
|
|
|
|
.SetMethod("maximize", &Window::Maximize)
|
|
|
|
.SetMethod("unmaximize", &Window::Unmaximize)
|
|
|
|
.SetMethod("minimize", &Window::Minimize)
|
|
|
|
.SetMethod("restore", &Window::Restore)
|
|
|
|
.SetMethod("setFullScreen", &Window::SetFullscreen)
|
|
|
|
.SetMethod("isFullScreen", &Window::IsFullscreen)
|
|
|
|
.SetMethod("getSize", &Window::GetSize)
|
|
|
|
.SetMethod("setSize", &Window::SetSize)
|
|
|
|
.SetMethod("setMinimumSize", &Window::SetMinimumSize)
|
|
|
|
.SetMethod("getMinimumSize", &Window::GetMinimumSize)
|
|
|
|
.SetMethod("setMaximumSize", &Window::SetMaximumSize)
|
|
|
|
.SetMethod("getMaximumSize", &Window::GetMaximumSize)
|
|
|
|
.SetMethod("setResizable", &Window::SetResizable)
|
|
|
|
.SetMethod("isResizable", &Window::IsResizable)
|
|
|
|
.SetMethod("setAlwaysOnTop", &Window::SetAlwaysOnTop)
|
|
|
|
.SetMethod("isAlwaysOnTop", &Window::IsAlwaysOnTop)
|
|
|
|
.SetMethod("center", &Window::Center)
|
|
|
|
.SetMethod("setPosition", &Window::SetPosition)
|
|
|
|
.SetMethod("getPosition", &Window::GetPosition)
|
|
|
|
.SetMethod("setTitle", &Window::SetTitle)
|
|
|
|
.SetMethod("getTitle", &Window::GetTitle)
|
|
|
|
.SetMethod("flashFrame", &Window::FlashFrame)
|
|
|
|
.SetMethod("setKiosk", &Window::SetKiosk)
|
|
|
|
.SetMethod("isKiosk", &Window::IsKiosk)
|
|
|
|
.SetMethod("openDevTools", &Window::OpenDevTools)
|
|
|
|
.SetMethod("closeDevTools", &Window::CloseDevTools)
|
|
|
|
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
|
|
|
|
.SetMethod("inspectElement", &Window::InspectElement)
|
|
|
|
.SetMethod("debugDevTools", &Window::DebugDevTools)
|
|
|
|
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
|
|
|
.SetMethod("blurWebView", &Window::BlurWebView)
|
|
|
|
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
|
|
|
.SetMethod("capturePage", &Window::CapturePage)
|
|
|
|
.SetMethod("getPageTitle", &Window::GetPageTitle)
|
|
|
|
.SetMethod("isLoading", &Window::IsLoading)
|
|
|
|
.SetMethod("isWaitingForResponse", &Window::IsWaitingForResponse)
|
|
|
|
.SetMethod("stop", &Window::Stop)
|
|
|
|
.SetMethod("getRoutingId", &Window::GetRoutingID)
|
|
|
|
.SetMethod("getProcessId", &Window::GetProcessID)
|
|
|
|
.SetMethod("isCrashed", &Window::IsCrashed)
|
|
|
|
.SetMethod("getDevTools", &Window::GetDevTools)
|
|
|
|
.SetMethod("executeJavaScriptInDevTools",
|
|
|
|
&Window::ExecuteJavaScriptInDevTools)
|
|
|
|
.SetMethod("loadUrl", &Window::LoadURL)
|
|
|
|
.SetMethod("getUrl", &Window::GetURL)
|
|
|
|
.SetMethod("canGoBack", &Window::CanGoBack)
|
|
|
|
.SetMethod("canGoForward", &Window::CanGoForward)
|
|
|
|
.SetMethod("canGoToOffset", &Window::CanGoToOffset)
|
|
|
|
.SetMethod("goBack", &Window::GoBack)
|
|
|
|
.SetMethod("goForward", &Window::GoForward)
|
|
|
|
.SetMethod("goToIndex", &Window::GoToIndex)
|
|
|
|
.SetMethod("goToOffset", &Window::GoToOffset)
|
|
|
|
.SetMethod("reload", &Window::Reload)
|
|
|
|
.SetMethod("reloadIgnoringCache", &Window::ReloadIgnoringCache);
|
2013-04-18 16:06:10 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace api
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace atom
|
2013-04-18 07:09:53 +00:00
|
|
|
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
namespace {
|
2013-04-18 07:09:53 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
void Initialize(v8::Handle<v8::Object> exports) {
|
|
|
|
using atom::api::Window;
|
|
|
|
v8::Local<v8::Function> constructor = mate::CreateConstructor<Window>(
|
|
|
|
node_isolate, "BrowserWindow", base::Bind(&Window::New));
|
|
|
|
mate::Dictionary dict(v8::Isolate::GetCurrent(), exports);
|
|
|
|
dict.Set("BrowserWindow", static_cast<v8::Handle<v8::Value>>(constructor));
|
2013-04-15 16:25:08 +00:00
|
|
|
}
|
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
} // namespace
|
2013-04-14 07:36:48 +00:00
|
|
|
|
2014-04-22 15:07:21 +00:00
|
|
|
NODE_MODULE(atom_browser_window, Initialize)
|