summaryrefslogtreecommitdiffstats
path: root/remoting
diff options
context:
space:
mode:
authorsergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-09 23:56:12 +0000
committersergeyu@chromium.org <sergeyu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-09 23:56:12 +0000
commit718231d6569e592dd14676aaa74c2e5ccbc59592 (patch)
treeceb1ae8337709a61383a429653000b963b38c6aa /remoting
parentd7d15d7ee5c5db773c7cdefff9ca0ff85891b635 (diff)
downloadchromium_src-718231d6569e592dd14676aaa74c2e5ccbc59592.zip
chromium_src-718231d6569e592dd14676aaa74c2e5ccbc59592.tar.gz
chromium_src-718231d6569e592dd14676aaa74c2e5ccbc59592.tar.bz2
Use ScopedRefNPObject to pass NPObjects in the host plugin.
Review URL: https://chromiumcodereview.appspot.com/10024025 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131489 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'remoting')
-rw-r--r--remoting/host/plugin/host_plugin_utils.cc12
-rw-r--r--remoting/host/plugin/host_plugin_utils.h8
-rw-r--r--remoting/host/plugin/host_script_object.cc47
-rw-r--r--remoting/host/plugin/host_script_object.h8
4 files changed, 36 insertions, 39 deletions
diff --git a/remoting/host/plugin/host_plugin_utils.cc b/remoting/host/plugin/host_plugin_utils.cc
index c1682c4b..d8061cf 100644
--- a/remoting/host/plugin/host_plugin_utils.cc
+++ b/remoting/host/plugin/host_plugin_utils.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -47,6 +47,11 @@ ScopedRefNPObject::ScopedRefNPObject(NPObject* object)
*this = object;
}
+ScopedRefNPObject::ScopedRefNPObject(const ScopedRefNPObject& object)
+ : object_(NULL) {
+ *this = object;
+}
+
ScopedRefNPObject::~ScopedRefNPObject() {
*this = NULL;
}
@@ -62,4 +67,9 @@ ScopedRefNPObject& ScopedRefNPObject::operator=(NPObject* object) {
return *this;
}
+ScopedRefNPObject& ScopedRefNPObject::operator=(
+ const ScopedRefNPObject& object) {
+ return *this = object.get();
+}
+
} // namespace remoting
diff --git a/remoting/host/plugin/host_plugin_utils.h b/remoting/host/plugin/host_plugin_utils.h
index b1e4c73..a7348bb 100644
--- a/remoting/host/plugin/host_plugin_utils.h
+++ b/remoting/host/plugin/host_plugin_utils.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -36,18 +36,18 @@ class ScopedRefNPObject {
public:
ScopedRefNPObject();
explicit ScopedRefNPObject(NPObject* object);
+ explicit ScopedRefNPObject(const ScopedRefNPObject& object);
~ScopedRefNPObject();
// Release the held reference and replace it with |object|, incrementing
// its reference count.
ScopedRefNPObject& operator=(NPObject* object);
+ ScopedRefNPObject& operator=(const ScopedRefNPObject& object);
- NPObject* get() { return object_; }
+ NPObject* get() const { return object_; }
private:
NPObject* object_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedRefNPObject);
};
} // namespace remoting
diff --git a/remoting/host/plugin/host_script_object.cc b/remoting/host/plugin/host_script_object.cc
index abe65ba..f7f64c8 100644
--- a/remoting/host/plugin/host_script_object.cc
+++ b/remoting/host/plugin/host_script_object.cc
@@ -657,14 +657,12 @@ bool HostNPScriptObject::GenerateKeyPair(const NPVariant* args,
return false;
}
- NPObject* callback_obj = ObjectFromNPVariant(args[0]);
- if (!callback_obj) {
+ ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
+ if (!callback_obj.get()) {
SetException("generateKeyPair: invalid callback parameter");
return false;
}
- callback_obj = g_npnetscape_funcs->retainobject(callback_obj);
-
worker_thread_.message_loop_proxy()->PostTask(
FROM_HERE, base::Bind(&HostNPScriptObject::DoGenerateKeyPair,
base::Unretained(this), callback_obj));
@@ -689,8 +687,8 @@ bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args,
scoped_ptr<base::DictionaryValue> config_dict(
reinterpret_cast<base::DictionaryValue*>(config.release()));
- NPObject* callback_obj = ObjectFromNPVariant(args[1]);
- if (!callback_obj) {
+ ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[1]));
+ if (callback_obj.get()) {
SetException("updateDaemonConfig: invalid callback parameter");
return false;
}
@@ -702,8 +700,6 @@ bool HostNPScriptObject::UpdateDaemonConfig(const NPVariant* args,
return false;
}
- callback_obj = g_npnetscape_funcs->retainobject(callback_obj);
-
daemon_controller_->UpdateConfig(
config_dict.Pass(),
base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback,
@@ -719,14 +715,12 @@ bool HostNPScriptObject::GetDaemonConfig(const NPVariant* args,
return false;
}
- NPObject* callback_obj = ObjectFromNPVariant(args[0]);
- if (!callback_obj) {
+ ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
+ if (!callback_obj.get()) {
SetException("getDaemonConfig: invalid callback parameter");
return false;
}
- callback_obj = g_npnetscape_funcs->retainobject(callback_obj);
-
// We control lifetime of the |daemon_controller_| so it's safe to
// use base::Unretained() here.
daemon_controller_->GetConfig(
@@ -754,14 +748,12 @@ bool HostNPScriptObject::StartDaemon(const NPVariant* args,
scoped_ptr<base::DictionaryValue> config_dict(
reinterpret_cast<base::DictionaryValue*>(config.release()));
- NPObject* callback_obj = ObjectFromNPVariant(args[1]);
- if (!callback_obj) {
+ ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[1]));
+ if (!callback_obj.get()) {
SetException("startDaemon: invalid callback parameter");
return false;
}
- callback_obj = g_npnetscape_funcs->retainobject(callback_obj);
-
daemon_controller_->SetConfigAndStart(
config_dict.Pass(),
base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback,
@@ -777,14 +769,12 @@ bool HostNPScriptObject::StopDaemon(const NPVariant* args,
return false;
}
- NPObject* callback_obj = ObjectFromNPVariant(args[0]);
- if (!callback_obj) {
+ ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
+ if (!callback_obj.get()) {
SetException("stopDaemon: invalid callback parameter");
return false;
}
- callback_obj = g_npnetscape_funcs->retainobject(callback_obj);
-
daemon_controller_->Stop(
base::Bind(&HostNPScriptObject::InvokeAsyncResultCallback,
base::Unretained(this), callback_obj));
@@ -1034,7 +1024,7 @@ void HostNPScriptObject::UpdateWebappNatPolicy(bool nat_traversal_enabled) {
}
}
-void HostNPScriptObject::DoGenerateKeyPair(NPObject* callback) {
+void HostNPScriptObject::DoGenerateKeyPair(const ScopedRefNPObject& callback) {
HostKeyPair key_pair;
key_pair.Generate();
InvokeGenerateKeyPairCallback(callback, key_pair.GetAsString(),
@@ -1042,7 +1032,7 @@ void HostNPScriptObject::DoGenerateKeyPair(NPObject* callback) {
}
void HostNPScriptObject::InvokeGenerateKeyPairCallback(
- NPObject* callback,
+ const ScopedRefNPObject& callback,
const std::string& private_key,
const std::string& public_key) {
if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) {
@@ -1056,14 +1046,13 @@ void HostNPScriptObject::InvokeGenerateKeyPairCallback(
NPVariant params[2];
params[0] = NPVariantFromString(private_key);
params[1] = NPVariantFromString(public_key);
- InvokeAndIgnoreResult(callback, params, arraysize(params));
+ InvokeAndIgnoreResult(callback.get(), params, arraysize(params));
g_npnetscape_funcs->releasevariantvalue(&(params[0]));
g_npnetscape_funcs->releasevariantvalue(&(params[1]));
- g_npnetscape_funcs->releaseobject(callback);
}
void HostNPScriptObject::InvokeAsyncResultCallback(
- NPObject* callback,
+ const ScopedRefNPObject& callback,
DaemonController::AsyncResult result) {
if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) {
plugin_message_loop_proxy_->PostTask(
@@ -1075,13 +1064,12 @@ void HostNPScriptObject::InvokeAsyncResultCallback(
NPVariant result_var;
INT32_TO_NPVARIANT(static_cast<int32>(result), result_var);
- InvokeAndIgnoreResult(callback, &result_var, 1);
+ InvokeAndIgnoreResult(callback.get(), &result_var, 1);
g_npnetscape_funcs->releasevariantvalue(&result_var);
- g_npnetscape_funcs->releaseobject(callback);
}
void HostNPScriptObject::InvokeGetDaemonConfigCallback(
- NPObject* callback,
+ const ScopedRefNPObject& callback,
scoped_ptr<base::DictionaryValue> config) {
if (!plugin_message_loop_proxy_->BelongsToCurrentThread()) {
plugin_message_loop_proxy_->PostTask(
@@ -1098,9 +1086,8 @@ void HostNPScriptObject::InvokeGetDaemonConfigCallback(
base::JSONWriter::Write(config.get(), &config_str);
NPVariant config_val = NPVariantFromString(config_str);
- InvokeAndIgnoreResult(callback, &config_val, 1);
+ InvokeAndIgnoreResult(callback.get(), &config_val, 1);
g_npnetscape_funcs->releasevariantvalue(&config_val);
- g_npnetscape_funcs->releaseobject(callback);
}
void HostNPScriptObject::LogDebugInfo(const std::string& message) {
diff --git a/remoting/host/plugin/host_script_object.h b/remoting/host/plugin/host_script_object.h
index 482c987..c7083fe 100644
--- a/remoting/host/plugin/host_script_object.h
+++ b/remoting/host/plugin/host_script_object.h
@@ -212,19 +212,19 @@ class HostNPScriptObject : public HostStatusObserver {
// Helper methods for Me2Me host.
// Helpers for GenerateKeyPair().
- void DoGenerateKeyPair(NPObject* callback);
- void InvokeGenerateKeyPairCallback(NPObject* callback,
+ void DoGenerateKeyPair(const ScopedRefNPObject& callback);
+ void InvokeGenerateKeyPairCallback(const ScopedRefNPObject& callback,
const std::string& private_key,
const std::string& public_key);
// Callback handler for SetConfigAndStart(), Stop() and SetPin() in
// DaemonController.
- void InvokeAsyncResultCallback(NPObject* callback,
+ void InvokeAsyncResultCallback(const ScopedRefNPObject& callback,
DaemonController::AsyncResult result);
// Callback handler for DaemonController::GetConfig().
- void InvokeGetDaemonConfigCallback(NPObject* callback,
+ void InvokeGetDaemonConfigCallback(const ScopedRefNPObject& callback,
scoped_ptr<base::DictionaryValue> config);
//////////////////////////////////////////////////////////