• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Embedded Framework Authors. All rights
2 // reserved. Use of this source code is governed by a BSD-style license that
3 // can be found in the LICENSE file.
4 
5 #include "tests/cefclient/browser/binding_test.h"
6 
7 #include <algorithm>
8 #include <string>
9 
10 #include "tests/cefclient/browser/test_runner.h"
11 
12 namespace client {
13 namespace binding_test {
14 
15 namespace {
16 
17 const char kTestUrlPath[] = "/binding";
18 const char kTestMessageName[] = "BindingTest";
19 
20 // Handle messages in the browser process.
21 class Handler : public CefMessageRouterBrowserSide::Handler {
22  public:
Handler()23   Handler() {}
24 
25   // Called due to cefQuery execution in binding.html.
OnQuery(CefRefPtr<CefBrowser> browser,CefRefPtr<CefFrame> frame,int64 query_id,const CefString & request,bool persistent,CefRefPtr<Callback> callback)26   virtual bool OnQuery(CefRefPtr<CefBrowser> browser,
27                        CefRefPtr<CefFrame> frame,
28                        int64 query_id,
29                        const CefString& request,
30                        bool persistent,
31                        CefRefPtr<Callback> callback) override {
32     // Only handle messages from the test URL.
33     const std::string& url = frame->GetURL();
34     if (!test_runner::IsTestURL(url, kTestUrlPath))
35       return false;
36 
37     const std::string& message_name = request;
38     if (message_name.find(kTestMessageName) == 0) {
39       // Reverse the string and return.
40       std::string result = message_name.substr(sizeof(kTestMessageName));
41       std::reverse(result.begin(), result.end());
42       callback->Success(result);
43       return true;
44     }
45 
46     return false;
47   }
48 };
49 
50 }  // namespace
51 
CreateMessageHandlers(test_runner::MessageHandlerSet & handlers)52 void CreateMessageHandlers(test_runner::MessageHandlerSet& handlers) {
53   handlers.insert(new Handler());
54 }
55 
56 }  // namespace binding_test
57 }  // namespace client
58