Fix buglet calling out to JS from plugin. (issue7265012)

0 views
Skip to first unread message

w...@chromium.org

unread,
Jun 27, 2011, 12:19:13 AM6/27/11
to dmac...@chromium.org, chromium...@chromium.org, jamiewal...@chromium.org, hclam...@chromium.org, simonmor...@chromium.org, wez+...@chromium.org, dmaclac...@chromium.org, garyka...@chromium.org, lambroslam...@chromium.org, ajwong...@chromium.org, sergey...@chromium.org
Reviewers: dmac,

Message:
Fix the Host plugin to invoke the supplied callback functions using the NPN
InvokeDefault API, rather than accessing the NPClass function table
directly.

Description:
Fix buglet calling out to JS from plugin.

BUG=
TEST=Host plugin does not crash renderer if run in a Chrome instance set to
run
plugins in-process.


Please review this at http://codereview.chromium.org/7265012/

SVN Base: svn://svn.chromium.org/chrome/trunk/src

Affected files:
M remoting/host/plugin/host_script_object.h
M remoting/host/plugin/host_script_object.cc


Index: remoting/host/plugin/host_script_object.cc
diff --git a/remoting/host/plugin/host_script_object.cc
b/remoting/host/plugin/host_script_object.cc
index
d0c84b7770940ae271d113ab7bc64d3d8e050a57..fdeb568e1cecadbac3cc230ae1e89a16ad1419a4
100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -463,7 +463,7 @@ void HostNPScriptObject::OnStateChanged(State state) {
state_ = state;
if (on_state_changed_func_) {
VLOG(2) << "Calling state changed " << state;
- bool is_good = CallJSFunction(on_state_changed_func_, NULL, 0, NULL);
+ bool is_good = InvokeAndIgnoreResult(on_state_changed_func_, NULL, 0);
LOG_IF(ERROR, !is_good) << "OnStateChanged failed";
}
}
@@ -479,7 +479,7 @@ void HostNPScriptObject::LogDebugInfo(const
std::string& message) {
NPVariant* arg = new NPVariant();
LOG(INFO) << "Logging: " << message;
STRINGZ_TO_NPVARIANT(message.c_str(), *arg);
- bool is_good = CallJSFunction(log_debug_info_func_, arg, 1, NULL);
+ bool is_good = InvokeAndIgnoreResult(log_debug_info_func_, arg, 1);
LOG_IF(ERROR, !is_good) << "LogDebugInfo failed";
}
}
@@ -490,19 +490,14 @@ void HostNPScriptObject::SetException(const
std::string& exception_string) {
LogDebugInfo(exception_string);
}

-bool HostNPScriptObject::CallJSFunction(NPObject* func,
- const NPVariant* args,
- uint32_t argCount,
- NPVariant* result) {
+bool HostNPScriptObject::InvokeAndIgnoreResult(NPObject* func,
+ const NPVariant* args,
+ uint32_t argCount) {
NPVariant np_result;
- bool is_good = func->_class->invokeDefault(func, args, argCount,
&np_result);
- if (is_good) {
- if (result) {
- *result = np_result;
- } else {
+ bool is_good = g_npnetscape_funcs->invokeDefault(plugin_, func, args,
+ argCount, &np_result);
+ if (is_good)
g_npnetscape_funcs->releasevariantvalue(&np_result);
- }
- }
return is_good;
}

Index: remoting/host/plugin/host_script_object.h
diff --git a/remoting/host/plugin/host_script_object.h
b/remoting/host/plugin/host_script_object.h
index
47e4fb4e1e04753f31bbe690facd2a681009085e..4ffeac3d7feb0d83d7aa7f88c3bf9aa1d6f9a2d2
100644
--- a/remoting/host/plugin/host_script_object.h
+++ b/remoting/host/plugin/host_script_object.h
@@ -106,13 +106,11 @@ class HostNPScriptObject : public HostStatusObserver {
// Callback for ChromotingHost::Shutdown().
void OnShutdownFinished();

- // Call a JavaScript function wrapped as an NPObject.
- // If result is non-null, the result of the call will be stored in it.
- // Caller is responsible for releasing result if they ask for it.
- static bool CallJSFunction(NPObject* func,
+ // Helper function for executing InvokeDefault on an NPObject, and
ignoring
+ // the return value.
+ bool InvokeAndIgnoreResult(NPObject* func,
const NPVariant* args,
- uint32_t argCount,
- NPVariant* result);
+ uint32_t argCount);

// Posts a task on the main NP thread.
void PostTaskToNPThread(const tracked_objects::Location& from_here,


dmac...@chromium.org

unread,
Jun 27, 2011, 12:27:35 AM6/27/11
to w...@chromium.org, chromium...@chromium.org, jamiewal...@chromium.org, hclam...@chromium.org, simonmor...@chromium.org, wez+...@chromium.org, dmaclac...@chromium.org, garyka...@chromium.org, lambroslam...@chromium.org, ajwong...@chromium.org, sergey...@chromium.org

commi...@chromium.org

unread,
Jun 27, 2011, 6:25:53 PM6/27/11
to w...@chromium.org, dmac...@chromium.org, chromium...@chromium.org, jamiewal...@chromium.org, hclam...@chromium.org, simonmor...@chromium.org, wez+...@chromium.org, dmaclac...@chromium.org, garyka...@chromium.org, lambroslam...@chromium.org, ajwong...@chromium.org, sergey...@chromium.org
Reply all
Reply to author
Forward
0 new messages