add open devtools api to webview tag

This commit is contained in:
gray 2014-11-02 06:34:22 -08:00
parent 5e99c8f280
commit 368d23ef5b
3 changed files with 47 additions and 2 deletions

View file

@ -11,20 +11,32 @@
#include "content/public/browser/browser_plugin_guest_delegate.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_observer.h"
#include "brightray/browser/default_web_contents_delegate.h"
#include "brightray/browser/inspectable_web_contents_delegate.h"
#include "brightray/browser/inspectable_web_contents_impl.h"
#include "native_mate/handle.h"
namespace mate {
class Dictionary;
}
namespace brightray
{
class InspectableWebContents;
class InspectableWebContentsImpl;
}
namespace atom {
class AtomJavaScriptDialogManager;
namespace api {
class WebContents : public mate::EventEmitter,
public content::BrowserPluginGuestDelegate,
public content::WebContentsDelegate,
public content::WebContentsObserver {
// public brightray::InspectableWebContentsDelegate {
public:
// Create from an existing WebContents.
static mate::Handle<WebContents> CreateFrom(
@ -57,6 +69,7 @@ class WebContents : public mate::EventEmitter,
void SetUserAgent(const std::string& user_agent);
void InsertCSS(const std::string& css);
void ExecuteJavaScript(const base::string16& code);
void OpenDevTools();
bool SendIPCMessage(const base::string16& channel,
const base::ListValue& args);
@ -83,6 +96,18 @@ class WebContents : public mate::EventEmitter,
explicit WebContents(const mate::Dictionary& options);
~WebContents();
brightray::InspectableWebContentsImpl* inspectable_web_contents() const {
return static_cast<brightray::InspectableWebContentsImpl*>(
inspectable_web_contents_.get());
}
// Devtools
/* void DevToolsSaveToFile(const std::string& url,
const std::string& content,
bool save_as) override;
void DevToolsAppendToFile(const std::string& url,
const std::string& content) override; */
// mate::Wrappable:
virtual mate::ObjectTemplateBuilder GetObjectTemplateBuilder(
v8::Isolate* isolate) override;
@ -180,6 +205,13 @@ class WebContents : public mate::EventEmitter,
// The WebContents that attaches this guest view.
content::WebContents* embedder_web_contents_;
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
// Notice that inspectable_web_contents_ must be placed after dialog_manager_,
// so we can make sure inspectable_web_contents_ is destroyed before
// dialog_manager_, otherwise a crash would happen.
scoped_ptr<brightray::InspectableWebContents> inspectable_web_contents_;
// The size of the container element.
gfx::Size element_size_;