Add API to execute javascript in devtools.
This commit is contained in:
parent
a50d3bde5c
commit
d7a54cf3a6
4 changed files with 23 additions and 4 deletions
|
@ -516,6 +516,18 @@ void Window::GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
|||
args.GetReturnValue().Set(devtools);
|
||||
}
|
||||
|
||||
// static
|
||||
void Window::ExecuteJavaScriptInDevTools(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
||||
std::string code;
|
||||
if (!FromV8Arguments(args, &code))
|
||||
return node::ThrowTypeError("Bad argument");
|
||||
|
||||
self->window_->ExecuteJavaScriptInDevTools(code);
|
||||
}
|
||||
|
||||
// static
|
||||
void Window::LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args) {
|
||||
UNWRAP_WINDOW_AND_CHECK;
|
||||
|
@ -700,6 +712,8 @@ void Window::Initialize(v8::Handle<v8::Object> target) {
|
|||
NODE_SET_PROTOTYPE_METHOD(t, "isCrashed", IsCrashed);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "getDevTools", GetDevTools);
|
||||
NODE_SET_PROTOTYPE_METHOD(
|
||||
t, "executeJavaScriptInDevTools", ExecuteJavaScriptInDevTools);
|
||||
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "loadUrl", LoadURL);
|
||||
NODE_SET_PROTOTYPE_METHOD(t, "getUrl", GetURL);
|
||||
|
|
|
@ -105,6 +105,8 @@ class Window : public EventEmitter,
|
|||
|
||||
// APIs for devtools.
|
||||
static void GetDevTools(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
static void ExecuteJavaScriptInDevTools(
|
||||
const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
||||
// APIs for NavigationController.
|
||||
static void LoadURL(const v8::FunctionCallbackInfo<v8::Value>& args);
|
||||
|
|
|
@ -225,6 +225,11 @@ void NativeWindow::InspectElement(int x, int y) {
|
|||
agent->InspectElement(x, y);
|
||||
}
|
||||
|
||||
void NativeWindow::ExecuteJavaScriptInDevTools(const std::string& script) {
|
||||
GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
|
||||
string16(), base::UTF8ToUTF16(script));
|
||||
}
|
||||
|
||||
void NativeWindow::FocusOnWebView() {
|
||||
GetWebContents()->GetRenderViewHost()->Focus();
|
||||
}
|
||||
|
@ -612,10 +617,7 @@ void NativeWindow::CallDevToolsFunction(const std::string& function_name,
|
|||
}
|
||||
}
|
||||
}
|
||||
base::string16 javascript =
|
||||
base::ASCIIToUTF16(function_name + "(" + params + ");");
|
||||
GetDevToolsWebContents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame(
|
||||
string16(), javascript);
|
||||
ExecuteJavaScriptInDevTools(function_name + "(" + params + ");");
|
||||
}
|
||||
|
||||
void NativeWindow::OnRendererMessage(const string16& channel,
|
||||
|
|
|
@ -136,6 +136,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
|
|||
virtual void CloseDevTools();
|
||||
virtual bool IsDevToolsOpened();
|
||||
virtual void InspectElement(int x, int y);
|
||||
virtual void ExecuteJavaScriptInDevTools(const std::string& script);
|
||||
|
||||
virtual void FocusOnWebView();
|
||||
virtual void BlurWebView();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue