Home | History | Annotate | Download | only in pepper
      1 // Copyright 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 CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_
      6 #define CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_
      7 
      8 #include <map>
      9 #include <string>
     10 #include <vector>
     11 
     12 #include "base/callback.h"
     13 #include "base/files/file_path.h"
     14 #include "content/public/renderer/render_frame_observer.h"
     15 #include "content/public/renderer/render_frame_observer_tracker.h"
     16 #include "ppapi/c/pp_file_info.h"
     17 #include "ppapi/c/pp_instance.h"
     18 #include "ppapi/c/pp_resource.h"
     19 
     20 class GURL;
     21 
     22 namespace content {
     23 
     24 // This class represents a connection from the renderer to the browser for
     25 // sending/receiving pepper ResourceHost related messages. When the browser
     26 // and renderer communicate about ResourceHosts, they should pass the plugin
     27 // process ID to identify which plugin they are talking about.
     28 class PepperBrowserConnection
     29     : public RenderFrameObserver,
     30       public RenderFrameObserverTracker<PepperBrowserConnection> {
     31  public:
     32   typedef base::Callback<void(const std::vector<int>&)>
     33       PendingResourceIDCallback;
     34   explicit PepperBrowserConnection(RenderFrame* render_frame);
     35   virtual ~PepperBrowserConnection();
     36 
     37   virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
     38 
     39   // TODO(teravest): Instead of having separate methods per message, we should
     40   // add generic functionality similar to PluginResource::Call().
     41 
     42   // Sends a request to the browser to create ResourceHosts for the given
     43   // |instance| of a plugin identified by |child_process_id|. |callback| will be
     44   // run when a reply is received with the pending resource IDs.
     45   void SendBrowserCreate(PP_Instance instance,
     46                          int child_process_id,
     47                          const std::vector<IPC::Message>& create_messages,
     48                          const PendingResourceIDCallback& callback);
     49 
     50   // Called when the renderer creates an in-process instance.
     51   void DidCreateInProcessInstance(PP_Instance instance,
     52                                   int render_frame_id,
     53                                   const GURL& document_url,
     54                                   const GURL& plugin_url);
     55 
     56   // Called when the renderer deletes an in-process instance.
     57   void DidDeleteInProcessInstance(PP_Instance instance);
     58 
     59  private:
     60   // Message handlers.
     61   void OnMsgCreateResourceHostsFromHostReply(
     62       int32_t sequence_number,
     63       const std::vector<int>& pending_resource_host_ids);
     64 
     65   // Return the next sequence number.
     66   int32_t GetNextSequence();
     67 
     68   // Sequence number to track pending callbacks.
     69   int32_t next_sequence_number_;
     70 
     71   // Maps a sequence number to the callback to be run.
     72   std::map<int32_t, PendingResourceIDCallback> pending_create_map_;
     73   DISALLOW_COPY_AND_ASSIGN(PepperBrowserConnection);
     74 };
     75 
     76 }  // namespace content
     77 
     78 #endif  // CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_
     79