by atai » Wed Feb 05, 2014 8:27 am
Hi Marshall,
When I tried to add desktop notification into cefclient, I had some problem.
I tried to add notification class (just customize the binding_test as a copy), and tried to use (customize) the binding.html to test notification. I did as follow:
----------------------------------------
1. In binding.html:
1.1. add one more form:
Message: <input type="text" id="message2" value="My Message2">
1.2. add one more textarea result2:
<br/><textarea rows="10" cols="40" id="result2"></textarea>
1.3. add one more app.setMessageCallback:
app.setMessageCallback('desktop_notification', function (name, args) {
document.getElementById('result2').value = "Response: " + args[1];
});
1.4. in function sendMessage() add:
var msg2 = document.getElementById("message2").value;
app.sendMessage('desktop_notification', [msg, msg2]);
3. I add desktop_notification class, the same as binding_test class:
#include "cefclient/desktop_notification.h"
#include "include/cef_browser.h"
#include <algorithm>
#include <string>
namespace desktop_notification {
namespace {
const char* kMessageName = "desktop_notification";
// Handle messages in the browser process.
class ProcessMessageDelegate : public ClientHandler::ProcessMessageDelegate {
public:
ProcessMessageDelegate() {
}
// From ClientHandler::ProcessMessageDelegate.
virtual bool OnProcessMessageReceived(
CefRefPtr<ClientHandler> handler,
CefRefPtr<CefBrowser> browser,
CefProcessId source_process,
CefRefPtr<CefProcessMessage> message) OVERRIDE {
std::string message_name = message->GetName();
if (message_name == kMessageName) {
// Handle the message.
std::string result;
std::string result2;
CefRefPtr<CefListValue> args = message->GetArgumentList();
if (args->GetSize() > 0 && args->GetType(0) == VTYPE_STRING) {
// Our result is a reverse of the original message.
result = args->GetString(0);
result2 = args->GetString(1);
MessageBoxA(NULL,"yes, I can get it", "test",MB_OK);
std::reverse(result2.begin(), result2.end());
} else {
result = "Invalid request";
}
// Send the result back to the render process.
CefRefPtr<CefProcessMessage> response =
CefProcessMessage::Create(kMessageName);
response->GetArgumentList()->SetString(0, result);
response->GetArgumentList()->SetString(1, result2);
browser->SendProcessMessage(PID_RENDERER, response);
return true;
}
return false;
}
IMPLEMENT_REFCOUNTING(ProcessMessageDelegate);
};
} // namespace
void CreateProcessMessageDelegates(ClientHandler::ProcessMessageDelegateSet& delegates)
{
delegates.insert(new ProcessMessageDelegate);
}
} // namespace desktop_notification
----------------------------------------
I tried to rebuild all and run the app, but there is no action in desktop_notification.cpp.
After that, i removed all things I added (comment out), return the beginning, but now the binding_test doesn't work as before.
Marshall, can you help to figure out?
Thanks.