Home | History | Annotate | Download | only in proxy
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #include "ppapi/proxy/ppp_find_proxy.h"
      6 
      7 #include "ppapi/proxy/host_dispatcher.h"
      8 #include "ppapi/proxy/ppapi_messages.h"
      9 #include "ppapi/shared_impl/api_id.h"
     10 #include "ppapi/shared_impl/proxy_lock.h"
     11 
     12 namespace ppapi {
     13 namespace proxy {
     14 
     15 namespace {
     16 
     17 #if !defined(OS_NACL)
     18 PP_Bool StartFind(PP_Instance instance,
     19                   const char* text,
     20                   PP_Bool case_sensitive) {
     21   DCHECK(case_sensitive == PP_FALSE);
     22   HostDispatcher::GetForInstance(instance)->Send(
     23       new PpapiPluginMsg_PPPFind_StartFind(API_ID_PPP_FIND_PRIVATE,
     24                                            instance,
     25                                            text));
     26   return PP_TRUE;
     27 }
     28 
     29 void SelectFindResult(PP_Instance instance,
     30                       PP_Bool forward) {
     31   HostDispatcher::GetForInstance(instance)->Send(
     32       new PpapiPluginMsg_PPPFind_SelectFindResult(API_ID_PPP_FIND_PRIVATE,
     33                                                   instance, forward));
     34 }
     35 
     36 void StopFind(PP_Instance instance) {
     37   HostDispatcher::GetForInstance(instance)->Send(
     38       new PpapiPluginMsg_PPPFind_StopFind(API_ID_PPP_FIND_PRIVATE, instance));
     39 }
     40 
     41 const PPP_Find_Private ppp_find_interface = {
     42   &StartFind,
     43   &SelectFindResult,
     44   &StopFind
     45 };
     46 #else
     47 // The NaCl plugin doesn't need the host side interface - stub it out.
     48 const PPP_Find_Private ppp_find_interface = {};
     49 #endif
     50 
     51 }  // namespace
     52 
     53 PPP_Find_Proxy::PPP_Find_Proxy(Dispatcher* dispatcher)
     54     : InterfaceProxy(dispatcher),
     55       ppp_find_(NULL) {
     56   if (dispatcher->IsPlugin()) {
     57     ppp_find_ = static_cast<const PPP_Find_Private*>(
     58         dispatcher->local_get_interface()(PPP_FIND_PRIVATE_INTERFACE));
     59   }
     60 }
     61 
     62 PPP_Find_Proxy::~PPP_Find_Proxy() {
     63 }
     64 
     65 // static
     66 const PPP_Find_Private* PPP_Find_Proxy::GetProxyInterface() {
     67   return &ppp_find_interface;
     68 }
     69 
     70 bool PPP_Find_Proxy::OnMessageReceived(const IPC::Message& msg) {
     71   if (!dispatcher()->IsPlugin())
     72     return false;
     73 
     74   bool handled = true;
     75   IPC_BEGIN_MESSAGE_MAP(PPP_Find_Proxy, msg)
     76     IPC_MESSAGE_HANDLER(PpapiPluginMsg_PPPFind_StartFind, OnPluginMsgStartFind)
     77     IPC_MESSAGE_HANDLER(PpapiPluginMsg_PPPFind_SelectFindResult,
     78                         OnPluginMsgSelectFindResult)
     79     IPC_MESSAGE_HANDLER(PpapiPluginMsg_PPPFind_StopFind, OnPluginMsgStopFind)
     80     IPC_MESSAGE_UNHANDLED(handled = false)
     81   IPC_END_MESSAGE_MAP()
     82   return handled;
     83 }
     84 
     85 void PPP_Find_Proxy::OnPluginMsgStartFind(PP_Instance instance,
     86                                           const std::string& text) {
     87   if (ppp_find_)
     88     CallWhileUnlocked(ppp_find_->StartFind, instance, text.c_str(), PP_FALSE);
     89 }
     90 
     91 void PPP_Find_Proxy::OnPluginMsgSelectFindResult(PP_Instance instance,
     92                                                  PP_Bool forward) {
     93   if (ppp_find_)
     94     CallWhileUnlocked(ppp_find_->SelectFindResult, instance, forward);
     95 }
     96 
     97 void PPP_Find_Proxy::OnPluginMsgStopFind(PP_Instance instance) {
     98   if (ppp_find_)
     99     CallWhileUnlocked(ppp_find_->StopFind, instance);
    100 }
    101 
    102 }  // namespace proxy
    103 }  // namespace ppapi
    104