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

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

Issue 6432001: Implement proxy for FlashMenu and Run/QuitMessageLoop (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 10 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
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ppapi/proxy/ppb_flash_menu_proxy.h"
6
7 #include "ppapi/c/pp_errors.h"
8 #include "ppapi/c/private/ppb_flash_menu.h"
9 #include "ppapi/proxy/ppapi_messages.h"
10
11 namespace pp {
12 namespace proxy {
13
viettrungluu 2011/02/08 18:18:09 Nit: extraneous blank line.
piman 2011/02/15 02:11:22 Done.
14
15 class FlashMenu : public PluginResource {
16 public:
17 explicit FlashMenu(const HostResource& resource)
18 : PluginResource(resource),
19 callback_(PP_BlockUntilComplete()),
20 selected_id_ptr_(NULL) {
21 }
22
23 virtual ~FlashMenu() { }
viettrungluu 2011/02/08 18:18:09 I think mostly we do |{}|, not |{ }|.
piman 2011/02/15 02:11:22 Done.
24
25 // Resource overrides.
26 virtual FlashMenu* AsFlashMenu() { return this; }
27
28 int32_t* selected_id_ptr() const { return selected_id_ptr_; }
29 void set_selected_id_ptr(int32_t* ptr) { selected_id_ptr_ = ptr; }
30
31 PP_CompletionCallback callback() const {
32 return callback_;
viettrungluu 2011/02/08 18:18:09 For consistency (with the above), you may as well
piman 2011/02/15 02:11:22 Done.
33 }
34
35 void set_callback(PP_CompletionCallback cb) {
36 callback_ = cb;
37 }
38
39 private:
40 PP_CompletionCallback callback_;
viettrungluu 2011/02/08 18:18:09 Side question: Do you know if brettw has a plan fo
piman 2011/02/15 02:11:22 Not really, I think this is something that we'll n
41 int32_t* selected_id_ptr_;
42
43 DISALLOW_COPY_AND_ASSIGN(FlashMenu);
44 };
45
46 namespace {
47
48 PP_Resource Create(PP_Instance instance_id, const PP_Flash_Menu* menu_data) {
49 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
50 if (!dispatcher)
51 return 0;
52
53 HostResource result;
54 pp::proxy::SerializedFlashMenu serialized_menu;
55 if (!serialized_menu.SetPPMenu(menu_data))
56 return 0;
57 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Create(
58 INTERFACE_ID_PPB_FLASH_MENU, instance_id, serialized_menu, &result));
59
60 if (result.is_null())
viettrungluu 2011/02/08 18:18:09 Super-nit: I'd prefer there not to be a blank line
piman 2011/02/15 02:11:22 Done.
61 return 0;
62 linked_ptr<FlashMenu> menu(new FlashMenu(result));
63 return PluginResourceTracker::GetInstance()->AddResource(menu);
64 }
65
66 PP_Bool IsFlashMenu(PP_Resource resource) {
67 return BoolToPPBool(!!PluginResource::GetAs<FlashMenu>(resource));
68 }
69
70 int32_t Show(PP_Resource menu_id,
71 const PP_Point* location,
72 int32_t* selected_id,
73 PP_CompletionCallback callback) {
74 FlashMenu* object = PluginResource::GetAs<FlashMenu>(menu_id);
75 if (!object)
76 return PP_ERROR_BADRESOURCE;
77 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(
78 object->instance());
79 if (!dispatcher)
80 return PP_ERROR_FAILED;
81
82 if (object->callback().func)
83 return PP_ERROR_INPROGRESS;
84
85 object->set_selected_id_ptr(selected_id);
86 object->set_callback(callback);
87
88 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Show(
89 INTERFACE_ID_PPB_FLASH_MENU, object->host_resource(), *location));
90
91 return PP_ERROR_WOULDBLOCK;
92 }
93
94 const PPB_Flash_Menu ppb_flash_menu = {
95 &Create,
96 &IsFlashMenu,
97 &Show,
98 };
99
100 } // namespace
101
102 PPB_Flash_Menu_Proxy::PPB_Flash_Menu_Proxy(Dispatcher* dispatcher,
103 const void* target_interface)
104 : InterfaceProxy(dispatcher, target_interface),
105 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) {
106 }
107
108 PPB_Flash_Menu_Proxy::~PPB_Flash_Menu_Proxy() {
109 }
110
111 const void* PPB_Flash_Menu_Proxy::GetSourceInterface() const {
112 return &ppb_flash_menu;
113 }
114
115 InterfaceID PPB_Flash_Menu_Proxy::GetInterfaceId() const {
116 return INTERFACE_ID_PPB_FLASH_MENU;
117 }
118
119 bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) {
120 bool handled = true;
121 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Menu_Proxy, msg)
122 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Create,
123 OnMsgCreate)
124 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Show,
125 OnMsgShow)
126
127 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashMenu_ShowACK,
128 OnMsgShowACK)
129 IPC_MESSAGE_UNHANDLED(handled = false)
130 IPC_END_MESSAGE_MAP()
131 // FIXME(brettw) handle bad messages!
132 return handled;
133 }
134
135 void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance_id,
136 const SerializedFlashMenu& menu_data,
137 HostResource* result) {
138 PP_Resource resource = ppb_flash_menu_target()->Create(instance_id,
139 menu_data.pp_menu());
140 result->SetHostResource(instance_id, resource);
141 }
142
143 struct PPB_Flash_Menu_Proxy::ShowRequest {
144 HostResource menu;
145 int32_t selected_id;
146 };
147
148 void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu,
149 const PP_Point& location) {
150 ShowRequest* request = new ShowRequest;
151 request->menu = menu;
152 CompletionCallback callback = callback_factory_.NewCallback(
153 &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request);
154 int32_t result = ppb_flash_menu_target()->Show(
155 menu.host_resource(),
156 &location,
157 &request->selected_id,
158 callback.pp_completion_callback());
159 if (result != PP_ERROR_WOULDBLOCK) {
160 // There was some error, so we won't get a flush callback. We need to now
viettrungluu 2011/02/08 18:18:09 s/flush/???/
piman 2011/02/15 02:11:22 Done.
161 // issue the ACK to the plugin hears about the error. This will also clean
viettrungluu 2011/02/08 18:18:09 s/to/so/
piman 2011/02/15 02:11:22 Done.
162 // up the data associated with the callback.
163 callback.Run(result);
164 }
165 }
166
167 void PPB_Flash_Menu_Proxy::OnMsgShowACK(const HostResource& menu,
168 int32_t selected_id,
169 int32_t result) {
170 PP_Resource plugin_resource =
171 PluginResourceTracker::GetInstance()->PluginResourceForHostResource(menu);
172 if (!plugin_resource)
173 return;
174 FlashMenu* object = PluginResource::GetAs<FlashMenu>(plugin_resource);
175 if (!object) {
176 // The plugin has released the FlashMenu object so don't issue the
viettrungluu 2011/02/08 18:18:09 Hrm. I suppose that someone will have ensured that
177 // callback.
178 return;
179 }
180
181 // Be careful to make the callback NULL again before issuing the callback
182 // since the plugin might want to flush from within the callback.
viettrungluu 2011/02/08 18:18:09 s/flush/???/
piman 2011/02/15 02:11:22 Done.
183 PP_CompletionCallback callback = object->callback();
184 object->set_callback(PP_BlockUntilComplete());
185 *(object->selected_id_ptr()) = selected_id;
186 PP_RunCompletionCallback(&callback, result);
187 }
188
189 void PPB_Flash_Menu_Proxy::SendShowACKToPlugin(
190 int32_t result,
191 ShowRequest* request) {
192 dispatcher()->Send(new PpapiMsg_PPBFlashMenu_ShowACK(
193 INTERFACE_ID_PPB_FLASH_MENU,
194 request->menu,
195 request->selected_id,
196 result));
197 delete request;
198 }
199
200 } // namespace proxy
201 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698