From 4ccb0cccf39e8831608483bf1d9dc50df2647ff6 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Fri, 24 Oct 2014 18:24:12 +0800 Subject: [PATCH] Rename web-view module to web-frame --- atom.gyp | 8 +- atom/browser/api/lib/web-contents.coffee | 4 + atom/common/node_bindings.cc | 2 +- atom/renderer/api/atom_api_web_frame.cc | 81 ++++++++++++++++ ...om_api_web_view.h => atom_api_web_frame.h} | 20 ++-- atom/renderer/api/atom_api_web_view.cc | 92 ------------------- atom/renderer/api/lib/web-frame.coffee | 1 + atom/renderer/api/lib/web-view.coffee | 1 - atom/renderer/lib/guest-view-internal.coffee | 3 + atom/renderer/lib/init.coffee | 2 +- .../lib/{webview.coffee => web-view.coffee} | 4 +- docs/README.md | 2 +- docs/api/{web-view.md => web-frame.md} | 16 ++-- 13 files changed, 116 insertions(+), 120 deletions(-) create mode 100644 atom/renderer/api/atom_api_web_frame.cc rename atom/renderer/api/{atom_api_web_view.h => atom_api_web_frame.h} (65%) delete mode 100644 atom/renderer/api/atom_api_web_view.cc create mode 100644 atom/renderer/api/lib/web-frame.coffee delete mode 100644 atom/renderer/api/lib/web-view.coffee rename atom/renderer/lib/{webview.coffee => web-view.coffee} (99%) rename docs/api/{web-view.md => web-frame.md} (65%) diff --git a/atom.gyp b/atom.gyp index d0eaf3565bc4..8ea0b8e9ab39 100644 --- a/atom.gyp +++ b/atom.gyp @@ -46,10 +46,10 @@ 'atom/renderer/lib/init.coffee', 'atom/renderer/lib/inspector.coffee', 'atom/renderer/lib/override.coffee', - 'atom/renderer/lib/webview.coffee', + 'atom/renderer/lib/web-view.coffee', 'atom/renderer/api/lib/ipc.coffee', 'atom/renderer/api/lib/remote.coffee', - 'atom/renderer/api/lib/web-view.coffee', + 'atom/renderer/api/lib/web-frame.coffee', ], 'lib_sources': [ 'atom/app/atom_content_client.cc', @@ -254,8 +254,8 @@ 'atom/renderer/api/atom_api_renderer_ipc.cc', 'atom/renderer/api/atom_renderer_bindings.cc', '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/api/atom_api_web_frame.cc', + 'atom/renderer/api/atom_api_web_frame.h', 'atom/renderer/atom_render_view_observer.cc', 'atom/renderer/atom_render_view_observer.h', 'atom/renderer/atom_renderer_client.cc', diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 318769eab535..c5f8b99321d0 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -26,6 +26,10 @@ module.exports.wrap = (webContents) -> webContents.getId = -> "#{@getProcessId()}-#{@getRoutingId()}" webContents.equal = (other) -> @getId() is other.getId() + # Set frame name of WebContents. + webContents.setName = (name) -> + @send 'ATOM_SHELL_WEB_CONTENTS_SET_NAME', name + # Tell the rpc server that a render view has been deleted and we need to # release all objects owned by it. webContents.on 'render-view-deleted', (event, processId, routingId) -> diff --git a/atom/common/node_bindings.cc b/atom/common/node_bindings.cc index 9dcba553bdef..8d2902711394 100644 --- a/atom/common/node_bindings.cc +++ b/atom/common/node_bindings.cc @@ -78,7 +78,7 @@ REFERENCE_MODULE(atom_common_screen); REFERENCE_MODULE(atom_common_shell); REFERENCE_MODULE(atom_common_v8_util); REFERENCE_MODULE(atom_renderer_ipc); -REFERENCE_MODULE(atom_renderer_web_view); +REFERENCE_MODULE(atom_renderer_web_frame); #undef REFERENCE_MODULE namespace atom { diff --git a/atom/renderer/api/atom_api_web_frame.cc b/atom/renderer/api/atom_api_web_frame.cc new file mode 100644 index 000000000000..905c68d9bcab --- /dev/null +++ b/atom/renderer/api/atom_api_web_frame.cc @@ -0,0 +1,81 @@ +// 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_frame.h" + +#include "atom/common/native_mate_converters/string16_converter.h" +#include "native_mate/dictionary.h" +#include "native_mate/object_template_builder.h" +#include "third_party/WebKit/public/web/WebDocument.h" +#include "third_party/WebKit/public/web/WebLocalFrame.h" +#include "third_party/WebKit/public/web/WebView.h" + +#include "atom/common/node_includes.h" + +namespace atom { + +namespace api { + +WebFrame::WebFrame() + : web_frame_(blink::WebLocalFrame::frameForCurrentContext()) { +} + +WebFrame::~WebFrame() { +} + +double WebFrame::SetZoomLevel(double level) { + return web_frame_->view()->setZoomLevel(level); +} + +double WebFrame::GetZoomLevel() const { + return web_frame_->view()->zoomLevel(); +} + +double WebFrame::SetZoomFactor(double factor) { + return blink::WebView::zoomLevelToZoomFactor(SetZoomLevel( + blink::WebView::zoomFactorToZoomLevel(factor))); +} + +double WebFrame::GetZoomFactor() const { + return blink::WebView::zoomLevelToZoomFactor(GetZoomLevel()); +} + +v8::Handle WebFrame::RegisterEmbedderCustomElement( + const base::string16& name, v8::Handle options) { + blink::WebExceptionCode c = 0; + return web_frame_->document().registerEmbedderCustomElement(name, options, c); +} + +mate::ObjectTemplateBuilder WebFrame::GetObjectTemplateBuilder( + v8::Isolate* isolate) { + return mate::ObjectTemplateBuilder(isolate) + .SetMethod("setZoomLevel", &WebFrame::SetZoomLevel) + .SetMethod("getZoomLevel", &WebFrame::GetZoomLevel) + .SetMethod("setZoomFactor", &WebFrame::SetZoomFactor) + .SetMethod("getZoomFactor", &WebFrame::GetZoomFactor) + .SetMethod("registerEmbedderCustomElement", + &WebFrame::RegisterEmbedderCustomElement); +} + +// static +mate::Handle WebFrame::Create(v8::Isolate* isolate) { + return CreateHandle(isolate, new WebFrame); +} + +} // namespace api + +} // namespace atom + +namespace { + +void Initialize(v8::Handle exports, v8::Handle unused, + v8::Handle context, void* priv) { + v8::Isolate* isolate = context->GetIsolate(); + mate::Dictionary dict(isolate, exports); + dict.Set("webFrame", atom::api::WebFrame::Create(isolate)); +} + +} // namespace + +NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_renderer_web_frame, Initialize) diff --git a/atom/renderer/api/atom_api_web_view.h b/atom/renderer/api/atom_api_web_frame.h similarity index 65% rename from atom/renderer/api/atom_api_web_view.h rename to atom/renderer/api/atom_api_web_frame.h index bfdd0d51a794..4ac8beb4bb0a 100644 --- a/atom/renderer/api/atom_api_web_view.h +++ b/atom/renderer/api/atom_api_web_frame.h @@ -2,27 +2,27 @@ // 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_ +#ifndef ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_ +#define ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_ #include "native_mate/handle.h" #include "native_mate/wrappable.h" namespace blink { -class WebView; +class WebLocalFrame; } namespace atom { namespace api { -class WebView : public mate::Wrappable { +class WebFrame : public mate::Wrappable { public: - static mate::Handle Create(v8::Isolate* isolate); + static mate::Handle Create(v8::Isolate* isolate); private: - WebView(); - virtual ~WebView(); + WebFrame(); + virtual ~WebFrame(); double SetZoomLevel(double level); double GetZoomLevel() const; @@ -36,13 +36,13 @@ class WebView : public mate::Wrappable { virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate); - blink::WebView* web_view_; + blink::WebLocalFrame* web_frame_; - DISALLOW_COPY_AND_ASSIGN(WebView); + DISALLOW_COPY_AND_ASSIGN(WebFrame); }; } // namespace api } // namespace atom -#endif // ATOM_RENDERER_API_ATOM_API_WEB_VIEW_H_ +#endif // ATOM_RENDERER_API_ATOM_API_WEB_FRAME_H_ diff --git a/atom/renderer/api/atom_api_web_view.cc b/atom/renderer/api/atom_api_web_view.cc deleted file mode 100644 index 9c2e1e4e0d8d..000000000000 --- a/atom/renderer/api/atom_api_web_view.cc +++ /dev/null @@ -1,92 +0,0 @@ -// 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 "atom/common/native_mate_converters/string16_converter.h" -#include "native_mate/dictionary.h" -#include "native_mate/object_template_builder.h" -#include "third_party/WebKit/public/web/WebDocument.h" -#include "third_party/WebKit/public/web/WebLocalFrame.h" -#include "third_party/WebKit/public/web/WebView.h" - -#include "atom/common/node_includes.h" - -namespace atom { - -namespace api { - -namespace { - -blink::WebView* GetCurrentWebView() { - blink::WebLocalFrame* frame = blink::WebLocalFrame::frameForCurrentContext(); - 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); -} - -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()); -} - -v8::Handle WebView::RegisterEmbedderCustomElement( - const base::string16& name, v8::Handle options) { - auto document = blink::WebLocalFrame::frameForCurrentContext()->document(); - blink::WebExceptionCode ec = 0; - return document.registerEmbedderCustomElement(name, options, ec); -} - -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) - .SetMethod("registerEmbedderCustomElement", - &WebView::RegisterEmbedderCustomElement); -} - -// static -mate::Handle WebView::Create(v8::Isolate* isolate) { - return CreateHandle(isolate, new WebView); -} - -} // namespace api - -} // namespace atom - -namespace { - -void Initialize(v8::Handle exports, v8::Handle unused, - v8::Handle context, void* priv) { - v8::Isolate* isolate = context->GetIsolate(); - mate::Dictionary dict(isolate, exports); - dict.Set("webView", atom::api::WebView::Create(isolate)); -} - -} // namespace - -NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_renderer_web_view, Initialize) diff --git a/atom/renderer/api/lib/web-frame.coffee b/atom/renderer/api/lib/web-frame.coffee new file mode 100644 index 000000000000..6525730e86f1 --- /dev/null +++ b/atom/renderer/api/lib/web-frame.coffee @@ -0,0 +1 @@ +module.exports = process.atomBinding('web_frame').webFrame diff --git a/atom/renderer/api/lib/web-view.coffee b/atom/renderer/api/lib/web-view.coffee deleted file mode 100644 index a02a16663abf..000000000000 --- a/atom/renderer/api/lib/web-view.coffee +++ /dev/null @@ -1 +0,0 @@ -module.exports = process.atomBinding('web_view').webView diff --git a/atom/renderer/lib/guest-view-internal.coffee b/atom/renderer/lib/guest-view-internal.coffee index 7fc2de3f2dde..9f3b33dc19d9 100644 --- a/atom/renderer/lib/guest-view-internal.coffee +++ b/atom/renderer/lib/guest-view-internal.coffee @@ -1,7 +1,10 @@ ipc = require 'ipc' +webFrame = require 'web-frame' requestId = 0 +ipc.on 'ATOM_SHELL_WEB_CONTENTS_SET_NAME', (name) -> + module.exports = createGuest: (type, params, callback) -> requestId++ diff --git a/atom/renderer/lib/init.coffee b/atom/renderer/lib/init.coffee index c39d88dd9bdf..cdb38fc2a2e4 100644 --- a/atom/renderer/lib/init.coffee +++ b/atom/renderer/lib/init.coffee @@ -57,4 +57,4 @@ else # Override default web functions. require path.join(__dirname, 'override') # Load webview tag implementation. - require path.join(__dirname, 'webview') + require path.join(__dirname, 'web-view') diff --git a/atom/renderer/lib/webview.coffee b/atom/renderer/lib/web-view.coffee similarity index 99% rename from atom/renderer/lib/webview.coffee rename to atom/renderer/lib/web-view.coffee index 7a7672343525..0063f5c11898 100644 --- a/atom/renderer/lib/webview.coffee +++ b/atom/renderer/lib/web-view.coffee @@ -1,6 +1,6 @@ v8Util = process.atomBinding 'v8_util' guestViewInternal = require './guest-view-internal' -webView = require 'web-view' +webFrame = require 'web-frame' # ID generator. nextId = 0 @@ -487,7 +487,7 @@ registerBrowserPluginElement = -> # Load the plugin immediately. unused = this.nonExistentAttribute - WebView.BrowserPlugin = webView.registerEmbedderCustomElement 'browserplugin', + WebView.BrowserPlugin = webFrame.registerEmbedderCustomElement 'browserplugin', extends: 'object', prototype: proto delete proto.createdCallback diff --git a/docs/README.md b/docs/README.md index d5d3468f760d..deede13c6e66 100644 --- a/docs/README.md +++ b/docs/README.md @@ -33,7 +33,7 @@ Modules for web page: * [ipc (renderer)](api/ipc-renderer.md) * [remote](api/remote.md) -* [web-view](api/web-view.md) +* [web-frame](api/web-frame.md) Modules for both sides: diff --git a/docs/api/web-view.md b/docs/api/web-frame.md similarity index 65% rename from docs/api/web-view.md rename to docs/api/web-frame.md index 672830b12bb3..1bd00e41d207 100644 --- a/docs/api/web-view.md +++ b/docs/api/web-frame.md @@ -1,26 +1,26 @@ -# web-view +# web-frame -The `web-view` module can custom the rendering of current web page. +The `web-frame` module can custom the rendering of current web page. An example of zooming current page to 200%. ```javascript -var webView = require('web-view'); -webView.setZoomFactor(2); +var webFrame = require('web-frame'); +webFrame.setZoomFactor(2); ``` -## webView.setZoomFactor(factor) +## webFrame.setZoomFactor(factor) * `factor` Number - Zoom factor Changes the zoom factor to the specified factor, zoom factor is zoom percent / 100, so 300% = 3.0. -## webView.getZoomFactor() +## webFrame.getZoomFactor() Returns the current zoom factor. -## webView.setZoomLevel(level) +## webFrame.setZoomLevel(level) * `level` Number - Zoom level @@ -28,6 +28,6 @@ Changes the zoom level to the specified level, 0 is "original size", and each increment above or below represents zooming 20% larger or smaller to default limits of 300% and 50% of original size, respectively. -## webView.getZoomLevel() +## webFrame.getZoomLevel() Returns the current zoom level.