electron/atom/renderer/api/atom_api_web_view.cc

81 lines
2 KiB
C++
Raw Normal View History

2014-06-16 06:27:57 +00:00
// Copyright (c) 2014 GitHub, Inc. All rights reserved.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "atom/renderer/api/atom_api_web_view.h"
#include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h"
#include "third_party/WebKit/public/web/WebFrame.h"
#include "third_party/WebKit/public/web/WebView.h"
#include "atom/common/node_includes.h"
namespace atom {
namespace api {
namespace {
blink::WebView* GetCurrentWebView() {
blink::WebFrame* frame = blink::WebFrame::frameForCurrentContext();
2014-06-16 06:27:57 +00:00
if (!frame)
return NULL;
return frame->view();
}
} // namespace
WebView::WebView() : web_view_(GetCurrentWebView()) {
}
WebView::~WebView() {
}
double WebView::SetZoomLevel(double level) {
return web_view_->setZoomLevel(level);
2014-06-16 06:27:57 +00:00
}
double WebView::GetZoomLevel() const {
return web_view_->zoomLevel();
}
double WebView::SetZoomFactor(double factor) {
return blink::WebView::zoomLevelToZoomFactor(SetZoomLevel(
blink::WebView::zoomFactorToZoomLevel(factor)));
}
double WebView::GetZoomFactor() const {
return blink::WebView::zoomLevelToZoomFactor(GetZoomLevel());
}
2014-06-16 06:27:57 +00:00
mate::ObjectTemplateBuilder WebView::GetObjectTemplateBuilder(
v8::Isolate* isolate) {
return mate::ObjectTemplateBuilder(isolate)
.SetMethod("setZoomLevel", &WebView::SetZoomLevel)
.SetMethod("getZoomLevel", &WebView::GetZoomLevel)
.SetMethod("setZoomFactor", &WebView::SetZoomFactor)
.SetMethod("getZoomFactor", &WebView::GetZoomFactor);
2014-06-16 06:27:57 +00:00
}
// static
mate::Handle<WebView> WebView::Create(v8::Isolate* isolate) {
return CreateHandle(isolate, new WebView);
}
} // namespace api
} // namespace atom
namespace {
void Initialize(v8::Handle<v8::Object> exports) {
v8::Isolate* isolate = v8::Isolate::GetCurrent();
mate::Dictionary dict(isolate, exports);
dict.Set("webView", atom::api::WebView::Create(isolate));
}
} // namespace
NODE_MODULE_X(atom_renderer_web_view, Initialize, NULL, NM_F_BUILTIN)