| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ | 5 #ifndef CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ |
| 6 #define CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ | 6 #define CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "content/public/renderer/render_view_observer.h" | 13 #include "content/public/renderer/render_view_observer.h" |
| 14 #include "content/public/renderer/render_view_observer_tracker.h" |
| 14 #include "ppapi/c/pp_file_info.h" | 15 #include "ppapi/c/pp_file_info.h" |
| 15 #include "ppapi/c/pp_instance.h" | 16 #include "ppapi/c/pp_instance.h" |
| 16 #include "ppapi/c/pp_resource.h" | 17 #include "ppapi/c/pp_resource.h" |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 | 20 |
| 20 class PepperHelperImpl; | |
| 21 | |
| 22 // This class represents a connection from the renderer to the browser for | 21 // This class represents a connection from the renderer to the browser for |
| 23 // sending/receiving pepper ResourceHost related messages. When the browser | 22 // sending/receiving pepper ResourceHost related messages. When the browser |
| 24 // and renderer communicate about ResourceHosts, they should pass the plugin | 23 // and renderer communicate about ResourceHosts, they should pass the plugin |
| 25 // process ID to identify which plugin they are talking about. | 24 // process ID to identify which plugin they are talking about. |
| 26 class PepperBrowserConnection { | 25 class PepperBrowserConnection |
| 26 : public RenderViewObserver, |
| 27 public RenderViewObserverTracker<PepperBrowserConnection> { |
| 27 public: | 28 public: |
| 28 typedef base::Callback<void(int)> PendingResourceIDCallback; | 29 typedef base::Callback<void(int)> PendingResourceIDCallback; |
| 29 typedef base::Callback<void(PP_FileSystemType, | 30 typedef base::Callback<void(PP_FileSystemType, |
| 30 std::string, | 31 std::string, |
| 31 base::FilePath)> FileRefGetInfoCallback; | 32 base::FilePath)> FileRefGetInfoCallback; |
| 32 | 33 |
| 33 explicit PepperBrowserConnection(PepperHelperImpl* helper); | 34 explicit PepperBrowserConnection(RenderView* render_view); |
| 34 virtual ~PepperBrowserConnection(); | 35 virtual ~PepperBrowserConnection(); |
| 35 | 36 |
| 36 bool OnMessageReceived(const IPC::Message& message); | 37 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
| 37 | 38 |
| 38 // TODO(teravest): Instead of having separate methods per message, we should | 39 // TODO(teravest): Instead of having separate methods per message, we should |
| 39 // add generic functionality similar to PluginResource::Call(). | 40 // add generic functionality similar to PluginResource::Call(). |
| 40 | 41 |
| 41 // Sends a request to the browser to create a ResourceHost for the given | 42 // Sends a request to the browser to create a ResourceHost for the given |
| 42 // |instance| of a plugin identified by |child_process_id|. |callback| will be | 43 // |instance| of a plugin identified by |child_process_id|. |callback| will be |
| 43 // run when a reply is received with the pending resource ID. | 44 // run when a reply is received with the pending resource ID. |
| 44 void SendBrowserCreate(PP_Instance instance, | 45 void SendBrowserCreate(PP_Instance instance, |
| 45 int child_process_id, | 46 int child_process_id, |
| 46 const IPC::Message& create_message, | 47 const IPC::Message& create_message, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 58 void OnMsgCreateResourceHostFromHostReply(int32_t sequence_number, | 59 void OnMsgCreateResourceHostFromHostReply(int32_t sequence_number, |
| 59 int pending_resource_host_id); | 60 int pending_resource_host_id); |
| 60 void OnMsgFileRefGetInfoReply(int32_t sequence_number, | 61 void OnMsgFileRefGetInfoReply(int32_t sequence_number, |
| 61 PP_FileSystemType type, | 62 PP_FileSystemType type, |
| 62 std::string file_system_url_spec, | 63 std::string file_system_url_spec, |
| 63 base::FilePath external_path); | 64 base::FilePath external_path); |
| 64 | 65 |
| 65 // Return the next sequence number. | 66 // Return the next sequence number. |
| 66 int32_t GetNextSequence(); | 67 int32_t GetNextSequence(); |
| 67 | 68 |
| 68 // The plugin helper that owns us. | |
| 69 PepperHelperImpl* helper_; | |
| 70 | |
| 71 // Sequence number to track pending callbacks. | 69 // Sequence number to track pending callbacks. |
| 72 int32_t next_sequence_number_; | 70 int32_t next_sequence_number_; |
| 73 | 71 |
| 74 // Maps a sequence number to the callback to be run. | 72 // Maps a sequence number to the callback to be run. |
| 75 std::map<int32_t, PendingResourceIDCallback> pending_create_map_; | 73 std::map<int32_t, PendingResourceIDCallback> pending_create_map_; |
| 76 std::map<int32_t, FileRefGetInfoCallback> get_info_map_; | 74 std::map<int32_t, FileRefGetInfoCallback> get_info_map_; |
| 77 DISALLOW_COPY_AND_ASSIGN(PepperBrowserConnection); | 75 DISALLOW_COPY_AND_ASSIGN(PepperBrowserConnection); |
| 78 }; | 76 }; |
| 79 | 77 |
| 80 } // namespace content | 78 } // namespace content |
| 81 | 79 |
| 82 #endif // CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ | 80 #endif // CONTENT_RENDERER_PEPPER_PEPPER_BROWSER_CONNECTION_H_ |
| OLD | NEW |