[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 1 | // Copyright (c) 2012 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 PPAPI_PROXY_PLUGIN_RESOURCE_H_ | ||||
6 | #define PPAPI_PROXY_PLUGIN_RESOURCE_H_ | ||||
7 | |||||
8 | #include "base/compiler_specific.h" | ||||
9 | #include "ipc/ipc_sender.h" | ||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 10 | #include "ppapi/proxy/connection.h" |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 11 | #include "ppapi/proxy/ppapi_proxy_export.h" |
12 | #include "ppapi/shared_impl/resource.h" | ||||
13 | |||||
14 | namespace IPC { | ||||
15 | class Message; | ||||
16 | } | ||||
17 | |||||
18 | namespace ppapi { | ||||
19 | namespace proxy { | ||||
20 | |||||
21 | class PluginDispatcher; | ||||
22 | |||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 23 | class PPAPI_PROXY_EXPORT PluginResource : public Resource { |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 24 | public: |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 25 | PluginResource(Connection connection, PP_Instance instance); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 26 | virtual ~PluginResource(); |
27 | |||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 28 | // Returns true if we've previously sent a create message to the browser |
29 | // or renderer. Generally resources will use these to tell if they should | ||||
30 | // lazily send create messages. | ||||
31 | bool sent_create_to_browser() const { return sent_create_to_browser_; } | ||||
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 32 | bool sent_create_to_renderer() const { return sent_create_to_renderer_; } |
33 | |||||
34 | protected: | ||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 35 | // Sends a create message to the browser or renderer for the current resource. |
36 | void SendCreateToBrowser(const IPC::Message& msg); | ||||
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 37 | void SendCreateToRenderer(const IPC::Message& msg); |
38 | |||||
39 | // Sends the given IPC message as a resource request to the host | ||||
40 | // corresponding to this resource object and does not expect a reply. | ||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 41 | void PostToBrowser(const IPC::Message& msg); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 42 | void PostToRenderer(const IPC::Message& msg); |
43 | |||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 44 | // Like PostToBrowser/Renderer but expects a response. |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 45 | // |
46 | // Returns the new request's sequence number which can be used to identify | ||||
47 | // the callback. The host will reply and ppapi::Resource::OnReplyReceived | ||||
48 | // will be called. | ||||
49 | // | ||||
50 | // Note that all integers (including 0 and -1) are valid request IDs. | ||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 51 | int32_t CallBrowser(const IPC::Message& msg); |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 52 | int32_t CallRenderer(const IPC::Message& msg); |
53 | |||||
[email protected] | ff44fc1 | 2012-10-03 00:52:16 | [diff] [blame^] | 54 | // Call the browser/renderer with sync messages. The pepper error code from |
55 | // the call is returned and the reply message is stored in |reply_msg|. | ||||
56 | int32_t CallBrowserSync(const IPC::Message& msg, IPC::Message* reply_msg); | ||||
57 | int32_t CallRendererSync(const IPC::Message& msg, IPC::Message* reply_msg); | ||||
58 | |||||
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 59 | private: |
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 60 | Connection connection_; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 61 | |
62 | int32_t next_sequence_number_; | ||||
63 | |||||
[email protected] | 93df81e | 2012-08-10 22:22:46 | [diff] [blame] | 64 | bool sent_create_to_browser_; |
[email protected] | eccf8031 | 2012-07-14 15:43:42 | [diff] [blame] | 65 | bool sent_create_to_renderer_; |
66 | |||||
67 | DISALLOW_COPY_AND_ASSIGN(PluginResource); | ||||
68 | }; | ||||
69 | |||||
70 | } // namespace proxy | ||||
71 | } // namespace ppapi | ||||
72 | |||||
73 | #endif // PPAPI_PROXY_PLUGIN_RESOURCE_H_ |