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

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: Handle NULL menus more gracefully 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
« no previous file with comments | « ppapi/proxy/ppb_flash_menu_proxy.h ('k') | ppapi/proxy/ppb_flash_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
(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
14 class FlashMenu : public PluginResource {
15 public:
16 explicit FlashMenu(const HostResource& resource)
17 : PluginResource(resource),
18 callback_(PP_BlockUntilComplete()),
19 selected_id_ptr_(NULL) {
20 }
21
22 virtual ~FlashMenu() {}
23
24 // Resource overrides.
25 virtual FlashMenu* AsFlashMenu() { return this; }
26
27 int32_t* selected_id_ptr() const { return selected_id_ptr_; }
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
33 private:
34 PP_CompletionCallback callback_;
35 int32_t* selected_id_ptr_;
36
37 DISALLOW_COPY_AND_ASSIGN(FlashMenu);
38 };
39
40 namespace {
41
42 PP_Resource Create(PP_Instance instance_id, const PP_Flash_Menu* menu_data) {
43 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance_id);
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 }
60
61 PP_Bool IsFlashMenu(PP_Resource resource) {
62 return BoolToPPBool(!!PluginResource::GetAs<FlashMenu>(resource));
63 }
64
65 int32_t Show(PP_Resource menu_id,
66 const PP_Point* location,
67 int32_t* selected_id,
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
77 if (object->callback().func)
78 return PP_ERROR_INPROGRESS;
79
80 object->set_selected_id_ptr(selected_id);
81 object->set_callback(callback);
82
83 dispatcher->Send(new PpapiHostMsg_PPBFlashMenu_Show(
84 INTERFACE_ID_PPB_FLASH_MENU, object->host_resource(), *location));
85
86 return PP_ERROR_WOULDBLOCK;
87 }
88
89 const PPB_Flash_Menu flash_menu_interface = {
90 &Create,
91 &IsFlashMenu,
92 &Show,
93 };
94
95 InterfaceProxy* CreateFlashMenuProxy(Dispatcher* dispatcher,
96 const void* target_interface) {
97 return new PPB_Flash_Menu_Proxy(dispatcher, target_interface);
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 InterfaceProxy::Info* PPB_Flash_Menu_Proxy::GetInfo() {
112 static const Info info = {
113 &flash_menu_interface,
114 PPB_FLASH_MENU_INTERFACE,
115 INTERFACE_ID_PPB_FLASH_MENU,
116 true,
117 &CreateFlashMenuProxy,
118 };
119 return &info;
120 }
121
122 bool PPB_Flash_Menu_Proxy::OnMessageReceived(const IPC::Message& msg) {
123 bool handled = true;
124 IPC_BEGIN_MESSAGE_MAP(PPB_Flash_Menu_Proxy, msg)
125 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Create,
126 OnMsgCreate)
127 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBFlashMenu_Show,
128 OnMsgShow)
129
130 IPC_MESSAGE_HANDLER(PpapiMsg_PPBFlashMenu_ShowACK,
131 OnMsgShowACK)
132 IPC_MESSAGE_UNHANDLED(handled = false)
133 IPC_END_MESSAGE_MAP()
134 // FIXME(brettw) handle bad messages!
135 return handled;
136 }
137
138 void PPB_Flash_Menu_Proxy::OnMsgCreate(PP_Instance instance_id,
139 const SerializedFlashMenu& menu_data,
140 HostResource* result) {
141 PP_Resource resource = ppb_flash_menu_target()->Create(instance_id,
142 menu_data.pp_menu());
143 result->SetHostResource(instance_id, resource);
144 }
145
146 struct PPB_Flash_Menu_Proxy::ShowRequest {
147 HostResource menu;
148 int32_t selected_id;
149 };
150
151 void PPB_Flash_Menu_Proxy::OnMsgShow(const HostResource& menu,
152 const PP_Point& location) {
153 ShowRequest* request = new ShowRequest;
154 request->menu = menu;
155 CompletionCallback callback = callback_factory_.NewCallback(
156 &PPB_Flash_Menu_Proxy::SendShowACKToPlugin, request);
157 int32_t result = ppb_flash_menu_target()->Show(
158 menu.host_resource(),
159 &location,
160 &request->selected_id,
161 callback.pp_completion_callback());
162 if (result != PP_ERROR_WOULDBLOCK) {
163 // 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
165 // clean up the data associated with the callback.
166 callback.Run(result);
167 }
168 }
169
170 void PPB_Flash_Menu_Proxy::OnMsgShowACK(const HostResource& menu,
171 int32_t selected_id,
172 int32_t result) {
173 PP_Resource plugin_resource =
174 PluginResourceTracker::GetInstance()->PluginResourceForHostResource(menu);
175 if (!plugin_resource)
176 return;
177 FlashMenu* object = PluginResource::GetAs<FlashMenu>(plugin_resource);
178 if (!object) {
179 // The plugin has released the FlashMenu object so don't issue the
180 // callback.
181 return;
182 }
183
184 // Be careful to make the callback NULL before issuing the callback since the
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 }
191
192 void PPB_Flash_Menu_Proxy::SendShowACKToPlugin(
193 int32_t result,
194 ShowRequest* request) {
195 dispatcher()->Send(new PpapiMsg_PPBFlashMenu_ShowACK(
196 INTERFACE_ID_PPB_FLASH_MENU,
197 request->menu,
198 request->selected_id,
199 result));
200 delete request;
201 }
202
203 } // namespace proxy
204 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/proxy/ppb_flash_menu_proxy.h ('k') | ppapi/proxy/ppb_flash_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698