Fix NPAPI and native messaging hosts to cope with NULL pairing registry.

Since there are no Windows or Mac pairing registry delegates yet, the host plugin currently crashes when the web-app starts up on those platforms.

Review URL: https://chromiumcodereview.appspot.com/19460020

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213381 0039d316-1c4b-4281-b951-d872f2087c98
parent b156a956
......@@ -1111,9 +1111,13 @@ bool HostNPScriptObject::ClearPairedClients(const NPVariant* args,
}
ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[0]));
pairing_registry_->ClearAllPairings(
base::Bind(&HostNPScriptObject::InvokeBooleanCallback, weak_ptr_,
callback_obj));
if (pairing_registry_) {
pairing_registry_->ClearAllPairings(
base::Bind(&HostNPScriptObject::InvokeBooleanCallback, weak_ptr_,
callback_obj));
} else {
InvokeBooleanCallback(callback_obj, false);
}
return true;
}
......@@ -1138,10 +1142,14 @@ bool HostNPScriptObject::DeletePairedClient(const NPVariant* args,
std::string client_id = StringFromNPVariant(args[0]);
ScopedRefNPObject callback_obj(ObjectFromNPVariant(args[1]));
pairing_registry_->DeletePairing(
client_id,
base::Bind(&HostNPScriptObject::InvokeBooleanCallback,
weak_ptr_, callback_obj));
if (pairing_registry_) {
pairing_registry_->DeletePairing(
client_id,
base::Bind(&HostNPScriptObject::InvokeBooleanCallback,
weak_ptr_, callback_obj));
} else {
InvokeBooleanCallback(callback_obj, false);
}
return true;
}
......@@ -1325,9 +1333,14 @@ bool HostNPScriptObject::GetPairedClients(const NPVariant* args,
return false;
}
pairing_registry_->GetAllPairings(
base::Bind(&HostNPScriptObject::InvokeGetPairedClientsCallback,
weak_ptr_, callback_obj));
if (pairing_registry_) {
pairing_registry_->GetAllPairings(
base::Bind(&HostNPScriptObject::InvokeGetPairedClientsCallback,
weak_ptr_, callback_obj));
} else {
scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue);
InvokeGetPairedClientsCallback(callback_obj, no_paired_clients.Pass());
}
return true;
}
......
......@@ -150,9 +150,13 @@ bool NativeMessagingHost::ProcessHello(
bool NativeMessagingHost::ProcessClearPairedClients(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
pairing_registry_->ClearAllPairings(
base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_,
base::Passed(&response)));
if (pairing_registry_) {
pairing_registry_->ClearAllPairings(
base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_,
base::Passed(&response)));
} else {
SendBooleanResult(response.Pass(), false);
}
return true;
}
......@@ -166,9 +170,13 @@ bool NativeMessagingHost::ProcessDeletePairedClient(
return false;
}
pairing_registry_->DeletePairing(
client_id, base::Bind(&NativeMessagingHost::SendBooleanResult, weak_ptr_,
base::Passed(&response)));
if (pairing_registry_) {
pairing_registry_->DeletePairing(
client_id, base::Bind(&NativeMessagingHost::SendBooleanResult,
weak_ptr_, base::Passed(&response)));
} else {
SendBooleanResult(response.Pass(), false);
}
return true;
}
......@@ -237,9 +245,14 @@ bool NativeMessagingHost::ProcessGetDaemonConfig(
bool NativeMessagingHost::ProcessGetPairedClients(
const base::DictionaryValue& message,
scoped_ptr<base::DictionaryValue> response) {
pairing_registry_->GetAllPairings(
base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_,
base::Passed(&response)));
if (pairing_registry_) {
pairing_registry_->GetAllPairings(
base::Bind(&NativeMessagingHost::SendPairedClientsResponse, weak_ptr_,
base::Passed(&response)));
} else {
scoped_ptr<base::ListValue> no_paired_clients(new base::ListValue);
SendPairedClientsResponse(response.Pass(), no_paired_clients.Pass());
}
return true;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment