Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(597)

Side by Side Diff: ppapi/proxy/ppb_flash_menu_proxy.cc

Issue 7149026: Implement flash menu and net connector resources using the API/thunk model. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/proxy/ppb_flash_menu_proxy.h ('k') | ppapi/proxy/ppb_flash_net_connector_proxy.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include "ppapi/proxy/ppb_flash_menu_proxy.h" 5 #include "ppapi/proxy/ppb_flash_menu_proxy.h"
6 6
7 #include "ppapi/c/pp_errors.h" 7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/private/ppb_flash_menu.h" 8 #include "ppapi/c/private/ppb_flash_menu.h"
9 #include "ppapi/proxy/enter_proxy.h"
9 #include "ppapi/proxy/ppapi_messages.h" 10 #include "ppapi/proxy/ppapi_messages.h"
11 #include "ppapi/thunk/enter.h"
12 #include "ppapi/thunk/ppb_flash_menu_api.h"
13 #include "ppapi/thunk/resource_creation_api.h"
14 #include "ppapi/thunk/thunk.h"
15
16 using ppapi::thunk::EnterFunctionNoLock;
17 using ppapi::thunk::PPB_Flash_Menu_API;
18 using ppapi::thunk::ResourceCreationAPI;
10 19
11 namespace pp { 20 namespace pp {
12 namespace proxy { 21 namespace proxy {
13 22
14 class FlashMenu : public PluginResource { 23 class FlashMenu : public PPB_Flash_Menu_API, public PluginResource {
15 public: 24 public:
16 explicit FlashMenu(const HostResource& resource) 25 explicit FlashMenu(const HostResource& resource);
17 : PluginResource(resource), 26 virtual ~FlashMenu();
18 callback_(PP_BlockUntilComplete()),
19 selected_id_ptr_(NULL) {
20 }
21 27
22 virtual ~FlashMenu() {} 28 // ResourceObjectBase overrides.
29 virtual PPB_Flash_Menu_API* AsPPB_Flash_Menu_API() OVERRIDE;
23 30
24 // Resource overrides. 31 // PPB_Flash_Menu_API implementation.
25 virtual FlashMenu* AsFlashMenu() { return this; } 32 virtual int32_t Show(const PP_Point* location,
33 int32_t* selected_id,
34 PP_CompletionCallback callback) OVERRIDE;
26 35
27 int32_t* selected_id_ptr() const { return selected_id_ptr_; } 36 void ShowACK(int32_t selected_id, int32_t result);
28 void set_selected_id_ptr(int32_t* ptr) { selected_id_ptr_ = ptr; }
29
30 PP_CompletionCallback callback() const { return callback_; }
31 void set_callback(PP_CompletionCallback cb) { callback_ = cb; }
32 37
33 private: 38 private:
34 PP_CompletionCallback callback_; 39 PP_CompletionCallback callback_;
35 int32_t* selected_id_ptr_; 40 int32_t* selected_id_ptr_;
36 41
37 DISALLOW_COPY_AND_ASSIGN(FlashMenu); 42 DISALLOW_COPY_AND_ASSIGN(FlashMenu);
38 }; 43 };
39 44
40 namespace { 45 FlashMenu::FlashMenu(const HostResource& resource)
41 46 : PluginResource(resource),
42 PP_Resource Create(PP_Instance instance_id, const PP_Flash_Menu* menu_data) { 47 callback_(PP_BlockUntilComplete()),
43 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id); 48 selected_id_ptr_(NULL) {
44 if (!dispatcher)
45 return 0;
46
47 HostResource result;
48 pp::proxy::SerializedFlashMenu serialized_menu;
49 if (!serialized_menu.SetPPMenu(menu_data))
50 return 0;
51
52 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Create(
53 INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result));
54 if (result.is_null())
55 return 0;
56
57 linked_ptr<FlashMenu> menu(new FlashMenu(result));
58 return PluginResourceTracker::GetInstance()->AddResource(menu);
59 } 49 }
60 50
61 PP_Bool IsFlashMenu(PP_Resource resource) { 51 FlashMenu::~FlashMenu() {
62 return BoolToPPBool(!!PluginResource::GetAs<FlashMenu>(resource));
63 } 52 }
64 53
65 int32_t Show(PP_Resource menu_id, 54 PPB_Flash_Menu_API* FlashMenu::AsPPB_Flash_Menu_API() {
66 const PP_Point* location, 55 return this;
67 int32_t* selected_id, 56 }
68 PP_CompletionCallback callback) {
69 FlashMenu* object = PluginResource::GetAs<FlashMenu>(menu_id);
70 if (!object)
71 return PP_ERROR_BADRESOURCE;
72 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
73 object->instance());
74 if (!dispatcher)
75 return PP_ERROR_FAILED;
76 57
77 if (object->callback().func) 58 int32_t FlashMenu::Show(const struct PP_Point* location,
59 int32_t* selected_id,
60 struct PP_CompletionCallback callback) {
61 if (callback_.func)
78 return PP_ERROR_INPROGRESS; 62 return PP_ERROR_INPROGRESS;
79 63
80 object->set_selected_id_ptr(selected_id); 64 selected_id_ptr_ = selected_id;
81 object->set_callback(callback); 65 callback_ = callback;
82 66
83 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Show( 67 GetDispatcher()->Send(new PpapiHostMsg_PPBFlashMenu_Show(
84 INTERFACE_ID_PPB_FLASH_MENU, object->host_resource(), *location)); 68 INTERFACE_ID_PPB_FLASH_MENU, host_resource(), *location));
85
86 return PP_OK_COMPLETIONPENDING; 69 return PP_OK_COMPLETIONPENDING;
87 } 70 }
88 71
89 const PPB_Flash_Menu flash_menu_interface = { 72 void FlashMenu::ShowACK(int32_t selected_id, int32_t result) {
90 &Create, 73 *selected_id_ptr_ = selected_id;
91 &IsFlashMenu, 74 PP_RunAndClearCompletionCallback(&callback_, result);
92 &Show, 75 }
93 }; 76
77 namespace {
94 78
95 InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher, 79 InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher,
96 const void* target_interface) { 80 const void* target_interface) {
97 return new PPB_Flash_Menu_Proxy(dispatcher, target_interface); 81 return new PPB_Flash_Menu_Proxy(dispatcher, target_interface);
98 } 82 }
99 83
100 } // namespace 84 } // namespace
101 85
102 PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher, 86 PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher,
103 const void* target_interface) 87 const void* target_interface)
104 : InterfaceProxy(dispatcher, target_interface), 88 : InterfaceProxy(dispatcher, target_interface),
105 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { 89 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
106 } 90 }
107 91
108 PPB_Flash_Menu_Proxy::~PPB_Flash_Menu_Proxy() { 92 PPB_Flash_Menu_Proxy::~PPB_Flash_Menu_Proxy() {
109 } 93 }
110 94
95 // static
111 const InterfaceProxy::Info* PPB_Flash_Menu_Proxy::GetInfo() { 96 const InterfaceProxy::Info* PPB_Flash_Menu_Proxy::GetInfo() {
112 static const Info info = { 97 static const Info info = {
113 &flash_menu_interface, 98 ppapi::thunk::GetPPB_Flash_Menu_Thunk(),
114 PPB_FLASH_MENU_INTERFACE, 99 PPB_FLASH_MENU_INTERFACE,
115 INTERFACE_ID_PPB_FLASH_MENU, 100 INTERFACE_ID_PPB_FLASH_MENU,
116 true, 101 true,
117 &CreateFlashMenuProxy, 102 &CreateFlashMenuProxy,
118 }; 103 };
119 return &info; 104 return &info;
120 } 105 }
121 106
107 // static
108 PP_Resource PPB_Flash_Menu_Proxy::CreateProxyResource(
109 PP_Instance instance_id,
110 const PP_Flash_Menu* menu_data) {
111 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
112 if (!dispatcher)
113 return 0;
114
115 HostResource result;
116 pp::proxy::SerializedFlashMenu serialized_menu;
117 if (!serialized_menu.SetPPMenu(menu_data))
118 return 0;
119
120 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Create(
121 INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result));
122 if (result.is_null())
123 return 0;
124
125 linked_ptr<FlashMenu> menu(new FlashMenu(result));
126 return PluginResourceTracker::GetInstance()->AddResource(menu);
127 }
128
122 bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) { 129 bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) {
123 bool handled = true; 130 bool handled = true;
124 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Menu_Proxy, msg) 131 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Menu_Proxy, msg)
125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Create, 132 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Create,
126 OnMsgCreate) 133 OnMsgCreate)
127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Show, 134 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Show,
128 OnMsgShow) 135 OnMsgShow)
129 136
130 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashMenu_ShowACK, 137 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashMenu_ShowACK,
131 OnMsgShowACK) 138 OnMsgShowACK)
132 IPC_MESSAGE_UNHANDLED(handled = false) 139 IPC_MESSAGE_UNHANDLED(handled = false)
133 IPC_END_MESSAGE_MAP() 140 IPC_END_MESSAGE_MAP()
134 // FIXME(brettw) handle bad messages! 141 // FIXME(brettw) handle bad messages!
135 return handled; 142 return handled;
136 } 143 }
137 144
138 void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance_id, 145 void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance,
139 const SerializedFlashMenu& menu_data, 146 const SerializedFlashMenu& menu_data,
140 HostResource* result) { 147 HostResource* result) {
141 PP_Resource resource = ppb_flash_menu_target()->Create(instance_id, 148 EnterFunctionNoLock<ResourceCreationAPI> enter(instance, true);
142 menu_data.pp_menu()); 149 if (enter.succeeded()) {
143 result->SetHostResource(instance_id, resource); 150 result->SetHostResource(
151 instance,
152 enter.functions()->CreateFlashMenu(instance, menu_data.pp_menu()));
153 }
144 } 154 }
145 155
146 struct PPB_Flash_Menu_Proxy::ShowRequest { 156 struct PPB_Flash_Menu_Proxy::ShowRequest {
147 HostResource menu; 157 HostResource menu;
148 int32_t selected_id; 158 int32_t selected_id;
149 }; 159 };
150 160
151 void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu, 161 void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu,
152 const PP_Point& location) { 162 const PP_Point& location) {
153 ShowRequest* request = new ShowRequest; 163 ShowRequest* request = new ShowRequest;
154 request->menu = menu; 164 request->menu = menu;
155 CompletionCallback callback = callback_factory_.NewCallback( 165 CompletionCallback callback = callback_factory_.NewCallback(
156 &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request); 166 &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request);
157 int32_t result = ppb_flash_menu_target()->Show( 167
158 menu.host_resource(), 168 EnterHostFromHostResource<PPB_Flash_Menu_API> enter(menu);
159 &location, 169 int32_t result = PP_ERROR_BADRESOURCE;
160 &request->selected_id, 170 if (enter.succeeded()) {
161 callback.pp_completion_callback()); 171 result = enter.object()->Show(&location,
172 &request->selected_id,
173 callback.pp_completion_callback());
174 }
162 if (result != PP_OK_COMPLETIONPENDING) { 175 if (result != PP_OK_COMPLETIONPENDING) {
163 // There was some error, so we won't get a callback. We need to now issue 176 // There was some error, so we won't get a callback. We need to now issue
164 // the ACK to the plugin so that it hears about the error. This will also 177 // the ACK to the plugin so that it hears about the error. This will also
165 // clean up the data associated with the callback. 178 // clean up the data associated with the callback.
166 callback.Run(result); 179 callback.Run(result);
167 } 180 }
168 } 181 }
169 182
170 void PPB_Flash_Menu_Proxy::OnMsgShowACK(const HostResource& menu, 183 void PPB_Flash_Menu_Proxy::OnMsgShowACK(const HostResource& menu,
171 int32_t selected_id, 184 int32_t selected_id,
172 int32_t result) { 185 int32_t result) {
173 PP_Resource plugin_resource = 186 PP_Resource plugin_resource =
174 PluginResourceTracker::GetInstance()->PluginResourceForHostResource(menu); 187 PluginResourceTracker::GetInstance()->PluginResourceForHostResource(menu);
175 if (!plugin_resource) 188 if (!plugin_resource)
176 return; 189 return;
177 FlashMenu* object = PluginResource::GetAs<FlashMenu>(plugin_resource); 190 FlashMenu* object = PluginResource::GetAs<FlashMenu>(plugin_resource);
178 if (!object) { 191 if (!object) {
179 // The plugin has released the FlashMenu object so don't issue the 192 // The plugin has released the FlashMenu object so don't issue the
180 // callback. 193 // callback.
181 return; 194 return;
182 } 195 }
183 196
184 // Be careful to make the callback NULL before issuing the callback since the 197 object->ShowACK(selected_id, result);
185 // plugin might want to show the menu again from within the callback.
186 PP_CompletionCallback callback = object->callback();
187 object->set_callback(PP_BlockUntilComplete());
188 *(object->selected_id_ptr()) = selected_id;
189 PP_RunCompletionCallback(&callback, result);
190 } 198 }
191 199
192 void PPB_Flash_Menu_Proxy::SendShowACKToPlugin( 200 void PPB_Flash_Menu_Proxy::SendShowACKToPlugin(
193 int32_t result, 201 int32_t result,
194 ShowRequest* request) { 202 ShowRequest* request) {
195 dispatcher()->Send(new PpapiMsg_PPBFlashMenu_ShowACK( 203 dispatcher()->Send(new PpapiMsg_PPBFlashMenu_ShowACK(
196 INTERFACE_ID_PPB_FLASH_MENU, 204 INTERFACE_ID_PPB_FLASH_MENU,
197 request->menu, 205 request->menu,
198 request->selected_id, 206 request->selected_id,
199 result)); 207 result));
200 delete request; 208 delete request;
201 } 209 }
202 210
203 } // namespace proxy 211 } // namespace proxy
204 } // namespace pp 212 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_menu_proxy.h ('k') | ppapi/proxy/ppb_flash_net_connector_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698