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 11 #include "base/callback.h" 12 #include "base/files/file_path.h" 13 #include "content/public/renderer/render_view_observer.h" 14 #include "content/public/renderer/render_view_observer_tracker.h" 15 #include "ppapi/c/pp_file_info.h" 16 #include "ppapi/c/pp_instance.h" 17 #include "ppapi/c/pp_resource.h" 18 19 namespace content { 20 21 // This class represents a connection from the renderer to the browser for 22 // sending/receiving pepper ResourceHost related messages. When the browser 23 // and renderer communicate about ResourceHosts, they should pass the plugin 24 // process ID to identify which plugin they are talking about. 25 class PepperBrowserConnection 26 : public RenderViewObserver, 27 public RenderViewObserverTracker<PepperBrowserConnection> { 28 public: 29 typedef base::Callback<void(int)> PendingResourceIDCallback; 30 typedef base::Callback<void( 31 const std::vector<PP_Resource>&, 32 const std::vector<PP_FileSystemType>&, 33 const std::vector<std::string>&, 34 const std::vector<base::FilePath>&)> FileRefGetInfoCallback; 35 36 explicit PepperBrowserConnection(RenderView* render_view); 37 virtual ~PepperBrowserConnection(); 38 39 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 40 41 // TODO(teravest): Instead of having separate methods per message, we should 42 // add generic functionality similar to PluginResource::Call(). 43 44 // Sends a request to the browser to create a ResourceHost for the given 45 // |instance| of a plugin identified by |child_process_id|. |callback| will be 46 // run when a reply is received with the pending resource ID. 47 void SendBrowserCreate(PP_Instance instance, 48 int child_process_id, 49 const IPC::Message& create_message, 50 const PendingResourceIDCallback& callback); 51 52 // Sends a request to the browser to get information about the given FileRef 53 // |resource|. |callback| will be run when a reply is received with the 54 // file information. 55 void SendBrowserFileRefGetInfo(int child_process_id, 56 const std::vector<PP_Resource>& resource, 57 const FileRefGetInfoCallback& callback); 58 59 // Called when the renderer creates an in-process instance. 60 void DidCreateInProcessInstance(PP_Instance instance, 61 int render_view_id, 62 const GURL& document_url, 63 const GURL& plugin_url); 64 65 // Called when the renderer deletes an in-process instance. 66 void DidDeleteInProcessInstance(PP_Instance instance); 67 68 private: 69 // Message handlers. 70 void OnMsgCreateResourceHostFromHostReply(int32_t sequence_number, 71 int pending_resource_host_id); 72 void OnMsgFileRefGetInfoReply( 73 int32_t sequence_number, 74 const std::vector<PP_Resource>& resources, 75 const std::vector<PP_FileSystemType>& types, 76 const std::vector<std::string>& file_system_url_specs, 77 const std::vector<base::FilePath>& external_paths); 78 79 // Return the next sequence number. 80 int32_t GetNextSequence(); 81 82 // Sequence number to track pending callbacks. 83 int32_t next_sequence_number_; 84 85 // Maps a sequence number to the callback to be run. 86 std::map<int32_t, PendingResourceIDCallback> pending_create_map_; 87 std::map<int32_t, FileRefGetInfoCallback> get_info_map_; 88 DISALLOW_COPY_AND_ASSIGN(PepperBrowserConnection); 89 }; 90 91 } // namespace content 92 93 #endif // CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ 94