diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 03:34:53 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 03:34:53 +0000 |
commit | 882b7b2ac4db4348b28f0de68e48febbfd814a70 (patch) | |
tree | aa53683904901bebe5f012851bede0edb20f757c /chrome/renderer | |
parent | 428f54bcc8e53882375b7fb9f30b2bc577c59b8a (diff) | |
download | chromium_src-882b7b2ac4db4348b28f0de68e48febbfd814a70.zip chromium_src-882b7b2ac4db4348b28f0de68e48febbfd814a70.tar.gz chromium_src-882b7b2ac4db4348b28f0de68e48febbfd814a70.tar.bz2 |
Adds RenderViewHost::ExecuteJavascriptInWebFrameNotifyResult which
executes script and uses a notification to post the results back.
BUG=54833
TEST=none
Review URL: http://codereview.chromium.org/3591008
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61475 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/renderer')
-rw-r--r-- | chrome/renderer/render_view.cc | 29 | ||||
-rw-r--r-- | chrome/renderer/render_view.h | 12 |
2 files changed, 27 insertions, 14 deletions
diff --git a/chrome/renderer/render_view.cc b/chrome/renderer/render_view.cc index ab4336a..38a44f3 100644 --- a/chrome/renderer/render_view.cc +++ b/chrome/renderer/render_view.cc @@ -143,6 +143,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebVector.h" #include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "third_party/WebKit/WebKit/chromium/public/WebWindowFeatures.h" +#include "v8/include/v8.h" #include "webkit/appcache/web_application_cache_host_impl.h" #include "webkit/glue/context_menu.h" #include "webkit/glue/dom_operations.h" @@ -4151,13 +4152,19 @@ void RenderView::SetSuggestResult(const std::string& suggest) { Send(new ViewHostMsg_SetSuggestResult(routing_id_, page_id_, suggest)); } -void RenderView::EvaluateScript(const std::wstring& frame_xpath, - const std::wstring& script) { - WebFrame* web_frame = GetChildFrame(frame_xpath); - if (!web_frame) - return; - - web_frame->executeScript(WebScriptSource(WideToUTF16Hack(script))); +void RenderView::EvaluateScript(const string16& frame_xpath, + const string16& script, + int id, + bool notify_result) { + v8::Handle<v8::Value> result; + WebFrame* web_frame = GetChildFrame(UTF16ToWideHack(frame_xpath)); + if (web_frame) + result = web_frame->executeScriptAndReturnValue(WebScriptSource(script)); + if (notify_result) { + bool bool_result = !result.IsEmpty() && result->IsBoolean() ? + result->BooleanValue() : false; + Send(new ViewHostMsg_ScriptEvalResponse(routing_id_, id, bool_result)); + } } void RenderView::InsertCSS(const std::wstring& frame_xpath, @@ -4199,9 +4206,11 @@ void RenderView::OnPepperPluginDestroy( } } -void RenderView::OnScriptEvalRequest(const std::wstring& frame_xpath, - const std::wstring& jscript) { - EvaluateScript(frame_xpath, jscript); +void RenderView::OnScriptEvalRequest(const string16& frame_xpath, + const string16& jscript, + int id, + bool notify_result) { + EvaluateScript(frame_xpath, jscript, id, notify_result); } void RenderView::OnCSSInsertRequest(const std::wstring& frame_xpath, diff --git a/chrome/renderer/render_view.h b/chrome/renderer/render_view.h index 2292a3c..2fb488c 100644 --- a/chrome/renderer/render_view.h +++ b/chrome/renderer/render_view.h @@ -232,8 +232,10 @@ class RenderView : public RenderWidget, void SetSuggestResult(const std::string& suggest); // Evaluates a string of JavaScript in a particular frame. - void EvaluateScript(const std::wstring& frame_xpath, - const std::wstring& jscript); + void EvaluateScript(const string16& frame_xpath, + const string16& jscript, + int id, + bool notify_result); // Adds the given file chooser request to the file_chooser_completion_ queue // (see that var for more) and requests the chooser be displayed if there are @@ -828,8 +830,10 @@ class RenderView : public RenderWidget, void OnReservePageIDRange(int size_of_range); void OnResetPageEncodingToDefault(); void OnRevertTranslation(int page_id); - void OnScriptEvalRequest(const std::wstring& frame_xpath, - const std::wstring& jscript); + void OnScriptEvalRequest(const string16& frame_xpath, + const string16& jscript, + int id, + bool notify_result); void OnSelectAll(); void OnSetAccessibilityFocus(int acc_obj_id); void OnSetActive(bool active); |