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/compiler_specific.h"
     13 #include "base/memory/linked_ptr.h"
     14 #include "chrome/renderer/extensions/request_sender.h"
     15 #include "ppapi/host/resource_host.h"
     16 
     17 namespace base {
     18 class ListValue;
     19 }
     20 
     21 namespace content {
     22 class RendererPpapiHost;
     23 }
     24 
     25 namespace ppapi {
     26 namespace host {
     27 struct ReplyMessageContext;
     28 }
     29 }
     30 
     31 namespace extensions {
     32 class Dispatcher;
     33 }
     34 
     35 namespace chrome {
     36 
     37 class PepperExtensionsCommonHost : public ppapi::host::ResourceHost,
     38                                    public extensions::RequestSender::Source {
     39  public:
     40   virtual ~PepperExtensionsCommonHost();
     41 
     42   static PepperExtensionsCommonHost* Create(content::RendererPpapiHost* host,
     43                                             PP_Instance instance,
     44                                             PP_Resource resource);
     45 
     46   // ppapi::host::ResourceMessageHandler overrides.
     47   virtual int32_t OnResourceMessageReceived(
     48       const IPC::Message& msg,
     49       ppapi::host::HostMessageContext* context) OVERRIDE;
     50 
     51   // extensions::RequestSender::Source implementation.
     52   virtual extensions::ChromeV8Context* GetContext() OVERRIDE;
     53   virtual void OnResponseReceived(const std::string& name,
     54                                   int request_id,
     55                                   bool success,
     56                                   const base::ListValue& response,
     57                                   const std::string& error) OVERRIDE;
     58  private:
     59   typedef std::map<int, linked_ptr<ppapi::host::ReplyMessageContext> >
     60       PendingRequestMap;
     61 
     62   PepperExtensionsCommonHost(content::RendererPpapiHost* host,
     63                              PP_Instance instance,
     64                              PP_Resource resource,
     65                              extensions::Dispatcher* dispatcher);
     66 
     67   int32_t OnPost(ppapi::host::HostMessageContext* context,
     68                  const std::string& request_name,
     69                  base::ListValue& args);
     70 
     71   int32_t OnCall(ppapi::host::HostMessageContext* context,
     72                  const std::string& request_name,
     73                  base::ListValue& args);
     74 
     75   // Non-owning pointer.
     76   content::RendererPpapiHost* renderer_ppapi_host_;
     77   // Non-owning pointer.
     78   extensions::Dispatcher* dispatcher_;
     79 
     80   PendingRequestMap pending_request_map_;
     81 
     82   DISALLOW_COPY_AND_ASSIGN(PepperExtensionsCommonHost);
     83 };
     84 
     85 }  // namespace chrome
     86 
     87 #endif  // CHROME_RENDERER_PEPPER_PEPPER_EXTENSIONS_COMMON_HOST_H_
     88