Merge pull request #778 from atom/project-infinium-webview-devtools

devtools for webview tags (continue work of #774)
This commit is contained in:
Cheng Zhao 2014-11-03 23:10:09 +08:00
commit a3a21b5b88
7 changed files with 57 additions and 13 deletions

View file

@ -11,6 +11,7 @@
#include "atom/common/native_mate_converters/string16_converter.h" #include "atom/common/native_mate_converters/string16_converter.h"
#include "atom/common/native_mate_converters/value_converter.h" #include "atom/common/native_mate_converters/value_converter.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "brightray/browser/inspectable_web_contents.h"
#include "content/public/browser/render_frame_host.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"
@ -55,9 +56,9 @@ WebContents::WebContents(const mate::Dictionary& options)
if (options.Get("isGuest", &is_guest) && is_guest) if (options.Get("isGuest", &is_guest) && is_guest)
params.guest_delegate = this; params.guest_delegate = this;
storage_.reset(content::WebContents::Create(params)); storage_.reset(brightray::InspectableWebContents::Create(params));
storage_->SetDelegate(this); Observe(storage_->GetWebContents());
Observe(storage_.get()); web_contents()->SetDelegate(this);
} }
WebContents::~WebContents() { WebContents::~WebContents() {
@ -368,6 +369,19 @@ void WebContents::ExecuteJavaScript(const base::string16& code) {
web_contents()->GetMainFrame()->ExecuteJavaScript(code); web_contents()->GetMainFrame()->ExecuteJavaScript(code);
} }
void WebContents::OpenDevTools() {
storage_->SetCanDock(false);
storage_->ShowDevTools();
}
void WebContents::CloseDevTools() {
storage_->CloseDevTools();
}
bool WebContents::IsDevToolsOpened() {
return storage_->IsDevToolsViewShowing();
}
bool WebContents::SendIPCMessage(const base::string16& channel, bool WebContents::SendIPCMessage(const base::string16& channel,
const base::ListValue& args) { const base::ListValue& args) {
return Send(new AtomViewMsg_Message(routing_id(), channel, args)); return Send(new AtomViewMsg_Message(routing_id(), channel, args));
@ -442,6 +456,9 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
.SetMethod("setAutoSize", &WebContents::SetAutoSize) .SetMethod("setAutoSize", &WebContents::SetAutoSize)
.SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency) .SetMethod("setAllowTransparency", &WebContents::SetAllowTransparency)
.SetMethod("isGuest", &WebContents::is_guest) .SetMethod("isGuest", &WebContents::is_guest)
.SetMethod("openDevTools", &WebContents::OpenDevTools)
.SetMethod("closeDevTools", &WebContents::CloseDevTools)
.SetMethod("isDevToolsOpened", &WebContents::IsDevToolsOpened)
.Build()); .Build());
return mate::ObjectTemplateBuilder( return mate::ObjectTemplateBuilder(

View file

@ -8,11 +8,16 @@
#include <string> #include <string>
#include "atom/browser/api/event_emitter.h" #include "atom/browser/api/event_emitter.h"
#include "brightray/browser/default_web_contents_delegate.h"
#include "content/public/browser/browser_plugin_guest_delegate.h" #include "content/public/browser/browser_plugin_guest_delegate.h"
#include "content/public/browser/web_contents_delegate.h" #include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h" #include "content/public/browser/web_contents_observer.h"
#include "native_mate/handle.h" #include "native_mate/handle.h"
namespace brightray {
class InspectableWebContents;
}
namespace mate { namespace mate {
class Dictionary; class Dictionary;
} }
@ -57,6 +62,9 @@ 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 CloseDevTools();
bool IsDevToolsOpened();
bool SendIPCMessage(const base::string16& channel, bool SendIPCMessage(const base::string16& channel,
const base::ListValue& args); const base::ListValue& args);
@ -175,7 +183,7 @@ class WebContents : public mate::EventEmitter,
scoped_ptr<base::DictionaryValue> extra_params_; scoped_ptr<base::DictionaryValue> extra_params_;
// Stores the WebContents that managed by this class. // Stores the WebContents that managed by this class.
scoped_ptr<content::WebContents> storage_; scoped_ptr<brightray::InspectableWebContents> storage_;
// The WebContents that attaches this guest view. // The WebContents that attaches this guest view.
content::WebContents* embedder_web_contents_; content::WebContents* embedder_web_contents_;

View file

@ -1,6 +1,7 @@
path = require 'path' process = global.process
timers = require 'timers' path = require 'path'
Module = require 'module' timers = require 'timers'
Module = require 'module'
process.atomBinding = (name) -> process.atomBinding = (name) ->
try try

View file

@ -1,6 +1,7 @@
path = require 'path' process = global.process
url = require 'url' path = require 'path'
Module = require 'module' url = require 'url'
Module = require 'module'
# Expose information of current process. # Expose information of current process.
process.type = 'renderer' process.type = 'renderer'
@ -83,3 +84,5 @@ else
# global reference after they are done. # global reference after they are done.
process.once 'BIND_DONE', -> process.once 'BIND_DONE', ->
delete global.process delete global.process
delete global.setImmediate
delete global.clearImmediate

View file

@ -517,7 +517,10 @@ registerWebViewElement = ->
"isCrashed" "isCrashed"
"setUserAgent" "setUserAgent"
"executeJavaScript" "executeJavaScript"
"insertCSS" "insertCSS",
"openDevTools",
"closeDevTools",
"isDevToolsOpened",
"send" "send"
] ]

View file

@ -167,7 +167,19 @@ Injects CSS into guest page.
* `code` String * `code` String
Evaluate `code` in guest page. Evaluates `code` in guest page.
### `<webview>`.openDevTools()
Opens a devtools window for guest page.
### `<webview>`.closeDevTools()
Closes the devtools window of guest page.
### `<webview>`.isDevToolsOpened()
Returns whether guest page has a devtools window attached.
### `<webview>`.send(channel[, args...]) ### `<webview>`.send(channel[, args...])

2
vendor/brightray vendored

@ -1 +1 @@
Subproject commit b90f13be24a006c55b7e1c935be492101ac2736c Subproject commit 52b2a6bfac3e5e1527c0dcfba6f5a5d2aa6ad9dd