Add web-view module.
This commit is contained in:
parent
386ef9197c
commit
accfabf569
5 changed files with 117 additions and 0 deletions
3
atom.gyp
3
atom.gyp
|
@ -41,6 +41,7 @@
|
||||||
'atom/renderer/lib/override.coffee',
|
'atom/renderer/lib/override.coffee',
|
||||||
'atom/renderer/api/lib/ipc.coffee',
|
'atom/renderer/api/lib/ipc.coffee',
|
||||||
'atom/renderer/api/lib/remote.coffee',
|
'atom/renderer/api/lib/remote.coffee',
|
||||||
|
'atom/renderer/api/lib/web-view.coffee',
|
||||||
],
|
],
|
||||||
'lib_sources': [
|
'lib_sources': [
|
||||||
'atom/app/atom_main_delegate.cc',
|
'atom/app/atom_main_delegate.cc',
|
||||||
|
@ -219,6 +220,8 @@
|
||||||
'atom/renderer/api/atom_api_renderer_ipc.cc',
|
'atom/renderer/api/atom_api_renderer_ipc.cc',
|
||||||
'atom/renderer/api/atom_renderer_bindings.cc',
|
'atom/renderer/api/atom_renderer_bindings.cc',
|
||||||
'atom/renderer/api/atom_renderer_bindings.h',
|
'atom/renderer/api/atom_renderer_bindings.h',
|
||||||
|
'atom/renderer/api/atom_api_web_view.cc',
|
||||||
|
'atom/renderer/api/atom_api_web_view.h',
|
||||||
'atom/renderer/atom_render_view_observer.cc',
|
'atom/renderer/atom_render_view_observer.cc',
|
||||||
'atom/renderer/atom_render_view_observer.h',
|
'atom/renderer/atom_render_view_observer.h',
|
||||||
'atom/renderer/atom_renderer_client.cc',
|
'atom/renderer/atom_renderer_client.cc',
|
||||||
|
|
|
@ -21,6 +21,7 @@ NODE_EXT_LIST_ITEM(atom_browser_window)
|
||||||
// Module names start with `atom_renderer_` can only be used by renderer
|
// Module names start with `atom_renderer_` can only be used by renderer
|
||||||
// process.
|
// process.
|
||||||
NODE_EXT_LIST_ITEM(atom_renderer_ipc)
|
NODE_EXT_LIST_ITEM(atom_renderer_ipc)
|
||||||
|
NODE_EXT_LIST_ITEM(atom_renderer_web_view)
|
||||||
|
|
||||||
// Module names start with `atom_common_` can be used by both browser and
|
// Module names start with `atom_common_` can be used by both browser and
|
||||||
// renderer processes.
|
// renderer processes.
|
||||||
|
|
69
atom/renderer/api/atom_api_web_view.cc
Normal file
69
atom/renderer/api/atom_api_web_view.cc
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
// 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 {
|
||||||
|
|
||||||
|
WebKit::WebView* GetCurrentWebView() {
|
||||||
|
WebKit::WebFrame* frame = WebKit::WebFrame::frameForCurrentContext();
|
||||||
|
if (!frame)
|
||||||
|
return NULL;
|
||||||
|
return frame->view();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
WebView::WebView() : web_view_(GetCurrentWebView()) {
|
||||||
|
}
|
||||||
|
|
||||||
|
WebView::~WebView() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebView::SetZoomLevel(double level) {
|
||||||
|
web_view_->setZoomLevel(level);
|
||||||
|
}
|
||||||
|
|
||||||
|
double WebView::GetZoomLevel() const {
|
||||||
|
return web_view_->zoomLevel();
|
||||||
|
}
|
||||||
|
|
||||||
|
mate::ObjectTemplateBuilder WebView::GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate) {
|
||||||
|
return mate::ObjectTemplateBuilder(isolate)
|
||||||
|
.SetMethod("setZoomLevel", &WebView::SetZoomLevel)
|
||||||
|
.SetMethod("getZoomLevel", &WebView::GetZoomLevel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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(atom_renderer_web_view, Initialize)
|
43
atom/renderer/api/atom_api_web_view.h
Normal file
43
atom/renderer/api/atom_api_web_view.h
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
#ifndef ATOM_RENDERER_API_ATOM_API_WEB_VIEW_H_
|
||||||
|
#define ATOM_RENDERER_API_ATOM_API_WEB_VIEW_H_
|
||||||
|
|
||||||
|
#include "native_mate/handle.h"
|
||||||
|
#include "native_mate/wrappable.h"
|
||||||
|
|
||||||
|
namespace WebKit {
|
||||||
|
class WebView;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
namespace api {
|
||||||
|
|
||||||
|
class WebView : public mate::Wrappable {
|
||||||
|
public:
|
||||||
|
static mate::Handle<WebView> Create(v8::Isolate* isolate);
|
||||||
|
|
||||||
|
private:
|
||||||
|
WebView();
|
||||||
|
virtual ~WebView();
|
||||||
|
|
||||||
|
void SetZoomLevel(double level);
|
||||||
|
double GetZoomLevel() const;
|
||||||
|
|
||||||
|
// mate::Wrappable:
|
||||||
|
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
|
||||||
|
v8::Isolate* isolate);
|
||||||
|
|
||||||
|
WebKit::WebView* web_view_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(WebView);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace api
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_RENDERER_API_ATOM_API_WEB_VIEW_H_
|
1
atom/renderer/api/lib/web-view.coffee
Normal file
1
atom/renderer/api/lib/web-view.coffee
Normal file
|
@ -0,0 +1 @@
|
||||||
|
module.exports = process.atomBinding('web_view').webView
|
Loading…
Reference in a new issue