Remove devtools APIs from NativeWindow
This commit is contained in:
parent
94d69777fa
commit
05468cc3fa
12 changed files with 118 additions and 128 deletions
|
@ -79,6 +79,10 @@ const int kDefaultHeight = 300;
|
||||||
|
|
||||||
v8::Persistent<v8::ObjectTemplate> template_;
|
v8::Persistent<v8::ObjectTemplate> template_;
|
||||||
|
|
||||||
|
// The wrapWebContents funtion which is implemented in JavaScript
|
||||||
|
using WrapWebContentsCallback = base::Callback<void(v8::Local<v8::Value>)>;
|
||||||
|
WrapWebContentsCallback g_wrap_web_contents;
|
||||||
|
|
||||||
// Get the window that has the |guest| embedded.
|
// Get the window that has the |guest| embedded.
|
||||||
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
NativeWindow* GetWindowFromGuest(const content::WebContents* guest) {
|
||||||
WebViewManager::WebViewInfo info;
|
WebViewManager::WebViewInfo info;
|
||||||
|
@ -530,10 +534,17 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
|
||||||
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
web_contents()->GetMainFrame()->ExecuteJavaScript(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::OpenDevTools() {
|
void WebContents::OpenDevTools(mate::Arguments* args) {
|
||||||
if (!inspectable_web_contents())
|
if (!inspectable_web_contents())
|
||||||
return;
|
return;
|
||||||
inspectable_web_contents()->SetCanDock(false);
|
bool detach = false;
|
||||||
|
if (is_guest()) {
|
||||||
|
detach = true;
|
||||||
|
} else if (args && args->Length() == 1) {
|
||||||
|
mate::Dictionary options;
|
||||||
|
args->GetNext(&options) && options.Get("detach", &detach);
|
||||||
|
}
|
||||||
|
inspectable_web_contents()->SetCanDock(!detach);
|
||||||
inspectable_web_contents()->ShowDevTools();
|
inspectable_web_contents()->ShowDevTools();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -549,10 +560,17 @@ bool WebContents::IsDevToolsOpened() {
|
||||||
return inspectable_web_contents()->IsDevToolsViewShowing();
|
return inspectable_web_contents()->IsDevToolsViewShowing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::ToggleDevTools() {
|
||||||
|
if (IsDevToolsOpened())
|
||||||
|
CloseDevTools();
|
||||||
|
else
|
||||||
|
OpenDevTools(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::InspectElement(int x, int y) {
|
void WebContents::InspectElement(int x, int y) {
|
||||||
if (!inspectable_web_contents())
|
if (!inspectable_web_contents())
|
||||||
return;
|
return;
|
||||||
OpenDevTools();
|
OpenDevTools(nullptr);
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
scoped_refptr<content::DevToolsAgentHost> agent(
|
||||||
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
content::DevToolsAgentHost::GetOrCreateFor(web_contents()));
|
||||||
agent->InspectElement(x, y);
|
agent->InspectElement(x, y);
|
||||||
|
@ -564,7 +582,7 @@ void WebContents::InspectServiceWorker() {
|
||||||
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
||||||
if (agent_host->GetType() ==
|
if (agent_host->GetType() ==
|
||||||
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
||||||
OpenDevTools();
|
OpenDevTools(nullptr);
|
||||||
inspectable_web_contents()->AttachTo(agent_host);
|
inspectable_web_contents()->AttachTo(agent_host);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -741,6 +759,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
.SetMethod("openDevTools", &WebContents::OpenDevTools)
|
||||||
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
|
||||||
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
|
||||||
|
.SetMethod("toggleDevTools", &WebContents::ToggleDevTools)
|
||||||
.SetMethod("inspectElement", &WebContents::InspectElement)
|
.SetMethod("inspectElement", &WebContents::InspectElement)
|
||||||
.SetMethod("undo", &WebContents::Undo)
|
.SetMethod("undo", &WebContents::Undo)
|
||||||
.SetMethod("redo", &WebContents::Redo)
|
.SetMethod("redo", &WebContents::Redo)
|
||||||
|
@ -800,19 +819,33 @@ gfx::Size WebContents::GetDefaultSize() const {
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||||
v8::Isolate* isolate, brightray::InspectableWebContents* web_contents) {
|
v8::Isolate* isolate, brightray::InspectableWebContents* web_contents) {
|
||||||
return mate::CreateHandle(isolate, new WebContents(web_contents));
|
auto handle = mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||||
|
g_wrap_web_contents.Run(handle.ToV8());
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebContents> WebContents::CreateFrom(
|
mate::Handle<WebContents> WebContents::CreateFrom(
|
||||||
v8::Isolate* isolate, content::WebContents* web_contents) {
|
v8::Isolate* isolate, content::WebContents* web_contents) {
|
||||||
return mate::CreateHandle(isolate, new WebContents(web_contents));
|
auto handle = mate::CreateHandle(isolate, new WebContents(web_contents));
|
||||||
|
g_wrap_web_contents.Run(handle.ToV8());
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Handle<WebContents> WebContents::Create(
|
mate::Handle<WebContents> WebContents::Create(
|
||||||
v8::Isolate* isolate, const mate::Dictionary& options) {
|
v8::Isolate* isolate, const mate::Dictionary& options) {
|
||||||
return mate::CreateHandle(isolate, new WebContents(options));
|
auto handle = mate::CreateHandle(isolate, new WebContents(options));
|
||||||
|
g_wrap_web_contents.Run(handle.ToV8());
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SetWrapWebContents(const WrapWebContentsCallback& callback) {
|
||||||
|
g_wrap_web_contents = callback;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearWrapWebContents() {
|
||||||
|
g_wrap_web_contents.Reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
@ -827,6 +860,8 @@ void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
|
||||||
v8::Isolate* isolate = context->GetIsolate();
|
v8::Isolate* isolate = context->GetIsolate();
|
||||||
mate::Dictionary dict(isolate, exports);
|
mate::Dictionary dict(isolate, exports);
|
||||||
dict.SetMethod("create", &atom::api::WebContents::Create);
|
dict.SetMethod("create", &atom::api::WebContents::Create);
|
||||||
|
dict.SetMethod("_setWrapWebContents", &atom::api::SetWrapWebContents);
|
||||||
|
dict.SetMethod("_clearWrapWebContents", &atom::api::ClearWrapWebContents);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -22,6 +22,7 @@ class InspectableWebContents;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
class Arguments;
|
||||||
class Dictionary;
|
class Dictionary;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +79,10 @@ class WebContents : public mate::EventEmitter,
|
||||||
void SetUserAgent(const std::string& user_agent);
|
void SetUserAgent(const std::string& user_agent);
|
||||||
void InsertCSS(const std::string& css);
|
void InsertCSS(const std::string& css);
|
||||||
void ExecuteJavaScript(const base::string16& code);
|
void ExecuteJavaScript(const base::string16& code);
|
||||||
void OpenDevTools();
|
void OpenDevTools(mate::Arguments* args);
|
||||||
void CloseDevTools();
|
void CloseDevTools();
|
||||||
bool IsDevToolsOpened();
|
bool IsDevToolsOpened();
|
||||||
|
void ToggleDevTools();
|
||||||
void InspectElement(int x, int y);
|
void InspectElement(int x, int y);
|
||||||
void InspectServiceWorker();
|
void InspectServiceWorker();
|
||||||
void HasServiceWorker(const base::Callback<void(bool)>&);
|
void HasServiceWorker(const base::Callback<void(bool)>&);
|
||||||
|
|
|
@ -165,6 +165,26 @@ void Window::OnDevToolsFocus() {
|
||||||
Emit("devtools-focused");
|
Emit("devtools-focused");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Window::OnDevToolsOpened() {
|
||||||
|
Emit("devtools-opened");
|
||||||
|
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::Locker locker(isolate);
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
auto handle =
|
||||||
|
WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
||||||
|
devtools_web_contents_.Reset(isolate, handle.ToV8());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Window::OnDevToolsClosed() {
|
||||||
|
Emit("devtools-closed");
|
||||||
|
|
||||||
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
|
v8::Locker locker(isolate);
|
||||||
|
v8::HandleScope handle_scope(isolate);
|
||||||
|
devtools_web_contents_.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
mate::Wrappable* Window::New(v8::Isolate* isolate,
|
||||||
const mate::Dictionary& options) {
|
const mate::Dictionary& options) {
|
||||||
|
@ -356,26 +376,6 @@ bool Window::IsKiosk() {
|
||||||
return window_->IsKiosk();
|
return window_->IsKiosk();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Window::OpenDevTools(bool can_dock) {
|
|
||||||
window_->OpenDevTools(can_dock);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::CloseDevTools() {
|
|
||||||
window_->CloseDevTools();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Window::IsDevToolsOpened() {
|
|
||||||
return window_->IsDevToolsOpened();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::InspectElement(int x, int y) {
|
|
||||||
window_->InspectElement(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::InspectServiceWorker() {
|
|
||||||
window_->InspectServiceWorker();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Window::FocusOnWebView() {
|
void Window::FocusOnWebView() {
|
||||||
window_->FocusOnWebView();
|
window_->FocusOnWebView();
|
||||||
}
|
}
|
||||||
|
@ -472,13 +472,20 @@ bool Window::IsVisibleOnAllWorkspaces() {
|
||||||
return window_->IsVisibleOnAllWorkspaces();
|
return window_->IsVisibleOnAllWorkspaces();
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
|
v8::Local<v8::Value> Window::WebContents(v8::Isolate* isolate) {
|
||||||
return WebContents::CreateFrom(isolate, window_->managed_web_contents());
|
if (web_contents_.IsEmpty()) {
|
||||||
|
auto handle =
|
||||||
|
WebContents::CreateFrom(isolate, window_->managed_web_contents());
|
||||||
|
web_contents_.Reset(isolate, handle.ToV8());
|
||||||
|
}
|
||||||
|
return v8::Local<v8::Value>::New(isolate, web_contents_);
|
||||||
}
|
}
|
||||||
|
|
||||||
mate::Handle<WebContents> Window::GetDevToolsWebContents(
|
v8::Local<v8::Value> Window::DevToolsWebContents(v8::Isolate* isolate) {
|
||||||
v8::Isolate* isolate) const {
|
if (devtools_web_contents_.IsEmpty())
|
||||||
return WebContents::CreateFrom(isolate, window_->GetDevToolsWebContents());
|
return v8::Null(isolate);
|
||||||
|
else
|
||||||
|
return v8::Local<v8::Value>::New(isolate, devtools_web_contents_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
|
@ -529,10 +536,6 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
.SetMethod("getRepresentedFilename", &Window::GetRepresentedFilename)
|
||||||
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
.SetMethod("setDocumentEdited", &Window::SetDocumentEdited)
|
||||||
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
.SetMethod("isDocumentEdited", &Window::IsDocumentEdited)
|
||||||
.SetMethod("_openDevTools", &Window::OpenDevTools)
|
|
||||||
.SetMethod("closeDevTools", &Window::CloseDevTools)
|
|
||||||
.SetMethod("isDevToolsOpened", &Window::IsDevToolsOpened)
|
|
||||||
.SetMethod("_inspectElement", &Window::InspectElement)
|
|
||||||
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
.SetMethod("focusOnWebView", &Window::FocusOnWebView)
|
||||||
.SetMethod("blurWebView", &Window::BlurWebView)
|
.SetMethod("blurWebView", &Window::BlurWebView)
|
||||||
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
.SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
|
||||||
|
@ -553,9 +556,8 @@ void Window::BuildPrototype(v8::Isolate* isolate,
|
||||||
.SetMethod("showDefinitionForSelection",
|
.SetMethod("showDefinitionForSelection",
|
||||||
&Window::ShowDefinitionForSelection)
|
&Window::ShowDefinitionForSelection)
|
||||||
#endif
|
#endif
|
||||||
.SetMethod("_getWebContents", &Window::GetWebContents)
|
.SetProperty("webContents", &Window::WebContents)
|
||||||
.SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents)
|
.SetProperty("devToolsWebContents", &Window::DevToolsWebContents);
|
||||||
.SetMethod("_inspectServiceWorker", &Window::InspectServiceWorker);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace api
|
} // namespace api
|
||||||
|
|
|
@ -78,6 +78,8 @@ class Window : public mate::EventEmitter,
|
||||||
void OnRendererUnresponsive() override;
|
void OnRendererUnresponsive() override;
|
||||||
void OnRendererResponsive() override;
|
void OnRendererResponsive() override;
|
||||||
void OnDevToolsFocus() override;
|
void OnDevToolsFocus() override;
|
||||||
|
void OnDevToolsOpened() override;
|
||||||
|
void OnDevToolsClosed() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// APIs for NativeWindow.
|
// APIs for NativeWindow.
|
||||||
|
@ -121,11 +123,6 @@ class Window : public mate::EventEmitter,
|
||||||
void SetSkipTaskbar(bool skip);
|
void SetSkipTaskbar(bool skip);
|
||||||
void SetKiosk(bool kiosk);
|
void SetKiosk(bool kiosk);
|
||||||
bool IsKiosk();
|
bool IsKiosk();
|
||||||
void OpenDevTools(bool can_dock);
|
|
||||||
void CloseDevTools();
|
|
||||||
bool IsDevToolsOpened();
|
|
||||||
void InspectElement(int x, int y);
|
|
||||||
void InspectServiceWorker();
|
|
||||||
void FocusOnWebView();
|
void FocusOnWebView();
|
||||||
void BlurWebView();
|
void BlurWebView();
|
||||||
bool IsWebViewFocused();
|
bool IsWebViewFocused();
|
||||||
|
@ -151,9 +148,11 @@ class Window : public mate::EventEmitter,
|
||||||
void SetVisibleOnAllWorkspaces(bool visible);
|
void SetVisibleOnAllWorkspaces(bool visible);
|
||||||
bool IsVisibleOnAllWorkspaces();
|
bool IsVisibleOnAllWorkspaces();
|
||||||
|
|
||||||
// APIs for WebContents.
|
v8::Local<v8::Value> WebContents(v8::Isolate* isolate);
|
||||||
mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
|
v8::Local<v8::Value> DevToolsWebContents(v8::Isolate* isolate);
|
||||||
mate::Handle<WebContents> GetDevToolsWebContents(v8::Isolate* isolate) const;
|
|
||||||
|
v8::Global<v8::Value> web_contents_;
|
||||||
|
v8::Global<v8::Value> devtools_web_contents_;
|
||||||
|
|
||||||
scoped_ptr<NativeWindow> window_;
|
scoped_ptr<NativeWindow> window_;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@ EventEmitter = require('events').EventEmitter
|
||||||
IDWeakMap = require 'id-weak-map'
|
IDWeakMap = require 'id-weak-map'
|
||||||
app = require 'app'
|
app = require 'app'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
wrapWebContents = require('web-contents').wrap
|
|
||||||
|
|
||||||
BrowserWindow = process.atomBinding('window').BrowserWindow
|
BrowserWindow = process.atomBinding('window').BrowserWindow
|
||||||
BrowserWindow::__proto__ = EventEmitter.prototype
|
BrowserWindow::__proto__ = EventEmitter.prototype
|
||||||
|
@ -16,10 +15,6 @@ BrowserWindow::_init = ->
|
||||||
menu = app.getApplicationMenu()
|
menu = app.getApplicationMenu()
|
||||||
@setMenu menu if menu?
|
@setMenu menu if menu?
|
||||||
|
|
||||||
@webContents = @getWebContents()
|
|
||||||
@devToolsWebContents = null
|
|
||||||
@webContents.once 'destroyed', => @webContents = null
|
|
||||||
|
|
||||||
# Remember the window ID.
|
# Remember the window ID.
|
||||||
Object.defineProperty this, 'id',
|
Object.defineProperty this, 'id',
|
||||||
value: BrowserWindow.windows.add(this)
|
value: BrowserWindow.windows.add(this)
|
||||||
|
@ -40,35 +35,6 @@ BrowserWindow::_init = ->
|
||||||
@once 'closed', =>
|
@once 'closed', =>
|
||||||
BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
|
BrowserWindow.windows.remove @id if BrowserWindow.windows.has @id
|
||||||
|
|
||||||
BrowserWindow::openDevTools = (options={}) ->
|
|
||||||
options.detach ?= false
|
|
||||||
@_openDevTools !options.detach
|
|
||||||
|
|
||||||
# Force devToolsWebContents to be created.
|
|
||||||
@devToolsWebContents = @getDevToolsWebContents()
|
|
||||||
@devToolsWebContents.once 'destroyed', => @devToolsWebContents = null
|
|
||||||
|
|
||||||
# Emit devtools events.
|
|
||||||
@devToolsWebContents.once 'did-finish-load', => @emit 'devtools-opened'
|
|
||||||
@devToolsWebContents.once 'destroyed', => @emit 'devtools-closed'
|
|
||||||
|
|
||||||
BrowserWindow::toggleDevTools = ->
|
|
||||||
if @isDevToolsOpened() then @closeDevTools() else @openDevTools()
|
|
||||||
|
|
||||||
BrowserWindow::inspectElement = (x, y) ->
|
|
||||||
@openDevTools true
|
|
||||||
@_inspectElement x, y
|
|
||||||
|
|
||||||
BrowserWindow::inspectServiceWorker = ->
|
|
||||||
@openDevTools true
|
|
||||||
@_inspectServiceWorker()
|
|
||||||
|
|
||||||
BrowserWindow::getWebContents = ->
|
|
||||||
wrapWebContents @_getWebContents()
|
|
||||||
|
|
||||||
BrowserWindow::getDevToolsWebContents = ->
|
|
||||||
wrapWebContents @_getDevToolsWebContents()
|
|
||||||
|
|
||||||
BrowserWindow::setMenu = (menu) ->
|
BrowserWindow::setMenu = (menu) ->
|
||||||
throw new TypeError('Invalid menu') unless menu is null or menu?.constructor?.name is 'Menu'
|
throw new TypeError('Invalid menu') unless menu is null or menu?.constructor?.name is 'Menu'
|
||||||
|
|
||||||
|
@ -110,7 +76,12 @@ BrowserWindow::stop = -> @webContents.stop()
|
||||||
BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
|
BrowserWindow::getRoutingId = -> @webContents.getRoutingId()
|
||||||
BrowserWindow::getProcessId = -> @webContents.getProcessId()
|
BrowserWindow::getProcessId = -> @webContents.getProcessId()
|
||||||
BrowserWindow::isCrashed = -> @webContents.isCrashed()
|
BrowserWindow::isCrashed = -> @webContents.isCrashed()
|
||||||
BrowserWindow::executeJavaScriptInDevTools = (code) ->
|
BrowserWindow::executeJavaScriptInDevTools = (code) -> @devToolsWebContents?.executeJavaScript code
|
||||||
@devToolsWebContents.executeJavaScript code
|
BrowserWindow::openDevTools = -> @webContents.openDevTools.apply @webContents, arguments
|
||||||
|
BrowserWindow::closeDevTools = -> @webContents.closeDevTools()
|
||||||
|
BrowserWindow::isDevToolsOpened = -> @webContents.isDevToolsOpened()
|
||||||
|
BrowserWindow::toggleDevTools = -> @webContents.toggleDevTools()
|
||||||
|
BrowserWindow::inspectElement = -> @webContents.inspectElement.apply @webContents, arguments
|
||||||
|
BrowserWindow::inspectServiceWorker = -> @webContents.inspectServiceWorker()
|
||||||
|
|
||||||
module.exports = BrowserWindow
|
module.exports = BrowserWindow
|
||||||
|
|
|
@ -3,9 +3,7 @@ NavigationController = require './navigation-controller'
|
||||||
binding = process.atomBinding 'web_contents'
|
binding = process.atomBinding 'web_contents'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
|
|
||||||
module.exports.wrap = (webContents) ->
|
wrapWebContents = (webContents) ->
|
||||||
return null unless webContents.isAlive()
|
|
||||||
|
|
||||||
# webContents is an EventEmitter.
|
# webContents is an EventEmitter.
|
||||||
webContents.__proto__ = EventEmitter.prototype
|
webContents.__proto__ = EventEmitter.prototype
|
||||||
|
|
||||||
|
@ -62,5 +60,8 @@ module.exports.wrap = (webContents) ->
|
||||||
|
|
||||||
webContents
|
webContents
|
||||||
|
|
||||||
|
binding._setWrapWebContents wrapWebContents
|
||||||
|
process.once 'exit', binding._clearWrapWebContents
|
||||||
|
|
||||||
module.exports.create = (options={}) ->
|
module.exports.create = (options={}) ->
|
||||||
@wrap binding.create(options)
|
binding.create(options)
|
||||||
|
|
|
@ -4,6 +4,9 @@
|
||||||
|
|
||||||
#include "atom/browser/common_web_contents_delegate.h"
|
#include "atom/browser/common_web_contents_delegate.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "atom/browser/atom_javascript_dialog_manager.h"
|
#include "atom/browser/atom_javascript_dialog_manager.h"
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "atom/browser/ui/file_dialog.h"
|
#include "atom/browser/ui/file_dialog.h"
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
#define ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
#define ATOM_BROWSER_COMMON_WEB_CONTENTS_DELEGATE_H_
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "brightray/browser/default_web_contents_delegate.h"
|
#include "brightray/browser/default_web_contents_delegate.h"
|
||||||
#include "brightray/browser/inspectable_web_contents_impl.h"
|
#include "brightray/browser/inspectable_web_contents_impl.h"
|
||||||
|
@ -42,7 +44,7 @@ class CommonWebContentsDelegate
|
||||||
return web_contents_.get();
|
return web_contents_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool is_guest() const { return is_guest_; };
|
bool is_guest() const { return is_guest_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// content::WebContentsDelegate:
|
// content::WebContentsDelegate:
|
||||||
|
|
|
@ -29,14 +29,11 @@
|
||||||
#include "brightray/browser/inspectable_web_contents_view.h"
|
#include "brightray/browser/inspectable_web_contents_view.h"
|
||||||
#include "chrome/browser/printing/print_view_manager_basic.h"
|
#include "chrome/browser/printing/print_view_manager_basic.h"
|
||||||
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
#include "content/browser/renderer_host/render_widget_host_impl.h"
|
||||||
#include "content/public/browser/devtools_agent_host.h"
|
|
||||||
#include "content/public/browser/invalidate_type.h"
|
|
||||||
#include "content/public/browser/navigation_entry.h"
|
#include "content/public/browser/navigation_entry.h"
|
||||||
#include "content/public/browser/notification_details.h"
|
#include "content/public/browser/notification_details.h"
|
||||||
#include "content/public/browser/notification_source.h"
|
#include "content/public/browser/notification_source.h"
|
||||||
#include "content/public/browser/notification_types.h"
|
#include "content/public/browser/notification_types.h"
|
||||||
#include "content/public/browser/plugin_service.h"
|
#include "content/public/browser/plugin_service.h"
|
||||||
#include "content/public/browser/render_frame_host.h"
|
|
||||||
#include "content/public/browser/render_process_host.h"
|
#include "content/public/browser/render_process_host.h"
|
||||||
#include "content/public/browser/render_view_host.h"
|
#include "content/public/browser/render_view_host.h"
|
||||||
#include "content/public/browser/render_widget_host_view.h"
|
#include "content/public/browser/render_widget_host_view.h"
|
||||||
|
@ -289,35 +286,6 @@ bool NativeWindow::HasModalDialog() {
|
||||||
return has_dialog_attached_;
|
return has_dialog_attached_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::OpenDevTools(bool can_dock) {
|
|
||||||
inspectable_web_contents()->SetCanDock(can_dock);
|
|
||||||
inspectable_web_contents()->ShowDevTools();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::CloseDevTools() {
|
|
||||||
inspectable_web_contents()->CloseDevTools();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NativeWindow::IsDevToolsOpened() {
|
|
||||||
return inspectable_web_contents()->IsDevToolsViewShowing();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::InspectElement(int x, int y) {
|
|
||||||
scoped_refptr<content::DevToolsAgentHost> agent(
|
|
||||||
content::DevToolsAgentHost::GetOrCreateFor(GetWebContents()));
|
|
||||||
agent->InspectElement(x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::InspectServiceWorker() {
|
|
||||||
for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) {
|
|
||||||
if (agent_host->GetType() ==
|
|
||||||
content::DevToolsAgentHost::TYPE_SERVICE_WORKER) {
|
|
||||||
inspectable_web_contents()->AttachTo(agent_host);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::FocusOnWebView() {
|
void NativeWindow::FocusOnWebView() {
|
||||||
GetWebContents()->GetRenderViewHost()->Focus();
|
GetWebContents()->GetRenderViewHost()->Focus();
|
||||||
}
|
}
|
||||||
|
@ -733,6 +701,14 @@ void NativeWindow::DevToolsFocused() {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsFocus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindow::DevToolsOpened() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsOpened());
|
||||||
|
}
|
||||||
|
|
||||||
|
void NativeWindow::DevToolsClosed() {
|
||||||
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnDevToolsClosed());
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
|
void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
|
||||||
if (!window_unresposive_closure_.IsCancelled())
|
if (!window_unresposive_closure_.IsCancelled())
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -144,11 +144,6 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
virtual bool IsVisibleOnAllWorkspaces() = 0;
|
||||||
|
|
||||||
virtual bool IsClosed() const { return is_closed_; }
|
virtual bool IsClosed() const { return is_closed_; }
|
||||||
virtual void OpenDevTools(bool can_dock);
|
|
||||||
virtual void CloseDevTools();
|
|
||||||
virtual bool IsDevToolsOpened();
|
|
||||||
virtual void InspectElement(int x, int y);
|
|
||||||
virtual void InspectServiceWorker();
|
|
||||||
|
|
||||||
virtual void FocusOnWebView();
|
virtual void FocusOnWebView();
|
||||||
virtual void BlurWebView();
|
virtual void BlurWebView();
|
||||||
|
@ -273,6 +268,8 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
|
|
||||||
// Implementations of brightray::InspectableWebContentsDelegate.
|
// Implementations of brightray::InspectableWebContentsDelegate.
|
||||||
void DevToolsFocused() override;
|
void DevToolsFocused() override;
|
||||||
|
void DevToolsOpened() override;
|
||||||
|
void DevToolsClosed() override;
|
||||||
|
|
||||||
// Whether window has standard frame.
|
// Whether window has standard frame.
|
||||||
bool has_frame_;
|
bool has_frame_;
|
||||||
|
|
|
@ -55,8 +55,10 @@ class NativeWindowObserver {
|
||||||
virtual void OnWindowEnterHtmlFullScreen() {}
|
virtual void OnWindowEnterHtmlFullScreen() {}
|
||||||
virtual void OnWindowLeaveHtmlFullScreen() {}
|
virtual void OnWindowLeaveHtmlFullScreen() {}
|
||||||
|
|
||||||
// Called when devtools window gets focused.
|
// Redirect devtools events.
|
||||||
virtual void OnDevToolsFocus() {}
|
virtual void OnDevToolsFocus() {}
|
||||||
|
virtual void OnDevToolsOpened() {}
|
||||||
|
virtual void OnDevToolsClosed() {}
|
||||||
|
|
||||||
// Called when renderer is hung.
|
// Called when renderer is hung.
|
||||||
virtual void OnRendererUnresponsive() {}
|
virtual void OnRendererUnresponsive() {}
|
||||||
|
|
2
vendor/brightray
vendored
2
vendor/brightray
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit 190c3dd1629141027f0962d0fab82c58853e7c85
|
Subproject commit 20af087dd3ba01b601f8ad176899610c9479b382
|
Loading…
Reference in a new issue