Home | History | Annotate | Download | only in pepper
      1 // Copyright (c) 2013 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 #ifndef CHROME_RENDERER_PEPPER_PEPPER_EXTENSIONS_COMMON_HOST_H_
      6 #define CHROME_RENDERER_PEPPER_PEPPER_EXTENSIONS_COMMON_HOST_H_
      7 
      8 #include <map>
      9 #include <string>
     10 
     11 #include "base/basictypes.h"
     12 #include "base/bind.h"
     13 #include "base/compiler_specific.h"
     14 #include "base/memory/linked_ptr.h"
     15 #include "base/memory/weak_ptr.h"
     16 #include "chrome/renderer/extensions/pepper_request_proxy.h"
     17 #include "ppapi/host/resource_host.h"
     18 
     19 namespace base {
     20 class ListValue;
     21 }
     22 
     23 namespace content {
     24 class RendererPpapiHost;
     25 }
     26 
     27 namespace ppapi {
     28 namespace host {
     29 struct ReplyMessageContext;
     30 }
     31 }
     32 
     33 namespace extensions {
     34 class Dispatcher;
     35 }
     36 
     37 class PepperExtensionsCommonHost : public ppapi::host::ResourceHost {
     38  public:
     39   virtual ~PepperExtensionsCommonHost();
     40 
     41   static PepperExtensionsCommonHost* Create(content::RendererPpapiHost* host,
     42                                             PP_Instance instance,
     43                                             PP_Resource resource);
     44 
     45   // ppapi::host::ResourceMessageHandler overrides.
     46   virtual int32_t OnResourceMessageReceived(
     47       const IPC::Message& msg,
     48       ppapi::host::HostMessageContext* context) OVERRIDE;
     49 
     50  private:
     51   PepperExtensionsCommonHost(
     52       content::RendererPpapiHost* host,
     53       PP_Instance instance,
     54       PP_Resource resource,
     55       extensions::PepperRequestProxy* pepper_request_proxy);
     56 
     57   int32_t OnPost(ppapi::host::HostMessageContext* context,
     58                  const std::string& request_name,
     59                  const base::ListValue& args);
     60 
     61   int32_t OnCall(ppapi::host::HostMessageContext* context,
     62                  const std::string& request_name,
     63                  const base::ListValue& args);
     64 
     65   void OnResponseReceived(
     66       scoped_ptr<ppapi::host::ReplyMessageContext> response_context,
     67       bool success,
     68       const base::ListValue& response,
     69       const std::string& error);
     70 
     71   // Non-owning pointer.
     72   content::RendererPpapiHost* renderer_ppapi_host_;
     73   // Non-owning pointer.
     74   extensions::PepperRequestProxy* pepper_request_proxy_;
     75 
     76   base::WeakPtrFactory<PepperExtensionsCommonHost> weak_factory_;
     77 
     78   DISALLOW_COPY_AND_ASSIGN(PepperExtensionsCommonHost);
     79 };
     80 
     81 #endif  // CHROME_RENDERER_PEPPER_PEPPER_EXTENSIONS_COMMON_HOST_H_
     82