2012-04-12 22:21:50 +02:00
|
|
|
// Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
|
|
|
|
// reserved. Use of this source code is governed by a BSD-style license that
|
|
|
|
// can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "cefclient/binding_test.h"
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "include/wrapper/cef_stream_resource_handler.h"
|
|
|
|
|
|
|
|
namespace binding_test {
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
const char kTestUrl[] = "http://tests/binding";
|
|
|
|
const char kTestMessageName[] = "BindingTest";
|
2012-04-12 22:21:50 +02:00
|
|
|
|
|
|
|
// Handle messages in the browser process.
|
2014-01-28 00:31:03 +01:00
|
|
|
class Handler : public CefMessageRouterBrowserSide::Handler {
|
2012-04-12 22:21:50 +02:00
|
|
|
public:
|
2014-01-28 00:31:03 +01:00
|
|
|
Handler() {}
|
|
|
|
|
|
|
|
// Called due to cefQuery execution in binding.html.
|
|
|
|
virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
|
|
|
|
CefRefPtr<CefFrame> frame,
|
|
|
|
int64 query_id,
|
|
|
|
const CefString& request,
|
|
|
|
bool persistent,
|
|
|
|
CefRefPtr<Callback> callback) OVERRIDE {
|
|
|
|
// Only handle messages from the test URL.
|
|
|
|
const std::string& url = frame->GetURL();
|
|
|
|
if (url.find(kTestUrl) != 0)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
const std::string& message_name = request;
|
|
|
|
if (message_name.find(kTestMessageName) == 0) {
|
|
|
|
// Reverse the string and return.
|
|
|
|
std::string result = message_name.substr(sizeof(kTestMessageName));
|
|
|
|
std::reverse(result.begin(), result.end());
|
|
|
|
callback->Success(result);
|
2012-04-12 22:21:50 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2014-01-28 00:31:03 +01:00
|
|
|
void CreateMessageHandlers(ClientHandler::MessageHandlerSet& handlers) {
|
|
|
|
handlers.insert(new Handler());
|
2012-04-12 22:21:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace binding_test
|