Skip to content

Commit 08094e4

Browse files
committed
Window.eval() implementation
Conflicts: src/api/window_bindings.cc
1 parent 9e5b3ad commit 08094e4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

src/api/window_bindings.cc

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,13 @@ using namespace WebCore;
3333
#include "third_party/WebKit/public/web/WebFrame.h"
3434
#include "third_party/WebKit/public/web/WebView.h"
3535
#include "third_party/WebKit/Source/web/WebFrameImpl.h"
36+
#include "third_party/WebKit/public/web/WebScriptSource.h"
3637

38+
#undef CHECK
39+
#include "V8HTMLIFrameElement.h"
40+
41+
using WebKit::WebScriptSource;
42+
using WebKit::WebFrame;
3743

3844
namespace nwapi {
3945

@@ -103,8 +109,24 @@ WindowBindings::CallObjectMethod(const v8::FunctionCallbackInfo<v8::Value>& args
103109
return;
104110
}
105111

106-
if (method == "setDevToolsJail") {
107-
WebKit::WebFrame* main_frame = render_view->GetWebView()->mainFrame();
112+
WebFrame* main_frame = render_view->GetWebView()->mainFrame();
113+
if (method == "EvaluateScript") {
114+
v8::Handle<v8::Value> result;
115+
v8::Handle<v8::Object> frm = v8::Handle<v8::Object>::Cast(args[2]);
116+
WebFrame* web_frame = NULL;
117+
if (frm->IsNull()) {
118+
web_frame = main_frame;
119+
}else{
120+
WebCore::HTMLIFrameElement* iframe = WebCore::V8HTMLIFrameElement::toNative(frm);
121+
web_frame = WebKit::WebFrameImpl::fromFrame(iframe->contentFrame());
122+
}
123+
base::string16 jscript = *v8::String::Value(args[3]);
124+
if (web_frame) {
125+
result = web_frame->executeScriptAndReturnValue(WebScriptSource(jscript));
126+
}
127+
args.GetReturnValue().Set(result);
128+
return;
129+
} else if (method == "setDevToolsJail") {
108130
v8::Handle<v8::Object> frm = v8::Handle<v8::Object>::Cast(args[2]);
109131
if (frm->IsNull()) {
110132
main_frame->setDevtoolsJail(NULL);

src/api/window_bindings.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ Window.prototype.capturePage = function(callback, image_format) {
434434
}
435435

436436
CallObjectMethod(this, 'CapturePage', [image_format]);
437-
}
437+
};
438+
439+
Window.prototype.eval = function(frame, script) {
440+
return CallObjectMethod(this, 'EvaluateScript', frame, script);
441+
};
438442

439443
} // function Window.init

0 commit comments

Comments
 (0)